Skip to content

Commit 6ccbbf6

Browse files
committed
refactor(payment_methods): filter applepay payment method from mca based on customer pm
1 parent f132527 commit 6ccbbf6

File tree

1 file changed

+41
-0
lines changed
  • crates/router/src/core/payment_methods

1 file changed

+41
-0
lines changed

crates/router/src/core/payment_methods/cards.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,47 @@ pub async fn list_payment_methods(
13161316
.await?;
13171317
}
13181318

1319+
// Filter out applepay payment method from mca if customer has already saved it
1320+
response
1321+
.iter()
1322+
.position(|pm| {
1323+
pm.payment_method == enums::PaymentMethod::Wallet
1324+
&& pm.payment_method_type == enums::PaymentMethodType::ApplePay
1325+
})
1326+
.as_ref()
1327+
.zip(customer.as_ref())
1328+
.async_map(|(index, customer)| async {
1329+
match db
1330+
.find_payment_method_by_customer_id_merchant_id_list(
1331+
&customer.customer_id,
1332+
&merchant_account.merchant_id,
1333+
None,
1334+
)
1335+
.await
1336+
{
1337+
Ok(customer_payment_methods) => {
1338+
if customer_payment_methods.iter().any(|pm| {
1339+
pm.payment_method == enums::PaymentMethod::Wallet
1340+
&& pm.payment_method_type == Some(enums::PaymentMethodType::ApplePay)
1341+
}) {
1342+
response.remove(*index);
1343+
}
1344+
Ok(())
1345+
}
1346+
Err(error) => {
1347+
if error.current_context().is_db_not_found() {
1348+
Ok(())
1349+
} else {
1350+
Err(error)
1351+
.change_context(errors::ApiErrorResponse::InternalServerError)
1352+
.attach_printable("failed to find payment methods for a customer")
1353+
}
1354+
}
1355+
}
1356+
})
1357+
.await
1358+
.transpose()?;
1359+
13191360
let mut pmt_to_auth_connector = HashMap::new();
13201361

13211362
if let Some((payment_attempt, payment_intent)) =

0 commit comments

Comments
 (0)