refactor(core): eliminate business profile database queries in payments confirm flow (#2190)

This commit is contained in:
BallaNitesh
2023-09-22 14:45:33 +05:30
committed by GitHub
parent 8b89969476
commit 90e43929a0
8 changed files with 28 additions and 16 deletions

View File

@ -636,6 +636,7 @@ pub async fn create_payment_connector(
&merchant_account,
req.profile_id.as_ref(),
&*state.store,
true,
)
.await?;

View File

@ -879,6 +879,7 @@ pub async fn list_payment_methods(
&merchant_account,
payment_intent.profile_id.as_ref(),
db,
false,
)
.await
.attach_printable("Could not find profile id from business details")

View File

@ -591,6 +591,7 @@ where
payment_data,
connector_name,
key_store,
false,
)
.await?;
@ -610,6 +611,7 @@ where
customer,
merchant_account,
key_store,
&merchant_connector_account,
payment_data,
)
.await?;
@ -799,6 +801,7 @@ where
&mut payment_data,
&session_connector_data.connector.connector_name.to_string(),
key_store,
false,
)
.await?;
@ -870,6 +873,7 @@ pub async fn call_create_connector_customer_if_required<F, Req>(
customer: &Option<domain::Customer>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
merchant_connector_account: &helpers::MerchantConnectorAccountType,
payment_data: &mut PaymentData<F>,
) -> RouterResult<Option<storage::CustomerUpdate>>
where
@ -888,15 +892,6 @@ where
match connector_name {
Some(connector_name) => {
let merchant_connector_account = construct_profile_id_and_get_mca(
state,
merchant_account,
payment_data,
&connector_name,
key_store,
)
.await?;
let connector = api::ConnectorData::get_connector_by_name(
&state.conf.connectors,
&connector_name,
@ -919,6 +914,7 @@ where
merchant_account,
payment_data.payment_intent.profile_id.as_ref(),
&*state.store,
false,
)
.await
.attach_printable("Could not find profile id from business details")?;
@ -943,7 +939,7 @@ where
merchant_account,
key_store,
customer,
&merchant_connector_account,
merchant_connector_account,
)
.await?;
@ -1057,6 +1053,7 @@ pub async fn construct_profile_id_and_get_mca<'a, F>(
payment_data: &mut PaymentData<F>,
connector_id: &str,
key_store: &domain::MerchantKeyStore,
should_validate: bool,
) -> RouterResult<helpers::MerchantConnectorAccountType>
where
F: Clone,
@ -1067,6 +1064,7 @@ where
merchant_account,
payment_data.payment_intent.profile_id.as_ref(),
&*state.store,
should_validate,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)

View File

@ -615,6 +615,7 @@ impl PaymentCreate {
merchant_account,
request.profile_id.as_ref(),
&*state.store,
true,
)
.await?;

View File

@ -340,6 +340,7 @@ where
merchant_account,
payment_intent.profile_id.as_ref(),
&*state.store,
false,
)
.await
.attach_printable("Could not find profile id from business details")?;

View File

@ -565,6 +565,7 @@ pub async fn create_recipient(
merchant_account,
payout_data.payout_attempt.profile_id.as_ref(),
&*state.store,
false,
)
.await?;

View File

@ -211,6 +211,7 @@ pub async fn construct_refund_router_data<'a, F>(
merchant_account,
payment_intent.profile_id.as_ref(),
&*state.store,
false,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
@ -484,6 +485,7 @@ pub async fn construct_accept_dispute_router_data<'a>(
merchant_account,
payment_intent.profile_id.as_ref(),
&*state.store,
false,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
@ -570,6 +572,7 @@ pub async fn construct_submit_evidence_router_data<'a>(
merchant_account,
payment_intent.profile_id.as_ref(),
&*state.store,
false,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
@ -654,6 +657,7 @@ pub async fn construct_upload_file_router_data<'a>(
merchant_account,
payment_intent.profile_id.as_ref(),
&*state.store,
false,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
@ -741,6 +745,7 @@ pub async fn construct_defend_dispute_router_data<'a>(
merchant_account,
payment_intent.profile_id.as_ref(),
&*state.store,
false,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
@ -992,16 +997,19 @@ pub async fn get_profile_id_from_business_details(
merchant_account: &domain::MerchantAccount,
request_profile_id: Option<&String>,
db: &dyn StorageInterface,
should_validate: bool,
) -> RouterResult<String> {
match request_profile_id.or(merchant_account.default_profile.as_ref()) {
Some(profile_id) => {
// Check whether this business profile belongs to the merchant
if should_validate {
let _ = validate_and_get_business_profile(
db,
Some(profile_id),
&merchant_account.merchant_id,
)
.await?;
}
Ok(profile_id.clone())
}
None => match business_country.zip(business_label) {

View File

@ -320,6 +320,7 @@ pub async fn get_profile_id_using_object_reference_id(
merchant_account,
payment_intent.profile_id.as_ref(),
db,
false,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)