From 839af3242eca8f9e2a0c41ade9e0bd13da70e649 Mon Sep 17 00:00:00 2001 From: DEEPANSHU BANSAL <41580413+deepanshu-iiitu@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:53:00 +0530 Subject: [PATCH] feat(connector): [BOA/CYB] Make state,zip optional for Non US CA Txns (#4926) Co-authored-by: Deepanshu Bansal --- .../connector/bankofamerica/transformers.rs | 36 +++++++++++++++---- .../src/connector/cybersource/transformers.rs | 36 +++++++++++++++---- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs index dacacb5d27e0..671cc40e05cb 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -264,8 +264,10 @@ pub struct BillTo { last_name: Secret, address1: Secret, locality: Secret, - administrative_area: Secret, - postal_code: Secret, + #[serde(skip_serializing_if = "Option::is_none")] + administrative_area: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + postal_code: Option>, country: api_enums::CountryAlpha2, email: pii::Email, } @@ -448,17 +450,37 @@ fn build_bill_to( .address .as_ref() .ok_or_else(utils::missing_field_err("billing.address"))?; - let mut state = address.to_state_code()?.peek().clone(); - state.truncate(20); + + let country = address.get_country()?.to_owned(); let first_name = address.get_first_name()?; + + let (administrative_area, postal_code) = + if country == api_enums::CountryAlpha2::US || country == api_enums::CountryAlpha2::CA { + let mut state = address.to_state_code()?.peek().clone(); + state.truncate(20); + ( + Some(Secret::from(state)), + Some(address.get_zip()?.to_owned()), + ) + } else { + let zip = address.zip.clone(); + let mut_state = address.state.clone().map(|state| state.expose()); + match mut_state { + Some(mut state) => { + state.truncate(20); + (Some(Secret::from(state)), zip) + } + None => (None, zip), + } + }; Ok(BillTo { first_name: first_name.clone(), last_name: address.get_last_name().unwrap_or(first_name).clone(), address1: address.get_line1()?.to_owned(), locality: Secret::new(address.get_city()?.to_owned()), - administrative_area: Secret::from(state), - postal_code: address.get_zip()?.to_owned(), - country: address.get_country()?.to_owned(), + administrative_area, + postal_code, + country, email, }) } diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 0fb178430114..edc5c0cac1d9 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -482,8 +482,10 @@ pub struct BillTo { last_name: Secret, address1: Secret, locality: String, - administrative_area: Secret, - postal_code: Secret, + #[serde(skip_serializing_if = "Option::is_none")] + administrative_area: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + postal_code: Option>, country: api_enums::CountryAlpha2, email: pii::Email, } @@ -868,17 +870,37 @@ fn build_bill_to( .address .as_ref() .ok_or_else(utils::missing_field_err("billing.address"))?; - let mut state = address.to_state_code()?.peek().clone(); - state.truncate(20); + + let country = address.get_country()?.to_owned(); let first_name = address.get_first_name()?; + + let (administrative_area, postal_code) = + if country == api_enums::CountryAlpha2::US || country == api_enums::CountryAlpha2::CA { + let mut state = address.to_state_code()?.peek().clone(); + state.truncate(20); + ( + Some(Secret::from(state)), + Some(address.get_zip()?.to_owned()), + ) + } else { + let zip = address.zip.clone(); + let mut_state = address.state.clone().map(|state| state.expose()); + match mut_state { + Some(mut state) => { + state.truncate(20); + (Some(Secret::from(state)), zip) + } + None => (None, zip), + } + }; Ok(BillTo { first_name: first_name.clone(), last_name: address.get_last_name().unwrap_or(first_name).clone(), address1: address.get_line1()?.to_owned(), locality: address.get_city()?.to_owned(), - administrative_area: Secret::from(state), - postal_code: address.get_zip()?.to_owned(), - country: address.get_country()?.to_owned(), + administrative_area, + postal_code, + country, email, }) }