mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
refactor(paylater): use payment_method_data.billing fields instead of payment_method_data (#4333)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -349,10 +349,9 @@ impl TryFrom<&MultisafepayRouterData<&types::PaymentsAuthorizeRouterData>>
|
||||
utils::get_unimplemented_payment_method_error_message("multisafepay"),
|
||||
))?,
|
||||
}),
|
||||
domain::PaymentMethodData::PayLater(domain::PayLaterData::KlarnaRedirect {
|
||||
billing_email: _,
|
||||
billing_country: _,
|
||||
}) => Some(Gateway::Klarna),
|
||||
domain::PaymentMethodData::PayLater(domain::PayLaterData::KlarnaRedirect {}) => {
|
||||
Some(Gateway::Klarna)
|
||||
}
|
||||
domain::PaymentMethodData::MandatePayment => None,
|
||||
domain::PaymentMethodData::CardRedirect(_)
|
||||
| domain::PaymentMethodData::PayLater(_)
|
||||
@ -484,15 +483,12 @@ impl TryFrom<&MultisafepayRouterData<&types::PaymentsAuthorizeRouterData>>
|
||||
domain::PaymentMethodData::PayLater(ref paylater) => {
|
||||
Some(GatewayInfo::PayLater(PayLaterInfo {
|
||||
email: Some(match paylater {
|
||||
domain::PayLaterData::KlarnaRedirect { billing_email, .. } => {
|
||||
billing_email.clone()
|
||||
domain::PayLaterData::KlarnaRedirect {} => {
|
||||
item.router_data.get_billing_email()?
|
||||
}
|
||||
domain::PayLaterData::KlarnaSdk { token: _ }
|
||||
| domain::PayLaterData::AffirmRedirect {}
|
||||
| domain::PayLaterData::AfterpayClearpayRedirect {
|
||||
billing_email: _,
|
||||
billing_name: _,
|
||||
}
|
||||
| domain::PayLaterData::AfterpayClearpayRedirect {}
|
||||
| domain::PayLaterData::PayBrightRedirect {}
|
||||
| domain::PayLaterData::WalleyRedirect {}
|
||||
| domain::PayLaterData::AlmaRedirect {}
|
||||
|
||||
@ -1057,44 +1057,6 @@ impl From<&domain::BankDebitData> for StripePaymentMethodType {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<(&domain::payments::PayLaterData, StripePaymentMethodType)> for StripeBillingAddress {
|
||||
type Error = errors::ConnectorError;
|
||||
|
||||
fn try_from(
|
||||
(pay_later_data, pm_type): (&domain::payments::PayLaterData, StripePaymentMethodType),
|
||||
) -> Result<Self, Self::Error> {
|
||||
match (pay_later_data, pm_type) {
|
||||
(
|
||||
domain::payments::PayLaterData::KlarnaRedirect {
|
||||
billing_email,
|
||||
billing_country,
|
||||
},
|
||||
StripePaymentMethodType::Klarna,
|
||||
) => Ok(Self {
|
||||
email: Some(billing_email.to_owned()),
|
||||
country: Some(billing_country.to_owned()),
|
||||
..Self::default()
|
||||
}),
|
||||
(
|
||||
domain::payments::PayLaterData::AffirmRedirect {},
|
||||
StripePaymentMethodType::Affirm,
|
||||
) => Ok(Self::default()),
|
||||
(
|
||||
domain::payments::PayLaterData::AfterpayClearpayRedirect {
|
||||
billing_email,
|
||||
billing_name,
|
||||
},
|
||||
StripePaymentMethodType::AfterpayClearpay,
|
||||
) => Ok(Self {
|
||||
email: Some(billing_email.to_owned()),
|
||||
name: Some(billing_name.to_owned()),
|
||||
..Self::default()
|
||||
}),
|
||||
_ => Err(errors::ConnectorError::MismatchedPaymentData),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&domain::BankDebitBilling> for StripeBillingAddress {
|
||||
fn from(item: &domain::BankDebitBilling) -> Self {
|
||||
Self {
|
||||
@ -1318,7 +1280,7 @@ fn create_stripe_payment_method(
|
||||
}
|
||||
domain::PaymentMethodData::PayLater(pay_later_data) => {
|
||||
let stripe_pm_type = StripePaymentMethodType::try_from(pay_later_data)?;
|
||||
let billing_address = StripeBillingAddress::try_from((pay_later_data, stripe_pm_type))?;
|
||||
|
||||
Ok((
|
||||
StripePaymentMethodData::PayLater(StripePayLaterData {
|
||||
payment_method_data_type: stripe_pm_type,
|
||||
|
||||
@ -66,18 +66,10 @@ pub enum CardRedirectData {
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub enum PayLaterData {
|
||||
KlarnaRedirect {
|
||||
billing_email: Email,
|
||||
billing_country: common_enums::CountryAlpha2,
|
||||
},
|
||||
KlarnaSdk {
|
||||
token: String,
|
||||
},
|
||||
KlarnaRedirect {},
|
||||
KlarnaSdk { token: String },
|
||||
AffirmRedirect {},
|
||||
AfterpayClearpayRedirect {
|
||||
billing_email: Email,
|
||||
billing_name: Secret<String>,
|
||||
},
|
||||
AfterpayClearpayRedirect {},
|
||||
PayBrightRedirect {},
|
||||
WalleyRedirect {},
|
||||
AlmaRedirect {},
|
||||
@ -713,22 +705,12 @@ impl From<api_models::payments::ApplePayWalletData> for ApplePayWalletData {
|
||||
impl From<api_models::payments::PayLaterData> for PayLaterData {
|
||||
fn from(value: api_models::payments::PayLaterData) -> Self {
|
||||
match value {
|
||||
api_models::payments::PayLaterData::KlarnaRedirect {
|
||||
billing_email,
|
||||
billing_country,
|
||||
} => Self::KlarnaRedirect {
|
||||
billing_email,
|
||||
billing_country,
|
||||
},
|
||||
api_models::payments::PayLaterData::KlarnaRedirect { .. } => Self::KlarnaRedirect {},
|
||||
api_models::payments::PayLaterData::KlarnaSdk { token } => Self::KlarnaSdk { token },
|
||||
api_models::payments::PayLaterData::AffirmRedirect {} => Self::AffirmRedirect {},
|
||||
api_models::payments::PayLaterData::AfterpayClearpayRedirect {
|
||||
billing_email,
|
||||
billing_name,
|
||||
} => Self::AfterpayClearpayRedirect {
|
||||
billing_email,
|
||||
billing_name,
|
||||
},
|
||||
api_models::payments::PayLaterData::AfterpayClearpayRedirect { .. } => {
|
||||
Self::AfterpayClearpayRedirect {}
|
||||
}
|
||||
api_models::payments::PayLaterData::PayBrightRedirect {} => Self::PayBrightRedirect {},
|
||||
api_models::payments::PayLaterData::WalleyRedirect {} => Self::WalleyRedirect {},
|
||||
api_models::payments::PayLaterData::AlmaRedirect {} => Self::AlmaRedirect {},
|
||||
|
||||
Reference in New Issue
Block a user