fix(router): make payment method or token not necessary for recurring mandates (#293)

This commit is contained in:
ItsMeShashank
2023-01-05 14:58:38 +05:30
committed by GitHub
parent 2bd418302c
commit 0e04341f80
3 changed files with 37 additions and 34 deletions

View File

@ -368,12 +368,20 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentConfir
expected_format: "merchant_id from merchant account".to_string(),
})?;
helpers::validate_pm_or_token_given(&request.payment_token, &request.payment_method_data)?;
let mandate_type = helpers::validate_mandate(request)?;
let payment_id = core_utils::get_or_generate_id("payment_id", &given_payment_id, "pay")?;
if !matches!(
request.payment_method,
Some(api_models::enums::PaymentMethodType::Paypal)
) && !matches!(mandate_type, Some(api::MandateTxnType::RecurringMandateTxn))
{
helpers::validate_pm_or_token_given(
&request.payment_token,
&request.payment_method_data,
)?;
}
Ok((
Box::new(self),
operations::ValidateResult {

View File

@ -407,25 +407,6 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentCreate
None => None,
};
if request.confirm.unwrap_or(false) {
if !matches!(
request.payment_method,
Some(api_models::enums::PaymentMethodType::Paypal)
) {
helpers::validate_pm_or_token_given(
&request.payment_token,
&request.payment_method_data,
)?;
}
helpers::validate_customer_id_mandatory_cases_api(
&request.shipping,
&request.billing,
&request.setup_future_usage,
&request.customer_id,
)?;
}
let request_merchant_id = request.merchant_id.as_deref();
helpers::validate_merchant_id(&merchant_account.merchant_id, request_merchant_id)
.change_context(errors::ApiErrorResponse::MerchantAccountNotFound)?;
@ -443,6 +424,19 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentCreate
let mandate_type = helpers::validate_mandate(request)?;
if request.confirm.unwrap_or(false)
&& !matches!(
request.payment_method,
Some(api_models::enums::PaymentMethodType::Paypal)
)
&& !matches!(mandate_type, Some(api::MandateTxnType::RecurringMandateTxn))
{
helpers::validate_pm_or_token_given(
&request.payment_token,
&request.payment_method_data,
)?;
}
Ok((
Box::new(self),
operations::ValidateResult {

View File

@ -385,18 +385,6 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentUpdate
None => None,
};
if request.confirm.unwrap_or(false)
&& !matches!(
request.payment_method,
Some(api_models::enums::PaymentMethodType::Paypal)
)
{
helpers::validate_pm_or_token_given(
&request.payment_token,
&request.payment_method_data,
)?;
}
let request_merchant_id = request.merchant_id.as_deref();
helpers::validate_merchant_id(&merchant_account.merchant_id, request_merchant_id)
.change_context(errors::ApiErrorResponse::InvalidDataFormat {
@ -416,6 +404,19 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentUpdate
let mandate_type = helpers::validate_mandate(request)?;
let payment_id = core_utils::get_or_generate_id("payment_id", &given_payment_id, "pay")?;
if request.confirm.unwrap_or(false)
&& !matches!(
request.payment_method,
Some(api_enums::PaymentMethodType::Paypal)
)
&& !matches!(mandate_type, Some(api::MandateTxnType::RecurringMandateTxn))
{
helpers::validate_pm_or_token_given(
&request.payment_token,
&request.payment_method_data,
)?;
}
Ok((
Box::new(self),
operations::ValidateResult {