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(core): fix partial authz retries for smart (#10564)
chikke srujana14f982e8e4a
diff --git a/crates/router/src/core/revenue_recovery.rs b/crates/router/src/core/revenue_recovery.rsindex 2061c162a3..fbbbbd1117 100644--- a/crates/router/src/core/revenue_recovery.rs+++ b/crates/router/src/core/revenue_recovery.rs@@ -316,8 +316,18 @@ pub async fn perform_execute_payment(&tracking_data.payment_attempt_id,)).await?;-- storage::revenue_recovery_redis_operation::RedisTokenManager::unlock_connector_customer_status(state, &connector_customer_id, &payment_intent.id).await?;+ // Unlock the customer status only if all tokens are hard declined and payment intent is in Failed status+ let _unlocked = match payment_intent.status {+ IntentStatus::Failed => {+ storage::revenue_recovery_redis_operation::RedisTokenManager::unlock_connector_customer_status(+ state,+ &connector_customer_id,+ &payment_intent.id,+ )+ .await?+ }+ _ => false,+ };}Some(payment_processor_token) => {diff --git a/crates/router/src/workflows/revenue_recovery.rs b/crates/router/src/workflows/revenue_recovery.rsindex 8a52830876..eb8402ead6 100644--- a/crates/router/src/workflows/revenue_recovery.rs+++ b/crates/router/src/workflows/revenue_recovery.rs@@ -796,8 +796,17 @@ pub async fn get_best_psp_token_available_for_smart_retry(errors::RedisError::RedisConnectionError.into(),))?;- match locked_acquired {- false => {+ match (locked_acquired, payment_intent.status) {+ (true, _) | (false, common_enums::IntentStatus::PartiallyCaptured) => {+ let payment_processor_token_response = get_payment_processor_token_by_calling_decider(+ state,+ payment_intent,+ connector_customer_id,+ )+ .await?;+ Ok(payment_processor_token_response)+ }+ (false, _) => {let token_details =RedisTokenManager::get_payment_processor_metadata_for_connector_customer(state,@@ -836,39 +845,43 @@ pub async fn get_best_psp_token_available_for_smart_retry(Ok(payment_processor_token_response)}+ }+}- true => {- // Get existing tokens from Redis- let existing_tokens =- RedisTokenManager::get_connector_customer_payment_processor_tokens(- state,- connector_customer_id,- )- .await- .change_context(errors::ProcessTrackerError::ERedisError(- errors::RedisError::RedisConnectionError.into(),- ))?;+#[cfg(feature = "v2")]+async fn get_payment_processor_token_by_calling_decider(+ state: &SessionState,+ payment_intent: &PaymentIntent,+ connector_customer_id: &str,+) -> CustomResult<PaymentProcessorTokenResponse, errors::ProcessTrackerError> {+ // Get existing tokens from Redis+ let existing_tokens = RedisTokenManager::get_connector_customer_payment_processor_tokens(+ state,+ connector_customer_id,+ )+ .await+ .change_context(errors::ProcessTrackerError::ERedisError(+ errors::RedisError::RedisConnectionError.into(),+ ))?;- let active_tokens: HashMap<_, _> = existing_tokens- .into_iter()- .filter(|(_, token_status)| token_status.is_active != Some(false))- .collect();+ let active_tokens: HashMap<_, _> = existing_tokens+ .into_iter()+ .filter(|(_, token_status)| token_status.is_active != Some(false))+ .collect();- let result = RedisTokenManager::get_tokens_with_retry_metadata(state, &active_tokens);+ let result = RedisTokenManager::get_tokens_with_retry_metadata(state, &active_tokens);- let payment_processor_token_response =- call_decider_for_payment_processor_tokens_select_closest_time(- state,- &result,- payment_intent,- connector_customer_id,- )- .await- .change_context(errors::ProcessTrackerError::EApiErrorResponse)?;+ let payment_processor_token_response =+ call_decider_for_payment_processor_tokens_select_closest_time(+ state,+ &result,+ payment_intent,+ connector_customer_id,+ )+ .await+ .change_context(errors::ProcessTrackerError::EApiErrorResponse)?;- Ok(payment_processor_token_response)- }- }+ Ok(payment_processor_token_response)}#[cfg(feature = "v2")]@@ -1061,14 +1074,24 @@ pub async fn call_decider_for_payment_processor_tokens_select_closest_time(.values().all(|token| token.token_status.is_hard_decline.unwrap_or(false))&& !processor_tokens.is_empty();-- RedisTokenManager::unlock_connector_customer_status(- state,- connector_customer_id,- &payment_intent.id,- )- .await- .change_context(errors::ProcessTrackerError::EApiErrorResponse)?;+ // Unlock the customer status only if all tokens are hard declined and payment intent is in Failed status+ let _unlocked = match payment_intent.status {+ common_enums::enums::IntentStatus::Failed => {+ let lock_released = RedisTokenManager::unlock_connector_customer_status(+ state,+ connector_customer_id,+ &payment_intent.id,+ )+ .await+ .change_context(+ errors::ProcessTrackerError::ERedisError(+ errors::RedisError::RedisConnectionError.into(),+ ),+ )?;+ lock_released+ }+ _ => false,+ };tracing::debug!("No payment processor tokens available for scheduling");