From 1929f56e2ab65fc8570eb492ebc4f254bd5092d0 Mon Sep 17 00:00:00 2001 From: Sai Harsha Vardhan <56996463+sai-harsha-vardhan@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:56:17 +0530 Subject: [PATCH] fix(router): add payment_method check in `get_mandate_type` (#5828) --- crates/router/src/core/mandate/helpers.rs | 22 +++++++++++-------- .../operations/payment_complete_authorize.rs | 1 + .../payments/operations/payment_confirm.rs | 1 + .../payments/operations/payment_create.rs | 1 + .../payments/operations/payment_update.rs | 1 + 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/crates/router/src/core/mandate/helpers.rs b/crates/router/src/core/mandate/helpers.rs index 96f00a0d20..52afa6e0e5 100644 --- a/crates/router/src/core/mandate/helpers.rs +++ b/crates/router/src/core/mandate/helpers.rs @@ -51,6 +51,7 @@ pub fn get_mandate_type( setup_future_usage: Option, customer_acceptance: Option, token: Option, + payment_method: Option, ) -> CustomResult, errors::ValidationError> { match ( mandate_data.clone(), @@ -58,25 +59,28 @@ pub fn get_mandate_type( setup_future_usage, customer_acceptance.or(mandate_data.and_then(|m_data| m_data.customer_acceptance)), token, + payment_method, ) { - (Some(_), Some(_), Some(enums::FutureUsage::OffSession), Some(_), Some(_)) => { + (Some(_), Some(_), Some(enums::FutureUsage::OffSession), Some(_), Some(_), _) => { Err(errors::ValidationError::InvalidValue { message: "Expected one out of recurring_details and mandate_data but got both" .to_string(), } .into()) } - (_, _, Some(enums::FutureUsage::OffSession), Some(_), Some(_)) - | (_, _, Some(enums::FutureUsage::OffSession), Some(_), _) - | (Some(_), _, Some(enums::FutureUsage::OffSession), _, _) => { + (_, _, Some(enums::FutureUsage::OffSession), Some(_), Some(_), _) + | (_, _, Some(enums::FutureUsage::OffSession), Some(_), _, _) + | (Some(_), _, Some(enums::FutureUsage::OffSession), _, _, _) => { Ok(Some(api::MandateTransactionType::NewMandateTransaction)) } - (_, _, Some(enums::FutureUsage::OffSession), _, Some(_)) - | (_, Some(_), _, _, _) - | (_, _, Some(enums::FutureUsage::OffSession), _, _) => Ok(Some( - api::MandateTransactionType::RecurringMandateTransaction, - )), + (_, _, Some(enums::FutureUsage::OffSession), _, Some(_), _) + | (_, Some(_), _, _, _, _) + | (_, _, Some(enums::FutureUsage::OffSession), _, _, Some(enums::PaymentMethod::Wallet)) => { + Ok(Some( + api::MandateTransactionType::RecurringMandateTransaction, + )) + } _ => Ok(None), } diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs index 0f9459b552..00eb0a3bc3 100644 --- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs +++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs @@ -111,6 +111,7 @@ impl GetTracker, api::PaymentsRequest> for Co payment_intent.setup_future_usage, request.customer_acceptance.clone(), request.payment_token.clone(), + payment_attempt.payment_method, ) .change_context(errors::ApiErrorResponse::MandateValidationFailed { reason: "Expected one out of recurring_details and mandate_data but got both".into(), diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index df2f8746e1..c4abe7ff86 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -524,6 +524,7 @@ impl GetTracker, api::PaymentsRequest> for Pa payment_intent.setup_future_usage, request.customer_acceptance.clone(), request.payment_token.clone(), + payment_attempt.payment_method.or(request.payment_method), ) .change_context(errors::ApiErrorResponse::MandateValidationFailed { reason: "Expected one out of recurring_details and mandate_data but got both".into(), diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index f590f79781..88489f4a03 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -150,6 +150,7 @@ impl GetTracker, api::PaymentsRequest> for Pa request.setup_future_usage, request.customer_acceptance.clone(), request.payment_token.clone(), + request.payment_method, ) .change_context(errors::ApiErrorResponse::MandateValidationFailed { reason: "Expected one out of recurring_details and mandate_data but got both".into(), diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 6928b8f6f7..3b243e8613 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -136,6 +136,7 @@ impl GetTracker, api::PaymentsRequest> for Pa payment_intent.setup_future_usage, request.customer_acceptance.clone(), request.payment_token.clone(), + payment_attempt.payment_method.or(request.payment_method), ) .change_context(errors::ApiErrorResponse::MandateValidationFailed { reason: "Expected one out of recurring_details and mandate_data but got both".into(),