Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(cybersource): Add truncation logic for administrative area (#7343)

Debarati Ghatak6b52449c55d6
diff --git a/crates/hyperswitch_connectors/src/connectors/cybersource/transformers.rs b/crates/hyperswitch_connectors/src/connectors/cybersource/transformers.rs
index 4c65218c5a..054a4930db 100644
--- a/crates/hyperswitch_connectors/src/connectors/cybersource/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/cybersource/transformers.rs
@@ -1150,6 +1150,12 @@ impl
// })
// }
+fn truncate_string(state: &Secret<String>, max_len: usize) -> Secret<String> {
+ let exposed = state.clone().expose();
+ let truncated = exposed.get(..max_len).unwrap_or(&exposed);
+ Secret::new(truncated.to_string())
+}
+
fn build_bill_to(
address_details: Option<&hyperswitch_domain_models::address::Address>,
email: pii::Email,
@@ -1171,11 +1177,12 @@ fn build_bill_to(
last_name: addr.last_name.remove_new_line(),
address1: addr.line1.remove_new_line(),
locality: addr.city.remove_new_line(),
- administrative_area: addr
- .to_state_code_as_optional()
- .ok()
- .flatten()
- .remove_new_line(),
+ administrative_area: addr.to_state_code_as_optional().unwrap_or_else(|_| {
+ addr.state
+ .remove_new_line()
+ .as_ref()
+ .map(|state| truncate_string(state, 20)) //NOTE: Cybersource connector throws error if billing state exceeds 20 characters, so truncation is done to avoid payment failure
+ }),
postal_code: addr.zip.remove_new_line(),
country: addr.country,
email,
@@ -3873,7 +3880,20 @@ impl TryFrom<(&AddressDetails, &PhoneDetails)> for CybersourceRecipientInfo {
last_name: billing_address.get_last_name()?.to_owned(),
address1: billing_address.get_line1()?.to_owned(),
locality: billing_address.get_city()?.to_owned(),
- administrative_area: billing_address.get_state()?.to_owned(),
+ administrative_area: {
+ billing_address
+ .to_state_code_as_optional()
+ .unwrap_or_else(|_| {
+ billing_address
+ .state
+ .remove_new_line()
+ .as_ref()
+ .map(|state| truncate_string(state, 20)) //NOTE: Cybersource connector throws error if billing state exceeds 20 characters, so truncation is done to avoid payment failure
+ })
+ .ok_or_else(|| errors::ConnectorError::MissingRequiredField {
+ field_name: "billing_address.state",
+ })?
+ },
postal_code: billing_address.get_zip()?.to_owned(),
country: billing_address.get_country()?.to_owned(),
phone_number: phone_address.number.clone(),
diff --git a/crates/scheduler/src/utils.rs b/crates/scheduler/src/utils.rs
index 51938e6c14..0dbea173ea 100644
--- a/crates/scheduler/src/utils.rs
+++ b/crates/scheduler/src/utils.rs
@@ -288,7 +288,7 @@ pub fn add_histogram_metrics(
#[warn(clippy::option_map_unit_fn)]
if let Some((schedule_time, runner)) = task.schedule_time.as_ref().zip(task.runner.as_ref()) {
let pickup_schedule_delta = (*pickup_time - *schedule_time).as_seconds_f64();
- logger::error!("Time delta for scheduled tasks: {pickup_schedule_delta} seconds");
+ logger::info!("Time delta for scheduled tasks: {pickup_schedule_delta} seconds");
let runner_name = runner.clone();
metrics::CONSUMER_OPS.record(
pickup_schedule_delta,