Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(paylater): use payment_method_data.billing fields instead of payment_method_data (#4333)
Swangi Kumarib878677f1572
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex b39355d2c9..819e67a73b 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -1063,11 +1063,11 @@ pub enum PayLaterData {/// For KlarnaRedirect as PayLater OptionKlarnaRedirect {/// 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 OptionKlarnaSdk {@@ -1079,11 +1079,11 @@ pub enum PayLaterData {/// For AfterpayClearpay redirect as PayLater OptionAfterpayClearpayRedirect {/// 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 OptionPayBrightRedirect {},@@ -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_datadiff --git a/crates/router/src/connector/multisafepay/transformers.rs b/crates/router/src/connector/multisafepay/transformers.rsindex 926781e39e..850bd058e4 100644--- a/crates/router/src/connector/multisafepay/transformers.rs+++ b/crates/router/src/connector/multisafepay/transformers.rs@@ -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 {}diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rsindex 46c47a51f3..6932f6b749 100644--- a/crates/router/src/connector/stripe/transformers.rs+++ b/crates/router/src/connector/stripe/transformers.rs@@ -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,diff --git a/crates/router/src/types/domain/payments.rs b/crates/router/src/types/domain/payments.rsindex fe34f2092b..58f2fa98ee 100644--- a/crates/router/src/types/domain/payments.rs+++ b/crates/router/src/types/domain/payments.rs@@ -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 {},diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.jsonindex d278c50a38..586fd1c111 100644--- a/openapi/openapi_spec.json+++ b/openapi/openapi_spec.json@@ -11951,17 +11951,19 @@"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": {- "$ref": "#/components/schemas/CountryAlpha2"+ "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}}}diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario12-BNPL-klarna/Payments - Confirm/request.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario12-BNPL-klarna/Payments - Confirm/request.jsonindex 9b19b521ca..bd39f2f528 100644--- a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario12-BNPL-klarna/Payments - Confirm/request.json+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario12-BNPL-klarna/Payments - Confirm/request.json@@ -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": "[email protected]"+ },"client_secret": "{{client_secret}}"}},diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario13-BNPL-afterpay/Payments - Create/request.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario13-BNPL-afterpay/Payments - Create/request.jsonindex dcbeac44d9..273ed5ee3c 100644--- a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario13-BNPL-afterpay/Payments - Create/request.json+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario13-BNPL-afterpay/Payments - Create/request.json@@ -42,7 +42,8 @@"first_name": "John","last_name": "Doe","country": "SE"- }+ },+ "email": "[email protected]"},"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",diff --git a/postman/collection-json/stripe.postman_collection.json b/postman/collection-json/stripe.postman_collection.jsonindex 2a18984e3f..c981df1a4c 100644--- a/postman/collection-json/stripe.postman_collection.json+++ b/postman/collection-json/stripe.postman_collection.json@@ -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\":\"[email protected]\",\"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\":\"[email protected]\",\"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\": \"[email protected]\"},\"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\":\"[email protected]\",\"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\":\"[email protected]\",\"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\": \"[email protected]\"},\"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",