diff --git a/crates/hyperswitch_domain_models/src/payment_address.rs b/crates/hyperswitch_domain_models/src/payment_address.rs index d4f2cf9f350f..548dd0c54166 100644 --- a/crates/hyperswitch_domain_models/src/payment_address.rs +++ b/crates/hyperswitch_domain_models/src/payment_address.rs @@ -53,6 +53,7 @@ impl PaymentAddress { } /// Unify the billing details from `payment_method_data.[payment_method_data].billing details`. + /// Here the fields passed in payment_method_data_billing takes precedence pub fn unify_with_payment_method_data_billing( self, payment_method_data_billing: Option
, @@ -72,6 +73,29 @@ impl PaymentAddress { } } + /// Unify the billing details from `payment_method_data.[payment_method_data].billing details`. + /// Here the `self` takes precedence + pub fn unify_with_payment_data_billing( + self, + other_payment_method_billing: Option, + ) -> Self { + let unified_payment_method_billing = self + .get_payment_method_billing() + .map(|payment_method_billing| { + payment_method_billing + .clone() + .unify_address(other_payment_method_billing.as_ref()) + }) + .or(other_payment_method_billing); + + Self { + shipping: self.shipping, + billing: self.billing, + unified_payment_method_billing, + payment_method_billing: self.payment_method_billing, + } + } + pub fn get_request_payment_method_billing(&self) -> Option<&Address> { self.payment_method_billing.as_ref() } diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 9182bf936068..24f5ffdca9a7 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -42,7 +42,7 @@ pub async fn construct_payment_router_data<'a, F, T>( payment_data: PaymentData