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

fix(webhooks): preserve setup payment id for Santander mandate API events (#14814)

Aniket Burman943256054fc0
diff --git a/crates/api_models/src/webhooks.rs b/crates/api_models/src/webhooks.rs
index b9b8607cd1..ab4a42feb7 100644
--- a/crates/api_models/src/webhooks.rs
+++ b/crates/api_models/src/webhooks.rs
@@ -210,6 +210,9 @@ pub enum WebhookResponseTracker {
PaymentMethod {
payment_method_id: String,
status: common_enums::PaymentMethodStatus,
+ /// Original setup payment associated with a connector-managed mandate.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ payment_id: Option<common_utils::id_type::PaymentId>,
},
NoEffect,
Relay {
@@ -225,7 +228,8 @@ impl WebhookResponseTracker {
Self::Payment { payment_id, .. }
| Self::Refund { payment_id, .. }
| Self::Dispute { payment_id, .. } => Some(payment_id.to_owned()),
- Self::NoEffect | Self::Mandate { .. } | Self::PaymentMethod { .. } => None,
+ Self::PaymentMethod { payment_id, .. } => payment_id.clone(),
+ Self::NoEffect | Self::Mandate { .. } => None,
#[cfg(feature = "payouts")]
Self::Payout { .. } => None,
Self::Relay { .. } => None,
diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs
index cc847dbcf8..a28cc2c1a2 100644
--- a/crates/router/src/core/webhooks/incoming.rs
+++ b/crates/router/src/core/webhooks/incoming.rs
@@ -2421,6 +2421,7 @@ async fn update_connector_managed_mandate_by_connector_txn_id(
&platform,
&business_profile,
payment_method,
+ setup_attempt.payment_id,
&merchant_connector_account.get_id(),
event_type,
)
@@ -2495,6 +2496,7 @@ async fn update_payment_method_mandate_status(
platform: &domain::Platform,
business_profile: &domain::Profile,
payment_method: domain::PaymentMethod,
+ payment_id: common_utils::id_type::PaymentId,
merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId,
event_type: webhooks::IncomingWebhookEvent,
) -> CustomResult<WebhookResponseTracker, errors::ApiErrorResponse> {
@@ -2630,6 +2632,7 @@ async fn update_payment_method_mandate_status(
Ok(WebhookResponseTracker::PaymentMethod {
payment_method_id,
status: tracker_status,
+ payment_id: Some(payment_id),
})
}
diff --git a/crates/router/src/core/webhooks/network_tokenization_incoming.rs b/crates/router/src/core/webhooks/network_tokenization_incoming.rs
index 1f1b06e0e6..2895f7ed98 100644
--- a/crates/router/src/core/webhooks/network_tokenization_incoming.rs
+++ b/crates/router/src/core/webhooks/network_tokenization_incoming.rs
@@ -265,6 +265,7 @@ pub async fn handle_metadata_update(
Ok(WebhookResponseTracker::PaymentMethod {
payment_method_id,
status,
+ payment_id: None,
})
}
true => {
@@ -404,6 +405,7 @@ pub async fn handle_metadata_update(
Ok(WebhookResponseTracker::PaymentMethod {
payment_method_id,
status,
+ payment_id: None,
})
}
}