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(connector): [stripe] fix bank redirect (`bancontact_card`) recurring mandate (#7990)

Pa1NarK40fd473989b0
diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs
index 9d372a5415..ad2e1d7e85 100644
--- a/crates/router/src/connector/stripe/transformers.rs
+++ b/crates/router/src/connector/stripe/transformers.rs
@@ -2071,7 +2071,7 @@ impl TryFrom<&types::SetupMandateRouterData> for SetupIntentRequest {
impl TryFrom<&types::TokenizationRouterData> for TokenRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &types::TokenizationRouterData) -> Result<Self, Self::Error> {
- // Card flow for tokenization is handled seperately because of API contact difference
+ // Card flow for tokenization is handled separately because of API contact difference
let request_payment_data = match &item.request.payment_method_data {
domain::PaymentMethodData::Card(card_details) => {
StripePaymentMethodData::CardToken(StripeCardToken {
@@ -2683,6 +2683,45 @@ pub fn get_connector_metadata(
Ok(next_action_response)
}
+pub fn get_payment_method_id(
+ latest_charge: Option<StripeChargeEnum>,
+ payment_method_id_from_intent_root: Secret<String>,
+) -> String {
+ match latest_charge {
+ Some(StripeChargeEnum::ChargeObject(charge)) => match charge.payment_method_details {
+ Some(StripePaymentMethodDetailsResponse::Bancontact { bancontact }) => bancontact
+ .attached_payment_method
+ .map(|attached_payment_method| attached_payment_method.expose())
+ .unwrap_or(payment_method_id_from_intent_root.expose()),
+ Some(StripePaymentMethodDetailsResponse::Ideal { ideal }) => ideal
+ .attached_payment_method
+ .map(|attached_payment_method| attached_payment_method.expose())
+ .unwrap_or(payment_method_id_from_intent_root.expose()),
+ Some(StripePaymentMethodDetailsResponse::Blik)
+ | Some(StripePaymentMethodDetailsResponse::Eps)
+ | Some(StripePaymentMethodDetailsResponse::Fpx)
+ | Some(StripePaymentMethodDetailsResponse::Giropay)
+ | Some(StripePaymentMethodDetailsResponse::Przelewy24)
+ | Some(StripePaymentMethodDetailsResponse::Card { .. })
+ | Some(StripePaymentMethodDetailsResponse::Klarna)
+ | Some(StripePaymentMethodDetailsResponse::Affirm)
+ | Some(StripePaymentMethodDetailsResponse::AfterpayClearpay)
+ | Some(StripePaymentMethodDetailsResponse::AmazonPay)
+ | Some(StripePaymentMethodDetailsResponse::ApplePay)
+ | Some(StripePaymentMethodDetailsResponse::Ach)
+ | Some(StripePaymentMethodDetailsResponse::Sepa)
+ | Some(StripePaymentMethodDetailsResponse::Becs)
+ | Some(StripePaymentMethodDetailsResponse::Bacs)
+ | Some(StripePaymentMethodDetailsResponse::Wechatpay)
+ | Some(StripePaymentMethodDetailsResponse::Alipay)
+ | Some(StripePaymentMethodDetailsResponse::CustomerBalance)
+ | Some(StripePaymentMethodDetailsResponse::Cashapp { .. })
+ | None => payment_method_id_from_intent_root.expose(),
+ },
+ Some(StripeChargeEnum::ChargeId(_)) | None => payment_method_id_from_intent_root.expose(),
+ }
+}
+
impl<F, T>
TryFrom<types::ResponseRouterData<F, PaymentIntentSyncResponse, T, types::PaymentsResponseData>>
for types::RouterData<F, T, types::PaymentsResponseData>
@@ -2713,46 +2752,11 @@ where
// Implemented Save and re-use payment information for recurring charges
// For more info: https://docs.stripe.com/recurring-payments#accept-recurring-payments
// For backward compatibility payment_method_id & connector_mandate_id is being populated with the same value
- let connector_mandate_id = Some(payment_method_id.clone().expose());
- let payment_method_id = match item.response.latest_charge.clone() {
- Some(StripeChargeEnum::ChargeObject(charge)) => {
- match charge.payment_method_details {
- Some(StripePaymentMethodDetailsResponse::Bancontact { bancontact }) => {
- bancontact
- .attached_payment_method
- .map(|attached_payment_method| attached_payment_method.expose())
- .unwrap_or(payment_method_id.expose())
- }
- Some(StripePaymentMethodDetailsResponse::Ideal { ideal }) => ideal
- .attached_payment_method
- .map(|attached_payment_method| attached_payment_method.expose())
- .unwrap_or(payment_method_id.expose()),
- Some(StripePaymentMethodDetailsResponse::Blik)
- | Some(StripePaymentMethodDetailsResponse::Eps)
- | Some(StripePaymentMethodDetailsResponse::Fpx)
- | Some(StripePaymentMethodDetailsResponse::Giropay)
- | Some(StripePaymentMethodDetailsResponse::Przelewy24)
- | Some(StripePaymentMethodDetailsResponse::Card { .. })
- | Some(StripePaymentMethodDetailsResponse::Klarna)
- | Some(StripePaymentMethodDetailsResponse::Affirm)
- | Some(StripePaymentMethodDetailsResponse::AfterpayClearpay)
- | Some(StripePaymentMethodDetailsResponse::AmazonPay)
- | Some(StripePaymentMethodDetailsResponse::ApplePay)
- | Some(StripePaymentMethodDetailsResponse::Ach)
- | Some(StripePaymentMethodDetailsResponse::Sepa)
- | Some(StripePaymentMethodDetailsResponse::Becs)
- | Some(StripePaymentMethodDetailsResponse::Bacs)
- | Some(StripePaymentMethodDetailsResponse::Wechatpay)
- | Some(StripePaymentMethodDetailsResponse::Alipay)
- | Some(StripePaymentMethodDetailsResponse::CustomerBalance)
- | Some(StripePaymentMethodDetailsResponse::Cashapp { .. })
- | None => payment_method_id.expose(),
- }
- }
- Some(StripeChargeEnum::ChargeId(_)) | None => payment_method_id.expose(),
- };
+ let payment_method_id =
+ get_payment_method_id(item.response.latest_charge.clone(), payment_method_id);
+
types::MandateReference {
- connector_mandate_id,
+ connector_mandate_id: Some(payment_method_id.clone()),
payment_method_id: Some(payment_method_id),
mandate_metadata: None,
connector_mandate_request_reference_id: None,