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(paysafe): drive Card 3DS via UCS PreAuthenticate + settle the frictionless flow (#13352)

Tushar Shuklac37e8b81684c
diff --git a/crates/hyperswitch_connectors/src/connectors/paysafe.rs b/crates/hyperswitch_connectors/src/connectors/paysafe.rs
index 04e46a245f..4a93be9c56 100644
--- a/crates/hyperswitch_connectors/src/connectors/paysafe.rs
+++ b/crates/hyperswitch_connectors/src/connectors/paysafe.rs
@@ -75,6 +75,20 @@ impl Paysafe {
amount_converter: &MinorUnitForConnector,
}
}
+
+ /// Whether a PreAuthenticate (3DS setup) leg must run before Authorize.
+ pub fn is_3ds_setup_required(
+ &self,
+ request: &PaymentsAuthorizeData,
+ auth_type: common_enums::AuthenticationType,
+ ) -> bool {
+ router_env::logger::info!(router_data_request=?request, auth_type=?auth_type, "Checking if 3DS setup is required for Paysafe");
+ auth_type.is_three_ds()
+ && request.is_card()
+ && (request.connector_mandate_id().is_none()
+ && request.get_optional_network_transaction_id().is_none())
+ && request.authentication_data.is_none()
+ }
}
impl api::Payment for Paysafe {}
@@ -1319,6 +1333,65 @@ impl ConnectorSpecifications for Paysafe {
Some(&PAYSAFE_CONNECTOR_INFO)
}
+ fn get_alternate_flow_if_needed(
+ &self,
+ current_flow: api::CurrentFlowInfo,
+ ) -> Option<api::AlternateFlow> {
+ match current_flow {
+ api::CurrentFlowInfo::Authorize {
+ request_data,
+ auth_type,
+ } => {
+ if self.is_3ds_setup_required(&request_data, auth_type) {
+ Some(api::AlternateFlow::PreAuthenticate)
+ } else {
+ None
+ }
+ }
+ api::CurrentFlowInfo::CompleteAuthorize { .. }
+ | api::CurrentFlowInfo::SetupMandate { .. }
+ | api::CurrentFlowInfo::Psync { .. }
+ | api::CurrentFlowInfo::UpdatePostConfirm { .. }
+ | api::CurrentFlowInfo::ConnectorWebhookRegister { .. } => None,
+ }
+ }
+
+ fn is_pre_authentication_flow_required(&self, current_flow: api::CurrentFlowInfo) -> bool {
+ match current_flow {
+ api::CurrentFlowInfo::Authorize {
+ request_data,
+ auth_type,
+ } => self.is_3ds_setup_required(&request_data, auth_type),
+ api::CurrentFlowInfo::CompleteAuthorize { .. }
+ | api::CurrentFlowInfo::SetupMandate { .. }
+ | api::CurrentFlowInfo::Psync { .. }
+ | api::CurrentFlowInfo::UpdatePostConfirm { .. }
+ | api::CurrentFlowInfo::ConnectorWebhookRegister { .. } => false,
+ }
+ }
+
+ /// Run the Authenticate step on the post-redirect CompleteAuthorize to recover the handle token.
+ fn is_authentication_flow_required(&self, current_flow: api::CurrentFlowInfo) -> bool {
+ match current_flow {
+ api::CurrentFlowInfo::CompleteAuthorize {
+ auth_type,
+ request_data,
+ payment_method,
+ } => {
+ // Paysafe's card ACS returns on a param-less GET, so gate on redirect_response.
+ let is_post_redirect = request_data.redirect_response.is_some();
+ auth_type.is_three_ds()
+ && matches!(payment_method, Some(enums::PaymentMethod::Card))
+ && is_post_redirect
+ }
+ api::CurrentFlowInfo::Authorize { .. }
+ | api::CurrentFlowInfo::SetupMandate { .. }
+ | api::CurrentFlowInfo::Psync { .. }
+ | api::CurrentFlowInfo::UpdatePostConfirm { .. }
+ | api::CurrentFlowInfo::ConnectorWebhookRegister { .. } => false,
+ }
+ }
+
fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {
Some(&*PAYSAFE_SUPPORTED_PAYMENT_METHODS)
}
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index 32c6d94e9f..eb487dafbe 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -571,6 +571,17 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
},
api_models::enums::Connector::Shift4 => true,
api_models::enums::Connector::Nuvei => true,
+ // Paysafe card + 3DS: PreAuthenticate mints the handle. When Paysafe returns no ACS
+ // redirect (frictionless / no challenge), continue straight to the settle Authorize
+ // in this flow; when it returns a redirect, break so the shopper completes the
+ // challenge and the settle runs from CompleteAuthorize.
+ api_models::enums::Connector::Paysafe => match &authorize_router_data.response {
+ Ok(types::PaymentsResponseData::TransactionResponse {
+ redirection_data,
+ ..
+ }) => redirection_data.is_none(),
+ _ => false,
+ },
_ => false,
};
Ok((authorize_router_data, should_continue_after_preauthenticate))
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rs
index 1f0612d4e3..9c7561968c 100644
--- a/crates/router/src/core/unified_connector_service.rs
+++ b/crates/router/src/core/unified_connector_service.rs
@@ -764,57 +764,55 @@ pub fn build_unified_connector_service_payment_method(
payment_method_token: Option<&PaymentMethodToken>,
connector_meta_data: Option<&common_utils::pii::SecretSerdeValue>,
) -> CustomResult<payments_grpc::PaymentMethod, UnifiedConnectorServiceError> {
+ // A connector tokenization token settles for any payment method, including wallets.
+ if let Some(PaymentMethodToken::Token(token)) = payment_method_token {
+ return Ok(payments_grpc::PaymentMethod {
+ payment_method: Some(PaymentMethod::Token(
+ payments_grpc::TokenPaymentMethodType {
+ token: Some(token.clone()),
+ },
+ )),
+ });
+ }
match payment_method_data {
hyperswitch_domain_models::payment_method_data::PaymentMethodData::Card(card) => {
- match payment_method_token {
- Some(PaymentMethodToken::Token(token)) => {
- let token_payment_method = payments_grpc::TokenPaymentMethodType {
- token: Some(token.clone()),
- };
- Ok(payments_grpc::PaymentMethod {
- payment_method: Some(PaymentMethod::Token(token_payment_method)),
- })
- }
- _ => {
- let card_exp_month = card
- .get_card_expiry_month_2_digit()
- .attach_printable("Failed to extract 2-digit expiry month from card")
- .change_context(UnifiedConnectorServiceError::InvalidDataFormat {
- field_name: "card_exp_month",
- })?
- .peek()
- .to_string();
-
- let card_network = card
- .card_network
- .clone()
- .map(payments_grpc::CardNetwork::foreign_from);
-
- let card_details = CardDetails {
- card_number: Some(
- CardNumber::from_str(&card.card_number.get_card_no()).change_context(
- UnifiedConnectorServiceError::RequestEncodingFailedWithReason(
- "Failed to parse card number".to_string(),
- ),
- )?,
+ let card_exp_month = card
+ .get_card_expiry_month_2_digit()
+ .attach_printable("Failed to extract 2-digit expiry month from card")
+ .change_context(UnifiedConnectorServiceError::InvalidDataFormat {
+ field_name: "card_exp_month",
+ })?
+ .peek()
+ .to_string();
+
+ let card_network = card
+ .card_network
+ .clone()
+ .map(payments_grpc::CardNetwork::foreign_from);
+
+ let card_details = CardDetails {
+ card_number: Some(
+ CardNumber::from_str(&card.card_number.get_card_no()).change_context(
+ UnifiedConnectorServiceError::RequestEncodingFailedWithReason(
+ "Failed to parse card number".to_string(),
),
- card_exp_month: Some(card_exp_month.into()),
- card_exp_year: Some(card.card_exp_year.expose().into()),
- card_cvc: Some(card.card_cvc.expose().into()),
- card_holder_name: card.card_holder_name.map(|name| name.expose().into()),
- card_issuer: card.card_issuer.clone(),
- card_network: card_network.map(|card_network| card_network.into()),
- card_type: card.card_type.clone(),
- bank_code: card.bank_code.clone(),
- nick_name: card.nick_name.map(|n| n.expose()),
- card_issuing_country_alpha2: card.card_issuing_country.clone(),
- };
+ )?,
+ ),
+ card_exp_month: Some(card_exp_month.into()),
+ card_exp_year: Some(card.card_exp_year.expose().into()),
+ card_cvc: Some(card.card_cvc.expose().into()),
+ card_holder_name: card.card_holder_name.map(|name| name.expose().into()),
+ card_issuer: card.card_issuer.clone(),
+ card_network: card_network.map(|card_network| card_network.into()),
+ card_type: card.card_type.clone(),
+ bank_code: card.bank_code.clone(),
+ nick_name: card.nick_name.map(|n| n.expose()),
+ card_issuing_country_alpha2: card.card_issuing_country.clone(),
+ };
- Ok(payments_grpc::PaymentMethod {
- payment_method: Some(PaymentMethod::Card(card_details)),
- })
- }
- }
+ Ok(payments_grpc::PaymentMethod {
+ payment_method: Some(PaymentMethod::Card(card_details)),
+ })
}
hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardWithOptionalCVC(
card,
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rs
index b5195a0516..673c0e944c 100644
--- a/crates/router/src/core/unified_connector_service/transformers.rs
+++ b/crates/router/src/core/unified_connector_service/transformers.rs
@@ -604,7 +604,25 @@ impl
router_data.connector_meta_data.as_ref(),
)
})
- .transpose()?;
+ .transpose()?
+ // Post-3DS settle: card data is not persisted through the redirect, so pay by the
+ // handle token the authenticate leg returned in connector metadata (stored on the
+ // request as connector_meta, same channel as authentication_data below).
+ .or_else(|| {
+ router_data
+ .request
+ .connector_meta
+ .as_ref()
+ .and_then(|metadata| metadata.get("payment_handle_token"))
+ .and_then(|token| token.as_str())
+ .map(|handle_token| payments_grpc::PaymentMethod {
+ payment_method: Some(payments_grpc::payment_method::PaymentMethod::Token(
+ payments_grpc::TokenPaymentMethodType {
+ token: Some(Secret::new(handle_token.to_string())),
+ },
+ )),
+ })
+ });
let address = payments_grpc::PaymentAddress::foreign_try_from(router_data.address.clone())?;
@@ -5831,6 +5849,22 @@ impl
.map(|id| router_request_types::ResponseId::ConnectorTransactionId(id.clone()))
.unwrap_or(router_request_types::ResponseId::NoResponseId);
+ // Connector feature data (e.g. a handle token minted by the authenticate leg) must
+ // survive this conversion even when no redirect is returned, so it is parsed
+ // independently of redirection_data.
+ let feature_metadata = response.connector_feature_data.clone().and_then(|secret| {
+ let exposed = secret.expose();
+ serde_json::from_str(&exposed)
+ .map_err(|e| {
+ tracing::warn!(
+ serialization_error = ?e,
+ metadata = ?response.connector_feature_data,
+ "Failed to parse connector_metadata as JSON value"
+ );
+ e
+ })
+ .ok()
+ });
let (connector_metadata, redirection_data) = match response.redirection_data.clone() {
Some(redirection_data) => match redirection_data.form_type {
Some(ref form_type) => match form_type {
@@ -5851,25 +5885,13 @@ impl
)
}
_ => (
- response.connector_feature_data.clone().and_then(|secret| {
- let exposed = secret.expose();
- serde_json::from_str(&exposed)
- .map_err(|e| {
- tracing::warn!(
- serialization_error = ?e,
- metadata = ?response.connector_feature_data,
- "Failed to parse connector_metadata as JSON value"
- );
- e
- })
- .ok()
- }),
+ feature_metadata,
Some(RedirectForm::foreign_try_from(redirection_data)).transpose()?,
),
},
- None => (None, None),
+ None => (feature_metadata, None),
},
- None => (None, None),
+ None => (feature_metadata, None),
};
let status_code = convert_connector_service_status_code(response.status_code)?;