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(revenue-recovery): fix the token fetch for A/B routing (#14539)

Rohan Malid206fe969f54
diff --git a/crates/router/src/core/revenue_recovery.rs b/crates/router/src/core/revenue_recovery.rs
index 1df0b54748..e9cb4444b3 100644
--- a/crates/router/src/core/revenue_recovery.rs
+++ b/crates/router/src/core/revenue_recovery.rs
@@ -432,12 +432,29 @@ pub async fn perform_execute_payment(
)
.await;
+ // Same dimensions calculate resolves the flag on
+ let ab_enabled = crate::core::configs::dimension_state::Dimensions::new()
+ .with_processor_merchant_id(payment_intent.merchant_id.clone().into())
+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())
+ .with_organization_id(payment_intent.organization_id.clone())
+ .with_profile_id(payment_intent.profile_id.clone())
+ .get_revenue_recovery_ab_enabled(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ None,
+ )
+ .await;
+
+ // Calculate schedules the invoice's own token on both the A/B and adaptive paths, and
+ // hands the invoice to the decider only when neither is on.
+ let smart_retry_uses_invoice_token = ab_enabled || adaptive_retry_enabled;
+
let processor_token = storage::revenue_recovery_redis_operation::RedisTokenManager::get_token_based_on_retry_type(
state,
&connector_customer_id,
tracking_data.revenue_recovery_retry,
last_token_used.as_deref(),
- adaptive_retry_enabled,
+ smart_retry_uses_invoice_token,
)
.await
.change_context(errors::ApiErrorResponse::GenericNotFoundError {
diff --git a/crates/router/src/types/storage/revenue_recovery_redis_operation.rs b/crates/router/src/types/storage/revenue_recovery_redis_operation.rs
index d41c4a1337..69f1c3f55d 100644
--- a/crates/router/src/types/storage/revenue_recovery_redis_operation.rs
+++ b/crates/router/src/types/storage/revenue_recovery_redis_operation.rs
@@ -949,14 +949,15 @@ impl RedisTokenManager {
}
// Get token based on retry type
- // Adaptive smart decides against the invoice's own token, so it resolves by id rather than
- // the `scheduled_at` marker, which only the decider writes and is shared across invoices.
+ // The A/B and adaptive smart paths decide against the invoice's own token, so they resolve it
+ // by id rather than the `scheduled_at` marker, which only the decider writes and is shared
+ // across invoices.
pub async fn get_token_based_on_retry_type(
state: &SessionState,
connector_customer_id: &str,
retry_algorithm_type: RevenueRecoveryAlgorithmType,
last_token_used: Option<&str>,
- adaptive_retry_enabled: bool,
+ smart_retry_uses_invoice_token: bool,
) -> CustomResult<Option<PaymentProcessorTokenStatus>, errors::StorageError> {
let mut token = None;
match retry_algorithm_type {
@@ -969,7 +970,7 @@ impl RedisTokenManager {
Self::get_invoice_token(state, connector_customer_id, last_token_used).await?;
}
- RevenueRecoveryAlgorithmType::Smart if adaptive_retry_enabled => {
+ RevenueRecoveryAlgorithmType::Smart if smart_retry_uses_invoice_token => {
token =
Self::get_invoice_token(state, connector_customer_id, last_token_used).await?;
}