mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
refactor(bank-debit): remove billingdetails from bankdebit pmd (#4371)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -1148,7 +1148,7 @@ pub enum BankDebitData {
|
||||
/// Payment Method data for Ach bank debit
|
||||
AchBankDebit {
|
||||
/// Billing details for bank debit
|
||||
billing_details: BankDebitBilling,
|
||||
billing_details: Option<BankDebitBilling>,
|
||||
/// Account number for ach bank debit payment
|
||||
#[schema(value_type = String, example = "000123456789")]
|
||||
account_number: Secret<String>,
|
||||
@ -1173,7 +1173,7 @@ pub enum BankDebitData {
|
||||
},
|
||||
SepaBankDebit {
|
||||
/// Billing details for bank debit
|
||||
billing_details: BankDebitBilling,
|
||||
billing_details: Option<BankDebitBilling>,
|
||||
/// International bank account number (iban) for SEPA
|
||||
#[schema(value_type = String, example = "DE89370400440532013000")]
|
||||
iban: Secret<String>,
|
||||
@ -1183,7 +1183,7 @@ pub enum BankDebitData {
|
||||
},
|
||||
BecsBankDebit {
|
||||
/// Billing details for bank debit
|
||||
billing_details: BankDebitBilling,
|
||||
billing_details: Option<BankDebitBilling>,
|
||||
/// Account number for Becs payment method
|
||||
#[schema(value_type = String, example = "000123456")]
|
||||
account_number: Secret<String>,
|
||||
@ -1196,7 +1196,7 @@ pub enum BankDebitData {
|
||||
},
|
||||
BacsBankDebit {
|
||||
/// Billing details for bank debit
|
||||
billing_details: BankDebitBilling,
|
||||
billing_details: Option<BankDebitBilling>,
|
||||
/// Account number for Bacs payment method
|
||||
#[schema(value_type = String, example = "00012345")]
|
||||
account_number: Secret<String>,
|
||||
@ -1212,11 +1212,12 @@ pub enum BankDebitData {
|
||||
impl GetAddressFromPaymentMethodData for BankDebitData {
|
||||
fn get_billing_address(&self) -> Option<Address> {
|
||||
fn get_billing_address_inner(
|
||||
bank_debit_billing: &BankDebitBilling,
|
||||
bank_debit_billing: Option<&BankDebitBilling>,
|
||||
bank_account_holder_name: Option<&Secret<String>>,
|
||||
) -> Option<Address> {
|
||||
// We will always have address here
|
||||
let mut address = bank_debit_billing.get_billing_address()?;
|
||||
let mut address = bank_debit_billing
|
||||
.and_then(GetAddressFromPaymentMethodData::get_billing_address)?;
|
||||
|
||||
// Prefer `account_holder_name` over `name`
|
||||
address.address.as_mut().map(|address| {
|
||||
@ -1248,7 +1249,10 @@ impl GetAddressFromPaymentMethodData for BankDebitData {
|
||||
billing_details,
|
||||
bank_account_holder_name,
|
||||
..
|
||||
} => get_billing_address_inner(billing_details, bank_account_holder_name.as_ref()),
|
||||
} => get_billing_address_inner(
|
||||
billing_details.as_ref(),
|
||||
bank_account_holder_name.as_ref(),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1447,7 +1451,7 @@ impl GetAddressFromPaymentMethodData for PaymentMethodData {
|
||||
Self::Wallet(wallet_data) => wallet_data.get_billing_address(),
|
||||
Self::PayLater(pay_later) => pay_later.get_billing_address(),
|
||||
Self::BankRedirect(_) => None,
|
||||
Self::BankDebit(_) => None,
|
||||
Self::BankDebit(bank_debit_data) => bank_debit_data.get_billing_address(),
|
||||
Self::BankTransfer(_) => None,
|
||||
Self::Voucher(voucher_data) => voucher_data.get_billing_address(),
|
||||
Self::Crypto(_)
|
||||
@ -2241,11 +2245,11 @@ impl GetAddressFromPaymentMethodData for BankTransferData {
|
||||
#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, ToSchema, Eq, PartialEq)]
|
||||
pub struct BankDebitBilling {
|
||||
/// The billing name for bank debits
|
||||
#[schema(value_type = String, example = "John Doe")]
|
||||
pub name: Secret<String>,
|
||||
#[schema(value_type = Option<String>, example = "John Doe")]
|
||||
pub name: Option<Secret<String>>,
|
||||
/// The billing email for bank debits
|
||||
#[schema(value_type = String, example = "example@example.com")]
|
||||
pub email: Email,
|
||||
#[schema(value_type = Option<String>, example = "example@example.com")]
|
||||
pub email: Option<Email>,
|
||||
/// The billing address for bank debits
|
||||
pub address: Option<AddressDetails>,
|
||||
}
|
||||
@ -2253,19 +2257,19 @@ pub struct BankDebitBilling {
|
||||
impl GetAddressFromPaymentMethodData for BankDebitBilling {
|
||||
fn get_billing_address(&self) -> Option<Address> {
|
||||
let address = if let Some(mut address) = self.address.clone() {
|
||||
address.first_name = Some(self.name.clone());
|
||||
address.first_name = self.name.clone().or(address.first_name);
|
||||
Address {
|
||||
address: Some(address),
|
||||
email: Some(self.email.clone()),
|
||||
email: self.email.clone(),
|
||||
phone: None,
|
||||
}
|
||||
} else {
|
||||
Address {
|
||||
address: Some(AddressDetails {
|
||||
first_name: Some(self.name.clone()),
|
||||
first_name: self.name.clone(),
|
||||
..AddressDetails::default()
|
||||
}),
|
||||
email: Some(self.email.clone()),
|
||||
email: self.email.clone(),
|
||||
phone: None,
|
||||
}
|
||||
};
|
||||
@ -4898,14 +4902,14 @@ mod billing_from_payment_method_data {
|
||||
let test_first_name = Secret::new(String::from("Chaser"));
|
||||
|
||||
let bank_redirect_billing = BankDebitBilling {
|
||||
name: test_first_name.clone(),
|
||||
name: Some(test_first_name.clone()),
|
||||
address: None,
|
||||
email: test_email.clone(),
|
||||
email: Some(test_email.clone()),
|
||||
};
|
||||
|
||||
let ach_bank_debit_payment_method_data =
|
||||
PaymentMethodData::BankDebit(BankDebitData::AchBankDebit {
|
||||
billing_details: bank_redirect_billing,
|
||||
billing_details: Some(bank_redirect_billing),
|
||||
account_number: Secret::new("1234".to_string()),
|
||||
routing_number: Secret::new("1235".to_string()),
|
||||
card_holder_name: None,
|
||||
|
||||
Reference in New Issue
Block a user