refactor(business_profile): change id for business profile (#5748)

This commit is contained in:
Narayan Bhat
2024-09-02 15:25:22 +05:30
committed by GitHub
parent c03587f9c6
commit 8e5c33e2d8
27 changed files with 538 additions and 274 deletions

View File

@ -58,6 +58,7 @@ pub struct BusinessProfile {
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: Option<bool>,
pub api_version: common_enums::ApiVersion,
}
#[cfg(all(
@ -100,6 +101,7 @@ pub struct BusinessProfileNew {
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: Option<bool>,
pub api_version: common_enums::ApiVersion,
}
#[cfg(all(
@ -229,6 +231,7 @@ impl BusinessProfileUpdateInternal {
.or(source.always_collect_shipping_details_from_wallet_connector),
tax_connector_id: tax_connector_id.or(source.tax_connector_id),
is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
api_version: source.api_version,
}
}
}
@ -240,9 +243,8 @@ impl BusinessProfileUpdateInternal {
/// fields read / written will be interchanged
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
#[derive(Clone, Debug, Identifiable, Queryable, Selectable, router_derive::DebugAsDisplay)]
#[diesel(table_name = business_profile, primary_key(profile_id), check_for_backend(diesel::pg::Pg))]
#[diesel(table_name = business_profile, primary_key(id), check_for_backend(diesel::pg::Pg))]
pub struct BusinessProfile {
pub profile_id: common_utils::id_type::ProfileId,
pub merchant_id: common_utils::id_type::MerchantId,
pub profile_name: String,
pub created_at: time::PrimitiveDateTime,
@ -275,15 +277,31 @@ pub struct BusinessProfile {
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub id: common_utils::id_type::ProfileId,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: Option<bool>,
pub api_version: common_enums::ApiVersion,
}
impl BusinessProfile {
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "business_profile_v2")
))]
pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
&self.profile_id
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
&self.id
}
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
#[diesel(table_name = business_profile, primary_key(profile_id))]
pub struct BusinessProfileNew {
pub profile_id: common_utils::id_type::ProfileId,
pub merchant_id: common_utils::id_type::MerchantId,
pub profile_name: String,
pub created_at: time::PrimitiveDateTime,
@ -316,8 +334,10 @@ pub struct BusinessProfileNew {
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub id: common_utils::id_type::ProfileId,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: Option<bool>,
pub api_version: common_enums::ApiVersion,
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@ -395,7 +415,7 @@ impl BusinessProfileUpdateInternal {
is_tax_connector_enabled,
} = self;
BusinessProfile {
profile_id: source.profile_id,
id: source.id,
merchant_id: source.merchant_id,
profile_name: profile_name.unwrap_or(source.profile_name),
created_at: source.created_at,
@ -449,6 +469,7 @@ impl BusinessProfileUpdateInternal {
default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
tax_connector_id: tax_connector_id.or(source.tax_connector_id),
is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
api_version: source.api_version,
}
}
}
@ -460,7 +481,7 @@ impl BusinessProfileUpdateInternal {
impl From<BusinessProfileNew> for BusinessProfile {
fn from(new: BusinessProfileNew) -> Self {
Self {
profile_id: new.profile_id,
id: new.id,
merchant_id: new.merchant_id,
profile_name: new.profile_name,
created_at: new.created_at,
@ -498,6 +519,7 @@ impl From<BusinessProfileNew> for BusinessProfile {
default_fallback_routing: new.default_fallback_routing,
tax_connector_id: new.tax_connector_id,
is_tax_connector_enabled: new.is_tax_connector_enabled,
api_version: new.api_version,
}
}
}

View File

@ -5,9 +5,9 @@ use super::generics;
any(feature = "v1", feature = "v2"),
not(feature = "business_profile_v2")
))]
use crate::schema::business_profile::dsl;
use crate::schema::business_profile::dsl::{self, profile_id as dsl_identifier};
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
use crate::schema_v2::business_profile::dsl;
use crate::schema_v2::business_profile::dsl::{self, id as dsl_identifier};
use crate::{
business_profile::{BusinessProfile, BusinessProfileNew, BusinessProfileUpdateInternal},
errors, PgPooledConn, StorageResult,
@ -27,7 +27,7 @@ impl BusinessProfile {
) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
self.profile_id.clone(),
self.get_id().to_owned(),
business_profile,
)
.await
@ -46,7 +46,7 @@ impl BusinessProfile {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::profile_id.eq(profile_id.to_owned()),
dsl_identifier.eq(profile_id.to_owned()),
)
.await
}
@ -60,7 +60,7 @@ impl BusinessProfile {
conn,
dsl::merchant_id
.eq(merchant_id.to_owned())
.and(dsl::profile_id.eq(profile_id.to_owned())),
.and(dsl_identifier.eq(profile_id.to_owned())),
)
.await
}
@ -105,7 +105,7 @@ impl BusinessProfile {
) -> StorageResult<bool> {
generics::generic_delete::<<Self as HasTable>::Table, _>(
conn,
dsl::profile_id
dsl_identifier
.eq(profile_id.to_owned())
.and(dsl::merchant_id.eq(merchant_id.to_owned())),
)

View File

@ -208,6 +208,7 @@ diesel::table! {
#[max_length = 64]
tax_connector_id -> Nullable<Varchar>,
is_tax_connector_enabled -> Nullable<Bool>,
api_version -> ApiVersion,
}
}

View File

@ -172,9 +172,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;
business_profile (profile_id) {
#[max_length = 64]
profile_id -> Varchar,
business_profile (id) {
#[max_length = 64]
merchant_id -> Varchar,
#[max_length = 64]
@ -213,8 +211,11 @@ diesel::table! {
payout_routing_algorithm_id -> Nullable<Varchar>,
default_fallback_routing -> Nullable<Jsonb>,
#[max_length = 64]
id -> Varchar,
#[max_length = 64]
tax_connector_id -> Nullable<Varchar>,
is_tax_connector_enabled -> Nullable<Bool>,
api_version -> ApiVersion,
}
}

View File

@ -1,5 +1,3 @@
// #[cfg(all(feature = "v2", feature = "business_profile_v2"))]
// use common_enums::OrderFulfillmentTimeOrigin;
use common_utils::{
crypto::OptionalEncryptableValue,
date_time,
@ -15,7 +13,10 @@ use diesel_models::business_profile::{
use error_stack::ResultExt;
use masking::{PeekInterface, Secret};
use crate::type_encryption::{crypto_operation, AsyncLift, CryptoOperation};
use crate::{
consts,
type_encryption::{crypto_operation, AsyncLift, CryptoOperation},
};
#[cfg(all(
any(feature = "v1", feature = "v2"),
@ -23,6 +24,46 @@ use crate::type_encryption::{crypto_operation, AsyncLift, CryptoOperation};
))]
#[derive(Clone, Debug)]
pub struct BusinessProfile {
profile_id: common_utils::id_type::ProfileId,
pub merchant_id: common_utils::id_type::MerchantId,
pub profile_name: String,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub return_url: Option<String>,
pub enable_payment_response_hash: bool,
pub payment_response_hash_key: Option<String>,
pub redirect_to_merchant_with_http_post: bool,
pub webhook_details: Option<WebhookDetails>,
pub metadata: Option<pii::SecretSerdeValue>,
pub routing_algorithm: Option<serde_json::Value>,
pub intent_fulfillment_time: Option<i64>,
pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>,
pub is_recon_enabled: bool,
pub applepay_verified_domains: Option<Vec<String>>,
pub payment_link_config: Option<BusinessPaymentLinkConfig>,
pub session_expiry: Option<i64>,
pub authentication_connector_details: Option<AuthenticationConnectorDetails>,
pub payout_link_config: Option<BusinessPayoutLinkConfig>,
pub is_extended_card_info_enabled: Option<bool>,
pub extended_card_info_config: Option<pii::SecretSerdeValue>,
pub is_connector_agnostic_mit_enabled: Option<bool>,
pub use_billing_as_payment_method_billing: Option<bool>,
pub collect_shipping_details_from_wallet_connector: Option<bool>,
pub collect_billing_details_from_wallet_connector: Option<bool>,
pub outgoing_webhook_custom_http_headers: OptionalEncryptableValue,
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: bool,
pub api_version: common_enums::ApiVersion,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "business_profile_v2")
))]
pub struct BusinessProfileSetter {
pub profile_id: common_utils::id_type::ProfileId,
pub merchant_id: common_utils::id_type::MerchantId,
pub profile_name: String,
@ -57,6 +98,69 @@ pub struct BusinessProfile {
pub is_tax_connector_enabled: bool,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "business_profile_v2")
))]
impl From<BusinessProfileSetter> for BusinessProfile {
fn from(value: BusinessProfileSetter) -> Self {
Self {
profile_id: value.profile_id,
merchant_id: value.merchant_id,
profile_name: value.profile_name,
created_at: value.created_at,
modified_at: value.modified_at,
return_url: value.return_url,
enable_payment_response_hash: value.enable_payment_response_hash,
payment_response_hash_key: value.payment_response_hash_key,
redirect_to_merchant_with_http_post: value.redirect_to_merchant_with_http_post,
webhook_details: value.webhook_details,
metadata: value.metadata,
routing_algorithm: value.routing_algorithm,
intent_fulfillment_time: value.intent_fulfillment_time,
frm_routing_algorithm: value.frm_routing_algorithm,
payout_routing_algorithm: value.payout_routing_algorithm,
is_recon_enabled: value.is_recon_enabled,
applepay_verified_domains: value.applepay_verified_domains,
payment_link_config: value.payment_link_config,
session_expiry: value.session_expiry,
authentication_connector_details: value.authentication_connector_details,
payout_link_config: value.payout_link_config,
is_extended_card_info_enabled: value.is_extended_card_info_enabled,
extended_card_info_config: value.extended_card_info_config,
is_connector_agnostic_mit_enabled: value.is_connector_agnostic_mit_enabled,
use_billing_as_payment_method_billing: value.use_billing_as_payment_method_billing,
collect_shipping_details_from_wallet_connector: value
.collect_shipping_details_from_wallet_connector,
collect_billing_details_from_wallet_connector: value
.collect_billing_details_from_wallet_connector,
outgoing_webhook_custom_http_headers: value.outgoing_webhook_custom_http_headers,
always_collect_billing_details_from_wallet_connector: value
.always_collect_billing_details_from_wallet_connector,
always_collect_shipping_details_from_wallet_connector: value
.always_collect_shipping_details_from_wallet_connector,
tax_connector_id: value.tax_connector_id,
is_tax_connector_enabled: value.is_tax_connector_enabled,
api_version: consts::API_VERSION,
}
}
}
impl BusinessProfile {
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "business_profile_v2")
))]
pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
&self.profile_id
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
&self.id
}
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "business_profile_v2")
@ -335,6 +439,7 @@ impl super::behaviour::Conversion for BusinessProfile {
.always_collect_shipping_details_from_wallet_connector,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: Some(self.is_tax_connector_enabled),
api_version: self.api_version,
})
}
@ -398,6 +503,7 @@ impl super::behaviour::Conversion for BusinessProfile {
.await?,
tax_connector_id: item.tax_connector_id,
is_tax_connector_enabled: item.is_tax_connector_enabled.unwrap_or(false),
api_version: item.api_version,
})
}
.await
@ -446,6 +552,7 @@ impl super::behaviour::Conversion for BusinessProfile {
.always_collect_shipping_details_from_wallet_connector,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: Some(self.is_tax_connector_enabled),
api_version: self.api_version,
})
}
}
@ -453,7 +560,7 @@ impl super::behaviour::Conversion for BusinessProfile {
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
#[derive(Clone, Debug)]
pub struct BusinessProfile {
pub profile_id: common_utils::id_type::ProfileId,
id: common_utils::id_type::ProfileId,
pub merchant_id: common_utils::id_type::MerchantId,
pub profile_name: String,
pub created_at: time::PrimitiveDateTime,
@ -487,6 +594,92 @@ pub struct BusinessProfile {
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: bool,
pub api_version: common_enums::ApiVersion,
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
pub struct BusinessProfileSetter {
pub id: common_utils::id_type::ProfileId,
pub merchant_id: common_utils::id_type::MerchantId,
pub profile_name: String,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub return_url: Option<String>,
pub enable_payment_response_hash: bool,
pub payment_response_hash_key: Option<String>,
pub redirect_to_merchant_with_http_post: bool,
pub webhook_details: Option<WebhookDetails>,
pub metadata: Option<pii::SecretSerdeValue>,
pub is_recon_enabled: bool,
pub applepay_verified_domains: Option<Vec<String>>,
pub payment_link_config: Option<BusinessPaymentLinkConfig>,
pub session_expiry: Option<i64>,
pub authentication_connector_details: Option<AuthenticationConnectorDetails>,
pub payout_link_config: Option<BusinessPayoutLinkConfig>,
pub is_extended_card_info_enabled: Option<bool>,
pub extended_card_info_config: Option<pii::SecretSerdeValue>,
pub is_connector_agnostic_mit_enabled: Option<bool>,
pub use_billing_as_payment_method_billing: Option<bool>,
pub collect_shipping_details_from_wallet_connector: Option<bool>,
pub collect_billing_details_from_wallet_connector: Option<bool>,
pub outgoing_webhook_custom_http_headers: OptionalEncryptableValue,
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub order_fulfillment_time: Option<i64>,
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: bool,
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
impl From<BusinessProfileSetter> for BusinessProfile {
fn from(value: BusinessProfileSetter) -> Self {
Self {
id: value.id,
merchant_id: value.merchant_id,
profile_name: value.profile_name,
created_at: value.created_at,
modified_at: value.modified_at,
return_url: value.return_url,
enable_payment_response_hash: value.enable_payment_response_hash,
payment_response_hash_key: value.payment_response_hash_key,
redirect_to_merchant_with_http_post: value.redirect_to_merchant_with_http_post,
webhook_details: value.webhook_details,
metadata: value.metadata,
is_recon_enabled: value.is_recon_enabled,
applepay_verified_domains: value.applepay_verified_domains,
payment_link_config: value.payment_link_config,
session_expiry: value.session_expiry,
authentication_connector_details: value.authentication_connector_details,
payout_link_config: value.payout_link_config,
is_extended_card_info_enabled: value.is_extended_card_info_enabled,
extended_card_info_config: value.extended_card_info_config,
is_connector_agnostic_mit_enabled: value.is_connector_agnostic_mit_enabled,
use_billing_as_payment_method_billing: value.use_billing_as_payment_method_billing,
collect_shipping_details_from_wallet_connector: value
.collect_shipping_details_from_wallet_connector,
collect_billing_details_from_wallet_connector: value
.collect_billing_details_from_wallet_connector,
outgoing_webhook_custom_http_headers: value.outgoing_webhook_custom_http_headers,
always_collect_billing_details_from_wallet_connector: value
.always_collect_billing_details_from_wallet_connector,
always_collect_shipping_details_from_wallet_connector: value
.always_collect_shipping_details_from_wallet_connector,
routing_algorithm_id: value.routing_algorithm_id,
order_fulfillment_time: value.order_fulfillment_time,
order_fulfillment_time_origin: value.order_fulfillment_time_origin,
frm_routing_algorithm_id: value.frm_routing_algorithm_id,
payout_routing_algorithm_id: value.payout_routing_algorithm_id,
default_fallback_routing: value.default_fallback_routing,
tax_connector_id: value.tax_connector_id,
is_tax_connector_enabled: value.is_tax_connector_enabled,
api_version: consts::API_VERSION,
}
}
}
impl BusinessProfile {
@ -769,7 +962,7 @@ impl super::behaviour::Conversion for BusinessProfile {
async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
Ok(diesel_models::business_profile::BusinessProfile {
profile_id: self.profile_id,
id: self.id,
merchant_id: self.merchant_id,
profile_name: self.profile_name,
created_at: self.created_at,
@ -809,6 +1002,7 @@ impl super::behaviour::Conversion for BusinessProfile {
default_fallback_routing: self.default_fallback_routing,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: Some(self.is_tax_connector_enabled),
api_version: self.api_version,
})
}
@ -823,7 +1017,7 @@ impl super::behaviour::Conversion for BusinessProfile {
{
async {
Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
profile_id: item.profile_id,
id: item.id,
merchant_id: item.merchant_id,
profile_name: item.profile_name,
created_at: item.created_at,
@ -874,6 +1068,7 @@ impl super::behaviour::Conversion for BusinessProfile {
default_fallback_routing: item.default_fallback_routing,
tax_connector_id: item.tax_connector_id,
is_tax_connector_enabled: item.is_tax_connector_enabled.unwrap_or(false),
api_version: item.api_version,
})
}
.await
@ -884,7 +1079,7 @@ impl super::behaviour::Conversion for BusinessProfile {
async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
Ok(diesel_models::business_profile::BusinessProfileNew {
profile_id: self.profile_id,
id: self.id,
merchant_id: self.merchant_id,
profile_name: self.profile_name,
created_at: self.created_at,
@ -924,6 +1119,7 @@ impl super::behaviour::Conversion for BusinessProfile {
default_fallback_routing: self.default_fallback_routing,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: Some(self.is_tax_connector_enabled),
api_version: self.api_version,
})
}
}

View File

@ -544,7 +544,7 @@ impl CreateBusinessProfile {
if business_profiles.len() == 1 {
merchant_account.default_profile = business_profiles
.first()
.map(|business_profile| business_profile.profile_id.clone())
.map(|business_profile| business_profile.get_id().to_owned())
}
}
Self::CreateDefaultBusinessProfile => {
@ -552,7 +552,7 @@ impl CreateBusinessProfile {
.create_default_business_profile(state, merchant_account.clone(), key_store)
.await?;
merchant_account.default_profile = Some(business_profile.profile_id);
merchant_account.default_profile = Some(business_profile.get_id().to_owned());
}
}
@ -899,7 +899,7 @@ impl MerchantAccountUpdateBridge for api::MerchantAccountUpdate {
merchant_id,
)
.await?
.map(|business_profile| Some(business_profile.profile_id))
.map(|business_profile| Some(business_profile.get_id().to_owned()))
} else {
None
};
@ -2449,7 +2449,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {
}
None => None,
},
profile_id: business_profile.profile_id.clone(),
profile_id: business_profile.get_id().to_owned(),
applepay_verified_domains: None,
pm_auth_config: self.pm_auth_config.clone(),
status: connector_status,
@ -2618,7 +2618,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {
}
None => None,
},
profile_id: business_profile.profile_id.clone(),
profile_id: business_profile.get_id().to_owned(),
applepay_verified_domains: None,
pm_auth_config: self.pm_auth_config.clone(),
status: connector_status,
@ -2745,7 +2745,7 @@ pub async fn create_connector(
pm_auth_config: &req.pm_auth_config,
db: store,
merchant_id,
profile_id: &business_profile.profile_id,
profile_id: business_profile.get_id(),
key_store: &key_store,
key_manager_state,
};
@ -2791,7 +2791,7 @@ pub async fn create_connector(
.await
.to_duplicate_response(
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount {
profile_id: business_profile.profile_id.get_string_repr().to_owned(),
profile_id: business_profile.get_id().get_string_repr().to_owned(),
connector_label: merchant_connector_account
.connector_label
.unwrap_or_default(),
@ -2808,7 +2808,7 @@ pub async fn create_connector(
merchant_connector_id: &mca.get_id(),
store,
merchant_id,
profile_id: &business_profile.profile_id,
profile_id: business_profile.get_id(),
transaction_type: &req.get_transaction_type(),
};
@ -3480,72 +3480,74 @@ impl BusinessProfileCreateBridge for api::BusinessProfileCreate {
})
.transpose()?;
Ok(domain::BusinessProfile {
profile_id,
merchant_id: merchant_account.get_id().clone(),
profile_name,
created_at: current_time,
modified_at: current_time,
return_url: self
.return_url
.map(|return_url| return_url.to_string())
.or(merchant_account.return_url.clone()),
enable_payment_response_hash: self
.enable_payment_response_hash
.unwrap_or(merchant_account.enable_payment_response_hash),
payment_response_hash_key: Some(payment_response_hash_key),
redirect_to_merchant_with_http_post: self
.redirect_to_merchant_with_http_post
.unwrap_or(merchant_account.redirect_to_merchant_with_http_post),
webhook_details: webhook_details.or(merchant_account.webhook_details.clone()),
metadata: self.metadata,
routing_algorithm: None,
intent_fulfillment_time: self
.intent_fulfillment_time
.map(i64::from)
.or(merchant_account.intent_fulfillment_time)
.or(Some(common_utils::consts::DEFAULT_INTENT_FULFILLMENT_TIME)),
frm_routing_algorithm: self
.frm_routing_algorithm
.or(merchant_account.frm_routing_algorithm.clone()),
#[cfg(feature = "payouts")]
payout_routing_algorithm: self
.payout_routing_algorithm
.or(merchant_account.payout_routing_algorithm.clone()),
#[cfg(not(feature = "payouts"))]
payout_routing_algorithm: None,
is_recon_enabled: merchant_account.is_recon_enabled,
applepay_verified_domains: self.applepay_verified_domains,
payment_link_config,
session_expiry: self
.session_expiry
.map(i64::from)
.or(Some(common_utils::consts::DEFAULT_SESSION_EXPIRY)),
authentication_connector_details: self
.authentication_connector_details
.map(ForeignInto::foreign_into),
payout_link_config,
is_connector_agnostic_mit_enabled: self.is_connector_agnostic_mit_enabled,
is_extended_card_info_enabled: None,
extended_card_info_config: None,
use_billing_as_payment_method_billing: self
.use_billing_as_payment_method_billing
.or(Some(true)),
collect_shipping_details_from_wallet_connector: self
.collect_shipping_details_from_wallet_connector
.or(Some(false)),
collect_billing_details_from_wallet_connector: self
.collect_billing_details_from_wallet_connector
.or(Some(false)),
outgoing_webhook_custom_http_headers: outgoing_webhook_custom_http_headers
.map(Into::into),
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: self.is_tax_connector_enabled,
always_collect_billing_details_from_wallet_connector: self
.always_collect_billing_details_from_wallet_connector,
always_collect_shipping_details_from_wallet_connector: self
.always_collect_shipping_details_from_wallet_connector,
})
Ok(domain::BusinessProfile::from(
domain::BusinessProfileSetter {
profile_id,
merchant_id: merchant_account.get_id().clone(),
profile_name,
created_at: current_time,
modified_at: current_time,
return_url: self
.return_url
.map(|return_url| return_url.to_string())
.or(merchant_account.return_url.clone()),
enable_payment_response_hash: self
.enable_payment_response_hash
.unwrap_or(merchant_account.enable_payment_response_hash),
payment_response_hash_key: Some(payment_response_hash_key),
redirect_to_merchant_with_http_post: self
.redirect_to_merchant_with_http_post
.unwrap_or(merchant_account.redirect_to_merchant_with_http_post),
webhook_details: webhook_details.or(merchant_account.webhook_details.clone()),
metadata: self.metadata,
routing_algorithm: None,
intent_fulfillment_time: self
.intent_fulfillment_time
.map(i64::from)
.or(merchant_account.intent_fulfillment_time)
.or(Some(common_utils::consts::DEFAULT_INTENT_FULFILLMENT_TIME)),
frm_routing_algorithm: self
.frm_routing_algorithm
.or(merchant_account.frm_routing_algorithm.clone()),
#[cfg(feature = "payouts")]
payout_routing_algorithm: self
.payout_routing_algorithm
.or(merchant_account.payout_routing_algorithm.clone()),
#[cfg(not(feature = "payouts"))]
payout_routing_algorithm: None,
is_recon_enabled: merchant_account.is_recon_enabled,
applepay_verified_domains: self.applepay_verified_domains,
payment_link_config,
session_expiry: self
.session_expiry
.map(i64::from)
.or(Some(common_utils::consts::DEFAULT_SESSION_EXPIRY)),
authentication_connector_details: self
.authentication_connector_details
.map(ForeignInto::foreign_into),
payout_link_config,
is_connector_agnostic_mit_enabled: self.is_connector_agnostic_mit_enabled,
is_extended_card_info_enabled: None,
extended_card_info_config: None,
use_billing_as_payment_method_billing: self
.use_billing_as_payment_method_billing
.or(Some(true)),
collect_shipping_details_from_wallet_connector: self
.collect_shipping_details_from_wallet_connector
.or(Some(false)),
collect_billing_details_from_wallet_connector: self
.collect_billing_details_from_wallet_connector
.or(Some(false)),
outgoing_webhook_custom_http_headers: outgoing_webhook_custom_http_headers
.map(Into::into),
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: self.is_tax_connector_enabled,
always_collect_billing_details_from_wallet_connector: self
.always_collect_billing_details_from_wallet_connector,
always_collect_shipping_details_from_wallet_connector: self
.always_collect_shipping_details_from_wallet_connector,
},
))
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@ -3593,61 +3595,63 @@ impl BusinessProfileCreateBridge for api::BusinessProfileCreate {
})
.transpose()?;
Ok(domain::BusinessProfile {
profile_id,
merchant_id: merchant_id.clone(),
profile_name,
created_at: current_time,
modified_at: current_time,
return_url: self.return_url.map(|return_url| return_url.to_string()),
enable_payment_response_hash: self.enable_payment_response_hash.unwrap_or(true),
payment_response_hash_key: Some(payment_response_hash_key),
redirect_to_merchant_with_http_post: self
.redirect_to_merchant_with_http_post
.unwrap_or(true),
webhook_details,
metadata: self.metadata,
is_recon_enabled: false,
applepay_verified_domains: self.applepay_verified_domains,
payment_link_config,
session_expiry: self
.session_expiry
.map(i64::from)
.or(Some(common_utils::consts::DEFAULT_SESSION_EXPIRY)),
authentication_connector_details: self
.authentication_connector_details
.map(ForeignInto::foreign_into),
payout_link_config,
is_connector_agnostic_mit_enabled: self.is_connector_agnostic_mit_enabled,
is_extended_card_info_enabled: None,
extended_card_info_config: None,
use_billing_as_payment_method_billing: self
.use_billing_as_payment_method_billing
.or(Some(true)),
collect_shipping_details_from_wallet_connector: self
.collect_shipping_details_from_wallet_connector_if_required
.or(Some(false)),
collect_billing_details_from_wallet_connector: self
.collect_billing_details_from_wallet_connector_if_required
.or(Some(false)),
outgoing_webhook_custom_http_headers: outgoing_webhook_custom_http_headers
.map(Into::into),
always_collect_billing_details_from_wallet_connector: self
.always_collect_billing_details_from_wallet_connector,
always_collect_shipping_details_from_wallet_connector: self
.always_collect_shipping_details_from_wallet_connector,
routing_algorithm_id: None,
frm_routing_algorithm_id: None,
payout_routing_algorithm_id: None,
order_fulfillment_time: self
.order_fulfillment_time
.map(|order_fulfillment_time| order_fulfillment_time.into_inner())
.or(Some(common_utils::consts::DEFAULT_ORDER_FULFILLMENT_TIME)),
order_fulfillment_time_origin: self.order_fulfillment_time_origin,
default_fallback_routing: None,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: self.is_tax_connector_enabled,
})
Ok(domain::BusinessProfile::from(
domain::BusinessProfileSetter {
id: profile_id,
merchant_id: merchant_id.clone(),
profile_name,
created_at: current_time,
modified_at: current_time,
return_url: self.return_url.map(|return_url| return_url.to_string()),
enable_payment_response_hash: self.enable_payment_response_hash.unwrap_or(true),
payment_response_hash_key: Some(payment_response_hash_key),
redirect_to_merchant_with_http_post: self
.redirect_to_merchant_with_http_post
.unwrap_or(true),
webhook_details,
metadata: self.metadata,
is_recon_enabled: false,
applepay_verified_domains: self.applepay_verified_domains,
payment_link_config,
session_expiry: self
.session_expiry
.map(i64::from)
.or(Some(common_utils::consts::DEFAULT_SESSION_EXPIRY)),
authentication_connector_details: self
.authentication_connector_details
.map(ForeignInto::foreign_into),
payout_link_config,
is_connector_agnostic_mit_enabled: self.is_connector_agnostic_mit_enabled,
is_extended_card_info_enabled: None,
extended_card_info_config: None,
use_billing_as_payment_method_billing: self
.use_billing_as_payment_method_billing
.or(Some(true)),
collect_shipping_details_from_wallet_connector: self
.collect_shipping_details_from_wallet_connector_if_required
.or(Some(false)),
collect_billing_details_from_wallet_connector: self
.collect_billing_details_from_wallet_connector_if_required
.or(Some(false)),
outgoing_webhook_custom_http_headers: outgoing_webhook_custom_http_headers
.map(Into::into),
always_collect_billing_details_from_wallet_connector: self
.always_collect_billing_details_from_wallet_connector,
always_collect_shipping_details_from_wallet_connector: self
.always_collect_shipping_details_from_wallet_connector,
routing_algorithm_id: None,
frm_routing_algorithm_id: None,
payout_routing_algorithm_id: None,
order_fulfillment_time: self
.order_fulfillment_time
.map(|order_fulfillment_time| order_fulfillment_time.into_inner())
.or(Some(common_utils::consts::DEFAULT_ORDER_FULFILLMENT_TIME)),
order_fulfillment_time_origin: self.order_fulfillment_time_origin,
default_fallback_routing: None,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: self.is_tax_connector_enabled,
},
))
}
}
@ -3674,7 +3678,7 @@ pub async fn create_business_profile(
.create_domain_model_from_request(&state, &key_store, merchant_account.get_id())
.await?;
let profile_id = business_profile.profile_id.clone();
let profile_id = business_profile.get_id().to_owned();
let business_profile = db
.insert_business_profile(key_manager_state, &key_store, business_profile)
@ -4056,7 +4060,7 @@ impl BusinessProfileWrapper {
fn get_routing_config_cache_key(self) -> storage_impl::redis::cache::CacheKind<'static> {
let merchant_id = self.profile.merchant_id.clone();
let profile_id = self.profile.profile_id.clone();
let profile_id = self.profile.get_id().to_owned();
storage_impl::redis::cache::CacheKind::Routing(
format!(
@ -4144,7 +4148,7 @@ impl BusinessProfileWrapper {
pub fn get_default_routing_configs_from_profile(
&self,
) -> RouterResult<routing_types::ProfileDefaultRoutingConfig> {
let profile_id = self.profile.profile_id.clone();
let profile_id = self.profile.get_id().to_owned();
let connectors = self.get_default_fallback_list_of_connector_under_profile()?;
Ok(routing_types::ProfileDefaultRoutingConfig {

View File

@ -133,7 +133,7 @@ pub async fn perform_pre_authentication(
business_profile.merchant_id.clone(),
authentication_connector_name.clone(),
token,
business_profile.profile_id.clone(),
business_profile.get_id().to_owned(),
payment_id,
three_ds_connector_account
.get_mca_id()

View File

@ -284,15 +284,15 @@ pub async fn get_authentication_connector_data(
.first()
.ok_or(errors::ApiErrorResponse::UnprocessableEntity {
message: format!(
"No authentication_connector found for profile_id {}",
business_profile.profile_id.get_string_repr()
"No authentication_connector found for profile_id {:?}",
business_profile.get_id()
),
})
.attach_printable(
"No authentication_connector found from merchant_account.authentication_details",
)?
.to_owned();
let profile_id = &business_profile.profile_id;
let profile_id = business_profile.get_id();
let authentication_connector_mca = payments::helpers::get_merchant_connector_account(
state,
&business_profile.merchant_id,

View File

@ -4844,7 +4844,7 @@ async fn generate_saved_pm_response(
pi.off_session_payment_flag,
pi.business_profile
.as_ref()
.map(|profile| profile.profile_id.clone()),
.map(|profile| profile.get_id().to_owned()),
)
})
.unwrap_or((false, false, false, Default::default()));

View File

@ -4284,7 +4284,7 @@ pub async fn get_apple_pay_retryable_connectors<F>(
where
F: Send + Clone,
{
let profile_id = &business_profile.profile_id;
let profile_id = business_profile.get_id();
let pre_decided_connector_data_first = pre_routing_connector_data_list
.first()
@ -5118,7 +5118,7 @@ pub async fn get_payment_external_authentication_flow_during_confirm<F: Clone>(
&business_profile.merchant_id,
None,
key_store,
&business_profile.profile_id,
business_profile.get_id(),
connector_data.connector_name.to_string().as_str(),
connector_data.merchant_connector_id.as_ref(),
)

View File

@ -302,7 +302,7 @@ pub async fn perform_static_routing_v1<F: Clone>(
))]
let fallback_config = routing::helpers::get_merchant_default_config(
&*state.clone().store,
business_profile.profile_id.get_string_repr(),
business_profile.get_id().get_string_repr(),
&api_enums::TransactionType::from(transaction_data),
)
.await
@ -322,7 +322,7 @@ pub async fn perform_static_routing_v1<F: Clone>(
state,
merchant_id,
&algorithm_id,
business_profile.profile_id.clone(),
business_profile.get_id().to_owned(),
&api_enums::TransactionType::from(transaction_data),
)
.await?;
@ -780,7 +780,7 @@ pub async fn perform_fallback_routing<F: Clone>(
fallback_config,
backend_input,
eligible_connectors,
business_profile.profile_id.clone(),
business_profile.get_id().to_owned(),
&api_enums::TransactionType::from(transaction_data),
)
.await
@ -800,7 +800,7 @@ pub async fn perform_eligibility_analysis_with_fallback<F: Clone>(
chosen,
transaction_data,
eligible_connectors.as_ref(),
business_profile.profile_id.clone(),
business_profile.get_id().to_owned(),
)
.await?;

View File

@ -140,13 +140,13 @@ pub async fn create_routing_algorithm_under_profile(
.await?;
let name_mca_id_set = helpers::ConnectNameAndMCAIdForProfile(
all_mcas.filter_by_profile(&business_profile.profile_id, |mca| {
all_mcas.filter_by_profile(business_profile.get_id(), |mca| {
(&mca.connector_name, mca.get_id())
}),
);
let name_set = helpers::ConnectNameForProfile(
all_mcas.filter_by_profile(&business_profile.profile_id, |mca| &mca.connector_name),
all_mcas.filter_by_profile(business_profile.get_id(), |mca| &mca.connector_name),
);
let algorithm_helper = helpers::RoutingAlgorithmHelpers {
@ -160,7 +160,7 @@ pub async fn create_routing_algorithm_under_profile(
let algo = RoutingAlgorithmUpdate::create_new_routing_algorithm(
&request,
merchant_account.get_id(),
business_profile.profile_id,
business_profile.get_id().to_owned(),
transaction_type,
);
@ -853,7 +853,7 @@ pub async fn retrieve_routing_config_under_profile(
let record = db
.list_routing_algorithm_metadata_by_profile_id(
&business_profile.profile_id,
business_profile.get_id(),
i64::from(query_params.limit.unwrap_or_default()),
i64::from(query_params.offset.unwrap_or_default()),
)
@ -914,6 +914,8 @@ pub async fn retrieve_linked_routing_config(
let mut active_algorithms = Vec::new();
for business_profile in business_profiles {
let profile_id = business_profile.get_id().to_owned();
let routing_ref: routing_types::RoutingAlgorithmRef = match transaction_type {
enums::TransactionType::Payment => business_profile.routing_algorithm,
#[cfg(feature = "payouts")]
@ -930,7 +932,7 @@ pub async fn retrieve_linked_routing_config(
let record = db
.find_routing_algorithm_metadata_by_algorithm_id_profile_id(
&algorithm_id,
&business_profile.profile_id,
&profile_id,
)
.await
.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?;
@ -970,7 +972,7 @@ pub async fn retrieve_default_routing_config_for_profiles(
.map(|prof| {
helpers::get_merchant_default_config(
db,
prof.profile_id.get_string_repr(),
prof.get_id().get_string_repr(),
transaction_type,
)
})
@ -983,7 +985,7 @@ pub async fn retrieve_default_routing_config_for_profiles(
let default_configs = configs
.into_iter()
.zip(all_profiles.iter().map(|prof| prof.profile_id.clone()))
.zip(all_profiles.iter().map(|prof| prof.get_id().to_owned()))
.map(
|(config, profile_id)| routing_types::ProfileDefaultRoutingConfig {
profile_id,
@ -1022,7 +1024,7 @@ pub async fn update_default_routing_config_for_profile(
})?;
let default_config = helpers::get_merchant_default_config(
db,
business_profile.profile_id.get_string_repr(),
business_profile.get_id().get_string_repr(),
transaction_type,
)
.await?;
@ -1064,7 +1066,7 @@ pub async fn update_default_routing_config_for_profile(
helpers::update_merchant_default_config(
db,
business_profile.profile_id.get_string_repr(),
business_profile.get_id().get_string_repr(),
updated_config.clone(),
transaction_type,
)
@ -1073,7 +1075,7 @@ pub async fn update_default_routing_config_for_profile(
metrics::ROUTING_UPDATE_CONFIG_FOR_PROFILE_SUCCESS_RESPONSE.add(&metrics::CONTEXT, 1, &[]);
Ok(service_api::ApplicationResponse::Json(
routing_types::ProfileDefaultRoutingConfig {
profile_id: business_profile.profile_id,
profile_id: business_profile.get_id().to_owned(),
connectors: updated_config,
},
))

View File

@ -203,7 +203,7 @@ pub async fn update_business_profile_active_algorithm_ref(
let merchant_id = current_business_profile.merchant_id.clone();
let profile_id = current_business_profile.profile_id.clone();
let profile_id = current_business_profile.get_id().to_owned();
let routing_cache_key = cache::CacheKind::Routing(
format!(

View File

@ -2423,7 +2423,7 @@ pub async fn list_profiles_for_user_in_org_and_merchant_account(
.into_iter()
.map(
|profile| user_api::ListProfilesForUserInOrgAndMerchantAccountResponse {
profile_id: profile.profile_id,
profile_id: profile.get_id().to_owned(),
profile_name: profile.profile_name,
},
)
@ -2461,7 +2461,7 @@ pub async fn list_profiles_for_user_in_org_and_merchant_account(
.into_iter()
.map(
|profile| user_api::ListProfilesForUserInOrgAndMerchantAccountResponse {
profile_id: profile.profile_id,
profile_id: profile.get_id().to_owned(),
profile_name: profile.profile_name,
},
)
@ -2550,8 +2550,8 @@ pub async fn switch_org_for_user(
.first()
.ok_or(UserErrors::InternalServerError)
.attach_printable("No business profile found for the merchant_id")?
.profile_id
.clone()
.get_id()
.to_owned()
};
let token = utils::user::generate_jwt_auth_token_with_attributes(
@ -2638,8 +2638,8 @@ pub async fn switch_merchant_for_user_in_org(
.first()
.ok_or(UserErrors::InternalServerError)
.attach_printable("No business profile found for the given merchant_id")?
.profile_id
.clone();
.get_id()
.to_owned();
(
merchant_account.organization_id,
@ -2691,8 +2691,8 @@ pub async fn switch_merchant_for_user_in_org(
.first()
.ok_or(UserErrors::InternalServerError)
.attach_printable("No business profile found for the merchant_id")?
.profile_id
.clone();
.get_id()
.to_owned();
(
user_from_token.org_id.clone(),
@ -2752,8 +2752,8 @@ pub async fn switch_merchant_for_user_in_org(
.first()
.ok_or(UserErrors::InternalServerError)
.attach_printable("No business profile found for the given merchant_id")?
.profile_id
.clone()
.get_id()
.to_owned()
};
(
user_from_token.org_id,
@ -2838,7 +2838,8 @@ pub async fn switch_profile_for_user_in_org_and_merchant(
.change_context(UserErrors::InvalidRoleOperationWithMessage(
"No such profile found for the merchant".to_string(),
))?
.profile_id;
.get_id()
.to_owned();
(profile_id, user_from_token.role_id)
}

View File

@ -1097,7 +1097,7 @@ pub async fn validate_and_get_business_profile(
// Check if the merchant_id of business profile is same as the current merchant_id
if business_profile.merchant_id.ne(merchant_id) {
Err(errors::ApiErrorResponse::AccessForbidden {
resource: business_profile.profile_id.get_string_repr().to_owned(),
resource: business_profile.get_id().get_string_repr().to_owned(),
}
.into())
} else {
@ -1193,7 +1193,7 @@ pub async fn get_profile_id_from_business_details(
id: profile_name,
})?;
Ok(business_profile.profile_id)
Ok(business_profile.get_id().to_owned())
}
_ => Err(report!(errors::ApiErrorResponse::MissingRequiredField {
field_name: "profile_id or business_country, business_label"

View File

@ -932,7 +932,7 @@ async fn get_or_update_dispute_object(
challenge_required_by: dispute_details.challenge_required_by,
connector_created_at: dispute_details.created_at,
connector_updated_at: dispute_details.updated_at,
profile_id: Some(business_profile.profile_id.clone()),
profile_id: Some(business_profile.get_id().to_owned()),
evidence: None,
merchant_connector_id: payment_attempt.merchant_connector_id.clone(),
dispute_amount: dispute_details.amount.parse::<i64>().unwrap_or(0),

View File

@ -71,7 +71,7 @@ pub(crate) async fn create_event_and_trigger_outgoing_webhook(
|| webhook_url_result.as_ref().is_ok_and(String::is_empty)
{
logger::debug!(
business_profile_id=?business_profile.profile_id,
business_profile_id=?business_profile.get_id(),
%idempotent_event_id,
"Outgoing webhooks are disabled in application configuration, or merchant webhook URL \
could not be obtained; skipping outgoing webhooks for event"
@ -107,7 +107,7 @@ pub(crate) async fn create_event_and_trigger_outgoing_webhook(
primary_object_type,
created_at: now,
merchant_id: Some(business_profile.merchant_id.clone()),
business_profile_id: Some(business_profile.profile_id.clone()),
business_profile_id: Some(business_profile.get_id().to_owned()),
primary_object_created_at,
idempotent_event_id: Some(idempotent_event_id.clone()),
initial_attempt_id: Some(event_id.clone()),
@ -533,7 +533,7 @@ pub(crate) async fn add_outgoing_webhook_retry_task_to_process_tracker(
let tracking_data = types::OutgoingWebhookTrackingData {
merchant_id: business_profile.merchant_id.clone(),
business_profile_id: business_profile.profile_id.clone(),
business_profile_id: business_profile.get_id().to_owned(),
event_type: event.event_type,
event_class: event.event_class,
primary_object_id: event.primary_object_id.clone(),

View File

@ -45,7 +45,7 @@ pub async fn list_initial_delivery_attempts(
.await,
MerchantAccountOrBusinessProfile::BusinessProfile(business_profile) => store
.list_initial_events_by_profile_id_primary_object_id(key_manager_state,
&business_profile.profile_id,
business_profile.get_id(),
&object_id,
&key_store,
)
@ -85,7 +85,7 @@ pub async fn list_initial_delivery_attempts(
.await,
MerchantAccountOrBusinessProfile::BusinessProfile(business_profile) => store
.list_initial_events_by_profile_id_constraints(key_manager_state,
&business_profile.profile_id,
business_profile.get_id(),
created_after,
created_before,
limit,
@ -208,7 +208,7 @@ pub async fn retry_delivery_attempt(
primary_object_type: event_to_retry.primary_object_type,
created_at: now,
merchant_id: Some(business_profile.merchant_id.clone()),
business_profile_id: Some(business_profile.profile_id.clone()),
business_profile_id: Some(business_profile.get_id().to_owned()),
primary_object_created_at: event_to_retry.primary_object_created_at,
idempotent_event_id: Some(idempotent_event_id),
initial_attempt_id: event_to_retry.initial_attempt_id,

View File

@ -268,7 +268,7 @@ impl BusinessProfileInterface for MockDb {
.lock()
.await
.iter()
.find(|business_profile| business_profile.profile_id == *profile_id)
.find(|business_profile| business_profile.get_id() == profile_id)
.cloned()
.async_map(|business_profile| async {
business_profile
@ -303,7 +303,7 @@ impl BusinessProfileInterface for MockDb {
.iter()
.find(|business_profile| {
business_profile.merchant_id == *merchant_id
&& business_profile.profile_id == *profile_id
&& business_profile.get_id() == profile_id
})
.cloned()
.async_map(|business_profile| async {
@ -333,12 +333,12 @@ impl BusinessProfileInterface for MockDb {
current_state: domain::BusinessProfile,
business_profile_update: domain::BusinessProfileUpdate,
) -> CustomResult<domain::BusinessProfile, errors::StorageError> {
let profile_id = current_state.profile_id.clone();
let profile_id = current_state.get_id().to_owned();
self.business_profiles
.lock()
.await
.iter_mut()
.find(|business_profile| business_profile.profile_id == profile_id)
.find(|business_profile| business_profile.get_id() == current_state.get_id())
.async_map(|business_profile| async {
let business_profile_updated =
storage::BusinessProfileUpdateInternal::from(business_profile_update)
@ -362,7 +362,7 @@ impl BusinessProfileInterface for MockDb {
.transpose()?
.ok_or(
errors::StorageError::ValueNotFound(format!(
"No business profile found for profile_id = {profile_id:?}"
"No business profile found for profile_id = {profile_id:?}",
))
.into(),
)
@ -377,7 +377,7 @@ impl BusinessProfileInterface for MockDb {
let index = business_profiles
.iter()
.position(|business_profile| {
business_profile.profile_id == *profile_id
business_profile.get_id() == profile_id
&& business_profile.merchant_id == *merchant_id
})
.ok_or::<errors::StorageError>(errors::StorageError::ValueNotFound(format!(

View File

@ -117,6 +117,7 @@ impl ForeignTryFrom<domain::BusinessProfile> for BusinessProfileResponse {
type Error = error_stack::Report<errors::ParsingError>;
fn foreign_try_from(item: domain::BusinessProfile) -> Result<Self, Self::Error> {
let profile_id = item.get_id().to_owned();
let outgoing_webhook_custom_http_headers = item
.outgoing_webhook_custom_http_headers
.map(|headers| {
@ -131,7 +132,7 @@ impl ForeignTryFrom<domain::BusinessProfile> for BusinessProfileResponse {
Ok(Self {
merchant_id: item.merchant_id,
profile_id: item.profile_id,
profile_id,
profile_name: item.profile_name,
return_url: item.return_url,
enable_payment_response_hash: item.enable_payment_response_hash,
@ -177,6 +178,8 @@ impl ForeignTryFrom<domain::BusinessProfile> for BusinessProfileResponse {
type Error = error_stack::Report<errors::ParsingError>;
fn foreign_try_from(item: domain::BusinessProfile) -> Result<Self, Self::Error> {
let id = item.get_id().to_owned();
let outgoing_webhook_custom_http_headers = item
.outgoing_webhook_custom_http_headers
.map(|headers| {
@ -197,7 +200,7 @@ impl ForeignTryFrom<domain::BusinessProfile> for BusinessProfileResponse {
Ok(Self {
merchant_id: item.merchant_id,
id: item.profile_id,
id,
profile_name: item.profile_name,
return_url: item.return_url,
enable_payment_response_hash: item.enable_payment_response_hash,
@ -285,71 +288,74 @@ pub async fn create_business_profile_from_merchant_account(
})
.transpose()?;
Ok(domain::BusinessProfile {
profile_id,
merchant_id,
profile_name: request.profile_name.unwrap_or("default".to_string()),
created_at: current_time,
modified_at: current_time,
return_url: request
.return_url
.map(|return_url| return_url.to_string())
.or(merchant_account.return_url),
enable_payment_response_hash: request
.enable_payment_response_hash
.unwrap_or(merchant_account.enable_payment_response_hash),
payment_response_hash_key: Some(payment_response_hash_key),
redirect_to_merchant_with_http_post: request
.redirect_to_merchant_with_http_post
.unwrap_or(merchant_account.redirect_to_merchant_with_http_post),
webhook_details: webhook_details.or(merchant_account.webhook_details),
metadata: request.metadata,
routing_algorithm: None,
intent_fulfillment_time: request
.intent_fulfillment_time
.map(i64::from)
.or(merchant_account.intent_fulfillment_time)
.or(Some(common_utils::consts::DEFAULT_INTENT_FULFILLMENT_TIME)),
frm_routing_algorithm: request
.frm_routing_algorithm
.or(merchant_account.frm_routing_algorithm),
#[cfg(feature = "payouts")]
payout_routing_algorithm: request
.payout_routing_algorithm
.or(merchant_account.payout_routing_algorithm),
#[cfg(not(feature = "payouts"))]
payout_routing_algorithm: None,
is_recon_enabled: merchant_account.is_recon_enabled,
applepay_verified_domains: request.applepay_verified_domains,
payment_link_config,
session_expiry: request
.session_expiry
.map(i64::from)
.or(Some(common_utils::consts::DEFAULT_SESSION_EXPIRY)),
authentication_connector_details: request
.authentication_connector_details
.map(ForeignInto::foreign_into),
payout_link_config,
is_connector_agnostic_mit_enabled: request.is_connector_agnostic_mit_enabled,
is_extended_card_info_enabled: None,
extended_card_info_config: None,
use_billing_as_payment_method_billing: request
.use_billing_as_payment_method_billing
.or(Some(true)),
collect_shipping_details_from_wallet_connector: request
.collect_shipping_details_from_wallet_connector
.or(Some(false)),
collect_billing_details_from_wallet_connector: request
.collect_billing_details_from_wallet_connector
.or(Some(false)),
always_collect_billing_details_from_wallet_connector: request
.always_collect_billing_details_from_wallet_connector
.or(Some(false)),
always_collect_shipping_details_from_wallet_connector: request
.always_collect_shipping_details_from_wallet_connector
.or(Some(false)),
outgoing_webhook_custom_http_headers: outgoing_webhook_custom_http_headers.map(Into::into),
tax_connector_id: request.tax_connector_id,
is_tax_connector_enabled: request.is_tax_connector_enabled,
})
Ok(domain::BusinessProfile::from(
domain::BusinessProfileSetter {
profile_id,
merchant_id,
profile_name: request.profile_name.unwrap_or("default".to_string()),
created_at: current_time,
modified_at: current_time,
return_url: request
.return_url
.map(|return_url| return_url.to_string())
.or(merchant_account.return_url),
enable_payment_response_hash: request
.enable_payment_response_hash
.unwrap_or(merchant_account.enable_payment_response_hash),
payment_response_hash_key: Some(payment_response_hash_key),
redirect_to_merchant_with_http_post: request
.redirect_to_merchant_with_http_post
.unwrap_or(merchant_account.redirect_to_merchant_with_http_post),
webhook_details: webhook_details.or(merchant_account.webhook_details),
metadata: request.metadata,
routing_algorithm: None,
intent_fulfillment_time: request
.intent_fulfillment_time
.map(i64::from)
.or(merchant_account.intent_fulfillment_time)
.or(Some(common_utils::consts::DEFAULT_INTENT_FULFILLMENT_TIME)),
frm_routing_algorithm: request
.frm_routing_algorithm
.or(merchant_account.frm_routing_algorithm),
#[cfg(feature = "payouts")]
payout_routing_algorithm: request
.payout_routing_algorithm
.or(merchant_account.payout_routing_algorithm),
#[cfg(not(feature = "payouts"))]
payout_routing_algorithm: None,
is_recon_enabled: merchant_account.is_recon_enabled,
applepay_verified_domains: request.applepay_verified_domains,
payment_link_config,
session_expiry: request
.session_expiry
.map(i64::from)
.or(Some(common_utils::consts::DEFAULT_SESSION_EXPIRY)),
authentication_connector_details: request
.authentication_connector_details
.map(ForeignInto::foreign_into),
payout_link_config,
is_connector_agnostic_mit_enabled: request.is_connector_agnostic_mit_enabled,
is_extended_card_info_enabled: None,
extended_card_info_config: None,
use_billing_as_payment_method_billing: request
.use_billing_as_payment_method_billing
.or(Some(true)),
collect_shipping_details_from_wallet_connector: request
.collect_shipping_details_from_wallet_connector
.or(Some(false)),
collect_billing_details_from_wallet_connector: request
.collect_billing_details_from_wallet_connector
.or(Some(false)),
always_collect_billing_details_from_wallet_connector: request
.always_collect_billing_details_from_wallet_connector
.or(Some(false)),
always_collect_shipping_details_from_wallet_connector: request
.always_collect_shipping_details_from_wallet_connector
.or(Some(false)),
outgoing_webhook_custom_http_headers: outgoing_webhook_custom_http_headers
.map(Into::into),
tax_connector_id: request.tax_connector_id,
is_tax_connector_enabled: request.is_tax_connector_enabled,
},
))
}

View File

@ -8,7 +8,7 @@ mod merchant_account {
mod business_profile {
pub use hyperswitch_domain_models::business_profile::{
BusinessProfile, BusinessProfileGeneralUpdate, BusinessProfileUpdate,
BusinessProfile, BusinessProfileGeneralUpdate, BusinessProfileSetter, BusinessProfileUpdate,
};
}

View File

@ -98,8 +98,8 @@ pub async fn generate_sample_data(
.attach_printable("Failed to get business profile")?
.first()
.ok_or(SampleDataError::InternalServerError)?
.profile_id
.clone()
.get_id()
.to_owned()
}
};

View File

@ -103,7 +103,7 @@ impl ProcessTrackerWorkflow<SessionState> for OutgoingWebhookRetryWorkflow {
primary_object_type: initial_event.primary_object_type,
created_at: now,
merchant_id: Some(business_profile.merchant_id.clone()),
business_profile_id: Some(business_profile.profile_id.clone()),
business_profile_id: Some(business_profile.get_id().to_owned()),
primary_object_created_at: initial_event.primary_object_created_at,
idempotent_event_id: Some(idempotent_event_id),
initial_attempt_id: Some(initial_event.event_id.clone()),

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE business_profile DROP COLUMN api_version;

View File

@ -0,0 +1,3 @@
-- Your SQL goes here
ALTER TABLE business_profile
ADD COLUMN api_version "ApiVersion" DEFAULT 'v1' NOT NULL;

View File

@ -15,3 +15,14 @@ ALTER TABLE business_profile DROP COLUMN routing_algorithm_id,
DROP COLUMN default_fallback_routing;
DROP TYPE "OrderFulfillmentTimeOrigin";
ALTER TABLE business_profile
ADD COLUMN profile_id VARCHAR(64);
UPDATE business_profile
SET profile_id = id;
ALTER TABLE business_profile DROP COLUMN id;
ALTER TABLE business_profile
ADD PRIMARY KEY (profile_id);

View File

@ -14,3 +14,18 @@ ALTER TABLE business_profile DROP COLUMN routing_algorithm,
DROP COLUMN intent_fulfillment_time,
DROP COLUMN frm_routing_algorithm,
DROP COLUMN payout_routing_algorithm;
-- This migration is to modify the id column in business_profile table to be a VARCHAR(64) and to set the id column as primary key
ALTER TABLE business_profile
ADD COLUMN id VARCHAR(64);
-- Backfill the id column with the profile_id to prevent null values
UPDATE business_profile
SET id = profile_id;
ALTER TABLE business_profile DROP CONSTRAINT business_profile_pkey;
ALTER TABLE business_profile
ADD PRIMARY KEY (id);
ALTER TABLE business_profile DROP COLUMN profile_id;