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(offers): notify offer engine via process tracker (#13727)
Apoorv Dixiteeaf0860cc98
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rsindex e9b945daef..bce55e2859 100644--- a/crates/common_enums/src/enums.rs+++ b/crates/common_enums/src/enums.rs@@ -11281,6 +11281,7 @@ pub enum ProcessTrackerRunner {PayoutSyncWorkFlow,BatchBlocklistUpload,NetworkTokenizationWorkflow,+ OfferEngineNotifyWorkflow,}#[derive(diff --git a/crates/router/src/bin/scheduler.rs b/crates/router/src/bin/scheduler.rsindex 5d289b058e..c492f5b8bf 100644--- a/crates/router/src/bin/scheduler.rs+++ b/crates/router/src/bin/scheduler.rs@@ -396,6 +396,21 @@ impl ProcessTrackerWorkflows<routes::SessionState> for WorkflowRunner {storage::ProcessTrackerRunner::NetworkTokenizationWorkflow => Ok(Box::new(workflows::network_tokenization::NetworkTokenizationWorkflow,)),+ storage::ProcessTrackerRunner::OfferEngineNotifyWorkflow => {+ #[cfg(feature = "v1")]+ {+ Ok(Box::new(+ workflows::offer_engine_notify::OfferEngineNotifyWorkflow,+ ))+ }+ #[cfg(feature = "v2")]+ {+ Err(error_stack::report!(ProcessTrackerError::UnexpectedFlow))+ .attach_printable(+ "Cannot run offer engine notify workflow when v1 feature is disabled",+ )+ }+ }}};diff --git a/crates/router/src/core/offer_engine.rs b/crates/router/src/core/offer_engine.rsindex d1f3191e07..a77357a276 100644--- a/crates/router/src/core/offer_engine.rs+++ b/crates/router/src/core/offer_engine.rs@@ -4,10 +4,14 @@ pub mod client;pub mod config;pub mod connectivity;pub mod eligibility;+#[cfg(feature = "v1")]+pub mod notify;pub mod types;#[cfg(feature = "v1")]pub mod velocity;pub use client::OfferEngineClient;pub use config::resolve_offer_engine_config;+#[cfg(feature = "v1")]+pub use notify::{schedule_payment_notification_for_attempt, schedule_refund_notification};pub use types::{OfferEngineCredentialSource, OfferEngineError, ResolvedOfferEngineConfig};diff --git a/crates/router/src/core/offer_engine/client.rs b/crates/router/src/core/offer_engine/client.rsindex 64362ceb20..dcf5f65da9 100644--- a/crates/router/src/core/offer_engine/client.rs+++ b/crates/router/src/core/offer_engine/client.rs@@ -11,12 +11,13 @@ use router_env::{IdReuse, RequestIdentifier};use super::types::{OfferApplyRequest, OfferApplyResponse, OfferEngineError, OfferListRequest, OfferListResponse,- ResolvedOfferEngineConfig,+ OfferNotifyRequest, ResolvedOfferEngineConfig,};use crate::{consts::BASE64_ENGINE, routes::SessionState};const OFFERS_LIST_PATH: &str = "v1/offers/list";const OFFERS_APPLY_PATH: &str = "offers/apply";+const OFFERS_NOTIFY_PATH: &str = "offers/notify";#[derive(Debug)]pub struct OfferEngineClient {@@ -71,6 +72,17 @@ impl OfferEngineClient {.map_err(map_offer_engine_error)}+ pub async fn notify(+ &self,+ state: &SessionState,+ request: OfferNotifyRequest,+ ) -> CustomResult<(), OfferEngineError> {+ OfferNotify::call(state, self, OfferNotifyV1Request(request))+ .await+ .map(|_| ())+ .map_err(map_offer_engine_error)+ }+pub async fn check_connectivity(&self, state: &SessionState) -> ConnectivityResult {match OfferConnectivity::call(state, self, OfferConnectivityRequest).await {Ok(_) => ConnectivityResult {@@ -238,6 +250,42 @@ hyperswitch_interfaces::impl_microservice_flow!(body = OfferApply::build_body);+pub struct OfferNotify;+pub struct OfferNotifyV1Request(pub OfferNotifyRequest);+pub struct OfferNotifyV1Response(pub super::types::OfferNotifyResponse);++impl TryFrom<&OfferNotifyV1Request> for OfferNotifyRequest {+ type Error = MicroserviceClientError;+ fn try_from(value: &OfferNotifyV1Request) -> Result<Self, Self::Error> {+ Ok(value.0.clone())+ }+}++impl TryFrom<serde_json::Value> for OfferNotifyV1Response {+ type Error = MicroserviceClientError;+ fn try_from(_: serde_json::Value) -> Result<Self, Self::Error> {+ Ok(Self(super::types::OfferNotifyResponse))+ }+}++impl OfferNotify {+ fn build_body(&self, request: OfferNotifyRequest) -> Option<RequestContent> {+ Some(RequestContent::Json(Box::new(request)))+ }+}++hyperswitch_interfaces::impl_microservice_flow!(+ OfferNotify,+ method = Method::Post,+ path = OFFERS_NOTIFY_PATH,+ v1_request = OfferNotifyV1Request,+ v2_request = OfferNotifyRequest,+ v2_response = serde_json::Value,+ v1_response = OfferNotifyV1Response,+ client = OfferEngineClient,+ body = OfferNotify::build_body+);+#[derive(Debug, Clone, serde::Serialize)]pub struct ConnectivityResult {pub reachable: bool,diff --git a/crates/router/src/core/offer_engine/config.rs b/crates/router/src/core/offer_engine/config.rsindex 1e04a9f029..1052b2f400 100644--- a/crates/router/src/core/offer_engine/config.rs+++ b/crates/router/src/core/offer_engine/config.rs@@ -16,34 +16,49 @@ pub async fn resolve_offer_engine_config<D>(whereD: dimension_state::DimensionsBase,{- let store = state.store.as_ref();- let superposition = state.superposition_service.as_ref();-let enabled = configs::fetch_db_config_for_dimensions::<dimension_config::OfferEngineEnabled>(- store,- superposition,+ state.store.as_ref(),+ state.superposition_service.as_ref(),dimensions,None,).await;if enabled {- let source = configs::fetch_db_config_for_string_enum::<- dimension_config::OfferEngineCredentialSource,- OfferEngineCredentialSource,- >(store, superposition, dimensions, None)- .await- .unwrap_or(OfferEngineCredentialSource::None);-- match source {- OfferEngineCredentialSource::None => Ok(None),- OfferEngineCredentialSource::Application => resolve_application_config(state).map(Some),- }+ resolve_offer_engine_credentials(state, dimensions).await} else {Ok(None)}}+/// Resolve the Offer Engine credentials for the given dimensions by credential+/// source, independent of the `enabled` toggle. The notification path uses this:+/// an applied offer's outcome must be reported even after the feature is disabled.+pub async fn resolve_offer_engine_credentials<D>(+ state: &SessionState,+ dimensions: &D,+) -> CustomResult<Option<ResolvedOfferEngineConfig>, OfferEngineError>+where+ D: dimension_state::DimensionsBase,+{+ let source = configs::fetch_db_config_for_string_enum::<+ dimension_config::OfferEngineCredentialSource,+ OfferEngineCredentialSource,+ >(+ state.store.as_ref(),+ state.superposition_service.as_ref(),+ dimensions,+ None,+ )+ .await+ .unwrap_or(OfferEngineCredentialSource::None);++ match source {+ OfferEngineCredentialSource::None => Ok(None),+ OfferEngineCredentialSource::Application => resolve_application_config(state).map(Some),+ }+}+fn resolve_application_config(state: &SessionState,) -> CustomResult<ResolvedOfferEngineConfig, OfferEngineError> {diff --git a/crates/router/src/core/offer_engine/notify.rs b/crates/router/src/core/offer_engine/notify.rsnew file mode 100644index 0000000000..716818025b--- /dev/null+++ b/crates/router/src/core/offer_engine/notify.rs@@ -0,0 +1,303 @@+use common_utils::{ext_traits::ValueExt, id_type};+use diesel_models::process_tracker::business_status;+use hyperswitch_domain_models::platform::ProcessorMerchantId;+use scheduler::{consumer::types::process_data, utils as pt_utils};++use super::{+ client::OfferEngineClient,+ config::resolve_offer_engine_credentials,+ types::{OfferNotifyOffer, OfferNotifyRequest, OfferNotifyStatus, OfferTxnStatus},+};+use crate::{+ core::{configs::dimension_state, errors},+ logger,+ routes::{metrics, SessionState},+ types::storage,+};++const OFFER_ENGINE_NOTIFY_NAME: &str = "OFFER_ENGINE_NOTIFY";+const OFFER_ENGINE_NOTIFY_TAG: &str = "OFFER_ENGINE";+const OFFER_ENGINE_NOTIFY_FLOW: &str = "OfferEngineNotify";+const OFFER_ENGINE_NOTIFY_RUNNER: diesel_models::ProcessTrackerRunner =+ diesel_models::ProcessTrackerRunner::OfferEngineNotifyWorkflow;++#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]+pub struct OfferEngineNotifyTrackingData {+ pub payment_id: id_type::PaymentId,+ pub payment_attempt_id: String,+ pub processor_merchant_id: id_type::MerchantId,+ pub refund_id: Option<String>,+ #[serde(default)]+ pub txn_status: OfferTxnStatus,+}++fn payment_task_id(attempt_id: &str) -> String {+ format!("offer_engine_notify_payment_{attempt_id}")+}++fn refund_task_id(refund_id: &str) -> String {+ format!("offer_engine_notify_refund_{refund_id}")+}++fn notify_attributes() -> [router_env::opentelemetry::KeyValue; 1] {+ [router_env::opentelemetry::KeyValue::new(+ "flow",+ OFFER_ENGINE_NOTIFY_FLOW,+ )]+}++/// Offer Engine txn status to report for an attempt, or `None` when it must not notify.+fn attempt_notify_status(status: common_enums::AttemptStatus) -> Option<OfferTxnStatus> {+ use common_enums::AttemptStatus;+ match status {+ AttemptStatus::AutoRefunded+ | AttemptStatus::Failure+ | AttemptStatus::AuthenticationFailed+ | AttemptStatus::AuthorizationFailed+ | AttemptStatus::RouterDeclined+ | AttemptStatus::Voided+ | AttemptStatus::VoidFailed+ | AttemptStatus::CaptureFailed+ | AttemptStatus::Expired => Some(OfferTxnStatus::Failure),+ AttemptStatus::Charged+ | AttemptStatus::PartialCharged+ | AttemptStatus::Started+ | AttemptStatus::AuthenticationPending+ | AttemptStatus::AuthenticationSuccessful+ | AttemptStatus::Authorized+ | AttemptStatus::Authorizing+ | AttemptStatus::CodInitiated+ | AttemptStatus::VoidedPostCharge+ | AttemptStatus::VoidInitiated+ | AttemptStatus::CaptureInitiated+ | AttemptStatus::PartiallyAuthorized+ | AttemptStatus::PartialChargedAndChargeable+ | AttemptStatus::Unresolved+ | AttemptStatus::Pending+ | AttemptStatus::PaymentMethodAwaited+ | AttemptStatus::ConfirmationAwaited+ | AttemptStatus::DeviceDataCollectionPending+ | AttemptStatus::IntegrityFailure+ | AttemptStatus::CaptureReview => None,+ }+}++pub async fn schedule_payment_notification_for_attempt(+ state: &SessionState,+ payment_attempt: &storage::PaymentAttempt,+) {+ if let Some(txn_status) = attempt_notify_status(payment_attempt.status)+ .filter(|_| payment_attempt.applied_offer_details.is_some())+ {+ let tracking_data = OfferEngineNotifyTrackingData {+ payment_id: payment_attempt.payment_id.clone(),+ payment_attempt_id: payment_attempt.attempt_id.clone(),+ processor_merchant_id: payment_attempt.processor_merchant_id.clone(),+ refund_id: None,+ txn_status,+ };+ let task_id = payment_task_id(&payment_attempt.attempt_id);+ insert_notification_task(state, task_id, tracking_data).await;+ }+}++pub async fn schedule_refund_notification(+ state: &SessionState,+ payment_attempt: &storage::PaymentAttempt,+ refund: &diesel_models::refund::Refund,+) {+ if payment_attempt.applied_offer_details.is_some() {+ let tracking_data = OfferEngineNotifyTrackingData {+ payment_id: refund.payment_id.clone(),+ payment_attempt_id: refund.attempt_id.clone(),+ processor_merchant_id: payment_attempt.processor_merchant_id.clone(),+ refund_id: Some(refund.refund_id.clone()),+ txn_status: OfferTxnStatus::Failure,+ };+ let task_id = refund_task_id(&refund.refund_id);+ insert_notification_task(state, task_id, tracking_data).await;+ }+}++async fn insert_notification_task(+ state: &SessionState,+ task_id: String,+ tracking_data: OfferEngineNotifyTrackingData,+) {+ let schedule_time = common_utils::date_time::now();+ match storage::ProcessTrackerNew::new(+ task_id.clone(),+ OFFER_ENGINE_NOTIFY_NAME,+ OFFER_ENGINE_NOTIFY_RUNNER,+ [OFFER_ENGINE_NOTIFY_TAG],+ tracking_data,+ None,+ schedule_time,+ common_types::consts::API_VERSION,+ common_enums::ApplicationSource::Main,+ ) {+ Err(err) => {+ logger::error!(?err, %task_id, "Failed to construct offer engine notify task");+ metrics::OFFER_ENGINE_NOTIFY_SCHEDULE_FAILURES.add(1, ¬ify_attributes());+ }+ Ok(entry) => match state.store.insert_process(entry).await {+ Ok(_) => {+ logger::info!(%task_id, "Scheduled offer engine notify task");+ metrics::OFFER_ENGINE_NOTIFY_TASKS_SCHEDULED.add(1, ¬ify_attributes());+ }+ Err(err) if err.current_context().is_db_unique_violation() => {+ logger::info!(%task_id, "Offer engine notify task already scheduled; suppressing duplicate");+ }+ Err(err) => {+ logger::error!(?err, %task_id, "Failed to schedule offer engine notify task");+ metrics::OFFER_ENGINE_NOTIFY_SCHEDULE_FAILURES.add(1, ¬ify_attributes());+ }+ },+ }+}++pub async fn execute_notification(+ state: &SessionState,+ process: storage::ProcessTracker,+) -> Result<(), errors::ProcessTrackerError> {+ let tracking_data: OfferEngineNotifyTrackingData = process+ .tracking_data+ .clone()+ .parse_value("OfferEngineNotifyTrackingData")?;+ let attributes = notify_attributes();++ let db = &*state.store;+ let key_store = db+ .get_merchant_key_store_by_merchant_id(+ &tracking_data.processor_merchant_id,+ &db.get_master_key().to_vec().into(),+ )+ .await?;+ let merchant_account = db+ .find_merchant_account_by_merchant_id(&tracking_data.processor_merchant_id, &key_store)+ .await?;+ let payment_attempt = db+ .find_payment_attempt_by_attempt_id_processor_merchant_id(+ &tracking_data.payment_attempt_id,+ &tracking_data.processor_merchant_id,+ merchant_account.storage_scheme,+ &key_store,+ )+ .await?;++ match payment_attempt.applied_offer_details.as_ref() {+ None => {+ logger::warn!(+ payment_id = %tracking_data.payment_id.get_string_repr(),+ payment_attempt_id = %tracking_data.payment_attempt_id,+ refund_id = ?tracking_data.refund_id,+ process_tracker_id = %process.id,+ "applied_offer_details missing; terminating offer engine notify task"+ );+ metrics::OFFER_ENGINE_NOTIFY_TERMINAL_FAILURES.add(1, &attributes);+ db.as_scheduler()+ .finish_process_with_business_status(+ process,+ business_status::RESOURCE_STATUS_MISMATCH,+ )+ .await+ .map_err(Into::<errors::ProcessTrackerError>::into)+ }+ Some(applied) => {+ let dimensions = dimension_state::Dimensions::new()+ .with_processor_merchant_id(ProcessorMerchantId::from(+ payment_attempt.processor_merchant_id.clone(),+ ))+ .with_organization_id(payment_attempt.organization_id.clone())+ .with_profile_id(payment_attempt.profile_id.clone());+ match resolve_offer_engine_credentials(state, &dimensions).await {+ Ok(Some(config)) => {+ let applied = applied.inner();+ let request = OfferNotifyRequest {+ order_id: tracking_data.payment_id.get_string_repr().to_string(),+ txn_id: applied.offer_engine_txn_id.clone(),+ txn_status: tracking_data.txn_status,+ merchant_id: applied.offer_engine_merchant_id.clone(),+ offers: vec![OfferNotifyOffer {+ offer_id: applied.offer_id.clone(),+ status: OfferNotifyStatus::Revoked,+ error_code: None,+ error_message: None,+ }],+ refund_id: tracking_data.refund_id.clone(),+ };++ let client =+ OfferEngineClient::new(config, &state.conf.trace_header.header_name);+ match client.notify(state, request).await {+ Ok(()) => {+ logger::info!(+ payment_id = %tracking_data.payment_id.get_string_repr(),+ payment_attempt_id = %tracking_data.payment_attempt_id,+ refund_id = ?tracking_data.refund_id,+ offer_id = %applied.offer_id,+ process_tracker_id = %process.id,+ attempt = process.retry_count,+ "Offer engine notification delivered"+ );+ metrics::OFFER_ENGINE_NOTIFY_SUCCESS.add(1, &attributes);+ db.as_scheduler()+ .finish_process_with_business_status(+ process,+ business_status::COMPLETED_BY_PT,+ )+ .await+ .map_err(Into::<errors::ProcessTrackerError>::into)+ }+ Err(err) => {+ logger::warn!(+ ?err,+ payment_attempt_id = %tracking_data.payment_attempt_id,+ refund_id = ?tracking_data.refund_id,+ process_tracker_id = %process.id,+ attempt = process.retry_count,+ "Offer engine notification delivery failed"+ );+ let mapping = process_data::RetryMapping::default();+ let time_delta = if process.retry_count == 0 {+ Some(mapping.start_after)+ } else {+ pt_utils::get_delay(process.retry_count + 1, &mapping.frequencies)+ };+ match pt_utils::get_time_from_delta(time_delta) {+ Some(schedule_time) => db+ .as_scheduler()+ .retry_process(process, schedule_time)+ .await+ .map_err(Into::<errors::ProcessTrackerError>::into),+ None => {+ metrics::OFFER_ENGINE_NOTIFY_TERMINAL_FAILURES+ .add(1, &attributes);+ db.as_scheduler()+ .finish_process_with_business_status(+ process,+ business_status::RETRIES_EXCEEDED,+ )+ .await+ .map_err(Into::<errors::ProcessTrackerError>::into)+ }+ }+ }+ }+ }+ other => {+ logger::error!(+ ?other,+ process_tracker_id = %process.id,+ "Offer Engine credentials unavailable; terminating notify task"+ );+ metrics::OFFER_ENGINE_NOTIFY_TERMINAL_FAILURES.add(1, &attributes);+ db.as_scheduler()+ .finish_process_with_business_status(process, business_status::FAILURE)+ .await+ .map_err(Into::<errors::ProcessTrackerError>::into)+ }+ }+ }+ }+}diff --git a/crates/router/src/core/offer_engine/types.rs b/crates/router/src/core/offer_engine/types.rsindex 4da337e71e..e52a042d76 100644--- a/crates/router/src/core/offer_engine/types.rs+++ b/crates/router/src/core/offer_engine/types.rs@@ -286,3 +286,41 @@ impl OfferApplyResponse {})}}++/// Transaction status reported to Offer Engine when revoking an applied offer; currently always `FAILURE`, the only valid revoke transition from the post-`/apply` `PENDING` state.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]+pub enum OfferTxnStatus {+ #[default]+ #[serde(rename = "FAILURE")]+ Failure,+}++/// Per-offer status reported alongside a notification; `/apply` already availed the offer, so this only ever revokes.+#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]+pub enum OfferNotifyStatus {+ #[serde(rename = "REVOKED")]+ Revoked,+}++/// A single offer's outcome inside a notification.+#[derive(Debug, Clone, serde::Serialize)]+pub struct OfferNotifyOffer {+ pub offer_id: String,+ pub status: OfferNotifyStatus,+ pub error_code: Option<String>,+ pub error_message: Option<String>,+}++/// Request body for `/offers/notify`.+#[derive(Debug, Clone, serde::Serialize)]+pub struct OfferNotifyRequest {+ pub order_id: String,+ pub txn_id: String,+ pub txn_status: OfferTxnStatus,+ pub merchant_id: String,+ pub offers: Vec<OfferNotifyOffer>,+ pub refund_id: Option<String>,+}++/// Response marker for `/offers/notify`; a 2xx is treated as delivered.+pub struct OfferNotifyResponse;diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rsindex f19b19a602..337bcceec5 100644--- a/crates/router/src/core/payments/operations/payment_response.rs+++ b/crates/router/src/core/payments/operations/payment_response.rs@@ -39,6 +39,8 @@ use tracing_futures::Instrument;use super::payment_update::PaymentUpdate;use super::{Operation, OperationSessionSetters, PostUpdateTracker};#[cfg(feature = "v1")]+use crate::core::offer_engine;+#[cfg(feature = "v1")]use crate::core::payment_methods::transformers::call_modular_payment_method_update;#[cfg(all(feature = "v1", feature = "dynamic_routing"))]use crate::core::routing::helpers as routing_helpers;@@ -3226,6 +3228,9 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(.await;}+ offer_engine::schedule_payment_notification_for_attempt(state, &payment_data.payment_attempt)+ .await;+match router_data.integrity_check {Ok(()) => Ok(payment_data),Err(err) => {diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rsindex 3db3200246..f47d32c448 100644--- a/crates/router/src/core/refunds.rs+++ b/crates/router/src/core/refunds.rs@@ -487,6 +487,11 @@ pub async fn trigger_refund_to_gateway(.await.map_err(|error| logger::warn!(refunds_outgoing_webhook_error=?error)).ok();+ #[cfg(feature = "v1")]+ if response.refund_status == diesel_models::enums::RefundStatus::Success {+ crate::core::offer_engine::schedule_refund_notification(state, payment_attempt, &response)+ .await;+ }Ok((response, router_data_res.raw_connector_response))}@@ -1115,6 +1120,11 @@ pub async fn sync_refund_with_gateway(.await.map_err(|error| logger::warn!(refunds_outgoing_webhook_error=?error)).ok();+ #[cfg(feature = "v1")]+ if response.refund_status == diesel_models::enums::RefundStatus::Success {+ crate::core::offer_engine::schedule_refund_notification(state, payment_attempt, &response)+ .await;+ }Ok((response, router_data_res.raw_connector_response))}diff --git a/crates/router/src/routes/metrics.rs b/crates/router/src/routes/metrics.rsindex 9505d44ecc..2c0ad783af 100644--- a/crates/router/src/routes/metrics.rs+++ b/crates/router/src/routes/metrics.rs@@ -234,6 +234,12 @@ counter_metric!(TASKS_ADDED_COUNT, GLOBAL_METER); // Tasks added to process traccounter_metric!(TASK_ADDITION_FAILURES_COUNT, GLOBAL_METER); // Failures in task addition to process trackercounter_metric!(TASKS_RESET_COUNT, GLOBAL_METER); // Tasks reset in process tracker for requeue flow+// Offer Engine notification (Process Tracker) metrics+counter_metric!(OFFER_ENGINE_NOTIFY_TASKS_SCHEDULED, GLOBAL_METER);+counter_metric!(OFFER_ENGINE_NOTIFY_SCHEDULE_FAILURES, GLOBAL_METER);+counter_metric!(OFFER_ENGINE_NOTIFY_SUCCESS, GLOBAL_METER);+counter_metric!(OFFER_ENGINE_NOTIFY_TERMINAL_FAILURES, GLOBAL_METER);+// Access token metrics//// A counter to indicate the number of new access tokens createddiff --git a/crates/router/src/workflows.rs b/crates/router/src/workflows.rsindex 42bead7483..89c744d6e3 100644--- a/crates/router/src/workflows.rs+++ b/crates/router/src/workflows.rs@@ -28,3 +28,6 @@ pub mod payout_sync;pub mod batch_blocklist_upload;pub mod network_tokenization;++#[cfg(feature = "v1")]+pub mod offer_engine_notify;diff --git a/crates/router/src/workflows/offer_engine_notify.rs b/crates/router/src/workflows/offer_engine_notify.rsnew file mode 100644index 0000000000..8ecc5ff0a8--- /dev/null+++ b/crates/router/src/workflows/offer_engine_notify.rs@@ -0,0 +1,28 @@+use scheduler::consumer::workflows::ProcessTrackerWorkflow;++use crate::{+ core::offer_engine::notify, errors, logger::error, routes::SessionState, types::storage,+};++pub struct OfferEngineNotifyWorkflow;++#[async_trait::async_trait]+impl ProcessTrackerWorkflow<SessionState> for OfferEngineNotifyWorkflow {+ async fn execute_workflow<'a>(+ &'a self,+ state: &'a SessionState,+ process: storage::ProcessTracker,+ ) -> Result<(), errors::ProcessTrackerError> {+ Box::pin(notify::execute_notification(state, process)).await+ }++ async fn error_handler<'a>(+ &'a self,+ _state: &'a SessionState,+ process: storage::ProcessTracker,+ _error: errors::ProcessTrackerError,+ ) -> errors::CustomResult<(), errors::ProcessTrackerError> {+ error!(%process.id, "Failed while executing offer engine notify workflow");+ Ok(())+ }+}