Skip to content

Commit

Permalink
fix(connector): use enum to deserialize latest_charge in stripe psync…
Browse files Browse the repository at this point in the history
… response (#2444)
  • Loading branch information
hrithikesh026 authored Oct 4, 2023
1 parent 6aec168 commit 05ee47a
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions crates/router/src/connector/stripe/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,14 @@ pub struct PaymentIntentSyncResponse {
#[serde(flatten)]
payment_intent_fields: PaymentIntentResponse,
pub last_payment_error: Option<LastPaymentError>,
pub latest_charge: Option<StripeCharge>,
pub latest_charge: Option<StripeChargeEnum>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
pub enum StripeChargeEnum {
ChargeId(String),
ChargeObject(StripeCharge),
}

#[derive(Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -2414,19 +2421,38 @@ impl<F, T>
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,
},
))
});
Expand Down

0 comments on commit 05ee47a

Please sign in to comment.