mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(session_token): create session token only if pmt is enabled (#703)
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
use std::{collections::HashSet, marker::PhantomData};
|
||||
|
||||
use api_models::admin::PaymentMethodsEnabled;
|
||||
use async_trait::async_trait;
|
||||
use common_utils::ext_traits::ValueExt;
|
||||
use error_stack::ResultExt;
|
||||
@ -13,7 +14,7 @@ use crate::{
|
||||
payments::{self, helpers, operations, PaymentData},
|
||||
},
|
||||
db::StorageInterface,
|
||||
pii,
|
||||
logger, pii,
|
||||
pii::Secret,
|
||||
routes::AppState,
|
||||
types::{
|
||||
@ -224,11 +225,6 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsSessionRequest> for Paymen
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Default)]
|
||||
pub struct PaymentMethodEnabled {
|
||||
payment_method: String,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<F: Clone + Send, Op: Send + Sync + Operation<F, api::PaymentsSessionRequest>>
|
||||
Domain<F, api::PaymentsSessionRequest> for Op
|
||||
@ -294,17 +290,44 @@ where
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("Database error when querying for merchant connector accounts")?;
|
||||
|
||||
let normal_connector_names = connector_accounts
|
||||
let normal_connector_names: HashSet<String> = connector_accounts
|
||||
.iter()
|
||||
.filter(|connector_account| {
|
||||
supported_connectors.contains(&connector_account.connector_name)
|
||||
connector_account
|
||||
.payment_methods_enabled
|
||||
.clone()
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.any(|payment_method| {
|
||||
let parsed_payment_method_result: Result<
|
||||
PaymentMethodsEnabled,
|
||||
error_stack::Report<errors::ParsingError>,
|
||||
> = payment_method.clone().parse_value("payment_method");
|
||||
|
||||
match parsed_payment_method_result {
|
||||
Ok(parsed_payment_method) => parsed_payment_method
|
||||
.payment_method_types
|
||||
.map(|payment_method_types| {
|
||||
payment_method_types.iter().any(|payment_method_type| {
|
||||
matches!(
|
||||
payment_method_type.payment_experience,
|
||||
Some(api_models::enums::PaymentExperience::InvokeSdkClient)
|
||||
)
|
||||
})
|
||||
})
|
||||
.unwrap_or(false),
|
||||
Err(parsing_error) => {
|
||||
logger::debug!(session_token_parsing_error=?parsing_error);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
.map(|filtered_connector| filtered_connector.connector_name.clone())
|
||||
.collect::<HashSet<String>>();
|
||||
.collect();
|
||||
|
||||
// Parse the payment methods enabled to check if the merchant has enabled gpay ( wallet )
|
||||
// through that connector. This parsing from serde_json::Value to payment method is costly and has to be done for every connector
|
||||
// for sure looks like an area of optimization
|
||||
// Parse the payment methods enabled to check if the merchant has enabled googlepay ( wallet ) using that connector.
|
||||
// A single connector can support creating session token from metadata as well as by calling the connector.
|
||||
let session_token_from_metadata_connectors = connector_accounts
|
||||
.iter()
|
||||
.filter(|connector_account| {
|
||||
@ -314,12 +337,28 @@ where
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.any(|payment_method| {
|
||||
let parsed_payment_method: PaymentMethodEnabled = payment_method
|
||||
.clone()
|
||||
.parse_value("payment_method")
|
||||
.unwrap_or_default();
|
||||
let parsed_payment_method_result: Result<
|
||||
PaymentMethodsEnabled,
|
||||
error_stack::Report<errors::ParsingError>,
|
||||
> = payment_method.clone().parse_value("payment_method");
|
||||
|
||||
parsed_payment_method.payment_method == "wallet"
|
||||
match parsed_payment_method_result {
|
||||
Ok(parsed_payment_method) => parsed_payment_method
|
||||
.payment_method_types
|
||||
.map(|payment_method_types| {
|
||||
payment_method_types.iter().any(|payment_method_type| {
|
||||
matches!(
|
||||
payment_method_type.payment_method_type,
|
||||
api_models::enums::PaymentMethodType::GooglePay
|
||||
)
|
||||
})
|
||||
})
|
||||
.unwrap_or(false),
|
||||
Err(parsing_error) => {
|
||||
logger::debug!(session_token_parsing_error=?parsing_error);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
.map(|filtered_connector| filtered_connector.connector_name.clone())
|
||||
|
||||
Reference in New Issue
Block a user