Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions crates/common_types/src/payment_methods.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
//! Common types to be used in payment methods

use diesel::{
backend::Backend, deserialize, deserialize::FromSql, sql_types::Jsonb, AsExpression, Queryable,
backend::Backend,
deserialize,
deserialize::FromSql,
sql_types::{Json, Jsonb},
AsExpression, Queryable,
};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// Details of all the payment methods enabled for the connector for the given merchant account

// sql_type for this can be json instead of jsonb. This is because validation at database is not required since it will always be written by the application.
// This is a performance optimization to avoid json validation at database level.
// jsonb enables faster querying on json columns, but it doesn't justify here since we are not querying on this column.
// https://docs.rs/diesel/latest/diesel/sql_types/struct.Jsonb.html
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, AsExpression)]
#[serde(deny_unknown_fields)]
#[diesel(sql_type = Jsonb)]
#[diesel(sql_type = Json)]
pub struct PaymentMethodsEnabled {
/// Type of payment method.
#[schema(value_type = PaymentMethod,example = "card")]
Expand Down
5 changes: 4 additions & 1 deletion crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub struct Profile {
pub force_3ds_challenge: Option<bool>,
pub is_debit_routing_enabled: bool,
pub merchant_business_country: Option<common_enums::CountryAlpha2>,
pub id: Option<common_utils::id_type::ProfileId>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -120,6 +121,7 @@ pub struct ProfileNew {
pub force_3ds_challenge: Option<bool>,
pub is_debit_routing_enabled: bool,
pub merchant_business_country: Option<common_enums::CountryAlpha2>,
pub id: Option<common_utils::id_type::ProfileId>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -289,6 +291,7 @@ impl ProfileUpdateInternal {
is_clear_pan_retries_enabled: is_clear_pan_retries_enabled
.unwrap_or(source.is_clear_pan_retries_enabled),
force_3ds_challenge,
id: source.id,
is_debit_routing_enabled,
merchant_business_country: merchant_business_country
.or(source.merchant_business_country),
Expand Down Expand Up @@ -348,6 +351,7 @@ pub struct Profile {
pub force_3ds_challenge: Option<bool>,
pub is_debit_routing_enabled: bool,
pub merchant_business_country: Option<common_enums::CountryAlpha2>,
pub id: common_utils::id_type::ProfileId,
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>,
Expand All @@ -356,7 +360,6 @@ pub struct Profile {
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub three_ds_decision_manager_config: Option<common_types::payments::DecisionManagerRecord>,
pub should_collect_cvv_during_payment: bool,
pub id: common_utils::id_type::ProfileId,
}

impl Profile {
Expand Down
6 changes: 4 additions & 2 deletions crates/diesel_models/src/merchant_connector_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct MerchantConnectorAccount {
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
pub version: common_enums::ApiVersion,
pub id: Option<id_type::MerchantConnectorAccountId>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -98,8 +99,8 @@ pub struct MerchantConnectorAccount {
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
pub version: common_enums::ApiVersion,
pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
pub id: id_type::MerchantConnectorAccountId,
pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -140,6 +141,7 @@ pub struct MerchantConnectorAccountNew {
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
pub version: common_enums::ApiVersion,
pub id: Option<id_type::MerchantConnectorAccountId>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -167,8 +169,8 @@ pub struct MerchantConnectorAccountNew {
pub status: storage_enums::ConnectorStatus,
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
pub id: id_type::MerchantConnectorAccountId,
pub version: common_enums::ApiVersion,
pub id: id_type::MerchantConnectorAccountId,
pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
}

Expand Down
4 changes: 4 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ diesel::table! {
force_3ds_challenge -> Nullable<Bool>,
is_debit_routing_enabled -> Bool,
merchant_business_country -> Nullable<CountryAlpha2>,
#[max_length = 64]
id -> Nullable<Varchar>,
}
}

Expand Down Expand Up @@ -788,6 +790,8 @@ diesel::table! {
additional_merchant_data -> Nullable<Bytea>,
connector_wallets_details -> Nullable<Bytea>,
version -> ApiVersion,
#[max_length = 64]
id -> Nullable<Varchar>,
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ diesel::table! {
is_debit_routing_enabled -> Bool,
merchant_business_country -> Nullable<CountryAlpha2>,
#[max_length = 64]
id -> Varchar,
#[max_length = 64]
routing_algorithm_id -> Nullable<Varchar>,
order_fulfillment_time -> Nullable<Int8>,
order_fulfillment_time_origin -> Nullable<OrderFulfillmentTimeOrigin>,
Expand All @@ -230,8 +232,6 @@ diesel::table! {
default_fallback_routing -> Nullable<Jsonb>,
three_ds_decision_manager_config -> Nullable<Jsonb>,
should_collect_cvv_during_payment -> Bool,
#[max_length = 64]
id -> Varchar,
}
}

Expand Down Expand Up @@ -750,7 +750,7 @@ diesel::table! {
connector_name -> Varchar,
connector_account_details -> Bytea,
disabled -> Nullable<Bool>,
payment_methods_enabled -> Nullable<Array<Nullable<Jsonb>>>,
payment_methods_enabled -> Nullable<Array<Nullable<Json>>>,
connector_type -> ConnectorType,
metadata -> Nullable<Jsonb>,
#[max_length = 255]
Expand All @@ -767,9 +767,9 @@ diesel::table! {
additional_merchant_data -> Nullable<Bytea>,
connector_wallets_details -> Nullable<Bytea>,
version -> ApiVersion,
feature_metadata -> Nullable<Jsonb>,
#[max_length = 64]
id -> Varchar,
feature_metadata -> Nullable<Jsonb>,
}
}

Expand Down
6 changes: 4 additions & 2 deletions crates/hyperswitch_domain_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ impl super::behaviour::Conversion for Profile {

async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
Ok(diesel_models::business_profile::Profile {
profile_id: self.profile_id,
profile_id: self.profile_id.clone(),
id: Some(self.profile_id),
merchant_id: self.merchant_id,
profile_name: self.profile_name,
created_at: self.created_at,
Expand Down Expand Up @@ -793,7 +794,8 @@ impl super::behaviour::Conversion for Profile {

async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
Ok(diesel_models::business_profile::ProfileNew {
profile_id: self.profile_id,
profile_id: self.profile_id.clone(),
id: Some(self.profile_id),
merchant_id: self.merchant_id,
profile_name: self.profile_name,
created_at: self.created_at,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ impl behaviour::Conversion for MerchantConnectorAccount {
connector_account_details: self.connector_account_details.into(),
test_mode: self.test_mode,
disabled: self.disabled,
merchant_connector_id: self.merchant_connector_id,
merchant_connector_id: self.merchant_connector_id.clone(),
id: Some(self.merchant_connector_id),
payment_methods_enabled: self.payment_methods_enabled,
connector_type: self.connector_type,
metadata: self.metadata,
Expand Down Expand Up @@ -452,7 +453,8 @@ impl behaviour::Conversion for MerchantConnectorAccount {
connector_account_details: Some(self.connector_account_details.into()),
test_mode: self.test_mode,
disabled: self.disabled,
merchant_connector_id: self.merchant_connector_id,
merchant_connector_id: self.merchant_connector_id.clone(),
id: Some(self.merchant_connector_id),
payment_methods_enabled: self.payment_methods_enabled,
connector_type: Some(self.connector_type),
metadata: self.metadata,
Expand Down
9 changes: 8 additions & 1 deletion crates/router/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ pub trait GlobalStorageInterface:

#[async_trait::async_trait]
pub trait AccountsStorageInterface:
Send + Sync + dyn_clone::DynClone + OrganizationInterface + 'static
Send
+ Sync
+ dyn_clone::DynClone
+ OrganizationInterface
+ merchant_account::MerchantAccountInterface
+ business_profile::ProfileInterface
+ merchant_connector_account::MerchantConnectorAccountInterface
+ 'static
{
}

Expand Down
14 changes: 7 additions & 7 deletions crates/router/src/db/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl ProfileInterface for Store {
merchant_key_store: &domain::MerchantKeyStore,
business_profile: domain::Profile,
) -> CustomResult<domain::Profile, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
business_profile
.construct_new()
.await
Expand All @@ -106,7 +106,7 @@ impl ProfileInterface for Store {
merchant_key_store: &domain::MerchantKeyStore,
profile_id: &common_utils::id_type::ProfileId,
) -> CustomResult<domain::Profile, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::Profile::find_by_profile_id(&conn, profile_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))?
Expand All @@ -126,7 +126,7 @@ impl ProfileInterface for Store {
merchant_id: &common_utils::id_type::MerchantId,
profile_id: &common_utils::id_type::ProfileId,
) -> CustomResult<domain::Profile, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::Profile::find_by_merchant_id_profile_id(&conn, merchant_id, profile_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))?
Expand All @@ -147,7 +147,7 @@ impl ProfileInterface for Store {
profile_name: &str,
merchant_id: &common_utils::id_type::MerchantId,
) -> CustomResult<domain::Profile, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::Profile::find_by_profile_name_merchant_id(&conn, profile_name, merchant_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))?
Expand All @@ -168,7 +168,7 @@ impl ProfileInterface for Store {
current_state: domain::Profile,
profile_update: domain::ProfileUpdate,
) -> CustomResult<domain::Profile, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
Conversion::convert(current_state)
.await
.change_context(errors::StorageError::EncryptionError)?
Expand All @@ -190,7 +190,7 @@ impl ProfileInterface for Store {
profile_id: &common_utils::id_type::ProfileId,
merchant_id: &common_utils::id_type::MerchantId,
) -> CustomResult<bool, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
storage::Profile::delete_by_profile_id_merchant_id(&conn, profile_id, merchant_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
Expand All @@ -203,7 +203,7 @@ impl ProfileInterface for Store {
merchant_key_store: &domain::MerchantKeyStore,
merchant_id: &common_utils::id_type::MerchantId,
) -> CustomResult<Vec<domain::Profile>, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::Profile::list_profile_by_merchant_id(&conn, merchant_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
Expand Down
20 changes: 10 additions & 10 deletions crates/router/src/db/merchant_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl MerchantAccountInterface for Store {
merchant_account: domain::MerchantAccount,
merchant_key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantAccount, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
merchant_account
.construct_new()
.await
Expand All @@ -137,7 +137,7 @@ impl MerchantAccountInterface for Store {
merchant_key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantAccount, errors::StorageError> {
let fetch_func = || async {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::MerchantAccount::find_by_merchant_id(&conn, merchant_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
Expand Down Expand Up @@ -183,7 +183,7 @@ impl MerchantAccountInterface for Store {
merchant_account: storage::MerchantAccountUpdate,
merchant_key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantAccount, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;

let updated_merchant_account = Conversion::convert(this)
.await
Expand Down Expand Up @@ -214,7 +214,7 @@ impl MerchantAccountInterface for Store {
merchant_account: storage::MerchantAccountUpdate,
merchant_key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantAccount, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
let updated_merchant_account = storage::MerchantAccount::update_with_specific_fields(
&conn,
merchant_id,
Expand Down Expand Up @@ -245,7 +245,7 @@ impl MerchantAccountInterface for Store {
) -> CustomResult<(domain::MerchantAccount, domain::MerchantKeyStore), errors::StorageError>
{
let fetch_by_pub_key_func = || async {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;

storage::MerchantAccount::find_by_publishable_key(&conn, publishable_key)
.await
Expand Down Expand Up @@ -294,7 +294,7 @@ impl MerchantAccountInterface for Store {
organization_id: &common_utils::id_type::OrganizationId,
) -> CustomResult<Vec<domain::MerchantAccount>, errors::StorageError> {
use futures::future::try_join_all;
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;

let encrypted_merchant_accounts =
storage::MerchantAccount::list_by_organization_id(&conn, organization_id)
Expand Down Expand Up @@ -338,7 +338,7 @@ impl MerchantAccountInterface for Store {
&self,
merchant_id: &common_utils::id_type::MerchantId,
) -> CustomResult<bool, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;

let is_deleted_func = || async {
storage::MerchantAccount::delete_by_merchant_id(&conn, merchant_id)
Expand Down Expand Up @@ -375,7 +375,7 @@ impl MerchantAccountInterface for Store {
state: &KeyManagerState,
merchant_ids: Vec<common_utils::id_type::MerchantId>,
) -> CustomResult<Vec<domain::MerchantAccount>, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;

let encrypted_merchant_accounts =
storage::MerchantAccount::list_multiple_merchant_accounts(&conn, merchant_ids)
Expand Down Expand Up @@ -439,7 +439,7 @@ impl MerchantAccountInterface for Store {
)>,
errors::StorageError,
> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
let encrypted_merchant_accounts =
storage::MerchantAccount::list_all_merchant_accounts(&conn, limit, offset)
.await
Expand All @@ -460,7 +460,7 @@ impl MerchantAccountInterface for Store {
&self,
merchant_account: storage::MerchantAccountUpdate,
) -> CustomResult<usize, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;

let db_func = || async {
storage::MerchantAccount::update_all_merchant_accounts(
Expand Down
Loading
Loading