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(core): 3DS Setup Mandate Webhook Trigger Fix (#11771)

Sagnik Mitra9475f642a6b2
diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs
index f802e2f334..7207de9436 100644
--- a/crates/hyperswitch_domain_models/src/payments.rs
+++ b/crates/hyperswitch_domain_models/src/payments.rs
@@ -531,6 +531,12 @@ impl PaymentIntent {
installment_options,
})
}
+
+ #[cfg(feature = "v1")]
+ pub fn is_setup_mandate(&self) -> bool {
+ self.amount == MinorUnit::zero()
+ && self.setup_future_usage == Some(common_enums::FutureUsage::OffSession)
+ }
}
#[cfg(feature = "v2")]
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index a6a4461a33..65680a743f 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -4243,6 +4243,7 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize {
None,
&payment_intent
.profile_id
+ .clone()
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("missing profile_id in payment_intent")?,
&payment_attempt
@@ -4280,9 +4281,7 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize {
}),
..Default::default()
};
- let is_setup_mandate = payment_intent.amount == MinorUnit::zero()
- && payment_intent.setup_future_usage
- == Some(storage_enums::FutureUsage::OffSession);
+ let is_setup_mandate = payment_intent.is_setup_mandate();
if is_setup_mandate {
Box::pin(payments_core::<
api::SetupMandate,
diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs
index 47e01b0a44..b7a00d0652 100644
--- a/crates/router/src/core/webhooks/incoming.rs
+++ b/crates/router/src/core/webhooks/incoming.rs
@@ -2496,34 +2496,69 @@ async fn external_authentication_incoming_webhook_flow(
== Some(common_enums::DecoupledAuthenticationType::Challenge)
&& event_type == webhooks::IncomingWebhookEvent::ExternalAuthenticationARes
{
+ let payment_intent = state
+ .store
+ .find_payment_intent_by_payment_id_processor_merchant_id(
+ &payment_id,
+ platform.get_processor().get_account().get_id(),
+ platform.get_processor().get_key_store(),
+ platform.get_processor().get_account().storage_scheme,
+ )
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
let payment_confirm_req = api::PaymentsRequest {
payment_id: Some(api_models::payments::PaymentIdType::PaymentIntentId(
- payment_id,
+ payment_intent.payment_id.clone(),
)),
merchant_id: Some(platform.get_processor().get_account().get_id().clone()),
..Default::default()
};
- let payments_response = Box::pin(payments::payments_core::<
- api::Authorize,
- api::PaymentsResponse,
- _,
- _,
- _,
- payments::PaymentData<api::Authorize>,
- >(
- state.clone(),
- req_state,
- platform.clone(),
- None,
- payments::PaymentConfirm,
- payment_confirm_req,
- services::api::AuthFlow::Merchant,
- payments::CallConnectorAction::Trigger,
- None,
- None,
- HeaderPayload::with_source(enums::PaymentSource::ExternalAuthenticator),
- ))
- .await?;
+ let is_setup_mandate = payment_intent.is_setup_mandate();
+ let payments_response = if is_setup_mandate {
+ Box::pin(payments::payments_core::<
+ api::SetupMandate,
+ api::PaymentsResponse,
+ _,
+ _,
+ _,
+ payments::PaymentData<api::SetupMandate>,
+ >(
+ state.clone(),
+ req_state,
+ platform.clone(),
+ None,
+ payments::PaymentConfirm,
+ payment_confirm_req,
+ services::api::AuthFlow::Merchant,
+ payments::CallConnectorAction::Trigger,
+ None,
+ None,
+ HeaderPayload::with_source(enums::PaymentSource::ExternalAuthenticator),
+ ))
+ .await?
+ } else {
+ Box::pin(payments::payments_core::<
+ api::Authorize,
+ api::PaymentsResponse,
+ _,
+ _,
+ _,
+ payments::PaymentData<api::Authorize>,
+ >(
+ state.clone(),
+ req_state,
+ platform.clone(),
+ None,
+ payments::PaymentConfirm,
+ payment_confirm_req,
+ services::api::AuthFlow::Merchant,
+ payments::CallConnectorAction::Trigger,
+ None,
+ None,
+ HeaderPayload::with_source(enums::PaymentSource::ExternalAuthenticator),
+ ))
+ .await?
+ };
match payments_response {
services::ApplicationResponse::JsonWithHeaders((payments_response, _)) => {
let payment_id = payments_response.payment_id.clone();