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(router): [affirm] UCS support — config header, CompleteAuthorize payment_method, auto-capture (#13049)

Tushar Shuklade95008a6fcc
diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs
index c63f890e3e..013cbd29e9 100644
--- a/crates/router/src/core/payments/flows.rs
+++ b/crates/router/src/core/payments/flows.rs
@@ -363,20 +363,23 @@ pub fn should_initiate_capture_flow(
status: common_enums::AttemptStatus,
) -> bool {
match status {
- common_enums::AttemptStatus::Authorized => {
- if let Some(api_enums::CaptureMethod::SequentialAutomatic) = capture_method {
- match connector_name {
- router_types::Connector::Paybox => {
- // Check CIT conditions for Paybox
- setup_future_usage == Some(api_enums::FutureUsage::OffSession)
- && customer_acceptance.is_some()
- }
- _ => false,
+ common_enums::AttemptStatus::Authorized => match capture_method {
+ Some(api_enums::CaptureMethod::SequentialAutomatic) => match connector_name {
+ router_types::Connector::Paybox => {
+ // Check CIT conditions for Paybox
+ setup_future_usage == Some(api_enums::FutureUsage::OffSession)
+ && customer_acceptance.is_some()
}
- } else {
- false
+ _ => false,
+ },
+ // Affirm (BNPL) authorizes the loan on the transaction-create (CompleteAuthorize)
+ // leg and needs a follow-up capture (POST /transactions/{id}/capture) to settle for
+ // automatic capture, so chain the capture flow when it comes back Authorized.
+ Some(api_enums::CaptureMethod::Automatic) => {
+ matches!(connector_name, router_types::Connector::Affirm)
}
- }
+ _ => false,
+ },
_ => false,
}
}
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 242e85018d..da6fc2caee 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -3766,6 +3766,19 @@ pub async fn make_pm_data<'a, F: Clone, R, D>(
_ => Ok((None, None)),
}?;
+ // For stateless redirect pay-later PMs (e.g. Affirm BNPL), the redirect-completion
+ // request carries no payment_method_data and there is no stored card/token, so the
+ // match above resolves to None. Reconstruct the PaymentMethodData from the persisted
+ // payment_method_type so downstream flows (e.g. UCS CompleteAuthorize) still receive a
+ // payment_method and can run the transaction-create leg with the checkout_token.
+ let payment_method =
+ payment_method.or_else(|| match payment_data.payment_attempt.payment_method_type {
+ Some(storage_enums::PaymentMethodType::Affirm) => Some(
+ domain::PaymentMethodData::PayLater(domain::PayLaterData::AffirmRedirect {}),
+ ),
+ _ => None,
+ });
+
Ok((operation, payment_method, pm_id))
}
diff --git a/crates/router/src/core/unified_connector_service/connector_config.rs b/crates/router/src/core/unified_connector_service/connector_config.rs
index 63579b0a11..5c34ebd63c 100644
--- a/crates/router/src/core/unified_connector_service/connector_config.rs
+++ b/crates/router/src/core/unified_connector_service/connector_config.rs
@@ -117,6 +117,11 @@ pub struct PeachpaymentsMetadata {
/// Connector-specific configuration enum for all supported connectors
#[derive(Debug, Clone, serde::Serialize)]
pub enum ConnectorSpecificConfig {
+ /// Affirm connector configuration (public/private API key pair, HTTP Basic auth)
+ Affirm {
+ public_key: Secret<String>,
+ private_key: Secret<String>,
+ },
/// Adyen connector configuration
Adyen {
api_key: Secret<String>,
@@ -993,6 +998,13 @@ impl ForeignTryFrom<(Connector, &ConnectorAuthType, Option<&serde_json::Value>)>
}),
_ => Err(err("Bamboraapac requires SignatureKey auth type")),
},
+ Connector::Affirm => match auth {
+ ConnectorAuthType::BodyKey { api_key, key1 } => Ok(Self::Affirm {
+ public_key: api_key.clone(),
+ private_key: key1.clone(),
+ }),
+ _ => Err(err("Affirm requires BodyKey auth type")),
+ },
Connector::Barclaycard => match auth {
ConnectorAuthType::SignatureKey {
api_key,