New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(bank-debit): remove billingdetails from bankdebit pmd #4371
Merged
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c746961
refactor: remove billingdetails from bankdebit pmd
swangi-kumari 3378876
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] f0c23d0
refactor: add postman test for ach-bank-debit for stripe connector
swangi-kumari e43ce2a
refactor: postman test for ach in stripe
swangi-kumari 7c1e6d6
refactor: removed unused functions
swangi-kumari a0cc68a
refactor: fix
swangi-kumari 1f3aa2c
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] f1fc6a2
Merge branch 'main' into bank-debit-billing
swangi-kumari a7cd85e
refactor: use utils functions
swangi-kumari 9d4239f
refactor: address
swangi-kumari 42adde3
refactor: first name
swangi-kumari f4d4e1f
Merge remote-tracking branch 'origin' into bank-debit-billing
swangi-kumari ac4ba73
Merge branch 'main' into bank-debit-billing
swangi-kumari 8491ca1
refactor: resolve conflicts
swangi-kumari dec55ed
refactor: resolve conflicts
swangi-kumari cc45fb6
refactor: resolve comments
swangi-kumari File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1091,7 +1091,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>, | ||
|
@@ -1116,7 +1116,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>, | ||
|
@@ -1126,7 +1126,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>, | ||
|
@@ -1139,7 +1139,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>, | ||
|
@@ -1155,20 +1155,26 @@ 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| { | ||
address.first_name = bank_account_holder_name | ||
.or(address.first_name.as_ref()) | ||
.cloned(); | ||
address = address.map(|mut address| -> Address { | ||
address.address = address | ||
.address | ||
.map(|mut address_details| -> AddressDetails { | ||
address_details.first_name = bank_account_holder_name | ||
.or(address_details.first_name.as_ref()) | ||
.cloned(); | ||
address_details | ||
}); | ||
address | ||
}); | ||
|
||
Some(address) | ||
address | ||
} | ||
|
||
match self { | ||
|
@@ -1191,7 +1197,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(), | ||
), | ||
} | ||
} | ||
} | ||
|
@@ -1345,7 +1354,7 @@ impl GetAddressFromPaymentMethodData for PaymentMethodData { | |
Self::Wallet(wallet_data) => wallet_data.get_billing_address(), | ||
Self::PayLater(_) => None, | ||
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(_) | ||
|
@@ -2139,31 +2148,31 @@ 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>, | ||
} | ||
|
||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, what if 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, | ||
} | ||
}; | ||
|
@@ -4772,14 +4781,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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this changed?