mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat(merchant_context): add struct merchant_context and replace all instances of merchant_account and key_store in core (#7882)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -14,7 +14,10 @@ use crate::{
|
||||
core::{api_locking, customers, payment_methods::cards},
|
||||
routes,
|
||||
services::{api, authentication as auth},
|
||||
types::api::{customers as customer_types, payment_methods},
|
||||
types::{
|
||||
api::{customers as customer_types, payment_methods},
|
||||
domain,
|
||||
},
|
||||
};
|
||||
|
||||
#[cfg(all(
|
||||
@ -55,7 +58,10 @@ pub async fn customer_create(
|
||||
&req,
|
||||
create_cust_req,
|
||||
|state, auth: auth::AuthenticationData, req, _| {
|
||||
customers::create_customer(state, auth.merchant_account, auth.key_store, req)
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
customers::create_customer(state, merchant_context, req)
|
||||
},
|
||||
&auth::HeaderAuth(auth::ApiKeyAuth {
|
||||
is_connected_allowed: false,
|
||||
@ -96,13 +102,10 @@ pub async fn customer_retrieve(
|
||||
&req,
|
||||
customer_id,
|
||||
|state, auth: auth::AuthenticationData, customer_id, _| {
|
||||
customers::retrieve_customer(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
None,
|
||||
auth.key_store,
|
||||
customer_id,
|
||||
)
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
customers::retrieve_customer(state, merchant_context, None, customer_id)
|
||||
},
|
||||
&auth::HeaderAuth(auth::ApiKeyAuth {
|
||||
is_connected_allowed: false,
|
||||
@ -157,12 +160,10 @@ pub async fn customer_update(
|
||||
&req,
|
||||
request_internal,
|
||||
|state, auth: auth::AuthenticationData, request_internal, _| {
|
||||
customers::update_customer(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
request_internal,
|
||||
auth.key_store,
|
||||
)
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
customers::update_customer(state, merchant_context, request_internal)
|
||||
},
|
||||
&auth::HeaderAuth(auth::ApiKeyAuth {
|
||||
is_connected_allowed: false,
|
||||
@ -203,7 +204,10 @@ pub async fn customer_delete(
|
||||
&req,
|
||||
customer_id,
|
||||
|state, auth: auth::AuthenticationData, customer_id, _| {
|
||||
customers::delete_customer(state, auth.merchant_account, customer_id, auth.key_store)
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
customers::delete_customer(state, merchant_context, customer_id)
|
||||
},
|
||||
&auth::HeaderAuth(auth::ApiKeyAuth {
|
||||
is_connected_allowed: false,
|
||||
@ -245,10 +249,12 @@ pub async fn list_customer_payment_method_api(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth: auth::AuthenticationData, req, _| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
cards::do_list_customer_pm_fetch_customer_if_not_passed(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
auth.key_store,
|
||||
merchant_context,
|
||||
Some(req),
|
||||
Some(&customer_id),
|
||||
None,
|
||||
|
||||
@ -16,8 +16,10 @@ use crate::{
|
||||
};
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
use crate::{
|
||||
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
|
||||
types::api as api_types,
|
||||
core::api_locking::GetLockingInput,
|
||||
logger,
|
||||
routes::payments::get_or_generate_payment_id,
|
||||
types::{api as api_types, domain},
|
||||
};
|
||||
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
@ -72,6 +74,9 @@ pub async fn payment_intents_create(
|
||||
&req,
|
||||
create_payment_req,
|
||||
|state, auth: auth::AuthenticationData, req, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
let eligible_connectors = req.connector.clone();
|
||||
payments::payments_core::<
|
||||
api_types::Authorize,
|
||||
@ -83,16 +88,14 @@ pub async fn payment_intents_create(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentCreate,
|
||||
req,
|
||||
api::AuthFlow::Merchant,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
eligible_connectors,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&auth::HeaderAuth(auth::ApiKeyAuth {
|
||||
@ -152,6 +155,9 @@ pub async fn payment_intents_retrieve(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, payload, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
payments::payments_core::<
|
||||
api_types::PSync,
|
||||
api_types::PaymentsResponse,
|
||||
@ -162,16 +168,14 @@ pub async fn payment_intents_retrieve(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentStatus,
|
||||
payload,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&*auth_type,
|
||||
@ -237,6 +241,9 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
payments::payments_core::<
|
||||
api_types::PSync,
|
||||
payment_types::PaymentsResponse,
|
||||
@ -247,16 +254,14 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentStatus,
|
||||
req,
|
||||
api::AuthFlow::Merchant,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&*auth_type,
|
||||
@ -318,6 +323,9 @@ pub async fn payment_intents_update(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
let eligible_connectors = req.connector.clone();
|
||||
payments::payments_core::<
|
||||
api_types::Authorize,
|
||||
@ -329,16 +337,14 @@ pub async fn payment_intents_update(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentUpdate,
|
||||
req,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
eligible_connectors,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&*auth_type,
|
||||
@ -409,6 +415,9 @@ pub async fn payment_intents_confirm(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
let eligible_connectors = req.connector.clone();
|
||||
payments::payments_core::<
|
||||
api_types::Authorize,
|
||||
@ -420,16 +429,14 @@ pub async fn payment_intents_confirm(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentConfirm,
|
||||
req,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
eligible_connectors,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&*auth_type,
|
||||
@ -482,6 +489,9 @@ pub async fn payment_intents_capture(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth: auth::AuthenticationData, payload, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
payments::payments_core::<
|
||||
api_types::Capture,
|
||||
api_types::PaymentsResponse,
|
||||
@ -492,16 +502,14 @@ pub async fn payment_intents_capture(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentCapture,
|
||||
payload,
|
||||
api::AuthFlow::Merchant,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&auth::HeaderAuth(auth::ApiKeyAuth {
|
||||
@ -566,6 +574,9 @@ pub async fn payment_intents_cancel(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
payments::payments_core::<
|
||||
api_types::Void,
|
||||
api_types::PaymentsResponse,
|
||||
@ -576,16 +587,14 @@ pub async fn payment_intents_cancel(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentCancel,
|
||||
req,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&*auth_type,
|
||||
@ -621,7 +630,10 @@ pub async fn payment_intent_list(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth: auth::AuthenticationData, req, _| {
|
||||
payments::list_payments(state, auth.merchant_account, None, auth.key_store, req)
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
payments::list_payments(state, merchant_context, None, req)
|
||||
},
|
||||
&auth::HeaderAuth(auth::ApiKeyAuth {
|
||||
is_connected_allowed: false,
|
||||
|
||||
@ -7,6 +7,7 @@ use router_env::{instrument, tracing, Flow, Tag};
|
||||
use crate::{
|
||||
compatibility::{stripe::errors, wrap},
|
||||
core::{api_locking, refunds},
|
||||
db::domain,
|
||||
logger, routes,
|
||||
services::{api, authentication as auth},
|
||||
types::api::refunds as refund_types,
|
||||
@ -50,7 +51,10 @@ pub async fn refund_create(
|
||||
&req,
|
||||
create_refund_req,
|
||||
|state, auth: auth::AuthenticationData, req, _| {
|
||||
refunds::refund_create_core(state, auth.merchant_account, None, auth.key_store, req)
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
refunds::refund_create_core(state, merchant_context, None, req)
|
||||
},
|
||||
&auth::HeaderAuth(auth::ApiKeyAuth {
|
||||
is_connected_allowed: false,
|
||||
@ -97,11 +101,13 @@ pub async fn refund_retrieve_with_gateway_creds(
|
||||
&req,
|
||||
refund_request,
|
||||
|state, auth: auth::AuthenticationData, refund_request, _| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
refunds::refund_response_wrapper(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
refund_request,
|
||||
refunds::refund_retrieve_core_with_refund_id,
|
||||
)
|
||||
@ -143,11 +149,13 @@ pub async fn refund_retrieve(
|
||||
&req,
|
||||
refund_request,
|
||||
|state, auth: auth::AuthenticationData, refund_request, _| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
refunds::refund_response_wrapper(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
refund_request,
|
||||
refunds::refund_retrieve_core_with_refund_id,
|
||||
)
|
||||
@ -187,7 +195,10 @@ pub async fn refund_update(
|
||||
&req,
|
||||
create_refund_update_req,
|
||||
|state, auth: auth::AuthenticationData, req, _| {
|
||||
refunds::refund_update_core(state, auth.merchant_account, req)
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
refunds::refund_update_core(state, merchant_context, req)
|
||||
},
|
||||
&auth::HeaderAuth(auth::ApiKeyAuth {
|
||||
is_connected_allowed: false,
|
||||
|
||||
@ -17,7 +17,7 @@ use crate::{
|
||||
core::{api_locking, payments},
|
||||
routes,
|
||||
services::{api, authentication as auth},
|
||||
types::api as api_types,
|
||||
types::{api as api_types, domain},
|
||||
};
|
||||
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
@ -59,6 +59,9 @@ pub async fn setup_intents_create(
|
||||
&req,
|
||||
create_payment_req,
|
||||
|state, auth: auth::AuthenticationData, req, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
payments::payments_core::<
|
||||
api_types::SetupMandate,
|
||||
api_types::PaymentsResponse,
|
||||
@ -69,16 +72,14 @@ pub async fn setup_intents_create(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentCreate,
|
||||
req,
|
||||
api::AuthFlow::Merchant,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&auth::HeaderAuth(auth::ApiKeyAuth {
|
||||
@ -138,6 +139,9 @@ pub async fn setup_intents_retrieve(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, payload, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
payments::payments_core::<
|
||||
api_types::PSync,
|
||||
api_types::PaymentsResponse,
|
||||
@ -148,16 +152,14 @@ pub async fn setup_intents_retrieve(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentStatus,
|
||||
payload,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&*auth_type,
|
||||
@ -220,6 +222,9 @@ pub async fn setup_intents_update(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
payments::payments_core::<
|
||||
api_types::SetupMandate,
|
||||
api_types::PaymentsResponse,
|
||||
@ -230,16 +235,14 @@ pub async fn setup_intents_update(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentUpdate,
|
||||
req,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&*auth_type,
|
||||
@ -303,6 +306,9 @@ pub async fn setup_intents_confirm(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req, req_state| {
|
||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||
domain::Context(auth.merchant_account, auth.key_store),
|
||||
));
|
||||
payments::payments_core::<
|
||||
api_types::SetupMandate,
|
||||
api_types::PaymentsResponse,
|
||||
@ -313,16 +319,14 @@ pub async fn setup_intents_confirm(
|
||||
>(
|
||||
state,
|
||||
req_state,
|
||||
auth.merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
auth.key_store,
|
||||
payments::PaymentConfirm,
|
||||
req,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
hyperswitch_domain_models::payments::HeaderPayload::default(),
|
||||
auth.platform_merchant_account,
|
||||
)
|
||||
},
|
||||
&*auth_type,
|
||||
|
||||
Reference in New Issue
Block a user