mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
feat(core): implement NameType for name validation (#6734)
This commit is contained in:
@ -18,7 +18,7 @@ pub struct CustomerRequest {
|
||||
pub merchant_id: id_type::MerchantId,
|
||||
/// The customer's name
|
||||
#[schema(max_length = 255, value_type = Option<String>, example = "Jon Test")]
|
||||
pub name: Option<Secret<String>>,
|
||||
pub name: Option<common_utils::types::NameType>,
|
||||
/// The customer's email address
|
||||
#[schema(value_type = Option<String>, max_length = 255, example = "JonTest@test.com")]
|
||||
pub email: Option<pii::Email>,
|
||||
|
||||
@ -57,7 +57,7 @@ pub struct MandateCardDetails {
|
||||
pub card_exp_year: Option<Secret<String>>,
|
||||
/// The card holder name
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
/// The token from card locker
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub card_token: Option<Secret<String>>,
|
||||
@ -79,7 +79,7 @@ pub struct MandateCardDetails {
|
||||
pub card_type: Option<String>,
|
||||
/// The nick_name of the card holder
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub nick_name: Option<Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
|
||||
@ -151,7 +151,7 @@ pub struct NetworkTransactionIdAndCardDetails {
|
||||
|
||||
/// The card holder's name
|
||||
#[schema(value_type = String, example = "John Test")]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// The name of the issuer of card
|
||||
#[schema(example = "chase")]
|
||||
@ -172,7 +172,7 @@ pub struct NetworkTransactionIdAndCardDetails {
|
||||
|
||||
/// The card holder's nick name
|
||||
#[schema(value_type = Option<String>, example = "John Test")]
|
||||
pub nick_name: Option<Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// The network transaction ID provided by the card network during a CIT (Customer Initiated Transaction),
|
||||
/// where `setup_future_usage` is set to `off_session`.
|
||||
|
||||
@ -539,11 +539,11 @@ pub struct CardDetail {
|
||||
|
||||
/// Card Holder Name
|
||||
#[schema(value_type = String,example = "John Doe")]
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Holder's Nick Name
|
||||
#[schema(value_type = Option<String>,example = "John Doe")]
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Issuing Country
|
||||
pub card_issuing_country: Option<String>,
|
||||
@ -599,11 +599,11 @@ pub struct CardDetail {
|
||||
|
||||
/// Card Holder Name
|
||||
#[schema(value_type = String,example = "John Doe")]
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Holder's Nick Name
|
||||
#[schema(value_type = Option<String>,example = "John Doe")]
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Issuing Country
|
||||
#[schema(value_type = CountryAlpha2)]
|
||||
@ -642,11 +642,11 @@ pub struct MigrateCardDetail {
|
||||
|
||||
/// Card Holder Name
|
||||
#[schema(value_type = String,example = "John Doe")]
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Holder's Nick Name
|
||||
#[schema(value_type = Option<String>,example = "John Doe")]
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Issuing Country
|
||||
pub card_issuing_country: Option<String>,
|
||||
@ -679,11 +679,11 @@ pub struct MigrateNetworkTokenData {
|
||||
|
||||
/// Card Holder Name
|
||||
#[schema(value_type = String,example = "John Doe")]
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Holder's Nick Name
|
||||
#[schema(value_type = Option<String>,example = "John Doe")]
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Issuing Country
|
||||
pub card_issuing_country: Option<String>,
|
||||
@ -726,11 +726,11 @@ pub struct CardDetailUpdate {
|
||||
|
||||
/// Card Holder Name
|
||||
#[schema(value_type = String,example = "John Doe")]
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Holder's Nick Name
|
||||
#[schema(value_type = Option<String>,example = "John Doe")]
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
@ -753,10 +753,7 @@ impl CardDetailUpdate {
|
||||
.card_holder_name
|
||||
.clone()
|
||||
.or(card_data_from_locker.name_on_card),
|
||||
nick_name: self
|
||||
.nick_name
|
||||
.clone()
|
||||
.or(card_data_from_locker.nick_name.map(masking::Secret::new)),
|
||||
nick_name: self.nick_name.clone().or(card_data_from_locker.nick_name),
|
||||
card_issuing_country: None,
|
||||
card_network: None,
|
||||
card_issuer: None,
|
||||
@ -771,11 +768,11 @@ impl CardDetailUpdate {
|
||||
pub struct CardDetailUpdate {
|
||||
/// Card Holder Name
|
||||
#[schema(value_type = String,example = "John Doe")]
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Holder's Nick Name
|
||||
#[schema(value_type = Option<String>,example = "John Doe")]
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
@ -789,10 +786,7 @@ impl CardDetailUpdate {
|
||||
.card_holder_name
|
||||
.clone()
|
||||
.or(card_data_from_locker.name_on_card),
|
||||
nick_name: self
|
||||
.nick_name
|
||||
.clone()
|
||||
.or(card_data_from_locker.nick_name.map(masking::Secret::new)),
|
||||
nick_name: self.nick_name.clone().or(card_data_from_locker.nick_name),
|
||||
card_issuing_country: None,
|
||||
card_network: None,
|
||||
card_issuer: None,
|
||||
@ -970,8 +964,8 @@ pub struct CardDetailsPaymentMethod {
|
||||
pub issuer_country: Option<String>,
|
||||
pub expiry_month: Option<masking::Secret<String>>,
|
||||
pub expiry_year: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
pub card_isin: Option<String>,
|
||||
pub card_issuer: Option<String>,
|
||||
pub card_network: Option<api_enums::CardNetwork>,
|
||||
@ -1065,12 +1059,12 @@ pub enum BankAccountAccessCreds {
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
||||
pub struct Card {
|
||||
pub card_number: CardNumber,
|
||||
pub name_on_card: Option<masking::Secret<String>>,
|
||||
pub name_on_card: Option<common_utils::types::NameType>,
|
||||
pub card_exp_month: masking::Secret<String>,
|
||||
pub card_exp_year: masking::Secret<String>,
|
||||
pub card_brand: Option<String>,
|
||||
pub card_isin: Option<String>,
|
||||
pub nick_name: Option<String>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
@ -1096,13 +1090,13 @@ pub struct CardDetailFromLocker {
|
||||
pub card_token: Option<masking::Secret<String>>,
|
||||
|
||||
#[schema(value_type=Option<String>)]
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
#[schema(value_type=Option<String>)]
|
||||
pub card_fingerprint: Option<masking::Secret<String>>,
|
||||
|
||||
#[schema(value_type=Option<String>)]
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
|
||||
#[schema(value_type = Option<CardNetwork>)]
|
||||
pub card_network: Option<api_enums::CardNetwork>,
|
||||
@ -1130,13 +1124,13 @@ pub struct CardDetailFromLocker {
|
||||
pub expiry_year: Option<masking::Secret<String>>,
|
||||
|
||||
#[schema(value_type=Option<String>)]
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
#[schema(value_type=Option<String>)]
|
||||
pub card_fingerprint: Option<masking::Secret<String>>,
|
||||
|
||||
#[schema(value_type=Option<String>)]
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
|
||||
#[schema(value_type = Option<CardNetwork>)]
|
||||
pub card_network: Option<api_enums::CardNetwork>,
|
||||
@ -2291,8 +2285,8 @@ pub struct TokenizedCardValue1 {
|
||||
pub card_number: String,
|
||||
pub exp_year: String,
|
||||
pub exp_month: String,
|
||||
pub name_on_card: Option<String>,
|
||||
pub nickname: Option<String>,
|
||||
pub name_on_card: Option<common_utils::types::NameType>,
|
||||
pub nickname: Option<common_utils::types::NameType>,
|
||||
pub card_last_four: Option<String>,
|
||||
pub card_token: Option<String>,
|
||||
}
|
||||
@ -2360,14 +2354,14 @@ pub struct TokenizedBankRedirectValue2 {
|
||||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
|
||||
pub struct PaymentMethodRecord {
|
||||
pub customer_id: id_type::CustomerId,
|
||||
pub name: Option<masking::Secret<String>>,
|
||||
pub name: Option<common_utils::types::NameType>,
|
||||
pub email: Option<pii::Email>,
|
||||
pub phone: Option<masking::Secret<String>>,
|
||||
pub phone_country_code: Option<String>,
|
||||
pub merchant_id: Option<id_type::MerchantId>,
|
||||
pub payment_method: Option<api_enums::PaymentMethod>,
|
||||
pub payment_method_type: Option<api_enums::PaymentMethodType>,
|
||||
pub nick_name: masking::Secret<String>,
|
||||
pub nick_name: common_utils::types::NameType,
|
||||
pub payment_instrument_id: Option<masking::Secret<String>>,
|
||||
pub card_number_masked: masking::Secret<String>,
|
||||
pub card_expiry_month: masking::Secret<String>,
|
||||
@ -2376,8 +2370,8 @@ pub struct PaymentMethodRecord {
|
||||
pub original_transaction_id: Option<String>,
|
||||
pub billing_address_zip: masking::Secret<String>,
|
||||
pub billing_address_state: masking::Secret<String>,
|
||||
pub billing_address_first_name: masking::Secret<String>,
|
||||
pub billing_address_last_name: masking::Secret<String>,
|
||||
pub billing_address_first_name: common_utils::types::NameType,
|
||||
pub billing_address_last_name: common_utils::types::NameType,
|
||||
pub billing_address_city: String,
|
||||
pub billing_address_country: Option<api_enums::CountryAlpha2>,
|
||||
pub billing_address_line1: masking::Secret<String>,
|
||||
@ -2647,11 +2641,11 @@ pub struct TokenizeCardRequest {
|
||||
|
||||
/// Card Holder Name
|
||||
#[schema(value_type = Option<String>, example = "John Doe")]
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Holder's Nick Name
|
||||
#[schema(value_type = Option<String>, example = "John Doe")]
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Card Issuing Country
|
||||
pub card_issuing_country: Option<String>,
|
||||
@ -2712,10 +2706,7 @@ impl From<&Card> for MigrateCardDetail {
|
||||
card_exp_month: card.card_exp_month.clone(),
|
||||
card_exp_year: card.card_exp_year.clone(),
|
||||
card_holder_name: card.name_on_card.clone(),
|
||||
nick_name: card
|
||||
.nick_name
|
||||
.as_ref()
|
||||
.map(|name| masking::Secret::new(name.clone())),
|
||||
nick_name: card.nick_name.clone(),
|
||||
card_issuing_country: None,
|
||||
card_network: None,
|
||||
card_issuer: None,
|
||||
|
||||
@ -23,7 +23,7 @@ use common_utils::{
|
||||
types::{MinorUnit, StringMajorUnit},
|
||||
};
|
||||
use error_stack::ResultExt;
|
||||
use masking::{PeekInterface, Secret, WithType};
|
||||
use masking::{Secret, WithType};
|
||||
use router_derive::Setter;
|
||||
use serde::{de, ser::Serializer, Deserialize, Deserializer, Serialize};
|
||||
use strum::Display;
|
||||
@ -1913,7 +1913,7 @@ pub struct Card {
|
||||
|
||||
/// The card holder's name
|
||||
#[schema(value_type = String, example = "John Test")]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// The CVC number for the card
|
||||
#[schema(value_type = String, example = "242")]
|
||||
@ -1937,7 +1937,7 @@ pub struct Card {
|
||||
pub bank_code: Option<String>,
|
||||
/// The card holder's nick name
|
||||
#[schema(value_type = Option<String>, example = "John Test")]
|
||||
pub nick_name: Option<Secret<String>>,
|
||||
pub nick_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
@ -1993,7 +1993,7 @@ pub struct ExtendedCardInfo {
|
||||
|
||||
/// The card holder's name
|
||||
#[schema(value_type = String, example = "John Test")]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// The CVC number for the card
|
||||
#[schema(value_type = String, example = "242")]
|
||||
@ -2046,19 +2046,20 @@ impl GetAddressFromPaymentMethodData for Card {
|
||||
// John Wheat Dough
|
||||
// first_name -> John
|
||||
// last_name -> Wheat Dough
|
||||
card_holder_name.peek().split_whitespace()
|
||||
card_holder_name.split_whitespace()
|
||||
})
|
||||
.map(|mut card_holder_name_iter| {
|
||||
let first_name = card_holder_name_iter
|
||||
.next()
|
||||
.map(ToOwned::to_owned)
|
||||
.map(Secret::new);
|
||||
.map(common_utils::types::NameType::get_unchecked); // it is unchecked because the string is coming from a checked type
|
||||
|
||||
let last_name = card_holder_name_iter.collect::<Vec<_>>().join(" ");
|
||||
let last_name = if last_name.is_empty_after_trim() {
|
||||
None
|
||||
} else {
|
||||
Some(Secret::new(last_name))
|
||||
Some(common_utils::types::NameType::get_unchecked(last_name))
|
||||
// it is unchecked because the string is coming from a checked type
|
||||
};
|
||||
|
||||
AddressDetails {
|
||||
@ -2110,7 +2111,7 @@ impl Card {
|
||||
pub struct CardToken {
|
||||
/// The card holder's name
|
||||
#[schema(value_type = String, example = "John Test")]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// The CVC number for the card
|
||||
#[schema(value_type = Option<String>)]
|
||||
@ -2152,7 +2153,7 @@ pub enum PayLaterData {
|
||||
billing_email: Option<Email>,
|
||||
/// The billing name
|
||||
#[schema(value_type = Option<String>)]
|
||||
billing_name: Option<Secret<String>>,
|
||||
billing_name: Option<common_utils::types::NameType>,
|
||||
},
|
||||
/// For PayBright Redirect as PayLater Option
|
||||
PayBrightRedirect {},
|
||||
@ -2221,10 +2222,10 @@ pub enum BankDebitData {
|
||||
routing_number: Secret<String>,
|
||||
|
||||
#[schema(value_type = String, example = "John Test")]
|
||||
card_holder_name: Option<Secret<String>>,
|
||||
card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
#[schema(value_type = String, example = "John Doe")]
|
||||
bank_account_holder_name: Option<Secret<String>>,
|
||||
bank_account_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
#[schema(value_type = String, example = "ACH")]
|
||||
bank_name: Option<common_enums::BankNames>,
|
||||
@ -2243,7 +2244,7 @@ pub enum BankDebitData {
|
||||
iban: Secret<String>,
|
||||
/// Owner name for bank debit
|
||||
#[schema(value_type = String, example = "A. Schneider")]
|
||||
bank_account_holder_name: Option<Secret<String>>,
|
||||
bank_account_holder_name: Option<common_utils::types::NameType>,
|
||||
},
|
||||
BecsBankDebit {
|
||||
/// Billing details for bank debit
|
||||
@ -2256,7 +2257,7 @@ pub enum BankDebitData {
|
||||
bsb_number: Secret<String>,
|
||||
/// Owner name for bank debit
|
||||
#[schema(value_type = Option<String>, example = "A. Schneider")]
|
||||
bank_account_holder_name: Option<Secret<String>>,
|
||||
bank_account_holder_name: Option<common_utils::types::NameType>,
|
||||
},
|
||||
BacsBankDebit {
|
||||
/// Billing details for bank debit
|
||||
@ -2269,7 +2270,7 @@ pub enum BankDebitData {
|
||||
sort_code: Secret<String>,
|
||||
/// holder name for bank debit
|
||||
#[schema(value_type = String, example = "A. Schneider")]
|
||||
bank_account_holder_name: Option<Secret<String>>,
|
||||
bank_account_holder_name: Option<common_utils::types::NameType>,
|
||||
},
|
||||
}
|
||||
|
||||
@ -2277,7 +2278,7 @@ impl GetAddressFromPaymentMethodData for BankDebitData {
|
||||
fn get_billing_address(&self) -> Option<Address> {
|
||||
fn get_billing_address_inner(
|
||||
bank_debit_billing: Option<&BankDebitBilling>,
|
||||
bank_account_holder_name: Option<&Secret<String>>,
|
||||
bank_account_holder_name: Option<&common_utils::types::NameType>,
|
||||
) -> Option<Address> {
|
||||
// We will always have address here
|
||||
let mut address = bank_debit_billing
|
||||
@ -2404,8 +2405,10 @@ mod payment_method_data_serde {
|
||||
Some(billing_address_details),
|
||||
) => {
|
||||
if card.card_holder_name.is_none() {
|
||||
card.card_holder_name =
|
||||
billing_address_details.get_optional_full_name();
|
||||
card.card_holder_name = billing_address_details
|
||||
.get_optional_full_name()
|
||||
.map(common_utils::types::NameType::get_unchecked_from_secret)
|
||||
// it is unchecked because the string is coming from a checked type
|
||||
}
|
||||
Some(PaymentMethodData::Card(card.clone()))
|
||||
}
|
||||
@ -2845,7 +2848,7 @@ pub struct AdditionalCardInfo {
|
||||
|
||||
pub card_exp_year: Option<Secret<String>>,
|
||||
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Additional payment checks done on the cvv and billing address by the processors.
|
||||
/// This is a free form field and the structure varies from processor to processor
|
||||
@ -2943,7 +2946,7 @@ pub enum BankRedirectData {
|
||||
|
||||
/// The card holder's name
|
||||
#[schema(value_type = String, example = "John Test")]
|
||||
card_holder_name: Option<Secret<String>>,
|
||||
card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
//Required by Stripes
|
||||
billing_details: Option<BankRedirectBilling>,
|
||||
@ -3194,10 +3197,10 @@ impl GetAddressFromPaymentMethodData for BankRedirectData {
|
||||
pub struct AlfamartVoucherData {
|
||||
/// The billing first name for Alfamart
|
||||
#[schema(value_type = Option<String>, example = "Jane")]
|
||||
pub first_name: Option<Secret<String>>,
|
||||
pub first_name: Option<common_utils::types::NameType>,
|
||||
/// The billing second name for Alfamart
|
||||
#[schema(value_type = Option<String>, example = "Doe")]
|
||||
pub last_name: Option<Secret<String>>,
|
||||
pub last_name: Option<common_utils::types::NameType>,
|
||||
/// The Email ID for Alfamart
|
||||
#[schema(value_type = Option<String>, example = "example@me.com")]
|
||||
pub email: Option<Email>,
|
||||
@ -3207,10 +3210,10 @@ pub struct AlfamartVoucherData {
|
||||
pub struct IndomaretVoucherData {
|
||||
/// The billing first name for Alfamart
|
||||
#[schema(value_type = Option<String>, example = "Jane")]
|
||||
pub first_name: Option<Secret<String>>,
|
||||
pub first_name: Option<common_utils::types::NameType>,
|
||||
/// The billing second name for Alfamart
|
||||
#[schema(value_type = Option<String>, example = "Doe")]
|
||||
pub last_name: Option<Secret<String>>,
|
||||
pub last_name: Option<common_utils::types::NameType>,
|
||||
/// The Email ID for Alfamart
|
||||
#[schema(value_type = Option<String>, example = "example@me.com")]
|
||||
pub email: Option<Email>,
|
||||
@ -3220,10 +3223,10 @@ pub struct IndomaretVoucherData {
|
||||
pub struct JCSVoucherData {
|
||||
/// The billing first name for Japanese convenience stores
|
||||
#[schema(value_type = Option<String>, example = "Jane")]
|
||||
pub first_name: Option<Secret<String>>,
|
||||
pub first_name: Option<common_utils::types::NameType>,
|
||||
/// The billing second name Japanese convenience stores
|
||||
#[schema(value_type = Option<String>, example = "Doe")]
|
||||
pub last_name: Option<Secret<String>>,
|
||||
pub last_name: Option<common_utils::types::NameType>,
|
||||
/// The Email ID for Japanese convenience stores
|
||||
#[schema(value_type = Option<String>, example = "example@me.com")]
|
||||
pub email: Option<Email>,
|
||||
@ -3243,10 +3246,10 @@ pub struct AchBillingDetails {
|
||||
pub struct DokuBillingDetails {
|
||||
/// The billing first name for Doku
|
||||
#[schema(value_type = Option<String>, example = "Jane")]
|
||||
pub first_name: Option<Secret<String>>,
|
||||
pub first_name: Option<common_utils::types::NameType>,
|
||||
/// The billing second name for Doku
|
||||
#[schema(value_type = Option<String>, example = "Doe")]
|
||||
pub last_name: Option<Secret<String>>,
|
||||
pub last_name: Option<common_utils::types::NameType>,
|
||||
/// The Email ID for Doku billing
|
||||
#[schema(value_type = Option<String>, example = "example@me.com")]
|
||||
pub email: Option<Email>,
|
||||
@ -3265,7 +3268,7 @@ pub struct SepaAndBacsBillingDetails {
|
||||
pub email: Option<Email>,
|
||||
/// The billing name for SEPA and BACS billing
|
||||
#[schema(value_type = Option<String>, example = "Jane Doe")]
|
||||
pub name: Option<Secret<String>>,
|
||||
pub name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
@ -3303,7 +3306,7 @@ pub struct SofortBilling {
|
||||
pub struct BankRedirectBilling {
|
||||
/// The name for which billing is issued
|
||||
#[schema(value_type = String, example = "John Doe")]
|
||||
pub billing_name: Option<Secret<String>>,
|
||||
pub billing_name: Option<common_utils::types::NameType>,
|
||||
/// The billing email for bank redirect
|
||||
#[schema(value_type = String, example = "example@example.com")]
|
||||
pub email: Option<Email>,
|
||||
@ -3477,7 +3480,7 @@ impl GetAddressFromPaymentMethodData for BankTransferData {
|
||||
pub struct BankDebitBilling {
|
||||
/// The billing name for bank debits
|
||||
#[schema(value_type = Option<String>, example = "John Doe")]
|
||||
pub name: Option<Secret<String>>,
|
||||
pub name: Option<common_utils::types::NameType>,
|
||||
/// The billing email for bank debits
|
||||
#[schema(value_type = Option<String>, example = "example@example.com")]
|
||||
pub email: Option<Email>,
|
||||
@ -3907,7 +3910,7 @@ pub struct CardResponse {
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub card_exp_year: Option<Secret<String>>,
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
pub payment_checks: Option<serde_json::Value>,
|
||||
pub authentication_data: Option<serde_json::Value>,
|
||||
}
|
||||
@ -4297,11 +4300,11 @@ pub struct AddressDetails {
|
||||
|
||||
/// The first name for the address
|
||||
#[schema(value_type = Option<String>, max_length = 255, example = "John")]
|
||||
pub first_name: Option<Secret<String>>,
|
||||
pub first_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// The last name for the address
|
||||
#[schema(value_type = Option<String>, max_length = 255, example = "Doe")]
|
||||
pub last_name: Option<Secret<String>>,
|
||||
pub last_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
impl AddressDetails {
|
||||
@ -4309,10 +4312,10 @@ impl AddressDetails {
|
||||
match (self.first_name.as_ref(), self.last_name.as_ref()) {
|
||||
(Some(first_name), Some(last_name)) => Some(Secret::new(format!(
|
||||
"{} {}",
|
||||
first_name.peek(),
|
||||
last_name.peek()
|
||||
String::from(first_name),
|
||||
String::from(last_name)
|
||||
))),
|
||||
(Some(name), None) | (None, Some(name)) => Some(name.to_owned()),
|
||||
(Some(name), None) | (None, Some(name)) => Some(Secret::from(name.to_owned())),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -8298,7 +8301,6 @@ mod payments_response_api_contract {
|
||||
mod billing_from_payment_method_data {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use common_enums::CountryAlpha2;
|
||||
use masking::ExposeOptionInterface;
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -8330,7 +8332,8 @@ mod billing_from_payment_method_data {
|
||||
#[test]
|
||||
fn test_bank_redirect_payment_method_data_eps() {
|
||||
let test_email = Email::try_from("example@example.com".to_string()).unwrap();
|
||||
let test_first_name = Secret::new(String::from("Chaser"));
|
||||
let test_first_name =
|
||||
common_utils::types::NameType::try_from(String::from("Chaser")).unwrap();
|
||||
|
||||
let bank_redirect_billing = BankRedirectBilling {
|
||||
billing_name: Some(test_first_name.clone()),
|
||||
@ -8381,7 +8384,8 @@ mod billing_from_payment_method_data {
|
||||
#[test]
|
||||
fn test_bank_debit_payment_method_data_ach() {
|
||||
let test_email = Email::try_from("example@example.com".to_string()).unwrap();
|
||||
let test_first_name = Secret::new(String::from("Chaser"));
|
||||
let test_first_name =
|
||||
common_utils::types::NameType::try_from(String::from("Chaser")).unwrap();
|
||||
|
||||
let bank_redirect_billing = BankDebitBilling {
|
||||
name: Some(test_first_name.clone()),
|
||||
@ -8415,7 +8419,10 @@ mod billing_from_payment_method_data {
|
||||
#[test]
|
||||
fn test_card_payment_method_data() {
|
||||
let card_payment_method_data = PaymentMethodData::Card(Card {
|
||||
card_holder_name: Some(Secret::new(TEST_FIRST_NAME_SINGLE.into())),
|
||||
card_holder_name: Some(
|
||||
common_utils::types::NameType::try_from(TEST_FIRST_NAME_SINGLE.to_string())
|
||||
.unwrap(),
|
||||
),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
@ -8424,7 +8431,11 @@ mod billing_from_payment_method_data {
|
||||
let billing_address = billing_address.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
billing_address.address.unwrap().first_name.expose_option(),
|
||||
billing_address
|
||||
.address
|
||||
.unwrap()
|
||||
.first_name
|
||||
.map(String::from),
|
||||
Some(TEST_FIRST_NAME_SINGLE.into())
|
||||
);
|
||||
}
|
||||
@ -8441,7 +8452,9 @@ mod billing_from_payment_method_data {
|
||||
#[test]
|
||||
fn test_card_payment_method_data_full_name() {
|
||||
let card_payment_method_data = PaymentMethodData::Card(Card {
|
||||
card_holder_name: Some(Secret::new(TEST_FULL_NAME.into())),
|
||||
card_holder_name: Some(
|
||||
common_utils::types::NameType::try_from(TEST_FULL_NAME.to_string()).unwrap(),
|
||||
),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
@ -8449,12 +8462,12 @@ mod billing_from_payment_method_data {
|
||||
let billing_address = billing_details.address.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
billing_address.first_name.expose_option(),
|
||||
billing_address.first_name.map(String::from),
|
||||
Some(TEST_FIRST_NAME.into())
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
billing_address.last_name.expose_option(),
|
||||
billing_address.last_name.map(String::from),
|
||||
Some(TEST_LAST_NAME.into())
|
||||
);
|
||||
}
|
||||
@ -8462,7 +8475,9 @@ mod billing_from_payment_method_data {
|
||||
#[test]
|
||||
fn test_card_payment_method_data_empty_string() {
|
||||
let card_payment_method_data = PaymentMethodData::Card(Card {
|
||||
card_holder_name: Some(Secret::new("".to_string())),
|
||||
card_holder_name: Some(
|
||||
common_utils::types::NameType::try_from("".to_string()).unwrap(),
|
||||
),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
|
||||
@ -27,11 +27,11 @@ pub struct AchBankDebitAdditionalData {
|
||||
|
||||
/// Card holder's name
|
||||
#[schema(value_type = Option<String>, example = "John Doe")]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Bank account's owner name
|
||||
#[schema(value_type = Option<String>, example = "John Doe")]
|
||||
pub bank_account_holder_name: Option<Secret<String>>,
|
||||
pub bank_account_holder_name: Option<common_utils::types::NameType>,
|
||||
|
||||
/// Name of the bank
|
||||
#[schema(value_type = Option<BankNames>, example = "ach")]
|
||||
@ -58,7 +58,7 @@ pub struct BacsBankDebitAdditionalData {
|
||||
|
||||
/// Bank account's owner name
|
||||
#[schema(value_type = Option<String>, example = "John Doe")]
|
||||
pub bank_account_holder_name: Option<Secret<String>>,
|
||||
pub bank_account_holder_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
@ -73,7 +73,7 @@ pub struct BecsBankDebitAdditionalData {
|
||||
|
||||
/// Bank account's owner name
|
||||
#[schema(value_type = Option<String>, example = "John Doe")]
|
||||
pub bank_account_holder_name: Option<Secret<String>>,
|
||||
pub bank_account_holder_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
@ -84,7 +84,7 @@ pub struct SepaBankDebitAdditionalData {
|
||||
|
||||
/// Bank account's owner name
|
||||
#[schema(value_type = Option<String>, example = "John Doe")]
|
||||
pub bank_account_holder_name: Option<Secret<String>>,
|
||||
pub bank_account_holder_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
@ -110,7 +110,7 @@ pub struct BancontactBankRedirectAdditionalData {
|
||||
|
||||
/// The card holder's name
|
||||
#[schema(value_type = Option<String>, example = "John Test")]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
@ -194,7 +194,7 @@ pub struct GivexGiftCardAdditionalData {
|
||||
pub struct CardTokenAdditionalData {
|
||||
/// The card holder's name
|
||||
#[schema(value_type = String, example = "John Test")]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
|
||||
@ -254,7 +254,7 @@ pub struct CardPayout {
|
||||
|
||||
/// The card holder's name
|
||||
#[schema(value_type = String, example = "John Doe")]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
pub card_holder_name: Option<common_utils::types::NameType>,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug, Deserialize, Serialize, ToSchema)]
|
||||
|
||||
Reference in New Issue
Block a user