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(payment-methods): version based retrievals for payments service (#12020)

Kashif9e9ea6e623cd
diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs
index c12b9340dd..622bea87bf 100644
--- a/crates/diesel_models/src/payment_method.rs
+++ b/crates/diesel_models/src/payment_method.rs
@@ -87,6 +87,7 @@ pub struct PaymentMethod {
//customer_id should only be none in case of guest checkout flow as volatile pm are stored in redis, for all other cases it should be present to maintain the db persistency
pub customer_id: Option<common_utils::id_type::GlobalCustomerId>,
pub merchant_id: common_utils::id_type::MerchantId,
+ pub payment_method_id: Option<String>,
pub created_at: PrimitiveDateTime,
pub last_modified: PrimitiveDateTime,
pub payment_method_data: Option<Encryption>,
@@ -184,6 +185,7 @@ pub struct PaymentMethodNew {
pub struct PaymentMethodNew {
pub customer_id: Option<common_utils::id_type::GlobalCustomerId>,
pub merchant_id: common_utils::id_type::MerchantId,
+ pub payment_method_id: Option<String>,
pub created_at: PrimitiveDateTime,
pub last_modified: PrimitiveDateTime,
pub payment_method_data: Option<Encryption>,
@@ -440,6 +442,7 @@ impl PaymentMethodUpdateInternal {
payment_method_type_v2: payment_method_type_v2.or(source.payment_method_type_v2),
payment_method_subtype: payment_method_subtype.or(source.payment_method_subtype),
id: source.id,
+ payment_method_id: source.payment_method_id,
version: source.version,
network_token_requestor_reference_id: network_token_requestor_reference_id
.or(source.network_token_requestor_reference_id),
@@ -1209,6 +1212,7 @@ impl From<&PaymentMethodNew> for PaymentMethod {
payment_method_type_v2: payment_method_new.payment_method_type_v2,
payment_method_subtype: payment_method_new.payment_method_subtype,
id: payment_method_new.id.clone(),
+ payment_method_id: payment_method_new.payment_method_id.clone(),
version: payment_method_new.version,
network_token_requestor_reference_id: payment_method_new
.network_token_requestor_reference_id
@@ -1240,7 +1244,6 @@ pub struct PaymentsMandateReferenceRecord {
pub connector_customer_id: Option<String>,
}
-#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ConnectorTokenReferenceRecord {
pub connector_token: String,
@@ -1274,14 +1277,12 @@ impl std::ops::DerefMut for PaymentsMandateReference {
}
}
-#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::AsExpression)]
#[diesel(sql_type = diesel::sql_types::Jsonb)]
pub struct PaymentsTokenReference(
pub HashMap<common_utils::id_type::MerchantConnectorAccountId, ConnectorTokenReferenceRecord>,
);
-#[cfg(feature = "v2")]
impl std::ops::Deref for PaymentsTokenReference {
type Target =
HashMap<common_utils::id_type::MerchantConnectorAccountId, ConnectorTokenReferenceRecord>;
@@ -1291,7 +1292,6 @@ impl std::ops::Deref for PaymentsTokenReference {
}
}
-#[cfg(feature = "v2")]
impl std::ops::DerefMut for PaymentsTokenReference {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
@@ -1410,6 +1410,75 @@ impl CommonMandateReference {
Ok(payments)
}
+ #[cfg(feature = "v1")]
+ fn parse_payments_reference_with_token_fallback(
+ payments_json: serde_json::Value,
+ ) -> CustomResult<PaymentsMandateReference, ParsingError> {
+ match serde_json::from_value::<PaymentsMandateReference>(payments_json.clone()) {
+ Ok(mandate_reference) => Ok(mandate_reference),
+ Err(mandate_err) => {
+ router_env::logger::warn!(
+ "Failed to parse connector_mandate_details as PaymentsMandateReference: {}. Falling back to PaymentsTokenReference parser",
+ mandate_err
+ );
+
+ let token_reference =
+ serde_json::from_value::<PaymentsTokenReference>(payments_json)
+ .inspect_err(|token_err| {
+ router_env::logger::error!(
+ "Failed to parse connector_mandate_details as PaymentsTokenReference: {}",
+ token_err
+ );
+ })
+ .change_context(ParsingError::StructParseFailure(
+ "Failed to parse payments data",
+ ))?;
+
+ let mandate_reference = PaymentsMandateReference(
+ token_reference
+ .0
+ .into_iter()
+ .map(|(mca_id, token_record)| {
+ let connector_mandate_status = match token_record.connector_token_status
+ {
+ common_enums::ConnectorTokenStatus::Active => {
+ common_enums::ConnectorMandateStatus::Active
+ }
+ common_enums::ConnectorTokenStatus::Inactive => {
+ common_enums::ConnectorMandateStatus::Inactive
+ }
+ };
+
+ (
+ mca_id,
+ PaymentsMandateReferenceRecord {
+ connector_mandate_id: token_record.connector_token,
+ payment_method_type: token_record.payment_method_subtype,
+ original_payment_authorized_amount: token_record
+ .original_payment_authorized_amount
+ .map(|amount| amount.get_amount_as_i64()),
+ original_payment_authorized_currency: token_record
+ .original_payment_authorized_currency,
+ mandate_metadata: token_record.metadata,
+ connector_mandate_status: Some(connector_mandate_status),
+ connector_mandate_request_reference_id: token_record
+ .connector_token_request_reference_id,
+ connector_customer_id: token_record.connector_customer_id,
+ },
+ )
+ })
+ .collect(),
+ );
+
+ router_env::logger::info!(
+ "Parsed connector_mandate_details using token shape fallback"
+ );
+
+ Ok(mandate_reference)
+ }
+ }
+ }
+
#[cfg(feature = "v2")]
fn parse_payments_reference_with_legacy_fallback(
payments_json: serde_json::Value,
@@ -1495,15 +1564,9 @@ where
.map(|obj| {
obj.remove("payouts");
- serde_json::from_value::<PaymentsMandateReference>(serde_json::Value::Object(
+ Self::parse_payments_reference_with_token_fallback(serde_json::Value::Object(
obj.clone(),
))
- .inspect_err(|err| {
- router_env::logger::error!("Failed to parse payments data: {}", err);
- })
- .change_context(ParsingError::StructParseFailure(
- "Failed to parse payments data",
- ))
})
.transpose()?;
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index fa0c99bde8..0d3b7f9e23 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -1295,6 +1295,8 @@ diesel::table! {
customer_id -> Nullable<Varchar>,
#[max_length = 64]
merchant_id -> Varchar,
+ #[max_length = 64]
+ payment_method_id -> Nullable<Varchar>,
created_at -> Timestamp,
last_modified -> Timestamp,
payment_method_data -> Nullable<Bytea>,
diff --git a/crates/hyperswitch_domain_models/src/mandates.rs b/crates/hyperswitch_domain_models/src/mandates.rs
index 53b2aa320e..ce9aec6eef 100644
--- a/crates/hyperswitch_domain_models/src/mandates.rs
+++ b/crates/hyperswitch_domain_models/src/mandates.rs
@@ -191,7 +191,6 @@ impl From<&PaymentsMandateReferenceRecord> for RecurringMandatePaymentData {
}
}
-#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ConnectorTokenReferenceRecord {
pub connector_token: String,
@@ -230,7 +229,6 @@ impl std::ops::DerefMut for PayoutsMandateReference {
}
}
-#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaymentsTokenReference(
pub HashMap<common_utils::id_type::MerchantConnectorAccountId, ConnectorTokenReferenceRecord>,
@@ -272,7 +270,6 @@ impl std::ops::DerefMut for PaymentsMandateReference {
}
}
-#[cfg(feature = "v2")]
impl std::ops::Deref for PaymentsTokenReference {
type Target =
HashMap<common_utils::id_type::MerchantConnectorAccountId, ConnectorTokenReferenceRecord>;
@@ -282,7 +279,6 @@ impl std::ops::Deref for PaymentsTokenReference {
}
}
-#[cfg(feature = "v2")]
impl std::ops::DerefMut for PaymentsTokenReference {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs
index 39eea8efae..2571cf3088 100644
--- a/crates/hyperswitch_domain_models/src/payment_methods.rs
+++ b/crates/hyperswitch_domain_models/src/payment_methods.rs
@@ -725,10 +725,12 @@ impl super::behaviour::Conversion for PaymentMethod {
type DstType = diesel_models::payment_method::PaymentMethod;
type NewDstType = diesel_models::payment_method::PaymentMethodNew;
async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
+ let payment_method_id = self.id.get_string_repr().to_owned();
Ok(Self::DstType {
customer_id: self.customer_id,
merchant_id: self.merchant_id,
id: self.id,
+ payment_method_id: Some(payment_method_id),
created_at: self.created_at,
last_modified: self.last_modified,
payment_method_type_v2: self.payment_method_type,
@@ -910,10 +912,12 @@ impl super::behaviour::Conversion for PaymentMethod {
}
async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
+ let payment_method_id = self.id.get_string_repr().to_owned();
Ok(Self::NewDstType {
customer_id: self.customer_id,
merchant_id: self.merchant_id,
id: self.id,
+ payment_method_id: Some(payment_method_id),
created_at: self.created_at,
last_modified: self.last_modified,
payment_method_type_v2: self.payment_method_type,
@@ -1071,6 +1075,13 @@ impl super::behaviour::Conversion for PaymentMethodSession {
}
}
+#[cfg(feature = "v1")]
+#[derive(Clone, Debug)]
+pub struct PaymentMethodWithRawData {
+ pub payment_method: PaymentMethod,
+ pub raw_payment_method_data: Option<domain_payment_method_data::PaymentMethodData>,
+}
+
#[async_trait::async_trait]
pub trait PaymentMethodInterface {
type Error;
diff --git a/crates/router/src/core/mandate/helpers.rs b/crates/router/src/core/mandate/helpers.rs
index 2146b05cee..0658aa1c0d 100644
--- a/crates/router/src/core/mandate/helpers.rs
+++ b/crates/router/src/core/mandate/helpers.rs
@@ -6,11 +6,9 @@ use diesel_models::Mandate;
use error_stack::ResultExt;
use hyperswitch_domain_models::mandates::MandateData;
-use crate::{
- core::{errors, payments},
- routes::SessionState,
- types::{api, domain},
-};
+use crate::{core::errors, types::api};
+#[cfg(feature = "v1")]
+use crate::{core::payments, routes::SessionState, types::domain};
#[cfg(feature = "v1")]
pub async fn get_profile_id_for_mandate(
@@ -85,6 +83,7 @@ pub fn get_mandate_type(
_ => Ok(None),
}
}
+#[cfg(feature = "v1")]
#[derive(Clone)]
pub struct MandateGenericData {
pub token: Option<String>,
diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rs
index 08270f6877..3903376111 100644
--- a/crates/router/src/core/payment_methods/transformers.rs
+++ b/crates/router/src/core/payment_methods/transformers.rs
@@ -15,6 +15,8 @@ use common_utils::{
request::RequestContent,
};
use error_stack::ResultExt;
+#[cfg(feature = "v1")]
+use hyperswitch_domain_models::payment_methods::PaymentMethodWithRawData;
#[cfg(feature = "v2")]
use hyperswitch_domain_models::{payment_method_data, sdk_auth::SdkAuthorization};
#[cfg(feature = "v1")]
@@ -44,14 +46,41 @@ use crate::{
pii::Secret,
routes,
services::{api as services, encryption, EncryptionAlgorithm},
- types::{api, domain},
+ types::{api, domain, storage, transformers},
utils::OptionExt,
};
#[cfg(feature = "v2")]
-use crate::{
- consts,
- types::{payment_methods as pm_types, transformers},
-};
+use crate::{consts, types::payment_methods as pm_types};
+
+#[cfg(feature = "v1")]
+#[derive(Default)]
+pub struct PaymentMethodFetchData {
+ pub payment_method_info: Option<domain::PaymentMethod>,
+ pub payment_method_with_raw_data: Option<PaymentMethodWithRawData>,
+ pub token_data: Option<storage::PaymentTokenData>,
+}
+
+#[cfg(feature = "v1")]
+impl PaymentMethodFetchData {
+ pub fn from_modular(payment_method_with_raw_data: PaymentMethodWithRawData) -> Self {
+ Self {
+ payment_method_info: Some(payment_method_with_raw_data.payment_method.clone()),
+ payment_method_with_raw_data: Some(payment_method_with_raw_data),
+ token_data: None,
+ }
+ }
+
+ pub fn from_legacy(
+ payment_method_info: domain::PaymentMethod,
+ token_data: Option<storage::PaymentTokenData>,
+ ) -> Self {
+ Self {
+ payment_method_info: Some(payment_method_info),
+ payment_method_with_raw_data: None,
+ token_data,
+ }
+ }
+}
#[derive(Debug, Serialize)]
#[serde(untagged)]
@@ -1317,13 +1346,6 @@ pub struct DomainPaymentMethodWrapper(pub domain::PaymentMethod);
#[cfg(feature = "v1")]
pub struct DomainPaymentMethodDataWrapper(pub domain::PaymentMethodData);
-#[derive(Clone, Debug)]
-#[cfg(feature = "v1")]
-pub struct PaymentMethodWithRawData {
- pub payment_method: DomainPaymentMethodWrapper,
- pub raw_payment_method_data: Option<domain::PaymentMethodData>,
-}
-
#[cfg(feature = "v1")]
impl DomainPaymentMethodWrapper {
pub async fn transform_pm_mod_retrieve_response(
@@ -1754,7 +1776,7 @@ impl TryFrom<CreatePaymentMethodResponse> for DomainPaymentMethodWrapper {
#[cfg(feature = "v1")]
impl<'a>
- crate::types::transformers::ForeignTryFrom<
+ transformers::ForeignTryFrom<
&'a hyperswitch_domain_models::payment_method_data::CardWithOptionalCVC,
> for domain::CardDetailsForNetworkTransactionId
{
@@ -1781,7 +1803,7 @@ impl<'a>
#[cfg(feature = "v1")]
impl<'a>
- crate::types::transformers::ForeignTryFrom<
+ transformers::ForeignTryFrom<
&'a hyperswitch_domain_models::payment_method_data::CardWithOptionalCVC,
> for domain::PaymentMethodData
{
@@ -1858,7 +1880,7 @@ pub async fn fetch_payment_method_from_modular_service(
.attach_printable("Failed to convert raw payment method data")?;
let pm_wrapper = PaymentMethodWithRawData {
- payment_method,
+ payment_method: payment_method.0,
raw_payment_method_data: raw_payment_method_data.map(|wrapper| wrapper.0),
};
Ok(pm_wrapper)
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 8a5318c5b8..4ee988c433 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -673,12 +673,10 @@ where
.validate_request(&req, platform.get_processor())?;
let feature_config = core_utils::get_feature_config(state, platform, dimensions).await;
-
- let payment_method_info = operation
+ let payment_method_fetch_data = operation
.to_domain()?
.fetch_payment_method(state, &req, platform, &feature_config)
.await?;
-
tracing::Span::current().record("payment_id", format!("{}", validate_result.payment_id));
// get profile from headers
@@ -697,7 +695,7 @@ where
platform,
auth_flow,
&header_payload,
- payment_method_info,
+ payment_method_fetch_data,
dimensions,
)
.await?;
@@ -1547,7 +1545,7 @@ where
&platform,
auth_flow,
&header_payload,
- None,
+ operations::PaymentMethodFetchData::default(),
dimensions,
)
.await?;
@@ -2489,7 +2487,11 @@ where
D: OperationSessionGetters<F> + Send + Sync,
Op: Operation<F, R, Data = D> + Send + Sync,
{
- if feature_config.is_payment_method_modular_allowed {
+ if feature_config.is_modular_with_pm_version(
+ payment_data
+ .get_payment_method_info()
+ .map(|payment_method| payment_method.version),
+ ) {
logger::debug!(
payment_id = ?payment_data.get_payment_attempt().payment_id,
"Modular merchant detected; calling update_modular_pm_and_mandate"
@@ -8302,6 +8304,11 @@ where
D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send + Sync + Clone,
{
let connector = payment_data.get_payment_attempt().connector.to_owned();
+ let should_use_modular_pm_path = feature_config.is_modular_with_pm_version(
+ payment_data
+ .get_payment_method_info()
+ .map(|payment_method| payment_method.version),
+ );
let is_mandate = payment_data
.get_mandate_id()
@@ -8317,7 +8324,7 @@ where
let payment_data_and_tokenization_action = match connector {
Some(_) if is_mandate => {
- if feature_config.is_payment_method_modular_allowed {
+ if should_use_modular_pm_path {
payment_data.set_payment_method_data(None);
}
(
@@ -8359,7 +8366,7 @@ where
let connector_tokenization_action = match payment_method_action {
TokenizationAction::TokenizeInRouter => {
- if !feature_config.is_payment_method_modular_allowed {
+ if !should_use_modular_pm_path {
let (_operation, payment_method_data, pm_id) = operation
.to_domain()?
.make_pm_data(
@@ -8407,7 +8414,7 @@ where
}
TokenizationAction::TokenizeInConnector => TokenizationAction::TokenizeInConnector,
TokenizationAction::TokenizeInConnectorAndRouter => {
- if !feature_config.is_payment_method_modular_allowed {
+ if !should_use_modular_pm_path {
let (_operation, payment_method_data, pm_id) = operation
.to_domain()?
.make_pm_data(
@@ -8507,9 +8514,14 @@ where
let is_external_authentication_requested = payment_data
.get_payment_intent()
.request_external_three_ds_authentication;
+ let should_use_modular_pm_path = feature_config.is_modular_with_pm_version(
+ payment_data
+ .get_payment_method_info()
+ .map(|payment_method| payment_method.version),
+ );
let payment_data =
if !is_operation_confirm(operation) || is_external_authentication_requested == Some(true) {
- if !feature_config.is_payment_method_modular_allowed {
+ if !should_use_modular_pm_path {
let (_operation, payment_method_data, pm_id) = operation
.to_domain()?
.make_pm_data(
@@ -8828,7 +8840,7 @@ impl PaymentEligibilityData {
locker_id,
None, // no CardToken CVC for eligibility
None, // no co-badged data needed
- pm_record,
+ pm_record.clone(),
))
.await
.change_context(errors::ApiErrorResponse::PaymentMethodNotFound)
@@ -10073,6 +10085,12 @@ where
}),
};
+ let should_use_modular_pm_path = feature_config.is_modular_with_pm_version(
+ payment_data
+ .get_payment_method_info()
+ .map(|payment_method| payment_method.version),
+ );
+
let decided_connector = decide_connector(
state.clone(),
processor,
@@ -10085,7 +10103,7 @@ where
dimensions,
fallback_config,
backend_input,
- feature_config.is_payment_method_modular_allowed,
+ should_use_modular_pm_path,
)
.await?;
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 4d1ce965fc..ff5b475657 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -77,6 +77,8 @@ use super::{
CustomerDetails, PaymentData,
};
#[cfg(feature = "v1")]
+use crate::core::mandate::helpers::MandateGenericData;
+#[cfg(feature = "v1")]
use crate::core::{
payments::{OperationSessionGetters, OperationSessionSetters},
utils as core_utils,
@@ -92,7 +94,6 @@ use crate::{
authentication,
configs::dimension_state,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
- mandate::helpers::MandateGenericData,
payment_methods::{
self,
cards::{self},
@@ -466,13 +467,8 @@ pub async fn get_token_pm_type_mandate_details(
payment_method_id: Option<String>,
payment_intent_customer_id: Option<&id_type::CustomerId>,
pm_info: Option<domain::PaymentMethod>,
- dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<MandateGenericData> {
let mandate_data = request.mandate_data.clone().map(MandateData::foreign_from);
- let is_payment_method_modular_allowed =
- core_utils::get_feature_config(state, platform, dimensions)
- .await
- .is_payment_method_modular_allowed;
let (
payment_token,
payment_method,
@@ -755,10 +751,9 @@ pub async fn get_token_pm_type_mandate_details(
}
}
None => {
- let payment_method_info = if is_payment_method_modular_allowed {
- pm_info
- } else {
- payment_method_id
+ let payment_method_info = match pm_info {
+ Some(pm_info) => Some(pm_info),
+ None => payment_method_id
.async_map(|payment_method_id| async move {
state
.store
@@ -771,7 +766,7 @@ pub async fn get_token_pm_type_mandate_details(
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)
})
.await
- .transpose()?
+ .transpose()?,
};
let resolved_payment_method = request.payment_method.or_else(|| {
payment_method_info
@@ -3112,10 +3107,10 @@ pub async fn fetch_card_details_for_network_transaction_flow_from_locker(
#[cfg(feature = "v2")]
pub async fn retrieve_payment_method_from_db_with_token_data(
- state: &SessionState,
- merchant_key_store: &domain::MerchantKeyStore,
- token_data: &storage::PaymentTokenData,
- storage_scheme: storage::enums::MerchantStorageScheme,
+ _state: &SessionState,
+ _merchant_key_store: &domain::MerchantKeyStore,
+ _token_data: &storage::PaymentTokenData,
+ _storage_scheme: storage::enums::MerchantStorageScheme,
) -> RouterResult<Option<domain::PaymentMethod>> {
todo!()
}
diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs
index f5519bddd3..1fae8e2a2f 100644
--- a/crates/router/src/core/payments/operations.rs
+++ b/crates/router/src/core/payments/operations.rs
@@ -100,7 +100,7 @@ pub use self::{
};
use super::{helpers, CustomerDetails, OperationSessionGetters, OperationSessionSetters};
#[cfg(feature = "v1")]
-use crate::core::payment_methods::transformers::PaymentMethodWithRawData;
+pub use crate::core::payment_methods::transformers::PaymentMethodFetchData;
#[cfg(feature = "v2")]
use crate::core::payments;
use crate::{
@@ -221,7 +221,7 @@ 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>,
+ payment_method_fetch_data: PaymentMethodFetchData,
dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<GetTrackerResponse<'a, F, R, D>>;
@@ -334,8 +334,8 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {
_request: &R,
_platform: &domain::Platform,
_feature_config: &core_utils::FeatureConfig,
- ) -> RouterResult<Option<PaymentMethodWithRawData>> {
- Ok(None)
+ ) -> RouterResult<PaymentMethodFetchData> {
+ Ok(PaymentMethodFetchData::default())
}
#[allow(clippy::too_many_arguments)]
diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs
index 6f5078ff2c..85d838ed7a 100644
--- a/crates/router/src/core/payments/operations/payment_approve.rs
+++ b/crates/router/src/core/payments/operations/payment_approve.rs
@@ -43,7 +43,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> 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 879fabffa8..e6d8c7f327 100644
--- a/crates/router/src/core/payments/operations/payment_cancel.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel.rs
@@ -45,7 +45,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> 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 5a1cf67260..9dd9924634 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,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<
operations::GetTrackerResponse<
diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs
index d10a7ac7c4..aa6594eed9 100644
--- a/crates/router/src/core/payments/operations/payment_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_capture.rs
@@ -45,7 +45,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<
operations::GetTrackerResponse<
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 ded10d393d..4158d7d1f7 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -49,8 +49,8 @@ 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>,
- dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
+ _dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
let db = &*state.store;
@@ -124,7 +124,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.change_context(errors::ApiErrorResponse::MandateValidationFailed {
reason: "Expected one out of recurring_details and mandate_data but got both".into(),
})?;
-
let m_helpers::MandateGenericData {
token,
payment_method,
@@ -141,7 +140,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
payment_attempt.payment_method_id.clone(),
payment_intent.customer_id.as_ref(),
None,
- dimensions,
))
.await?;
let customer_acceptance: Option<CustomerAcceptance> =
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index eea3fab99c..fd649fb660 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -5,6 +5,7 @@ use api_models::payment_methods::PaymentMethodsData;
use api_models::{
admin::ExtendedCardInfoConfig,
enums::FrmSuggestion,
+ mandates::RecurringDetails,
payments::{
ConnectorMandateReferenceId, ExtendedCardInfo, GetAddressFromPaymentMethodData,
MandateTransactionType,
@@ -17,6 +18,7 @@ use error_stack::{report, ResultExt};
use futures::FutureExt;
use hyperswitch_domain_models::{
payment_method_data::RecurringDetails as domain_recurring_details,
+ payment_methods::PaymentMethodWithRawData,
payments::{self as domain_payments, payment_intent::PaymentIntentUpdateFields},
router_request_types::unified_authentication_service,
};
@@ -41,7 +43,7 @@ use crate::{
errors::{self, CustomResult, RouterResult, StorageErrorExt},
mandate::helpers as m_helpers,
metrics,
- payment_methods::{transformers as pm_transformers, utils as pm_utils},
+ payment_methods::transformers as pm_transformers,
payments::{
self, helpers, operations,
operations::payment_confirm::unified_authentication_service::ThreeDsMetaData,
@@ -86,10 +88,15 @@ 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>,
+ payment_method_fetch_data: operations::PaymentMethodFetchData,
dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
+ let operations::PaymentMethodFetchData {
+ payment_method_info: prefetched_payment_method_info,
+ payment_method_with_raw_data,
+ token_data: prefetched_token_data,
+ } = payment_method_fetch_data;
let processor_merchant_id = platform.get_processor().get_account().get_id();
let storage_scheme = platform.get_processor().get_account().storage_scheme;
let (currency, amount);
@@ -552,7 +559,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.and_then(|pmd| pmd.billing.clone())
.or(payment_method_with_raw_data.clone().and_then(|pm| {
pm.payment_method
- .0
.payment_method_billing_address
.clone()
.map(|decrypted_data| decrypted_data.into_inner().expose())
@@ -606,11 +612,8 @@ 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();
- let payment_method_info_from_modular = payment_method_with_raw_data
- .clone()
- .map(|pm| pm.payment_method.0);
+ let m_payment_method_info = prefetched_payment_method_info.clone();
- let m_pm_dimensions = dimensions.clone();
let mandate_details_fut = tokio::spawn(
async move {
Box::pin(helpers::get_token_pm_type_mandate_details(
@@ -620,8 +623,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
&m_platform,
None,
payment_intent_customer_id.as_ref(),
- payment_method_info_from_modular,
- &m_pm_dimensions,
+ m_payment_method_info,
))
.await
}
@@ -661,51 +663,25 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
&request.ctp_service_details,
)?;
- let pm_modular_dimensions = dimensions
- .with_organization_id(
- platform
- .get_processor()
- .get_account()
- .organization_id
- .clone(),
- )
- .without_provider_merchant_id()
- .without_processor_merchant_id();
-
//fetch for repeat cit using payment token
+ let payment_method_info = payment_method_info.or(prefetched_payment_method_info);
+ let feature_config = core_utils::get_feature_config(state, platform, dimensions).await;
+ let payment_method_version = payment_method_info.as_ref().map(|pm| pm.version);
let is_modular_payment_method_flow =
- pm_utils::get_organization_eligibility_config_for_pm_modular_service(
- state,
- &pm_modular_dimensions,
- )
- .await;
-
+ feature_config.is_modular_with_pm_version(payment_method_version);
let (token_data, payment_method_info) = if is_modular_payment_method_flow {
- (
- None,
- payment_method_with_raw_data
- .clone()
- .map(|pm| pm.payment_method.0),
- )
- } else if let Some(token) = token.clone() {
- let token_data = helpers::retrieve_payment_token_data(
+ (None, payment_method_info)
+ } else {
+ self.resolve_legacy_token_payment_method_context(
state,
- token,
+ platform,
+ prefetched_token_data,
+ payment_method_info,
+ token.clone(),
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)
+ .await?
};
let additional_pm_data_from_locker = if let Some(ref pm) = payment_method_info {
let card_detail_from_locker: Option<api::CardDetailFromLocker> = pm
@@ -815,10 +791,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
payment_method_data_billing.get_billing_address()
})
.map(From::from);
- let pm_pmd_billing = payment_method_with_raw_data.as_ref().and_then(|pm| {
- pm.payment_method
- .0
- .payment_method_billing_address
+ let pm_pmd_billing = payment_method_info.as_ref().and_then(|pm| {
+ pm.payment_method_billing_address
.clone()
.map(|decrypted_data| decrypted_data.into_inner().expose())
.and_then(|decrypted_value| {
@@ -840,7 +814,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.recurring_details
.as_ref()
.and_then(|recurring_details| match recurring_details {
- api_models::mandates::RecurringDetails::ProcessorPaymentToken(token) => {
+ RecurringDetails::ProcessorPaymentToken(token) => {
payment_intent.is_payment_processor_token_flow = Some(true);
Some(api_models::payments::MandateIds {
mandate_id: None,
@@ -858,16 +832,16 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
),
})
}
- api_models::mandates::RecurringDetails::CardWithLimitedData(_)
- | api_models::mandates::RecurringDetails::NetworkTransactionIdAndNetworkTokenDetails(_)
- | api_models::mandates::RecurringDetails::NetworkTransactionIdAndDecryptedWalletTokenDetails(_)
- | api_models::mandates::RecurringDetails::NetworkTransactionIdAndCardDetails(_) => {
+ RecurringDetails::CardWithLimitedData(_)
+ | RecurringDetails::NetworkTransactionIdAndNetworkTokenDetails(_)
+ | RecurringDetails::NetworkTransactionIdAndDecryptedWalletTokenDetails(_)
+ | RecurringDetails::NetworkTransactionIdAndCardDetails(_) => {
Some(api_models::payments::MandateIds {
mandate_id: None,
mandate_reference_id: mandate_reference_id_from_recurring_details,
})
}
- api_models::mandates::RecurringDetails::PaymentMethodId(_) | api_models::mandates::RecurringDetails::MandateId(_) => None,
+ RecurringDetails::PaymentMethodId(_) | RecurringDetails::MandateId(_) => None,
});
let pmt_order_tax_amount = payment_intent.tax_details.clone().and_then(|tax| {
@@ -1247,76 +1221,105 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
req: &api::PaymentsRequest,
platform: &domain::Platform,
feature_config: &core_utils::FeatureConfig,
- ) -> RouterResult<Option<operations::PaymentMethodWithRawData>> {
- match feature_config.is_payment_method_modular_allowed {
- true => {
- utils::when(
- req.off_session == Some(true) && req.recurring_details.is_none(),
- || {
- Err(error_stack::report!(
- errors::ApiErrorResponse::PreconditionFailed {
- message: "off_session requires recurring_details".into(),
- }
- ))
- },
- )?;
+ ) -> RouterResult<operations::PaymentMethodFetchData> {
+ let payment_method_fetch_data = if feature_config.is_payment_method_modular_allowed {
+ utils::when(
+ req.off_session == Some(true) && req.recurring_details.is_none(),
+ || {
+ Err(error_stack::report!(
+ errors::ApiErrorResponse::PreconditionFailed {
+ message: "off_session requires recurring_details".into(),
+ }
+ ))
+ },
+ )?;
- let profile_id = req
- .profile_id
- .clone()
- .or(platform
- .get_processor()
- .get_account()
- .get_default_profile()
- .clone())
- .get_required_value("profile_id")?;
-
- let pm_info = if let Some(payment_token) = &req.payment_token {
- logger::info!("Organization is eligible for PM Modular Service, proceeding to fetch payment method using PM Modular Service.");
- //fetch req/payment_method_data, if CardToken, then send it in fetch call else None
- let pmd = req
- .payment_method_data
- .clone()
- .and_then(|pmd| pmd.payment_method_data)
- .map(Into::into);
- let payment_method_data =
- if let Some(domain::PaymentMethodData::CardToken(ref token)) = pmd {
- Some(token.clone())
- } else {
- None
- };
- // Fetch payment method using PM Modular Service
- let pm_info = pm_transformers::fetch_payment_method_from_modular_service(
+ if let Some(payment_method_ref) = self.get_payment_method_reference(req) {
+ logger::debug!(
+ "Organization is enabled for modular service, fetching payment method from PM Modular Service"
+ );
+ let pm_info = self
+ .fetch_payment_method_from_modular_service(
state,
+ req,
platform,
- &profile_id,
- payment_token,
- payment_method_data,
+ payment_method_ref,
)
.await?;
- logger::info!("Payment method fetched from PM Modular Service.");
- utils::when(
- pm_info.payment_method.0.customer_id.as_ref() != req.get_customer_id(),
- || {
- logger::info!("Payment method id does not belong to the customer id provided in the request.");
- Err(errors::ApiErrorResponse::PaymentMethodNotFound)
- },
- )?;
+ operations::PaymentMethodFetchData::from_modular(pm_info)
+ } else {
+ operations::PaymentMethodFetchData::default()
+ }
+ } else {
+ let token_data = match (req.payment_token.clone(), req.payment_method) {
+ (Some(token), Some(payment_method)) => Some(
+ helpers::retrieve_payment_token_data(state, token, Some(payment_method))
+ .await?,
+ ),
+ _ => None,
+ };
- Some(pm_info)
- } else {
- None
- };
+ let payment_method_info = match token_data.as_ref() {
+ Some(token_data) => {
+ helpers::retrieve_payment_method_from_db_with_token_data(
+ state,
+ platform.get_provider().get_key_store(),
+ token_data,
+ platform.get_processor().get_account().storage_scheme,
+ )
+ .await?
+ }
+ None => match req.recurring_details.as_ref() {
+ Some(RecurringDetails::PaymentMethodId(payment_method_id)) => Some(
+ state
+ .store
+ .find_payment_method(
+ platform.get_provider().get_key_store(),
+ payment_method_id,
+ platform.get_processor().get_account().storage_scheme,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::PaymentMethodNotFound,
+ )?,
+ ),
+ _ => None,
+ },
+ };
- //the pm_info will be set in payment_data in get trackers
- Ok(pm_info)
- }
- false => {
- logger::info!("Organization is not eligible for PM Modular Service, skipping fetch payment method.");
- Ok(None)
+ match payment_method_info {
+ Some(payment_method)
+ if feature_config.is_modular_with_pm_version(Some(payment_method.version)) =>
+ {
+ logger::debug!(
+ "Payment method version is V2, fetching payment method from PM Modular Service"
+ );
+ let payment_method_id = payment_method.get_id().to_owned();
+ let pm_info = self
+ .fetch_payment_method_from_modular_service(
+ state,
+ req,
+ platform,
+ &payment_method_id,
+ )
+ .await?;
+
+ operations::PaymentMethodFetchData::from_modular(pm_info)
+ }
+ Some(payment_method) => {
+ logger::info!("Organization is not eligible for PM Modular Service, skipping fetch payment method.");
+ operations::PaymentMethodFetchData::from_legacy(payment_method, token_data)
+ }
+ None => operations::PaymentMethodFetchData {
+ payment_method_info: None,
+ payment_method_with_raw_data: None,
+ token_data,
+ },
}
- }
+ };
+
+ Ok(payment_method_fetch_data)
}
#[instrument(skip_all)]
@@ -2264,6 +2267,107 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
}
}
+impl PaymentConfirm {
+ async fn resolve_legacy_token_payment_method_context(
+ self,
+ state: &SessionState,
+ platform: &domain::Platform,
+ prefetched_token_data: Option<storage::PaymentTokenData>,
+ payment_method_info: Option<domain::PaymentMethod>,
+ token: Option<String>,
+ payment_method: Option<common_enums::enums::PaymentMethod>,
+ ) -> RouterResult<(
+ Option<storage::PaymentTokenData>,
+ Option<domain::PaymentMethod>,
+ )> {
+ // Case - payment_token was sent in the request
+ // token_data was fetched from redis
+ // payment_method was fetched from DB
+ if prefetched_token_data.is_some() && payment_method_info.is_some() {
+ Ok((prefetched_token_data, payment_method_info))
+ // Case - payment_token was sent in the request but token_data or payment_method could not be fetched
+ } else if let Some(token) = token {
+ let token_data =
+ helpers::retrieve_payment_token_data(state, token, 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,
+ platform.get_processor().get_account().storage_scheme,
+ )
+ .await?
+ .or(payment_method_info);
+
+ Ok((Some(token_data), payment_method_info))
+ // Case - payment_token was not sent in the request
+ } else {
+ Ok((None, payment_method_info))
+ }
+ }
+
+ async fn fetch_payment_method_from_modular_service(
+ &self,
+ state: &SessionState,
+ req: &api::PaymentsRequest,
+ platform: &domain::Platform,
+ payment_method_ref: &str,
+ ) -> RouterResult<PaymentMethodWithRawData> {
+ let profile_id = req
+ .profile_id
+ .clone()
+ .or(platform
+ .get_processor()
+ .get_account()
+ .get_default_profile()
+ .clone())
+ .get_required_value("profile_id")?;
+
+ let pmd = req
+ .payment_method_data
+ .clone()
+ .and_then(|pmd| pmd.payment_method_data)
+ .map(Into::into);
+ let payment_method_data = match pmd {
+ Some(domain::PaymentMethodData::CardToken(token)) => Some(token),
+ _ => None,
+ };
+
+ let pm_info = pm_transformers::fetch_payment_method_from_modular_service(
+ state,
+ platform,
+ &profile_id,
+ payment_method_ref,
+ payment_method_data,
+ )
+ .await?;
+ logger::info!("Payment method fetched from PM Modular Service.");
+
+ utils::when(
+ pm_info.payment_method.customer_id.as_ref() != req.get_customer_id(),
+ || {
+ logger::info!(
+ "Payment method id does not belong to the customer id provided in the request."
+ );
+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)
+ },
+ )?;
+
+ Ok(pm_info)
+ }
+
+ fn get_payment_method_reference(self, req: &api::PaymentsRequest) -> Option<&str> {
+ req.payment_token
+ .as_deref()
+ .or(match req.recurring_details.as_ref() {
+ Some(RecurringDetails::PaymentMethodId(payment_method_id)) => {
+ Some(payment_method_id.as_str())
+ }
+ _ => None,
+ })
+ }
+}
+
#[cfg(feature = "v2")]
#[async_trait]
impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for PaymentConfirm {
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 6bffc61c2e..e0ff37aae3 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -21,6 +21,7 @@ use error_stack::{self, ResultExt};
use hyperswitch_domain_models::{
mandates::MandateDetails,
payment_method_data::RecurringDetails as domain_recurring_details,
+ payment_methods::PaymentMethodWithRawData,
payments::{payment_attempt::PaymentAttempt, FromRequestEncryptablePaymentIntent},
};
use hyperswitch_masking::{ExposeInterface, PeekInterface, Secret};
@@ -80,10 +81,15 @@ 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>,
+ payment_method_fetch_data: operations::PaymentMethodFetchData,
dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
+ let operations::PaymentMethodFetchData {
+ payment_method_info: prefetched_payment_method_info,
+ payment_method_with_raw_data,
+ ..
+ } = payment_method_fetch_data;
let db = &*state.store;
let money @ (amount, currency) = payments_create_request_validation(request)?;
@@ -156,10 +162,6 @@ 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 payment_method_info_from_modular = payment_method_with_raw_data
- .clone()
- .map(|pm| pm.payment_method.0);
-
let m_helpers::MandateGenericData {
token,
payment_method,
@@ -175,8 +177,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
platform,
None,
None,
- payment_method_info_from_modular,
- dimensions,
+ prefetched_payment_method_info,
)
.await?;
@@ -224,7 +225,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.and_then(|pmd| pmd.billing.clone())
.or(payment_method_with_raw_data.as_ref().and_then(|pm| {
pm.payment_method
- .0
.payment_method_billing_address
.clone()
.map(|decrypted_data| decrypted_data.into_inner().expose())
@@ -625,7 +625,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.map(From::from);
let pm_pmd_billing = payment_method_with_raw_data.as_ref().and_then(|pm| {
pm.payment_method
- .0
.payment_method_billing_address
.clone()
.map(|decrypted_data| decrypted_data.into_inner().expose())
@@ -910,65 +909,84 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
req: &api::PaymentsRequest,
platform: &domain::Platform,
feature_config: &core_utils::FeatureConfig,
- ) -> RouterResult<Option<pm_transformers::PaymentMethodWithRawData>> {
- match feature_config.is_payment_method_modular_allowed {
- true => {
- logger::info!("Organization is eligible for PM Modular Service, fetching payment method if payment_token is provided.");
- utils::when(
- req.off_session == Some(true) && req.recurring_details.is_none(),
- || {
- Err(error_stack::report!(
- errors::ApiErrorResponse::PreconditionFailed {
- message: "off_session requires recurring_details".into(),
- }
- ))
- },
- )?;
+ ) -> RouterResult<operations::PaymentMethodFetchData> {
+ let payment_method_fetch_data = if feature_config.is_payment_method_modular_allowed {
+ logger::debug!("PM Modular Service branch selected for payment method fetch");
+ utils::when(
+ req.off_session == Some(true) && req.recurring_details.is_none(),
+ || {
+ Err(error_stack::report!(
+ errors::ApiErrorResponse::PreconditionFailed {
+ message: "off_session requires recurring_details".into(),
+ }
+ ))
+ },
+ )?;
- let profile_id = req
- .profile_id
- .clone()
- .or(platform
- .get_processor()
- .get_account()
- .get_default_profile()
- .clone())
- .get_required_value("profile_id")?;
-
- let payment_method_reference = self.get_payment_method_reference(req);
-
- let pm_info = if let Some(payment_method_ref) = payment_method_reference {
- // Fetch payment method using PM Modular Service
- let pm_info = pm_transformers::fetch_payment_method_from_modular_service(
+ if let Some(payment_method_ref) = self.get_payment_method_reference(req) {
+ let pm_info = self
+ .fetch_payment_method_from_modular_service(
state,
+ req,
platform,
- &profile_id,
payment_method_ref,
- None, // CVC token data is not passed in create api
)
.await?;
- logger::info!("Payment method fetched from PM Modular Service.");
- utils::when(
- pm_info.payment_method.0.customer_id.as_ref() != req.get_customer_id(),
- || {
- logger::info!("Payment method id does not belong to the customer id provided in the request.");
- Err(errors::ApiErrorResponse::PaymentMethodNotFound)
- },
- )?;
+ operations::PaymentMethodFetchData::from_modular(pm_info)
+ } else {
+ logger::debug!("No payment method reference found, skipping payment method fetch");
+ operations::PaymentMethodFetchData::default()
+ }
+ } else {
+ let payment_method_info = if let Some(payment_method_id) =
+ self.get_recurring_payment_method_id(req)
+ {
+ logger::debug!("Non-modular payment method DB lookup branch selected");
+ Some(
+ 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)?,
+ )
+ } else {
+ logger::debug!(
+ "No recurring payment method id found, skipping payment method DB lookup"
+ );
+ None
+ };
- Some(pm_info)
- } else {
- None
- };
+ if let Some(payment_method) = payment_method_info {
+ if feature_config.is_modular_with_pm_version(Some(payment_method.version)) {
+ logger::debug!(
+ "Payment method version is V2, fetching payment method from PM Modular Service"
+ );
+ let payment_method_id = payment_method.get_id().to_owned();
+ let pm_info = self
+ .fetch_payment_method_from_modular_service(
+ state,
+ req,
+ platform,
+ &payment_method_id,
+ )
+ .await?;
- Ok(pm_info)
- }
- false => {
- logger::info!("Organization is not eligible for PM Modular Service, skipping fetch payment method.");
- Ok(None)
+ operations::PaymentMethodFetchData::from_modular(pm_info)
+ } else {
+ logger::debug!("Using legacy DB payment method branch");
+ operations::PaymentMethodFetchData::from_legacy(payment_method, None)
+ }
+ } else {
+ operations::PaymentMethodFetchData::default()
}
- }
+ };
+
+ Ok(payment_method_fetch_data)
}
#[instrument(skip_all)]
@@ -1292,15 +1310,59 @@ impl<F: Send + Clone + Sync> ValidateRequest<F, api::PaymentsRequest, PaymentDat
}
impl PaymentCreate {
+ async fn fetch_payment_method_from_modular_service(
+ &self,
+ state: &SessionState,
+ req: &api::PaymentsRequest,
+ platform: &domain::Platform,
+ payment_method_ref: &str,
+ ) -> RouterResult<PaymentMethodWithRawData> {
+ let profile_id = req
+ .profile_id
+ .clone()
+ .or(platform
+ .get_processor()
+ .get_account()
+ .get_default_profile()
+ .clone())
+ .get_required_value("profile_id")?;
+
+ let pm_info = pm_transformers::fetch_payment_method_from_modular_service(
+ state,
+ platform,
+ &profile_id,
+ payment_method_ref,
+ None, // CVC token data is not passed in create api
+ )
+ .await?;
+ logger::info!("Payment method fetched from PM Modular Service.");
+
+ utils::when(
+ pm_info.payment_method.customer_id.as_ref() != req.get_customer_id(),
+ || {
+ logger::info!(
+ "Payment method id does not belong to the customer id provided in the request."
+ );
+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)
+ },
+ )?;
+
+ Ok(pm_info)
+ }
+
/// Determines the payment method reference for modular payment flows.
- 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
- (Some(true), Some(RecurringDetails::PaymentMethodId(payment_method_id))) => {
- Some(payment_method_id)
- }
- // All other cases
- _ => req.payment_token.as_ref(),
+ fn get_payment_method_reference(self, req: &api::PaymentsRequest) -> Option<&str> {
+ self.get_recurring_payment_method_id(req)
+ .or(req.payment_token.as_deref())
+ }
+
+ fn get_recurring_payment_method_id(self, req: &api::PaymentsRequest) -> Option<&str> {
+ if let Some(RecurringDetails::PaymentMethodId(payment_method_id)) =
+ req.recurring_details.as_ref()
+ {
+ Some(payment_method_id.as_str())
+ } else {
+ None
}
}
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 a985f707e2..4d8b7a07b3 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,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<
operations::GetTrackerResponse<
diff --git a/crates/router/src/core/payments/operations/payment_recurrence.rs b/crates/router/src/core/payments/operations/payment_recurrence.rs
index 255d9eb4df..6dea53615b 100644
--- a/crates/router/src/core/payments/operations/payment_recurrence.rs
+++ b/crates/router/src/core/payments/operations/payment_recurrence.rs
@@ -18,7 +18,6 @@ use crate::{
configs::dimension_state,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
mandate::helpers as m_helpers,
- payment_methods::transformers as pm_transformers,
payments::{helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
},
routes::{app::ReqState, SessionState},
@@ -51,10 +50,15 @@ 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>,
+ payment_method_fetch_data: operations::PaymentMethodFetchData,
dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
+ let operations::PaymentMethodFetchData {
+ payment_method_info: prefetched_payment_method_info,
+ payment_method_with_raw_data,
+ ..
+ } = payment_method_fetch_data;
let processor_merchant_id = platform.get_processor().get_account().get_id();
let storage_scheme = platform.get_processor().get_account().storage_scheme;
let (currency, amount);
@@ -216,8 +220,11 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
let payment_intent_customer_id = payment_intent.customer_id.clone();
- let m_pm_wrapper = payment_method_with_raw_data.clone();
- let mandate_dimensions = dimensions.clone();
+ let m_payment_method_info = prefetched_payment_method_info.or_else(|| {
+ payment_method_with_raw_data
+ .as_ref()
+ .map(|payment_method_wrapper| payment_method_wrapper.payment_method.clone())
+ });
let mandate_details_fut = tokio::spawn(
async move {
Box::pin(helpers::get_token_pm_type_mandate_details(
@@ -227,8 +234,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),
- &mandate_dimensions,
+ m_payment_method_info,
))
.await
}
@@ -309,7 +315,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.map(From::from);
let pm_pmd_billing = payment_method_with_raw_data.as_ref().and_then(|pm| {
pm.payment_method
- .0
.payment_method_billing_address
.clone()
.and_then(|decrypted_data| {
diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs
index d359b2fad8..84c825a2ff 100644
--- a/crates/router/src/core/payments/operations/payment_reject.rs
+++ b/crates/router/src/core/payments/operations/payment_reject.rs
@@ -42,7 +42,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<operations::GetTrackerResponse<'a, F, PaymentsCancelRequest, PaymentData<F>>>
{
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 5ed525aa44..e37eb116f6 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -747,7 +747,11 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
where
F: 'b + Clone + Send + Sync,
{
- if !feature_config.is_payment_method_modular_allowed {
+ if !feature_config.is_modular_with_pm_version(
+ payment_data
+ .get_payment_method_info()
+ .map(|payment_method| payment_method.version),
+ ) {
let _ = update_pm_connector_mandate_details(
state,
provider,
@@ -1047,7 +1051,11 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for
where
F: 'b + Clone + Send + Sync,
{
- if !feature_config.is_payment_method_modular_allowed {
+ if !feature_config.is_modular_with_pm_version(
+ payment_data
+ .get_payment_method_info()
+ .map(|payment_method| payment_method.version),
+ ) {
let _ = update_pm_connector_mandate_details(
state,
provider,
@@ -1795,7 +1803,11 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
where
F: 'b + Clone + Send + Sync,
{
- if !feature_config.is_payment_method_modular_allowed {
+ if !feature_config.is_modular_with_pm_version(
+ payment_data
+ .get_payment_method_info()
+ .map(|payment_method| payment_method.version),
+ ) {
let _ = update_pm_connector_mandate_details(
state,
provider,
@@ -1930,7 +1942,11 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
where
F: 'b + Clone + Send + Sync,
{
- if !feature_config.is_payment_method_modular_allowed {
+ if !feature_config.is_modular_with_pm_version(
+ payment_data
+ .get_payment_method_info()
+ .map(|payment_method| payment_method.version),
+ ) {
let _ = update_pm_connector_mandate_details(
state,
provider,
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index d184c78133..86380e2fdf 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -46,7 +46,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> 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 3cc426633a..d234e35e20 100644
--- a/crates/router/src/core/payments/operations/payment_start.rs
+++ b/crates/router/src/core/payments/operations/payment_start.rs
@@ -44,7 +44,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<
operations::GetTrackerResponse<'a, F, api::PaymentsStartRequest, PaymentData<F>>,
@@ -131,13 +131,12 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsStartReq
// 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 = {
- let is_payment_method_modular_allowed =
- utils::get_feature_config(state, platform, dimensions)
- .await
- .is_payment_method_modular_allowed;
+ let feature_config = utils::get_feature_config(state, platform, dimensions).await;
+ let should_use_modular_payment_method_flow =
+ feature_config.is_modular_with_pm_version(None);
match (
payment_attempt.payment_token.clone(),
- is_payment_method_modular_allowed,
+ should_use_modular_payment_method_flow,
) {
(Some(token), false) => Some(
helpers::retrieve_payment_token_data(
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index c76fa78d04..3b7972d18f 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -12,12 +12,10 @@ use crate::{
core::{
configs::dimension_state,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
- payment_methods::transformers as pm_transformers,
payments::{
helpers, operations, types as payment_types, CustomerDetails, PaymentAddress,
PaymentData,
},
- utils as core_utils,
},
events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
@@ -233,7 +231,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<
operations::GetTrackerResponse<'a, F, api::PaymentsRetrieveRequest, PaymentData<F>>,
@@ -284,10 +282,6 @@ async fn get_tracker_for_sync<
{
let (payment_intent, mut payment_attempt, currency, amount);
- let dimensions = dimension_state::Dimensions::new()
- .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
- .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id());
-
(payment_intent, payment_attempt) = get_payment_intent_payment_attempt(
state,
payment_id,
@@ -438,36 +432,20 @@ async fn get_tracker_for_sync<
let profile_id = payment_intent
.profile_id
- .as_ref()
+ .clone()
.get_required_value("profile_id")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("'profile_id' not set in payment intent")?;
let business_profile = db
- .find_business_profile_by_profile_id(platform.get_processor().get_key_store(), profile_id)
+ .find_business_profile_by_profile_id(platform.get_processor().get_key_store(), &profile_id)
.await
.to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {
id: profile_id.get_string_repr().to_owned(),
})?;
- let payment_method_info = if let Some(ref payment_method_id) =
- payment_attempt.payment_method_id.clone()
- {
- if core_utils::get_feature_config(state, platform, &dimensions)
- .await
- .is_payment_method_modular_allowed
- {
- let pm_info = pm_transformers::fetch_payment_method_from_modular_service(
- state,
- platform,
- profile_id,
- payment_method_id,
- None,
- )
- .await
- .attach_printable("Failed to fetch payment method from modular service in sync flow")?;
- Some(pm_info.payment_method.0)
- } else {
+ let payment_method_info =
+ if let Some(ref payment_method_id) = payment_attempt.payment_method_id.clone() {
match db
.find_payment_method(
platform.get_provider().get_key_store(),
@@ -476,7 +454,7 @@ async fn get_tracker_for_sync<
)
.await
{
- Ok(payment_method) => Some(payment_method),
+ Ok(payment_method_info) => Some(payment_method_info),
Err(error) => {
if error.current_context().is_db_not_found() {
logger::info!("Payment Method not found in db {:?}", error);
@@ -488,10 +466,9 @@ async fn get_tracker_for_sync<
}
}
}
- }
- } else {
- None
- };
+ } else {
+ None
+ };
let merchant_id = payment_intent.merchant_id.clone();
let key_manager_state = &(state).into();
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index a430f91c55..0e3cc3e752 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -60,8 +60,8 @@ 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>,
- dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
+ _dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
let (mut payment_intent, mut payment_attempt, currency): (_, _, storage_enums::Currency);
@@ -141,7 +141,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
let customer_acceptance = request.customer_acceptance.clone();
let recurring_details = request.recurring_details.clone();
-
let mandate_type = m_helpers::get_mandate_type(
request.mandate_data.clone(),
request.off_session,
@@ -170,7 +169,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
None,
payment_intent.customer_id.as_ref(),
None,
- dimensions,
))
.await?;
helpers::validate_amount_to_capture_and_capture_method(Some(&payment_attempt), request)?;
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 3c054bc5de..94a7bfd8ba 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,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> 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 8f56450c3b..a4ec168777 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,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<
operations::GetTrackerResponse<
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 816103e78f..c5bdeb6ac8 100644
--- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
@@ -51,7 +51,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<
operations::GetTrackerResponse<
diff --git a/crates/router/src/core/payments/operations/tax_calculation.rs b/crates/router/src/core/payments/operations/tax_calculation.rs
index 52fb351a1a..e37f815563 100644
--- a/crates/router/src/core/payments/operations/tax_calculation.rs
+++ b/crates/router/src/core/payments/operations/tax_calculation.rs
@@ -49,7 +49,7 @@ 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>,
+ _payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<
operations::GetTrackerResponse<
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 13bbc79a8d..5a75deec68 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -73,6 +73,16 @@ pub struct FeatureConfig {
pub is_payment_method_modular_allowed: bool,
}
+impl FeatureConfig {
+ pub fn is_modular_with_pm_version(
+ &self,
+ payment_method_version: Option<common_enums::ApiVersion>,
+ ) -> bool {
+ self.is_payment_method_modular_allowed
+ || payment_method_version == Some(common_enums::ApiVersion::V2)
+ }
+}
+
pub async fn get_feature_config(
state: &SessionState,
platform: &domain::Platform,
diff --git a/v2_migrations/2025-01-13-081847_drop_v1_columns/down.sql b/v2_migrations/2025-01-13-081847_drop_v1_columns/down.sql
index f28582f186..9fe4f9a149 100644
--- a/v2_migrations/2025-01-13-081847_drop_v1_columns/down.sql
+++ b/v2_migrations/2025-01-13-081847_drop_v1_columns/down.sql
@@ -110,7 +110,6 @@ CREATE TYPE "PaymentMethodIssuerCode" AS ENUM (
);
ALTER TABLE payment_methods
- ADD COLUMN IF NOT EXISTS payment_method_id VARCHAR(64),
ADD COLUMN IF NOT EXISTS accepted_currency "Currency" [ ],
ADD COLUMN IF NOT EXISTS scheme VARCHAR(32),
ADD COLUMN IF NOT EXISTS token VARCHAR(128),
diff --git a/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql b/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql
index 95348656f9..b73e98b1fc 100644
--- a/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql
+++ b/v2_migrations/2025-01-13-081847_drop_v1_columns/up.sql
@@ -98,7 +98,6 @@ ALTER TABLE payment_attempt DROP COLUMN attempt_id,
ALTER TABLE payment_methods
- DROP COLUMN IF EXISTS payment_method_id,
DROP COLUMN IF EXISTS accepted_currency,
DROP COLUMN IF EXISTS scheme,
DROP COLUMN IF EXISTS token,