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(pm-modular): move behind feature flags (#11689)

Kashifa9c38e2d73ed
diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml
index 3a9eba984b..fde588fbdb 100644
--- a/crates/router/Cargo.toml
+++ b/crates/router/Cargo.toml
@@ -37,6 +37,7 @@ v1 = ["common_default", "api_models/v1", "diesel_models/v1", "hyperswitch_domain
dynamic_routing = ["external_services/dynamic_routing", "storage_impl/dynamic_routing", "api_models/dynamic_routing"]
revenue_recovery = ["api_models/revenue_recovery", "hyperswitch_interfaces/revenue_recovery", "hyperswitch_domain_models/revenue_recovery", "hyperswitch_connectors/revenue_recovery", "external_services/revenue_recovery", "dep:prost-types"]
tokenization_v2 = ["api_models/tokenization_v2", "diesel_models/tokenization_v2", "hyperswitch_domain_models/tokenization_v2", "storage_impl/tokenization_v2"]
+pm_modular = []
# Partial Auth
# The feature reduces the overhead of the router authenticating the merchant for every request, and trusts on `x-merchant-id` header to be present in the request.
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 6eda385161..b024cf6a98 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -115,6 +115,8 @@ use crate::core::card_testing_guard::utils as card_testing_guard_utils;
use crate::core::debit_routing;
#[cfg(feature = "frm")]
use crate::core::fraud_check as frm_core;
+#[cfg(any(feature = "v2", all(feature = "v1", feature = "pm_modular")))]
+use crate::core::payment_methods::vault;
#[cfg(feature = "v2")]
use crate::core::revenue_recovery::get_workflow_entries;
#[cfg(feature = "v2")]
@@ -135,7 +137,7 @@ use crate::{
consts,
core::{
errors::{self, CustomResult, RouterResponse, RouterResult},
- payment_methods::{cards, network_tokenization, transformers as pm_transformers, vault},
+ payment_methods::{cards, network_tokenization},
payments::helpers::{
get_applepay_metadata, is_applepay_predecrypted_flow_supported,
is_googlepay_predecrypted_flow_supported,
@@ -664,9 +666,10 @@ where
.to_validate_request()?
.validate_request(&req, platform.get_processor())?;
- // Create feature_config
+ #[cfg(feature = "pm_modular")]
let feature_config = core_utils::get_feature_config(state, platform).await;
+ #[cfg(feature = "pm_modular")]
let payment_method_info = operation
.to_domain()?
.fetch_payment_method(state, &req, platform, &feature_config)
@@ -690,6 +693,7 @@ where
platform,
auth_flow,
&header_payload,
+ #[cfg(feature = "pm_modular")]
payment_method_info,
)
.await?;
@@ -705,6 +709,7 @@ where
&payment_data.get_payment_intent().clone(),
)?;
+ #[cfg(feature = "pm_modular")]
operation
.to_domain()?
.create_payment_method(
@@ -757,6 +762,7 @@ where
&req,
platform.get_processor(),
&business_profile,
+ #[cfg(feature = "pm_modular")]
&feature_config,
&mut payment_data,
eligible_connectors,
@@ -795,6 +801,7 @@ where
&validate_result,
platform,
&business_profile,
+ #[cfg(feature = "pm_modular")]
&feature_config,
)
.await?;
@@ -981,6 +988,7 @@ where
&business_profile,
false,
None,
+ #[cfg(feature = "pm_modular")]
&feature_config,
)
.await?;
@@ -1048,6 +1056,7 @@ where
//add connector http status code metrics
add_connector_http_status_code_metrics(connector_http_status_code);
+ #[cfg(feature = "pm_modular")]
handle_pm_and_mandate_post_update(
state,
operation.as_ref(),
@@ -1060,6 +1069,18 @@ where
)
.await?;
+ #[cfg(not(feature = "pm_modular"))]
+ operation
+ .to_post_update_tracker()?
+ .save_pm_and_mandate(
+ state,
+ &router_data,
+ platform,
+ &mut payment_data,
+ &business_profile,
+ )
+ .await?;
+
let router_data_for_pm_mandate = router_data.clone();
let mut payment_data = operation
.to_post_update_tracker()?
@@ -1084,6 +1105,7 @@ where
platform.get_initiator(),
&payment_data,
&router_data_for_pm_mandate,
+ #[cfg(feature = "pm_modular")]
&feature_config,
)
.await?;
@@ -1154,6 +1176,7 @@ where
&business_profile,
false,
routing_decision,
+ #[cfg(feature = "pm_modular")]
&feature_config,
)
.await?;
@@ -1241,6 +1264,7 @@ where
#[cfg(not(feature = "frm"))]
None,
&business_profile,
+ #[cfg(feature = "pm_modular")]
&feature_config,
)
.await?;
@@ -1256,6 +1280,7 @@ where
//add connector http status code metrics
add_connector_http_status_code_metrics(connector_http_status_code);
+ #[cfg(feature = "pm_modular")]
handle_pm_and_mandate_post_update(
state,
operation.as_ref(),
@@ -1268,6 +1293,18 @@ where
)
.await?;
+ #[cfg(not(feature = "pm_modular"))]
+ operation
+ .to_post_update_tracker()?
+ .save_pm_and_mandate(
+ state,
+ &router_data,
+ platform,
+ &mut payment_data,
+ &business_profile,
+ )
+ .await?;
+
let router_data_for_pm_mandate = router_data.clone();
let mut payment_data = operation
.to_post_update_tracker()?
@@ -1292,6 +1329,7 @@ where
platform.get_initiator(),
&payment_data,
&router_data_for_pm_mandate,
+ #[cfg(feature = "pm_modular")]
&feature_config,
)
.await?;
@@ -1500,6 +1538,7 @@ where
tracing::Span::current().record("payment_id", format!("{}", validate_result.payment_id));
+ #[cfg(feature = "pm_modular")]
let feature_config = core_utils::get_feature_config(state, &platform).await;
let operations::GetTrackerResponse {
@@ -1517,6 +1556,7 @@ where
&platform,
auth_flow,
&header_payload,
+ #[cfg(feature = "pm_modular")]
None,
)
.await?;
@@ -1646,6 +1686,7 @@ where
platform.get_initiator(),
&payment_data,
&router_data_for_pm_mandate,
+ #[cfg(feature = "pm_modular")]
&feature_config,
)
.await?;
@@ -2420,7 +2461,7 @@ pub async fn call_surcharge_decision_management_for_session_flow(
}
}
-#[cfg(feature = "v1")]
+#[cfg(all(feature = "v1", feature = "pm_modular"))]
#[allow(clippy::too_many_arguments)]
async fn handle_pm_and_mandate_post_update<F, R, Op, D>(
state: &SessionState,
@@ -4778,7 +4819,7 @@ pub async fn call_connector_service_prerequisites<F, RouterDReq, ApiRequest, D>(
business_profile: &domain::Profile,
should_retry_with_pan: bool,
routing_decision: Option<routing_helpers::RoutingDecisionData>,
- feature_config: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] feature_config: &core_utils::FeatureConfig,
) -> RouterResult<(
helpers::MerchantConnectorAccountType,
RouterData<F, RouterDReq, router_types::PaymentsResponseData>,
@@ -4882,6 +4923,7 @@ where
platform,
business_profile,
should_retry_with_pan,
+ #[cfg(feature = "pm_modular")]
feature_config,
)
.await?;
@@ -8032,7 +8074,7 @@ pub async fn get_connector_tokenization_action_when_confirm_true<F, Req, D>(
platform: &domain::Platform,
business_profile: &domain::Profile,
should_retry_with_pan: bool,
- feature_config: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] feature_config: &core_utils::FeatureConfig,
) -> RouterResult<(D, TokenizationAction)>
where
F: Send + Clone,
@@ -8054,6 +8096,7 @@ where
let payment_data_and_tokenization_action = match connector {
Some(_) if is_mandate => {
+ #[cfg(feature = "pm_modular")]
if feature_config.is_payment_method_modular_allowed {
payment_data.set_payment_method_data(None);
}
@@ -8096,6 +8139,23 @@ where
let connector_tokenization_action = match payment_method_action {
TokenizationAction::TokenizeInRouter => {
+ #[cfg(not(feature = "pm_modular"))]
+ {
+ let (_operation, payment_method_data, pm_id) = operation
+ .to_domain()?
+ .make_pm_data(
+ state,
+ payment_data,
+ validate_result.storage_scheme,
+ platform,
+ business_profile,
+ should_retry_with_pan,
+ )
+ .await?;
+ payment_data.set_payment_method_data(payment_method_data);
+ payment_data.set_payment_method_id_in_attempt(pm_id);
+ }
+ #[cfg(feature = "pm_modular")]
if !feature_config.is_payment_method_modular_allowed {
let (_operation, payment_method_data, pm_id) = operation
.to_domain()?
@@ -8144,6 +8204,24 @@ where
}
TokenizationAction::TokenizeInConnector => TokenizationAction::TokenizeInConnector,
TokenizationAction::TokenizeInConnectorAndRouter => {
+ #[cfg(not(feature = "pm_modular"))]
+ {
+ let (_operation, payment_method_data, pm_id) = operation
+ .to_domain()?
+ .make_pm_data(
+ state,
+ payment_data,
+ validate_result.storage_scheme,
+ platform,
+ business_profile,
+ should_retry_with_pan,
+ )
+ .await?;
+
+ payment_data.set_payment_method_data(payment_method_data);
+ payment_data.set_payment_method_id_in_attempt(pm_id);
+ }
+ #[cfg(feature = "pm_modular")]
if !feature_config.is_payment_method_modular_allowed {
let (_operation, payment_method_data, pm_id) = operation
.to_domain()?
@@ -8234,7 +8312,7 @@ pub async fn tokenize_in_router_when_confirm_false_or_external_authentication<F,
validate_result: &operations::ValidateResult,
platform: &domain::Platform,
business_profile: &domain::Profile,
- feature_config: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] feature_config: &core_utils::FeatureConfig,
) -> RouterResult<D>
where
F: Send + Clone,
@@ -8246,6 +8324,25 @@ where
.request_external_three_ds_authentication;
let payment_data =
if !is_operation_confirm(operation) || is_external_authentication_requested == Some(true) {
+ #[cfg(not(feature = "pm_modular"))]
+ {
+ let (_operation, payment_method_data, pm_id) = operation
+ .to_domain()?
+ .make_pm_data(
+ state,
+ payment_data,
+ validate_result.storage_scheme,
+ platform,
+ business_profile,
+ false,
+ )
+ .await?;
+ payment_data.set_payment_method_data(payment_method_data);
+ if let Some(payment_method_id) = pm_id {
+ payment_data.set_payment_method_id_in_attempt(Some(payment_method_id));
+ }
+ }
+ #[cfg(feature = "pm_modular")]
if !feature_config.is_payment_method_modular_allowed {
let (_operation, payment_method_data, pm_id) = operation
.to_domain()?
@@ -8277,7 +8374,7 @@ where
Ok(payment_data.to_owned())
}
-#[cfg(feature = "v1")]
+#[cfg(all(feature = "v1", feature = "pm_modular"))]
async fn set_payment_method_from_token_for_modular_payment_method_flow<F, D>(
state: &SessionState,
payment_data: &mut D,
@@ -9329,7 +9426,7 @@ pub async fn choose_connector<F, Req, D>(
req: &Req,
processor: &domain::Processor,
business_profile: &domain::Profile,
- feature_config: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] feature_config: &core_utils::FeatureConfig,
payment_data: &mut D,
eligible_connectors: Option<Vec<enums::RoutableConnectors>>,
mandate_type: Option<api::MandateTransactionType>,
@@ -9398,6 +9495,7 @@ where
state,
processor,
business_profile,
+ #[cfg(feature = "pm_modular")]
feature_config,
payment_data,
Some(straight_through),
@@ -9414,6 +9512,7 @@ where
state,
processor,
business_profile,
+ #[cfg(feature = "pm_modular")]
feature_config,
payment_data,
None,
@@ -9613,7 +9712,7 @@ pub async fn perform_routing_for_connector_selection<F, D>(
state: &SessionState,
processor: &domain::Processor,
business_profile: &domain::Profile,
- feature_config: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] feature_config: &core_utils::FeatureConfig,
payment_data: &mut D,
request_straight_through: Option<serde_json::Value>,
eligible_connectors: Option<Vec<enums::RoutableConnectors>>,
@@ -9666,7 +9765,10 @@ where
mandate_type,
fallback_config,
backend_input,
+ #[cfg(feature = "pm_modular")]
feature_config.is_payment_method_modular_allowed,
+ #[cfg(not(feature = "pm_modular"))]
+ false,
)
.await?;
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index a1b0a51b20..1f06b3349b 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -467,7 +467,10 @@ pub async fn get_token_pm_type_mandate_details(
pm_info: Option<domain::PaymentMethod>,
) -> RouterResult<MandateGenericData> {
let mandate_data = request.mandate_data.clone().map(MandateData::foreign_from);
- let feature_config = core_utils::get_feature_config(state, platform).await;
+ #[cfg(feature = "pm_modular")]
+ let is_payment_method_modular_allowed = core_utils::get_feature_config(state, platform)
+ .await
+ .is_payment_method_modular_allowed;
let (
payment_token,
payment_method,
@@ -750,7 +753,8 @@ pub async fn get_token_pm_type_mandate_details(
}
}
None => {
- let payment_method_info = if feature_config.is_payment_method_modular_allowed {
+ #[cfg(feature = "pm_modular")]
+ let payment_method_info = if is_payment_method_modular_allowed {
pm_info
} else {
payment_method_id
@@ -768,6 +772,21 @@ pub async fn get_token_pm_type_mandate_details(
.await
.transpose()?
};
+ #[cfg(not(feature = "pm_modular"))]
+ let payment_method_info = payment_method_id
+ .async_map(|payment_method_id| async move {
+ state
+ .store
+ .find_payment_method(
+ platform.get_provider().get_key_store(),
+ &payment_method_id,
+ platform.get_provider().get_account().storage_scheme,
+ )
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)
+ })
+ .await
+ .transpose()?;
let resolved_payment_method = request.payment_method.or_else(|| {
payment_method_info
.as_ref()
diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs
index 0637a22790..8b019ca094 100644
--- a/crates/router/src/core/payments/operations.rs
+++ b/crates/router/src/core/payments/operations.rs
@@ -99,15 +99,16 @@ pub use self::{
payment_session_intent::PaymentSessionIntent,
};
use super::{helpers, CustomerDetails, OperationSessionGetters, OperationSessionSetters};
+#[cfg(all(feature = "v1", feature = "pm_modular"))]
+use crate::core::payment_methods::transformers::PaymentMethodWithRawData;
#[cfg(feature = "v2")]
use crate::core::payments;
-#[cfg(feature = "v1")]
-use crate::core::payments::pm_transformers::PaymentMethodWithRawData;
+#[cfg(feature = "pm_modular")]
+use crate::core::utils as core_utils;
use crate::{
core::{
configs::dimension_state::DimensionsWithMerchantIdAndProfileId,
errors::{self, CustomResult, RouterResult},
- utils as core_utils,
},
routes::{app::ReqState, SessionState},
services,
@@ -221,7 +222,9 @@ pub trait GetTracker<F: Clone, D, R>: Send {
platform: &domain::Platform,
auth_flow: services::AuthFlow,
header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- payment_method_with_raw_data: Option<PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] payment_method_with_raw_data: Option<
+ PaymentMethodWithRawData,
+ >,
) -> RouterResult<GetTrackerResponse<'a, F, R, D>>;
#[cfg(feature = "v2")]
@@ -311,7 +314,7 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {
) -> CustomResult<(), errors::ApiErrorResponse> {
Ok(())
}
- #[cfg(feature = "v1")]
+ #[cfg(all(feature = "v1", feature = "pm_modular"))]
async fn create_payment_method(
&self,
_state: &SessionState,
@@ -324,7 +327,7 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {
Ok(())
}
- #[cfg(feature = "v1")]
+ #[cfg(all(feature = "v1", feature = "pm_modular"))]
async fn fetch_payment_method(
&self,
_state: &SessionState,
@@ -623,7 +626,7 @@ pub trait PostUpdateTracker<F, D, R: Send>: Send {
_initiator: Option<&domain::Initiator>,
_payment_data: &D,
_router_data: &types::RouterData<F, R, PaymentsResponseData>,
- _feature_set: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] _feature_set: &core_utils::FeatureConfig,
) -> RouterResult<()>
where
F: 'b + Clone + Send + Sync,
@@ -631,7 +634,7 @@ pub trait PostUpdateTracker<F, D, R: Send>: Send {
Ok(())
}
- #[cfg(feature = "v1")]
+ #[cfg(all(feature = "v1", feature = "pm_modular"))]
async fn update_modular_pm_and_mandate<'b>(
&self,
_state: &SessionState,
diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs
index 4844cb2573..7c1953a66f 100644
--- a/crates/router/src/core/payments/operations/payment_approve.rs
+++ b/crates/router/src/core/payments/operations/payment_approve.rs
@@ -42,7 +42,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCaptureR
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<'a, F, api::PaymentsCaptureRequest, PaymentData<F>>,
> {
diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs
index 51677b5576..875fbe21c8 100644
--- a/crates/router/src/core/payments/operations/payment_cancel.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel.rs
@@ -44,7 +44,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelRe
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<'a, F, api::PaymentsCancelRequest, PaymentData<F>>,
> {
diff --git a/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs b/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs
index 4108a16ba0..1dcb7741d6 100644
--- a/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs
@@ -43,7 +43,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelPo
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<
'a,
diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs
index da525e7e8b..7aa95e2605 100644
--- a/crates/router/src/core/payments/operations/payment_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_capture.rs
@@ -44,7 +44,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, payments::PaymentData<F>, api::Paymen
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<
'a,
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 248abd32da..c460a0ae18 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -49,7 +49,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
let db = &*state.store;
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index a5a4af16ef..48dc30a599 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -12,7 +12,9 @@ use common_utils::ext_traits::{AsyncExt, Encode, StringExt, ValueExt};
use diesel_models::payment_attempt::ConnectorMandateReferenceId as DieselConnectorMandateReferenceId;
use error_stack::{report, ResultExt};
use futures::FutureExt;
-#[cfg(feature = "v1")]
+#[cfg(all(feature = "v1", not(feature = "pm_modular")))]
+use hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdateFields;
+#[cfg(all(feature = "v1", feature = "pm_modular"))]
use hyperswitch_domain_models::payments::{
self as domain_payments, payment_intent::PaymentIntentUpdateFields,
};
@@ -26,6 +28,10 @@ use router_env::{instrument, logger, tracing};
use tracing_futures::Instrument;
use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, ValidateRequest};
+#[cfg(feature = "pm_modular")]
+use crate::core::payment_methods::{transformers as pm_transformers, utils as pm_utils};
+#[cfg(feature = "pm_modular")]
+use crate::core::payments::OperationSessionSetters;
#[cfg(feature = "v1")]
use crate::{
consts,
@@ -41,12 +47,11 @@ use crate::{
errors::{self, CustomResult, RouterResult, StorageErrorExt},
mandate::helpers as m_helpers,
metrics,
- payment_methods::{transformers as pm_transformers, utils as pm_utils},
payments::{
self, helpers, operations,
operations::payment_confirm::unified_authentication_service::ThreeDsMetaData,
populate_installment_details, populate_surcharge_details, CustomerDetails,
- OperationSessionGetters, OperationSessionSetters, PaymentAddress, PaymentData,
+ OperationSessionGetters, PaymentAddress, PaymentData,
},
three_ds_decision_rule,
unified_authentication_service::{
@@ -86,7 +91,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
platform: &domain::Platform,
auth_flow: services::AuthFlow,
header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- payment_method_with_raw_data: Option<pm_transformers::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] payment_method_with_raw_data: Option<
+ pm_transformers::PaymentMethodWithRawData,
+ >,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
let processor_merchant_id = platform.get_processor().get_account().get_id();
@@ -539,6 +546,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
let n_payment_method_billing_address_id =
payment_attempt.payment_method_billing_address_id.clone();
+ #[cfg(feature = "pm_modular")]
let n_request_payment_method_billing_address = request
.payment_method_data
.as_ref()
@@ -555,6 +563,11 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.ok()
})
}));
+ #[cfg(not(feature = "pm_modular"))]
+ let n_request_payment_method_billing_address = request
+ .payment_method_data
+ .as_ref()
+ .and_then(|pmd| pmd.billing.clone());
let m_payment_intent_customer_id = payment_intent.customer_id.clone();
let m_payment_intent_payment_id = payment_intent.payment_id.clone();
let m_key_store = platform.get_processor().get_key_store().clone();
@@ -599,8 +612,13 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
let m_request = request.clone();
let payment_intent_customer_id = payment_intent.customer_id.clone();
+ #[cfg(feature = "pm_modular")]
+ let payment_method_info_from_modular = payment_method_with_raw_data
+ .clone()
+ .map(|pm| pm.payment_method.0);
+ #[cfg(not(feature = "pm_modular"))]
+ let payment_method_info_from_modular = None;
- let m_pm_wrapper = payment_method_with_raw_data.clone();
let mandate_details_fut = tokio::spawn(
async move {
Box::pin(helpers::get_token_pm_type_mandate_details(
@@ -610,7 +628,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
&m_platform,
None,
payment_intent_customer_id.as_ref(),
- m_pm_wrapper.map(|pm| pm.payment_method.0),
+ payment_method_info_from_modular,
))
.await
}
@@ -652,6 +670,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
//fetch for repeat cit using payment token
+ #[cfg(feature = "pm_modular")]
let is_modular_payment_method_flow =
pm_utils::get_organization_eligibility_config_for_pm_modular_service(
&*state.store,
@@ -659,6 +678,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
)
.await;
+ #[cfg(feature = "pm_modular")]
let (token_data, payment_method_info) = if is_modular_payment_method_flow {
(
None,
@@ -685,6 +705,26 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
} else {
(None, payment_method_info)
};
+ #[cfg(not(feature = "pm_modular"))]
+ let (token_data, payment_method_info) = if let Some(token) = token.clone() {
+ let token_data = helpers::retrieve_payment_token_data(
+ state,
+ token,
+ payment_method.or(payment_attempt.payment_method),
+ )
+ .await?;
+
+ let payment_method_info = helpers::retrieve_payment_method_from_db_with_token_data(
+ state,
+ platform.get_provider().get_key_store(),
+ &token_data,
+ storage_scheme,
+ )
+ .await?;
+ (Some(token_data), payment_method_info)
+ } else {
+ (None, payment_method_info)
+ };
let additional_pm_data_from_locker = if let Some(ref pm) = payment_method_info {
let card_detail_from_locker: Option<api::CardDetailFromLocker> = pm
.payment_method_data
@@ -761,6 +801,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
request_payment_method_data.payment_method_data.clone()
});
+ #[cfg(feature = "pm_modular")]
let payment_method_data = payment_method_with_raw_data
.clone()
.and_then(|pm| pm.raw_payment_method_data)
@@ -773,6 +814,17 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
payment_method_data
}
});
+ #[cfg(not(feature = "pm_modular"))]
+ let payment_method_data = payment_method_data_from_request
+ .map(Into::into)
+ .or(payment_method_recurring_details.clone())
+ .map(|payment_method_data| {
+ if let Some(additional_pm_data) = additional_pm_data {
+ payment_method_data.apply_additional_payment_data(additional_pm_data)
+ } else {
+ payment_method_data
+ }
+ });
payment_attempt.payment_method_billing_address_id = payment_method_billing
.as_ref()
@@ -793,6 +845,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
payment_method_data_billing.get_billing_address()
})
.map(From::from);
+ #[cfg(feature = "pm_modular")]
let pm_pmd_billing = payment_method_with_raw_data.as_ref().and_then(|pm| {
pm.payment_method
.0
@@ -809,7 +862,10 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
});
// billing address from request body has the highest priority followed by billing address from raw pm data and then billing address from payment_attempt
+ #[cfg(feature = "pm_modular")]
let pmd_address = payment_method_data_billing.or(pm_pmd_billing);
+ #[cfg(not(feature = "pm_modular"))]
+ let pmd_address = payment_method_data_billing;
let unified_address = address.unify_with_payment_method_data_billing(pmd_address);
@@ -882,6 +938,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
);
//setting vault operation to existing vault data if raw payment method data is present in pm_info
+ #[cfg(feature = "pm_modular")]
let vault_operation =
payment_method_with_raw_data.and_then(|pm| match pm.raw_payment_method_data {
Some(domain::PaymentMethodData::Card(card)) => {
@@ -891,6 +948,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
}
_ => None,
});
+ #[cfg(not(feature = "pm_modular"))]
+ let vault_operation = None;
payment_attempt.installment_data = request.installment_data.clone().map(Into::into);
@@ -1079,6 +1138,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
Ok(())
}
+ #[cfg(feature = "pm_modular")]
#[instrument(skip_all)]
async fn create_payment_method(
&self,
@@ -1172,6 +1232,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
}
}
+ #[cfg(feature = "pm_modular")]
#[instrument(skip_all)]
async fn fetch_payment_method(
&self,
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index b616ca762a..97b55b74fd 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -28,6 +28,8 @@ use storage_impl::platform_wrapper;
use time::PrimitiveDateTime;
use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, ValidateRequest};
+#[cfg(feature = "pm_modular")]
+use crate::core::payment_methods::transformers as pm_transformers;
use crate::{
consts,
core::{
@@ -35,7 +37,6 @@ use crate::{
errors::{self, CustomResult, RouterResult, StorageErrorExt},
mandate::helpers as m_helpers,
payment_link,
- payment_methods::transformers as pm_transformers,
payments::{
self, client_session::ClientSessionManager, helpers, operations, CustomerDetails,
PaymentAddress, PaymentData,
@@ -78,7 +79,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- payment_method_with_raw_data: Option<pm_transformers::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] payment_method_with_raw_data: Option<
+ pm_transformers::PaymentMethodWithRawData,
+ >,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
let db = &*state.store;
@@ -153,7 +156,13 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
reason: "Expected one out of recurring_details and mandate_data but got both".into(),
})?;
- let m_pm_wrapper = payment_method_with_raw_data.clone();
+ #[cfg(feature = "pm_modular")]
+ let payment_method_info_from_modular = payment_method_with_raw_data
+ .clone()
+ .map(|pm| pm.payment_method.0);
+ #[cfg(not(feature = "pm_modular"))]
+ let payment_method_info_from_modular = None;
+
let m_helpers::MandateGenericData {
token,
payment_method,
@@ -169,7 +178,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
platform,
None,
None,
- m_pm_wrapper.map(|pm| pm.payment_method.0),
+ payment_method_info_from_modular,
)
.await?;
@@ -207,6 +216,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
)
.await?;
+ #[cfg(feature = "pm_modular")]
let payment_method_data_billing = request
.payment_method_data
.as_ref()
@@ -224,6 +234,12 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
})
}));
+ #[cfg(not(feature = "pm_modular"))]
+ let payment_method_data_billing = request
+ .payment_method_data
+ .as_ref()
+ .and_then(|pmd| pmd.billing.clone());
+
let payment_method_billing_address =
helpers::create_or_find_address_for_payment_by_request(
state,
@@ -530,6 +546,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
request_payment_method_data.payment_method_data.clone()
});
+ #[cfg(feature = "pm_modular")]
let payment_method_data = payment_method_with_raw_data
.clone()
.and_then(|pm| pm.raw_payment_method_data)
@@ -543,6 +560,18 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
}
});
+ #[cfg(not(feature = "pm_modular"))]
+ let payment_method_data = payment_method_data_from_request
+ .map(Into::into)
+ .or(payment_method_recurring_details.clone())
+ .map(|payment_method_data| {
+ if let Some(additional_pm_data) = additional_payment_data {
+ payment_method_data.apply_additional_payment_data(additional_pm_data)
+ } else {
+ payment_method_data
+ }
+ });
+
let additional_pm_data_from_locker = if let Some(ref pm) = payment_method_info {
let card_detail_from_locker: Option<api::CardDetailFromLocker> = pm
.payment_method_data
@@ -609,6 +638,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
payment_method_data_billing.get_billing_address()
})
.map(From::from);
+ #[cfg(feature = "pm_modular")]
let pm_pmd_billing = payment_method_with_raw_data.as_ref().and_then(|pm| {
pm.payment_method
.0
@@ -624,7 +654,10 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
})
});
+ #[cfg(feature = "pm_modular")]
let add = payment_method_data_billing.or(pm_pmd_billing);
+ #[cfg(not(feature = "pm_modular"))]
+ let add = payment_method_data_billing;
let unified_address = address.unify_with_payment_method_data_billing(add);
@@ -865,6 +898,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
}
}
+ #[cfg(feature = "pm_modular")]
#[instrument(skip_all)]
async fn fetch_payment_method(
&self,
@@ -1254,6 +1288,7 @@ impl<F: Send + Clone + Sync> ValidateRequest<F, api::PaymentsRequest, PaymentDat
impl PaymentCreate {
/// Determines the payment method reference for modular payment flows.
+ #[cfg(feature = "pm_modular")]
fn get_payment_method_reference(self, req: &api::PaymentsRequest) -> Option<&String> {
match (req.off_session, req.recurring_details.as_ref()) {
// Payment using off_session MITs using PM ID
diff --git a/crates/router/src/core/payments/operations/payment_post_session_tokens.rs b/crates/router/src/core/payments/operations/payment_post_session_tokens.rs
index 8e6eb07c05..2210c2e609 100644
--- a/crates/router/src/core/payments/operations/payment_post_session_tokens.rs
+++ b/crates/router/src/core/payments/operations/payment_post_session_tokens.rs
@@ -44,7 +44,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsPostSess
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<
'a,
diff --git a/crates/router/src/core/payments/operations/payment_recurrence.rs b/crates/router/src/core/payments/operations/payment_recurrence.rs
index 51d6b3a115..d7ee67aa32 100644
--- a/crates/router/src/core/payments/operations/payment_recurrence.rs
+++ b/crates/router/src/core/payments/operations/payment_recurrence.rs
@@ -59,9 +59,16 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- payment_method_with_raw_data: Option<pm_transformers::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] payment_method_with_raw_data: Option<
+ pm_transformers::PaymentMethodWithRawData,
+ >,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
+ #[cfg(not(feature = "pm_modular"))]
+ let payment_method_with_raw_data: Option<
+ pm_transformers::PaymentMethodWithRawData,
+ > = None;
+
let processor_merchant_id = platform.get_processor().get_account().get_id();
let storage_scheme = platform.get_processor().get_account().storage_scheme;
let (currency, amount);
diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs
index f341ea33cf..cff2474c3f 100644
--- a/crates/router/src/core/payments/operations/payment_reject.rs
+++ b/crates/router/src/core/payments/operations/payment_reject.rs
@@ -41,7 +41,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, PaymentsCancelRequest
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<operations::GetTrackerResponse<'a, F, PaymentsCancelRequest, PaymentData<F>>>
{
let db = &*state.store;
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index b418c4221c..01303a53fa 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -1,6 +1,6 @@
use std::{collections::HashMap, ops::Deref};
-#[cfg(feature = "v1")]
+#[cfg(all(feature = "v1", feature = "pm_modular"))]
use ::payment_methods::client::{
CardDetailUpdate, PaymentMethodUpdateData, UpdatePaymentMethodV1Payload,
};
@@ -9,7 +9,7 @@ use api_models::payments::{ConnectorMandateReferenceId, MandateReferenceId};
use api_models::routing::RoutableConnectorChoice;
use async_trait::async_trait;
use common_enums::AuthorizationStatus;
-#[cfg(feature = "v1")]
+#[cfg(all(feature = "v1", feature = "pm_modular"))]
use common_enums::{ConnectorTokenStatus, TokenizationType};
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
use common_utils::ext_traits::ValueExt;
@@ -32,7 +32,7 @@ use router_env::{instrument, logger, tracing};
use tracing_futures::Instrument;
use super::{Operation, OperationSessionSetters, PostUpdateTracker};
-#[cfg(feature = "v1")]
+#[cfg(all(feature = "v1", feature = "pm_modular"))]
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;
@@ -70,7 +70,7 @@ use crate::{
/// This implementation executes the flow only when
/// 1. Payment was created with supported payment methods
/// 2. Payment attempt's status was not a terminal failure
-#[cfg(feature = "v1")]
+#[cfg(all(feature = "v1", feature = "pm_modular"))]
async fn update_modular_pm_and_mandate_impl<F, T>(
state: &SessionState,
resp: &types::RouterData<F, T, types::PaymentsResponseData>,
@@ -719,12 +719,27 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
types::PaymentsAuthorizeData,
types::PaymentsResponseData,
>,
- feature_set: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] feature_set: &core_utils::FeatureConfig,
) -> RouterResult<()>
where
F: 'b + Clone + Send + Sync,
{
- if !feature_set.is_payment_method_modular_allowed {
+ #[cfg(feature = "pm_modular")]
+ {
+ if !feature_set.is_payment_method_modular_allowed {
+ return update_pm_connector_mandate_details(
+ state,
+ provider,
+ initiator,
+ payment_data,
+ router_data,
+ )
+ .await;
+ }
+ Ok(())
+ }
+ #[cfg(not(feature = "pm_modular"))]
+ {
update_pm_connector_mandate_details(
state,
provider,
@@ -733,12 +748,10 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
router_data,
)
.await
- } else {
- Ok(())
}
}
- #[cfg(feature = "v1")]
+ #[cfg(all(feature = "v1", feature = "pm_modular"))]
async fn update_modular_pm_and_mandate<'b>(
&self,
state: &SessionState,
@@ -1020,12 +1033,27 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for
initiator: Option<&domain::Initiator>,
payment_data: &PaymentData<F>,
router_data: &types::RouterData<F, types::PaymentsSyncData, types::PaymentsResponseData>,
- feature_set: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] feature_set: &core_utils::FeatureConfig,
) -> RouterResult<()>
where
F: 'b + Clone + Send + Sync,
{
- if !feature_set.is_payment_method_modular_allowed {
+ #[cfg(feature = "pm_modular")]
+ {
+ if !feature_set.is_payment_method_modular_allowed {
+ return update_pm_connector_mandate_details(
+ state,
+ provider,
+ initiator,
+ payment_data,
+ router_data,
+ )
+ .await;
+ }
+ Ok(())
+ }
+ #[cfg(not(feature = "pm_modular"))]
+ {
update_pm_connector_mandate_details(
state,
provider,
@@ -1034,12 +1062,10 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for
router_data,
)
.await
- } else {
- Ok(())
}
}
- #[cfg(feature = "v1")]
+ #[cfg(all(feature = "v1", feature = "pm_modular"))]
async fn update_modular_pm_and_mandate<'b>(
&self,
state: &SessionState,
@@ -1766,7 +1792,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
types::SetupMandateRequestData,
types::PaymentsResponseData,
>,
- _feature_set: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] _feature_set: &core_utils::FeatureConfig,
) -> RouterResult<()>
where
F: 'b + Clone + Send + Sync,
@@ -1774,7 +1800,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
update_pm_connector_mandate_details(state, provider, initiator, payment_data, router_data)
.await
}
- #[cfg(feature = "v1")]
+ #[cfg(all(feature = "v1", feature = "pm_modular"))]
async fn update_modular_pm_and_mandate<'b>(
&self,
state: &SessionState,
@@ -1892,12 +1918,27 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
types::CompleteAuthorizeData,
types::PaymentsResponseData,
>,
- feature_set: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] feature_set: &core_utils::FeatureConfig,
) -> RouterResult<()>
where
F: 'b + Clone + Send + Sync,
{
- if !feature_set.is_payment_method_modular_allowed {
+ #[cfg(feature = "pm_modular")]
+ {
+ if !feature_set.is_payment_method_modular_allowed {
+ return update_pm_connector_mandate_details(
+ state,
+ provider,
+ initiator,
+ payment_data,
+ router_data,
+ )
+ .await;
+ }
+ Ok(())
+ }
+ #[cfg(not(feature = "pm_modular"))]
+ {
update_pm_connector_mandate_details(
state,
provider,
@@ -1906,12 +1947,10 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
router_data,
)
.await
- } else {
- Ok(())
}
}
- #[cfg(feature = "v1")]
+ #[cfg(all(feature = "v1", feature = "pm_modular"))]
async fn update_modular_pm_and_mandate<'b>(
&self,
state: &SessionState,
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index aac497e201..7553e77173 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -44,7 +44,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsSessionR
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<'a, 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 f449e146a8..ab54a4b5d2 100644
--- a/crates/router/src/core/payments/operations/payment_start.rs
+++ b/crates/router/src/core/payments/operations/payment_start.rs
@@ -7,12 +7,13 @@ use router_derive::PaymentOperation;
use router_env::{instrument, logger, tracing};
use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, ValidateRequest};
+#[cfg(feature = "pm_modular")]
+use crate::core::utils;
use crate::{
core::{
configs::dimension_state::DimensionsWithMerchantIdAndProfileId,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments::{helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
- utils,
},
routes::{app::ReqState, SessionState},
services,
@@ -44,7 +45,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsStartReq
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<'a, F, api::PaymentsStartRequest, PaymentData<F>>,
> {
@@ -127,19 +130,38 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsStartReq
)
.await?;
- let feature_config = utils::get_feature_config(state, platform).await;
-
// In case of modular payment method flow payment token in the request will belong to payment method modular service
// hence populating token data is not required
- let token_data = match (
- payment_attempt.payment_token.clone(),
- feature_config.is_payment_method_modular_allowed,
- ) {
- (Some(token), false) => Some(
+ #[cfg(feature = "pm_modular")]
+ let token_data = {
+ let is_payment_method_modular_allowed = utils::get_feature_config(state, platform)
+ .await
+ .is_payment_method_modular_allowed;
+ match (
+ payment_attempt.payment_token.clone(),
+ is_payment_method_modular_allowed,
+ ) {
+ (Some(token), false) => Some(
+ helpers::retrieve_payment_token_data(
+ state,
+ token,
+ payment_attempt.payment_method,
+ )
+ .await?,
+ ),
+ _ => {
+ logger::debug!("skipping token data retrieval in payment start");
+ None
+ }
+ }
+ };
+ #[cfg(not(feature = "pm_modular"))]
+ let token_data = match payment_attempt.payment_token.clone() {
+ Some(token) => Some(
helpers::retrieve_payment_token_data(state, token, payment_attempt.payment_method)
.await?,
),
- _ => {
+ None => {
logger::debug!("skipping token data retrieval in payment start");
None
}
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index 1077e875dc..c3f9220eeb 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -228,7 +228,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRetrieve
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<'a, 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 0871ade56e..044d33e4cb 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -59,7 +59,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
platform: &domain::Platform,
auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
let (mut payment_intent, mut payment_attempt, currency): (_, _, storage_enums::Currency);
diff --git a/crates/router/src/core/payments/operations/payment_update_metadata.rs b/crates/router/src/core/payments/operations/payment_update_metadata.rs
index 62b927e533..d90b6075ac 100644
--- a/crates/router/src/core/payments/operations/payment_update_metadata.rs
+++ b/crates/router/src/core/payments/operations/payment_update_metadata.rs
@@ -45,7 +45,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsUpdateMe
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<'a, F, api::PaymentsUpdateMetadataRequest, PaymentData<F>>,
> {
diff --git a/crates/router/src/core/payments/operations/payments_extend_authorization.rs b/crates/router/src/core/payments/operations/payments_extend_authorization.rs
index a22ae1d762..bd9c924724 100644
--- a/crates/router/src/core/payments/operations/payments_extend_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_extend_authorization.rs
@@ -43,7 +43,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsExtendAu
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<
'a,
diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
index 7f66a407b5..da6bb861cb 100644
--- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
@@ -48,7 +48,9 @@ impl<F: Send + Clone + Sync>
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<
'a,
diff --git a/crates/router/src/core/payments/operations/tax_calculation.rs b/crates/router/src/core/payments/operations/tax_calculation.rs
index 48096e828c..55303c05c2 100644
--- a/crates/router/src/core/payments/operations/tax_calculation.rs
+++ b/crates/router/src/core/payments/operations/tax_calculation.rs
@@ -50,7 +50,9 @@ impl<F: Send + Clone + Sync>
platform: &domain::Platform,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_wrapper: Option<operations::PaymentMethodWithRawData>,
+ #[cfg(feature = "pm_modular")] _payment_method_wrapper: Option<
+ operations::PaymentMethodWithRawData,
+ >,
) -> RouterResult<
operations::GetTrackerResponse<
'a,
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index ac32d71973..5647a998a0 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -9,6 +9,8 @@ use router_env::{
tracing::{self, instrument},
};
+#[cfg(feature = "pm_modular")]
+use crate::core::utils as core_utils;
use crate::{
consts,
core::{
@@ -19,7 +21,6 @@ use crate::{
helpers as payments_helpers, operations,
},
routing::helpers as routing_helpers,
- utils as core_utils,
},
db::StorageInterface,
routes::{
@@ -48,7 +49,7 @@ pub async fn do_gsm_actions<'a, F, ApiRequest, FData, D>(
schedule_time: Option<time::PrimitiveDateTime>,
frm_suggestion: Option<storage_enums::FrmSuggestion>,
business_profile: &domain::Profile,
- feature_config: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] feature_config: &core_utils::FeatureConfig,
) -> RouterResult<types::RouterData<F, FData, types::PaymentsResponseData>>
where
F: Clone + Send + Sync + std::fmt::Debug + 'static,
@@ -118,6 +119,7 @@ where
false, //should_retry_with_pan is not applicable for step-up
None,
initial_gsm.clone(),
+ #[cfg(feature = "pm_modular")]
feature_config,
)
.await?;
@@ -225,6 +227,7 @@ where
should_retry_with_pan,
routing_decision,
gsm.clone(),
+ #[cfg(feature = "pm_modular")]
feature_config,
)
.await?;
@@ -374,7 +377,7 @@ pub async fn do_retry<'a, F, ApiRequest, FData, D>(
should_retry_with_pan: bool,
routing_decision: Option<routing_helpers::RoutingDecisionData>,
initial_gsm: Option<hyperswitch_domain_models::gsm::GatewayStatusMap>,
- feature_config: &core_utils::FeatureConfig,
+ #[cfg(feature = "pm_modular")] feature_config: &core_utils::FeatureConfig,
) -> RouterResult<types::RouterData<F, FData, types::PaymentsResponseData>>
where
F: Clone + Send + Sync + std::fmt::Debug + 'static,
@@ -414,6 +417,7 @@ where
business_profile,
should_retry_with_pan,
routing_decision,
+ #[cfg(feature = "pm_modular")]
feature_config,
)
.await?;
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 1e85e5ab5e..77f4f7c6fe 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -60,13 +60,13 @@ use crate::{
utils::{generate_id, OptionExt, ValueExt},
};
-#[cfg(feature = "v1")]
+#[cfg(all(feature = "v1", feature = "pm_modular"))]
#[derive(Debug, Clone, Default)]
pub struct FeatureConfig {
pub is_payment_method_modular_allowed: bool,
}
-#[cfg(feature = "v1")]
+#[cfg(all(feature = "v1", feature = "pm_modular"))]
pub async fn get_feature_config(
state: &SessionState,
platform: &domain::Platform,
@@ -89,14 +89,19 @@ pub async fn validate_legacy_endpoint_access<E>(
where
E: From<errors::ApiErrorResponse> + error_stack::Context,
{
- let feature_config = get_feature_config(state, platform).await;
- common_utils::fp_utils::when(feature_config.is_payment_method_modular_allowed, || {
- Err(error_stack::report!(E::from(
- errors::ApiErrorResponse::AccessForbidden {
- resource: "Deprecated route".to_string(),
- },
- )))
- })?;
+ #[cfg(feature = "pm_modular")]
+ {
+ let feature_config = get_feature_config(state, platform).await;
+ common_utils::fp_utils::when(feature_config.is_payment_method_modular_allowed, || {
+ Err(error_stack::report!(E::from(
+ errors::ApiErrorResponse::AccessForbidden {
+ resource: "Deprecated route".to_string(),
+ },
+ )))
+ })?;
+ }
+ #[cfg(not(feature = "pm_modular"))]
+ let _ = (state, platform);
Ok(())
}