Skip to content

Commit 1929f56

Browse files
fix(router): add payment_method check in get_mandate_type (#5828)
1 parent 985761c commit 1929f56

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

crates/router/src/core/mandate/helpers.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,36 @@ pub fn get_mandate_type(
5151
setup_future_usage: Option<enums::FutureUsage>,
5252
customer_acceptance: Option<api_payments::CustomerAcceptance>,
5353
token: Option<String>,
54+
payment_method: Option<enums::PaymentMethod>,
5455
) -> CustomResult<Option<api::MandateTransactionType>, errors::ValidationError> {
5556
match (
5657
mandate_data.clone(),
5758
off_session,
5859
setup_future_usage,
5960
customer_acceptance.or(mandate_data.and_then(|m_data| m_data.customer_acceptance)),
6061
token,
62+
payment_method,
6163
) {
62-
(Some(_), Some(_), Some(enums::FutureUsage::OffSession), Some(_), Some(_)) => {
64+
(Some(_), Some(_), Some(enums::FutureUsage::OffSession), Some(_), Some(_), _) => {
6365
Err(errors::ValidationError::InvalidValue {
6466
message: "Expected one out of recurring_details and mandate_data but got both"
6567
.to_string(),
6668
}
6769
.into())
6870
}
69-
(_, _, Some(enums::FutureUsage::OffSession), Some(_), Some(_))
70-
| (_, _, Some(enums::FutureUsage::OffSession), Some(_), _)
71-
| (Some(_), _, Some(enums::FutureUsage::OffSession), _, _) => {
71+
(_, _, Some(enums::FutureUsage::OffSession), Some(_), Some(_), _)
72+
| (_, _, Some(enums::FutureUsage::OffSession), Some(_), _, _)
73+
| (Some(_), _, Some(enums::FutureUsage::OffSession), _, _, _) => {
7274
Ok(Some(api::MandateTransactionType::NewMandateTransaction))
7375
}
7476

75-
(_, _, Some(enums::FutureUsage::OffSession), _, Some(_))
76-
| (_, Some(_), _, _, _)
77-
| (_, _, Some(enums::FutureUsage::OffSession), _, _) => Ok(Some(
78-
api::MandateTransactionType::RecurringMandateTransaction,
79-
)),
77+
(_, _, Some(enums::FutureUsage::OffSession), _, Some(_), _)
78+
| (_, Some(_), _, _, _, _)
79+
| (_, _, Some(enums::FutureUsage::OffSession), _, _, Some(enums::PaymentMethod::Wallet)) => {
80+
Ok(Some(
81+
api::MandateTransactionType::RecurringMandateTransaction,
82+
))
83+
}
8084

8185
_ => Ok(None),
8286
}

crates/router/src/core/payments/operations/payment_complete_authorize.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
111111
payment_intent.setup_future_usage,
112112
request.customer_acceptance.clone(),
113113
request.payment_token.clone(),
114+
payment_attempt.payment_method,
114115
)
115116
.change_context(errors::ApiErrorResponse::MandateValidationFailed {
116117
reason: "Expected one out of recurring_details and mandate_data but got both".into(),

crates/router/src/core/payments/operations/payment_confirm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
524524
payment_intent.setup_future_usage,
525525
request.customer_acceptance.clone(),
526526
request.payment_token.clone(),
527+
payment_attempt.payment_method.or(request.payment_method),
527528
)
528529
.change_context(errors::ApiErrorResponse::MandateValidationFailed {
529530
reason: "Expected one out of recurring_details and mandate_data but got both".into(),

crates/router/src/core/payments/operations/payment_create.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
150150
request.setup_future_usage,
151151
request.customer_acceptance.clone(),
152152
request.payment_token.clone(),
153+
request.payment_method,
153154
)
154155
.change_context(errors::ApiErrorResponse::MandateValidationFailed {
155156
reason: "Expected one out of recurring_details and mandate_data but got both".into(),

crates/router/src/core/payments/operations/payment_update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
136136
payment_intent.setup_future_usage,
137137
request.customer_acceptance.clone(),
138138
request.payment_token.clone(),
139+
payment_attempt.payment_method.or(request.payment_method),
139140
)
140141
.change_context(errors::ApiErrorResponse::MandateValidationFailed {
141142
reason: "Expected one out of recurring_details and mandate_data but got both".into(),

0 commit comments

Comments
 (0)