Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(core): validate amount_to_capture in payment update (#3830)

Hrithikesh04e9734800a9
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 0eaf3c07ee..0baba7035c 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -677,8 +677,11 @@ pub fn validate_amount_to_capture_and_capture_method(
.unwrap_or(0);
let total_capturable_amount =
original_amount.map(|original_amount| original_amount + surcharge_amount);
+ let amount_to_capture = request
+ .amount_to_capture
+ .or(payment_attempt.and_then(|pa| pa.amount_to_capture));
if let Some((total_capturable_amount, amount_to_capture)) =
- total_capturable_amount.zip(request.amount_to_capture)
+ total_capturable_amount.zip(amount_to_capture)
{
utils::when(amount_to_capture != total_capturable_amount, || {
Err(report!(errors::ApiErrorResponse::PreconditionFailed {
diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario23- Update Amount/Payments - Update/request.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario23- Update Amount/Payments - Update/request.json
index 813d6dc24a..44023297d1 100644
--- a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario23- Update Amount/Payments - Update/request.json
+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario23- Update Amount/Payments - Update/request.json
@@ -18,7 +18,8 @@
}
},
"raw_json_formatted": {
- "amount": 1000
+ "amount": 1000,
+ "amount_to_capture": 1000
}
},
"url": {