Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 33 additions & 26 deletions crates/router/src/core/revenue_recovery/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ impl Action {
})
.ok();

let is_expiry_update = account_updater_action.as_ref().map(storage::revenue_recovery_redis_operation::AccountUpdaterAction::is_expiry_update);

let _account_updater_result = account_updater_action
.async_map(|action| {
let customer_id = connector_customer_id.clone();
Expand Down Expand Up @@ -617,16 +619,16 @@ impl Action {
.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,
&platform,
profile,
payment_data.payment_attempt.id.get_string_repr().to_string(),
payments_response
)
.await?;
state,
common_enums::EventClass::Payments,
event_status,
payment_intent,
&platform,
profile,
payment_data.payment_attempt.id.get_string_repr().to_string(),
payments_response
)
.await?;

Ok(Self::SuccessfulPayment(
payment_data.payment_attempt.clone(),
Expand Down Expand Up @@ -711,25 +713,30 @@ impl Action {
.await
.ok();

// when account updater is an expiry update we dont want to update the hard decline flag to give it a chance to do a retry
let should_we_update_hard_decline_flag = is_expiry_update
.and_then(|is_expiry| is_expiry.then_some(false))
.or(is_hard_decline);

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,
&connector_customer_id,
&error_code,
&should_we_update_hard_decline_flag,
Some(&scheduled_token
.payment_processor_token_details
.payment_processor_token)
,
)
.await;

// unlocking the token
storage::revenue_recovery_redis_operation::RedisTokenManager::unlock_connector_customer_status(
state,
&connector_customer_id,
&payment_intent.id
)
.await;
let _unlock_connector_customer_id = storage::revenue_recovery_redis_operation::RedisTokenManager::unlock_connector_customer_status(
state,
&connector_customer_id,
&payment_intent.id
)
.await;

// Reopen calculate workflow on payment failure
Box::pin(reopen_calculate_workflow_on_payment_failure(
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/core/webhooks/recovery_incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ impl RevenueRecoveryAttempt {
card_type: revenue_recovery_attempt_data.card_info.card_type.clone(),
card_isin: revenue_recovery_attempt_data.card_info.card_isin.clone(),
},
is_active: Some(true), // Tokens created from recovery attempts are active by default
is_active: None, // Tokens created from recovery attempts are active by default
account_update_history: None, // No prior account update history exists for freshly ingested tokens
decision_threshold: None,
};
Expand All @@ -974,6 +974,7 @@ impl RevenueRecoveryAttempt {
state,
&connector_customer_id,
token_unit,
false,
)
.await
.change_context(errors::RevenueRecoveryError::RevenueRecoveryRedisInsertFailed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ impl RedisTokenManager {
state: &SessionState,
connector_customer_id: &str,
token_data: PaymentProcessorTokenStatus,
is_account_updater: bool,
) -> CustomResult<bool, errors::StorageError> {
let mut token_map =
Self::get_connector_customer_payment_processor_tokens(state, connector_customer_id)
Expand Down Expand Up @@ -612,9 +613,9 @@ impl RedisTokenManager {
.and_modify(|v| *v += value)
.or_insert(value);
}
existing_token.account_update_history = token_data.account_update_history.clone();
existing_token.payment_processor_token_details =
token_data.payment_processor_token_details.clone();
is_account_updater.then(|| existing_token.is_active = token_data.is_active);

existing_token
.modified_at
Expand All @@ -634,9 +635,6 @@ impl RedisTokenManager {
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;
token_data
.is_active
.map(|is_active| existing_token.is_active = Some(is_active));
});
})
.or_else(|| {
Expand Down Expand Up @@ -1326,16 +1324,26 @@ impl AccountUpdaterAction {
OffsetDateTime::now_utc().date(),
OffsetDateTime::now_utc().time(),
));
updated_token.daily_retry_history = HashMap::new();

RedisTokenManager::upsert_payment_processor_token(
state,
customer_id,
updated_token,
true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add comment here

)
.await?;

logger::info!("Successfully deactivated old token.");

let is_existing_token =
RedisTokenManager::get_payment_processor_token_using_token_id(
state,
customer_id,
new_token.to_owned().as_str(),
)
.await?;

let new_token = PaymentProcessorTokenStatus {
payment_processor_token_details: PaymentProcessorTokenDetails {
payment_processor_token: new_token.to_owned(),
Expand Down Expand Up @@ -1377,9 +1385,19 @@ impl AccountUpdaterAction {
decision_threshold: None,
};

RedisTokenManager::upsert_payment_processor_token(state, customer_id, new_token)
/// Check whether we got have the new token in redis or not. If we have it we dont have to anything. If it dosent we have to insert it inton Redis.
if is_existing_token.is_some() {
logger::info!("New token already exists. Skipping the insertion into Redis.");
} else {
RedisTokenManager::upsert_payment_processor_token(
state,
customer_id,
new_token,
true,
)
.await?;
logger::info!("Successfully updated token with new token information.")
logger::info!("Successfully updated token with new token information.");
Comment on lines +1389 to +1399
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we write match here

}
}
Self::ExpiryUpdate(updated_mandate_details) => {
logger::info!("Handling ExpiryUpdate action");
Expand All @@ -1398,6 +1416,8 @@ impl AccountUpdaterAction {
OffsetDateTime::now_utc().date(),
OffsetDateTime::now_utc().time(),
));
updated_token.is_active = Some(true);
updated_token.daily_retry_history = HashMap::new();
updated_token
.account_update_history
.get_or_insert_with(Vec::new)
Expand Down Expand Up @@ -1426,6 +1446,7 @@ impl AccountUpdaterAction {
state,
customer_id,
updated_token,
true,
)
.await?;

Expand All @@ -1443,4 +1464,8 @@ impl AccountUpdaterAction {

Ok(())
}

pub fn is_expiry_update(&self) -> bool {
matches!(self, Self::ExpiryUpdate(_))
}
}
Loading