diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index f7c78b9fb24..88287d4a60d 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -2528,22 +2528,29 @@ pub fn should_store_payment_method_data_in_vault( #[instrument(skip_all)] pub(crate) fn validate_capture_method( capture_method: storage_enums::CaptureMethod, + connector: Option, ) -> RouterResult<()> { - utils::when( + // Determine the match criteria based on the connector + let match_criteria = if connector.as_deref() == Some("paybox") { + // For "paybox", allow both `Automatic` and `SequentialAutomatic` matches!( capture_method, storage_enums::CaptureMethod::Automatic | storage_enums::CaptureMethod::SequentialAutomatic - ), - || { - Err(report!(errors::ApiErrorResponse::PaymentUnexpectedState { - field_name: "capture_method".to_string(), - current_flow: "captured".to_string(), - current_value: capture_method.to_string(), - states: "manual, manual_multiple, scheduled".to_string() - })) - }, - ) + ) + } else { + // For other connectors, only allow `Automatic` + matches!(capture_method, storage_enums::CaptureMethod::Automatic) + }; + + utils::when(!match_criteria, || { + Err(report!(errors::ApiErrorResponse::PaymentUnexpectedState { + field_name: "capture_method".to_string(), + current_flow: "captured".to_string(), + current_value: capture_method.to_string(), + states: "manual, manual_multiple, scheduled".to_string(), + })) + }) } #[instrument(skip_all)] diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index 2451cbcd8e9..6f7fbc95470 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -102,7 +102,7 @@ impl GetTracker, api::PaymentsCaptu .map(|capture_amount| capture_amount.get_amount_as_i64()), )?; - helpers::validate_capture_method(capture_method)?; + helpers::validate_capture_method(capture_method, payment_attempt.connector.clone())?; let multiple_capture_data = if capture_method == enums::CaptureMethod::ManualMultiple { let amount_to_capture = request