refactor(merchant_account_v2): recreate id for merchant_account v2 (#5439)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-07-26 12:39:34 +05:30
committed by GitHub
parent 2d235a64e9
commit 93976db30a
18 changed files with 438 additions and 119 deletions

View File

@ -412,7 +412,10 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
#[cfg(feature = "olap")]
enum CreateOrValidateOrganization {
/// Creates a new organization
#[cfg(any(feature = "v1", feature = "v2"))]
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2")
))]
Create,
/// Validates if this organization exists in the records
Validate {
@ -451,7 +454,10 @@ impl CreateOrValidateOrganization {
db: &dyn StorageInterface,
) -> RouterResult<diesel_models::organization::Organization> {
match self {
#[cfg(any(feature = "v1", feature = "v2"))]
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2")
))]
Self::Create => {
let new_organization = api_models::organization::OrganizationNew::new(None);
let db_organization = ForeignFrom::foreign_from(new_organization);
@ -637,17 +643,14 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
.await?;
let key = key_store.key.into_inner();
let merchant_id = self
.get_merchant_reference_id()
.get_string_repr()
.to_owned();
let id = self.get_merchant_reference_id().to_owned();
let key_manager_state = state.into();
let identifier = km_types::Identifier::Merchant(merchant_id.clone());
let identifier = km_types::Identifier::Merchant(id.clone());
async {
Ok::<_, error_stack::Report<common_utils::errors::CryptoError>>(
domain::MerchantAccount {
merchant_id,
domain::MerchantAccount::from(domain::MerchantAccountSetter {
id,
merchant_name: Some(
domain_types::encrypt(
&key_manager_state,
@ -695,7 +698,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
recon_status: diesel_models::enums::ReconStatus::NotRequested,
payment_link_config: None,
pm_collect_link_config: None,
},
}),
)
}
.await

View File

@ -206,7 +206,7 @@ impl CustomerCreateBridge for customers::CustomerRequest {
) -> errors::CustomResult<domain::Customer, errors::CustomersErrorResponse> {
let _default_customer_billing_address = self.get_default_customer_billing_address();
let _default_customer_shipping_address = self.get_default_customer_shipping_address();
let merchant_id = merchant_account.merchant_id.clone();
let merchant_id = merchant_account.get_id().clone();
let key = key_store.key.get_inner().peek();
let encrypted_data = types::batch_encrypt(
@ -230,14 +230,13 @@ impl CustomerCreateBridge for customers::CustomerRequest {
customer_id: merchant_reference_id
.to_owned()
.ok_or(errors::CustomersErrorResponse::InternalServerError)?, // doing this to make it compile, will remove once we start moving to domain models
merchant_id: merchant_id.to_string(),
merchant_id,
name: encryptable_customer.name,
email: encryptable_customer.email,
phone: encryptable_customer.phone,
description: self.description.clone(),
phone_country_code: self.phone_country_code.clone(),
metadata: self.metadata.clone(),
id: None,
connector_customer: None,
address_id: None,
created_at: common_utils::date_time::now(),