refactor: add support for passing context generic to api calls (#2433)

This commit is contained in:
Chethan Rao
2023-10-06 13:10:13 +05:30
committed by GitHub
parent 61288d541f
commit 601c1744b6
26 changed files with 720 additions and 431 deletions

View File

@ -20,6 +20,7 @@ use crate::{
core::{
api_locking,
errors::{self, ConnectorErrorExt, CustomResult, RouterResponse},
payment_methods::PaymentMethodRetrieve,
payments, refunds,
},
db::StorageInterface,
@ -39,7 +40,10 @@ use crate::{
const OUTGOING_WEBHOOK_TIMEOUT_SECS: u64 = 5;
const MERCHANT_ID: &str = "merchant_id";
pub async fn payments_incoming_webhook_flow<W: types::OutgoingWebhookType>(
pub async fn payments_incoming_webhook_flow<
W: types::OutgoingWebhookType,
Ctx: PaymentMethodRetrieve,
>(
state: AppState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
@ -74,27 +78,28 @@ pub async fn payments_incoming_webhook_flow<W: types::OutgoingWebhookType>(
.perform_locking_action(&state, merchant_account.merchant_id.to_string())
.await?;
let response = payments::payments_core::<api::PSync, api::PaymentsResponse, _, _, _>(
state.clone(),
merchant_account.clone(),
key_store,
payments::operations::PaymentStatus,
api::PaymentsRetrieveRequest {
resource_id: id,
merchant_id: Some(merchant_account.merchant_id.clone()),
force_sync: true,
connector: None,
param: None,
merchant_connector_details: None,
client_secret: None,
expand_attempts: None,
expand_captures: None,
},
services::AuthFlow::Merchant,
consume_or_trigger_flow,
HeaderPayload::default(),
)
.await;
let response =
payments::payments_core::<api::PSync, api::PaymentsResponse, _, _, _, Ctx>(
state.clone(),
merchant_account.clone(),
key_store,
payments::operations::PaymentStatus,
api::PaymentsRetrieveRequest {
resource_id: id,
merchant_id: Some(merchant_account.merchant_id.clone()),
force_sync: true,
connector: None,
param: None,
merchant_connector_details: None,
client_secret: None,
expand_attempts: None,
expand_captures: None,
},
services::AuthFlow::Merchant,
consume_or_trigger_flow,
HeaderPayload::default(),
)
.await;
lock_action
.free_lock_action(&state, merchant_account.merchant_id.to_owned())
@ -531,7 +536,7 @@ pub async fn disputes_incoming_webhook_flow<W: types::OutgoingWebhookType>(
}
}
async fn bank_transfer_webhook_flow<W: types::OutgoingWebhookType>(
async fn bank_transfer_webhook_flow<W: types::OutgoingWebhookType, Ctx: PaymentMethodRetrieve>(
state: AppState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
@ -553,7 +558,7 @@ async fn bank_transfer_webhook_flow<W: types::OutgoingWebhookType>(
payment_token: payment_attempt.payment_token,
..Default::default()
};
payments::payments_core::<api::Authorize, api::PaymentsResponse, _, _, _>(
payments::payments_core::<api::Authorize, api::PaymentsResponse, _, _, _, Ctx>(
state.clone(),
merchant_account.to_owned(),
key_store,
@ -824,7 +829,7 @@ pub async fn trigger_webhook_to_merchant<W: types::OutgoingWebhookType>(
Ok(())
}
pub async fn webhooks_wrapper<W: types::OutgoingWebhookType>(
pub async fn webhooks_wrapper<W: types::OutgoingWebhookType, Ctx: PaymentMethodRetrieve>(
state: AppState,
req: &actix_web::HttpRequest,
merchant_account: domain::MerchantAccount,
@ -832,7 +837,7 @@ pub async fn webhooks_wrapper<W: types::OutgoingWebhookType>(
connector_name_or_mca_id: &str,
body: actix_web::web::Bytes,
) -> RouterResponse<serde_json::Value> {
let (application_response, _webhooks_response_tracker) = webhooks_core::<W>(
let (application_response, _webhooks_response_tracker) = webhooks_core::<W, Ctx>(
state,
req,
merchant_account,
@ -846,7 +851,8 @@ pub async fn webhooks_wrapper<W: types::OutgoingWebhookType>(
}
#[instrument(skip_all)]
pub async fn webhooks_core<W: types::OutgoingWebhookType>(
pub async fn webhooks_core<W: types::OutgoingWebhookType, Ctx: PaymentMethodRetrieve>(
state: AppState,
req: &actix_web::HttpRequest,
merchant_account: domain::MerchantAccount,
@ -1044,7 +1050,7 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
};
match flow_type {
api::WebhookFlow::Payment => payments_incoming_webhook_flow::<W>(
api::WebhookFlow::Payment => payments_incoming_webhook_flow::<W, Ctx>(
state.clone(),
merchant_account,
key_store,
@ -1078,7 +1084,7 @@ pub async fn webhooks_core<W: types::OutgoingWebhookType>(
.await
.attach_printable("Incoming webhook flow for disputes failed")?,
api::WebhookFlow::BankTransfer => bank_transfer_webhook_flow::<W>(
api::WebhookFlow::BankTransfer => bank_transfer_webhook_flow::<W, Ctx>(
state.clone(),
merchant_account,
key_store,