diff --git a/crates/router/src/core/mandate/helpers.rs b/crates/router/src/core/mandate/helpers.rs index 7fb0cfa28a..2bb981d03e 100644 --- a/crates/router/src/core/mandate/helpers.rs +++ b/crates/router/src/core/mandate/helpers.rs @@ -70,9 +70,11 @@ pub fn get_mandate_type( Ok(Some(api::MandateTransactionType::NewMandateTransaction)) } - (_, _, Some(enums::FutureUsage::OffSession), _, Some(_)) | (_, Some(_), _, _, _) => Ok( - Some(api::MandateTransactionType::RecurringMandateTransaction), - ), + (_, _, Some(enums::FutureUsage::OffSession), _, Some(_)) + | (_, Some(_), _, _, _) + | (_, _, Some(enums::FutureUsage::OffSession), _, _) => Ok(Some( + api::MandateTransactionType::RecurringMandateTransaction, + )), _ => Ok(None), } diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 9802860ef9..e9df375ab6 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -533,6 +533,63 @@ pub async fn get_token_pm_type_mandate_details( mandate_generic_data.mandate_connector, mandate_generic_data.payment_method_info, ) + } else if request.payment_method_type + == Some(api_models::enums::PaymentMethodType::ApplePay) + || request.payment_method_type + == Some(api_models::enums::PaymentMethodType::GooglePay) + { + if let Some(customer_id) = &request.customer_id { + let customer_saved_pm_option = match state + .store + .find_payment_method_by_customer_id_merchant_id_list( + customer_id, + merchant_account.merchant_id.as_str(), + None, + ) + .await + { + Ok(customer_payment_methods) => Ok(customer_payment_methods + .iter() + .find(|payment_method| { + payment_method.payment_method_type + == request.payment_method_type + }) + .cloned()), + Err(error) => { + if error.current_context().is_db_not_found() { + Ok(None) + } else { + Err(error) + .change_context( + errors::ApiErrorResponse::InternalServerError, + ) + .attach_printable( + "failed to find payment methods for a customer", + ) + } + } + }?; + + ( + None, + request.payment_method, + request.payment_method_type, + None, + None, + None, + customer_saved_pm_option, + ) + } else { + ( + None, + request.payment_method, + request.payment_method_type, + None, + None, + None, + None, + ) + } } else { ( request.payment_token.to_owned(),