mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 17:47:54 +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:
@ -1063,11 +1063,11 @@ pub enum PayLaterData {
|
||||
/// For KlarnaRedirect as PayLater Option
|
||||
KlarnaRedirect {
|
||||
/// The billing email
|
||||
#[schema(value_type = String)]
|
||||
billing_email: Email,
|
||||
#[schema(value_type = Option<String>)]
|
||||
billing_email: Option<Email>,
|
||||
// The billing country code
|
||||
#[schema(value_type = CountryAlpha2, example = "US")]
|
||||
billing_country: api_enums::CountryAlpha2,
|
||||
#[schema(value_type = Option<CountryAlpha2>, example = "US")]
|
||||
billing_country: Option<api_enums::CountryAlpha2>,
|
||||
},
|
||||
/// For Klarna Sdk as PayLater Option
|
||||
KlarnaSdk {
|
||||
@ -1079,11 +1079,11 @@ pub enum PayLaterData {
|
||||
/// For AfterpayClearpay redirect as PayLater Option
|
||||
AfterpayClearpayRedirect {
|
||||
/// The billing email
|
||||
#[schema(value_type = String)]
|
||||
billing_email: Email,
|
||||
#[schema(value_type = Option<String>)]
|
||||
billing_email: Option<Email>,
|
||||
/// The billing name
|
||||
#[schema(value_type = String)]
|
||||
billing_name: Secret<String>,
|
||||
#[schema(value_type = Option<String>)]
|
||||
billing_name: Option<Secret<String>>,
|
||||
},
|
||||
/// For PayBright Redirect as PayLater Option
|
||||
PayBrightRedirect {},
|
||||
@ -1102,13 +1102,13 @@ impl GetAddressFromPaymentMethodData for PayLaterData {
|
||||
billing_country,
|
||||
} => {
|
||||
let address_details = AddressDetails {
|
||||
country: Some(*billing_country),
|
||||
country: *billing_country,
|
||||
..AddressDetails::default()
|
||||
};
|
||||
|
||||
Some(Address {
|
||||
address: Some(address_details),
|
||||
email: Some(billing_email.clone()),
|
||||
email: billing_email.clone(),
|
||||
phone: None,
|
||||
})
|
||||
}
|
||||
@ -1117,13 +1117,13 @@ impl GetAddressFromPaymentMethodData for PayLaterData {
|
||||
billing_name,
|
||||
} => {
|
||||
let address_details = AddressDetails {
|
||||
first_name: Some(billing_name.clone()),
|
||||
first_name: billing_name.clone(),
|
||||
..AddressDetails::default()
|
||||
};
|
||||
|
||||
Some(Address {
|
||||
address: Some(address_details),
|
||||
email: Some(billing_email.clone()),
|
||||
email: billing_email.clone(),
|
||||
phone: None,
|
||||
})
|
||||
}
|
||||
@ -1444,7 +1444,7 @@ impl GetAddressFromPaymentMethodData for PaymentMethodData {
|
||||
Self::Card(card_data) => card_data.get_billing_address(),
|
||||
Self::CardRedirect(_) => None,
|
||||
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::BankDebit(_) => None,
|
||||
Self::BankTransfer(_) => None,
|
||||
@ -4871,8 +4871,8 @@ mod billing_from_payment_method_data {
|
||||
|
||||
let klarna_paylater_payment_method_data =
|
||||
PaymentMethodData::PayLater(PayLaterData::KlarnaRedirect {
|
||||
billing_email: test_email.clone(),
|
||||
billing_country: TEST_COUNTRY,
|
||||
billing_email: Some(test_email.clone()),
|
||||
billing_country: Some(TEST_COUNTRY),
|
||||
});
|
||||
|
||||
let billing_address = klarna_paylater_payment_method_data
|
||||
|
||||
@ -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 {},
|
||||
|
||||
@ -11951,18 +11951,20 @@
|
||||
"klarna_redirect": {
|
||||
"type": "object",
|
||||
"description": "For KlarnaRedirect as PayLater Option",
|
||||
"required": [
|
||||
"billing_email",
|
||||
"billing_country"
|
||||
],
|
||||
"properties": {
|
||||
"billing_email": {
|
||||
"type": "string",
|
||||
"description": "The billing email"
|
||||
"description": "The billing email",
|
||||
"nullable": true
|
||||
},
|
||||
"billing_country": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/CountryAlpha2"
|
||||
}
|
||||
],
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12009,18 +12011,16 @@
|
||||
"afterpay_clearpay_redirect": {
|
||||
"type": "object",
|
||||
"description": "For AfterpayClearpay redirect as PayLater Option",
|
||||
"required": [
|
||||
"billing_email",
|
||||
"billing_name"
|
||||
],
|
||||
"properties": {
|
||||
"billing_email": {
|
||||
"type": "string",
|
||||
"description": "The billing email"
|
||||
"description": "The billing email",
|
||||
"nullable": true
|
||||
},
|
||||
"billing_name": {
|
||||
"type": "string",
|
||||
"description": "The billing name"
|
||||
"description": "The billing name",
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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}}"
|
||||
}
|
||||
},
|
||||
|
||||
@ -42,7 +42,8 @@
|
||||
"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",
|
||||
|
||||
@ -13426,7 +13426,7 @@
|
||||
"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": {
|
||||
"raw": "{{baseUrl}}/payments/:id/confirm",
|
||||
@ -13677,7 +13677,7 @@
|
||||
"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": {
|
||||
"raw": "{{baseUrl}}/payments",
|
||||
|
||||
Reference in New Issue
Block a user