From d848b55a119e426f809b46bd9d30b356ecd7ba2a Mon Sep 17 00:00:00 2001 From: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:30:31 +0530 Subject: [PATCH] fix: make amount_capturable zero when payment intent status is processing (#2163) --- .../payments/operations/payment_response.rs | 17 ++++++++++++++--- .../router/src/types/storage/payment_attempt.rs | 10 ++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 454c748779..3d91faf119 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -18,7 +18,10 @@ use crate::{ services::RedirectForm, types::{ self, api, - storage::{self, enums, payment_attempt::PaymentAttemptExt}, + storage::{ + self, enums, + payment_attempt::{AttemptStatusExt, PaymentAttemptExt}, + }, transformers::ForeignTryFrom, CaptureSyncResponse, }, @@ -320,7 +323,11 @@ async fn payment_response_update_tracker( error_message: Some(Some(err.message)), error_code: Some(Some(err.code)), error_reason: Some(err.reason), - amount_capturable: if status.is_terminal_status() { + amount_capturable: if status.is_terminal_status() + || router_data + .status + .maps_to_intent_status(enums::IntentStatus::Processing) + { Some(0) } else { None @@ -432,7 +439,11 @@ async fn payment_response_update_tracker( error_message: error_status.clone(), error_reason: error_status, connector_response_reference_id, - amount_capturable: if router_data.status.is_terminal_status() { + amount_capturable: if router_data.status.is_terminal_status() + || router_data + .status + .maps_to_intent_status(enums::IntentStatus::Processing) + { Some(0) } else { None diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs index 8b78be195a..b1f53a285e 100644 --- a/crates/router/src/types/storage/payment_attempt.rs +++ b/crates/router/src/types/storage/payment_attempt.rs @@ -69,6 +69,16 @@ impl PaymentAttemptExt for PaymentAttempt { } } +pub trait AttemptStatusExt { + fn maps_to_intent_status(self, intent_status: enums::IntentStatus) -> bool; +} + +impl AttemptStatusExt for enums::AttemptStatus { + fn maps_to_intent_status(self, intent_status: enums::IntentStatus) -> bool { + enums::IntentStatus::foreign_from(self) == intent_status + } +} + #[cfg(test)] #[cfg(feature = "dummy_connector")] mod tests {