Skip to content

Commit

Permalink
feat(connector): [BOA/CYB] Make state,zip optional for Non US CA Txns
Browse files Browse the repository at this point in the history
  • Loading branch information
Deepanshu Bansal authored and Deepanshu Bansal committed Jun 7, 2024
1 parent d0fd709 commit ec66fcd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
36 changes: 29 additions & 7 deletions crates/router/src/connector/bankofamerica/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ pub struct BillTo {
last_name: Secret<String>,
address1: Secret<String>,
locality: Secret<String>,
administrative_area: Secret<String>,
postal_code: Secret<String>,
#[serde(skip_serializing_if = "Option::is_none")]
administrative_area: Option<Secret<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
postal_code: Option<Secret<String>>,
country: api_enums::CountryAlpha2,
email: pii::Email,
}
Expand Down Expand Up @@ -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,
})
}
Expand Down
36 changes: 29 additions & 7 deletions crates/router/src/connector/cybersource/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@ pub struct BillTo {
last_name: Secret<String>,
address1: Secret<String>,
locality: String,
administrative_area: Secret<String>,
postal_code: Secret<String>,
#[serde(skip_serializing_if = "Option::is_none")]
administrative_area: Option<Secret<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
postal_code: Option<Secret<String>>,
country: api_enums::CountryAlpha2,
email: pii::Email,
}
Expand Down Expand Up @@ -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,
})
}
Expand Down

0 comments on commit ec66fcd

Please sign in to comment.