Skip to content

Commit 839af32

Browse files
deepanshu-iiituDeepanshu Bansal
and
Deepanshu Bansal
authored
feat(connector): [BOA/CYB] Make state,zip optional for Non US CA Txns (#4926)
Co-authored-by: Deepanshu Bansal <[email protected]>
1 parent c577b89 commit 839af32

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
lines changed

crates/router/src/connector/bankofamerica/transformers.rs

+29-7
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,10 @@ pub struct BillTo {
264264
last_name: Secret<String>,
265265
address1: Secret<String>,
266266
locality: Secret<String>,
267-
administrative_area: Secret<String>,
268-
postal_code: Secret<String>,
267+
#[serde(skip_serializing_if = "Option::is_none")]
268+
administrative_area: Option<Secret<String>>,
269+
#[serde(skip_serializing_if = "Option::is_none")]
270+
postal_code: Option<Secret<String>>,
269271
country: api_enums::CountryAlpha2,
270272
email: pii::Email,
271273
}
@@ -448,17 +450,37 @@ fn build_bill_to(
448450
.address
449451
.as_ref()
450452
.ok_or_else(utils::missing_field_err("billing.address"))?;
451-
let mut state = address.to_state_code()?.peek().clone();
452-
state.truncate(20);
453+
454+
let country = address.get_country()?.to_owned();
453455
let first_name = address.get_first_name()?;
456+
457+
let (administrative_area, postal_code) =
458+
if country == api_enums::CountryAlpha2::US || country == api_enums::CountryAlpha2::CA {
459+
let mut state = address.to_state_code()?.peek().clone();
460+
state.truncate(20);
461+
(
462+
Some(Secret::from(state)),
463+
Some(address.get_zip()?.to_owned()),
464+
)
465+
} else {
466+
let zip = address.zip.clone();
467+
let mut_state = address.state.clone().map(|state| state.expose());
468+
match mut_state {
469+
Some(mut state) => {
470+
state.truncate(20);
471+
(Some(Secret::from(state)), zip)
472+
}
473+
None => (None, zip),
474+
}
475+
};
454476
Ok(BillTo {
455477
first_name: first_name.clone(),
456478
last_name: address.get_last_name().unwrap_or(first_name).clone(),
457479
address1: address.get_line1()?.to_owned(),
458480
locality: Secret::new(address.get_city()?.to_owned()),
459-
administrative_area: Secret::from(state),
460-
postal_code: address.get_zip()?.to_owned(),
461-
country: address.get_country()?.to_owned(),
481+
administrative_area,
482+
postal_code,
483+
country,
462484
email,
463485
})
464486
}

crates/router/src/connector/cybersource/transformers.rs

+29-7
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,10 @@ pub struct BillTo {
482482
last_name: Secret<String>,
483483
address1: Secret<String>,
484484
locality: String,
485-
administrative_area: Secret<String>,
486-
postal_code: Secret<String>,
485+
#[serde(skip_serializing_if = "Option::is_none")]
486+
administrative_area: Option<Secret<String>>,
487+
#[serde(skip_serializing_if = "Option::is_none")]
488+
postal_code: Option<Secret<String>>,
487489
country: api_enums::CountryAlpha2,
488490
email: pii::Email,
489491
}
@@ -868,17 +870,37 @@ fn build_bill_to(
868870
.address
869871
.as_ref()
870872
.ok_or_else(utils::missing_field_err("billing.address"))?;
871-
let mut state = address.to_state_code()?.peek().clone();
872-
state.truncate(20);
873+
874+
let country = address.get_country()?.to_owned();
873875
let first_name = address.get_first_name()?;
876+
877+
let (administrative_area, postal_code) =
878+
if country == api_enums::CountryAlpha2::US || country == api_enums::CountryAlpha2::CA {
879+
let mut state = address.to_state_code()?.peek().clone();
880+
state.truncate(20);
881+
(
882+
Some(Secret::from(state)),
883+
Some(address.get_zip()?.to_owned()),
884+
)
885+
} else {
886+
let zip = address.zip.clone();
887+
let mut_state = address.state.clone().map(|state| state.expose());
888+
match mut_state {
889+
Some(mut state) => {
890+
state.truncate(20);
891+
(Some(Secret::from(state)), zip)
892+
}
893+
None => (None, zip),
894+
}
895+
};
874896
Ok(BillTo {
875897
first_name: first_name.clone(),
876898
last_name: address.get_last_name().unwrap_or(first_name).clone(),
877899
address1: address.get_line1()?.to_owned(),
878900
locality: address.get_city()?.to_owned(),
879-
administrative_area: Secret::from(state),
880-
postal_code: address.get_zip()?.to_owned(),
881-
country: address.get_country()?.to_owned(),
901+
administrative_area,
902+
postal_code,
903+
country,
882904
email,
883905
})
884906
}

0 commit comments

Comments
 (0)