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
feat(core): Update Refund Status to Manual Review After All Process Tracker Retries Are Exhausted (#12755)
Anurag298e43e9dfc5
diff --git a/config/superposition_seed.toml b/config/superposition_seed.tomlindex cc3e739170..e19de19316 100644--- a/config/superposition_seed.toml+++ b/config/superposition_seed.toml@@ -2634,11 +2634,12 @@ pt_mapping_outgoing_connector_webhooks = { value = { default_mapping = { frequen],], start_after = 60 } }, schema = { type = "object" }, description = "Revenue recovery (PCR) payment retry process tracker mapping configuration", change_reason = "Initial setup" }"process_tracker.pt_mapping_refund_sync" = { value = { default_mapping = { frequencies = [- [- 300,- 5,- ],-], start_after = 60 }, max_retries_count = 5 }, schema = { type = "object" }, description = "Refund sync retry process tracker mapping configuration", change_reason = "Initial setup" }+ [1800, 4], # 30 min * 4 = 2 hours+ [7200, 2], # 2 hour * 2 = 4 hours+ [21600, 3], # 6 hour * 3 = 18 hours+ [43200, 4], # 12 hour * 4 = 48 hours+ [86400, 4], # 24 hour * 4 = 96 hours+], start_after = 60 }, max_retries_count = 17 }, schema = { type = "object" }, description = "Refund sync retry process tracker mapping configuration", change_reason = "Initial setup" }"payments.requires_cvv" = { value = true, schema = { type = "boolean" }, description = "Whether CVV is required for payments", change_reason = "Initial setup" }"routing.routing_result_source" = { value = "hyperswitch_routing", schema = { enum = ["decision_engine",diff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rsindex 18c2d22efd..aee9016f69 100644--- a/crates/router/src/core/configs/dimension_config.rs+++ b/crates/router/src/core/configs/dimension_config.rs@@ -648,7 +648,7 @@ impl DatabaseBackedConfig for PtMappingPaymentSync {config! {superposition_key = PT_MAPPING_REFUND_SYNC,output = scheduler::types::process_data::ConnectorPTMapping,- default = scheduler::types::process_data::ConnectorPTMapping::default(),+ default = scheduler::types::process_data::ConnectorPTMapping::refund_default(),object = true,requires = dimension_state::DimensionsWithProcessorMerchantIdAndConnector,targeting_key = id_type::PaymentIddiff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rsindex 9629b3a188..baa915b9ee 100644--- a/crates/router/src/core/refunds.rs+++ b/crates/router/src/core/refunds.rs@@ -814,20 +814,14 @@ fn should_call_refund(force_sync: bool,all_keys_required: bool,) -> bool {- // This implies, we cannot perform a refund sync & `the connector_refund_id`- // doesn't exist- let predicate1 = refund.connector_refund_id.is_some();-// This allows refund sync at connector level if all_keys_required or force_sync is enabled for non terminal refund statuses (i.e. not success or failure)- let predicate2 = all_keys_required+ all_keys_required|| (force_sync&& !matches!(refund.refund_status,diesel_models::enums::RefundStatus::Failure| diesel_models::enums::RefundStatus::Success- ));-- predicate1 && predicate2+ ))}#[allow(clippy::too_many_arguments)]@@ -1989,12 +1983,13 @@ pub async fn sync_refund_with_gateway_workflow(})?;let platform = core_utils::build_platform_from_refund_core(state, &refund_core).await?;+ let storage_scheme = platform.get_processor().get_account().storage_scheme;let response = Box::pin(refund_retrieve_core_with_internal_reference_id(state.clone(),platform,None,- refund_core.refund_internal_reference_id,+ refund_core.refund_internal_reference_id.clone(),Some(true),)).await?;@@ -2019,15 +2014,55 @@ pub async fn sync_refund_with_gateway_workflow(.processor_merchant_id.clone().unwrap_or(response.merchant_id);- _ = retry_refund_sync_task(+ let is_last_retry = retry_refund_sync_task(&*state.store,state.superposition_service.as_ref(),- response.connector,- processor_merchant_id,+ response.connector.clone(),+ processor_merchant_id.clone(),Some(refund_core.payment_id.clone()),refund_tracker.to_owned(),).await?;++ // If the refund status is still pending and there is no connector_refund_id+ // then move the refund status to manual review if all retries exceeded+ if is_last_retry+ && response.refund_status == enums::RefundStatus::Pending+ && response.connector_refund_id.is_none()+ {+ let processor_merchant_id = refund_core+ .processor_merchant_id+ .clone()+ .unwrap_or_else(|| refund_core.merchant_id.clone());++ let refund = state+ .store+ .find_refund_by_internal_reference_id_processor_merchant_id(+ &refund_core.refund_internal_reference_id,+ &processor_merchant_id,+ storage_scheme,+ )+ .await+ .change_context(errors::ApiErrorResponse::RefundNotFound)+ .attach_printable("Failed to fetch refund for failure update")?;++ let refund_update = diesel_refund::RefundUpdate::StatusUpdate {+ connector_refund_id: None,+ sent_to_gateway: response.sent_to_gateway,+ refund_status: enums::RefundStatus::ManualReview,+ updated_by: refund.updated_by.clone(),+ processor_refund_data: refund.processor_refund_data.clone(),+ };++ state+ .store+ .update_refund(refund, refund_update, storage_scheme)+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable(+ "Failed to update refund status to Failure after retries exhausted",+ )?;+ }}}diff --git a/crates/scheduler/src/consumer/types/process_data.rs b/crates/scheduler/src/consumer/types/process_data.rsindex 473511eb30..50c3ad13f1 100644--- a/crates/scheduler/src/consumer/types/process_data.rs+++ b/crates/scheduler/src/consumer/types/process_data.rs@@ -42,6 +42,24 @@ impl Default for ConnectorPTMapping {}}+impl ConnectorPTMapping {+ pub fn refund_default() -> Self {+ Self {+ default_mapping: RetryMapping {+ start_after: 60,+ frequencies: vec![+ (1800, 4), // 30 min * 4 = 2 hours+ (7200, 2), // 2 hour * 2 = 4 hours+ (21600, 3), // 6 hour * 3 = 18 hours+ (43200, 4), // 12 hour * 4 = 48 hours+ (86400, 4), // 24 hour * 4 = 96 hours+ ],+ },+ max_retries_count: 17,+ }+ }+}+#[derive(Serialize, Deserialize)]pub struct SubscriptionInvoiceSyncPTMapping {pub default_mapping: RetryMapping,