refactor(core): Add additional parameters in AppState and refactor AppState references (#2123)

Co-authored-by: Kritik Modi <kritik.modi@juspay.in>
Co-authored-by: Kritik Modi <61862301+kritikmodi@users.noreply.github.com>
Co-authored-by: Nitesh Balla <nitesh.balla@juspay.in>
This commit is contained in:
Abhishek Marrivagu
2023-09-18 14:01:03 +05:30
committed by GitHub
parent b39369ced9
commit a0a8ef27b3
46 changed files with 531 additions and 395 deletions

View File

@ -46,7 +46,7 @@ pub async fn payments_incoming_webhook_flow<W: types::OutgoingWebhookType>(
let payments_response = match webhook_details.object_reference_id {
api_models::webhooks::ObjectReferenceId::PaymentId(id) => {
let response = payments::payments_core::<api::PSync, api::PaymentsResponse, _, _, _>(
&state,
state.clone(),
merchant_account.clone(),
key_store,
payments::operations::PaymentStatus,
@ -197,7 +197,7 @@ pub async fn refunds_incoming_webhook_flow<W: types::OutgoingWebhookType>(
})?
} else {
refunds::refund_retrieve_core(
&state,
state.clone(),
merchant_account.clone(),
key_store,
api_models::refunds::RefundsRetrieveRequest {
@ -432,7 +432,7 @@ async fn bank_transfer_webhook_flow<W: types::OutgoingWebhookType>(
..Default::default()
};
payments::payments_core::<api::Authorize, api::PaymentsResponse, _, _, _>(
&state,
state.clone(),
merchant_account.to_owned(),
key_store,
payments::PaymentConfirm,
@ -645,8 +645,10 @@ pub async fn trigger_webhook_to_merchant<W: types::OutgoingWebhookType>(
.body(Some(transformed_outgoing_webhook_string))
.build();
let response =
services::api::send_request(state, request, Some(OUTGOING_WEBHOOK_TIMEOUT_SECS)).await;
let response = state
.api_client
.send_request(state, request, Some(OUTGOING_WEBHOOK_TIMEOUT_SECS), false)
.await;
metrics::WEBHOOK_OUTGOING_COUNT.add(
&metrics::CONTEXT,
@ -701,7 +703,7 @@ pub async fn trigger_webhook_to_merchant<W: types::OutgoingWebhookType>(
#[instrument(skip_all)]
pub async fn webhooks_core<W: types::OutgoingWebhookType>(
state: &AppState,
state: AppState,
req: &actix_web::HttpRequest,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
@ -725,7 +727,7 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
};
let (merchant_connector_account, connector) = fetch_mca_and_connector(
state,
state.clone(),
&merchant_account,
connector_name_or_mca_id,
&key_store,
@ -739,7 +741,7 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
let decoded_body = connector
.decode_webhook_body(
&*state.store,
&*state.clone().store,
&request_details,
&merchant_account.merchant_id,
)
@ -752,7 +754,13 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
let event_type = match connector
.get_webhook_event_type(&request_details)
.allow_webhook_event_type_not_found(
state.conf.webhooks.ignore_error.event_type.unwrap_or(true),
state
.clone()
.conf
.webhooks
.ignore_error
.event_type
.unwrap_or(true),
)
.switch()
.attach_printable("Could not find event type in incoming webhook body")?
@ -782,7 +790,7 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
};
let process_webhook_further = utils::lookup_webhook_event(
&*state.store,
&*state.clone().store,
connector_name.as_str(),
&merchant_account.merchant_id,
&event_type,
@ -915,7 +923,7 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
}
async fn fetch_mca_and_connector(
state: &AppState,
state: AppState,
merchant_account: &domain::MerchantAccount,
connector_name_or_mca_id: &str,
key_store: &domain::MerchantKeyStore,