mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +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 std::{collections::HashSet, marker::PhantomData};
|
||||||
|
|
||||||
|
use api_models::admin::PaymentMethodsEnabled;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use common_utils::ext_traits::ValueExt;
|
use common_utils::ext_traits::ValueExt;
|
||||||
use error_stack::ResultExt;
|
use error_stack::ResultExt;
|
||||||
@ -13,7 +14,7 @@ use crate::{
|
|||||||
payments::{self, helpers, operations, PaymentData},
|
payments::{self, helpers, operations, PaymentData},
|
||||||
},
|
},
|
||||||
db::StorageInterface,
|
db::StorageInterface,
|
||||||
pii,
|
logger, pii,
|
||||||
pii::Secret,
|
pii::Secret,
|
||||||
routes::AppState,
|
routes::AppState,
|
||||||
types::{
|
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]
|
#[async_trait]
|
||||||
impl<F: Clone + Send, Op: Send + Sync + Operation<F, api::PaymentsSessionRequest>>
|
impl<F: Clone + Send, Op: Send + Sync + Operation<F, api::PaymentsSessionRequest>>
|
||||||
Domain<F, api::PaymentsSessionRequest> for Op
|
Domain<F, api::PaymentsSessionRequest> for Op
|
||||||
@ -294,17 +290,44 @@ where
|
|||||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||||
.attach_printable("Database error when querying for merchant connector accounts")?;
|
.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()
|
.iter()
|
||||||
.filter(|connector_account| {
|
.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())
|
.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 )
|
// Parse the payment methods enabled to check if the merchant has enabled googlepay ( wallet ) using that connector.
|
||||||
// through that connector. This parsing from serde_json::Value to payment method is costly and has to be done for every connector
|
// A single connector can support creating session token from metadata as well as by calling the connector.
|
||||||
// for sure looks like an area of optimization
|
|
||||||
let session_token_from_metadata_connectors = connector_accounts
|
let session_token_from_metadata_connectors = connector_accounts
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|connector_account| {
|
.filter(|connector_account| {
|
||||||
@ -314,12 +337,28 @@ where
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|payment_method| {
|
.any(|payment_method| {
|
||||||
let parsed_payment_method: PaymentMethodEnabled = payment_method
|
let parsed_payment_method_result: Result<
|
||||||
.clone()
|
PaymentMethodsEnabled,
|
||||||
.parse_value("payment_method")
|
error_stack::Report<errors::ParsingError>,
|
||||||
.unwrap_or_default();
|
> = 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())
|
.map(|filtered_connector| filtered_connector.connector_name.clone())
|
||||||
|
|||||||
Reference in New Issue
Block a user