mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
feat(connector): Mandates for alternate payment methods via Stripe (#1041)
Co-authored-by: Manoj Ghorela <manoj.ghorela@juspay.in> Co-authored-by: Arjun Karthik <m.arjunkarthik@gmail.com>
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
pub mod access_token;
|
||||
pub mod customers;
|
||||
pub mod flows;
|
||||
pub mod helpers;
|
||||
pub mod operations;
|
||||
pub mod tokenization;
|
||||
pub mod transformers;
|
||||
|
||||
use std::{fmt::Debug, marker::PhantomData, time::Instant};
|
||||
@ -24,6 +26,7 @@ use self::{
|
||||
operations::{payment_complete_authorize, BoxedOperation, Operation},
|
||||
};
|
||||
use crate::{
|
||||
configs::settings::PaymentMethodTypeTokenFilter,
|
||||
core::{
|
||||
errors::{self, CustomResult, RouterResponse, RouterResult},
|
||||
payment_methods::vault,
|
||||
@ -654,14 +657,38 @@ fn is_payment_method_tokenization_enabled_for_connector(
|
||||
state: &AppState,
|
||||
connector_name: &str,
|
||||
payment_method: &storage::enums::PaymentMethod,
|
||||
payment_method_type: &Option<storage::enums::PaymentMethodType>,
|
||||
) -> RouterResult<bool> {
|
||||
let connector_tokenization_filter = state.conf.tokenization.0.get(connector_name);
|
||||
|
||||
Ok(connector_tokenization_filter
|
||||
.map(|connector_filter| connector_filter.payment_method.contains(payment_method))
|
||||
.map(|connector_filter| {
|
||||
connector_filter
|
||||
.payment_method
|
||||
.clone()
|
||||
.contains(payment_method)
|
||||
&& is_payment_method_type_allowed_for_connector(
|
||||
payment_method_type,
|
||||
connector_filter.payment_method_type.clone(),
|
||||
)
|
||||
})
|
||||
.unwrap_or(false))
|
||||
}
|
||||
|
||||
fn is_payment_method_type_allowed_for_connector(
|
||||
current_pm_type: &Option<storage::enums::PaymentMethodType>,
|
||||
pm_type_filter: Option<PaymentMethodTypeTokenFilter>,
|
||||
) -> bool {
|
||||
match current_pm_type.clone().zip(pm_type_filter) {
|
||||
Some((pm_type, type_filter)) => match type_filter {
|
||||
PaymentMethodTypeTokenFilter::AllAccepted => true,
|
||||
PaymentMethodTypeTokenFilter::EnableOnly(enabled) => enabled.contains(&pm_type),
|
||||
PaymentMethodTypeTokenFilter::DisableOnly(disabled) => !disabled.contains(&pm_type),
|
||||
},
|
||||
None => true, // Allow all types if payment_method_type is not present
|
||||
}
|
||||
}
|
||||
|
||||
async fn decide_payment_method_tokenize_action(
|
||||
state: &AppState,
|
||||
connector_name: &str,
|
||||
@ -736,12 +763,14 @@ where
|
||||
.payment_attempt
|
||||
.payment_method
|
||||
.get_required_value("payment_method")?;
|
||||
let payment_method_type = &payment_data.payment_attempt.payment_method_type;
|
||||
|
||||
let is_connector_tokenization_enabled =
|
||||
is_payment_method_tokenization_enabled_for_connector(
|
||||
state,
|
||||
&connector,
|
||||
payment_method,
|
||||
payment_method_type,
|
||||
)?;
|
||||
|
||||
let payment_method_action = decide_payment_method_tokenize_action(
|
||||
|
||||
Reference in New Issue
Block a user