refactor(merchant_id): create domain type for merchant_id (#5408)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-07-24 19:18:25 +05:30
committed by GitHub
parent e18ea7a7ba
commit 7068fbfbe2
406 changed files with 3168 additions and 2633 deletions

View File

@ -210,7 +210,7 @@ pub async fn find_payment_intent_from_payment_id_type(
.find_payment_intent_by_payment_id_merchant_id(
&key_manager_state,
&payment_id,
&merchant_account.merchant_id,
merchant_account.get_id(),
key_store,
merchant_account.storage_scheme,
)
@ -219,7 +219,7 @@ pub async fn find_payment_intent_from_payment_id_type(
payments::PaymentIdType::ConnectorTransactionId(connector_transaction_id) => {
let attempt = db
.find_payment_attempt_by_merchant_id_connector_txn_id(
&merchant_account.merchant_id,
merchant_account.get_id(),
&connector_transaction_id,
merchant_account.storage_scheme,
)
@ -228,7 +228,7 @@ pub async fn find_payment_intent_from_payment_id_type(
db.find_payment_intent_by_payment_id_merchant_id(
&key_manager_state,
&attempt.payment_id,
&merchant_account.merchant_id,
merchant_account.get_id(),
key_store,
merchant_account.storage_scheme,
)
@ -239,7 +239,7 @@ pub async fn find_payment_intent_from_payment_id_type(
let attempt = db
.find_payment_attempt_by_attempt_id_merchant_id(
&attempt_id,
&merchant_account.merchant_id,
merchant_account.get_id(),
merchant_account.storage_scheme,
)
.await
@ -247,7 +247,7 @@ pub async fn find_payment_intent_from_payment_id_type(
db.find_payment_intent_by_payment_id_merchant_id(
&key_manager_state,
&attempt.payment_id,
&merchant_account.merchant_id,
merchant_account.get_id(),
key_store,
merchant_account.storage_scheme,
)
@ -271,7 +271,7 @@ pub async fn find_payment_intent_from_refund_id_type(
let refund = match refund_id_type {
webhooks::RefundIdType::RefundId(id) => db
.find_refund_by_merchant_id_refund_id(
&merchant_account.merchant_id,
merchant_account.get_id(),
&id,
merchant_account.storage_scheme,
)
@ -279,7 +279,7 @@ pub async fn find_payment_intent_from_refund_id_type(
.to_not_found_response(errors::ApiErrorResponse::RefundNotFound)?,
webhooks::RefundIdType::ConnectorRefundId(id) => db
.find_refund_by_merchant_id_connector_refund_id_connector(
&merchant_account.merchant_id,
merchant_account.get_id(),
&id,
connector_name,
merchant_account.storage_scheme,
@ -290,7 +290,7 @@ pub async fn find_payment_intent_from_refund_id_type(
let attempt = db
.find_payment_attempt_by_attempt_id_merchant_id(
&refund.attempt_id,
&merchant_account.merchant_id,
merchant_account.get_id(),
merchant_account.storage_scheme,
)
.await
@ -298,7 +298,7 @@ pub async fn find_payment_intent_from_refund_id_type(
db.find_payment_intent_by_payment_id_merchant_id(
&state.into(),
&attempt.payment_id,
&merchant_account.merchant_id,
merchant_account.get_id(),
key_store,
merchant_account.storage_scheme,
)
@ -316,7 +316,7 @@ pub async fn find_payment_intent_from_mandate_id_type(
let mandate = match mandate_id_type {
webhooks::MandateIdType::MandateId(mandate_id) => db
.find_mandate_by_merchant_id_mandate_id(
&merchant_account.merchant_id,
merchant_account.get_id(),
mandate_id.as_str(),
merchant_account.storage_scheme,
)
@ -324,7 +324,7 @@ pub async fn find_payment_intent_from_mandate_id_type(
.to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?,
webhooks::MandateIdType::ConnectorMandateId(connector_mandate_id) => db
.find_mandate_by_merchant_id_connector_mandate_id(
&merchant_account.merchant_id,
merchant_account.get_id(),
connector_mandate_id.as_str(),
merchant_account.storage_scheme,
)
@ -337,7 +337,7 @@ pub async fn find_payment_intent_from_mandate_id_type(
.original_payment_id
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("original_payment_id not present in mandate record")?,
&merchant_account.merchant_id,
merchant_account.get_id(),
key_store,
merchant_account.storage_scheme,
)
@ -355,14 +355,14 @@ pub async fn find_mca_from_authentication_id_type(
let authentication = match authentication_id_type {
webhooks::AuthenticationIdType::AuthenticationId(authentication_id) => db
.find_authentication_by_merchant_id_authentication_id(
merchant_account.merchant_id.clone(),
merchant_account.get_id(),
authentication_id,
)
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?,
webhooks::AuthenticationIdType::ConnectorAuthenticationId(connector_authentication_id) => {
db.find_authentication_by_merchant_id_connector_authentication_id(
merchant_account.merchant_id.clone(),
merchant_account.get_id().clone(),
connector_authentication_id,
)
.await
@ -371,7 +371,7 @@ pub async fn find_mca_from_authentication_id_type(
};
db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
&state.into(),
&merchant_account.merchant_id,
merchant_account.get_id(),
&authentication.merchant_connector_id,
key_store,
)
@ -392,7 +392,7 @@ pub async fn get_mca_from_payment_intent(
let payment_attempt = db
.find_payment_attempt_by_attempt_id_merchant_id(
&payment_intent.active_attempt.get_id(),
&merchant_account.merchant_id,
merchant_account.get_id(),
merchant_account.storage_scheme,
)
.await
@ -402,7 +402,7 @@ pub async fn get_mca_from_payment_intent(
Some(merchant_connector_id) => db
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
key_manager_state,
&merchant_account.merchant_id,
merchant_account.get_id(),
&merchant_connector_id,
key_store,
)
@ -454,7 +454,7 @@ pub async fn get_mca_from_payout_attempt(
let payout = match payout_id_type {
webhooks::PayoutIdType::PayoutAttemptId(payout_attempt_id) => db
.find_payout_attempt_by_merchant_id_payout_attempt_id(
&merchant_account.merchant_id,
merchant_account.get_id(),
&payout_attempt_id,
merchant_account.storage_scheme,
)
@ -462,7 +462,7 @@ pub async fn get_mca_from_payout_attempt(
.to_not_found_response(errors::ApiErrorResponse::PayoutNotFound)?,
webhooks::PayoutIdType::ConnectorPayoutId(connector_payout_id) => db
.find_payout_attempt_by_merchant_id_connector_payout_id(
&merchant_account.merchant_id,
merchant_account.get_id(),
&connector_payout_id,
merchant_account.storage_scheme,
)
@ -474,7 +474,7 @@ pub async fn get_mca_from_payout_attempt(
Some(merchant_connector_id) => db
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
key_manager_state,
&merchant_account.merchant_id,
merchant_account.get_id(),
&merchant_connector_id,
key_store,
)
@ -677,14 +677,14 @@ pub trait CustomerAddress {
address_details: payments::AddressDetails,
key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme,
merchant_id: String,
merchant_id: id_type::MerchantId,
) -> CustomResult<storage::AddressUpdate, common_utils::errors::CryptoError>;
async fn get_domain_address(
&self,
state: &SessionState,
address_details: payments::AddressDetails,
merchant_id: &str,
merchant_id: &id_type::MerchantId,
customer_id: &id_type::CustomerId,
key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme,
@ -700,7 +700,7 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
address_details: payments::AddressDetails,
key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme,
merchant_id: String,
merchant_id: id_type::MerchantId,
) -> CustomResult<storage::AddressUpdate, common_utils::errors::CryptoError> {
let encrypted_data = batch_encrypt(
&state.into(),
@ -736,7 +736,7 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
&self,
state: &SessionState,
address_details: payments::AddressDetails,
merchant_id: &str,
merchant_id: &id_type::MerchantId,
customer_id: &id_type::CustomerId,
key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme,
@ -748,7 +748,7 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
phone_number: self.phone.clone(),
email: self.email.clone(),
}),
Identifier::Merchant(merchant_id.to_string()),
Identifier::Merchant(merchant_id.to_owned()),
key,
)
.await?;
@ -767,7 +767,7 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
last_name: encryptable_address.last_name,
phone_number: encryptable_address.phone_number,
country_code: self.phone_country_code.clone(),
merchant_id: merchant_id.to_string(),
merchant_id: merchant_id.to_owned(),
address_id: generate_id(consts::ID_LENGTH, "add"),
created_at: common_utils::date_time::now(),
modified_at: common_utils::date_time::now(),
@ -785,7 +785,7 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
pub fn add_apple_pay_flow_metrics(
apple_pay_flow: &Option<domain::ApplePayFlow>,
connector: Option<String>,
merchant_id: String,
merchant_id: id_type::MerchantId,
) {
if let Some(flow) = apple_pay_flow {
match flow {
@ -797,7 +797,7 @@ pub fn add_apple_pay_flow_metrics(
"connector",
connector.to_owned().unwrap_or("null".to_string()),
),
("merchant_id", merchant_id.to_owned()),
("merchant_id", merchant_id.get_string_repr().to_owned()),
]),
),
domain::ApplePayFlow::Manual => metrics::APPLE_PAY_MANUAL_FLOW.add(
@ -808,7 +808,7 @@ pub fn add_apple_pay_flow_metrics(
"connector",
connector.to_owned().unwrap_or("null".to_string()),
),
("merchant_id", merchant_id.to_owned()),
("merchant_id", merchant_id.get_string_repr().to_owned()),
]),
),
}
@ -819,7 +819,7 @@ pub fn add_apple_pay_payment_status_metrics(
payment_attempt_status: enums::AttemptStatus,
apple_pay_flow: Option<domain::ApplePayFlow>,
connector: Option<String>,
merchant_id: String,
merchant_id: id_type::MerchantId,
) {
if payment_attempt_status == enums::AttemptStatus::Charged {
if let Some(flow) = apple_pay_flow {
@ -833,7 +833,7 @@ pub fn add_apple_pay_payment_status_metrics(
"connector",
connector.to_owned().unwrap_or("null".to_string()),
),
("merchant_id", merchant_id.to_owned()),
("merchant_id", merchant_id.get_string_repr().to_owned()),
]),
)
}
@ -846,7 +846,7 @@ pub fn add_apple_pay_payment_status_metrics(
"connector",
connector.to_owned().unwrap_or("null".to_string()),
),
("merchant_id", merchant_id.to_owned()),
("merchant_id", merchant_id.get_string_repr().to_owned()),
]),
),
}
@ -863,7 +863,7 @@ pub fn add_apple_pay_payment_status_metrics(
"connector",
connector.to_owned().unwrap_or("null".to_string()),
),
("merchant_id", merchant_id.to_owned()),
("merchant_id", merchant_id.get_string_repr().to_owned()),
]),
)
}
@ -875,7 +875,7 @@ pub fn add_apple_pay_payment_status_metrics(
"connector",
connector.to_owned().unwrap_or("null".to_string()),
),
("merchant_id", merchant_id.to_owned()),
("merchant_id", merchant_id.get_string_repr().to_owned()),
]),
),
}
@ -998,10 +998,6 @@ pub async fn flatten_join_error<T>(handle: Handle<T>) -> RouterResult<T> {
}
}
pub(crate) fn get_merchant_fingerprint_secret_key(merchant_id: impl AsRef<str>) -> String {
format!("fingerprint_secret_{}", merchant_id.as_ref())
}
#[cfg(test)]
mod tests {
use crate::utils;