Skip to content

Commit 2db39e8

Browse files
authored
refactor(payment_methods): filter applepay payment method from mca based on customer pm (#3953)
1 parent a1fd36a commit 2db39e8

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
@@ -1322,6 +1322,47 @@ pub async fn list_payment_methods(
13221322
.await?;
13231323
}
13241324

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

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

0 commit comments

Comments
 (0)