Skip to content

Commit

Permalink
fix(core): payments - map billing first and last name to card holder …
Browse files Browse the repository at this point in the history
…name (#6791)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
kashif-m and hyperswitch-bot[bot] authored Dec 10, 2024
1 parent 8431842 commit c3b22cf
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 18 deletions.
29 changes: 22 additions & 7 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2092,14 +2092,29 @@ mod payment_method_data_serde {
if inner_map.is_empty() {
None
} else {
Some(
serde_json::from_value::<PaymentMethodData>(
payment_method_data_value,
)
.map_err(|serde_json_error| {
de::Error::custom(serde_json_error.to_string())
})?,
let payment_method_data = serde_json::from_value::<PaymentMethodData>(
payment_method_data_value,
)
.map_err(|serde_json_error| {
de::Error::custom(serde_json_error.to_string())
})?;
let address_details = parsed_value
.billing
.as_ref()
.and_then(|billing| billing.address.clone());
match (payment_method_data.clone(), address_details.as_ref()) {
(
PaymentMethodData::Card(ref mut card),
Some(billing_address_details),
) => {
if card.card_holder_name.is_none() {
card.card_holder_name =
billing_address_details.get_optional_full_name();
}
Some(PaymentMethodData::Card(card.clone()))
}
_ => Some(payment_method_data),
}
}
} else {
Err(de::Error::custom("Expected a map for payment_method_data"))?
Expand Down
7 changes: 6 additions & 1 deletion crates/hyperswitch_domain_models/src/payment_method_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub struct Card {
pub card_issuing_country: Option<String>,
pub bank_code: Option<String>,
pub nick_name: Option<Secret<String>>,
pub card_holder_name: Option<Secret<String>>,
}

#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize, Default)]
Expand All @@ -95,6 +96,7 @@ pub struct CardDetailsForNetworkTransactionId {
pub card_issuing_country: Option<String>,
pub bank_code: Option<String>,
pub nick_name: Option<Secret<String>>,
pub card_holder_name: Option<Secret<String>>,
}

impl CardDetailsForNetworkTransactionId {
Expand Down Expand Up @@ -136,6 +138,7 @@ impl From<mandates::NetworkTransactionIdAndCardDetails> for CardDetailsForNetwor
card_issuing_country: card_details_for_nti.card_issuing_country,
bank_code: card_details_for_nti.bank_code,
nick_name: card_details_for_nti.nick_name,
card_holder_name: card_details_for_nti.card_holder_name,
}
}
}
Expand Down Expand Up @@ -666,7 +669,7 @@ impl From<api_models::payments::Card> for Card {
card_number,
card_exp_month,
card_exp_year,
card_holder_name: _,
card_holder_name,
card_cvc,
card_issuer,
card_network,
Expand All @@ -687,6 +690,7 @@ impl From<api_models::payments::Card> for Card {
card_issuing_country,
bank_code,
nick_name,
card_holder_name,
}
}
}
Expand Down Expand Up @@ -1438,6 +1442,7 @@ pub struct TokenizedCardValue1 {
pub nickname: Option<String>,
pub card_last_four: Option<String>,
pub card_token: Option<String>,
pub card_holder_name: Option<Secret<String>>,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/payment_methods/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Vaultable for domain::Card {
nickname: self.nick_name.as_ref().map(|name| name.peek().clone()),
card_last_four: None,
card_token: None,
card_holder_name: self.card_holder_name.clone(),
};

value1
Expand Down Expand Up @@ -119,6 +120,7 @@ impl Vaultable for domain::Card {
card_issuing_country: None,
card_type: None,
nick_name: value1.nickname.map(masking::Secret::new),
card_holder_name: value1.card_holder_name,
};

let supp_data = SupplementaryVaultData {
Expand Down
14 changes: 8 additions & 6 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,7 @@ pub async fn retrieve_card_with_permanent_token(
card_issuing_country: None,
bank_code: None,
nick_name: card_details_from_locker.nick_name.map(masking::Secret::new),
card_holder_name: card_details_from_locker.name_on_card.clone(),
};

Ok(
Expand Down Expand Up @@ -2130,6 +2131,7 @@ pub async fn retrieve_card_with_permanent_token(
card_issuing_country: None,
bank_code: None,
nick_name: card_details_from_locker.nick_name.map(masking::Secret::new),
card_holder_name: card_details_from_locker.name_on_card,
};

Ok(
Expand Down Expand Up @@ -4408,7 +4410,7 @@ pub async fn get_additional_payment_data(
bank_code: card_data.bank_code.to_owned(),
card_exp_month: Some(card_data.card_exp_month.clone()),
card_exp_year: Some(card_data.card_exp_year.clone()),
card_holder_name: card_data.nick_name.clone(), //todo!
card_holder_name: card_data.card_holder_name.clone(),
last4: last4.clone(),
card_isin: card_isin.clone(),
card_extended_bin: card_extended_bin.clone(),
Expand Down Expand Up @@ -4441,7 +4443,7 @@ pub async fn get_additional_payment_data(
card_extended_bin: card_extended_bin.clone(),
card_exp_month: Some(card_data.card_exp_month.clone()),
card_exp_year: Some(card_data.card_exp_year.clone()),
card_holder_name: card_data.nick_name.clone(), //todo!
card_holder_name: card_data.card_holder_name.clone(),
// These are filled after calling the processor / connector
payment_checks: None,
authentication_data: None,
Expand All @@ -4461,7 +4463,7 @@ pub async fn get_additional_payment_data(
card_extended_bin,
card_exp_month: Some(card_data.card_exp_month.clone()),
card_exp_year: Some(card_data.card_exp_year.clone()),
card_holder_name: card_data.nick_name.clone(), //todo!
card_holder_name: card_data.card_holder_name.clone(),
// These are filled after calling the processor / connector
payment_checks: None,
authentication_data: None,
Expand Down Expand Up @@ -4671,7 +4673,7 @@ pub async fn get_additional_payment_data(
bank_code: card_data.bank_code.to_owned(),
card_exp_month: Some(card_data.card_exp_month.clone()),
card_exp_year: Some(card_data.card_exp_year.clone()),
card_holder_name: card_data.nick_name.clone(), //todo!
card_holder_name: card_data.card_holder_name.clone(),
last4: last4.clone(),
card_isin: card_isin.clone(),
card_extended_bin: card_extended_bin.clone(),
Expand Down Expand Up @@ -4704,7 +4706,7 @@ pub async fn get_additional_payment_data(
card_extended_bin: card_extended_bin.clone(),
card_exp_month: Some(card_data.card_exp_month.clone()),
card_exp_year: Some(card_data.card_exp_year.clone()),
card_holder_name: card_data.nick_name.clone(), //todo!
card_holder_name: card_data.card_holder_name.clone(),
// These are filled after calling the processor / connector
payment_checks: None,
authentication_data: None,
Expand All @@ -4724,7 +4726,7 @@ pub async fn get_additional_payment_data(
card_extended_bin,
card_exp_month: Some(card_data.card_exp_month.clone()),
card_exp_year: Some(card_data.card_exp_year.clone()),
card_holder_name: card_data.nick_name.clone(), //todo!
card_holder_name: card_data.card_holder_name.clone(),
// These are filled after calling the processor / connector
payment_checks: None,
authentication_data: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/utils/verify_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn generate_card_from_details(
card_type: None,
card_issuing_country: None,
bank_code: None,
card_holder_name: None,
})
}

Expand Down
2 changes: 2 additions & 0 deletions crates/router/tests/connectors/aci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData {
card_issuing_country: None,
bank_code: None,
nick_name: Some(Secret::new("nick_name".into())),
card_holder_name: Some(Secret::new("card holder name".into())),
}),
confirm: true,
statement_descriptor_suffix: None,
Expand Down Expand Up @@ -296,6 +297,7 @@ async fn payments_create_failure() {
card_issuing_country: None,
bank_code: None,
nick_name: Some(Secret::new("nick_name".into())),
card_holder_name: Some(Secret::new("card holder name".into())),
});

let response = services::api::execute_connector_processing_step(
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/adyen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl AdyenTest {
card_issuing_country: None,
bank_code: None,
nick_name: Some(Secret::new("nick_name".into())),
card_holder_name: Some(Secret::new("card holder name".into())),
}),
confirm: true,
statement_descriptor_suffix: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/airwallex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
card_issuing_country: None,
bank_code: None,
nick_name: Some(Secret::new("nick_name".into())),
card_holder_name: Some(Secret::new("card holder name".into())),
}),
capture_method: Some(diesel_models::enums::CaptureMethod::Manual),
router_return_url: Some("https://google.com".to_string()),
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/fiserv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
card_issuing_country: None,
bank_code: None,
nick_name: Some(Secret::new("nick_name".into())),
card_holder_name: Some(Secret::new("card holder name".into())),
}),
capture_method: Some(diesel_models::enums::CaptureMethod::Manual),
..utils::PaymentAuthorizeType::default().0
Expand Down
2 changes: 2 additions & 0 deletions crates/router/tests/connectors/rapyd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async fn should_only_authorize_payment() {
card_issuing_country: None,
bank_code: None,
nick_name: Some(Secret::new("nick_name".into())),
card_holder_name: Some(Secret::new("card holder name".into())),
}),
capture_method: Some(diesel_models::enums::CaptureMethod::Manual),
..utils::PaymentAuthorizeType::default().0
Expand Down Expand Up @@ -80,6 +81,7 @@ async fn should_authorize_and_capture_payment() {
card_issuing_country: None,
bank_code: None,
nick_name: Some(Secret::new("nick_name".into())),
card_holder_name: Some(Secret::new("card holder name".into())),
}),
..utils::PaymentAuthorizeType::default().0
}),
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ impl Default for CCardType {
card_issuing_country: None,
bank_code: None,
nick_name: Some(Secret::new("nick_name".into())),
card_holder_name: Some(Secret::new("card holder name".into())),
})
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/worldline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl WorldlineTest {
card_issuing_country: None,
bank_code: None,
nick_name: Some(Secret::new("nick_name".into())),
card_holder_name: Some(Secret::new("card holder name".into())),
}),
confirm: true,
statement_descriptor_suffix: None,
Expand Down
4 changes: 2 additions & 2 deletions cypress-tests/cypress/e2e/PaymentUtils/Cybersource.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const payment_method_data_no3ds = {
card_extended_bin: null,
card_exp_month: "01",
card_exp_year: "50",
card_holder_name: null,
card_holder_name: "joseph Doe",
payment_checks: {
avs_response: {
code: "Y",
Expand All @@ -83,7 +83,7 @@ const payment_method_data_3ds = {
card_extended_bin: null,
card_exp_month: "01",
card_exp_year: "50",
card_holder_name: null,
card_holder_name: "joseph Doe",
payment_checks: null,
authentication_data: null,
},
Expand Down
4 changes: 2 additions & 2 deletions cypress-tests/cypress/e2e/PaymentUtils/Stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const payment_method_data_3ds = {
card_extended_bin: null,
card_exp_month: "10",
card_exp_year: "50",
card_holder_name: null,
card_holder_name: "morino",
payment_checks: null,
authentication_data: null,
},
Expand All @@ -79,7 +79,7 @@ const payment_method_data_no3ds = {
card_extended_bin: null,
card_exp_month: "10",
card_exp_year: "50",
card_holder_name: null,
card_holder_name: "morino",
payment_checks: {
cvc_check: "pass",
address_line1_check: "pass",
Expand Down

0 comments on commit c3b22cf

Please sign in to comment.