From 1b7cde2d1b687e9c5ca8e3c02eef5c7d3fb7da8f Mon Sep 17 00:00:00 2001 From: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com> Date: Tue, 16 Apr 2024 11:57:53 +0530 Subject: [PATCH] fix(address): use first_name if last_name is not passed (#4360) --- .../connector/bankofamerica/transformers.rs | 5 +-- .../src/connector/bluesnap/transformers.rs | 5 +-- .../src/connector/cybersource/transformers.rs | 5 +-- .../src/connector/forte/transformers.rs | 5 +-- .../connector/multisafepay/transformers.rs | 12 ++++--- .../router/src/connector/nmi/transformers.rs | 8 +++-- .../src/connector/nuvei/transformers.rs | 32 ++++++++++++------- crates/router/src/connector/utils.rs | 7 +++- .../router/src/connector/volt/transformers.rs | 5 +-- 9 files changed, 55 insertions(+), 29 deletions(-) diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs index 974d155c94..d8a5f8af73 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -424,9 +424,10 @@ fn build_bill_to( .ok_or_else(utils::missing_field_err("billing.address"))?; let mut state = address.to_state_code()?.peek().clone(); state.truncate(20); + let first_name = address.get_first_name()?; Ok(BillTo { - first_name: address.get_first_name()?.to_owned(), - last_name: address.get_last_name()?.to_owned(), + 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), diff --git a/crates/router/src/connector/bluesnap/transformers.rs b/crates/router/src/connector/bluesnap/transformers.rs index e92ba86477..2a572a2231 100644 --- a/crates/router/src/connector/bluesnap/transformers.rs +++ b/crates/router/src/connector/bluesnap/transformers.rs @@ -1133,9 +1133,10 @@ fn get_card_holder_info( address: &api::AddressDetails, email: Email, ) -> CustomResult, errors::ConnectorError> { + let first_name = address.get_first_name()?; Ok(Some(BluesnapCardHolderInfo { - first_name: address.get_first_name()?.clone(), - last_name: address.get_last_name()?.clone(), + first_name: first_name.clone(), + last_name: address.get_last_name().unwrap_or(first_name).clone(), email, })) } diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 346d212764..14e2ba76c0 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -784,9 +784,10 @@ fn build_bill_to( .ok_or_else(utils::missing_field_err("billing.address"))?; let mut state = address.to_state_code()?.peek().clone(); state.truncate(20); + let first_name = address.get_first_name()?; Ok(BillTo { - first_name: address.get_first_name()?.to_owned(), - last_name: address.get_last_name()?.to_owned(), + 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), diff --git a/crates/router/src/connector/forte/transformers.rs b/crates/router/src/connector/forte/transformers.rs index aef5ed32cf..861801d129 100644 --- a/crates/router/src/connector/forte/transformers.rs +++ b/crates/router/src/connector/forte/transformers.rs @@ -88,9 +88,10 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for FortePaymentsRequest { expire_year: ccard.card_exp_year.clone(), card_verification_value: ccard.card_cvc.clone(), }; + let first_name = address.get_first_name()?; let billing_address = BillingAddress { - first_name: address.get_first_name()?.to_owned(), - last_name: address.get_last_name()?.to_owned(), + first_name: first_name.clone(), + last_name: address.get_last_name().unwrap_or(first_name).clone(), }; let authorization_amount = utils::to_currency_base_unit_asf64(item.request.amount, item.request.currency)?; diff --git a/crates/router/src/connector/multisafepay/transformers.rs b/crates/router/src/connector/multisafepay/transformers.rs index 39433c38aa..926781e39e 100644 --- a/crates/router/src/connector/multisafepay/transformers.rs +++ b/crates/router/src/connector/multisafepay/transformers.rs @@ -411,9 +411,13 @@ impl TryFrom<&MultisafepayRouterData<&types::PaymentsAuthorizeRouterData>> .address .as_ref() .ok_or_else(utils::missing_field_err("billing.address"))?; + let first_name = billing_address.get_first_name()?; let delivery = DeliveryObject { - first_name: billing_address.get_first_name()?.to_owned(), - last_name: billing_address.get_last_name()?.to_owned(), + first_name: first_name.clone(), + last_name: billing_address + .get_last_name() + .unwrap_or(first_name) + .clone(), address1: billing_address.get_line1()?.to_owned(), house_number: billing_address.get_line2()?.to_owned(), zip_code: billing_address.get_zip()?.to_owned(), @@ -917,7 +921,7 @@ impl From for Option { | 1031 // IncorrectItemPrice | 1035 // InvalidSignatureRefund | 1036 // InvalidIdealIssuerID - | 5001 // CartDataNotValidated + | 5001 // CartDataNotValidated | 1032 // InvalidAPIKey => { Some(AttemptStatus::AuthenticationFailed) @@ -925,7 +929,7 @@ impl From for Option { 1034 // CannotRefundTransaction | 1022 // CannotInitiateTransaction - | 1024 //TransactionDeclined + | 1024 //TransactionDeclined => Some(AttemptStatus::Failure), 1017 // InsufficientFunds => Some(AttemptStatus::AuthorizationFailed), diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index 0ff6a67711..27e0e5c2a4 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -116,14 +116,18 @@ impl TryFrom<&types::PaymentsPreProcessingRouterData> for NmiVaultRequest { let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?; let (ccnumber, ccexp, cvv) = get_card_details(item.request.payment_method_data.clone())?; let billing_details = item.get_billing_address()?; + let first_name = billing_details.get_first_name()?; Ok(Self { security_key: auth_type.api_key, ccnumber, ccexp, cvv, - first_name: billing_details.get_first_name()?.to_owned(), - last_name: billing_details.get_last_name()?.to_owned(), + first_name: first_name.clone(), + last_name: billing_details + .get_last_name() + .unwrap_or(first_name) + .clone(), address1: billing_details.line1.clone(), address2: billing_details.line2.clone(), city: billing_details.city.clone(), diff --git a/crates/router/src/connector/nuvei/transformers.rs b/crates/router/src/connector/nuvei/transformers.rs index f84b34f23a..793ec2d87d 100644 --- a/crates/router/src/connector/nuvei/transformers.rs +++ b/crates/router/src/connector/nuvei/transformers.rs @@ -663,10 +663,11 @@ impl ), (AlternativePaymentMethodType::Sofort, _) | (AlternativePaymentMethodType::Eps, _) => { let address = item.get_billing_address()?; + let first_name = address.get_first_name()?; ( Some(BillingAddress { - first_name: Some(address.get_first_name()?.clone()), - last_name: Some(address.get_last_name()?.clone()), + first_name: Some(first_name.clone()), + last_name: Some(address.get_last_name().unwrap_or(first_name).clone()), email: item.request.get_email()?, country: item.get_billing_country()?, }), @@ -678,10 +679,13 @@ impl Some(domain::BankRedirectData::Ideal { bank_name, .. }), ) => { let address = item.get_billing_address()?; + let first_name = address.get_first_name()?.clone(); ( Some(BillingAddress { - first_name: Some(address.get_first_name()?.clone()), - last_name: Some(address.get_last_name()?.clone()), + first_name: Some(first_name.clone()), + last_name: Some( + address.get_last_name().ok().unwrap_or(&first_name).clone(), + ), email: item.request.get_email()?, country: item.get_billing_country()?, }), @@ -715,6 +719,7 @@ fn get_pay_later_info( .address .as_ref() .ok_or_else(utils::missing_field_err("billing.address"))?; + let first_name = address.get_first_name()?; let payment_method = payment_method_type; Ok(NuveiPaymentsRequest { payment_option: PaymentOption { @@ -724,8 +729,8 @@ fn get_pay_later_info( }), billing_address: Some(BillingAddress { email: item.request.get_email()?, - first_name: Some(address.get_first_name()?.to_owned()), - last_name: Some(address.get_last_name()?.to_owned()), + first_name: Some(first_name.clone()), + last_name: Some(address.get_last_name().unwrap_or(first_name).clone()), country: address.get_country()?.to_owned(), }), ..Default::default() @@ -905,12 +910,15 @@ fn get_card_info( .and_then(|billing_details| billing_details.address.as_ref()); let billing_address = match address { - Some(address) => Some(BillingAddress { - first_name: Some(address.get_first_name()?.clone()), - last_name: Some(address.get_last_name()?.clone()), - email: item.request.get_email()?, - country: item.get_billing_country()?, - }), + Some(address) => { + let first_name = address.get_first_name()?.clone(); + Some(BillingAddress { + first_name: Some(first_name.clone()), + last_name: Some(address.get_last_name().ok().unwrap_or(&first_name).clone()), + email: item.request.get_email()?, + country: item.get_billing_country()?, + }) + } None => None, }; let (is_rebilling, additional_params, user_token_id) = diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index f9919d8b91..3aa6affc27 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -1194,7 +1194,12 @@ impl AddressDetailsData for api::AddressDetails { fn get_full_name(&self) -> Result, Error> { let first_name = self.get_first_name()?.peek().to_owned(); - let last_name = self.get_last_name()?.peek().to_owned(); + let last_name = self + .get_last_name() + .ok() + .cloned() + .unwrap_or(Secret::new("".to_string())); + let last_name = last_name.peek(); let full_name = format!("{} {}", first_name, last_name).trim().to_string(); Ok(Secret::new(full_name)) } diff --git a/crates/router/src/connector/volt/transformers.rs b/crates/router/src/connector/volt/transformers.rs index 8c64398bd5..d3913296c0 100644 --- a/crates/router/src/connector/volt/transformers.rs +++ b/crates/router/src/connector/volt/transformers.rs @@ -98,10 +98,11 @@ impl TryFrom<&VoltRouterData<&types::PaymentsAuthorizeRouterData>> for VoltPayme let payment_pending_url = item.router_data.request.router_return_url.clone(); let payment_cancel_url = item.router_data.request.router_return_url.clone(); let address = item.router_data.get_billing_address()?; + let first_name = address.get_first_name()?; let shopper = ShopperDetails { email: item.router_data.request.email.clone(), - first_name: address.get_first_name()?.to_owned(), - last_name: address.get_last_name()?.to_owned(), + first_name: first_name.to_owned(), + last_name: address.get_last_name().unwrap_or(first_name).to_owned(), reference: item.router_data.get_customer_id()?.to_owned(), }; let transaction_type = TransactionType::Services; //transaction_type is a form of enum, it is pre defined and value for this can not be taken from user so we are keeping it as Services as this transaction is type of service.