fix: make amount_capturable zero when payment intent status is processing (#2163)

This commit is contained in:
Hrithikesh
2023-09-15 11:30:31 +05:30
committed by GitHub
parent 5be2591cc4
commit d848b55a11
2 changed files with 24 additions and 3 deletions

View File

@ -18,7 +18,10 @@ use crate::{
services::RedirectForm, services::RedirectForm,
types::{ types::{
self, api, self, api,
storage::{self, enums, payment_attempt::PaymentAttemptExt}, storage::{
self, enums,
payment_attempt::{AttemptStatusExt, PaymentAttemptExt},
},
transformers::ForeignTryFrom, transformers::ForeignTryFrom,
CaptureSyncResponse, CaptureSyncResponse,
}, },
@ -320,7 +323,11 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
error_message: Some(Some(err.message)), error_message: Some(Some(err.message)),
error_code: Some(Some(err.code)), error_code: Some(Some(err.code)),
error_reason: Some(err.reason), 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) Some(0)
} else { } else {
None None
@ -432,7 +439,11 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
error_message: error_status.clone(), error_message: error_status.clone(),
error_reason: error_status, error_reason: error_status,
connector_response_reference_id, 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) Some(0)
} else { } else {
None None

View File

@ -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(test)]
#[cfg(feature = "dummy_connector")] #[cfg(feature = "dummy_connector")]
mod tests { mod tests {