Skip to content

Commit 1b7cde2

Browse files
fix(address): use first_name if last_name is not passed (#4360)
1 parent 897612a commit 1b7cde2

File tree

9 files changed

+55
-29
lines changed

9 files changed

+55
-29
lines changed

crates/router/src/connector/bankofamerica/transformers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,10 @@ fn build_bill_to(
424424
.ok_or_else(utils::missing_field_err("billing.address"))?;
425425
let mut state = address.to_state_code()?.peek().clone();
426426
state.truncate(20);
427+
let first_name = address.get_first_name()?;
427428
Ok(BillTo {
428-
first_name: address.get_first_name()?.to_owned(),
429-
last_name: address.get_last_name()?.to_owned(),
429+
first_name: first_name.clone(),
430+
last_name: address.get_last_name().unwrap_or(first_name).clone(),
430431
address1: address.get_line1()?.to_owned(),
431432
locality: Secret::new(address.get_city()?.to_owned()),
432433
administrative_area: Secret::from(state),

crates/router/src/connector/bluesnap/transformers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,9 +1133,10 @@ fn get_card_holder_info(
11331133
address: &api::AddressDetails,
11341134
email: Email,
11351135
) -> CustomResult<Option<BluesnapCardHolderInfo>, errors::ConnectorError> {
1136+
let first_name = address.get_first_name()?;
11361137
Ok(Some(BluesnapCardHolderInfo {
1137-
first_name: address.get_first_name()?.clone(),
1138-
last_name: address.get_last_name()?.clone(),
1138+
first_name: first_name.clone(),
1139+
last_name: address.get_last_name().unwrap_or(first_name).clone(),
11391140
email,
11401141
}))
11411142
}

crates/router/src/connector/cybersource/transformers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,10 @@ fn build_bill_to(
784784
.ok_or_else(utils::missing_field_err("billing.address"))?;
785785
let mut state = address.to_state_code()?.peek().clone();
786786
state.truncate(20);
787+
let first_name = address.get_first_name()?;
787788
Ok(BillTo {
788-
first_name: address.get_first_name()?.to_owned(),
789-
last_name: address.get_last_name()?.to_owned(),
789+
first_name: first_name.clone(),
790+
last_name: address.get_last_name().unwrap_or(first_name).clone(),
790791
address1: address.get_line1()?.to_owned(),
791792
locality: address.get_city()?.to_owned(),
792793
administrative_area: Secret::from(state),

crates/router/src/connector/forte/transformers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for FortePaymentsRequest {
8888
expire_year: ccard.card_exp_year.clone(),
8989
card_verification_value: ccard.card_cvc.clone(),
9090
};
91+
let first_name = address.get_first_name()?;
9192
let billing_address = BillingAddress {
92-
first_name: address.get_first_name()?.to_owned(),
93-
last_name: address.get_last_name()?.to_owned(),
93+
first_name: first_name.clone(),
94+
last_name: address.get_last_name().unwrap_or(first_name).clone(),
9495
};
9596
let authorization_amount =
9697
utils::to_currency_base_unit_asf64(item.request.amount, item.request.currency)?;

crates/router/src/connector/multisafepay/transformers.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,13 @@ impl TryFrom<&MultisafepayRouterData<&types::PaymentsAuthorizeRouterData>>
411411
.address
412412
.as_ref()
413413
.ok_or_else(utils::missing_field_err("billing.address"))?;
414+
let first_name = billing_address.get_first_name()?;
414415
let delivery = DeliveryObject {
415-
first_name: billing_address.get_first_name()?.to_owned(),
416-
last_name: billing_address.get_last_name()?.to_owned(),
416+
first_name: first_name.clone(),
417+
last_name: billing_address
418+
.get_last_name()
419+
.unwrap_or(first_name)
420+
.clone(),
417421
address1: billing_address.get_line1()?.to_owned(),
418422
house_number: billing_address.get_line2()?.to_owned(),
419423
zip_code: billing_address.get_zip()?.to_owned(),
@@ -917,15 +921,15 @@ impl From<MultisafepayErrorResponse> for Option<AttemptStatus> {
917921
| 1031 // IncorrectItemPrice
918922
| 1035 // InvalidSignatureRefund
919923
| 1036 // InvalidIdealIssuerID
920-
| 5001 // CartDataNotValidated
924+
| 5001 // CartDataNotValidated
921925
| 1032 // InvalidAPIKey
922926
=> {
923927
Some(AttemptStatus::AuthenticationFailed)
924928
}
925929

926930
1034 // CannotRefundTransaction
927931
| 1022 // CannotInitiateTransaction
928-
| 1024 //TransactionDeclined
932+
| 1024 //TransactionDeclined
929933
=> Some(AttemptStatus::Failure),
930934
1017 // InsufficientFunds
931935
=> Some(AttemptStatus::AuthorizationFailed),

crates/router/src/connector/nmi/transformers.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,18 @@ impl TryFrom<&types::PaymentsPreProcessingRouterData> for NmiVaultRequest {
116116
let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?;
117117
let (ccnumber, ccexp, cvv) = get_card_details(item.request.payment_method_data.clone())?;
118118
let billing_details = item.get_billing_address()?;
119+
let first_name = billing_details.get_first_name()?;
119120

120121
Ok(Self {
121122
security_key: auth_type.api_key,
122123
ccnumber,
123124
ccexp,
124125
cvv,
125-
first_name: billing_details.get_first_name()?.to_owned(),
126-
last_name: billing_details.get_last_name()?.to_owned(),
126+
first_name: first_name.clone(),
127+
last_name: billing_details
128+
.get_last_name()
129+
.unwrap_or(first_name)
130+
.clone(),
127131
address1: billing_details.line1.clone(),
128132
address2: billing_details.line2.clone(),
129133
city: billing_details.city.clone(),

crates/router/src/connector/nuvei/transformers.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -663,10 +663,11 @@ impl<F>
663663
),
664664
(AlternativePaymentMethodType::Sofort, _) | (AlternativePaymentMethodType::Eps, _) => {
665665
let address = item.get_billing_address()?;
666+
let first_name = address.get_first_name()?;
666667
(
667668
Some(BillingAddress {
668-
first_name: Some(address.get_first_name()?.clone()),
669-
last_name: Some(address.get_last_name()?.clone()),
669+
first_name: Some(first_name.clone()),
670+
last_name: Some(address.get_last_name().unwrap_or(first_name).clone()),
670671
email: item.request.get_email()?,
671672
country: item.get_billing_country()?,
672673
}),
@@ -678,10 +679,13 @@ impl<F>
678679
Some(domain::BankRedirectData::Ideal { bank_name, .. }),
679680
) => {
680681
let address = item.get_billing_address()?;
682+
let first_name = address.get_first_name()?.clone();
681683
(
682684
Some(BillingAddress {
683-
first_name: Some(address.get_first_name()?.clone()),
684-
last_name: Some(address.get_last_name()?.clone()),
685+
first_name: Some(first_name.clone()),
686+
last_name: Some(
687+
address.get_last_name().ok().unwrap_or(&first_name).clone(),
688+
),
685689
email: item.request.get_email()?,
686690
country: item.get_billing_country()?,
687691
}),
@@ -715,6 +719,7 @@ fn get_pay_later_info<F>(
715719
.address
716720
.as_ref()
717721
.ok_or_else(utils::missing_field_err("billing.address"))?;
722+
let first_name = address.get_first_name()?;
718723
let payment_method = payment_method_type;
719724
Ok(NuveiPaymentsRequest {
720725
payment_option: PaymentOption {
@@ -724,8 +729,8 @@ fn get_pay_later_info<F>(
724729
}),
725730
billing_address: Some(BillingAddress {
726731
email: item.request.get_email()?,
727-
first_name: Some(address.get_first_name()?.to_owned()),
728-
last_name: Some(address.get_last_name()?.to_owned()),
732+
first_name: Some(first_name.clone()),
733+
last_name: Some(address.get_last_name().unwrap_or(first_name).clone()),
729734
country: address.get_country()?.to_owned(),
730735
}),
731736
..Default::default()
@@ -905,12 +910,15 @@ fn get_card_info<F>(
905910
.and_then(|billing_details| billing_details.address.as_ref());
906911

907912
let billing_address = match address {
908-
Some(address) => Some(BillingAddress {
909-
first_name: Some(address.get_first_name()?.clone()),
910-
last_name: Some(address.get_last_name()?.clone()),
911-
email: item.request.get_email()?,
912-
country: item.get_billing_country()?,
913-
}),
913+
Some(address) => {
914+
let first_name = address.get_first_name()?.clone();
915+
Some(BillingAddress {
916+
first_name: Some(first_name.clone()),
917+
last_name: Some(address.get_last_name().ok().unwrap_or(&first_name).clone()),
918+
email: item.request.get_email()?,
919+
country: item.get_billing_country()?,
920+
})
921+
}
914922
None => None,
915923
};
916924
let (is_rebilling, additional_params, user_token_id) =

crates/router/src/connector/utils.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,12 @@ impl AddressDetailsData for api::AddressDetails {
11941194

11951195
fn get_full_name(&self) -> Result<Secret<String>, Error> {
11961196
let first_name = self.get_first_name()?.peek().to_owned();
1197-
let last_name = self.get_last_name()?.peek().to_owned();
1197+
let last_name = self
1198+
.get_last_name()
1199+
.ok()
1200+
.cloned()
1201+
.unwrap_or(Secret::new("".to_string()));
1202+
let last_name = last_name.peek();
11981203
let full_name = format!("{} {}", first_name, last_name).trim().to_string();
11991204
Ok(Secret::new(full_name))
12001205
}

crates/router/src/connector/volt/transformers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ impl TryFrom<&VoltRouterData<&types::PaymentsAuthorizeRouterData>> for VoltPayme
9898
let payment_pending_url = item.router_data.request.router_return_url.clone();
9999
let payment_cancel_url = item.router_data.request.router_return_url.clone();
100100
let address = item.router_data.get_billing_address()?;
101+
let first_name = address.get_first_name()?;
101102
let shopper = ShopperDetails {
102103
email: item.router_data.request.email.clone(),
103-
first_name: address.get_first_name()?.to_owned(),
104-
last_name: address.get_last_name()?.to_owned(),
104+
first_name: first_name.to_owned(),
105+
last_name: address.get_last_name().unwrap_or(first_name).to_owned(),
105106
reference: item.router_data.get_customer_id()?.to_owned(),
106107
};
107108
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.

0 commit comments

Comments
 (0)