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
fix(api_response): ghost payment_method_billing being populated in the response (#4085)
Narayan Bhat3d4baa230cdf
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 1642691610..4eb05fdbaf 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -2123,6 +2123,7 @@ pub mod payment_address {pub struct PaymentAddress {shipping: Option<api::Address>,billing: Option<api::Address>,+ unified_payment_method_billing: Option<api::Address>,payment_method_billing: Option<api::Address>,}@@ -2132,20 +2133,26 @@ pub mod payment_address {billing: Option<api::Address>,payment_method_billing: Option<api::Address>,) -> Self {- let payment_method_billing = match (payment_method_billing, billing.clone()) {- (Some(payment_method_billing), Some(order_billing)) => Some(api::Address {- address: payment_method_billing.address.or(order_billing.address),- phone: payment_method_billing.phone.or(order_billing.phone),- email: payment_method_billing.email.or(order_billing.email),- }),- (Some(payment_method_billing), None) => Some(payment_method_billing),- (None, Some(order_billing)) => Some(order_billing),- (None, None) => None,- };+ // Merge the billing details field from both `payment.billing` and `payment.payment_method_data.billing`+ // The unified payment_method_billing will be used as billing address and passed to the connector module+ // This unification is required in order to provide backwards compatibility+ // so that if `payment.billing` is passed it should be sent to the connector module+ let unified_payment_method_billing =+ match (payment_method_billing.clone(), billing.clone()) {+ (Some(payment_method_billing), Some(order_billing)) => Some(api::Address {+ address: payment_method_billing.address.or(order_billing.address),+ phone: payment_method_billing.phone.or(order_billing.phone),+ email: payment_method_billing.email.or(order_billing.email),+ }),+ (Some(payment_method_billing), None) => Some(payment_method_billing),+ (None, Some(order_billing)) => Some(order_billing),+ (None, None) => None,+ };Self {shipping,billing,+ unified_payment_method_billing,payment_method_billing,}}@@ -2155,6 +2162,10 @@ pub mod payment_address {}pub fn get_payment_method_billing(&self) -> Option<&api::Address> {+ self.unified_payment_method_billing.as_ref()+ }++ pub fn get_request_payment_method_billing(&self) -> Option<&api::Address> {self.payment_method_billing.as_ref()}diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex 315ddd3b39..73d780c096 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -467,7 +467,10 @@ wherelet payment_method_data_response = payment_method_data.map(|payment_method_data| {api_models::payments::PaymentMethodDataResponseWithBilling {payment_method_data,- billing: payment_data.address.get_payment_method_billing().cloned(),+ billing: payment_data+ .address+ .get_request_payment_method_billing()+ .cloned(),}});diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rsindex 006c4503ce..e9082299ab 100644--- a/crates/router/src/types/transformers.rs+++ b/crates/router/src/types/transformers.rs@@ -583,7 +583,7 @@ impl<'a> ForeignFrom<&'a api_types::ConfigUpdate> for storage::ConfigUpdate {impl<'a> From<&'a domain::Address> for api_types::Address {fn from(address: &domain::Address) -> Self {- // If all the fields of address are none, then+ // If all the fields of address are none, then pass the address as Nonelet address_details = if address.city.is_none()&& address.line1.is_none()&& address.line2.is_none()@@ -608,12 +608,19 @@ impl<'a> From<&'a domain::Address> for api_types::Address {})};- Self {- address: address_details,- phone: Some(api_types::PhoneDetails {+ // If all the fields of phone are none, then pass the phone as None+ let phone_details = if address.phone_number.is_none() && address.country_code.is_none() {+ None+ } else {+ Some(api_types::PhoneDetails {number: address.phone_number.clone().map(Encryptable::into_inner),country_code: address.country_code.clone(),- }),+ })+ };++ Self {+ address: address_details,+ phone: phone_details,email: address.email.clone().map(pii::Email::from),}}diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario29-Create payment with payment method billing/Payments - Create/event.test.js b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario29-Create payment with payment method billing/Payments - Create/event.test.jsindex d18cc474f8..cad157942d 100644--- a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario29-Create payment with payment method billing/Payments - Create/event.test.js+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario29-Create payment with payment method billing/Payments - Create/event.test.js@@ -87,3 +87,11 @@ pm.test(.true;},);++// Response body should not have "payment.billing"+pm.test(+ "[POST]::/payments - Content check if 'payment.billing' is null",+ function () {+ pm.expect(jsonData?.billing).to.be.null+ },+);diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario29-Create payment with payment method billing/Payments - Create/request.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario29-Create payment with payment method billing/Payments - Create/request.jsonindex 7a755ed4e6..83e3a58da2 100644--- a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario29-Create payment with payment method billing/Payments - Create/request.json+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario29-Create payment with payment method billing/Payments - Create/request.json@@ -60,19 +60,6 @@"email": "[email protected]"}},- "billing": {- "address": {- "line1": "1467",- "line2": "Harrison Street",- "line3": "Harrison Street",- "city": "San Fransico",- "state": "California",- "zip": "94122",- "country": "US",- "first_name": "sundari",- "last_name": "sundari"- }- },"shipping": {"address": {"line1": "1467",diff --git a/postman/collection-dir/stripe/QuickStart/Payments - Create/event.test.js b/postman/collection-dir/stripe/QuickStart/Payments - Create/event.test.jsindex 3d51aaa49a..93d36d988d 100644--- a/postman/collection-dir/stripe/QuickStart/Payments - Create/event.test.js+++ b/postman/collection-dir/stripe/QuickStart/Payments - Create/event.test.js@@ -97,3 +97,11 @@ pm.test(.true;},);++// Response body should not have "payment_method_data.billing"+pm.test(+ "[POST]::/payments - Content check if 'payment_method_data.billing' should be null",+ function () {+ pm.expect(jsonData?.payment_method_data?.billing).to.be.null;+ },+);diff --git a/postman/collection-json/stripe.postman_collection.json b/postman/collection-json/stripe.postman_collection.jsonindex c3d6371fd7..46829047bd 100644--- a/postman/collection-json/stripe.postman_collection.json+++ b/postman/collection-json/stripe.postman_collection.json@@ -2451,6 +2451,14 @@" .true;"," },",");",+ "",+ "// Response body should not have \"payment_method_data.billing\"",+ "pm.test(",+ " \"[POST]::/payments - Content check if 'payment_method_data.billing' should be null\",",+ " function () {",+ " pm.expect(jsonData?.payment_method_data?.billing).to.be.null;",+ " },",+ ");",""],"type": "text/javascript"@@ -20865,6 +20873,14 @@" .true;"," },",");",+ "",+ "// Response body should not have \"payment.billing\"",+ "pm.test(",+ " \"[POST]::/payments - Content check if 'payment.billing' is null\",",+ " function () {",+ " pm.expect(jsonData?.billing).to.be.null",+ " },",+ ");",""],"type": "text/javascript"@@ -20890,7 +20906,7 @@"language": "json"}},- "raw": "{\"amount\":6540,\"currency\":\"USD\",\"confirm\":true,\"business_country\":\"US\",\"business_label\":\"default\",\"capture_method\":\"automatic\",\"capture_on\":\"2022-09-10T10:11:12Z\",\"amount_to_capture\":6540,\"customer_id\":\"bernard123\",\"email\":\"[email protected]\",\"name\":\"John Doe\",\"phone\":\"999999999\",\"phone_country_code\":\"+65\",\"description\":\"Its my first payment request\",\"authentication_type\":\"no_three_ds\",\"return_url\":\"https://duck.com\",\"setup_future_usage\":\"on_session\",\"payment_method\":\"card\",\"payment_method_type\":\"debit\",\"payment_method_data\":{\"card\":{\"card_number\":\"4242424242424242\",\"card_exp_month\":\"01\",\"card_exp_year\":\"26\",\"card_holder_name\":\"joseph Doe\",\"card_cvc\":\"123\"},\"billing\":{\"address\":{\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrisoff Street\",\"city\":\"San Fransico\",\"state\":\"California\",\"zip\":\"94122\",\"country\":\"US\",\"first_name\":\"Narayan\",\"last_name\":\"Doe\"},\"email\":\"[email protected]\"}},\"billing\":{\"address\":{\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"city\":\"San Fransico\",\"state\":\"California\",\"zip\":\"94122\",\"country\":\"US\",\"first_name\":\"sundari\",\"last_name\":\"sundari\"}},\"shipping\":{\"address\":{\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"city\":\"San Fransico\",\"state\":\"California\",\"zip\":\"94122\",\"country\":\"US\",\"first_name\":\"sundari\",\"last_name\":\"sundari\"}},\"statement_descriptor_name\":\"joseph\",\"statement_descriptor_suffix\":\"JS\",\"metadata\":{\"udf1\":\"value1\",\"new_customer\":\"true\",\"login_date\":\"2019-09-10T10:11:12Z\"},\"routing\":{\"type\":\"single\",\"data\":\"stripe\"}}"+ "raw": "{\"amount\":6540,\"currency\":\"USD\",\"confirm\":true,\"business_country\":\"US\",\"business_label\":\"default\",\"capture_method\":\"automatic\",\"capture_on\":\"2022-09-10T10:11:12Z\",\"amount_to_capture\":6540,\"customer_id\":\"bernard123\",\"email\":\"[email protected]\",\"name\":\"John Doe\",\"phone\":\"999999999\",\"phone_country_code\":\"+65\",\"description\":\"Its my first payment request\",\"authentication_type\":\"no_three_ds\",\"return_url\":\"https://duck.com\",\"setup_future_usage\":\"on_session\",\"payment_method\":\"card\",\"payment_method_type\":\"debit\",\"payment_method_data\":{\"card\":{\"card_number\":\"4242424242424242\",\"card_exp_month\":\"01\",\"card_exp_year\":\"26\",\"card_holder_name\":\"joseph Doe\",\"card_cvc\":\"123\"},\"billing\":{\"address\":{\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrisoff Street\",\"city\":\"San Fransico\",\"state\":\"California\",\"zip\":\"94122\",\"country\":\"US\",\"first_name\":\"Narayan\",\"last_name\":\"Doe\"},\"email\":\"[email protected]\"}},\"shipping\":{\"address\":{\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"city\":\"San Fransico\",\"state\":\"California\",\"zip\":\"94122\",\"country\":\"US\",\"first_name\":\"sundari\",\"last_name\":\"sundari\"}},\"statement_descriptor_name\":\"joseph\",\"statement_descriptor_suffix\":\"JS\",\"metadata\":{\"udf1\":\"value1\",\"new_customer\":\"true\",\"login_date\":\"2019-09-10T10:11:12Z\"},\"routing\":{\"type\":\"single\",\"data\":\"stripe\"}}"},"url": {"raw": "{{baseUrl}}/payments",