Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(connector): [STAX] Incoming amount will be processed in higher unit (#2091)
DEEPANSHU BANSALde9e0feac0e0
diff --git a/crates/router/src/connector/stax/transformers.rs b/crates/router/src/connector/stax/transformers.rsindex d4a9aebece..e36f66abb7 100644--- a/crates/router/src/connector/stax/transformers.rs+++ b/crates/router/src/connector/stax/transformers.rs@@ -1,10 +1,12 @@use common_utils::pii::Email;-use error_stack::IntoReport;+use error_stack::{IntoReport, ResultExt};use masking::{ExposeInterface, Secret};use serde::{Deserialize, Serialize};use crate::{- connector::utils::{missing_field_err, CardData, PaymentsAuthorizeRequestData, RouterData},+ connector::utils::{+ self, missing_field_err, CardData, PaymentsAuthorizeRequestData, RouterData,+ },core::errors,types::{self, api, storage::enums},};@@ -17,7 +19,7 @@ pub struct StaxPaymentsRequestMetaData {#[derive(Debug, Serialize)]pub struct StaxPaymentsRequest {payment_method_id: Secret<String>,- total: i64,+ total: f64,is_refundable: bool,pre_auth: bool,meta: StaxPaymentsRequestMetaData,@@ -32,12 +34,14 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for StaxPaymentsRequest {connector: "Stax",})?}+ let total = utils::to_currency_base_unit_asf64(item.request.amount, item.request.currency)?;+match item.request.payment_method_data.clone() {api::PaymentMethodData::Card(_) => {let pre_auth = !item.request.is_auto_capture()?;Ok(Self {meta: StaxPaymentsRequestMetaData { tax: 0 },- total: item.request.amount,+ total,is_refundable: true,pre_auth,payment_method_id: Secret::new(item.get_payment_method_token()?),@@ -49,7 +53,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for StaxPaymentsRequest {let pre_auth = !item.request.is_auto_capture()?;Ok(Self {meta: StaxPaymentsRequestMetaData { tax: 0 },- total: item.request.amount,+ total,is_refundable: true,pre_auth,payment_method_id: Secret::new(item.get_payment_method_token()?),@@ -322,13 +326,16 @@ impl<F, T>#[derive(Debug, Serialize)]#[serde(rename_all = "camelCase")]pub struct StaxCaptureRequest {- total: Option<i64>,+ total: Option<f64>,}impl TryFrom<&types::PaymentsCaptureRouterData> for StaxCaptureRequest {type Error = error_stack::Report<errors::ConnectorError>;fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {- let total = item.request.amount_to_capture;+ let total = utils::to_currency_base_unit_asf64(+ item.request.amount_to_capture,+ item.request.currency,+ )?;Ok(Self { total: Some(total) })}}@@ -337,14 +344,17 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for StaxCaptureRequest {// Type definition for RefundRequest#[derive(Debug, Serialize)]pub struct StaxRefundRequest {- pub total: i64,+ pub total: f64,}impl<F> TryFrom<&types::RefundsRouterData<F>> for StaxRefundRequest {type Error = error_stack::Report<errors::ConnectorError>;fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {Ok(Self {- total: item.request.refund_amount,+ total: utils::to_currency_base_unit_asf64(+ item.request.refund_amount,+ item.request.currency,+ )?,})}}@@ -354,7 +364,7 @@ pub struct ChildTransactionsInResponse {id: String,success: bool,created_at: String,- total: i64,+ total: f64,}#[derive(Debug, Deserialize)]pub struct RefundResponse {@@ -370,11 +380,16 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>>fn try_from(item: types::RefundsResponseRouterData<api::Execute, RefundResponse>,) -> Result<Self, Self::Error> {+ let refund_amount = utils::to_currency_base_unit_asf64(+ item.data.request.refund_amount,+ item.data.request.currency,+ )+ .change_context(errors::ConnectorError::ResponseHandlingFailed)?;let filtered_txn: Vec<&ChildTransactionsInResponse> = item.response.child_transactions.iter()- .filter(|txn| txn.total == item.data.request.refund_amount)+ .filter(|txn| txn.total == refund_amount).collect();let mut refund_txn = filtered_txndiff --git a/crates/router/tests/connectors/stax.rs b/crates/router/tests/connectors/stax.rsindex c4eb2c5132..72c1d89da0 100644--- a/crates/router/tests/connectors/stax.rs+++ b/crates/router/tests/connectors/stax.rs@@ -625,7 +625,7 @@ async fn should_fail_for_refund_amount_higher_than_payment_amount() {.unwrap();assert_eq!(response.response.unwrap_err().reason,- Some(r#"{"total":["The total may not be greater than 100."]}"#.to_string()),+ Some(r#"{"total":["The total may not be greater than 1."]}"#.to_string()),);}