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

feat(revenue_recovery): align recovery statuses with payment intent status (#15213)

balakrishna76ab6a77fb4d
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index 43308b6328..388dc30983 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -2367,12 +2367,13 @@ pub enum RecoveryStatus {
/// The payment has been successfully recovered through retry mechanisms.
/// This indicates that a previously failed payment has been completed.
Recovered,
+ /// The payment has been fully paid.
+ Succeeded,
+ /// The payment has been cancelled.
+ Cancelled,
/// The payment is scheduled for retry and will be processed automatically.
/// This status is shown when a retry is queued but not yet picked up for processing.
Scheduled,
- /// The payment has exceeded the maximum retry threshold but was never picked up for processing.
- /// This typically occurs when the payment is a hard decline that the merchant has not enabled for retry.
- NoPicked,
/// The payment is currently being processed with the payment gateway.
/// This status is shown during active retry attempts.
Processing,
@@ -2383,7 +2384,8 @@ pub enum RecoveryStatus {
/// This includes cases where all retries have been exhausted or the payment has hard decline errors.
Terminated,
/// The payment is being monitored for potential recovery.
- /// This status is shown when the attempt count is below the threshold and the system is waiting to pick it up.
+ /// This status is shown when the attempt count is below the threshold and the system is waiting to pick it up,
+ /// or the payment is waiting on customer or merchant action.
#[default]
Monitoring,
/// The payment is queued in the calculate workflow but has not yet been scheduled for execution.
@@ -2392,9 +2394,6 @@ pub enum RecoveryStatus {
/// The payment has been partially recovered through retry mechanisms.
/// This indicates that a partially captured payment has been processed.
PartiallyRecovered,
- /// The payment is pending action from the customer, merchant, or requires additional information.
- /// This status is shown for payments that require customer action, merchant action, payment method, confirmation, or capture.
- Pending,
}
/// Specifies how the payment method can be used for future payments.
diff --git a/crates/router/src/core/revenue_recovery.rs b/crates/router/src/core/revenue_recovery.rs
index b0bd70c0f6..bb7ab9ac83 100644
--- a/crates/router/src/core/revenue_recovery.rs
+++ b/crates/router/src/core/revenue_recovery.rs
@@ -2157,7 +2157,7 @@ pub fn map_recovery_status(
execute_process_tracker_status,
|| {
if attempt_count > max_retry_threshold {
- RecoveryStatus::NoPicked
+ RecoveryStatus::Terminated
} else {
RecoveryStatus::Monitoring
}
@@ -2175,23 +2175,22 @@ pub fn map_recovery_status(
}
// For all other intent statuses, return the mapped recovery status
- IntentStatus::Succeeded => RecoveryStatus::Recovered,
+ IntentStatus::Succeeded => RecoveryStatus::Succeeded,
IntentStatus::Processing | IntentStatus::PartiallyCapturedAndProcessing => {
RecoveryStatus::Processing
}
- IntentStatus::Cancelled
- | IntentStatus::CancelledPostCapture
+ IntentStatus::Cancelled => RecoveryStatus::Cancelled,
+ IntentStatus::CancelledPostCapture
| IntentStatus::Conflicted
| IntentStatus::Expired
| IntentStatus::Review => RecoveryStatus::Terminated,
- // For statuses that don't need recovery
IntentStatus::RequiresCustomerAction
| IntentStatus::RequiresMerchantAction
| IntentStatus::RequiresPaymentMethod
| IntentStatus::RequiresConfirmation
| IntentStatus::RequiresCapture
- | IntentStatus::PartiallyAuthorizedAndRequiresCapture => RecoveryStatus::Pending,
+ | IntentStatus::PartiallyAuthorizedAndRequiresCapture => RecoveryStatus::Monitoring,
}
}
@@ -2367,4 +2366,24 @@ mod tests {
assert_eq!(recovery_status, RecoveryStatus::Terminated);
}
+
+ #[test]
+ fn recovery_status_without_workflows_follows_the_intent() {
+ for (intent_status, attempt_count, expected) in [
+ (IntentStatus::Succeeded, 1, "succeeded"),
+ (IntentStatus::Cancelled, 1, "cancelled"),
+ (IntentStatus::CancelledPostCapture, 1, "terminated"),
+ (IntentStatus::RequiresPaymentMethod, 1, "monitoring"),
+ (IntentStatus::Failed, 3, "monitoring"),
+ (IntentStatus::Failed, 4, "terminated"),
+ ] {
+ let recovery_status = map_recovery_status(intent_status, None, None, attempt_count, 3);
+
+ assert_eq!(
+ serde_json::to_value(recovery_status).ok(),
+ Some(serde_json::json!(expected)),
+ "{intent_status:?} with {attempt_count} attempts"
+ );
+ }
+ }
}