From 05ee47a6e90bd68a0faa6dcc381c48a1f0f274d8 Mon Sep 17 00:00:00 2001 From: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com> Date: Wed, 4 Oct 2023 21:24:54 +0530 Subject: [PATCH] fix(connector): use enum to deserialize latest_charge in stripe psync response (#2444) --- .../src/connector/stripe/transformers.rs | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 488a7a295bd2..57a7935f0300 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -2125,7 +2125,14 @@ pub struct PaymentIntentSyncResponse { #[serde(flatten)] payment_intent_fields: PaymentIntentResponse, pub last_payment_error: Option, - pub latest_charge: Option, + pub latest_charge: Option, +} + +#[derive(Deserialize, Debug, Clone)] +#[serde(untagged)] +pub enum StripeChargeEnum { + ChargeId(String), + ChargeObject(StripeCharge), } #[derive(Deserialize, Clone, Debug)] @@ -2414,19 +2421,38 @@ impl types::MandateReference::foreign_from(( item.response.payment_method_options.clone(), match item.response.latest_charge.clone() { - Some(charge) => match charge.payment_method_details { - Some(StripePaymentMethodDetailsResponse::Bancontact { bancontact }) => { - bancontact.attached_payment_method.unwrap_or(pm) - } - Some(StripePaymentMethodDetailsResponse::Ideal { ideal }) => { - ideal.attached_payment_method.unwrap_or(pm) + Some(StripeChargeEnum::ChargeObject(charge)) => { + match charge.payment_method_details { + Some(StripePaymentMethodDetailsResponse::Bancontact { bancontact }) => { + bancontact.attached_payment_method.unwrap_or(pm) + } + Some(StripePaymentMethodDetailsResponse::Ideal { ideal }) => { + ideal.attached_payment_method.unwrap_or(pm) + } + Some(StripePaymentMethodDetailsResponse::Sofort { sofort }) => { + sofort.attached_payment_method.unwrap_or(pm) + } + 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::ApplePay) + | Some(StripePaymentMethodDetailsResponse::Ach) + | Some(StripePaymentMethodDetailsResponse::Sepa) + | Some(StripePaymentMethodDetailsResponse::Becs) + | Some(StripePaymentMethodDetailsResponse::Bacs) + | Some(StripePaymentMethodDetailsResponse::Wechatpay) + | Some(StripePaymentMethodDetailsResponse::Alipay) + | Some(StripePaymentMethodDetailsResponse::CustomerBalance) + | None => pm, } - Some(StripePaymentMethodDetailsResponse::Sofort { sofort }) => { - sofort.attached_payment_method.unwrap_or(pm) - } - _ => pm, - }, - None => pm, + } + Some(StripeChargeEnum::ChargeId(_)) | None => pm, }, )) });