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(mandates): store network transaction id only when `pg_agnostic` config is enabled in the `authorize_flow` (#4318)
Shankar Singh C7b4c4fea332d
diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rsindex 346c662713..1f6c2bcad1 100644--- a/crates/router/src/connector/stripe/transformers.rs+++ b/crates/router/src/connector/stripe/transformers.rs@@ -2663,12 +2663,23 @@ impl<F, T>item.response.id.clone(),))} else {+ let network_transaction_id = match item.response.latest_charge.clone() {+ Some(StripeChargeEnum::ChargeObject(charge_object)) => charge_object+ .payment_method_details+ .and_then(|payment_method_details| match payment_method_details {+ StripePaymentMethodDetailsResponse::Card { card } => {+ card.network_transaction_id+ }+ _ => None,+ }),+ _ => None,+ };Ok(types::PaymentsResponseData::TransactionResponse {resource_id: types::ResponseId::ConnectorTransactionId(item.response.id.clone()),redirection_data,mandate_reference,connector_metadata,- network_txn_id: None,+ network_txn_id: network_transaction_id,connector_response_reference_id: Some(item.response.id.clone()),incremental_authorization_allowed: None,})diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 22f7cb311c..91b1d7f319 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -1347,6 +1347,7 @@ wheremerchant_account,connector_request,key_store,+ payment_data.payment_intent.profile_id.clone(),).await} else {@@ -1475,6 +1476,7 @@ wheremerchant_account,None,key_store,+ payment_data.payment_intent.profile_id.clone(),);join_handlers.push(res);@@ -3069,6 +3071,7 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Cloneconnector_data.connector_name,payment_method_info,) {+ logger::info!("using network_transaction_id for MIT flow");let network_transaction_id = payment_method_info.network_transaction_id.as_ref()diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rsindex 6c952dc259..abe23016f7 100644--- a/crates/router/src/core/payments/flows.rs+++ b/crates/router/src/core/payments/flows.rs@@ -49,6 +49,7 @@ pub trait Feature<F, T> {merchant_account: &domain::MerchantAccount,connector_request: Option<services::Request>,key_store: &domain::MerchantKeyStore,+ profile_id: Option<String>,) -> RouterResult<Self>whereSelf: Sized,diff --git a/crates/router/src/core/payments/flows/approve_flow.rs b/crates/router/src/core/payments/flows/approve_flow.rsindex 14b710de91..43e36847eb 100644--- a/crates/router/src/core/payments/flows/approve_flow.rs+++ b/crates/router/src/core/payments/flows/approve_flow.rs@@ -54,6 +54,7 @@ impl Feature<api::Approve, types::PaymentsApproveData>_merchant_account: &domain::MerchantAccount,_connector_request: Option<services::Request>,_key_store: &domain::MerchantKeyStore,+ _profile_id: Option<String>,) -> RouterResult<Self> {Err(ApiErrorResponse::NotImplemented {message: NotImplementedMessage::Reason("Flow not supported".to_string()),diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rsindex f891f44f09..cccfab5a74 100644--- a/crates/router/src/core/payments/flows/authorize_flow.rs+++ b/crates/router/src/core/payments/flows/authorize_flow.rs@@ -66,6 +66,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAumerchant_account: &domain::MerchantAccount,connector_request: Option<services::Request>,key_store: &domain::MerchantKeyStore,+ profile_id: Option<String>,) -> RouterResult<Self> {let connector_integration: services::BoxedConnectorIntegration<'_,@@ -103,6 +104,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAukey_store,Some(resp.request.amount),Some(resp.request.currency),+ profile_id,)).await?;@@ -132,6 +134,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAukey_store,Some(resp.request.amount),Some(resp.request.currency),+ profile_id,)).await;diff --git a/crates/router/src/core/payments/flows/cancel_flow.rs b/crates/router/src/core/payments/flows/cancel_flow.rsindex 5918380ee0..5814b1cafb 100644--- a/crates/router/src/core/payments/flows/cancel_flow.rs+++ b/crates/router/src/core/payments/flows/cancel_flow.rs@@ -53,6 +53,7 @@ impl Feature<api::Void, types::PaymentsCancelData>_merchant_account: &domain::MerchantAccount,connector_request: Option<services::Request>,_key_store: &domain::MerchantKeyStore,+ _profile_id: Option<String>,) -> RouterResult<Self> {metrics::PAYMENT_CANCEL_COUNT.add(&metrics::CONTEXT,diff --git a/crates/router/src/core/payments/flows/capture_flow.rs b/crates/router/src/core/payments/flows/capture_flow.rsindex d2b7c8e91b..5f64014bce 100644--- a/crates/router/src/core/payments/flows/capture_flow.rs+++ b/crates/router/src/core/payments/flows/capture_flow.rs@@ -54,6 +54,7 @@ impl Feature<api::Capture, types::PaymentsCaptureData>_merchant_account: &domain::MerchantAccount,connector_request: Option<services::Request>,_key_store: &domain::MerchantKeyStore,+ _profile_id: Option<String>,) -> RouterResult<Self> {let connector_integration: services::BoxedConnectorIntegration<'_,diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rsindex 68d0ee8d47..e64240387d 100644--- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs+++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs@@ -68,6 +68,7 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>_merchant_account: &domain::MerchantAccount,connector_request: Option<services::Request>,_key_store: &domain::MerchantKeyStore,+ _profile_id: Option<String>,) -> RouterResult<Self> {let connector_integration: services::BoxedConnectorIntegration<'_,diff --git a/crates/router/src/core/payments/flows/incremental_authorization_flow.rs b/crates/router/src/core/payments/flows/incremental_authorization_flow.rsindex 387916bab7..99f8e4831b 100644--- a/crates/router/src/core/payments/flows/incremental_authorization_flow.rs+++ b/crates/router/src/core/payments/flows/incremental_authorization_flow.rs@@ -61,6 +61,7 @@ impl Feature<api::IncrementalAuthorization, types::PaymentsIncrementalAuthorizat_merchant_account: &domain::MerchantAccount,connector_request: Option<services::Request>,_key_store: &domain::MerchantKeyStore,+ _profile_id: Option<String>,) -> RouterResult<Self> {let connector_integration: services::BoxedConnectorIntegration<'_,diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rsindex cb7a764985..6463e87279 100644--- a/crates/router/src/core/payments/flows/psync_flow.rs+++ b/crates/router/src/core/payments/flows/psync_flow.rs@@ -57,6 +57,7 @@ impl Feature<api::PSync, types::PaymentsSyncData>_merchant_account: &domain::MerchantAccount,connector_request: Option<services::Request>,_key_store: &domain::MerchantKeyStore,+ _profile_id: Option<String>,) -> RouterResult<Self> {let connector_integration: services::BoxedConnectorIntegration<'_,diff --git a/crates/router/src/core/payments/flows/reject_flow.rs b/crates/router/src/core/payments/flows/reject_flow.rsindex 910cc955e6..4157edf8d0 100644--- a/crates/router/src/core/payments/flows/reject_flow.rs+++ b/crates/router/src/core/payments/flows/reject_flow.rs@@ -53,6 +53,7 @@ impl Feature<api::Reject, types::PaymentsRejectData>_merchant_account: &domain::MerchantAccount,_connector_request: Option<services::Request>,_key_store: &domain::MerchantKeyStore,+ _profile_id: Option<String>,) -> RouterResult<Self> {Err(ApiErrorResponse::NotImplemented {message: NotImplementedMessage::Reason("Flow not supported".to_string()),diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rsindex 349c76cd23..1ab72dff15 100644--- a/crates/router/src/core/payments/flows/session_flow.rs+++ b/crates/router/src/core/payments/flows/session_flow.rs@@ -58,6 +58,7 @@ impl Feature<api::Session, types::PaymentsSessionData> for types::PaymentsSessio_merchant_account: &domain::MerchantAccount,_connector_request: Option<services::Request>,_key_store: &domain::MerchantKeyStore,+ _profile_id: Option<String>,) -> RouterResult<Self> {metrics::SESSION_TOKEN_CREATED.add(&metrics::CONTEXT,diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rsindex 27204450a0..d8acfe98f3 100644--- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs+++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs@@ -62,6 +62,7 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setupmerchant_account: &domain::MerchantAccount,connector_request: Option<services::Request>,key_store: &domain::MerchantKeyStore,+ profile_id: Option<String>,) -> RouterResult<Self> {if let Some(mandate_id) = self.request@@ -79,6 +80,7 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup&state.conf.mandates.update_mandate_supported,connector_request,maybe_customer,+ profile_id,)).await} else {@@ -109,6 +111,7 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setupkey_store,resp.request.amount,Some(resp.request.currency),+ profile_id,)).await?;@@ -217,6 +220,7 @@ impl types::SetupMandateRouterData {call_connector_action: payments::CallConnectorAction,merchant_account: &domain::MerchantAccount,key_store: &domain::MerchantKeyStore,+ profile_id: Option<String>,) -> RouterResult<Self> {match confirm {Some(true) => {@@ -248,6 +252,7 @@ impl types::SetupMandateRouterData {key_store,resp.request.amount,Some(resp.request.currency),+ profile_id,)).await?;@@ -278,6 +283,7 @@ impl types::SetupMandateRouterData {supported_connectors_for_update_mandate: &settings::SupportedPaymentMethodsForMandate,connector_request: Option<services::Request>,maybe_customer: &Option<domain::Customer>,+ profile_id: Option<String>,) -> RouterResult<Self> {let payment_method_type = self.request.payment_method_type;@@ -336,6 +342,7 @@ impl types::SetupMandateRouterData {key_store,resp.request.amount,Some(resp.request.currency),+ profile_id,)).await?.0;diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rsindex 70cf702311..aeb4d6e5b1 100644--- a/crates/router/src/core/payments/operations/payment_response.rs+++ b/crates/router/src/core/payments/operations/payment_response.rs@@ -1001,12 +1001,13 @@ async fn update_payment_method_status_and_ntid<F: Clone>(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("The pg_agnostic config was not found in the DB")?;- if &pg_agnostic.config == "true" {+ if &pg_agnostic.config == "true"+ && payment_data.payment_intent.setup_future_usage+ == Some(diesel_models::enums::FutureUsage::OffSession)+ {Some(network_transaction_id)} else {- logger::info!(- "Skip storing network transaction id as pg_agnostic config is not enabled"- );+ logger::info!("Skip storing network transaction id");None}} else {diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rsindex 47cd1cd9eb..3f24c55c99 100644--- a/crates/router/src/core/payments/tokenization.rs+++ b/crates/router/src/core/payments/tokenization.rs@@ -41,6 +41,7 @@ pub async fn save_payment_method<F: Clone, FData>(key_store: &domain::MerchantKeyStore,amount: Option<i64>,currency: Option<storage_enums::Currency>,+ profile_id: Option<String>,) -> RouterResult<(Option<String>, Option<common_enums::PaymentMethodStatus>)>whereFData: mandate::MandateBehaviour,@@ -64,6 +65,35 @@ where_ => None,};+ let network_transaction_id =+ if let Some(network_transaction_id) = network_transaction_id {+ let profile_id = profile_id+ .as_ref()+ .ok_or(errors::ApiErrorResponse::ResourceIdNotFound)?;++ let pg_agnostic = state+ .store+ .find_config_by_key_unwrap_or(+ &format!("pg_agnostic_mandate_{}", profile_id),+ Some("false".to_string()),+ )+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("The pg_agnostic config was not found in the DB")?;++ if &pg_agnostic.config == "true"+ && resp.request.get_setup_future_usage()+ == Some(storage_enums::FutureUsage::OffSession)+ {+ Some(network_transaction_id)+ } else {+ logger::info!("Skip storing network transaction id");+ None+ }+ } else {+ None+ };+let connector_token = if token_store {let tokens = resp.payment_method_token