Skip to content

refactor(payment_methods): refactor merchant payment method list for wallets #7866

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

Merged
merged 4 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,10 @@ pub enum PaymentMethodType {

impl PaymentMethodType {
pub fn should_check_for_customer_saved_payment_method_type(self) -> bool {
matches!(self, Self::ApplePay | Self::GooglePay | Self::SamsungPay)
matches!(
self,
Self::ApplePay | Self::GooglePay | Self::SamsungPay | Self::Paypal | Self::Klarna
)
}
pub fn to_display_name(&self) -> String {
let display_name = match self {
Expand Down
55 changes: 0 additions & 55 deletions crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3459,61 +3459,6 @@ pub async fn list_payment_methods(
response
);

// Filter out wallet payment method from mca if customer has already saved it
customer
.as_ref()
.async_map(|customer| async {
let wallet_pm_exists = response
.iter()
.any(|mca| mca.payment_method == enums::PaymentMethod::Wallet);
if wallet_pm_exists {
match db
.find_payment_method_by_customer_id_merchant_id_status(
&((&state).into()),
&key_store,
&customer.customer_id,
merchant_account.get_id(),
common_enums::PaymentMethodStatus::Active,
None,
merchant_account.storage_scheme,
)
.await
{
Ok(customer_payment_methods) => {
let customer_wallet_pm = customer_payment_methods
.iter()
.filter(|cust_pm| {
cust_pm.get_payment_method_type() == Some(enums::PaymentMethod::Wallet)
})
.collect::<Vec<_>>();

response.retain(|mca| {
!(mca.payment_method == enums::PaymentMethod::Wallet
&& customer_wallet_pm.iter().any(|cust_pm| {
cust_pm.get_payment_method_subtype() == Some(mca.payment_method_type)
}))
});

logger::debug!("Filtered out wallet payment method from mca since customer has already saved it");
Ok(())
}
Err(error) => {
if error.current_context().is_db_not_found() {
Ok(())
} else {
Err(error)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("failed to find payment methods for a customer")
}
}
}
} else {
Ok(())
}
})
.await
.transpose()?;

let mut pmt_to_auth_connector: HashMap<
enums::PaymentMethod,
HashMap<enums::PaymentMethodType, String>,
Expand Down
Loading