Skip to content

Commit

Permalink
feat(core): accept business profile in core functions for payments, r…
Browse files Browse the repository at this point in the history
…efund, payout and disputes (#5498)
  • Loading branch information
hrithikesh026 authored Aug 1, 2024
1 parent 85209d1 commit fb32b61
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 20 deletions.
9 changes: 8 additions & 1 deletion crates/router/src/compatibility/stripe/payment_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub async fn payment_intents_create(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentCreate,
req,
Expand Down Expand Up @@ -123,6 +124,7 @@ pub async fn payment_intents_retrieve(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentStatus,
payload,
Expand Down Expand Up @@ -193,6 +195,7 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentStatus,
req,
Expand Down Expand Up @@ -259,6 +262,7 @@ pub async fn payment_intents_update(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentUpdate,
req,
Expand Down Expand Up @@ -331,6 +335,7 @@ pub async fn payment_intents_confirm(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentConfirm,
req,
Expand Down Expand Up @@ -392,6 +397,7 @@ pub async fn payment_intents_capture(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentCapture,
payload,
Expand Down Expand Up @@ -457,6 +463,7 @@ pub async fn payment_intents_cancel(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentCancel,
req,
Expand Down Expand Up @@ -499,7 +506,7 @@ pub async fn payment_intent_list(
&req,
payload,
|state, auth, req, _| {
payments::list_payments(state, auth.merchant_account, auth.key_store, req)
payments::list_payments(state, auth.merchant_account, None, auth.key_store, req)
},
&auth::HeaderAuth(auth::ApiKeyAuth),
api_locking::LockAction::NotApplicable,
Expand Down
4 changes: 3 additions & 1 deletion crates/router/src/compatibility/stripe/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub async fn refund_create(
&req,
create_refund_req,
|state, auth, req, _| {
refunds::refund_create_core(state, auth.merchant_account, auth.key_store, req)
refunds::refund_create_core(state, auth.merchant_account, None, auth.key_store, req)
},
&auth::HeaderAuth(auth::ApiKeyAuth),
api_locking::LockAction::NotApplicable,
Expand Down Expand Up @@ -97,6 +97,7 @@ pub async fn refund_retrieve_with_gateway_creds(
refunds::refund_response_wrapper(
state,
auth.merchant_account,
None,
auth.key_store,
refund_request,
refunds::refund_retrieve_core,
Expand Down Expand Up @@ -139,6 +140,7 @@ pub async fn refund_retrieve(
refunds::refund_response_wrapper(
state,
auth.merchant_account,
None,
auth.key_store,
refund_request,
refunds::refund_retrieve_core,
Expand Down
4 changes: 4 additions & 0 deletions crates/router/src/compatibility/stripe/setup_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub async fn setup_intents_create(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentCreate,
req,
Expand Down Expand Up @@ -124,6 +125,7 @@ pub async fn setup_intents_retrieve(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentStatus,
payload,
Expand Down Expand Up @@ -196,6 +198,7 @@ pub async fn setup_intents_update(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentUpdate,
req,
Expand Down Expand Up @@ -269,6 +272,7 @@ pub async fn setup_intents_confirm(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentConfirm,
req,
Expand Down
6 changes: 6 additions & 0 deletions crates/router/src/core/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::{
pub async fn retrieve_dispute(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id: Option<String>,
req: disputes::DisputeId,
) -> RouterResponse<api_models::disputes::DisputeResponse> {
let dispute = state
Expand All @@ -43,6 +44,7 @@ pub async fn retrieve_dispute(
pub async fn retrieve_disputes_list(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id_list: Option<Vec<String>>,
constraints: api_models::disputes::DisputeListConstraints,
) -> RouterResponse<Vec<api_models::disputes::DisputeResponse>> {
let disputes = state
Expand All @@ -62,6 +64,7 @@ pub async fn retrieve_disputes_list(
pub async fn accept_dispute(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id: Option<String>,
key_store: domain::MerchantKeyStore,
req: disputes::DisputeId,
) -> RouterResponse<dispute_models::DisputeResponse> {
Expand Down Expand Up @@ -164,6 +167,7 @@ pub async fn accept_dispute(
pub async fn submit_evidence(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id: Option<String>,
key_store: domain::MerchantKeyStore,
req: dispute_models::SubmitEvidenceRequest,
) -> RouterResponse<dispute_models::DisputeResponse> {
Expand Down Expand Up @@ -329,6 +333,7 @@ pub async fn submit_evidence(
pub async fn attach_evidence(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id: Option<String>,
key_store: domain::MerchantKeyStore,
attach_evidence_request: api::AttachEvidenceRequest,
) -> RouterResponse<files_api_models::CreateFileResponse> {
Expand Down Expand Up @@ -406,6 +411,7 @@ pub async fn attach_evidence(
pub async fn retrieve_dispute_evidence(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id: Option<String>,
req: disputes::DisputeId,
) -> RouterResponse<Vec<api_models::disputes::DisputeEvidenceBlock>> {
let dispute = state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl<F: Send + Clone> Domain<F> for FraudCheckPost {
state.clone(),
req_state.clone(),
merchant_account.clone(),
None,
key_store.clone(),
payments::PaymentCancel,
cancel_req,
Expand Down Expand Up @@ -270,6 +271,7 @@ impl<F: Send + Clone> Domain<F> for FraudCheckPost {
state.clone(),
req_state.clone(),
merchant_account.clone(),
None,
key_store.clone(),
payments::PaymentCapture,
capture_request,
Expand Down
8 changes: 8 additions & 0 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ pub async fn payments_core<F, Res, Req, Op, FData>(
state: SessionState,
req_state: ReqState,
merchant_account: domain::MerchantAccount,
_profile_id: Option<String>,
key_store: domain::MerchantKeyStore,
operation: Op,
req: Req,
Expand Down Expand Up @@ -998,6 +999,7 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
state.clone(),
req_state,
merchant_account,
None,
merchant_key_store,
payment_complete_authorize::CompleteAuthorize,
payment_confirm_req,
Expand Down Expand Up @@ -1129,6 +1131,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync {
state.clone(),
req_state,
merchant_account,
None,
merchant_key_store,
PaymentStatus,
payment_sync_req,
Expand Down Expand Up @@ -1286,6 +1289,7 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize {
state.clone(),
req_state,
merchant_account,
None,
merchant_key_store,
PaymentConfirm,
payment_confirm_req,
Expand Down Expand Up @@ -1316,6 +1320,7 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize {
state.clone(),
req_state,
merchant_account.clone(),
None,
merchant_key_store,
PaymentStatus,
payment_sync_req,
Expand Down Expand Up @@ -2866,6 +2871,7 @@ pub fn is_operation_complete_authorize<Op: Debug>(operation: &Op) -> bool {
pub async fn list_payments(
state: SessionState,
merchant: domain::MerchantAccount,
_profile_id_list: Option<Vec<String>>,
key_store: domain::MerchantKeyStore,
constraints: api::PaymentListConstraints,
) -> RouterResponse<api::PaymentListResponse> {
Expand Down Expand Up @@ -2938,6 +2944,7 @@ pub async fn list_payments(
pub async fn apply_filters_on_payments(
state: SessionState,
merchant: domain::MerchantAccount,
_profile_id_list: Option<Vec<String>>,
merchant_key_store: domain::MerchantKeyStore,
constraints: api::PaymentListFilterConstraints,
) -> RouterResponse<api::PaymentListResponseV2> {
Expand Down Expand Up @@ -3035,6 +3042,7 @@ pub async fn get_filters_for_payments(
pub async fn get_payment_filters(
state: SessionState,
merchant: domain::MerchantAccount,
_profile_id_list: Option<Vec<String>>,
) -> RouterResponse<api::PaymentListFiltersV2> {
let merchant_connector_accounts = if let services::ApplicationResponse::Json(data) =
super::admin::list_payment_connectors(state, merchant.get_id().to_owned()).await?
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/core/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ pub async fn payouts_update_core(
pub async fn payouts_retrieve_core(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id: Option<String>,
key_store: domain::MerchantKeyStore,
req: payouts::PayoutRetrieveRequest,
) -> RouterResponse<payouts::PayoutCreateResponse> {
Expand Down Expand Up @@ -707,6 +708,7 @@ pub async fn payouts_fulfill_core(
pub async fn payouts_list_core(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id_list: Option<Vec<String>>,
key_store: domain::MerchantKeyStore,
constraints: payouts::PayoutListConstraints,
) -> RouterResponse<payouts::PayoutListResponse> {
Expand Down Expand Up @@ -805,6 +807,7 @@ pub async fn payouts_list_core(
pub async fn payouts_filtered_list_core(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id_list: Option<Vec<String>>,
key_store: domain::MerchantKeyStore,
filters: payouts::PayoutListFilterConstraints,
) -> RouterResponse<payouts::PayoutListResponse> {
Expand Down
16 changes: 14 additions & 2 deletions crates/router/src/core/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use crate::{
pub async fn refund_create_core(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id: Option<String>,
key_store: domain::MerchantKeyStore,
req: refunds::RefundRequest,
) -> RouterResponse<refunds::RefundResponse> {
Expand Down Expand Up @@ -373,17 +374,24 @@ where
pub async fn refund_response_wrapper<'a, F, Fut, T, Req>(
state: SessionState,
merchant_account: domain::MerchantAccount,
profile_id: Option<String>,
key_store: domain::MerchantKeyStore,
request: Req,
f: F,
) -> RouterResponse<refunds::RefundResponse>
where
F: Fn(SessionState, domain::MerchantAccount, domain::MerchantKeyStore, Req) -> Fut,
F: Fn(
SessionState,
domain::MerchantAccount,
Option<String>,
domain::MerchantKeyStore,
Req,
) -> Fut,
Fut: futures::Future<Output = RouterResult<T>>,
T: ForeignInto<refunds::RefundResponse>,
{
Ok(services::ApplicationResponse::Json(
f(state, merchant_account, key_store, request)
f(state, merchant_account, profile_id, key_store, request)
.await?
.foreign_into(),
))
Expand All @@ -393,6 +401,7 @@ where
pub async fn refund_retrieve_core(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id: Option<String>,
key_store: domain::MerchantKeyStore,
request: refunds::RefundsRetrieveRequest,
) -> RouterResult<storage::Refund> {
Expand Down Expand Up @@ -856,6 +865,7 @@ pub async fn validate_and_create_refund(
pub async fn refund_list(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id_list: Option<Vec<String>>,
req: api_models::refunds::RefundListRequest,
) -> RouterResponse<api_models::refunds::RefundListResponse> {
let db = state.store;
Expand Down Expand Up @@ -977,6 +987,7 @@ pub async fn refund_manual_update(
pub async fn get_filters_for_refunds(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id_list: Option<Vec<String>>,
) -> RouterResponse<api_models::refunds::RefundListFilters> {
let merchant_connector_accounts = if let services::ApplicationResponse::Json(data) =
super::admin::list_payment_connectors(state, merchant_account.get_id().to_owned()).await?
Expand Down Expand Up @@ -1157,6 +1168,7 @@ pub async fn sync_refund_with_gateway_workflow(
let response = Box::pin(refund_retrieve_core(
state.clone(),
merchant_account,
None,
key_store,
refunds::RefundsRetrieveRequest {
refund_id: refund_core.refund_internal_reference_id,
Expand Down
6 changes: 6 additions & 0 deletions crates/router/src/core/webhooks/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ async fn payments_incoming_webhook_flow(
state.clone(),
req_state,
merchant_account.clone(),
None,
key_store.clone(),
payments::operations::PaymentStatus,
api::PaymentsRetrieveRequest {
Expand Down Expand Up @@ -824,6 +825,7 @@ async fn refunds_incoming_webhook_flow(
Box::pin(refunds::refund_retrieve_core(
state.clone(),
merchant_account.clone(),
None,
key_store.clone(),
api_models::refunds::RefundsRetrieveRequest {
refund_id: refund_id.to_owned(),
Expand Down Expand Up @@ -1075,6 +1077,7 @@ async fn external_authentication_incoming_webhook_flow(
state.clone(),
req_state,
merchant_account.clone(),
None,
key_store.clone(),
payments::PaymentConfirm,
payment_confirm_req,
Expand Down Expand Up @@ -1268,6 +1271,7 @@ async fn frm_incoming_webhook_flow(
state.clone(),
req_state,
merchant_account.clone(),
None,
key_store.clone(),
payments::PaymentApprove,
api::PaymentsCaptureRequest {
Expand All @@ -1293,6 +1297,7 @@ async fn frm_incoming_webhook_flow(
state.clone(),
req_state,
merchant_account.clone(),
None,
key_store.clone(),
payments::PaymentReject,
api::PaymentsCancelRequest {
Expand Down Expand Up @@ -1459,6 +1464,7 @@ async fn bank_transfer_webhook_flow(
state.clone(),
req_state,
merchant_account.to_owned(),
None,
key_store.clone(),
payments::PaymentConfirm,
request,
Expand Down
Loading

0 comments on commit fb32b61

Please sign in to comment.