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): Ensure payment attempt Insert and proxy call use the same payment processor token (#9935)

Aniket Burmanec18289a08d7
diff --git a/crates/router/src/core/revenue_recovery.rs b/crates/router/src/core/revenue_recovery.rs
index 5a9f32ab9d..8354ca1626 100644
--- a/crates/router/src/core/revenue_recovery.rs
+++ b/crates/router/src/core/revenue_recovery.rs
@@ -32,7 +32,10 @@ use crate::{
operations::{GetTrackerResponse, Operation},
transformers::GenerateResponse,
},
- revenue_recovery::types::RevenueRecoveryOutgoingWebhook,
+ revenue_recovery::types::{
+ reopen_calculate_workflow_on_payment_failure, RevenueRecoveryOutgoingWebhook,
+ },
+ revenue_recovery_data_backfill::unlock_connector_customer_status,
},
db::StorageInterface,
logger,
@@ -160,6 +163,73 @@ pub async fn upsert_calculate_pcr_task(
})
}
+#[allow(clippy::too_many_arguments)]
+pub async fn record_internal_attempt_and_execute_payment(
+ state: &SessionState,
+ execute_task_process: &storage::ProcessTracker,
+ profile: &domain::Profile,
+ merchant_context: domain::MerchantContext,
+ tracking_data: &pcr::RevenueRecoveryWorkflowTrackingData,
+ revenue_recovery_payment_data: &pcr::RevenueRecoveryPaymentData,
+ payment_intent: &PaymentIntent,
+ payment_processor_token: &storage::revenue_recovery_redis_operation::PaymentProcessorTokenStatus,
+ revenue_recovery_metadata: &mut api_models::payments::PaymentRevenueRecoveryMetadata,
+) -> Result<(), sch_errors::ProcessTrackerError> {
+ let db = &*state.store;
+
+ let card_info = api_models::payments::AdditionalCardInfo::foreign_from(payment_processor_token);
+
+ // record attempt call
+ let record_attempt = api::record_internal_attempt_api(
+ state,
+ payment_intent,
+ revenue_recovery_payment_data,
+ revenue_recovery_metadata,
+ card_info,
+ &payment_processor_token
+ .payment_processor_token_details
+ .payment_processor_token,
+ )
+ .await;
+
+ match record_attempt {
+ Ok(record_attempt_response) => {
+ let action = Box::pin(types::Action::execute_payment(
+ state,
+ revenue_recovery_payment_data.merchant_account.get_id(),
+ payment_intent,
+ execute_task_process,
+ profile,
+ merchant_context,
+ revenue_recovery_payment_data,
+ revenue_recovery_metadata,
+ &record_attempt_response.id,
+ payment_processor_token,
+ ))
+ .await?;
+ Box::pin(action.execute_payment_task_response_handler(
+ state,
+ payment_intent,
+ execute_task_process,
+ revenue_recovery_payment_data,
+ revenue_recovery_metadata,
+ ))
+ .await?;
+ }
+ Err(err) => {
+ logger::error!("Error while recording attempt: {:?}", err);
+ let pt_update = storage::ProcessTrackerUpdate::StatusUpdate {
+ status: enums::ProcessTrackerStatus::Pending,
+ business_status: Some(String::from(business_status::EXECUTE_WORKFLOW_REQUEUE)),
+ };
+ db.as_scheduler()
+ .update_process(execute_task_process.clone(), pt_update)
+ .await?;
+ }
+ }
+ Ok(())
+}
+
pub async fn perform_execute_payment(
state: &SessionState,
execute_task_process: &storage::ProcessTracker,
@@ -210,66 +280,55 @@ pub async fn perform_execute_payment(
&connector_customer_id,
tracking_data.revenue_recovery_retry,
last_token_used.as_deref(),
- )
- .await
- .change_context(errors::ApiErrorResponse::GenericNotFoundError {
- message: "Failed to fetch token details from redis".to_string(),
- })?
- .ok_or(errors::ApiErrorResponse::GenericNotFoundError {
- message: "Failed to fetch token details from redis".to_string(),
- })?;
- logger::info!("Token fetched from redis success");
- let card_info =
- api_models::payments::AdditionalCardInfo::foreign_from(&processor_token);
- // record attempt call
- let record_attempt = api::record_internal_attempt_api(
- state,
- payment_intent,
- revenue_recovery_payment_data,
- &revenue_recovery_metadata,
- card_info,
- &processor_token
- .payment_processor_token_details
- .payment_processor_token,
)
- .await;
+ .await
+ .change_context(errors::ApiErrorResponse::GenericNotFoundError {
+ message: "Failed to fetch token details from redis".to_string(),
+ })?;
+
+ match processor_token {
+ None => {
+ logger::info!("No Token fetched from redis");
- match record_attempt {
- Ok(record_attempt_response) => {
- let action = Box::pin(types::Action::execute_payment(
+ // Close the job if there is no token available
+ db.as_scheduler()
+ .finish_process_with_business_status(
+ execute_task_process.clone(),
+ business_status::EXECUTE_WORKFLOW_COMPLETE,
+ )
+ .await?;
+
+ Box::pin(reopen_calculate_workflow_on_payment_failure(
state,
- revenue_recovery_payment_data.merchant_account.get_id(),
- payment_intent,
execute_task_process,
profile,
merchant_context,
+ payment_intent,
revenue_recovery_payment_data,
- &revenue_recovery_metadata,
- &record_attempt_response.id,
+ &tracking_data.payment_attempt_id,
))
.await?;
- Box::pin(action.execute_payment_task_response_handler(
+
+ storage::revenue_recovery_redis_operation::RedisTokenManager::unlock_connector_customer_status(state, &connector_customer_id).await?;
+ }
+
+ Some(payment_processor_token) => {
+ logger::info!("Token fetched from redis success");
+
+ record_internal_attempt_and_execute_payment(
state,
- payment_intent,
execute_task_process,
+ profile,
+ merchant_context,
+ tracking_data,
revenue_recovery_payment_data,
+ payment_intent,
+ &payment_processor_token,
&mut revenue_recovery_metadata,
- ))
+ )
.await?;
}
- Err(err) => {
- logger::error!("Error while recording attempt: {:?}", err);
- let pt_update = storage::ProcessTrackerUpdate::StatusUpdate {
- status: enums::ProcessTrackerStatus::Pending,
- business_status: Some(String::from(
- business_status::EXECUTE_WORKFLOW_REQUEUE,
- )),
- };
- db.as_scheduler()
- .update_process(execute_task_process.clone(), pt_update)
- .await?;
- }
- }
+ };
}
types::Decision::Psync(attempt_status, attempt_id) => {
diff --git a/crates/router/src/core/revenue_recovery/types.rs b/crates/router/src/core/revenue_recovery/types.rs
index 6b0a267f66..5e6713982a 100644
--- a/crates/router/src/core/revenue_recovery/types.rs
+++ b/crates/router/src/core/revenue_recovery/types.rs
@@ -406,271 +406,187 @@ impl Action {
revenue_recovery_payment_data: &storage::revenue_recovery::RevenueRecoveryPaymentData,
revenue_recovery_metadata: &PaymentRevenueRecoveryMetadata,
latest_attempt_id: &id_type::GlobalAttemptId,
+ scheduled_token: &storage::revenue_recovery_redis_operation::PaymentProcessorTokenStatus,
) -> RecoveryResult<Self> {
let connector_customer_id = payment_intent
.extract_connector_customer_id_from_payment_intent()
.change_context(errors::RecoveryError::ValueNotFound)
.attach_printable("Failed to extract customer ID from payment intent")?;
- let tracking_data: pcr::RevenueRecoveryWorkflowTrackingData =
- serde_json::from_value(process.tracking_data.clone())
- .change_context(errors::RecoveryError::ValueNotFound)
- .attach_printable("Failed to deserialize the tracking data from process tracker")?;
+ let response = revenue_recovery_core::api::call_proxy_api(
+ state,
+ payment_intent,
+ revenue_recovery_payment_data,
+ revenue_recovery_metadata,
+ &scheduled_token
+ .payment_processor_token_details
+ .payment_processor_token,
+ )
+ .await;
- let last_token_used = payment_intent
- .feature_metadata
- .as_ref()
- .and_then(|fm| fm.payment_revenue_recovery_metadata.as_ref())
- .map(|rr| {
- rr.billing_connector_payment_details
- .payment_processor_token
- .clone()
- });
+ let recovery_payment_intent =
+ hyperswitch_domain_models::revenue_recovery::RecoveryPaymentIntent::from(
+ payment_intent,
+ );
+ // handle proxy api's response
+ match response {
+ Ok(payment_data) => match payment_data.payment_attempt.status.foreign_into() {
+ RevenueRecoveryPaymentsAttemptStatus::Succeeded => {
+ let recovery_payment_attempt =
+ hyperswitch_domain_models::revenue_recovery::RecoveryPaymentAttempt::from(
+ &payment_data.payment_attempt,
+ );
+
+ let recovery_payment_tuple = recovery_incoming_flow::RecoveryPaymentTuple::new(
+ &recovery_payment_intent,
+ &recovery_payment_attempt,
+ );
- let recovery_algorithm = tracking_data.revenue_recovery_retry;
+ // publish events to kafka
+ if let Err(e) = recovery_incoming_flow::RecoveryPaymentTuple::publish_revenue_recovery_event_to_kafka(
+ state,
+ &recovery_payment_tuple,
+ Some(process.retry_count+1)
+ )
+ .await{
+ router_env::logger::error!(
+ "Failed to publish revenue recovery event to kafka: {:?}",
+ e
+ );
+ };
- let scheduled_token = match storage::revenue_recovery_redis_operation::RedisTokenManager::get_token_based_on_retry_type(
- state,
- &connector_customer_id,
- recovery_algorithm,
- last_token_used.as_deref(),
- )
- .await {
- Ok(scheduled_token_opt) => scheduled_token_opt,
- Err(e) => {
- logger::error!(
- error = ?e,
- connector_customer_id = %connector_customer_id,
- "Failed to get PSP token status"
- );
- None
- }
- };
+ // update the status of token in redis
+ let _update_error_code = storage::revenue_recovery_redis_operation::RedisTokenManager::update_payment_processor_token_error_code_from_process_tracker(
+ state,
+ &connector_customer_id,
+ &None,
+ &None,
+ Some(&scheduled_token.payment_processor_token_details.payment_processor_token),
+ )
+ .await;
- match scheduled_token {
- Some(scheduled_token) => {
- let response = revenue_recovery_core::api::call_proxy_api(
- state,
- payment_intent,
- revenue_recovery_payment_data,
- revenue_recovery_metadata,
- &scheduled_token
- .payment_processor_token_details
- .payment_processor_token,
- )
- .await;
+ // unlocking the token
+ let _unlock_the_connector_customer_id = storage::revenue_recovery_redis_operation::RedisTokenManager::unlock_connector_customer_status(
+ state,
+ &connector_customer_id,
+ )
+ .await;
+
+ let event_status = common_enums::EventType::PaymentSucceeded;
- let recovery_payment_intent =
- hyperswitch_domain_models::revenue_recovery::RecoveryPaymentIntent::from(
+ let payments_response = payment_data
+ .clone()
+ .generate_response(
+ state,
+ None,
+ None,
+ None,
+ &merchant_context,
+ profile,
+ None,
+ )
+ .change_context(errors::RecoveryError::PaymentsResponseGenerationFailed)
+ .attach_printable("Failed while generating response for payment")?;
+
+ RevenueRecoveryOutgoingWebhook::send_outgoing_webhook_based_on_revenue_recovery_status(
+ state,
+ common_enums::EventClass::Payments,
+ event_status,
payment_intent,
- );
- // handle proxy api's response
- match response {
- Ok(payment_data) => match payment_data.payment_attempt.status.foreign_into() {
- RevenueRecoveryPaymentsAttemptStatus::Succeeded => {
- let recovery_payment_attempt =
- hyperswitch_domain_models::revenue_recovery::RecoveryPaymentAttempt::from(
- &payment_data.payment_attempt,
- );
-
- let recovery_payment_tuple =
- recovery_incoming_flow::RecoveryPaymentTuple::new(
- &recovery_payment_intent,
- &recovery_payment_attempt,
- );
-
- // publish events to kafka
- if let Err(e) = recovery_incoming_flow::RecoveryPaymentTuple::publish_revenue_recovery_event_to_kafka(
- state,
- &recovery_payment_tuple,
- Some(process.retry_count+1)
- )
- .await{
- router_env::logger::error!(
- "Failed to publish revenue recovery event to kafka: {:?}",
- e
- );
- };
-
- // update the status of token in redis
- let _update_error_code = storage::revenue_recovery_redis_operation::RedisTokenManager::update_payment_processor_token_error_code_from_process_tracker(
- state,
- &connector_customer_id,
- &None,
- &None,
- Some(&scheduled_token.payment_processor_token_details.payment_processor_token),
- )
- .await;
-
- // unlocking the token
- let _unlock_the_connector_customer_id = storage::revenue_recovery_redis_operation::RedisTokenManager::unlock_connector_customer_status(
- state,
- &connector_customer_id,
- )
- .await;
-
- let event_status = common_enums::EventType::PaymentSucceeded;
-
- let payments_response = payment_data
- .clone()
- .generate_response(
- state,
- None,
- None,
- None,
- &merchant_context,
- profile,
- None,
- )
- .change_context(
- errors::RecoveryError::PaymentsResponseGenerationFailed,
- )
- .attach_printable("Failed while generating response for payment")?;
-
- RevenueRecoveryOutgoingWebhook::send_outgoing_webhook_based_on_revenue_recovery_status(
- state,
- common_enums::EventClass::Payments,
- event_status,
- payment_intent,
- &merchant_context,
- profile,
- payment_data.payment_attempt.id.get_string_repr().to_string(),
- payments_response
- )
- .await?;
-
- Ok(Self::SuccessfulPayment(
- payment_data.payment_attempt.clone(),
- ))
- }
- RevenueRecoveryPaymentsAttemptStatus::Failed => {
- let recovery_payment_attempt =
- hyperswitch_domain_models::revenue_recovery::RecoveryPaymentAttempt::from(
- &payment_data.payment_attempt,
- );
-
- let recovery_payment_tuple =
- recovery_incoming_flow::RecoveryPaymentTuple::new(
- &recovery_payment_intent,
- &recovery_payment_attempt,
- );
-
- // publish events to kafka
- if let Err(e) = recovery_incoming_flow::RecoveryPaymentTuple::publish_revenue_recovery_event_to_kafka(
- state,
- &recovery_payment_tuple,
- Some(process.retry_count+1)
- )
- .await{
- router_env::logger::error!(
- "Failed to publish revenue recovery event to kafka: {:?}",
- e
- );
- };
-
- let error_code = payment_data
- .payment_attempt
- .clone()
- .error
- .map(|error| error.code);
-
- let is_hard_decline = revenue_recovery::check_hard_decline(
- state,
- &payment_data.payment_attempt,
- )
- .await
- .ok();
+ &merchant_context,
+ profile,
+ payment_data.payment_attempt.id.get_string_repr().to_string(),
+ payments_response
+ )
+ .await?;
- let _update_connector_customer_id = storage::revenue_recovery_redis_operation::RedisTokenManager::update_payment_processor_token_error_code_from_process_tracker(
- state,
- &connector_customer_id,
- &error_code,
- &is_hard_decline,
- Some(&scheduled_token
- .payment_processor_token_details
- .payment_processor_token)
- ,
- )
- .await;
-
- // unlocking the token
- let _unlock_connector_customer_id = storage::revenue_recovery_redis_operation::RedisTokenManager::unlock_connector_customer_status(
- state,
- &connector_customer_id,
- )
- .await;
-
- // Reopen calculate workflow on payment failure
- Box::pin(reopen_calculate_workflow_on_payment_failure(
- state,
- process,
- profile,
- merchant_context,
- payment_intent,
- revenue_recovery_payment_data,
- latest_attempt_id,
- ))
- .await?;
-
- // Return terminal failure to finish the current execute workflow
- Ok(Self::TerminalFailure(payment_data.payment_attempt.clone()))
- }
-
- RevenueRecoveryPaymentsAttemptStatus::Processing => {
- Ok(Self::SyncPayment(payment_data.payment_attempt.clone()))
- }
- RevenueRecoveryPaymentsAttemptStatus::InvalidStatus(action) => {
- logger::info!(?action, "Invalid Payment Status For PCR Payment");
- Ok(Self::ManualReviewAction)
- }
- },
- Err(err) =>
- // check for an active attempt being constructed or not
- {
- logger::error!(execute_payment_res=?err);
- Ok(Self::ReviewPayment)
- }
+ Ok(Self::SuccessfulPayment(
+ payment_data.payment_attempt.clone(),
+ ))
}
- }
- None => {
- let response = revenue_recovery_core::api::call_psync_api(
- state,
- payment_intent.get_id(),
- revenue_recovery_payment_data,
- true,
- true,
- )
- .await;
+ RevenueRecoveryPaymentsAttemptStatus::Failed => {
+ let recovery_payment_attempt =
+ hyperswitch_domain_models::revenue_recovery::RecoveryPaymentAttempt::from(
+ &payment_data.payment_attempt,
+ );
+
+ let recovery_payment_tuple = recovery_incoming_flow::RecoveryPaymentTuple::new(
+ &recovery_payment_intent,
+ &recovery_payment_attempt,
+ );
- let payment_status_data = response
- .change_context(errors::RecoveryError::PaymentCallFailed)
- .attach_printable("Error while executing the Psync call")?;
+ // publish events to kafka
+ if let Err(e) = recovery_incoming_flow::RecoveryPaymentTuple::publish_revenue_recovery_event_to_kafka(
+ state,
+ &recovery_payment_tuple,
+ Some(process.retry_count+1)
+ )
+ .await{
+ router_env::logger::error!(
+ "Failed to publish revenue recovery event to kafka: {:?}",
+ e
+ );
+ };
+
+ let error_code = payment_data
+ .payment_attempt
+ .clone()
+ .error
+ .map(|error| error.code);
- let payment_attempt = payment_status_data.payment_attempt;
+ let is_hard_decline =
+ revenue_recovery::check_hard_decline(state, &payment_data.payment_attempt)
+ .await
+ .ok();
- logger::info!(
- process_id = %process.id,
- connector_customer_id = %connector_customer_id,
- "No token available, finishing EXECUTE_WORKFLOW"
- );
+ let _update_connector_customer_id = storage::revenue_recovery_redis_operation::RedisTokenManager::update_payment_processor_token_error_code_from_process_tracker(
+ state,
+ &connector_customer_id,
+ &error_code,
+ &is_hard_decline,
+ Some(&scheduled_token
+ .payment_processor_token_details
+ .payment_processor_token)
+ ,
+ )
+ .await;
- state
- .store
- .as_scheduler()
- .finish_process_with_business_status(
- process.clone(),
- business_status::CALCULATE_WORKFLOW_FINISH,
+ // unlocking the token
+ let _unlock_connector_customer_id = storage::revenue_recovery_redis_operation::RedisTokenManager::unlock_connector_customer_status(
+ state,
+ &connector_customer_id,
)
- .await
- .change_context(errors::RecoveryError::ProcessTrackerFailure)
- .attach_printable("Failed to finish EXECUTE_WORKFLOW")?;
+ .await;
- logger::info!(
- process_id = %process.id,
- connector_customer_id = %connector_customer_id,
- "EXECUTE_WORKFLOW finished successfully"
- );
- Ok(Self::TerminalFailure(payment_attempt.clone()))
+ // Reopen calculate workflow on payment failure
+ Box::pin(reopen_calculate_workflow_on_payment_failure(
+ state,
+ process,
+ profile,
+ merchant_context,
+ payment_intent,
+ revenue_recovery_payment_data,
+ latest_attempt_id,
+ ))
+ .await?;
+
+ // Return terminal failure to finish the current execute workflow
+ Ok(Self::TerminalFailure(payment_data.payment_attempt.clone()))
+ }
+
+ RevenueRecoveryPaymentsAttemptStatus::Processing => {
+ Ok(Self::SyncPayment(payment_data.payment_attempt.clone()))
+ }
+ RevenueRecoveryPaymentsAttemptStatus::InvalidStatus(action) => {
+ logger::info!(?action, "Invalid Payment Status For PCR Payment");
+ Ok(Self::ManualReviewAction)
+ }
+ },
+ Err(err) =>
+ // check for an active attempt being constructed or not
+ {
+ logger::error!(execute_payment_res=?err);
+ Ok(Self::ReviewPayment)
}
}
}
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 d732d9baa7..fe19e1b325 100644
--- a/crates/router/src/types/storage/revenue_recovery_redis_operation.rs
+++ b/crates/router/src/types/storage/revenue_recovery_redis_operation.rs
@@ -127,7 +127,7 @@ impl RedisTokenManager {
state: &SessionState,
connector_customer_id: &str,
exp_in_seconds: i64,
- ) -> CustomResult<bool, errors::StorageError> {
+ ) -> CustomResult<(), errors::StorageError> {
let redis_conn =
state
.store
@@ -139,7 +139,7 @@ impl RedisTokenManager {
let lock_key = Self::get_connector_customer_lock_key(connector_customer_id);
let result: bool = redis_conn
- .set_expiry(&lock_key.into(), exp_in_seconds)
+ .set_expiry(&lock_key.clone().into(), exp_in_seconds)
.await
.map_or_else(
|error| {
@@ -149,14 +149,20 @@ impl RedisTokenManager {
|_| true,
);
- tracing::debug!(
- connector_customer_id = connector_customer_id,
- new_ttl_in_seconds = exp_in_seconds,
- ttl_updated = %result,
- "Connector customer lock TTL update with new expiry time"
- );
+ if result {
+ tracing::debug!(
+ lock_key = %lock_key,
+ new_ttl_in_seconds = exp_in_seconds,
+ "Redis key TTL updated successfully"
+ );
+ } else {
+ tracing::error!(
+ lock_key = %lock_key,
+ "Failed to update TTL: key not found or error occurred"
+ );
+ }
- Ok(result)
+ Ok(())
}
/// Unlock connector customer status
@@ -602,6 +608,49 @@ impl RedisTokenManager {
}
}
+ // Update all payment processor token schedule time to None
+ #[instrument(skip_all)]
+ pub async fn update_payment_processor_tokens_schedule_time_to_none(
+ state: &SessionState,
+ connector_customer_id: &str,
+ ) -> CustomResult<(), errors::StorageError> {
+ let tokens_map =
+ Self::get_connector_customer_payment_processor_tokens(state, connector_customer_id)
+ .await?;
+
+ let mut updated_tokens_map = HashMap::new();
+
+ for (token_id, status) in tokens_map {
+ let updated_status = PaymentProcessorTokenStatus {
+ payment_processor_token_details: status.payment_processor_token_details.clone(),
+ inserted_by_attempt_id: status.inserted_by_attempt_id.clone(),
+ error_code: status.error_code.clone(),
+ daily_retry_history: status.daily_retry_history.clone(),
+ scheduled_at: None,
+ is_hard_decline: status.is_hard_decline,
+ modified_at: Some(PrimitiveDateTime::new(
+ OffsetDateTime::now_utc().date(),
+ OffsetDateTime::now_utc().time(),
+ )),
+ };
+ updated_tokens_map.insert(token_id, updated_status);
+ }
+
+ Self::update_or_add_connector_customer_payment_processor_tokens(
+ state,
+ connector_customer_id,
+ updated_tokens_map,
+ )
+ .await?;
+
+ tracing::debug!(
+ connector_customer_id = connector_customer_id,
+ "Updated all payment processor tokens schedule time to None",
+ );
+
+ Ok(())
+ }
+
// Update payment processor token schedule time
#[instrument(skip_all)]
pub async fn update_payment_processor_token_schedule_time(
@@ -658,7 +707,7 @@ impl RedisTokenManager {
None => {
tracing::debug!(
connector_customer_id = connector_customer_id,
- "payment processor tokens with not found",
+ "Payment processor tokens not found",
);
Ok(false)
}
@@ -768,14 +817,37 @@ impl RedisTokenManager {
}
}
- token = token.and_then(|t| {
- t.is_hard_decline
- .unwrap_or(false)
- .then(|| {
- logger::error!("Token is hard declined");
- })
- .map_or(Some(t), |_| None)
- });
+ let token = match token {
+ Some(t) => {
+ if t.is_hard_decline.unwrap_or(false) {
+ // Update the schedule time to None for hard declined tokens
+
+ logger::warn!(
+ connector_customer_id = connector_customer_id,
+ "Token is hard declined, setting schedule time to None"
+ );
+
+ Self::update_payment_processor_token_schedule_time(
+ state,
+ connector_customer_id,
+ &t.payment_processor_token_details.payment_processor_token,
+ None,
+ )
+ .await?;
+
+ None
+ } else {
+ Some(t)
+ }
+ }
+ None => {
+ logger::warn!(
+ connector_customer_id = connector_customer_id,
+ "No token found for the customer",
+ );
+ None
+ }
+ };
Ok(token)
}
diff --git a/crates/router/src/workflows/revenue_recovery.rs b/crates/router/src/workflows/revenue_recovery.rs
index d11645ed43..2bf9ce768b 100644
--- a/crates/router/src/workflows/revenue_recovery.rs
+++ b/crates/router/src/workflows/revenue_recovery.rs
@@ -314,7 +314,10 @@ pub(crate) async fn get_schedule_time_for_smart_retry(
let card_network_str = card_network.map(|network| network.to_string());
- let card_issuer_str = card_info.card_issuer.clone();
+ let card_issuer_str = card_info
+ .card_issuer
+ .clone()
+ .filter(|card_issuer| !card_issuer.is_empty());
let card_funding_str = match card_info.card_type.as_deref() {
Some("card") => None,
@@ -915,6 +918,13 @@ pub async fn call_decider_for_payment_processor_tokens_select_closest_time(
Some(token) => {
tracing::debug!("Found payment processor token with least schedule time");
+ RedisTokenManager::update_payment_processor_tokens_schedule_time_to_none(
+ state,
+ connector_customer_id,
+ )
+ .await
+ .change_context(errors::ProcessTrackerError::EApiErrorResponse)?;
+
RedisTokenManager::update_payment_processor_token_schedule_time(
state,
connector_customer_id,