fix(router): add payment_method check in get_mandate_type (#5828)

This commit is contained in:
Sai Harsha Vardhan
2024-09-12 18:56:17 +05:30
committed by GitHub
parent 985761cfb3
commit 1929f56e2a
5 changed files with 17 additions and 9 deletions

View File

@ -51,6 +51,7 @@ pub fn get_mandate_type(
setup_future_usage: Option<enums::FutureUsage>, setup_future_usage: Option<enums::FutureUsage>,
customer_acceptance: Option<api_payments::CustomerAcceptance>, customer_acceptance: Option<api_payments::CustomerAcceptance>,
token: Option<String>, token: Option<String>,
payment_method: Option<enums::PaymentMethod>,
) -> CustomResult<Option<api::MandateTransactionType>, errors::ValidationError> { ) -> CustomResult<Option<api::MandateTransactionType>, errors::ValidationError> {
match ( match (
mandate_data.clone(), mandate_data.clone(),
@ -58,25 +59,28 @@ pub fn get_mandate_type(
setup_future_usage, setup_future_usage,
customer_acceptance.or(mandate_data.and_then(|m_data| m_data.customer_acceptance)), customer_acceptance.or(mandate_data.and_then(|m_data| m_data.customer_acceptance)),
token, token,
payment_method,
) { ) {
(Some(_), Some(_), Some(enums::FutureUsage::OffSession), Some(_), Some(_)) => { (Some(_), Some(_), Some(enums::FutureUsage::OffSession), Some(_), Some(_), _) => {
Err(errors::ValidationError::InvalidValue { Err(errors::ValidationError::InvalidValue {
message: "Expected one out of recurring_details and mandate_data but got both" message: "Expected one out of recurring_details and mandate_data but got both"
.to_string(), .to_string(),
} }
.into()) .into())
} }
(_, _, Some(enums::FutureUsage::OffSession), Some(_), Some(_)) (_, _, Some(enums::FutureUsage::OffSession), Some(_), Some(_), _)
| (_, _, Some(enums::FutureUsage::OffSession), Some(_), _) | (_, _, Some(enums::FutureUsage::OffSession), Some(_), _, _)
| (Some(_), _, Some(enums::FutureUsage::OffSession), _, _) => { | (Some(_), _, Some(enums::FutureUsage::OffSession), _, _, _) => {
Ok(Some(api::MandateTransactionType::NewMandateTransaction)) Ok(Some(api::MandateTransactionType::NewMandateTransaction))
} }
(_, _, Some(enums::FutureUsage::OffSession), _, Some(_)) (_, _, Some(enums::FutureUsage::OffSession), _, Some(_), _)
| (_, Some(_), _, _, _) | (_, Some(_), _, _, _, _)
| (_, _, Some(enums::FutureUsage::OffSession), _, _) => Ok(Some( | (_, _, Some(enums::FutureUsage::OffSession), _, _, Some(enums::PaymentMethod::Wallet)) => {
api::MandateTransactionType::RecurringMandateTransaction, Ok(Some(
)), api::MandateTransactionType::RecurringMandateTransaction,
))
}
_ => Ok(None), _ => Ok(None),
} }

View File

@ -111,6 +111,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
payment_intent.setup_future_usage, payment_intent.setup_future_usage,
request.customer_acceptance.clone(), request.customer_acceptance.clone(),
request.payment_token.clone(), request.payment_token.clone(),
payment_attempt.payment_method,
) )
.change_context(errors::ApiErrorResponse::MandateValidationFailed { .change_context(errors::ApiErrorResponse::MandateValidationFailed {
reason: "Expected one out of recurring_details and mandate_data but got both".into(), reason: "Expected one out of recurring_details and mandate_data but got both".into(),

View File

@ -524,6 +524,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
payment_intent.setup_future_usage, payment_intent.setup_future_usage,
request.customer_acceptance.clone(), request.customer_acceptance.clone(),
request.payment_token.clone(), request.payment_token.clone(),
payment_attempt.payment_method.or(request.payment_method),
) )
.change_context(errors::ApiErrorResponse::MandateValidationFailed { .change_context(errors::ApiErrorResponse::MandateValidationFailed {
reason: "Expected one out of recurring_details and mandate_data but got both".into(), reason: "Expected one out of recurring_details and mandate_data but got both".into(),

View File

@ -150,6 +150,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
request.setup_future_usage, request.setup_future_usage,
request.customer_acceptance.clone(), request.customer_acceptance.clone(),
request.payment_token.clone(), request.payment_token.clone(),
request.payment_method,
) )
.change_context(errors::ApiErrorResponse::MandateValidationFailed { .change_context(errors::ApiErrorResponse::MandateValidationFailed {
reason: "Expected one out of recurring_details and mandate_data but got both".into(), reason: "Expected one out of recurring_details and mandate_data but got both".into(),

View File

@ -136,6 +136,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
payment_intent.setup_future_usage, payment_intent.setup_future_usage,
request.customer_acceptance.clone(), request.customer_acceptance.clone(),
request.payment_token.clone(), request.payment_token.clone(),
payment_attempt.payment_method.or(request.payment_method),
) )
.change_context(errors::ApiErrorResponse::MandateValidationFailed { .change_context(errors::ApiErrorResponse::MandateValidationFailed {
reason: "Expected one out of recurring_details and mandate_data but got both".into(), reason: "Expected one out of recurring_details and mandate_data but got both".into(),