Skip to content

Commit

Permalink
init-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
awasthi21 committed Nov 19, 2024
1 parent be82db9 commit 0c53a66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 18 additions & 11 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
) -> 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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentData<F>, 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
Expand Down

0 comments on commit 0c53a66

Please sign in to comment.