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

feat(superposition): migrate object configs to superposition (#11625)

Aniket Burman3bcd559dd617
diff --git a/config/superposition_seed.toml b/config/superposition_seed.toml
index 22a8e321d2..2aa3389856 100644
--- a/config/superposition_seed.toml
+++ b/config/superposition_seed.toml
@@ -180,3 +180,67 @@ value = false
schema = { type = "boolean" }
description = "Whether a specific incoming webhook event is disabled for a given connector"
change_reason = "Initial setup"
+
+[default-configs.poll_config_external_three_ds]
+schema = { type = "object" }
+description = "Poll configuration for external 3DS authentication per connector"
+change_reason = "Initial setup"
+
+[default-configs.poll_config_external_three_ds.value]
+delay_in_secs = 2
+frequency = 5
+
+[default-configs.pt_mapping_outgoing_webhooks]
+schema = { type = "object" }
+description = "Outgoing webhook retry process tracker mapping configuration"
+change_reason = "Initial setup"
+
+[default-configs.pt_mapping_outgoing_webhooks.value.default_mapping]
+start_after = 60
+frequencies = [[300, 2], [600, 5], [3600, 5], [21600, 3]]
+
+[default-configs.pt_mapping_pcr_retries]
+schema = { type = "object" }
+description = "Revenue recovery (PCR) payment retry process tracker mapping configuration"
+change_reason = "Initial setup"
+
+[default-configs.pt_mapping_pcr_retries.value.default_mapping]
+start_after = 60
+frequencies = [[10800, 2], [21600, 3], [32400, 3], [43200, 3], [64800, 3]]
+
+[default-configs.pt_mapping_payment_sync]
+schema = { type = "object" }
+description = "Payment sync (psync) retry process tracker mapping configuration"
+change_reason = "Initial setup"
+
+[default-configs.pt_mapping_payment_sync.value]
+max_retries_count = 5
+
+[default-configs.pt_mapping_payment_sync.value.default_mapping]
+start_after = 60
+frequencies = [[300, 5]]
+
+[default-configs.pt_mapping_refund_sync]
+schema = { type = "object" }
+description = "Refund sync retry process tracker mapping configuration"
+change_reason = "Initial setup"
+
+[default-configs.pt_mapping_refund_sync.value]
+max_retries_count = 5
+
+[default-configs.pt_mapping_refund_sync.value.default_mapping]
+start_after = 60
+frequencies = [[300, 5]]
+
+[default-configs.pt_mapping_dispute_sync]
+schema = { type = "object" }
+description = "Dispute sync retry process tracker mapping configuration"
+change_reason = "Initial setup"
+
+[default-configs.pt_mapping_dispute_sync.value]
+max_retries_count = 5
+
+[default-configs.pt_mapping_dispute_sync.value.default_mapping]
+start_after = 60
+frequencies = [[300, 5]]
+
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 733f435943..d60ffc01b8 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -10510,6 +10510,7 @@ pub enum ApplePaySessionResponse {
ThirdPartySdk(ThirdPartySdkSessionResponse),
/// We get this session response, when there is no involvement of third party sdk
/// This is the common response most of the times
+ #[smithy(value_type = "smithy.api#Document")]
NoThirdPartySdk(serde_json::Value),
/// This is for the empty session response
#[smithy(value_type = "smithy.api#Unit")]
diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rs
index 5a5591d289..75235e7276 100644
--- a/crates/diesel_models/src/merchant_connector_account.rs
+++ b/crates/diesel_models/src/merchant_connector_account.rs
@@ -105,9 +105,9 @@ pub struct MerchantConnectorAccount {
pub connector_wallets_details: Option<Encryption>,
pub version: common_enums::ApiVersion,
pub id: id_type::MerchantConnectorAccountId,
- pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
#[serde(default)]
pub connector_webhook_registration_details: Option<serde_json::Value>,
+ pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
}
#[cfg(feature = "v2")]
diff --git a/crates/hyperswitch_domain_models/src/platform.rs b/crates/hyperswitch_domain_models/src/platform.rs
index 9a7ea46421..5b3a610f11 100644
--- a/crates/hyperswitch_domain_models/src/platform.rs
+++ b/crates/hyperswitch_domain_models/src/platform.rs
@@ -81,6 +81,12 @@ impl ProcessorMerchantId {
}
}
+impl From<common_utils::id_type::MerchantId> for ProcessorMerchantId {
+ fn from(id: common_utils::id_type::MerchantId) -> Self {
+ Self(id)
+ }
+}
+
/// Initiator = The entity that initiated the operation.
#[derive(Clone, Debug)]
pub enum Initiator {
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index 499259b884..e449ae5dc9 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -359,6 +359,18 @@ pub mod superposition {
pub const IMPLICIT_CUSTOMER_UPDATE: &str = "implicit_customer_update";
/// Fingerprint secret configuration key
pub const FINGERPRINT_SECRET: &str = "fingerprint_secret";
+ /// Poll config for external 3DS authentication key
+ pub const POLL_CONFIG_EXTERNAL_THREE_DS: &str = "poll_config_external_three_ds";
+ /// Outgoing webhook retry process tracker mapping key
+ pub const PT_MAPPING_OUTGOING_WEBHOOKS: &str = "pt_mapping_outgoing_webhooks";
+ /// PCR (Revenue Recovery) payments retry process tracker mapping key
+ pub const PT_MAPPING_PCR_RETRIES: &str = "pt_mapping_pcr_retries";
+ /// Payment sync (psync) retry process tracker mapping key
+ pub const PT_MAPPING_PAYMENT_SYNC: &str = "pt_mapping_payment_sync";
+ /// Refund sync retry process tracker mapping key
+ pub const PT_MAPPING_REFUND_SYNC: &str = "pt_mapping_refund_sync";
+ /// Dispute sync retry process tracker mapping key
+ pub const PT_MAPPING_DISPUTE_SYNC: &str = "pt_mapping_dispute_sync";
/// GSM (Global Status Map) call configuration key
pub const SHOULD_CALL_GSM: &str = "should_call_gsm";
/// Eligibility check configuration key
diff --git a/crates/router/src/core/authentication_client.rs b/crates/router/src/core/authentication_client.rs
index 8bba6cddc5..bcd80edc99 100644
--- a/crates/router/src/core/authentication_client.rs
+++ b/crates/router/src/core/authentication_client.rs
@@ -38,7 +38,7 @@ impl<'a> AuthenticationServiceClient<'a> {
}
}
-impl<'a> MicroserviceClient for AuthenticationServiceClient<'a> {
+impl MicroserviceClient for AuthenticationServiceClient<'_> {
fn base_url(&self) -> &Url {
&self.base_url
}
diff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rs
index d131741183..e37dbbff06 100644
--- a/crates/router/src/core/configs/dimension_config.rs
+++ b/crates/router/src/core/configs/dimension_config.rs
@@ -541,6 +541,60 @@ impl DatabaseBackedConfig for MaxAutoPayoutRetries {
}
}
+config! {
+ superposition_key = POLL_CONFIG_EXTERNAL_THREE_DS,
+ output = crate::types::PollConfig,
+ default = crate::types::PollConfig::default(),
+ object = true,
+ requires = dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
+ targeting_key = id_type::PaymentId
+}
+
+config! {
+ superposition_key = PT_MAPPING_OUTGOING_WEBHOOKS,
+ output = scheduler::types::process_data::OutgoingWebhookRetryProcessTrackerMapping,
+ default = scheduler::types::process_data::OutgoingWebhookRetryProcessTrackerMapping::default(),
+ object = true,
+ requires = dimension_state::DimensionsWithProcessorMerchantId,
+ targeting_key = id_type::PaymentId
+}
+
+config! {
+ superposition_key = PT_MAPPING_PCR_RETRIES,
+ output = scheduler::types::process_data::RevenueRecoveryPaymentProcessTrackerMapping,
+ default = scheduler::types::process_data::RevenueRecoveryPaymentProcessTrackerMapping::default(),
+ object = true,
+ requires = dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
+ targeting_key = id_type::PaymentId
+}
+
+config! {
+ superposition_key = PT_MAPPING_PAYMENT_SYNC,
+ output = scheduler::types::process_data::ConnectorPTMapping,
+ default = scheduler::types::process_data::ConnectorPTMapping::default(),
+ object = true,
+ requires = dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
+ targeting_key = id_type::PaymentId
+}
+
+config! {
+ superposition_key = PT_MAPPING_REFUND_SYNC,
+ output = scheduler::types::process_data::ConnectorPTMapping,
+ default = scheduler::types::process_data::ConnectorPTMapping::default(),
+ object = true,
+ requires = dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
+ targeting_key = id_type::PaymentId
+}
+
+config! {
+ superposition_key = PT_MAPPING_DISPUTE_SYNC,
+ output = scheduler::types::process_data::ConnectorPTMapping,
+ default = scheduler::types::process_data::ConnectorPTMapping::default(),
+ object = true,
+ requires = dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
+ targeting_key = id_type::PaymentId
+}
+
config! {
superposition_key = ROUTING_RESULT_SOURCE,
output = api_models::routing::RoutingResultSource,
diff --git a/crates/router/src/core/configs/dimension_state.rs b/crates/router/src/core/configs/dimension_state.rs
index 565fa3b9bf..167bd0348f 100644
--- a/crates/router/src/core/configs/dimension_state.rs
+++ b/crates/router/src/core/configs/dimension_state.rs
@@ -577,6 +577,17 @@ pub type DimensionsWithProcessorMerchantId = Dimensions<
NoWebhookEvent,
>;
+// Type alias - processor merchant ID and connector present
+pub type DimensionsWithProcessorMerchantIdAndConnector = Dimensions<
+ NoProviderMerchantId,
+ HasProcessorMerchantId,
+ NoOrgId,
+ NoProfileId,
+ HasConnector,
+ NoPayoutRetryType,
+ NoWebhookEvent,
+>;
+
// Type aliases - both provider and processor merchant IDs present
pub type DimensionsWithProcessorAndProviderMerchantId = Dimensions<
HasProviderMerchantId,
diff --git a/crates/router/src/core/disputes.rs b/crates/router/src/core/disputes.rs
index 4bc1caa3c8..599fedfff0 100644
--- a/crates/router/src/core/disputes.rs
+++ b/crates/router/src/core/disputes.rs
@@ -855,11 +855,23 @@ pub async fn fetch_disputes_from_connector(
.await;
if payment_attempt.is_ok() {
+ let payment_id = payment_attempt
+ .as_ref()
+ .ok()
+ .map(|pa| pa.payment_id.clone());
+ let connector_enum = connector_name
+ .parse::<common_enums::connector_enums::Connector>()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Invalid connector name")?;
+ let dimensions = crate::core::configs::dimension_state::Dimensions::new()
+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
+ .with_connector(connector_enum);
let schedule_time = process_dispute::get_sync_process_schedule_time(
&*state.store,
- &connector_name,
- platform.get_processor().get_account().get_id(),
+ state.superposition_service.as_ref(),
+ &dimensions,
0,
+ payment_id.as_ref(),
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index a1e628cf76..7bddf322d3 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -986,10 +986,22 @@ where
.map_err(|e| logger::error!(routable_connector_error=?e))
.unwrap_or_default();
let schedule_time = if should_add_task_to_process_tracker {
+ let connector_enum = connector
+ .connector_data
+ .connector
+ .id()
+ .parse::<common_enums::connector_enums::Connector>()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Invalid connector name")?;
+ let dimensions = Dimensions::new()
+ .with_processor_merchant_id(
+ platform.get_processor().get_processor_merchant_id(),
+ )
+ .with_connector(connector_enum);
payment_sync::get_sync_process_schedule_time(
&*state.store,
- connector.connector_data.connector.id(),
- platform.get_processor().get_account().get_id(),
+ state.superposition_service.as_ref(),
+ &dimensions,
0,
)
.await
@@ -1160,10 +1172,21 @@ where
)?;
let schedule_time = if should_add_task_to_process_tracker {
+ let connector_enum = connector_data
+ .connector
+ .id()
+ .parse::<common_enums::connector_enums::Connector>()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Invalid connector name")?;
+ let dimensions = Dimensions::new()
+ .with_processor_merchant_id(
+ platform.get_processor().get_processor_merchant_id(),
+ )
+ .with_connector(connector_enum);
payment_sync::get_sync_process_schedule_time(
&*state.store,
- connector_data.connector.id(),
- platform.get_processor().get_account().get_id(),
+ state.superposition_service.as_ref(),
+ &dimensions,
0,
)
.await
@@ -1623,10 +1646,19 @@ where
let locale = header_payload.locale.clone();
let schedule_time = if should_add_task_to_process_tracker {
+ let connector_enum = connector
+ .connector
+ .id()
+ .parse::<common_enums::connector_enums::Connector>()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Invalid connector name")?;
+ let dimensions = Dimensions::new()
+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
+ .with_connector(connector_enum);
payment_sync::get_sync_process_schedule_time(
&*state.store,
- connector.connector.id(),
- platform.get_processor().get_account().get_id(),
+ state.superposition_service.as_ref(),
+ &dimensions,
0,
)
.await
@@ -4414,25 +4446,20 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize {
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to add poll_id in redis")?;
};
- let default_poll_config = router_types::PollConfig::default();
- let default_config_str = default_poll_config
- .encode_to_string_of_json()
+ let connector_enum = common_enums::connector_enums::Connector::from_str(&connector)
.change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Error while stringifying default poll config")?;
- let poll_config = state
- .store
- .find_config_by_key_unwrap_or(
- &router_types::PollConfig::get_poll_config_key(connector),
- Some(default_config_str),
+ .attach_printable("Invalid connector name")?;
+ let merchant_id = platform.get_processor().get_account().get_id();
+ let dimensions = Dimensions::new()
+ .with_processor_merchant_id(merchant_id.clone().into())
+ .with_connector(connector_enum);
+ let poll_config = dimensions
+ .get_poll_config_external_three_ds(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ Some(&payment_id),
)
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("The poll config was not found in the DB")?;
- let poll_config: router_types::PollConfig = poll_config
- .config
- .parse_struct("PollConfig")
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Error while parsing PollConfig")?;
+ .await;
let profile_id = payments_response
.profile_id
.as_ref()
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index d71baf8300..83931e0a05 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -9,7 +9,7 @@ use api_models::{
payments::{ExtendedCardInfo, GetAddressFromPaymentMethodData},
};
use async_trait::async_trait;
-use common_utils::ext_traits::{AsyncExt, Encode, StringExt, ValueExt};
+use common_utils::ext_traits::{AsyncExt, Encode, ValueExt};
use diesel_models::payment_attempt::ConnectorMandateReferenceId as DieselConnectorMandateReferenceId;
use error_stack::{report, ResultExt};
use futures::FutureExt;
@@ -58,7 +58,6 @@ use crate::{
routes::{app::ReqState, SessionState},
services,
types::{
- self,
api::{self, ConnectorCallType, PaymentIdTypeExt},
domain::{self},
storage::{self, enums as storage_enums},
@@ -1504,13 +1503,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.is_failed()
{
*should_continue_confirm_transaction = false;
- let default_poll_config = types::PollConfig::default();
- let default_config_str = default_poll_config
- .encode_to_string_of_json()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Error while stringifying default poll config")?;
-
- // raise error if authentication_connector is not present since it should we be present in the current flow
+ // raise error if authentication_connector is not present since it should be present in the current flow
let authentication_connector = authentication_store
.authentication
.authentication_connector
@@ -1519,21 +1512,20 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.attach_printable(
"authentication_connector not present in authentication record",
)?;
-
- let poll_config = state
- .store
- .find_config_by_key_unwrap_or(
- &types::PollConfig::get_poll_config_key(authentication_connector),
- Some(default_config_str),
- )
- .await
+ let connector = authentication_connector
+ .parse::<common_enums::connector_enums::Connector>()
.change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("The poll config was not found in the DB")?;
- let poll_config: types::PollConfig = poll_config
- .config
- .parse_struct("PollConfig")
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Error while parsing PollConfig")?;
+ .attach_printable("Invalid authentication connector name")?;
+ let dimensions = dimension_state::Dimensions::new()
+ .with_processor_merchant_id(processor.get_processor_merchant_id())
+ .with_connector(connector);
+ let poll_config = dimensions
+ .get_poll_config_external_three_ds(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ Some(payment_data.payment_intent.get_id()),
+ )
+ .await;
payment_data.poll_config = Some(poll_config)
}
Some(authentication_store)
@@ -2051,33 +2043,25 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
|| eligibility_response.status.is_failed()
{
*should_continue_confirm_transaction = false;
- let default_poll_config = types::PollConfig::default();
- let default_config_str = default_poll_config
- .encode_to_string_of_json()
+ // raise error if authentication_connector is not present since it should be present in the current flow
+ let authentication_connector = authentication_create_response.authentication_connector
+ .ok_or(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("authentication_connector not found in eligibility_response")?;
+ let connector = authentication_connector
+ .to_string()
+ .parse::<common_enums::connector_enums::Connector>()
.change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Error while stringifying default poll config")?;
-
- // raise error if authentication_connector is not present since it should we be present in the current flow
- let authentication_connector = eligibility_response.authentication_connector
- .ok_or(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("authentication_connector not found in eligibility_response")?;
-
- let poll_config = state
- .store
- .find_config_by_key_unwrap_or(
- &types::PollConfig::get_poll_config_key(
- authentication_connector.to_string()
- ),
- Some(default_config_str),
+ .attach_printable("Invalid authentication connector name")?;
+ let dimensions = dimension_state::Dimensions::new()
+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
+ .with_connector(connector);
+ let poll_config = dimensions
+ .get_poll_config_external_three_ds(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ Some(payment_data.payment_intent.get_id()),
)
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("The poll config was not found in the DB")?;
- let poll_config: types::PollConfig = poll_config
- .config
- .parse_struct("PollConfig")
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Error while parsing PollConfig")?;
+ .await;
payment_data.poll_config = Some(poll_config)
}
@@ -2132,15 +2116,14 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
authentication_id: authentication_id.clone(),
};
- let response = crate::core::authentication_client::AuthenticationSyncFlow::call(
+ crate::core::authentication_client::AuthenticationSyncFlow::call(
state,
&client,
(sync_req, business_profile.merchant_id.get_string_repr().to_owned()),
).await
.change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Failed to call authentication sync flow")?;
+ .attach_printable("Failed to call authentication sync flow")?
- response
}
} else {
return Err(errors::ApiErrorResponse::InternalServerError).attach_printable("Pull mechanism disabled or terminal status during post-authentication sync")?;
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index d2bccc1d22..def08b8eee 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -6,7 +6,7 @@ use api_models::admin::MerchantConnectorInfo;
use api_models::enums as api_enums;
use common_enums::ExecutionMode;
use common_utils::{
- ext_traits::{AsyncExt, StringExt},
+ ext_traits::AsyncExt,
types::{ConnectorTransactionId, MinorUnit},
};
use diesel_models::{process_tracker::business_status, refund as diesel_refund};
@@ -20,9 +20,7 @@ use hyperswitch_interfaces::{
integrity::{CheckIntegrity, FlowIntegrity, GetIntegrityObject},
};
use router_env::{instrument, tracing, tracing::Instrument};
-use scheduler::{
- consumer::types::process_data, errors as sch_errors, utils as process_tracker_utils,
-};
+use scheduler::{errors as sch_errors, utils as process_tracker_utils};
#[cfg(feature = "olap")]
use strum::IntoEnumIterator;
@@ -1927,6 +1925,7 @@ pub async fn schedule_refund_execution(
Ok((updated_refund_data, raw_connector_response)) => {
add_refund_sync_task(
db,
+ state.superposition_service.as_ref(),
&updated_refund_data,
runner,
state.conf.application_source
@@ -1954,6 +1953,7 @@ pub async fn schedule_refund_execution(
api_models::refunds::RefundType::Scheduled => {
add_refund_sync_task(
db,
+ state.superposition_service.as_ref(),
&refund,
runner,
state.conf.application_source
@@ -2027,8 +2027,10 @@ pub async fn sync_refund_with_gateway_workflow(
_ => {
_ = retry_refund_sync_task(
&*state.store,
+ state.superposition_service.as_ref(),
response.connector,
response.merchant_id,
+ Some(refund_core.payment_id.clone()),
refund_tracker.to_owned(),
)
.await?;
@@ -2043,13 +2045,26 @@ pub async fn sync_refund_with_gateway_workflow(
/// Returns bool which indicates whether this was the last refund retry or not
pub async fn retry_refund_sync_task(
db: &dyn db::StorageInterface,
+ superposition_client: &external_services::superposition::SuperpositionClient,
connector: String,
merchant_id: common_utils::id_type::MerchantId,
+ payment_id: Option<common_utils::id_type::PaymentId>,
pt: storage::ProcessTracker,
) -> Result<bool, sch_errors::ProcessTrackerError> {
- let schedule_time =
- get_refund_sync_process_schedule_time(db, &connector, &merchant_id, pt.retry_count + 1)
- .await?;
+ let connector_enum = connector
+ .parse::<common_enums::connector_enums::Connector>()
+ .map_err(|_| sch_errors::ProcessTrackerError::UnexpectedFlow)?;
+ let dimensions = crate::core::configs::dimension_state::Dimensions::new()
+ .with_processor_merchant_id(merchant_id.into())
+ .with_connector(connector_enum);
+ let schedule_time = get_refund_sync_process_schedule_time(
+ db,
+ superposition_client,
+ &dimensions,
+ pt.retry_count + 1,
+ payment_id.as_ref(),
+ )
+ .await?;
match schedule_time {
Some(s_time) => {
@@ -2156,6 +2171,7 @@ pub async fn trigger_refund_execute_workflow(
.await?;
add_refund_sync_task(
db,
+ state.superposition_service.as_ref(),
&updated_refund,
storage::ProcessTrackerRunner::RefundWorkflowRouter,
state.conf.application_source,
@@ -2166,6 +2182,7 @@ pub async fn trigger_refund_execute_workflow(
// create sync task
add_refund_sync_task(
db,
+ state.superposition_service.as_ref(),
&refund,
storage::ProcessTrackerRunner::RefundWorkflowRouter,
state.conf.application_source,
@@ -2202,18 +2219,32 @@ pub fn refund_to_refund_core_workflow_model(
#[instrument(skip_all)]
pub async fn add_refund_sync_task(
db: &dyn db::StorageInterface,
+ superposition_client: &external_services::superposition::SuperpositionClient,
refund: &diesel_refund::Refund,
runner: storage::ProcessTrackerRunner,
application_source: common_enums::ApplicationSource,
) -> RouterResult<storage::ProcessTracker> {
let task = "SYNC_REFUND";
let process_tracker_id = format!("{runner}_{task}_{}", refund.internal_reference_id);
- let schedule_time =
- get_refund_sync_process_schedule_time(db, &refund.connector, &refund.merchant_id, 0)
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Failed to fetch schedule time for refund sync process")?
- .unwrap_or_else(common_utils::date_time::now);
+ let connector_enum = refund
+ .connector
+ .parse::<common_enums::connector_enums::Connector>()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Invalid connector name in refund")?;
+ let dimensions = crate::core::configs::dimension_state::Dimensions::new()
+ .with_processor_merchant_id(refund.merchant_id.clone().into())
+ .with_connector(connector_enum);
+ let schedule_time = get_refund_sync_process_schedule_time(
+ db,
+ superposition_client,
+ &dimensions,
+ 0,
+ Some(&refund.payment_id),
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to fetch schedule time for refund sync process")?
+ .unwrap_or_else(common_utils::date_time::now);
let refund_workflow_tracking_data = refund_to_refund_core_workflow_model(refund);
let tag = ["REFUND"];
let process_tracker_entry = storage::ProcessTrackerNew::new(
@@ -2286,32 +2317,16 @@ pub async fn add_refund_execute_task(
pub async fn get_refund_sync_process_schedule_time(
db: &dyn db::StorageInterface,
- connector: &str,
- merchant_id: &common_utils::id_type::MerchantId,
+ superposition_client: &external_services::superposition::SuperpositionClient,
+ dimensions: &crate::core::configs::dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
retry_count: i32,
+ payment_id: Option<&common_utils::id_type::PaymentId>,
) -> Result<Option<time::PrimitiveDateTime>, errors::ProcessTrackerError> {
- let mapping: common_utils::errors::CustomResult<
- process_data::ConnectorPTMapping,
- errors::StorageError,
- > = db
- .find_config_by_key(&format!("pt_mapping_refund_sync_{connector}"))
- .await
- .map(|value| value.config)
- .and_then(|config| {
- config
- .parse_struct("ConnectorPTMapping")
- .change_context(errors::StorageError::DeserializationFailed)
- });
-
- let mapping = match mapping {
- Ok(x) => x,
- Err(err) => {
- logger::error!("Error: while getting connector mapping: {err:?}");
- process_data::ConnectorPTMapping::default()
- }
- };
+ let mapping = dimensions
+ .get_pt_mapping_refund_sync(db, superposition_client, payment_id)
+ .await;
- let time_delta = process_tracker_utils::get_schedule_time(mapping, merchant_id, retry_count);
+ let time_delta = process_tracker_utils::get_schedule_time(mapping, retry_count);
Ok(process_tracker_utils::get_time_from_delta(time_delta))
}
diff --git a/crates/router/src/core/revenue_recovery.rs b/crates/router/src/core/revenue_recovery.rs
index 0dc6206512..6f2e065d01 100644
--- a/crates/router/src/core/revenue_recovery.rs
+++ b/crates/router/src/core/revenue_recovery.rs
@@ -618,6 +618,7 @@ pub async fn perform_calculate_workflow(
state,
&connector_customer_id,
payment_intent,
+ revenue_recovery_payment_data.billing_mca.connector_name,
retry_algorithm_type,
process.retry_count,
)
diff --git a/crates/router/src/core/webhooks/outgoing.rs b/crates/router/src/core/webhooks/outgoing.rs
index add56be468..56b620ee9d 100644
--- a/crates/router/src/core/webhooks/outgoing.rs
+++ b/crates/router/src/core/webhooks/outgoing.rs
@@ -201,6 +201,7 @@ pub(crate) async fn create_event_and_trigger_outgoing_webhook(
let process_tracker = add_outgoing_webhook_retry_task_to_process_tracker(
&*state.store,
+ state.superposition_service.as_ref(),
&platform,
&webhook_recipient,
&event,
@@ -576,17 +577,20 @@ async fn raise_webhooks_analytics_event(
pub(crate) async fn add_outgoing_webhook_retry_task_to_process_tracker(
db: &dyn StorageInterface,
+ superposition_client: &external_services::superposition::SuperpositionClient,
platform: &domain::Platform,
webhook_recipient: &utils::WebhookRecipientContext,
event: &domain::Event,
application_source: common_enums::ApplicationSource,
) -> CustomResult<storage::ProcessTracker, errors::StorageError> {
- let provider_merchant_id = platform.get_provider().get_account().get_id().clone();
let processor_merchant_id = platform.get_processor().get_account().get_id().clone();
-
+ let provider_merchant_id = platform.get_provider().get_account().get_id().clone();
+ let dimensions = crate::core::configs::dimension_state::Dimensions::new()
+ .with_processor_merchant_id(processor_merchant_id.clone().into());
let schedule_time = outgoing_webhook_retry::get_webhook_delivery_retry_schedule_time(
db,
- &webhook_recipient.profile.merchant_id,
+ superposition_client,
+ &dimensions,
0,
)
.await
@@ -810,6 +814,7 @@ async fn api_client_error_handler(
// merchant_id for retry schedule lookup, consistent with initial scheduling.
outgoing_webhook_retry::retry_webhook_delivery_task(
&*state.store,
+ state.superposition_service.as_ref(),
webhook_recipient_merchant_id,
*process_tracker,
)
@@ -975,6 +980,7 @@ async fn error_response_handler(
// merchant_id for retry schedule lookup, consistent with initial scheduling.
outgoing_webhook_retry::retry_webhook_delivery_task(
&*state.store,
+ state.superposition_service.as_ref(),
webhook_recipient_merchant_id,
*process_tracker,
)
diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs
index 481d880fa4..d04ca419dc 100644
--- a/crates/router/src/db/events.rs
+++ b/crates/router/src/db/events.rs
@@ -2181,7 +2181,7 @@ mod tests {
)
.await
.map_err(|e| format!("resolve_webhook_recipient failed: {e}"))?;
- webhooks_core::create_event_and_trigger_outgoing_webhook(
+ Box::pin(webhooks_core::create_event_and_trigger_outgoing_webhook(
state_clone,
cloned_platform,
event_type,
@@ -2191,7 +2191,7 @@ mod tests {
content_clone,
primary_object_created_at,
webhook_recipient,
- )
+ ))
.await
.map_err(|e| format!("create_event_and_trigger_outgoing_webhook failed: {e}"))
});
diff --git a/crates/router/src/types/storage/revenue_recovery.rs b/crates/router/src/types/storage/revenue_recovery.rs
index 536efc297b..0991a40ca4 100644
--- a/crates/router/src/types/storage/revenue_recovery.rs
+++ b/crates/router/src/types/storage/revenue_recovery.rs
@@ -55,9 +55,25 @@ impl RevenueRecoveryPaymentData {
}
enums::RevenueRecoveryAlgorithmType::Cascading => {
logger::info!("Cascading type found for Revenue Recovery retry payment");
+ let connector = payment_attempt.connector.as_ref().and_then(|c| {
+ c.parse::<common_enums::connector_enums::Connector>()
+ .map_err(|e| {
+ logger::error!(
+ "Failed to parse connector {:?} for payment_attempt {:?}: {:?}",
+ c,
+ payment_attempt.payment_id,
+ e
+ )
+ })
+ .ok()
+ })?;
+ let dimensions = crate::core::configs::dimension_state::Dimensions::new()
+ .with_processor_merchant_id(merchant_id.clone().into())
+ .with_connector(connector);
revenue_recovery::get_schedule_time_to_retry_mit_payments(
state.store.as_ref(),
- merchant_id,
+ state.superposition_service.as_ref(),
+ &dimensions,
retry_count,
)
.await
diff --git a/crates/router/src/workflows/dispute_list.rs b/crates/router/src/workflows/dispute_list.rs
index ee7ed4d2eb..2be0fe896f 100644
--- a/crates/router/src/workflows/dispute_list.rs
+++ b/crates/router/src/workflows/dispute_list.rs
@@ -1,11 +1,11 @@
use std::ops::Deref;
-use common_utils::ext_traits::{StringExt, ValueExt};
+use common_utils::ext_traits::ValueExt;
use diesel_models::process_tracker::business_status;
use error_stack::ResultExt;
use router_env::{logger, tracing::Instrument};
use scheduler::{
- consumer::{self, types::process_data, workflows::ProcessTrackerWorkflow},
+ consumer::{self, workflows::ProcessTrackerWorkflow},
errors as sch_errors, utils as scheduler_utils,
};
@@ -129,6 +129,7 @@ impl ProcessTrackerWorkflow<SessionState> for DisputeListWorkflow {
if response.is_err() {
retry_sync_task(
db,
+ state.superposition_service.as_ref(),
tracking_data.connector_name,
tracking_data
.processor_merchant_id
@@ -159,31 +160,14 @@ impl ProcessTrackerWorkflow<SessionState> for DisputeListWorkflow {
pub async fn get_sync_process_schedule_time(
db: &dyn StorageInterface,
- connector: &str,
- processor_merchant_id: &common_utils::id_type::MerchantId,
+ superposition_client: &external_services::superposition::SuperpositionClient,
+ dimensions: &crate::core::configs::dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
retry_count: i32,
) -> Result<Option<time::PrimitiveDateTime>, errors::ProcessTrackerError> {
- let mapping: common_utils::errors::CustomResult<
- process_data::ConnectorPTMapping,
- errors::StorageError,
- > = db
- .find_config_by_key(&format!("pt_mapping_{connector}"))
- .await
- .map(|value| value.config)
- .and_then(|config| {
- config
- .parse_struct("ConnectorPTMapping")
- .change_context(errors::StorageError::DeserializationFailed)
- });
- let mapping = match mapping {
- Ok(x) => x,
- Err(error) => {
- logger::info!(?error, "Redis Mapping Error");
- process_data::ConnectorPTMapping::default()
- }
- };
- let time_delta =
- scheduler_utils::get_schedule_time(mapping, processor_merchant_id, retry_count);
+ let mapping = dimensions
+ .get_pt_mapping_dispute_sync(db, superposition_client, None)
+ .await;
+ let time_delta = scheduler_utils::get_schedule_time(mapping, retry_count);
Ok(scheduler_utils::get_time_from_delta(time_delta))
}
@@ -193,12 +177,19 @@ pub async fn get_sync_process_schedule_time(
/// Returns bool which indicates whether this was the last retry or not
pub async fn retry_sync_task(
db: &dyn StorageInterface,
+ superposition_client: &external_services::superposition::SuperpositionClient,
connector: String,
processor_merchant_id: common_utils::id_type::MerchantId,
pt: storage::ProcessTracker,
) -> Result<bool, sch_errors::ProcessTrackerError> {
+ let connector_enum = connector
+ .parse::<common_enums::connector_enums::Connector>()
+ .map_err(|_| sch_errors::ProcessTrackerError::UnexpectedFlow)?;
+ let dimensions = crate::core::configs::dimension_state::Dimensions::new()
+ .with_processor_merchant_id(processor_merchant_id.into())
+ .with_connector(connector_enum);
let schedule_time: Option<time::PrimitiveDateTime> =
- get_sync_process_schedule_time(db, &connector, &processor_merchant_id, pt.retry_count + 1)
+ get_sync_process_schedule_time(db, superposition_client, &dimensions, pt.retry_count + 1)
.await?;
match schedule_time {
diff --git a/crates/router/src/workflows/outgoing_webhook_retry.rs b/crates/router/src/workflows/outgoing_webhook_retry.rs
index d020c33b7a..2e59b2ee8f 100644
--- a/crates/router/src/workflows/outgoing_webhook_retry.rs
+++ b/crates/router/src/workflows/outgoing_webhook_retry.rs
@@ -16,7 +16,6 @@ use hyperswitch_masking::PeekInterface;
use router_env::tracing::{self, instrument};
use scheduler::{
consumer::{self, workflows::ProcessTrackerWorkflow},
- types::process_data,
utils as scheduler_utils,
};
#[cfg(feature = "v1")]
@@ -307,13 +306,6 @@ impl ProcessTrackerWorkflow<SessionState> for OutgoingWebhookRetryWorkflow {
/// "start_after": 60,
/// "frequency": [300],
/// "count": [5]
-/// },
-/// "custom_merchant_mapping": {
-/// "merchant_id1": {
-/// "start_after": 30,
-/// "frequency": [300],
-/// "count": [2]
-/// }
/// }
/// }
/// ```
@@ -323,49 +315,20 @@ impl ProcessTrackerWorkflow<SessionState> for OutgoingWebhookRetryWorkflow {
/// default.
/// - `default_mapping.frequency` and `count`: The next 5 retries should have an interval of 300
/// seconds between them by default.
-/// - `custom_merchant_mapping.merchant_id1`: Merchant-specific retry configuration for merchant
-/// with merchant ID `merchant_id1`.
#[cfg(feature = "v1")]
#[instrument(skip_all)]
pub(crate) async fn get_webhook_delivery_retry_schedule_time(
db: &dyn StorageInterface,
- merchant_id: &id_type::MerchantId,
+ superposition_client: &external_services::superposition::SuperpositionClient,
+ dimensions: &crate::core::configs::dimension_state::DimensionsWithProcessorMerchantId,
retry_count: i32,
) -> Option<time::PrimitiveDateTime> {
- let key = "pt_mapping_outgoing_webhooks";
-
- let result = db
- .find_config_by_key(key)
- .await
- .map(|value| value.config)
- .and_then(|config| {
- config
- .parse_struct("OutgoingWebhookRetryProcessTrackerMapping")
- .change_context(errors::StorageError::DeserializationFailed)
- });
- let mapping = result.map_or_else(
- |error| {
- if error.current_context().is_db_not_found() {
- logger::debug!("Outgoing webhooks retry config `{key}` not found, ignoring");
- } else {
- logger::error!(
- ?error,
- "Failed to read outgoing webhooks retry config `{key}`"
- );
- }
- process_data::OutgoingWebhookRetryProcessTrackerMapping::default()
- },
- |mapping| {
- logger::debug!(?mapping, "Using custom outgoing webhooks retry config");
- mapping
- },
- );
+ let mapping = dimensions
+ .get_pt_mapping_outgoing_webhooks(db, superposition_client, None)
+ .await;
- let time_delta = scheduler_utils::get_outgoing_webhook_retry_schedule_time(
- mapping,
- merchant_id,
- retry_count,
- );
+ let time_delta =
+ scheduler_utils::get_outgoing_webhook_retry_schedule_time(mapping, retry_count);
scheduler_utils::get_time_from_delta(time_delta)
}
@@ -375,11 +338,19 @@ pub(crate) async fn get_webhook_delivery_retry_schedule_time(
#[instrument(skip_all)]
pub(crate) async fn retry_webhook_delivery_task(
db: &dyn StorageInterface,
+ superposition_client: &external_services::superposition::SuperpositionClient,
merchant_id: &id_type::MerchantId,
process: storage::ProcessTracker,
) -> errors::CustomResult<(), errors::StorageError> {
- let schedule_time =
- get_webhook_delivery_retry_schedule_time(db, merchant_id, process.retry_count + 1).await;
+ let dimensions = crate::core::configs::dimension_state::Dimensions::new()
+ .with_processor_merchant_id(merchant_id.clone().into());
+ let schedule_time = get_webhook_delivery_retry_schedule_time(
+ db,
+ superposition_client,
+ &dimensions,
+ process.retry_count + 1,
+ )
+ .await;
match schedule_time {
Some(schedule_time) => {
diff --git a/crates/router/src/workflows/payment_sync.rs b/crates/router/src/workflows/payment_sync.rs
index fb7986cf63..2d0581b5b0 100644
--- a/crates/router/src/workflows/payment_sync.rs
+++ b/crates/router/src/workflows/payment_sync.rs
@@ -1,11 +1,11 @@
#[cfg(feature = "v2")]
use common_utils::ext_traits::AsyncExt;
-use common_utils::ext_traits::{OptionExt, StringExt, ValueExt};
+use common_utils::ext_traits::{OptionExt, ValueExt};
use diesel_models::process_tracker::business_status;
use error_stack::ResultExt;
use router_env::logger;
use scheduler::{
- consumer::{self, types::process_data, workflows::ProcessTrackerWorkflow},
+ consumer::{self, workflows::ProcessTrackerWorkflow},
errors as sch_errors, utils as scheduler_utils,
};
@@ -132,6 +132,7 @@ impl ProcessTrackerWorkflow<SessionState> for PaymentsSyncWorkflow {
let is_last_retry = retry_sync_task(
db,
+ state.superposition_service.as_ref(),
connector,
payment_data.payment_attempt.merchant_id.clone(),
process,
@@ -264,30 +265,14 @@ impl ProcessTrackerWorkflow<SessionState> for PaymentsSyncWorkflow {
/// After than do 2 retries with an interval of 1800 seconds.
pub async fn get_sync_process_schedule_time(
db: &dyn StorageInterface,
- connector: &str,
- merchant_id: &common_utils::id_type::MerchantId,
+ superposition_client: &external_services::superposition::SuperpositionClient,
+ dimensions: &dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
retry_count: i32,
) -> Result<Option<time::PrimitiveDateTime>, errors::ProcessTrackerError> {
- let mapping: common_utils::errors::CustomResult<
- process_data::ConnectorPTMapping,
- errors::StorageError,
- > = db
- .find_config_by_key(&format!("pt_mapping_{connector}"))
- .await
- .map(|value| value.config)
- .and_then(|config| {
- config
- .parse_struct("ConnectorPTMapping")
- .change_context(errors::StorageError::DeserializationFailed)
- });
- let mapping = match mapping {
- Ok(x) => x,
- Err(error) => {
- logger::info!(?error, "Redis Mapping Error");
- process_data::ConnectorPTMapping::default()
- }
- };
- let time_delta = scheduler_utils::get_schedule_time(mapping, merchant_id, retry_count);
+ let mapping = dimensions
+ .get_pt_mapping_payment_sync(db, superposition_client, None)
+ .await;
+ let time_delta = scheduler_utils::get_schedule_time(mapping, retry_count);
Ok(scheduler_utils::get_time_from_delta(time_delta))
}
@@ -297,12 +282,20 @@ pub async fn get_sync_process_schedule_time(
/// Returns bool which indicates whether this was the last retry or not
pub async fn retry_sync_task(
db: &dyn StorageInterface,
+ superposition_client: &external_services::superposition::SuperpositionClient,
connector: String,
merchant_id: common_utils::id_type::MerchantId,
pt: storage::ProcessTracker,
) -> Result<bool, sch_errors::ProcessTrackerError> {
+ let connector_enum = connector
+ .parse::<common_enums::connector_enums::Connector>()
+ .map_err(|_| sch_errors::ProcessTrackerError::UnexpectedFlow)?;
+ let dimensions = dimension_state::Dimensions::new()
+ .with_processor_merchant_id(merchant_id.into())
+ .with_connector(connector_enum);
let schedule_time =
- get_sync_process_schedule_time(db, &connector, &merchant_id, pt.retry_count + 1).await?;
+ get_sync_process_schedule_time(db, superposition_client, &dimensions, pt.retry_count + 1)
+ .await?;
match schedule_time {
Some(s_time) => {
@@ -330,8 +323,19 @@ pub async fn recovery_retry_sync_task(
pt: storage::ProcessTracker,
) -> Result<bool, sch_errors::ProcessTrackerError> {
let db = &*state.store;
- let schedule_time =
- get_sync_process_schedule_time(db, &connector, &merchant_id, pt.retry_count + 1).await?;
+ let connector_enum = connector
+ .parse::<common_enums::connector_enums::Connector>()
+ .map_err(|_| sch_errors::ProcessTrackerError::UnexpectedFlow)?;
+ let dimensions = dimension_state::Dimensions::new()
+ .with_processor_merchant_id(merchant_id.into())
+ .with_connector(connector_enum);
+ let schedule_time = get_sync_process_schedule_time(
+ db,
+ state.superposition_service.as_ref(),
+ &dimensions,
+ pt.retry_count + 1,
+ )
+ .await?;
match schedule_time {
Some(s_time) => {
@@ -365,24 +369,18 @@ pub async fn recovery_retry_sync_task(
#[cfg(test)]
mod tests {
+ use scheduler::consumer::types::process_data;
+
use super::*;
#[test]
fn test_get_default_schedule_time() {
- let merchant_id =
- common_utils::id_type::MerchantId::try_from(std::borrow::Cow::from("-")).unwrap();
- let schedule_time_delta = scheduler_utils::get_schedule_time(
- process_data::ConnectorPTMapping::default(),
- &merchant_id,
- 0,
- )
- .unwrap();
- let first_retry_time_delta = scheduler_utils::get_schedule_time(
- process_data::ConnectorPTMapping::default(),
- &merchant_id,
- 1,
- )
- .unwrap();
+ let schedule_time_delta =
+ scheduler_utils::get_schedule_time(process_data::ConnectorPTMapping::default(), 0)
+ .unwrap();
+ let first_retry_time_delta =
+ scheduler_utils::get_schedule_time(process_data::ConnectorPTMapping::default(), 1)
+ .unwrap();
let cpt_default = process_data::ConnectorPTMapping::default().default_mapping;
assert_eq!(
vec![schedule_time_delta, first_retry_time_delta],
diff --git a/crates/router/src/workflows/process_dispute.rs b/crates/router/src/workflows/process_dispute.rs
index 11e4d8ca21..3faa1f2ebb 100644
--- a/crates/router/src/workflows/process_dispute.rs
+++ b/crates/router/src/workflows/process_dispute.rs
@@ -1,9 +1,8 @@
-use common_utils::ext_traits::{StringExt, ValueExt};
+use common_utils::ext_traits::ValueExt;
use diesel_models::process_tracker::business_status;
-use error_stack::ResultExt;
use router_env::logger;
use scheduler::{
- consumer::{self, types::process_data, workflows::ProcessTrackerWorkflow},
+ consumer::{self, workflows::ProcessTrackerWorkflow},
errors as sch_errors, utils as scheduler_utils,
};
@@ -110,6 +109,7 @@ impl ProcessTrackerWorkflow<SessionState> for ProcessDisputeWorkflow {
.finish_process_with_business_status(process, business_status::COMPLETED_BY_PT)
.await?;
} else {
+ let payment_id = payment_attempt.payment_id.clone();
// Update dispute data
let response = Box::pin(disputes::update_dispute_data(
state,
@@ -137,10 +137,12 @@ impl ProcessTrackerWorkflow<SessionState> for ProcessDisputeWorkflow {
Err(_) => {
retry_sync_task(
db,
+ state.superposition_service.as_ref(),
tracking_data.connector_name,
tracking_data
.processor_merchant_id
.unwrap_or_else(|| tracking_data.merchant_id.clone()),
+ Some(payment_id),
process,
)
.await?;
@@ -162,31 +164,15 @@ impl ProcessTrackerWorkflow<SessionState> for ProcessDisputeWorkflow {
pub async fn get_sync_process_schedule_time(
db: &dyn StorageInterface,
- connector: &str,
- processor_merchant_id: &common_utils::id_type::MerchantId,
+ superposition_client: &external_services::superposition::SuperpositionClient,
+ dimensions: &crate::core::configs::dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
retry_count: i32,
+ payment_id: Option<&common_utils::id_type::PaymentId>,
) -> Result<Option<time::PrimitiveDateTime>, errors::ProcessTrackerError> {
- let mapping: common_utils::errors::CustomResult<
- process_data::ConnectorPTMapping,
- errors::StorageError,
- > = db
- .find_config_by_key(&format!("pt_mapping_{connector}"))
- .await
- .map(|value| value.config)
- .and_then(|config| {
- config
- .parse_struct("ConnectorPTMapping")
- .change_context(errors::StorageError::DeserializationFailed)
- });
- let mapping = match mapping {
- Ok(x) => x,
- Err(error) => {
- logger::info!(?error, "Redis Mapping Error");
- process_data::ConnectorPTMapping::default()
- }
- };
- let time_delta =
- scheduler_utils::get_schedule_time(mapping, processor_merchant_id, retry_count);
+ let mapping = dimensions
+ .get_pt_mapping_dispute_sync(db, superposition_client, payment_id)
+ .await;
+ let time_delta = scheduler_utils::get_schedule_time(mapping, retry_count);
Ok(scheduler_utils::get_time_from_delta(time_delta))
}
@@ -196,13 +182,26 @@ pub async fn get_sync_process_schedule_time(
/// Returns bool which indicates whether this was the last retry or not
pub async fn retry_sync_task(
db: &dyn StorageInterface,
+ superposition_client: &external_services::superposition::SuperpositionClient,
connector: String,
processor_merchant_id: common_utils::id_type::MerchantId,
+ payment_id: Option<common_utils::id_type::PaymentId>,
pt: storage::ProcessTracker,
) -> Result<bool, sch_errors::ProcessTrackerError> {
- let schedule_time =
- get_sync_process_schedule_time(db, &connector, &processor_merchant_id, pt.retry_count + 1)
- .await?;
+ let connector_enum = connector
+ .parse::<common_enums::connector_enums::Connector>()
+ .map_err(|_| sch_errors::ProcessTrackerError::UnexpectedFlow)?;
+ let dimensions = crate::core::configs::dimension_state::Dimensions::new()
+ .with_processor_merchant_id(processor_merchant_id.into())
+ .with_connector(connector_enum);
+ let schedule_time = get_sync_process_schedule_time(
+ db,
+ superposition_client,
+ &dimensions,
+ pt.retry_count + 1,
+ payment_id.as_ref(),
+ )
+ .await?;
match schedule_time {
Some(s_time) => {
diff --git a/crates/router/src/workflows/revenue_recovery.rs b/crates/router/src/workflows/revenue_recovery.rs
index 97932049b6..7baca6324b 100644
--- a/crates/router/src/workflows/revenue_recovery.rs
+++ b/crates/router/src/workflows/revenue_recovery.rs
@@ -235,40 +235,15 @@ pub(crate) async fn extract_data_and_perform_action(
#[cfg(feature = "v2")]
pub(crate) async fn get_schedule_time_to_retry_mit_payments(
db: &dyn StorageInterface,
- merchant_id: &id_type::MerchantId,
+ superposition_client: &external_services::superposition::SuperpositionClient,
+ dimensions: &crate::core::configs::dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
retry_count: i32,
) -> Option<time::PrimitiveDateTime> {
- let key = "pt_mapping_pcr_retries";
- let result = db
- .find_config_by_key(key)
- .await
- .map(|value| value.config)
- .and_then(|config| {
- config
- .parse_struct("RevenueRecoveryPaymentProcessTrackerMapping")
- .change_context(StorageError::DeserializationFailed)
- });
-
- let mapping = result.map_or_else(
- |error| {
- if error.current_context().is_db_not_found() {
- logger::debug!("Revenue Recovery retry config `{key}` not found, ignoring");
- } else {
- logger::error!(
- ?error,
- "Failed to read Revenue Recovery retry config `{key}`"
- );
- }
- process_data::RevenueRecoveryPaymentProcessTrackerMapping::default()
- },
- |mapping| {
- logger::debug!(?mapping, "Using custom pcr payments retry config");
- mapping
- },
- );
+ let mapping = dimensions
+ .get_pt_mapping_pcr_retries(db, superposition_client, None)
+ .await;
- let time_delta =
- scheduler_utils::get_pcr_payments_retry_schedule_time(mapping, merchant_id, retry_count);
+ let time_delta = scheduler_utils::get_pcr_payments_retry_schedule_time(mapping, retry_count);
scheduler_utils::get_time_from_delta(time_delta)
}
@@ -658,6 +633,7 @@ pub async fn get_token_with_schedule_time_based_on_retry_algorithm_type(
state: &SessionState,
connector_customer_id: &str,
payment_intent: &PaymentIntent,
+ billing_connector: common_enums::connector_enums::Connector,
retry_algorithm_type: RevenueRecoveryAlgorithmType,
retry_count: i32,
) -> CustomResult<PaymentProcessorTokenResponse, errors::ProcessTrackerError> {
@@ -668,9 +644,13 @@ pub async fn get_token_with_schedule_time_based_on_retry_algorithm_type(
}
RevenueRecoveryAlgorithmType::Cascading => {
+ let dimensions = crate::core::configs::dimension_state::Dimensions::new()
+ .with_processor_merchant_id(payment_intent.merchant_id.clone().into())
+ .with_connector(billing_connector);
let time = get_schedule_time_to_retry_mit_payments(
state.store.as_ref(),
- &payment_intent.merchant_id,
+ state.superposition_service.as_ref(),
+ &dimensions,
retry_count,
)
.await
diff --git a/crates/scheduler/src/consumer/types/process_data.rs b/crates/scheduler/src/consumer/types/process_data.rs
index e74b72e513..473511eb30 100644
--- a/crates/scheduler/src/consumer/types/process_data.rs
+++ b/crates/scheduler/src/consumer/types/process_data.rs
@@ -30,14 +30,12 @@ impl TryFrom<serde_json::Value> for RetryMapping {
#[derive(Serialize, Deserialize)]
pub struct ConnectorPTMapping {
pub default_mapping: RetryMapping,
- pub custom_merchant_mapping: HashMap<common_utils::id_type::MerchantId, RetryMapping>,
pub max_retries_count: i32,
}
impl Default for ConnectorPTMapping {
fn default() -> Self {
Self {
- custom_merchant_mapping: HashMap::new(),
default_mapping: RetryMapping::default(),
max_retries_count: 5,
}
@@ -90,9 +88,6 @@ pub struct OutgoingWebhookRetryProcessTrackerMapping {
/// Default (fallback) retry configuration used when no merchant-specific retry configuration
/// exists.
pub default_mapping: RetryMapping,
-
- /// Merchant-specific retry configuration.
- pub custom_merchant_mapping: HashMap<common_utils::id_type::MerchantId, RetryMapping>,
}
impl Default for OutgoingWebhookRetryProcessTrackerMapping {
@@ -113,7 +108,6 @@ impl Default for OutgoingWebhookRetryProcessTrackerMapping {
(60 * 60 * 6, 3),
],
},
- custom_merchant_mapping: HashMap::new(),
}
}
}
@@ -124,9 +118,6 @@ pub struct RevenueRecoveryPaymentProcessTrackerMapping {
/// Default (fallback) retry configuration used when no merchant-specific retry configuration
/// exists.
pub default_mapping: RetryMapping,
-
- /// Merchant-specific retry configuration.
- pub custom_merchant_mapping: HashMap<common_utils::id_type::MerchantId, RetryMapping>,
}
impl Default for RevenueRecoveryPaymentProcessTrackerMapping {
@@ -149,7 +140,6 @@ impl Default for RevenueRecoveryPaymentProcessTrackerMapping {
(60 * 60 * 18, 3),
],
},
- custom_merchant_mapping: HashMap::new(),
}
}
}
diff --git a/crates/scheduler/src/utils.rs b/crates/scheduler/src/utils.rs
index fd1baaff78..10d1633124 100644
--- a/crates/scheduler/src/utils.rs
+++ b/crates/scheduler/src/utils.rs
@@ -334,13 +334,9 @@ pub fn add_histogram_metrics(
pub fn get_schedule_time(
mapping: process_data::ConnectorPTMapping,
- merchant_id: &common_utils::id_type::MerchantId,
retry_count: i32,
) -> Option<i32> {
- let mapping = match mapping.custom_merchant_mapping.get(merchant_id) {
- Some(map) => map.clone(),
- None => mapping.default_mapping,
- };
+ let mapping = mapping.default_mapping;
// For first try, get the `start_after` time
if retry_count == 0 {
@@ -369,13 +365,9 @@ pub fn get_pm_schedule_time(
pub fn get_outgoing_webhook_retry_schedule_time(
mapping: process_data::OutgoingWebhookRetryProcessTrackerMapping,
- merchant_id: &common_utils::id_type::MerchantId,
retry_count: i32,
) -> Option<i32> {
- let retry_mapping = match mapping.custom_merchant_mapping.get(merchant_id) {
- Some(map) => map.clone(),
- None => mapping.default_mapping,
- };
+ let retry_mapping = mapping.default_mapping;
// For first try, get the `start_after` time
if retry_count == 0 {
@@ -387,13 +379,9 @@ pub fn get_outgoing_webhook_retry_schedule_time(
pub fn get_pcr_payments_retry_schedule_time(
mapping: process_data::RevenueRecoveryPaymentProcessTrackerMapping,
- merchant_id: &common_utils::id_type::MerchantId,
retry_count: i32,
) -> Option<i32> {
- let mapping = match mapping.custom_merchant_mapping.get(merchant_id) {
- Some(map) => map.clone(),
- None => mapping.default_mapping,
- };
+ let mapping = mapping.default_mapping;
// TODO: check if the current scheduled time is not more than the configured timerange
// For first try, get the `start_after` time