fix(connector): [Trustpay] send billing address name as cardholder name (#1806)

This commit is contained in:
Sai Harsha Vardhan
2023-07-28 12:43:26 +05:30
committed by GitHub
parent 32c2227864
commit 71b75c6538

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use api_models::payments::BankRedirectData;
use common_utils::{errors::CustomResult, pii};
use error_stack::{report, IntoReport, ResultExt};
use masking::Secret;
use masking::{PeekInterface, Secret};
use reqwest::Url;
use serde::{Deserialize, Serialize};
@ -182,6 +182,7 @@ pub struct TrustpayMandatoryParams {
pub billing_country: api_models::enums::CountryAlpha2,
pub billing_street1: Secret<String>,
pub billing_postcode: Secret<String>,
pub billing_first_name: Secret<String>,
}
impl TryFrom<&BankRedirectData> for TrustpayPaymentMethod {
@ -210,6 +211,7 @@ fn get_mandatory_fields(
billing_country: billing_address.get_country()?.to_owned(),
billing_street1: billing_address.get_line1()?.to_owned(),
billing_postcode: billing_address.get_zip()?.to_owned(),
billing_first_name: billing_address.get_first_name()?.to_owned(),
})
}
@ -223,6 +225,11 @@ fn get_card_request_data(
) -> Result<TrustpayPaymentsRequest, Error> {
let email = item.request.get_email()?;
let customer_ip_address = browser_info.get_ip_address()?;
let billing_last_name = item
.get_billing()?
.address
.as_ref()
.map(|address| address.last_name.clone().unwrap_or_default());
Ok(TrustpayPaymentsRequest::CardsPaymentRequest(Box::new(
PaymentRequestCards {
amount,
@ -230,7 +237,12 @@ fn get_card_request_data(
pan: ccard.card_number.clone(),
cvv: ccard.card_cvc.clone(),
expiry_date: ccard.get_card_expiry_month_year_2_digit_with_delimiter("/".to_owned()),
cardholder: ccard.card_holder_name.clone(),
cardholder: match billing_last_name {
Some(last_name) => {
format!("{} {}", params.billing_first_name.peek(), last_name.peek()).into()
}
None => params.billing_first_name,
},
reference: item.payment_id.clone(),
redirect_url: return_url,
billing_city: params.billing_city,