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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(revenue_recovery): Change business status from EXECUTE_WORKFLOW_COMPLETE to EXECUTE_WORKFLOW_FAILURE (#10092)
Aniket Burman2201e2a3f764
diff --git a/crates/router/src/core/revenue_recovery.rs b/crates/router/src/core/revenue_recovery.rsindex 8354ca1626..9c9d6bf410 100644--- a/crates/router/src/core/revenue_recovery.rs+++ b/crates/router/src/core/revenue_recovery.rs@@ -294,7 +294,7 @@ pub async fn perform_execute_payment(db.as_scheduler().finish_process_with_business_status(execute_task_process.clone(),- business_status::EXECUTE_WORKFLOW_COMPLETE,+ business_status::EXECUTE_WORKFLOW_FAILURE,).await?;diff --git a/crates/router/src/core/webhooks/recovery_incoming.rs b/crates/router/src/core/webhooks/recovery_incoming.rsindex e16766ddf6..ed49f6f0a4 100644--- a/crates/router/src/core/webhooks/recovery_incoming.rs+++ b/crates/router/src/core/webhooks/recovery_incoming.rs@@ -908,7 +908,8 @@ impl RevenueRecoveryAttempt {payment_connector_name: Option<common_enums::connector_enums::Connector>,) -> CustomResult<(), errors::RevenueRecoveryError> {let revenue_recovery_attempt_data = &self.0;- let error_code = recovery_attempt.error_code.clone();++ let error_code = revenue_recovery_attempt_data.error_code.clone();let error_message = revenue_recovery_attempt_data.error_message.clone();let connector_name = payment_connector_name.ok_or(errors::RevenueRecoveryError::TransactionWebhookProcessingFailed)diff --git a/crates/router/src/types/storage/revenue_recovery_redis_operation.rs b/crates/router/src/types/storage/revenue_recovery_redis_operation.rsindex 7769ae97d0..70aa960d0a 100644--- a/crates/router/src/types/storage/revenue_recovery_redis_operation.rs+++ b/crates/router/src/types/storage/revenue_recovery_redis_operation.rs@@ -484,7 +484,7 @@ impl RedisTokenManager {let error_code = token_data.error_code.clone();- let modified_at = token_data.modified_at;+ let last_external_attempt_at = token_data.modified_at;let today = OffsetDateTime::now_utc().date();@@ -501,11 +501,25 @@ impl RedisTokenManager {.or_insert(value);}- (existing_token.modified_at < modified_at).then(|| {- existing_token.modified_at = modified_at;- error_code.map(|err| existing_token.error_code = Some(err));- existing_token.is_hard_decline = token_data.is_hard_decline;- });+ existing_token+ .modified_at+ .zip(last_external_attempt_at)+ .and_then(|(existing_token_modified_at, last_external_attempt_at)| {+ (last_external_attempt_at > existing_token_modified_at)+ .then_some(last_external_attempt_at)+ })+ .or_else(|| {+ existing_token+ .modified_at+ .is_none()+ .then_some(last_external_attempt_at)+ .flatten()+ })+ .map(|last_external_attempt_at| {+ existing_token.modified_at = Some(last_external_attempt_at);+ existing_token.error_code = error_code;+ existing_token.is_hard_decline = token_data.is_hard_decline;+ });}).or_else(|| {token_map.insert(token_id.clone(), token_data);diff --git a/crates/router/src/workflows/revenue_recovery.rs b/crates/router/src/workflows/revenue_recovery.rsindex 6d96bceca9..097c4a7982 100644--- a/crates/router/src/workflows/revenue_recovery.rs+++ b/crates/router/src/workflows/revenue_recovery.rs@@ -705,7 +705,7 @@ pub async fn get_best_psp_token_available_for_smart_retry(payment_intent: &PaymentIntent,) -> CustomResult<PaymentProcessorTokenResponse, errors::ProcessTrackerError> {// Lock using payment_id- let locked = RedisTokenManager::lock_connector_customer_status(+ let locked_acquired = RedisTokenManager::lock_connector_customer_status(state,connector_customer_id,&payment_intent.id,@@ -715,7 +715,7 @@ pub async fn get_best_psp_token_available_for_smart_retry(errors::RedisError::RedisConnectionError.into(),))?;- match locked {+ match locked_acquired {false => {let token_details =RedisTokenManager::get_payment_processor_metadata_for_connector_customer(@@ -905,7 +905,8 @@ pub async fn call_decider_for_payment_processor_tokens_select_closest_time(// Check if all tokens are hard declinedlet hard_decline_status = processor_tokens.values()- .all(|token| token.token_status.is_hard_decline.unwrap_or(false));+ .all(|token| token.token_status.is_hard_decline.unwrap_or(false))+ && !processor_tokens.is_empty();RedisTokenManager::unlock_connector_customer_status(state, connector_customer_id).await