Skip to content

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

feat(core): Add network_transaction_id in payments Response (#9032)

awasthi217047c3faa1e7
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 9c3b4a56d6..0a08599181 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -96,6 +96,7 @@ pub struct PaymentAttempt {
pub processor_merchant_id: Option<id_type::MerchantId>,
pub created_by: Option<String>,
pub connector_request_reference_id: Option<String>,
+ pub network_transaction_id: Option<String>,
#[diesel(deserialize_as = RequiredFromNullable<storage_enums::PaymentMethod>)]
pub payment_method_type_v2: storage_enums::PaymentMethod,
pub connector_payment_id: Option<ConnectorTransactionId>,
@@ -210,6 +211,7 @@ pub struct PaymentAttempt {
pub setup_future_usage_applied: Option<storage_enums::FutureUsage>,
pub routing_approach: Option<storage_enums::RoutingApproach>,
pub connector_request_reference_id: Option<String>,
+ pub network_transaction_id: Option<String>,
}
#[cfg(feature = "v1")]
@@ -309,6 +311,7 @@ pub struct PaymentAttemptNew {
pub preprocessing_step_id: Option<String>,
pub error_reason: Option<String>,
pub connector_response_reference_id: Option<String>,
+ pub network_transaction_id: Option<String>,
pub multiple_capture_count: Option<i16>,
pub amount_capturable: MinorUnit,
pub updated_by: String,
@@ -431,6 +434,7 @@ pub struct PaymentAttemptNew {
pub setup_future_usage_applied: Option<storage_enums::FutureUsage>,
pub routing_approach: Option<storage_enums::RoutingApproach>,
pub connector_request_reference_id: Option<String>,
+ pub network_transaction_id: Option<String>,
}
#[cfg(feature = "v1")]
@@ -453,6 +457,7 @@ pub enum PaymentAttemptUpdate {
tax_amount: Option<MinorUnit>,
fingerprint_id: Option<String>,
payment_method_billing_address_id: Option<String>,
+ network_transaction_id: Option<String>,
updated_by: String,
},
UpdateTrackers {
@@ -506,6 +511,7 @@ pub enum PaymentAttemptUpdate {
card_discovery: Option<storage_enums::CardDiscovery>,
routing_approach: Option<storage_enums::RoutingApproach>,
connector_request_reference_id: Option<String>,
+ network_transaction_id: Option<String>,
},
VoidUpdate {
status: storage_enums::AttemptStatus,
@@ -537,6 +543,7 @@ pub enum PaymentAttemptUpdate {
connector: Option<String>,
connector_transaction_id: Option<String>,
authentication_type: Option<storage_enums::AuthenticationType>,
+ network_transaction_id: Option<String>,
payment_method_id: Option<String>,
mandate_id: Option<String>,
connector_metadata: Option<serde_json::Value>,
@@ -975,6 +982,7 @@ impl PaymentAttemptUpdateInternal {
processor_merchant_id: source.processor_merchant_id,
created_by: source.created_by,
payment_method_type_v2: source.payment_method_type_v2,
+ network_transaction_id: source.network_transaction_id,
connector_payment_id: source.connector_payment_id,
payment_method_subtype: source.payment_method_subtype,
routing_result: source.routing_result,
@@ -1058,6 +1066,7 @@ pub struct PaymentAttemptUpdateInternal {
pub setup_future_usage_applied: Option<storage_enums::FutureUsage>,
pub routing_approach: Option<storage_enums::RoutingApproach>,
pub connector_request_reference_id: Option<String>,
+ pub network_transaction_id: Option<String>,
}
#[cfg(feature = "v1")]
@@ -1249,6 +1258,7 @@ impl PaymentAttemptUpdate {
setup_future_usage_applied,
routing_approach,
connector_request_reference_id,
+ network_transaction_id,
} = PaymentAttemptUpdateInternal::from(self).populate_derived_fields(&source);
PaymentAttempt {
amount: amount.unwrap_or(source.amount),
@@ -1318,6 +1328,7 @@ impl PaymentAttemptUpdate {
routing_approach: routing_approach.or(source.routing_approach),
connector_request_reference_id: connector_request_reference_id
.or(source.connector_request_reference_id),
+ network_transaction_id: network_transaction_id.or(source.network_transaction_id),
..source
}
}
@@ -2317,6 +2328,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
fingerprint_id,
updated_by,
payment_method_billing_address_id,
+ network_transaction_id,
} => Self {
amount: Some(amount),
currency: Some(currency),
@@ -2378,6 +2390,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id,
},
PaymentAttemptUpdate::AuthenticationTypeUpdate {
authentication_type,
@@ -2442,6 +2455,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::ConfirmUpdate {
amount,
@@ -2479,6 +2493,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_discovery,
routing_approach,
connector_request_reference_id,
+ network_transaction_id,
} => Self {
amount: Some(amount),
currency: Some(currency),
@@ -2539,6 +2554,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach,
connector_request_reference_id,
+ network_transaction_id,
},
PaymentAttemptUpdate::VoidUpdate {
status,
@@ -2604,6 +2620,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::RejectUpdate {
status,
@@ -2670,6 +2687,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::BlocklistUpdate {
status,
@@ -2736,6 +2754,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::ConnectorMandateDetailUpdate {
connector_mandate_detail,
@@ -2800,6 +2819,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::PaymentMethodDetailsUpdate {
payment_method_id,
@@ -2864,6 +2884,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::ResponseUpdate {
status,
@@ -2890,6 +2911,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
connector_mandate_detail,
charges,
setup_future_usage_applied,
+ network_transaction_id,
} => {
let (connector_transaction_id, processor_transaction_data) =
connector_transaction_id
@@ -2956,6 +2978,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id,
}
}
PaymentAttemptUpdate::ErrorUpdate {
@@ -3039,6 +3062,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
}
}
PaymentAttemptUpdate::StatusUpdate { status, updated_by } => Self {
@@ -3101,6 +3125,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::UpdateTrackers {
payment_token,
@@ -3172,6 +3197,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::UnresolvedResponseUpdate {
status,
@@ -3249,6 +3275,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
}
}
PaymentAttemptUpdate::PreprocessingUpdate {
@@ -3325,6 +3352,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
}
}
PaymentAttemptUpdate::CaptureUpdate {
@@ -3391,6 +3419,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::AmountToCaptureUpdate {
status,
@@ -3456,6 +3485,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::ConnectorResponse {
authentication_data,
@@ -3530,6 +3560,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
}
}
PaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate {
@@ -3595,6 +3626,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::AuthenticationUpdate {
status,
@@ -3662,6 +3694,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
PaymentAttemptUpdate::ManualUpdate {
status,
@@ -3738,6 +3771,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
}
}
PaymentAttemptUpdate::PostSessionTokensUpdate {
@@ -3803,6 +3837,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
},
}
}
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 319503e65c..08675d904d 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -981,6 +981,8 @@ diesel::table! {
routing_approach -> Nullable<RoutingApproach>,
#[max_length = 255]
connector_request_reference_id -> Nullable<Varchar>,
+ #[max_length = 255]
+ network_transaction_id -> Nullable<Varchar>,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 1837903f3a..4711143d32 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -923,6 +923,8 @@ diesel::table! {
created_by -> Nullable<Varchar>,
#[max_length = 255]
connector_request_reference_id -> Nullable<Varchar>,
+ #[max_length = 255]
+ network_transaction_id -> Nullable<Varchar>,
payment_method_type_v2 -> Nullable<Varchar>,
#[max_length = 128]
connector_payment_id -> Nullable<Varchar>,
diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rs
index f892ac8e86..846c0852b6 100644
--- a/crates/diesel_models/src/user/sample_data.rs
+++ b/crates/diesel_models/src/user/sample_data.rs
@@ -218,6 +218,7 @@ pub struct PaymentAttemptBatchNew {
pub setup_future_usage_applied: Option<common_enums::FutureUsage>,
pub routing_approach: Option<common_enums::RoutingApproach>,
pub connector_request_reference_id: Option<String>,
+ pub network_transaction_id: Option<String>,
}
#[cfg(feature = "v1")]
@@ -305,6 +306,7 @@ impl PaymentAttemptBatchNew {
setup_future_usage_applied: self.setup_future_usage_applied,
routing_approach: self.routing_approach,
connector_request_reference_id: self.connector_request_reference_id,
+ network_transaction_id: self.network_transaction_id,
}
}
}
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index 755d9f79c4..4d1ae8bb92 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -490,6 +490,7 @@ pub struct PaymentAttempt {
/// merchantwho invoked the resource based api (identifier) and through what source (Api, Jwt(Dashboard))
pub created_by: Option<CreatedBy>,
pub connector_request_reference_id: Option<String>,
+ pub network_transaction_id: Option<String>,
}
impl PaymentAttempt {
@@ -622,6 +623,7 @@ impl PaymentAttempt {
processor_merchant_id: payment_intent.merchant_id.clone(),
created_by: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
})
}
@@ -711,6 +713,7 @@ impl PaymentAttempt {
processor_merchant_id: payment_intent.merchant_id.clone(),
created_by: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
})
}
@@ -806,6 +809,7 @@ impl PaymentAttempt {
processor_merchant_id: payment_intent.merchant_id.clone(),
created_by: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
})
}
@@ -915,6 +919,7 @@ impl PaymentAttempt {
processor_merchant_id: payment_intent.merchant_id.clone(),
created_by: None,
connector_request_reference_id,
+ network_transaction_id: None,
})
}
@@ -1015,6 +1020,7 @@ pub struct PaymentAttempt {
pub routing_approach: Option<storage_enums::RoutingApproach>,
pub connector_request_reference_id: Option<String>,
pub debit_routing_savings: Option<MinorUnit>,
+ pub network_transaction_id: Option<String>,
}
#[cfg(feature = "v1")]
@@ -1307,6 +1313,7 @@ pub struct PaymentAttemptNew {
pub setup_future_usage_applied: Option<storage_enums::FutureUsage>,
pub routing_approach: Option<storage_enums::RoutingApproach>,
pub connector_request_reference_id: Option<String>,
+ pub network_transaction_id: Option<String>,
}
#[cfg(feature = "v1")]
@@ -1328,6 +1335,7 @@ pub enum PaymentAttemptUpdate {
fingerprint_id: Option<String>,
payment_method_billing_address_id: Option<String>,
updated_by: String,
+ network_transaction_id: Option<String>,
},
UpdateTrackers {
payment_token: Option<String>,
@@ -1376,6 +1384,7 @@ pub enum PaymentAttemptUpdate {
card_discovery: Option<common_enums::CardDiscovery>,
routing_approach: Option<storage_enums::RoutingApproach>,
connector_request_reference_id: Option<String>,
+ network_transaction_id: Option<String>,
},
RejectUpdate {
status: storage_enums::AttemptStatus,
@@ -1406,6 +1415,7 @@ pub enum PaymentAttemptUpdate {
status: storage_enums::AttemptStatus,
connector: Option<String>,
connector_transaction_id: Option<String>,
+ network_transaction_id: Option<String>,
authentication_type: Option<storage_enums::AuthenticationType>,
payment_method_id: Option<String>,
mandate_id: Option<String>,
@@ -1532,6 +1542,7 @@ impl PaymentAttemptUpdate {
amount_to_capture,
capture_method,
fingerprint_id,
+ network_transaction_id,
payment_method_billing_address_id,
updated_by,
} => DieselPaymentAttemptUpdate::Update {
@@ -1551,6 +1562,7 @@ impl PaymentAttemptUpdate {
tax_amount: net_amount.get_tax_on_surcharge(),
fingerprint_id,
payment_method_billing_address_id,
+ network_transaction_id,
updated_by,
},
Self::UpdateTrackers {
@@ -1645,6 +1657,7 @@ impl PaymentAttemptUpdate {
card_discovery,
routing_approach,
connector_request_reference_id,
+ network_transaction_id,
} => DieselPaymentAttemptUpdate::ConfirmUpdate {
amount: net_amount.get_order_amount(),
currency,
@@ -1688,6 +1701,7 @@ impl PaymentAttemptUpdate {
_ => approach,
}),
connector_request_reference_id,
+ network_transaction_id,
},
Self::VoidUpdate {
status,
@@ -1723,6 +1737,7 @@ impl PaymentAttemptUpdate {
connector_mandate_detail,
charges,
setup_future_usage_applied,
+ network_transaction_id,
debit_routing_savings: _,
} => DieselPaymentAttemptUpdate::ResponseUpdate {
status,
@@ -1749,6 +1764,7 @@ impl PaymentAttemptUpdate {
connector_mandate_detail,
charges,
setup_future_usage_applied,
+ network_transaction_id,
},
Self::UnresolvedResponseUpdate {
status,
@@ -2123,6 +2139,7 @@ impl behaviour::Conversion for PaymentAttempt {
created_by: self.created_by.map(|cb| cb.to_string()),
routing_approach: self.routing_approach,
connector_request_reference_id: self.connector_request_reference_id,
+ network_transaction_id: self.network_transaction_id,
})
}
@@ -2221,6 +2238,7 @@ impl behaviour::Conversion for PaymentAttempt {
routing_approach: storage_model.routing_approach,
connector_request_reference_id: storage_model.connector_request_reference_id,
debit_routing_savings: None,
+ network_transaction_id: storage_model.network_transaction_id,
})
}
.await
@@ -2311,6 +2329,7 @@ impl behaviour::Conversion for PaymentAttempt {
setup_future_usage_applied: self.setup_future_usage_applied,
routing_approach: self.routing_approach,
connector_request_reference_id: self.connector_request_reference_id,
+ network_transaction_id: self.network_transaction_id,
})
}
}
@@ -2383,6 +2402,7 @@ impl behaviour::Conversion for PaymentAttempt {
processor_merchant_id,
created_by,
connector_request_reference_id,
+ network_transaction_id,
} = self;
let AttemptAmountDetails {
@@ -2478,6 +2498,7 @@ impl behaviour::Conversion for PaymentAttempt {
processor_merchant_id: Some(processor_merchant_id),
created_by: created_by.map(|cb| cb.to_string()),
connector_request_reference_id,
+ network_transaction_id,
})
}
@@ -2601,6 +2622,7 @@ impl behaviour::Conversion for PaymentAttempt {
.created_by
.and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
connector_request_reference_id: storage_model.connector_request_reference_id,
+ network_transaction_id: storage_model.network_transaction_id,
})
}
.await
@@ -2660,6 +2682,7 @@ impl behaviour::Conversion for PaymentAttempt {
processor_merchant_id,
created_by,
connector_request_reference_id,
+ network_transaction_id,
} = self;
let card_network = payment_method_data
@@ -2677,6 +2700,7 @@ impl behaviour::Conversion for PaymentAttempt {
payment_id,
merchant_id,
status,
+ network_transaction_id,
error_message: error_details
.as_ref()
.map(|details| details.message.clone()),
diff --git a/crates/hyperswitch_domain_models/src/router_response_types.rs b/crates/hyperswitch_domain_models/src/router_response_types.rs
index c7cfbc7674..17c268fb60 100644
--- a/crates/hyperswitch_domain_models/src/router_response_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_response_types.rs
@@ -143,6 +143,12 @@ impl PaymentsResponseData {
_ => None,
}
}
+ pub fn get_network_transaction_id(&self) -> Option<String> {
+ match self {
+ Self::TransactionResponse { network_txn_id, .. } => network_txn_id.clone(),
+ _ => None,
+ }
+ }
pub fn get_connector_transaction_id(
&self,
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 1523a4b3c2..b3a1c7e52b 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -4635,6 +4635,7 @@ impl AttemptType {
setup_future_usage_applied: None,
routing_approach: old_payment_attempt.routing_approach,
connector_request_reference_id: None,
+ network_transaction_id: None,
}
}
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 7cc48fd6f4..dca5c726a5 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -1967,6 +1967,10 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
card_discovery,
routing_approach: payment_data.payment_attempt.routing_approach,
connector_request_reference_id,
+ network_transaction_id: payment_data
+ .payment_attempt
+ .network_transaction_id
+ .clone(),
},
storage_scheme,
)
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index d9b71791df..79bfbebf49 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -1386,6 +1386,7 @@ impl PaymentCreate {
setup_future_usage_applied: request.setup_future_usage,
routing_approach: Some(common_enums::RoutingApproach::default()),
connector_request_reference_id: None,
+ network_transaction_id:None,
},
additional_pm_data,
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 0ffc4f84da..830186eeaa 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -1726,6 +1726,12 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
types::ResponseId::ConnectorTransactionId(ref id)
| types::ResponseId::EncodedData(ref id) => Some(id),
};
+ let resp_network_transaction_id = router_data.response.as_ref()
+ .map_err(|err| {
+ logger::error!(error = ?err, "Failed to obtain the network_transaction_id from payment response");
+ })
+ .ok()
+ .and_then(|resp| resp.get_network_transaction_id());
let encoded_data = payment_data.payment_attempt.encoded_data.clone();
@@ -1932,6 +1938,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
.payment_attempt
.setup_future_usage_applied,
debit_routing_savings,
+ network_transaction_id: resp_network_transaction_id,
}),
),
};
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 6026a82e0d..b1460efcf4 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -813,6 +813,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
.surcharge_details
.as_ref()
.map(|surcharge_details| surcharge_details.tax_on_surcharge_amount);
+ let network_transaction_id = payment_data.payment_attempt.network_transaction_id.clone();
payment_data.payment_attempt = state
.store
.update_payment_attempt_with_attempt_id(
@@ -832,6 +833,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
fingerprint_id: None,
payment_method_billing_address_id,
updated_by: storage_scheme.to_string(),
+ network_transaction_id,
net_amount:
hyperswitch_domain_models::payments::payment_attempt::NetAmount::new(
payment_data.amount.into(),
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index b49103b961..1811a449af 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -517,6 +517,10 @@ where
charges,
setup_future_usage_applied: None,
debit_routing_savings,
+ network_transaction_id: payment_data
+ .get_payment_attempt()
+ .network_transaction_id
+ .clone(),
};
#[cfg(feature = "v1")]
@@ -715,6 +719,7 @@ pub fn make_new_payment_attempt(
setup_future_usage_applied: setup_future_usage_intent, // setup future usage is picked from intent for new payment attempt
routing_approach: old_payment_attempt.routing_approach,
connector_request_reference_id: Default::default(),
+ network_transaction_id: old_payment_attempt.network_transaction_id,
}
}
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index cf91b2bcc3..8a3594c310 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -3338,9 +3338,7 @@ where
fingerprint: payment_intent.fingerprint_id,
browser_info: payment_attempt.browser_info,
payment_method_id: payment_attempt.payment_method_id,
- network_transaction_id: payment_data
- .get_payment_method_info()
- .and_then(|info| info.network_transaction_id.clone()),
+ network_transaction_id: payment_attempt.network_transaction_id,
payment_method_status: payment_data
.get_payment_method_info()
.map(|info| info.status),
diff --git a/crates/router/src/services/kafka/payment_attempt.rs b/crates/router/src/services/kafka/payment_attempt.rs
index 0d8dfd8704..9afb697e14 100644
--- a/crates/router/src/services/kafka/payment_attempt.rs
+++ b/crates/router/src/services/kafka/payment_attempt.rs
@@ -278,6 +278,7 @@ impl<'a> KafkaPaymentAttempt<'a> {
processor_merchant_id,
created_by,
connector_request_reference_id,
+ network_transaction_id: _,
} = attempt;
let (connector_payment_id, connector_payment_data) = connector_payment_id
diff --git a/crates/router/src/services/kafka/payment_attempt_event.rs b/crates/router/src/services/kafka/payment_attempt_event.rs
index 5f87e017f8..46a05d6fcf 100644
--- a/crates/router/src/services/kafka/payment_attempt_event.rs
+++ b/crates/router/src/services/kafka/payment_attempt_event.rs
@@ -280,6 +280,7 @@ impl<'a> KafkaPaymentAttemptEvent<'a> {
processor_merchant_id,
created_by,
connector_request_reference_id,
+ network_transaction_id: _,
} = attempt;
let (connector_payment_id, connector_payment_data) = connector_payment_id
diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs
index 32601f25c7..c0ccc2ee37 100644
--- a/crates/router/src/types/storage/payment_attempt.rs
+++ b/crates/router/src/types/storage/payment_attempt.rs
@@ -227,6 +227,7 @@ mod tests {
setup_future_usage_applied: Default::default(),
routing_approach: Default::default(),
connector_request_reference_id: Default::default(),
+ network_transaction_id: Default::default(),
};
let store = state
@@ -319,6 +320,7 @@ mod tests {
setup_future_usage_applied: Default::default(),
routing_approach: Default::default(),
connector_request_reference_id: Default::default(),
+ network_transaction_id: Default::default(),
};
let store = state
.stores
@@ -424,6 +426,7 @@ mod tests {
setup_future_usage_applied: Default::default(),
routing_approach: Default::default(),
connector_request_reference_id: Default::default(),
+ network_transaction_id: Default::default(),
};
let store = state
.stores
diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs
index f7253fc057..5c8d79e0f0 100644
--- a/crates/router/src/utils/user/sample_data.rs
+++ b/crates/router/src/utils/user/sample_data.rs
@@ -391,6 +391,7 @@ pub async fn generate_sample_data(
setup_future_usage_applied: None,
routing_approach: None,
connector_request_reference_id: None,
+ network_transaction_id: None,
};
let refund = if refunds_count < number_of_refunds && !is_failed_payment {
diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs
index 0268bc93ac..022c226527 100644
--- a/crates/storage_impl/src/mock_db/payment_attempt.rs
+++ b/crates/storage_impl/src/mock_db/payment_attempt.rs
@@ -238,6 +238,7 @@ impl PaymentAttemptInterface for MockDb {
routing_approach: payment_attempt.routing_approach,
connector_request_reference_id: payment_attempt.connector_request_reference_id,
debit_routing_savings: None,
+ network_transaction_id: payment_attempt.network_transaction_id,
};
payment_attempts.push(payment_attempt.clone());
Ok(payment_attempt)
diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs
index 5424ad964e..f5bcf1dce3 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -692,6 +692,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
.connector_request_reference_id
.clone(),
debit_routing_savings: None,
+ network_transaction_id: payment_attempt.network_transaction_id.clone(),
};
let field = format!("pa_{}", created_attempt.attempt_id);
@@ -1900,6 +1901,7 @@ impl DataModelExt for PaymentAttempt {
processor_merchant_id: Some(self.processor_merchant_id),
created_by: self.created_by.map(|created_by| created_by.to_string()),
connector_request_reference_id: self.connector_request_reference_id,
+ network_transaction_id: self.network_transaction_id,
}
}
@@ -1993,6 +1995,7 @@ impl DataModelExt for PaymentAttempt {
routing_approach: storage_model.routing_approach,
connector_request_reference_id: storage_model.connector_request_reference_id,
debit_routing_savings: None,
+ network_transaction_id: storage_model.network_transaction_id,
}
}
}
@@ -2084,6 +2087,7 @@ impl DataModelExt for PaymentAttemptNew {
setup_future_usage_applied: self.setup_future_usage_applied,
routing_approach: self.routing_approach,
connector_request_reference_id: self.connector_request_reference_id,
+ network_transaction_id: self.network_transaction_id,
}
}
@@ -2168,6 +2172,7 @@ impl DataModelExt for PaymentAttemptNew {
setup_future_usage_applied: storage_model.setup_future_usage_applied,
routing_approach: storage_model.routing_approach,
connector_request_reference_id: storage_model.connector_request_reference_id,
+ network_transaction_id: storage_model.network_transaction_id,
}
}
}
diff --git a/migrations/2025-08-20-095434_add_ntid_in_attempt_table/down.sql b/migrations/2025-08-20-095434_add_ntid_in_attempt_table/down.sql
new file mode 100644
index 0000000000..98f92ed3d6
--- /dev/null
+++ b/migrations/2025-08-20-095434_add_ntid_in_attempt_table/down.sql
@@ -0,0 +1,2 @@
+ALTER TABLE payment_attempt
+DROP COLUMN IF EXISTS network_transaction_id;
diff --git a/migrations/2025-08-20-095434_add_ntid_in_attempt_table/up.sql b/migrations/2025-08-20-095434_add_ntid_in_attempt_table/up.sql
new file mode 100644
index 0000000000..922423e606
--- /dev/null
+++ b/migrations/2025-08-20-095434_add_ntid_in_attempt_table/up.sql
@@ -0,0 +1,2 @@
+ALTER TABLE payment_attempt
+ADD COLUMN IF NOT EXISTS network_transaction_id VARCHAR(255) NULL;