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(core): added key should_cancel_transaction in update trackers to support Frm Pre flow cancellation (#1811)

rishavkar5d6510eddf71
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index 7929264172..37ba25ce2c 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -1561,3 +1561,24 @@ pub enum PayoutEntityType {
Business,
Personal,
}
+
+#[derive(
+ Clone,
+ Copy,
+ Default,
+ Debug,
+ Eq,
+ Hash,
+ PartialEq,
+ serde::Deserialize,
+ serde::Serialize,
+ strum::Display,
+ strum::EnumString,
+ ToSchema,
+)]
+#[serde(rename_all = "snake_case")]
+#[strum(serialize_all = "snake_case")]
+pub enum CancelTransaction {
+ #[default]
+ FrmCancelTransaction,
+}
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index bb98368a7e..9fcc04b05d 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -207,6 +207,7 @@ where
validate_result.storage_scheme,
updated_customer,
&key_store,
+ None,
)
.await?;
}
@@ -628,6 +629,7 @@ where
merchant_account.storage_scheme,
updated_customer,
key_store,
+ None,
)
.await?;
diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs
index bbbebfa8ef..1ba878be27 100644
--- a/crates/router/src/core/payments/operations.rs
+++ b/crates/router/src/core/payments/operations.rs
@@ -10,6 +10,7 @@ pub mod payment_start;
pub mod payment_status;
pub mod payment_update;
+use api_models::enums::CancelTransaction;
use async_trait::async_trait;
use error_stack::{report, ResultExt};
use router_env::{instrument, tracing};
@@ -149,6 +150,7 @@ pub trait UpdateTracker<F, D, Req>: Send {
storage_scheme: enums::MerchantStorageScheme,
updated_customer: Option<storage::CustomerUpdate>,
mechant_key_store: &domain::MerchantKeyStore,
+ should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(BoxedOperation<'b, F, Req>, D)>
where
F: 'b + Send;
diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs
index 6bb467d8ed..e72e430285 100644
--- a/crates/router/src/core/payments/operations/payment_cancel.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel.rs
@@ -1,5 +1,6 @@
use std::marker::PhantomData;
+use api_models::enums::CancelTransaction;
use async_trait::async_trait;
use common_utils::ext_traits::AsyncExt;
use error_stack::ResultExt;
@@ -180,6 +181,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsCancelRequest> for
storage_scheme: enums::MerchantStorageScheme,
_updated_customer: Option<storage::CustomerUpdate>,
_mechant_key_store: &domain::MerchantKeyStore,
+ _should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(
BoxedOperation<'b, F, api::PaymentsCancelRequest>,
PaymentData<F>,
diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs
index 11ad4627ee..6f40bc9560 100644
--- a/crates/router/src/core/payments/operations/payment_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_capture.rs
@@ -1,5 +1,6 @@
use std::marker::PhantomData;
+use api_models::enums::CancelTransaction;
use async_trait::async_trait;
use common_utils::ext_traits::AsyncExt;
use error_stack::ResultExt;
@@ -187,6 +188,7 @@ impl<F: Clone> UpdateTracker<F, payments::PaymentData<F>, api::PaymentsCaptureRe
_storage_scheme: enums::MerchantStorageScheme,
_updated_customer: Option<storage::CustomerUpdate>,
_mechant_key_store: &domain::MerchantKeyStore,
+ _should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(
BoxedOperation<'b, F, api::PaymentsCaptureRequest>,
payments::PaymentData<F>,
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
index 2aced2b4e2..6dc4e5a4d5 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -1,5 +1,6 @@
use std::marker::PhantomData;
+use api_models::enums::CancelTransaction;
use async_trait::async_trait;
use error_stack::ResultExt;
use router_derive::PaymentOperation;
@@ -330,6 +331,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Comple
_storage_scheme: storage_enums::MerchantStorageScheme,
_updated_customer: Option<storage::CustomerUpdate>,
_merchant_key_store: &domain::MerchantKeyStore,
+ _should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(BoxedOperation<'b, F, api::PaymentsRequest>, PaymentData<F>)>
where
F: 'b + Send,
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index d22be94c1e..53454f6e4d 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -1,5 +1,6 @@
use std::marker::PhantomData;
+use api_models::enums::CancelTransaction;
use async_trait::async_trait;
use common_utils::ext_traits::{AsyncExt, Encode};
use error_stack::ResultExt;
@@ -380,6 +381,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
storage_scheme: storage_enums::MerchantStorageScheme,
updated_customer: Option<storage::CustomerUpdate>,
key_store: &domain::MerchantKeyStore,
+ should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(BoxedOperation<'b, F, api::PaymentsRequest>, PaymentData<F>)>
where
F: 'b + Send,
@@ -387,10 +389,18 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
let payment_method = payment_data.payment_attempt.payment_method;
let browser_info = payment_data.payment_attempt.browser_info.clone();
- let (intent_status, attempt_status) = (
- storage_enums::IntentStatus::Processing,
- storage_enums::AttemptStatus::Pending,
- );
+ let (intent_status, attempt_status) = match should_cancel_transaction {
+ Some(should_cancel) => match should_cancel {
+ CancelTransaction::FrmCancelTransaction => (
+ storage_enums::IntentStatus::Failed,
+ storage_enums::AttemptStatus::Failure,
+ ),
+ },
+ None => (
+ storage_enums::IntentStatus::Processing,
+ storage_enums::AttemptStatus::Pending,
+ ),
+ };
let connector = payment_data.payment_attempt.connector.clone();
let straight_through_algorithm = payment_data
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 5b638b5e7b..c491603954 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -1,5 +1,6 @@
use std::marker::PhantomData;
+use api_models::enums::CancelTransaction;
use async_trait::async_trait;
use common_utils::ext_traits::{AsyncExt, Encode, ValueExt};
use diesel_models::ephemeral_key;
@@ -350,6 +351,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
storage_scheme: enums::MerchantStorageScheme,
_updated_customer: Option<storage::CustomerUpdate>,
_merchant_key_store: &domain::MerchantKeyStore,
+ _should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(BoxedOperation<'b, F, api::PaymentsRequest>, PaymentData<F>)>
where
F: 'b + Send,
diff --git a/crates/router/src/core/payments/operations/payment_method_validate.rs b/crates/router/src/core/payments/operations/payment_method_validate.rs
index af037972ba..b3d7f59e2a 100644
--- a/crates/router/src/core/payments/operations/payment_method_validate.rs
+++ b/crates/router/src/core/payments/operations/payment_method_validate.rs
@@ -1,5 +1,6 @@
use std::marker::PhantomData;
+use api_models::enums::CancelTransaction;
use async_trait::async_trait;
use common_utils::{date_time, errors::CustomResult, ext_traits::AsyncExt};
use error_stack::ResultExt;
@@ -212,6 +213,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::VerifyRequest> for PaymentM
storage_scheme: storage_enums::MerchantStorageScheme,
_updated_customer: Option<storage::CustomerUpdate>,
_mechant_key_store: &domain::MerchantKeyStore,
+ _should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(BoxedOperation<'b, F, api::VerifyRequest>, PaymentData<F>)>
where
F: 'b + Send,
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index 7fa976b2d3..88e9c6184f 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -1,6 +1,6 @@
use std::marker::PhantomData;
-use api_models::admin::PaymentMethodsEnabled;
+use api_models::{admin::PaymentMethodsEnabled, enums::CancelTransaction};
use async_trait::async_trait;
use common_utils::ext_traits::{AsyncExt, ValueExt};
use error_stack::ResultExt;
@@ -198,6 +198,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsSessionRequest> for
storage_scheme: storage_enums::MerchantStorageScheme,
_updated_customer: Option<storage::CustomerUpdate>,
_mechant_key_store: &domain::MerchantKeyStore,
+ _should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(
BoxedOperation<'b, F, api::PaymentsSessionRequest>,
PaymentData<F>,
diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs
index afdea2a362..3610926cea 100644
--- a/crates/router/src/core/payments/operations/payment_start.rs
+++ b/crates/router/src/core/payments/operations/payment_start.rs
@@ -1,5 +1,6 @@
use std::marker::PhantomData;
+use api_models::enums::CancelTransaction;
use async_trait::async_trait;
use error_stack::ResultExt;
use router_derive::PaymentOperation;
@@ -170,6 +171,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsStartRequest> for P
_storage_scheme: storage_enums::MerchantStorageScheme,
_updated_customer: Option<storage::CustomerUpdate>,
_mechant_key_store: &domain::MerchantKeyStore,
+ _should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(
BoxedOperation<'b, F, api::PaymentsStartRequest>,
PaymentData<F>,
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index 8fd4f1e7e5..9e8f9a6267 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -1,5 +1,6 @@
use std::marker::PhantomData;
+use api_models::enums::CancelTransaction;
use async_trait::async_trait;
use common_utils::ext_traits::AsyncExt;
use error_stack::ResultExt;
@@ -122,6 +123,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
_storage_scheme: enums::MerchantStorageScheme,
_updated_customer: Option<storage::CustomerUpdate>,
_key_store: &domain::MerchantKeyStore,
+ _should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(BoxedOperation<'b, F, api::PaymentsRequest>, PaymentData<F>)>
where
F: 'b + Send,
@@ -140,6 +142,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRetrieveRequest> fo
_storage_scheme: enums::MerchantStorageScheme,
_updated_customer: Option<storage::CustomerUpdate>,
_key_store: &domain::MerchantKeyStore,
+ _should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(
BoxedOperation<'b, F, api::PaymentsRetrieveRequest>,
PaymentData<F>,
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 495e639b8c..57c8d583c8 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -1,5 +1,6 @@
use std::marker::PhantomData;
+use api_models::enums::CancelTransaction;
use async_trait::async_trait;
use common_utils::ext_traits::{AsyncExt, Encode, ValueExt};
use error_stack::ResultExt;
@@ -419,6 +420,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
storage_scheme: storage_enums::MerchantStorageScheme,
_updated_customer: Option<storage::CustomerUpdate>,
_key_store: &domain::MerchantKeyStore,
+ _should_cancel_transaction: Option<CancelTransaction>,
) -> RouterResult<(BoxedOperation<'b, F, api::PaymentsRequest>, PaymentData<F>)>
where
F: 'b + Send,