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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(core): Trim whitespace from phone numbers and country code (#10754)
Vani Guptaaf933a372630
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 03e36a4eb9..34096e6be4 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -153,7 +153,8 @@ pub async fn create_or_update_address_for_payment_by_request(phone_number: address.phone.as_ref()- .and_then(|phone| phone.number.clone()),+ .and_then(|phone_details| phone_details.number.clone())+ .and_then(utils::trim_secret_string),email: address.as_ref()@@ -193,7 +194,8 @@ pub async fn create_or_update_address_for_payment_by_request(country_code: address.phone.as_ref()- .and_then(|value| value.country_code.clone()),+ .and_then(|phone_details| phone_details.country_code.clone())+ .and_then(utils::trim_string),updated_by: storage_scheme.to_string(),email: encryptable_address.email.map(|email| {let encryptable: Encryptable<masking::Secret<String, pii::EmailStrategy>> =@@ -361,7 +363,8 @@ pub async fn get_domain_address(phone_number: address.phone.as_ref()- .and_then(|phone| phone.number.clone()),+ .and_then(|phone_details| phone_details.number.clone())+ .and_then(utils::trim_secret_string),email: address.as_ref()@@ -380,7 +383,11 @@ pub async fn get_domain_address(.change_context(common_utils::errors::CryptoError::EncodingFailed)?;Ok(domain::Address {phone_number: encryptable_address.phone_number,- country_code: address.phone.as_ref().and_then(|a| a.country_code.clone()),+ country_code: address+ .phone+ .as_ref()+ .and_then(|phone_details| phone_details.country_code.clone())+ .and_then(utils::trim_string),merchant_id: merchant_id.to_owned(),address_id: generate_id(consts::ID_LENGTH, "add"),city: address_details.and_then(|address_details| address_details.city.clone()),@@ -1623,13 +1630,15 @@ pub fn get_customer_details_from_request(.customer.as_ref().and_then(|customer_details| customer_details.phone.clone())- .or(request.phone.clone());+ .or(request.phone.clone())+ .and_then(utils::trim_secret_string);let customer_phone_code = request.customer.as_ref().and_then(|customer_details| customer_details.phone_country_code.clone())- .or(request.phone_country_code.clone());+ .or(request.phone_country_code.clone())+ .and_then(utils::trim_string);let tax_registration_id = request.customerdiff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rsindex 1779897b8f..b0647a94df 100644--- a/crates/router/src/utils.rs+++ b/crates/router/src/utils.rs@@ -697,6 +697,18 @@ pub fn get_http_status_code_type(Ok(status_code_type.to_string())}+// Trims whitespace from a Secret string and returns None if empty+pub fn trim_secret_string(secret: masking::Secret<String>) -> Option<masking::Secret<String>> {+ let trimmed = secret.expose().trim().to_string();+ (!trimmed.is_empty()).then(|| masking::Secret::new(trimmed))+}++// Trims whitespace from a regular string and returns None if empty+pub fn trim_string(value: String) -> Option<String> {+ let trimmed = value.trim().to_string();+ (!trimmed.is_empty()).then_some(trimmed)+}+pub fn add_connector_http_status_code_metrics(option_status_code: Option<u16>) {if let Some(status_code) = option_status_code {let status_code_type = get_http_status_code_type(status_code).ok();