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(unified_connector_service): complete PayPal wallet redirect over UCS (#13242)

Tushar Shukla72921fb3664e
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rs
index 9c7561968c..4e67117860 100644
--- a/crates/router/src/core/unified_connector_service.rs
+++ b/crates/router/src/core/unified_connector_service.rs
@@ -758,6 +758,25 @@ pub async fn should_call_unified_connector_service_for_webhooks(
Ok((execution_path, rollout_result.webhook_flows))
}
+/// On a redirect-complete callback the inbound request carries only redirect params, so
+/// `payment_method_data` is `None`. UCS still requires `payment_method` on the authorize call,
+/// so rebuild a minimal one from the attempt's payment method type.
+pub fn reconstruct_payment_method_data_for_redirect_completion(
+ payment_method_type: Option<PaymentMethodType>,
+ email: Option<common_utils::pii::Email>,
+) -> Option<hyperswitch_domain_models::payment_method_data::PaymentMethodData> {
+ match payment_method_type {
+ Some(PaymentMethodType::Paypal) => Some(
+ hyperswitch_domain_models::payment_method_data::PaymentMethodData::Wallet(
+ hyperswitch_domain_models::payment_method_data::WalletData::PaypalRedirect(
+ hyperswitch_domain_models::payment_method_data::PaypalRedirection { email },
+ ),
+ ),
+ ),
+ _ => None,
+ }
+}
+
pub fn build_unified_connector_service_payment_method(
payment_method_data: hyperswitch_domain_models::payment_method_data::PaymentMethodData,
payment_method_type: Option<PaymentMethodType>,
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rs
index f1f3c8d7f6..9fb29f8c9a 100644
--- a/crates/router/src/core/unified_connector_service/transformers.rs
+++ b/crates/router/src/core/unified_connector_service/transformers.rs
@@ -595,10 +595,14 @@ impl
) -> Result<Self, Self::Error> {
let currency = payments_grpc::Currency::foreign_try_from(router_data.request.currency)?;
- let payment_method = router_data
- .request
- .payment_method_data
- .clone()
+ let payment_method_data = router_data.request.payment_method_data.clone().or_else(|| {
+ unified_connector_service::reconstruct_payment_method_data_for_redirect_completion(
+ router_data.request.payment_method_type,
+ router_data.request.email.clone(),
+ )
+ });
+
+ let payment_method = payment_method_data
.map(|payment_method_data| {
unified_connector_service::build_unified_connector_service_payment_method(
payment_method_data,
@@ -794,7 +798,8 @@ impl
.map(payments_grpc::Tokenization::foreign_from)
.map(Into::into),
l2_l3_data: None,
- connector_order_id: None,
+ // Captures the order created before the redirect instead of creating a new one.
+ connector_order_id: router_data.request.connector_transaction_id.clone(),
merchant_request_id: None,
partner_merchant_identifier_details: None,
})
@@ -2221,9 +2226,17 @@ impl
.map(payments_grpc::CaptureMethod::foreign_try_from)
.transpose()?;
+ // MIT/recurring charges do not resend the payment method, so the subtype of the saved
+ // payment method comes from the stored mandate via `recurring_mandate_payment_data`.
let payment_method_type = router_data
.request
.payment_method_type
+ .or_else(|| {
+ router_data
+ .recurring_mandate_payment_data
+ .as_ref()
+ .and_then(|data| data.payment_method_type)
+ })
.map(payments_grpc::PaymentMethodType::foreign_try_from)
.transpose()?
.map(|pm_type| pm_type.into());
@@ -2471,6 +2484,8 @@ impl
}),
}),
auth_type: Some(auth_type.into()),
+ // Provide the HS complete-authorize URL so a wallet MIT that needs buyer
+ // re-approval returns to HS (→ CompleteAuthorize) rather than the merchant URL.
complete_authorize_url: router_data.request.complete_authorize_url.clone(),
payment_channel: router_data
.request
@@ -3325,7 +3340,13 @@ impl
Ok((
PaymentsResponseData::TransactionResponse {
resource_id: connector_transaction_id,
- redirection_data: Box::new(None),
+ redirection_data: Box::new(
+ response
+ .redirection_data
+ .clone()
+ .map(RedirectForm::foreign_try_from)
+ .transpose()?,
+ ),
mandate_reference: Box::new(response.mandate_reference_details.map(hyperswitch_domain_models::router_response_types::MandateReference::foreign_try_from).transpose()?),
connector_metadata,
network_txn_id: response.network_transaction_id.clone(),