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, &merchant_account,
req.profile_id.as_ref(), req.profile_id.as_ref(),
&*state.store, &*state.store,
true,
) )
.await?; .await?;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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