mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 21:37:41 +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:
@ -80,9 +80,8 @@ pub async fn save_payment_method<FData>(
|
||||
connector_name: String,
|
||||
save_payment_method_data: SavePaymentMethodData<FData>,
|
||||
customer_id: Option<id_type::CustomerId>,
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
merchant_context: &domain::MerchantContext,
|
||||
payment_method_type: Option<storage_enums::PaymentMethodType>,
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
billing_name: Option<Secret<String>>,
|
||||
payment_method_billing_address: Option<&hyperswitch_domain_models::address::Address>,
|
||||
business_profile: &domain::Profile,
|
||||
@ -197,7 +196,7 @@ where
|
||||
)
|
||||
.await?;
|
||||
let customer_id = customer_id.to_owned().get_required_value("customer_id")?;
|
||||
let merchant_id = merchant_account.get_id();
|
||||
let merchant_id = merchant_context.get_merchant_account().get_id();
|
||||
let is_network_tokenization_enabled =
|
||||
business_profile.is_network_tokenization_enabled;
|
||||
let (
|
||||
@ -205,7 +204,7 @@ where
|
||||
network_token_resp,
|
||||
) = if !state.conf.locker.locker_enabled {
|
||||
let (res, dc) = skip_saving_card_in_locker(
|
||||
merchant_account,
|
||||
merchant_context,
|
||||
payment_method_create_request.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
@ -216,7 +215,7 @@ where
|
||||
));
|
||||
let (res, dc) = Box::pin(save_in_locker(
|
||||
state,
|
||||
merchant_account,
|
||||
merchant_context,
|
||||
payment_method_create_request.to_owned(),
|
||||
))
|
||||
.await?;
|
||||
@ -231,7 +230,7 @@ where
|
||||
network_token_requestor_ref_id,
|
||||
) = Box::pin(save_network_token_in_locker(
|
||||
state,
|
||||
merchant_account,
|
||||
merchant_context,
|
||||
card,
|
||||
payment_method_create_request.clone(),
|
||||
))
|
||||
@ -278,7 +277,13 @@ where
|
||||
let key_manager_state = state.into();
|
||||
let pm_data_encrypted: Option<Encryptable<Secret<serde_json::Value>>> =
|
||||
optional_pm_details
|
||||
.async_map(|pm| create_encrypted_data(&key_manager_state, key_store, pm))
|
||||
.async_map(|pm| {
|
||||
create_encrypted_data(
|
||||
&key_manager_state,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
pm,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.transpose()
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
@ -294,7 +299,11 @@ where
|
||||
|
||||
pm_token_details
|
||||
.async_map(|pm_card| {
|
||||
create_encrypted_data(&key_manager_state, key_store, pm_card)
|
||||
create_encrypted_data(
|
||||
&key_manager_state,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
pm_card,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.transpose()
|
||||
@ -308,7 +317,11 @@ where
|
||||
Encryptable<Secret<serde_json::Value>>,
|
||||
> = payment_method_billing_address
|
||||
.async_map(|address| {
|
||||
create_encrypted_data(&key_manager_state, key_store, address.clone())
|
||||
create_encrypted_data(
|
||||
&key_manager_state,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
address.clone(),
|
||||
)
|
||||
})
|
||||
.await
|
||||
.transpose()
|
||||
@ -325,9 +338,9 @@ where
|
||||
let existing_pm_by_pmid = db
|
||||
.find_payment_method(
|
||||
&(state.into()),
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
&payment_method_id,
|
||||
merchant_account.storage_scheme,
|
||||
merchant_context.get_merchant_account().storage_scheme,
|
||||
)
|
||||
.await;
|
||||
|
||||
@ -337,9 +350,11 @@ where
|
||||
let existing_pm_by_locker_id = db
|
||||
.find_payment_method_by_locker_id(
|
||||
&(state.into()),
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
&payment_method_id,
|
||||
merchant_account.storage_scheme,
|
||||
merchant_context
|
||||
.get_merchant_account()
|
||||
.storage_scheme,
|
||||
)
|
||||
.await;
|
||||
|
||||
@ -371,11 +386,11 @@ where
|
||||
)?;
|
||||
payment_methods::cards::update_payment_method_metadata_and_last_used(
|
||||
state,
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
db,
|
||||
pm.clone(),
|
||||
pm_metadata,
|
||||
merchant_account.storage_scheme,
|
||||
merchant_context.get_merchant_account().storage_scheme,
|
||||
)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
@ -395,11 +410,11 @@ where
|
||||
pm_metadata,
|
||||
customer_acceptance,
|
||||
pm_data_encrypted,
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
None,
|
||||
pm_status,
|
||||
network_transaction_id,
|
||||
merchant_account.storage_scheme,
|
||||
merchant_context.get_merchant_account().storage_scheme,
|
||||
encrypted_payment_method_billing_address,
|
||||
resp.card.and_then(|card| {
|
||||
card.card_network
|
||||
@ -426,9 +441,9 @@ where
|
||||
let existing_pm_by_pmid = db
|
||||
.find_payment_method(
|
||||
&(state.into()),
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
&payment_method_id,
|
||||
merchant_account.storage_scheme,
|
||||
merchant_context.get_merchant_account().storage_scheme,
|
||||
)
|
||||
.await;
|
||||
|
||||
@ -438,9 +453,11 @@ where
|
||||
let existing_pm_by_locker_id = db
|
||||
.find_payment_method_by_locker_id(
|
||||
&(state.into()),
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
&payment_method_id,
|
||||
merchant_account.storage_scheme,
|
||||
merchant_context
|
||||
.get_merchant_account()
|
||||
.storage_scheme,
|
||||
)
|
||||
.await;
|
||||
|
||||
@ -489,11 +506,11 @@ where
|
||||
)?;
|
||||
payment_methods::cards::update_payment_method_connector_mandate_details(
|
||||
state,
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
db,
|
||||
pm.clone(),
|
||||
connector_mandate_details,
|
||||
merchant_account.storage_scheme,
|
||||
merchant_context.get_merchant_account().storage_scheme,
|
||||
)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
@ -513,11 +530,13 @@ where
|
||||
resp.metadata.clone().map(|val| val.expose()),
|
||||
customer_acceptance,
|
||||
pm_data_encrypted,
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
None,
|
||||
pm_status,
|
||||
network_transaction_id,
|
||||
merchant_account.storage_scheme,
|
||||
merchant_context
|
||||
.get_merchant_account()
|
||||
.storage_scheme,
|
||||
encrypted_payment_method_billing_address,
|
||||
resp.card.and_then(|card| {
|
||||
card.card_network.map(|card_network| {
|
||||
@ -557,7 +576,7 @@ where
|
||||
payment_method_create_request,
|
||||
&card,
|
||||
&customer_id,
|
||||
merchant_account,
|
||||
merchant_context,
|
||||
api::enums::LockerChoice::HyperswitchCardVault,
|
||||
Some(
|
||||
existing_pm
|
||||
@ -572,7 +591,7 @@ where
|
||||
logger::error!(vault_err=?err);
|
||||
db.delete_payment_method_by_merchant_id_payment_method_id(
|
||||
&(state.into()),
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
merchant_id,
|
||||
&resp.payment_method_id,
|
||||
)
|
||||
@ -630,7 +649,11 @@ where
|
||||
Encryptable<Secret<serde_json::Value>>,
|
||||
> = updated_pmd
|
||||
.async_map(|pmd| {
|
||||
create_encrypted_data(&key_manager_state, key_store, pmd)
|
||||
create_encrypted_data(
|
||||
&key_manager_state,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
pmd,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.transpose()
|
||||
@ -639,11 +662,11 @@ where
|
||||
|
||||
payment_methods::cards::update_payment_method_and_last_used(
|
||||
state,
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
db,
|
||||
existing_pm,
|
||||
pm_data_encrypted.map(Into::into),
|
||||
merchant_account.storage_scheme,
|
||||
merchant_context.get_merchant_account().storage_scheme,
|
||||
card_scheme,
|
||||
)
|
||||
.await
|
||||
@ -664,7 +687,7 @@ where
|
||||
.store
|
||||
.find_payment_method_by_customer_id_merchant_id_list(
|
||||
&(state.into()),
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
&customer_id,
|
||||
merchant_id,
|
||||
None,
|
||||
@ -700,8 +723,8 @@ where
|
||||
payment_methods::cards::update_last_used_at(
|
||||
&customer_saved_pm,
|
||||
state,
|
||||
merchant_account.storage_scheme,
|
||||
key_store,
|
||||
merchant_context.get_merchant_account().storage_scheme,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
@ -732,11 +755,11 @@ where
|
||||
pm_metadata,
|
||||
customer_acceptance,
|
||||
pm_data_encrypted,
|
||||
key_store,
|
||||
merchant_context.get_merchant_key_store(),
|
||||
None,
|
||||
pm_status,
|
||||
network_transaction_id,
|
||||
merchant_account.storage_scheme,
|
||||
merchant_context.get_merchant_account().storage_scheme,
|
||||
encrypted_payment_method_billing_address,
|
||||
resp.card.and_then(|card| {
|
||||
card.card_network
|
||||
@ -802,9 +825,8 @@ pub async fn save_payment_method<FData>(
|
||||
_connector_name: String,
|
||||
_save_payment_method_data: SavePaymentMethodData<FData>,
|
||||
_customer_id: Option<id_type::CustomerId>,
|
||||
_merchant_account: &domain::MerchantAccount,
|
||||
_merchant_context: &domain::MerchantContext,
|
||||
_payment_method_type: Option<storage_enums::PaymentMethodType>,
|
||||
_key_store: &domain::MerchantKeyStore,
|
||||
_billing_name: Option<Secret<String>>,
|
||||
_payment_method_billing_address: Option<&api::Address>,
|
||||
_business_profile: &domain::Profile,
|
||||
@ -821,13 +843,13 @@ where
|
||||
not(feature = "payment_methods_v2")
|
||||
))]
|
||||
async fn skip_saving_card_in_locker(
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
merchant_context: &domain::MerchantContext,
|
||||
payment_method_request: api::PaymentMethodCreate,
|
||||
) -> RouterResult<(
|
||||
api_models::payment_methods::PaymentMethodResponse,
|
||||
Option<payment_methods::transformers::DataDuplicationCheck>,
|
||||
)> {
|
||||
let merchant_id = merchant_account.get_id();
|
||||
let merchant_id = merchant_context.get_merchant_account().get_id();
|
||||
let customer_id = payment_method_request
|
||||
.clone()
|
||||
.customer_id
|
||||
@ -910,7 +932,7 @@ async fn skip_saving_card_in_locker(
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
async fn skip_saving_card_in_locker(
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
merchant_context: &domain::MerchantContext,
|
||||
payment_method_request: api::PaymentMethodCreate,
|
||||
) -> RouterResult<(
|
||||
api_models::payment_methods::PaymentMethodResponse,
|
||||
@ -925,14 +947,14 @@ async fn skip_saving_card_in_locker(
|
||||
))]
|
||||
pub async fn save_in_locker(
|
||||
state: &SessionState,
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
merchant_context: &domain::MerchantContext,
|
||||
payment_method_request: api::PaymentMethodCreate,
|
||||
) -> RouterResult<(
|
||||
api_models::payment_methods::PaymentMethodResponse,
|
||||
Option<payment_methods::transformers::DataDuplicationCheck>,
|
||||
)> {
|
||||
payment_method_request.validate()?;
|
||||
let merchant_id = merchant_account.get_id();
|
||||
let merchant_id = merchant_context.get_merchant_account().get_id();
|
||||
let customer_id = payment_method_request
|
||||
.customer_id
|
||||
.clone()
|
||||
@ -943,7 +965,7 @@ pub async fn save_in_locker(
|
||||
payment_method_request,
|
||||
&card,
|
||||
&customer_id,
|
||||
merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
))
|
||||
.await
|
||||
@ -976,7 +998,7 @@ pub async fn save_in_locker(
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
pub async fn save_in_locker(
|
||||
_state: &SessionState,
|
||||
_merchant_account: &domain::MerchantAccount,
|
||||
_merchant_context: &domain::MerchantContext,
|
||||
_payment_method_request: api::PaymentMethodCreate,
|
||||
) -> RouterResult<(
|
||||
api_models::payment_methods::PaymentMethodResponse,
|
||||
@ -988,7 +1010,7 @@ pub async fn save_in_locker(
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
pub async fn save_network_token_in_locker(
|
||||
_state: &SessionState,
|
||||
_merchant_account: &domain::MerchantAccount,
|
||||
_merchant_context: &domain::MerchantContext,
|
||||
_card_data: &domain::Card,
|
||||
_payment_method_request: api::PaymentMethodCreate,
|
||||
) -> RouterResult<(
|
||||
@ -1005,7 +1027,7 @@ pub async fn save_network_token_in_locker(
|
||||
))]
|
||||
pub async fn save_network_token_in_locker(
|
||||
state: &SessionState,
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
merchant_context: &domain::MerchantContext,
|
||||
card_data: &domain::Card,
|
||||
payment_method_request: api::PaymentMethodCreate,
|
||||
) -> RouterResult<(
|
||||
@ -1056,7 +1078,7 @@ pub async fn save_network_token_in_locker(
|
||||
payment_method_request,
|
||||
&network_token_data,
|
||||
&customer_id,
|
||||
merchant_account,
|
||||
merchant_context,
|
||||
None,
|
||||
))
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user