mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 13:30:39 +08:00
fix(router): validate payment method data and type co-presence (#371)
This commit is contained in:
@ -989,6 +989,31 @@ pub(crate) fn validate_amount_to_capture(
|
||||
)
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
pub(crate) fn validate_payment_method_fields_present(
|
||||
req: &api::PaymentsRequest,
|
||||
) -> RouterResult<()> {
|
||||
utils::when(
|
||||
req.payment_method.is_none() && req.payment_method_data.is_some(),
|
||||
|| {
|
||||
Err(errors::ApiErrorResponse::MissingRequiredField {
|
||||
field_name: "payent_method".to_string(),
|
||||
})
|
||||
},
|
||||
)?;
|
||||
|
||||
utils::when(
|
||||
req.payment_method.is_some() && req.payment_method_data.is_none(),
|
||||
|| {
|
||||
Err(errors::ApiErrorResponse::MissingRequiredField {
|
||||
field_name: "payment_method_data".to_string(),
|
||||
})
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn can_call_connector(status: &storage_enums::AttemptStatus) -> bool {
|
||||
!matches!(
|
||||
status,
|
||||
@ -1295,7 +1320,7 @@ pub(crate) fn validate_pm_or_token_given(
|
||||
!matches!(payment_method, Some(api_enums::PaymentMethodType::Paypal))
|
||||
&& !matches!(mandate_type, Some(api::MandateTxnType::RecurringMandateTxn))
|
||||
&& token.is_none()
|
||||
&& payment_method_data.is_none(),
|
||||
&& (payment_method_data.is_none() || payment_method.is_none()),
|
||||
|| {
|
||||
Err(errors::ApiErrorResponse::InvalidRequestData {
|
||||
message: "A payment token or payment method data is required".to_string(),
|
||||
|
||||
@ -367,6 +367,8 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentConfir
|
||||
expected_format: "merchant_id from merchant account".to_string(),
|
||||
})?;
|
||||
|
||||
helpers::validate_payment_method_fields_present(request)?;
|
||||
|
||||
let mandate_type = helpers::validate_mandate(request)?;
|
||||
let payment_id = core_utils::get_or_generate_id("payment_id", &given_payment_id, "pay")?;
|
||||
|
||||
|
||||
@ -367,6 +367,8 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentCreate
|
||||
expected_format: "amount_to_capture lesser than amount".to_string(),
|
||||
})?;
|
||||
|
||||
helpers::validate_payment_method_fields_present(request)?;
|
||||
|
||||
let payment_id = core_utils::get_or_generate_id("payment_id", &given_payment_id, "pay")?;
|
||||
|
||||
let mandate_type = helpers::validate_mandate(request)?;
|
||||
|
||||
@ -405,6 +405,8 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentUpdate
|
||||
expected_format: "amount_to_capture lesser than or equal to amount".to_string(),
|
||||
})?;
|
||||
|
||||
helpers::validate_payment_method_fields_present(request)?;
|
||||
|
||||
let mandate_type = helpers::validate_mandate(request)?;
|
||||
let payment_id = core_utils::get_or_generate_id("payment_id", &given_payment_id, "pay")?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user