From 04e9734800a9011d9ae7bd43f75c90a75a9a9334 Mon Sep 17 00:00:00 2001 From: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:45:33 +0530 Subject: [PATCH] fix(core): validate amount_to_capture in payment update (#3830) --- crates/router/src/core/payments/helpers.rs | 5 ++++- .../Scenario23- Update Amount/Payments - Update/request.json | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) 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": {