mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
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:
@ -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
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -483,7 +483,7 @@ impl MerchantAccountInterface for MockDb {
|
||||
let accounts = self.merchant_accounts.lock().await;
|
||||
let account: Option<domain::MerchantAccount> = accounts
|
||||
.iter()
|
||||
.find(|account| account.merchant_id == *merchant_id)
|
||||
.find(|account| account.get_id() == merchant_id)
|
||||
.cloned()
|
||||
.async_map(|a| async {
|
||||
a.convert(
|
||||
@ -608,7 +608,7 @@ async fn publish_and_redact_all_merchant_account_cache(
|
||||
) -> CustomResult<(), errors::StorageError> {
|
||||
let merchant_ids = merchant_accounts
|
||||
.iter()
|
||||
.map(|m| m.merchant_id.get_string_repr().to_string());
|
||||
.map(|merchant_account| merchant_account.get_id().get_string_repr().to_string());
|
||||
let publishable_keys = merchant_accounts
|
||||
.iter()
|
||||
.filter_map(|m| m.publishable_key.clone());
|
||||
|
||||
@ -20,8 +20,12 @@ use tokio::sync::oneshot;
|
||||
use self::settings::Tenant;
|
||||
#[cfg(feature = "olap")]
|
||||
use super::blocklist;
|
||||
#[cfg(any(feature = "olap", feature = "oltp"))]
|
||||
use super::currency;
|
||||
#[cfg(feature = "dummy_connector")]
|
||||
use super::dummy_connector::*;
|
||||
#[cfg(all(any(feature = "olap", feature = "oltp"), not(feature = "customer_v2")))]
|
||||
use super::payment_methods::*;
|
||||
#[cfg(feature = "payouts")]
|
||||
use super::payout_link::*;
|
||||
#[cfg(feature = "payouts")]
|
||||
@ -46,8 +50,6 @@ use super::{
|
||||
use super::{cache::*, health::*};
|
||||
#[cfg(any(feature = "olap", feature = "oltp"))]
|
||||
use super::{configs::*, customers::*, mandates::*, payments::*, refunds::*};
|
||||
#[cfg(any(feature = "olap", feature = "oltp"))]
|
||||
use super::{currency, payment_methods::*};
|
||||
#[cfg(feature = "oltp")]
|
||||
use super::{ephemeral_key::*, webhooks::*};
|
||||
#[cfg(feature = "olap")]
|
||||
@ -58,8 +60,6 @@ use crate::analytics::AnalyticsProvider;
|
||||
use crate::routes::fraud_check as frm_routes;
|
||||
#[cfg(all(feature = "recon", feature = "olap"))]
|
||||
use crate::routes::recon as recon_routes;
|
||||
#[cfg(all(feature = "olap", not(feature = "v2")))]
|
||||
use crate::routes::verify_connector::payment_connector_verify;
|
||||
pub use crate::{
|
||||
configs::settings,
|
||||
core::routing,
|
||||
@ -1116,7 +1116,7 @@ impl MerchantConnectorAccount {
|
||||
route = route
|
||||
.service(
|
||||
web::resource("/connectors/verify")
|
||||
.route(web::post().to(payment_connector_verify)),
|
||||
.route(web::post().to(super::verify_connector::payment_connector_verify)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/{merchant_id}/connectors")
|
||||
|
||||
@ -91,13 +91,15 @@ impl ForeignTryFrom<domain::MerchantAccount> for MerchantAccountResponse {
|
||||
fn foreign_try_from(item: domain::MerchantAccount) -> Result<Self, Self::Error> {
|
||||
use common_utils::ext_traits::OptionExt;
|
||||
|
||||
let id = item.get_id().to_owned();
|
||||
|
||||
let merchant_name = item
|
||||
.merchant_name
|
||||
.get_required_value("merchant_name")?
|
||||
.into_inner();
|
||||
|
||||
Ok(Self {
|
||||
id: item.merchant_id,
|
||||
id,
|
||||
merchant_name,
|
||||
merchant_details: item.merchant_details,
|
||||
publishable_key: item.publishable_key,
|
||||
|
||||
@ -22,17 +22,14 @@ use api_models::{
|
||||
};
|
||||
use base64::Engine;
|
||||
use common_utils::types::keymanager::KeyManagerState;
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
use common_utils::types::keymanager::{Identifier, ToEncryptable};
|
||||
pub use common_utils::{
|
||||
crypto,
|
||||
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
|
||||
fp_utils::when,
|
||||
validation::validate_email,
|
||||
};
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
use common_utils::{
|
||||
id_type,
|
||||
types::keymanager::{Identifier, ToEncryptable},
|
||||
};
|
||||
use error_stack::ResultExt;
|
||||
use hyperswitch_domain_models::payments::PaymentIntent;
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
@ -677,15 +674,15 @@ pub trait CustomerAddress {
|
||||
address_details: payments::AddressDetails,
|
||||
key: &[u8],
|
||||
storage_scheme: storage::enums::MerchantStorageScheme,
|
||||
merchant_id: id_type::MerchantId,
|
||||
merchant_id: common_utils::id_type::MerchantId,
|
||||
) -> CustomResult<storage::AddressUpdate, common_utils::errors::CryptoError>;
|
||||
|
||||
async fn get_domain_address(
|
||||
&self,
|
||||
state: &SessionState,
|
||||
address_details: payments::AddressDetails,
|
||||
merchant_id: &id_type::MerchantId,
|
||||
customer_id: &id_type::CustomerId,
|
||||
merchant_id: &common_utils::id_type::MerchantId,
|
||||
customer_id: &common_utils::id_type::CustomerId,
|
||||
key: &[u8],
|
||||
storage_scheme: storage::enums::MerchantStorageScheme,
|
||||
) -> CustomResult<domain::CustomerAddress, common_utils::errors::CryptoError>;
|
||||
@ -700,7 +697,7 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
|
||||
address_details: payments::AddressDetails,
|
||||
key: &[u8],
|
||||
storage_scheme: storage::enums::MerchantStorageScheme,
|
||||
merchant_id: id_type::MerchantId,
|
||||
merchant_id: common_utils::id_type::MerchantId,
|
||||
) -> CustomResult<storage::AddressUpdate, common_utils::errors::CryptoError> {
|
||||
let encrypted_data = batch_encrypt(
|
||||
&state.into(),
|
||||
@ -736,8 +733,8 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
|
||||
&self,
|
||||
state: &SessionState,
|
||||
address_details: payments::AddressDetails,
|
||||
merchant_id: &id_type::MerchantId,
|
||||
customer_id: &id_type::CustomerId,
|
||||
merchant_id: &common_utils::id_type::MerchantId,
|
||||
customer_id: &common_utils::id_type::CustomerId,
|
||||
key: &[u8],
|
||||
storage_scheme: storage::enums::MerchantStorageScheme,
|
||||
) -> CustomResult<domain::CustomerAddress, common_utils::errors::CryptoError> {
|
||||
@ -784,7 +781,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: id_type::MerchantId,
|
||||
merchant_id: common_utils::id_type::MerchantId,
|
||||
) {
|
||||
if let Some(flow) = apple_pay_flow {
|
||||
match flow {
|
||||
@ -818,7 +815,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: id_type::MerchantId,
|
||||
merchant_id: common_utils::id_type::MerchantId,
|
||||
) {
|
||||
if payment_attempt_status == enums::AttemptStatus::Charged {
|
||||
if let Some(flow) = apple_pay_flow {
|
||||
|
||||
Reference in New Issue
Block a user