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): add 3ds complete authorize support for modular payment method flow (#11354)

Shankar Singh C4a13dc64df61
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 5bbd7b5382..5ebc2d695a 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -115,8 +115,6 @@ use crate::core::debit_routing;
#[cfg(feature = "frm")]
use crate::core::fraud_check as frm_core;
#[cfg(feature = "v2")]
-use crate::core::payment_methods::vault;
-#[cfg(feature = "v2")]
use crate::core::revenue_recovery::get_workflow_entries;
#[cfg(feature = "v2")]
use crate::core::revenue_recovery::map_to_recovery_payment_item;
@@ -136,7 +134,7 @@ use crate::{
consts,
core::{
errors::{self, CustomResult, RouterResponse, RouterResult},
- payment_methods::{cards, network_tokenization, transformers as pm_transformers},
+ payment_methods::{cards, network_tokenization, transformers as pm_transformers, vault},
payments::helpers::{
get_applepay_metadata, is_applepay_predecrypted_flow_supported,
is_googlepay_predecrypted_flow_supported,
@@ -789,6 +787,7 @@ where
&validate_result,
platform,
&business_profile,
+ &feature_config,
)
.await?;
@@ -7951,8 +7950,29 @@ where
payment_data.set_payment_method_data(payment_method_data);
payment_data.set_payment_method_id_in_attempt(pm_id);
} else {
- logger::debug!("Organization is eligible for PM Modular service, skipping make_pm_data call since raw payment method data fetch is done");
//Merchant enabled for PM Modular service
+ logger::debug!("Organization is eligible for PM Modular service, skipping make_pm_data call since raw payment method data fetch is done");
+ let payment_token = payment_data
+ .get_payment_method_data()
+ .async_map(|payment_method_data| async {
+ helpers::store_payment_method_data_in_vault(
+ state,
+ payment_data.get_payment_attempt(),
+ payment_data.get_payment_intent(),
+ enums::PaymentMethod::Card,
+ payment_method_data,
+ platform.get_provider().get_key_store(),
+ Some(business_profile),
+ )
+ .await
+ .attach_printable(
+ "Failed to store payment method data in vault in modular payment method flow",
+ )
+ })
+ .await
+ .transpose()?
+ .flatten();
+ payment_token.map(|data| payment_data.set_token(data));
let pm_id = payment_data
.get_payment_method_info()
.map(|pm| pm.payment_method_id.clone());
@@ -7982,6 +8002,27 @@ where
} else {
//Merchant enabled for PM Modular service
logger::debug!("Organization is eligible for PM Modular service, skipping make_pm_data call since raw payment method data fetch is done");
+ let payment_token = payment_data
+ .get_payment_method_data()
+ .async_map(|payment_method_data| async {
+ helpers::store_payment_method_data_in_vault(
+ state,
+ payment_data.get_payment_attempt(),
+ payment_data.get_payment_intent(),
+ enums::PaymentMethod::Card,
+ payment_method_data,
+ platform.get_provider().get_key_store(),
+ Some(business_profile),
+ )
+ .await
+ .attach_printable(
+ "Failed to store payment method data in vault in modular payment method flow",
+ )
+ })
+ .await
+ .transpose()?
+ .flatten();
+ payment_token.map(|data| payment_data.set_token(data));
let pm_id = payment_data
.get_payment_method_info()
.map(|pm| pm.payment_method_id.clone());
@@ -8034,6 +8075,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,
) -> RouterResult<D>
where
F: Send + Clone,
@@ -8045,20 +8087,29 @@ where
.request_external_three_ds_authentication;
let payment_data =
if !is_operation_confirm(operation) || is_external_authentication_requested == Some(true) {
- let (_operation, payment_method_data, pm_id) = operation
- .to_domain()?
- .make_pm_data(
+ if !feature_config.is_payment_method_modular_allowed {
+ 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));
+ }
+ } else {
+ set_payment_method_from_token_for_modular_payment_method_flow(
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));
+ .await;
}
payment_data
} else {
@@ -8067,6 +8118,54 @@ where
Ok(payment_data.to_owned())
}
+#[cfg(feature = "v1")]
+async fn set_payment_method_from_token_for_modular_payment_method_flow<F, D>(
+ state: &SessionState,
+ payment_data: &mut D,
+ platform: &domain::Platform,
+) where
+ F: Send + Clone,
+ D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send + Sync + Clone,
+{
+ let payment_method = match payment_data.get_token_data() {
+ Some(storage::PaymentTokenData::TemporaryGeneric(generic_token_data)) => {
+ logger::debug!("Using temporary token data");
+
+ vault::Vault::get_payment_method_data_from_locker(
+ state,
+ &generic_token_data.token,
+ platform.get_provider().get_key_store(),
+ )
+ .await
+ .map(|(pm, _)| pm)
+ .unwrap_or_else(|err| {
+ logger::error!(
+ "Failed to fetch payment method from temp storage: {:?}",
+ err
+ );
+ None
+ })
+ }
+ Some(
+ storage::PaymentTokenData::Temporary(_)
+ | storage::PaymentTokenData::Permanent(_)
+ | storage::PaymentTokenData::PermanentCard(_)
+ | storage::PaymentTokenData::AuthBankDebit(_)
+ | storage::PaymentTokenData::WalletToken(_)
+ | storage::PaymentTokenData::BankDebit(_),
+ )
+ | None => {
+ logger::debug!(
+ "No valid token data found: {:?}",
+ payment_data.get_token_data()
+ );
+ None
+ }
+ };
+
+ payment_data.set_payment_method_data(payment_method);
+}
+
#[derive(Clone)]
pub struct MandateConnectorDetails {
pub connector: String,
@@ -11634,6 +11733,7 @@ pub trait OperationSessionSetters<F> {
fn set_payment_method_info(&mut self, payment_method_info: Option<domain::PaymentMethod>);
fn set_payment_method_id_in_attempt(&mut self, payment_method_id: Option<String>);
fn set_pm_token(&mut self, token: String);
+ fn set_token(&mut self, token: String);
fn set_connector_customer_id(&mut self, customer_id: Option<String>);
fn push_sessions_token(&mut self, token: api::SessionToken);
fn set_surcharge_details(&mut self, surcharge_details: Option<types::SurchargeDetails>);
@@ -11905,6 +12005,10 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentData<F> {
self.pm_token = Some(token);
}
+ fn set_token(&mut self, token: String) {
+ self.token = Some(token);
+ }
+
fn set_connector_customer_id(&mut self, customer_id: Option<String>) {
self.connector_customer_id = customer_id;
}
@@ -12259,6 +12363,10 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentIntentData<F> {
todo!()
}
+ fn set_token(&mut self, token: String) {
+ todo!()
+ }
+
fn set_connector_customer_id(&mut self, customer_id: Option<String>) {
self.connector_customer_id = customer_id;
}
@@ -12554,6 +12662,10 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentConfirmData<F> {
todo!()
}
+ fn set_token(&mut self, token: String) {
+ todo!()
+ }
+
fn set_connector_customer_id(&mut self, _customer_id: Option<String>) {
// TODO: handle this case. Should we add connector_customer_id in paymentConfirmData?
}
@@ -12868,6 +12980,10 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentStatusData<F> {
todo!()
}
+ fn set_token(&mut self, token: String) {
+ todo!()
+ }
+
fn set_connector_customer_id(&mut self, _customer_id: Option<String>) {
// TODO: handle this case. Should we add connector_customer_id in paymentConfirmData?
}
@@ -13172,6 +13288,10 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentCaptureData<F> {
todo!()
}
+ fn set_token(&mut self, token: String) {
+ todo!()
+ }
+
fn set_connector_customer_id(&mut self, _customer_id: Option<String>) {
// TODO: handle this case. Should we add connector_customer_id in paymentConfirmData?
}
@@ -13621,6 +13741,10 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentCancelData<F> {
!todo!()
}
+ fn set_token(&mut self, token: String) {
+ todo!()
+ }
+
fn set_connector_customer_id(&mut self, _customer_id: Option<String>) {
// TODO: handle this case. Should we add connector_customer_id in PaymentCancelData?
}
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 642dea0faf..08569dbcd9 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -464,6 +464,7 @@ 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;
let (
payment_token,
payment_method,
@@ -731,9 +732,10 @@ pub async fn get_token_pm_type_mandate_details(
}
}
None => {
- let payment_method_info = match pm_info {
- Some(pm) => Some(pm.clone()),
- None => payment_method_id
+ let payment_method_info = if feature_config.is_payment_method_modular_allowed {
+ pm_info
+ } else {
+ payment_method_id
.async_map(|payment_method_id| async move {
state
.store
@@ -746,7 +748,7 @@ pub async fn get_token_pm_type_mandate_details(
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)
})
.await
- .transpose()?,
+ .transpose()?
};
(
request.payment_token.to_owned(),
diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs
index ef3b5cb03e..3ccb4a1424 100644
--- a/crates/router/src/core/payments/operations/payment_start.rs
+++ b/crates/router/src/core/payments/operations/payment_start.rs
@@ -4,7 +4,7 @@ use api_models::enums::FrmSuggestion;
use async_trait::async_trait;
use error_stack::ResultExt;
use router_derive::PaymentOperation;
-use router_env::{instrument, tracing};
+use router_env::{instrument, logger, tracing};
use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, ValidateRequest};
use crate::{
@@ -12,6 +12,7 @@ use crate::{
configs::dimension_state::DimensionsWithMerchantId,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments::{helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
+ utils,
},
routes::{app::ReqState, SessionState},
services,
@@ -126,13 +127,22 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsStartReq
)
.await?;
- let token_data = if let Some(token) = payment_attempt.payment_token.clone() {
- Some(
+ 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(
helpers::retrieve_payment_token_data(state, token, payment_attempt.payment_method)
.await?,
- )
- } else {
- None
+ ),
+ _ => {
+ logger::debug!("skipping token data retrieval in payment start");
+ None
+ }
};
payment_intent.shipping_address_id = shipping_address.clone().map(|i| i.address_id);