fix(router): add config to avoid connector tokenization for apple pay simplified flow (#3234)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Shankar Singh C
2024-01-11 13:39:46 +05:30
committed by GitHub
parent 8626bda6d5
commit 4f9c04b856
7 changed files with 45 additions and 14 deletions

View File

@ -287,6 +287,15 @@ pub struct PaymentMethodTokenFilter {
pub payment_method: HashSet<diesel_models::enums::PaymentMethod>,
pub payment_method_type: Option<PaymentMethodTypeTokenFilter>,
pub long_lived_token: bool,
pub apple_pay_pre_decrypt_flow: Option<ApplePayPreDecryptFlow>,
}
#[derive(Debug, Deserialize, Clone, Default)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub enum ApplePayPreDecryptFlow {
#[default]
ConnectorTokenization,
NetworkTokenization,
}
#[derive(Debug, Deserialize, Clone, Default)]

View File

@ -44,7 +44,7 @@ use super::{errors::StorageErrorExt, payment_methods::surcharge_decision_configs
#[cfg(feature = "frm")]
use crate::core::fraud_check as frm_core;
use crate::{
configs::settings::PaymentMethodTypeTokenFilter,
configs::settings::{ApplePayPreDecryptFlow, PaymentMethodTypeTokenFilter},
core::{
errors::{self, CustomResult, RouterResponse, RouterResult},
payment_methods::PaymentMethodRetrieve,
@ -1582,6 +1582,7 @@ fn is_payment_method_tokenization_enabled_for_connector(
connector_name: &str,
payment_method: &storage::enums::PaymentMethod,
payment_method_type: &Option<storage::enums::PaymentMethodType>,
apple_pay_flow: &Option<enums::ApplePayFlow>,
) -> RouterResult<bool> {
let connector_tokenization_filter = state.conf.tokenization.0.get(connector_name);
@ -1595,13 +1596,35 @@ fn is_payment_method_tokenization_enabled_for_connector(
payment_method_type,
connector_filter.payment_method_type.clone(),
)
&& is_apple_pay_pre_decrypt_type_connector_tokenization(
payment_method_type,
apple_pay_flow,
connector_filter.apple_pay_pre_decrypt_flow.clone(),
)
})
.unwrap_or(false))
}
fn is_apple_pay_pre_decrypt_type_connector_tokenization(
payment_method_type: &Option<storage::enums::PaymentMethodType>,
apple_pay_flow: &Option<enums::ApplePayFlow>,
apple_pay_pre_decrypt_flow_filter: Option<ApplePayPreDecryptFlow>,
) -> bool {
match (payment_method_type, apple_pay_flow) {
(
Some(storage::enums::PaymentMethodType::ApplePay),
Some(enums::ApplePayFlow::Simplified),
) => !matches!(
apple_pay_pre_decrypt_flow_filter,
Some(ApplePayPreDecryptFlow::NetworkTokenization)
),
_ => true,
}
}
fn decide_apple_pay_flow(
payment_method_type: &Option<api_models::enums::PaymentMethodType>,
merchant_connector_account: &Option<helpers::MerchantConnectorAccountType>,
merchant_connector_account: Option<&helpers::MerchantConnectorAccountType>,
) -> Option<enums::ApplePayFlow> {
payment_method_type.and_then(|pmt| match pmt {
api_models::enums::PaymentMethodType::ApplePay => {
@ -1612,9 +1635,9 @@ fn decide_apple_pay_flow(
}
fn check_apple_pay_metadata(
merchant_connector_account: &Option<helpers::MerchantConnectorAccountType>,
merchant_connector_account: Option<&helpers::MerchantConnectorAccountType>,
) -> Option<enums::ApplePayFlow> {
merchant_connector_account.clone().and_then(|mca| {
merchant_connector_account.and_then(|mca| {
let metadata = mca.get_metadata();
metadata.and_then(|apple_pay_metadata| {
let parsed_metadata = apple_pay_metadata
@ -1785,19 +1808,18 @@ where
.get_required_value("payment_method")?;
let payment_method_type = &payment_data.payment_attempt.payment_method_type;
let apple_pay_flow =
decide_apple_pay_flow(payment_method_type, Some(merchant_connector_account));
let is_connector_tokenization_enabled =
is_payment_method_tokenization_enabled_for_connector(
state,
&connector,
payment_method,
payment_method_type,
&apple_pay_flow,
)?;
let apple_pay_flow = decide_apple_pay_flow(
payment_method_type,
&Some(merchant_connector_account.clone()),
);
add_apple_pay_flow_metrics(
&apple_pay_flow,
payment_data.payment_attempt.connector.clone(),

View File

@ -118,7 +118,7 @@ where
let apple_pay_flow = payments::decide_apple_pay_flow(
&payment_data.payment_attempt.payment_method_type,
&Some(merchant_connector_account.clone()),
Some(merchant_connector_account),
);
router_data = types::RouterData {