Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(payment-methods): fetch payment method details in payouts flow (#8729)

Kashif56d8ed72458f
diff --git a/crates/payment_methods/src/controller.rs b/crates/payment_methods/src/controller.rs
index bd5a9f316e..095788fa36 100644
--- a/crates/payment_methods/src/controller.rs
+++ b/crates/payment_methods/src/controller.rs
@@ -229,6 +229,12 @@ pub trait PaymentMethodsController {
merchant_id: &id_type::MerchantId,
card_network: Option<common_enums::CardNetwork>,
) -> errors::PmResult<()>;
+
+ #[cfg(feature = "v1")]
+ async fn get_card_details_from_locker(
+ &self,
+ pm: &payment_methods::PaymentMethod,
+ ) -> errors::PmResult<api::CardDetailFromLocker>;
}
pub async fn create_encrypted_data<T>(
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 8f29e05e15..7ba707316c 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -890,6 +890,14 @@ impl PaymentMethodsController for PmCards<'_> {
.await
}
+ #[cfg(feature = "v1")]
+ async fn get_card_details_from_locker(
+ &self,
+ pm: &domain::PaymentMethod,
+ ) -> errors::RouterResult<api::CardDetailFromLocker> {
+ get_card_details_from_locker(self.state, pm).await
+ }
+
#[cfg(feature = "v1")]
#[instrument(skip_all)]
async fn retrieve_payment_method(
@@ -4205,6 +4213,7 @@ pub async fn list_customer_payment_method(
&pm,
Some(parent_payment_method_token.clone()),
true,
+ false,
&merchant_context,
)
.await?;
@@ -4349,6 +4358,7 @@ pub async fn list_customer_payment_method(
}
#[cfg(feature = "v1")]
+#[allow(clippy::too_many_arguments)]
pub async fn get_pm_list_context(
state: &routes::SessionState,
payment_method: &enums::PaymentMethod,
@@ -4358,6 +4368,7 @@ pub async fn get_pm_list_context(
#[cfg(feature = "payouts")] parent_payment_method_token: Option<String>,
#[cfg(not(feature = "payouts"))] _parent_payment_method_token: Option<String>,
is_payment_associated: bool,
+ force_fetch_card_from_vault: bool,
merchant_context: &domain::MerchantContext,
) -> Result<Option<PaymentMethodListContext>, error_stack::Report<errors::ApiErrorResponse>> {
let cards = PmCards {
@@ -4366,7 +4377,11 @@ pub async fn get_pm_list_context(
};
let payment_method_retrieval_context = match payment_method {
enums::PaymentMethod::Card => {
- let card_details = cards.get_card_details_with_locker_fallback(pm).await?;
+ let card_details = if force_fetch_card_from_vault {
+ Some(cards.get_card_details_from_locker(pm).await?)
+ } else {
+ cards.get_card_details_with_locker_fallback(pm).await?
+ };
card_details.as_ref().map(|card| PaymentMethodListContext {
card_details: Some(card.clone()),
diff --git a/crates/router/src/core/payouts/validator.rs b/crates/router/src/core/payouts/validator.rs
index 3d58d1f367..198caa4b89 100644
--- a/crates/router/src/core/payouts/validator.rs
+++ b/crates/router/src/core/payouts/validator.rs
@@ -233,6 +233,7 @@ pub async fn validate_create_request(
payment_method,
None,
false,
+ true,
merchant_context,
)
.await?
@@ -243,7 +244,7 @@ pub async fn validate_create_request(
card_number: card.card_number.get_required_value("card_number")?,
card_holder_name: card.card_holder_name,
expiry_month: card.expiry_month.get_required_value("expiry_month")?,
- expiry_year: card.expiry_year.get_required_value("expiry_month")?,
+ expiry_year: card.expiry_year.get_required_value("expiry_year")?,
},
))),
(_, Some(bank)) => Ok(Some(payouts::PayoutMethodData::Bank(bank))),