From 25455f09bdb40f41299221817ed6281c598bf233 Mon Sep 17 00:00:00 2001 From: Mrudul Vajpayee Date: Tue, 12 Nov 2024 22:02:24 +0530 Subject: [PATCH] use shipping address --- .../src/connectors/nexixpay/transformers.rs | 88 +++++++++++++++++-- crates/hyperswitch_connectors/src/utils.rs | 7 ++ 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs index 6458f760f2a8..4a54488d8b31 100644 --- a/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs @@ -158,13 +158,13 @@ pub struct Order { #[serde(rename_all = "camelCase")] pub struct CustomerInfo { card_holder_name: Secret, - billing_address: Address, - shipping_address: Option
, + billing_address: BillingAddress, + shipping_address: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct Address { +pub struct BillingAddress { name: Secret, street: Secret, city: String, @@ -172,6 +172,16 @@ pub struct Address { country: enums::CountryAlpha2, } +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ShippingAddress { + name: Option>, + street: Option>, + city: Option, + post_code: Option>, + country: Option, +} + #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct NexixpayCard { @@ -435,17 +445,47 @@ impl TryFrom<&NexixpayRouterData<&PaymentsAuthorizeRouterData>> for NexixpayPaym fn try_from( item: &NexixpayRouterData<&PaymentsAuthorizeRouterData>, ) -> Result { - let billing_address = Address { + let billing_address_street = format!( + "{}, {}", + item.router_data.get_billing_line1()?.expose(), + item.router_data.get_billing_line2()?.expose() + ); + + let billing_address = BillingAddress { name: item.router_data.get_billing_full_name()?, - street: item.router_data.get_billing_line1()?, + street: Secret::new(billing_address_street), city: item.router_data.get_billing_city()?, post_code: item.router_data.get_billing_zip()?, country: item.router_data.get_billing_country()?, }; + let shipping_address_street = match ( + item.router_data.get_optional_shipping_line1(), + item.router_data.get_optional_shipping_line2(), + ) { + (Some(line1), Some(line2)) => Some(Secret::new(format!( + "{}, {}", + line1.expose(), + line2.expose() + ))), + (Some(line1), None) => Some(Secret::new(line1.expose())), + (None, Some(line2)) => Some(Secret::new(line2.expose())), + (None, None) => None, + }; + + let shipping_address = item + .router_data + .get_optional_billing() + .map(|_| ShippingAddress { + name: item.router_data.get_optional_shipping_full_name(), + street: shipping_address_street, + city: item.router_data.get_optional_shipping_city(), + post_code: item.router_data.get_optional_shipping_zip(), + country: item.router_data.get_optional_shipping_country(), + }); let customer_info = CustomerInfo { card_holder_name: item.router_data.get_billing_full_name()?, billing_address: billing_address.clone(), - shipping_address: Some(billing_address), + shipping_address: shipping_address.clone(), }; let order = Order { order_id: item.router_data.connector_request_reference_id.clone(), @@ -944,17 +984,47 @@ impl TryFrom<&NexixpayRouterData<&PaymentsCompleteAuthorizeRouterData>> let order_id = item.router_data.connector_request_reference_id.clone(); let amount = item.amount.clone(); - let billing_address = Address { + let billing_address_street = format!( + "{}, {}", + item.router_data.get_billing_line1()?.expose(), + item.router_data.get_billing_line2()?.expose() + ); + + let billing_address = BillingAddress { name: item.router_data.get_billing_full_name()?, - street: item.router_data.get_billing_line1()?, + street: Secret::new(billing_address_street), city: item.router_data.get_billing_city()?, post_code: item.router_data.get_billing_zip()?, country: item.router_data.get_billing_country()?, }; + let shipping_address_street = match ( + item.router_data.get_optional_shipping_line1(), + item.router_data.get_optional_shipping_line2(), + ) { + (Some(line1), Some(line2)) => Some(Secret::new(format!( + "{}, {}", + line1.expose(), + line2.expose() + ))), + (Some(line1), None) => Some(Secret::new(line1.expose())), + (None, Some(line2)) => Some(Secret::new(line2.expose())), + (None, None) => None, + }; + + let shipping_address = item + .router_data + .get_optional_billing() + .map(|_| ShippingAddress { + name: item.router_data.get_optional_shipping_full_name(), + street: shipping_address_street, + city: item.router_data.get_optional_shipping_city(), + post_code: item.router_data.get_optional_shipping_zip(), + country: item.router_data.get_optional_shipping_country(), + }); let customer_info = CustomerInfo { card_holder_name: item.router_data.get_billing_full_name()?, billing_address: billing_address.clone(), - shipping_address: Some(billing_address), + shipping_address: shipping_address.clone(), }; let order_data = Order { order_id, diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs index 83d54823cae5..ee83b0fe9339 100644 --- a/crates/hyperswitch_connectors/src/utils.rs +++ b/crates/hyperswitch_connectors/src/utils.rs @@ -299,6 +299,7 @@ pub trait RouterData { fn get_optional_shipping_state(&self) -> Option>; fn get_optional_shipping_first_name(&self) -> Option>; fn get_optional_shipping_last_name(&self) -> Option>; + fn get_optional_shipping_full_name(&self) -> Option>; fn get_optional_shipping_phone_number(&self) -> Option>; fn get_optional_shipping_email(&self) -> Option; @@ -368,6 +369,12 @@ impl RouterData }) } + fn get_optional_shipping_full_name(&self) -> Option> { + self.get_optional_shipping() + .and_then(|shipping_details| shipping_details.address.as_ref()) + .and_then(|shipping_address| shipping_address.get_optional_full_name()) + } + fn get_optional_shipping_line1(&self) -> Option> { self.address.get_shipping().and_then(|shipping_address| { shipping_address