mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	fix(cybersource): Add truncation logic for administrative area (#7343)
This commit is contained in:
		| @ -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( | fn build_bill_to( | ||||||
|     address_details: Option<&hyperswitch_domain_models::address::Address>, |     address_details: Option<&hyperswitch_domain_models::address::Address>, | ||||||
|     email: pii::Email, |     email: pii::Email, | ||||||
| @ -1171,11 +1177,12 @@ fn build_bill_to( | |||||||
|                 last_name: addr.last_name.remove_new_line(), |                 last_name: addr.last_name.remove_new_line(), | ||||||
|                 address1: addr.line1.remove_new_line(), |                 address1: addr.line1.remove_new_line(), | ||||||
|                 locality: addr.city.remove_new_line(), |                 locality: addr.city.remove_new_line(), | ||||||
|                 administrative_area: addr |                 administrative_area: addr.to_state_code_as_optional().unwrap_or_else(|_| { | ||||||
|                     .to_state_code_as_optional() |                     addr.state | ||||||
|                     .ok() |                         .remove_new_line() | ||||||
|                     .flatten() |                         .as_ref() | ||||||
|                     .remove_new_line(), |                         .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(), |                 postal_code: addr.zip.remove_new_line(), | ||||||
|                 country: addr.country, |                 country: addr.country, | ||||||
|                 email, |                 email, | ||||||
| @ -3873,7 +3880,20 @@ impl TryFrom<(&AddressDetails, &PhoneDetails)> for CybersourceRecipientInfo { | |||||||
|             last_name: billing_address.get_last_name()?.to_owned(), |             last_name: billing_address.get_last_name()?.to_owned(), | ||||||
|             address1: billing_address.get_line1()?.to_owned(), |             address1: billing_address.get_line1()?.to_owned(), | ||||||
|             locality: billing_address.get_city()?.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(), |             postal_code: billing_address.get_zip()?.to_owned(), | ||||||
|             country: billing_address.get_country()?.to_owned(), |             country: billing_address.get_country()?.to_owned(), | ||||||
|             phone_number: phone_address.number.clone(), |             phone_number: phone_address.number.clone(), | ||||||
|  | |||||||
| @ -288,7 +288,7 @@ pub fn add_histogram_metrics( | |||||||
|     #[warn(clippy::option_map_unit_fn)] |     #[warn(clippy::option_map_unit_fn)] | ||||||
|     if let Some((schedule_time, runner)) = task.schedule_time.as_ref().zip(task.runner.as_ref()) { |     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(); |         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(); |         let runner_name = runner.clone(); | ||||||
|         metrics::CONSUMER_OPS.record( |         metrics::CONSUMER_OPS.record( | ||||||
|             pickup_schedule_delta, |             pickup_schedule_delta, | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Debarati Ghatak
					Debarati Ghatak