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: make amount_capturable zero when payment intent status is processing (#2163)

Hrithikeshd848b55a119e
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<F: Clone, T: types::Capturable>(
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<F: Clone, T: types::Capturable>(
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 {