mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
feat: fetch merchant key store only once per session (#1400)
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
@ -49,6 +49,7 @@ use crate::{
|
||||
pub async fn payments_operation_core<F, Req, Op, FData>(
|
||||
state: &AppState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
operation: Op,
|
||||
req: Req,
|
||||
call_connector_action: CallConnectorAction,
|
||||
@ -87,6 +88,7 @@ where
|
||||
&req,
|
||||
validate_result.mandate_type.to_owned(),
|
||||
&merchant_account,
|
||||
&key_store,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -102,7 +104,7 @@ where
|
||||
&*state.store,
|
||||
&mut payment_data,
|
||||
customer_details,
|
||||
validate_result.merchant_id,
|
||||
&key_store,
|
||||
)
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound)
|
||||
@ -113,6 +115,7 @@ where
|
||||
state,
|
||||
&req,
|
||||
&merchant_account,
|
||||
&key_store,
|
||||
&mut payment_data,
|
||||
)
|
||||
.await?;
|
||||
@ -125,6 +128,7 @@ where
|
||||
state,
|
||||
&customer,
|
||||
&merchant_account,
|
||||
&key_store,
|
||||
&mut payment_data,
|
||||
)
|
||||
.await?;
|
||||
@ -144,6 +148,7 @@ where
|
||||
let router_data = call_connector_service(
|
||||
state,
|
||||
&merchant_account,
|
||||
&key_store,
|
||||
connector,
|
||||
&operation,
|
||||
&mut payment_data,
|
||||
@ -172,6 +177,7 @@ where
|
||||
call_multiple_connectors_service(
|
||||
state,
|
||||
&merchant_account,
|
||||
&key_store,
|
||||
connectors,
|
||||
&operation,
|
||||
payment_data,
|
||||
@ -194,6 +200,7 @@ where
|
||||
customer.clone(),
|
||||
validate_result.storage_scheme,
|
||||
updated_customer,
|
||||
&key_store,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
@ -205,6 +212,7 @@ where
|
||||
pub async fn payments_core<F, Res, Req, Op, FData>(
|
||||
state: &AppState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
operation: Op,
|
||||
req: Req,
|
||||
auth_flow: services::AuthFlow,
|
||||
@ -230,6 +238,7 @@ where
|
||||
let (payment_data, req, customer) = payments_operation_core(
|
||||
state,
|
||||
merchant_account,
|
||||
key_store,
|
||||
operation.clone(),
|
||||
req,
|
||||
call_connector_action,
|
||||
@ -267,6 +276,7 @@ pub trait PaymentRedirectFlow: Sync {
|
||||
&self,
|
||||
state: &AppState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
merchant_key_store: domain::MerchantKeyStore,
|
||||
req: PaymentsRedirectResponseData,
|
||||
connector_action: CallConnectorAction,
|
||||
) -> RouterResponse<api::PaymentsResponse>;
|
||||
@ -286,6 +296,7 @@ pub trait PaymentRedirectFlow: Sync {
|
||||
&self,
|
||||
state: &AppState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
req: PaymentsRedirectResponseData,
|
||||
) -> RouterResponse<api::RedirectionResponse> {
|
||||
metrics::REDIRECTION_TRIGGERED.add(
|
||||
@ -328,7 +339,13 @@ pub trait PaymentRedirectFlow: Sync {
|
||||
.attach_printable("Failed to decide the response flow")?;
|
||||
|
||||
let response = self
|
||||
.call_payment_flow(state, merchant_account.clone(), req.clone(), flow_type)
|
||||
.call_payment_flow(
|
||||
state,
|
||||
merchant_account.clone(),
|
||||
key_store,
|
||||
req.clone(),
|
||||
flow_type,
|
||||
)
|
||||
.await;
|
||||
|
||||
let payments_response = match response? {
|
||||
@ -354,6 +371,7 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
|
||||
&self,
|
||||
state: &AppState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
merchant_key_store: domain::MerchantKeyStore,
|
||||
req: PaymentsRedirectResponseData,
|
||||
connector_action: CallConnectorAction,
|
||||
) -> RouterResponse<api::PaymentsResponse> {
|
||||
@ -374,6 +392,7 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
|
||||
payments_core::<api::CompleteAuthorize, api::PaymentsResponse, _, _, _>(
|
||||
state,
|
||||
merchant_account,
|
||||
merchant_key_store,
|
||||
payment_complete_authorize::CompleteAuthorize,
|
||||
payment_confirm_req,
|
||||
services::api::AuthFlow::Merchant,
|
||||
@ -441,6 +460,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync {
|
||||
&self,
|
||||
state: &AppState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
merchant_key_store: domain::MerchantKeyStore,
|
||||
req: PaymentsRedirectResponseData,
|
||||
connector_action: CallConnectorAction,
|
||||
) -> RouterResponse<api::PaymentsResponse> {
|
||||
@ -460,6 +480,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync {
|
||||
payments_core::<api::PSync, api::PaymentsResponse, _, _, _>(
|
||||
state,
|
||||
merchant_account,
|
||||
merchant_key_store,
|
||||
PaymentStatus,
|
||||
payment_sync_req,
|
||||
services::api::AuthFlow::Merchant,
|
||||
@ -492,6 +513,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync {
|
||||
pub async fn call_connector_service<F, RouterDReq, ApiRequest>(
|
||||
state: &AppState,
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
connector: api::ConnectorData,
|
||||
operation: &BoxedOperation<'_, F, ApiRequest>,
|
||||
payment_data: &mut PaymentData<F>,
|
||||
@ -515,7 +537,13 @@ where
|
||||
let stime_connector = Instant::now();
|
||||
|
||||
let mut router_data = payment_data
|
||||
.construct_router_data(state, connector.connector.id(), merchant_account, customer)
|
||||
.construct_router_data(
|
||||
state,
|
||||
connector.connector.id(),
|
||||
merchant_account,
|
||||
key_store,
|
||||
customer,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let add_access_token_result = router_data
|
||||
@ -575,6 +603,7 @@ where
|
||||
customer.clone(),
|
||||
merchant_account.storage_scheme,
|
||||
updated_customer,
|
||||
key_store,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -608,6 +637,7 @@ where
|
||||
pub async fn call_multiple_connectors_service<F, Op, Req>(
|
||||
state: &AppState,
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
connectors: Vec<api::SessionConnectorData>,
|
||||
_operation: &Op,
|
||||
mut payment_data: PaymentData<F>,
|
||||
@ -633,7 +663,7 @@ where
|
||||
for session_connector_data in connectors.iter() {
|
||||
let connector_id = session_connector_data.connector.connector.id();
|
||||
let router_data = payment_data
|
||||
.construct_router_data(state, connector_id, merchant_account, customer)
|
||||
.construct_router_data(state, connector_id, merchant_account, key_store, customer)
|
||||
.await?;
|
||||
|
||||
let res = router_data.decide_flows(
|
||||
@ -689,6 +719,7 @@ pub async fn call_create_connector_customer_if_required<F, Req>(
|
||||
state: &AppState,
|
||||
customer: &Option<domain::Customer>,
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
payment_data: &mut PaymentData<F>,
|
||||
) -> RouterResult<Option<storage::CustomerUpdate>>
|
||||
where
|
||||
@ -737,6 +768,7 @@ where
|
||||
state,
|
||||
connector.connector.id(),
|
||||
merchant_account,
|
||||
key_store,
|
||||
customer,
|
||||
)
|
||||
.await?;
|
||||
@ -1237,6 +1269,7 @@ pub async fn get_connector_choice<F, Req>(
|
||||
state: &AppState,
|
||||
req: &Req,
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
payment_data: &mut PaymentData<F>,
|
||||
) -> RouterResult<Option<api::ConnectorCallType>>
|
||||
where
|
||||
@ -1244,7 +1277,13 @@ where
|
||||
{
|
||||
let connector_choice = operation
|
||||
.to_domain()?
|
||||
.get_connector(merchant_account, state, req, &payment_data.payment_intent)
|
||||
.get_connector(
|
||||
merchant_account,
|
||||
state,
|
||||
req,
|
||||
&payment_data.payment_intent,
|
||||
key_store,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let connector = if should_call_connector(operation, payment_data) {
|
||||
|
||||
Reference in New Issue
Block a user