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(router): fix attempt status for techincal failures in psync flow (#2252)

Sai Harsha Vardhan2b8bd03a7243
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 4c62dd5caa..8a97b8139d 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -12,6 +12,7 @@ use crate::{
errors::{self, RouterResult, StorageErrorExt},
mandate,
payments::{types::MultipleCaptureData, PaymentData},
+ utils as core_utils,
},
db::StorageInterface,
routes::metrics,
@@ -311,10 +312,21 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
(Some((multiple_capture_data, capture_update_list)), None)
}
None => {
- let status = match err.status_code {
- 500..=511 => storage::enums::AttemptStatus::Pending,
- _ => storage::enums::AttemptStatus::Failure,
- };
+ let flow_name = core_utils::get_flow_name::<F>()?;
+ let status =
+ // mark previous attempt status for technical failures in PSync flow
+ if flow_name == "PSync" {
+ match err.status_code {
+ // marking failure for 2xx because this is genuine payment failure
+ 200..=299 => storage::enums::AttemptStatus::Failure,
+ _ => payment_data.payment_attempt.status,
+ }
+ } else {
+ match err.status_code {
+ 500..=511 => storage::enums::AttemptStatus::Pending,
+ _ => storage::enums::AttemptStatus::Failure,
+ }
+ };
(
None,
Some(storage::PaymentAttemptUpdate::ErrorUpdate {
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index bf34c13296..feec956d22 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -1033,3 +1033,15 @@ pub async fn get_profile_id_from_business_details(
},
}
}
+
+#[inline]
+pub fn get_flow_name<F>() -> RouterResult<String> {
+ Ok(std::any::type_name::<F>()
+ .to_string()
+ .rsplit("::")
+ .next()
+ .ok_or(errors::ApiErrorResponse::InternalServerError)
+ .into_report()
+ .attach_printable("Flow stringify failed")?
+ .to_string())
+}