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:
Swangi Kumari
2024-05-06 13:09:18 +05:30
committed by GitHub
parent 1335554f51
commit b878677f15
8 changed files with 58 additions and 104 deletions

View File

@ -1063,11 +1063,11 @@ pub enum PayLaterData {
/// For KlarnaRedirect as PayLater Option /// For KlarnaRedirect as PayLater Option
KlarnaRedirect { KlarnaRedirect {
/// The billing email /// The billing email
#[schema(value_type = String)] #[schema(value_type = Option<String>)]
billing_email: Email, billing_email: Option<Email>,
// The billing country code // The billing country code
#[schema(value_type = CountryAlpha2, example = "US")] #[schema(value_type = Option<CountryAlpha2>, example = "US")]
billing_country: api_enums::CountryAlpha2, billing_country: Option<api_enums::CountryAlpha2>,
}, },
/// For Klarna Sdk as PayLater Option /// For Klarna Sdk as PayLater Option
KlarnaSdk { KlarnaSdk {
@ -1079,11 +1079,11 @@ pub enum PayLaterData {
/// For AfterpayClearpay redirect as PayLater Option /// For AfterpayClearpay redirect as PayLater Option
AfterpayClearpayRedirect { AfterpayClearpayRedirect {
/// The billing email /// The billing email
#[schema(value_type = String)] #[schema(value_type = Option<String>)]
billing_email: Email, billing_email: Option<Email>,
/// The billing name /// The billing name
#[schema(value_type = String)] #[schema(value_type = Option<String>)]
billing_name: Secret<String>, billing_name: Option<Secret<String>>,
}, },
/// For PayBright Redirect as PayLater Option /// For PayBright Redirect as PayLater Option
PayBrightRedirect {}, PayBrightRedirect {},
@ -1102,13 +1102,13 @@ impl GetAddressFromPaymentMethodData for PayLaterData {
billing_country, billing_country,
} => { } => {
let address_details = AddressDetails { let address_details = AddressDetails {
country: Some(*billing_country), country: *billing_country,
..AddressDetails::default() ..AddressDetails::default()
}; };
Some(Address { Some(Address {
address: Some(address_details), address: Some(address_details),
email: Some(billing_email.clone()), email: billing_email.clone(),
phone: None, phone: None,
}) })
} }
@ -1117,13 +1117,13 @@ impl GetAddressFromPaymentMethodData for PayLaterData {
billing_name, billing_name,
} => { } => {
let address_details = AddressDetails { let address_details = AddressDetails {
first_name: Some(billing_name.clone()), first_name: billing_name.clone(),
..AddressDetails::default() ..AddressDetails::default()
}; };
Some(Address { Some(Address {
address: Some(address_details), address: Some(address_details),
email: Some(billing_email.clone()), email: billing_email.clone(),
phone: None, phone: None,
}) })
} }
@ -1444,7 +1444,7 @@ impl GetAddressFromPaymentMethodData for PaymentMethodData {
Self::Card(card_data) => card_data.get_billing_address(), Self::Card(card_data) => card_data.get_billing_address(),
Self::CardRedirect(_) => None, Self::CardRedirect(_) => None,
Self::Wallet(wallet_data) => wallet_data.get_billing_address(), Self::Wallet(wallet_data) => wallet_data.get_billing_address(),
Self::PayLater(_) => None, Self::PayLater(pay_later) => pay_later.get_billing_address(),
Self::BankRedirect(_) => None, Self::BankRedirect(_) => None,
Self::BankDebit(_) => None, Self::BankDebit(_) => None,
Self::BankTransfer(_) => None, Self::BankTransfer(_) => None,
@ -4871,8 +4871,8 @@ mod billing_from_payment_method_data {
let klarna_paylater_payment_method_data = let klarna_paylater_payment_method_data =
PaymentMethodData::PayLater(PayLaterData::KlarnaRedirect { PaymentMethodData::PayLater(PayLaterData::KlarnaRedirect {
billing_email: test_email.clone(), billing_email: Some(test_email.clone()),
billing_country: TEST_COUNTRY, billing_country: Some(TEST_COUNTRY),
}); });
let billing_address = klarna_paylater_payment_method_data let billing_address = klarna_paylater_payment_method_data

View File

@ -349,10 +349,9 @@ impl TryFrom<&MultisafepayRouterData<&types::PaymentsAuthorizeRouterData>>
utils::get_unimplemented_payment_method_error_message("multisafepay"), utils::get_unimplemented_payment_method_error_message("multisafepay"),
))?, ))?,
}), }),
domain::PaymentMethodData::PayLater(domain::PayLaterData::KlarnaRedirect { domain::PaymentMethodData::PayLater(domain::PayLaterData::KlarnaRedirect {}) => {
billing_email: _, Some(Gateway::Klarna)
billing_country: _, }
}) => Some(Gateway::Klarna),
domain::PaymentMethodData::MandatePayment => None, domain::PaymentMethodData::MandatePayment => None,
domain::PaymentMethodData::CardRedirect(_) domain::PaymentMethodData::CardRedirect(_)
| domain::PaymentMethodData::PayLater(_) | domain::PaymentMethodData::PayLater(_)
@ -484,15 +483,12 @@ impl TryFrom<&MultisafepayRouterData<&types::PaymentsAuthorizeRouterData>>
domain::PaymentMethodData::PayLater(ref paylater) => { domain::PaymentMethodData::PayLater(ref paylater) => {
Some(GatewayInfo::PayLater(PayLaterInfo { Some(GatewayInfo::PayLater(PayLaterInfo {
email: Some(match paylater { email: Some(match paylater {
domain::PayLaterData::KlarnaRedirect { billing_email, .. } => { domain::PayLaterData::KlarnaRedirect {} => {
billing_email.clone() item.router_data.get_billing_email()?
} }
domain::PayLaterData::KlarnaSdk { token: _ } domain::PayLaterData::KlarnaSdk { token: _ }
| domain::PayLaterData::AffirmRedirect {} | domain::PayLaterData::AffirmRedirect {}
| domain::PayLaterData::AfterpayClearpayRedirect { | domain::PayLaterData::AfterpayClearpayRedirect {}
billing_email: _,
billing_name: _,
}
| domain::PayLaterData::PayBrightRedirect {} | domain::PayLaterData::PayBrightRedirect {}
| domain::PayLaterData::WalleyRedirect {} | domain::PayLaterData::WalleyRedirect {}
| domain::PayLaterData::AlmaRedirect {} | domain::PayLaterData::AlmaRedirect {}

View File

@ -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 { impl From<&domain::BankDebitBilling> for StripeBillingAddress {
fn from(item: &domain::BankDebitBilling) -> Self { fn from(item: &domain::BankDebitBilling) -> Self {
Self { Self {
@ -1318,7 +1280,7 @@ fn create_stripe_payment_method(
} }
domain::PaymentMethodData::PayLater(pay_later_data) => { domain::PaymentMethodData::PayLater(pay_later_data) => {
let stripe_pm_type = StripePaymentMethodType::try_from(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(( Ok((
StripePaymentMethodData::PayLater(StripePayLaterData { StripePaymentMethodData::PayLater(StripePayLaterData {
payment_method_data_type: stripe_pm_type, payment_method_data_type: stripe_pm_type,

View File

@ -66,18 +66,10 @@ pub enum CardRedirectData {
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize)]
pub enum PayLaterData { pub enum PayLaterData {
KlarnaRedirect { KlarnaRedirect {},
billing_email: Email, KlarnaSdk { token: String },
billing_country: common_enums::CountryAlpha2,
},
KlarnaSdk {
token: String,
},
AffirmRedirect {}, AffirmRedirect {},
AfterpayClearpayRedirect { AfterpayClearpayRedirect {},
billing_email: Email,
billing_name: Secret<String>,
},
PayBrightRedirect {}, PayBrightRedirect {},
WalleyRedirect {}, WalleyRedirect {},
AlmaRedirect {}, AlmaRedirect {},
@ -713,22 +705,12 @@ impl From<api_models::payments::ApplePayWalletData> for ApplePayWalletData {
impl From<api_models::payments::PayLaterData> for PayLaterData { impl From<api_models::payments::PayLaterData> for PayLaterData {
fn from(value: api_models::payments::PayLaterData) -> Self { fn from(value: api_models::payments::PayLaterData) -> Self {
match value { match value {
api_models::payments::PayLaterData::KlarnaRedirect { api_models::payments::PayLaterData::KlarnaRedirect { .. } => Self::KlarnaRedirect {},
billing_email,
billing_country,
} => Self::KlarnaRedirect {
billing_email,
billing_country,
},
api_models::payments::PayLaterData::KlarnaSdk { token } => Self::KlarnaSdk { token }, api_models::payments::PayLaterData::KlarnaSdk { token } => Self::KlarnaSdk { token },
api_models::payments::PayLaterData::AffirmRedirect {} => Self::AffirmRedirect {}, api_models::payments::PayLaterData::AffirmRedirect {} => Self::AffirmRedirect {},
api_models::payments::PayLaterData::AfterpayClearpayRedirect { api_models::payments::PayLaterData::AfterpayClearpayRedirect { .. } => {
billing_email, Self::AfterpayClearpayRedirect {}
billing_name, }
} => Self::AfterpayClearpayRedirect {
billing_email,
billing_name,
},
api_models::payments::PayLaterData::PayBrightRedirect {} => Self::PayBrightRedirect {}, api_models::payments::PayLaterData::PayBrightRedirect {} => Self::PayBrightRedirect {},
api_models::payments::PayLaterData::WalleyRedirect {} => Self::WalleyRedirect {}, api_models::payments::PayLaterData::WalleyRedirect {} => Self::WalleyRedirect {},
api_models::payments::PayLaterData::AlmaRedirect {} => Self::AlmaRedirect {}, api_models::payments::PayLaterData::AlmaRedirect {} => Self::AlmaRedirect {},

View File

@ -11951,17 +11951,19 @@
"klarna_redirect": { "klarna_redirect": {
"type": "object", "type": "object",
"description": "For KlarnaRedirect as PayLater Option", "description": "For KlarnaRedirect as PayLater Option",
"required": [
"billing_email",
"billing_country"
],
"properties": { "properties": {
"billing_email": { "billing_email": {
"type": "string", "type": "string",
"description": "The billing email" "description": "The billing email",
"nullable": true
}, },
"billing_country": { "billing_country": {
"$ref": "#/components/schemas/CountryAlpha2" "allOf": [
{
"$ref": "#/components/schemas/CountryAlpha2"
}
],
"nullable": true
} }
} }
} }
@ -12009,18 +12011,16 @@
"afterpay_clearpay_redirect": { "afterpay_clearpay_redirect": {
"type": "object", "type": "object",
"description": "For AfterpayClearpay redirect as PayLater Option", "description": "For AfterpayClearpay redirect as PayLater Option",
"required": [
"billing_email",
"billing_name"
],
"properties": { "properties": {
"billing_email": { "billing_email": {
"type": "string", "type": "string",
"description": "The billing email" "description": "The billing email",
"nullable": true
}, },
"billing_name": { "billing_name": {
"type": "string", "type": "string",
"description": "The billing name" "description": "The billing name",
"nullable": true
} }
} }
} }

View File

@ -50,6 +50,19 @@
} }
} }
}, },
"billing": {
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "US",
"first_name": "sundari"
},
"email": "narayan@example.com"
},
"client_secret": "{{client_secret}}" "client_secret": "{{client_secret}}"
} }
}, },

View File

@ -42,7 +42,8 @@
"first_name": "John", "first_name": "John",
"last_name": "Doe", "last_name": "Doe",
"country": "SE" "country": "SE"
} },
"email": "narayan@example.com"
}, },
"browser_info": { "browser_info": {
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",

View File

@ -13426,7 +13426,7 @@
"language": "json" "language": "json"
} }
}, },
"raw": "{\"payment_method\":\"pay_later\",\"payment_method_type\":\"klarna\",\"payment_experience\":\"redirect_to_url\",\"payment_method_data\":{\"pay_later\":{\"klarna_redirect\":{\"issuer_name\":\"stripe\",\"billing_email\":\"arjun.karthik@juspay.in\",\"billing_country\":\"US\"}}},\"client_secret\":\"{{client_secret}}\"}" "raw": "{\"payment_method\":\"pay_later\",\"payment_method_type\":\"klarna\",\"payment_experience\":\"redirect_to_url\",\"payment_method_data\":{\"pay_later\":{\"klarna_redirect\":{\"issuer_name\":\"stripe\",\"billing_email\":\"arjun.karthik@juspay.in\",\"billing_country\":\"US\"}}},\"billing\": {\"address\": {\"line1\": \"1467\",\"line2\": \"Harrison Street\",\"line3\": \"Harrison Street\",\"city\": \"San Fransico\",\"state\": \"California\",\"zip\": \"94122\",\"country\": \"US\",\"first_name\": \"sundari\"},\"email\": \"narayan@example.com\"},\"client_secret\":\"{{client_secret}}\"}"
}, },
"url": { "url": {
"raw": "{{baseUrl}}/payments/:id/confirm", "raw": "{{baseUrl}}/payments/:id/confirm",
@ -13677,7 +13677,7 @@
"language": "json" "language": "json"
} }
}, },
"raw": "{\"amount\":7000,\"currency\":\"USD\",\"confirm\":false,\"capture_method\":\"automatic\",\"capture_on\":\"2022-09-10T10:11:12Z\",\"customer_id\":\"StripeCustomer\",\"email\":\"abcdef123@gmail.com\",\"name\":\"John Doe\",\"phone\":\"999999999\",\"phone_country_code\":\"+65\",\"description\":\"Its my first payment request\",\"authentication_type\":\"three_ds\",\"return_url\":\"https://duck.com\",\"billing\":{\"address\":{\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"city\":\"San Fransico\",\"state\":\"California\",\"zip\":\"94122\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"country\":\"SE\"}},\"browser_info\":{\"user_agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36\",\"accept_header\":\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\",\"language\":\"nl-NL\",\"color_depth\":24,\"screen_height\":723,\"screen_width\":1536,\"time_zone\":0,\"java_enabled\":true,\"java_script_enabled\":true,\"ip_address\":\"127.0.0.1\"},\"shipping\":{\"address\":{\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"city\":\"San Fransico\",\"state\":\"California\",\"zip\":\"94122\",\"country\":\"SE\",\"first_name\":\"John\",\"last_name\":\"Doe\"}},\"statement_descriptor_name\":\"joseph\",\"statement_descriptor_suffix\":\"JS\",\"metadata\":{\"order_details\":{\"product_name\":\"Socks\",\"amount\":7000,\"quantity\":1}},\"routing\":{\"type\":\"single\",\"data\":\"stripe\"}}" "raw": "{\"amount\":7000,\"currency\":\"USD\",\"confirm\":false,\"capture_method\":\"automatic\",\"capture_on\":\"2022-09-10T10:11:12Z\",\"customer_id\":\"StripeCustomer\",\"email\":\"abcdef123@gmail.com\",\"name\":\"John Doe\",\"phone\":\"999999999\",\"phone_country_code\":\"+65\",\"description\":\"Its my first payment request\",\"authentication_type\":\"three_ds\",\"return_url\":\"https://duck.com\",\"billing\":{\"address\":{\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"city\":\"San Fransico\",\"state\":\"California\",\"zip\":\"94122\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"country\":\"SE\"},\"email\": \"narayan@example.com\"},\"browser_info\":{\"user_agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36\",\"accept_header\":\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\",\"language\":\"nl-NL\",\"color_depth\":24,\"screen_height\":723,\"screen_width\":1536,\"time_zone\":0,\"java_enabled\":true,\"java_script_enabled\":true,\"ip_address\":\"127.0.0.1\"},\"shipping\":{\"address\":{\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"city\":\"San Fransico\",\"state\":\"California\",\"zip\":\"94122\",\"country\":\"SE\",\"first_name\":\"John\",\"last_name\":\"Doe\"}},\"statement_descriptor_name\":\"joseph\",\"statement_descriptor_suffix\":\"JS\",\"metadata\":{\"order_details\":{\"product_name\":\"Socks\",\"amount\":7000,\"quantity\":1}},\"routing\":{\"type\":\"single\",\"data\":\"stripe\"}}"
}, },
"url": { "url": {
"raw": "{{baseUrl}}/payments", "raw": "{{baseUrl}}/payments",