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
102 changes: 100 additions & 2 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ pub struct MerchantConnectorResponse {

/// Unique ID of the merchant connector account
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub connector_id: String,
pub id: String,

/// Identifier for the business profile, if not provided default will be chosen from merchant account
#[schema(max_length = 64)]
Expand Down Expand Up @@ -1032,7 +1032,7 @@ impl MerchantConnectorResponse {
pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo {
MerchantConnectorInfo {
connector_label: connector_label.to_string(),
merchant_connector_id: self.connector_id.clone(),
merchant_connector_id: self.id.clone(),
}
}
}
Expand Down Expand Up @@ -1162,6 +1162,10 @@ impl MerchantConnectorResponse {
}
}

#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_connector_account_v2")
))]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct MerchantConnectorListResponse {
Expand Down Expand Up @@ -1257,6 +1261,10 @@ pub struct MerchantConnectorListResponse {
pub additional_merchant_data: Option<AdditionalMerchantData>,
}

#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_connector_account_v2")
))]
impl MerchantConnectorListResponse {
pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo {
MerchantConnectorInfo {
Expand All @@ -1266,6 +1274,96 @@ impl MerchantConnectorListResponse {
}
}

#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct MerchantConnectorListResponse {
/// Type of the Connector for the financial use case. Could range from Payments to Accounting to Banking.
#[schema(value_type = ConnectorType, example = "payment_processor")]
pub connector_type: api_enums::ConnectorType,
/// Name of the Connector
#[schema(value_type = Connector, example = "stripe")]
pub connector_name: String,

/// A unique label to identify the connector account created under a business profile
#[schema(example = "stripe_US_travel")]
pub connector_label: Option<String>,

/// Unique ID of the merchant connector account
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub id: String,

/// Identifier for the business profile, if not provided default will be chosen from merchant account
#[schema(max_length = 64)]
pub profile_id: Option<String>,

/// An object containing the details about the payment methods that need to be enabled under this merchant connector account
#[schema(example = json!([
{
"payment_method": "wallet",
"payment_method_types": [
"upi_collect",
"upi_intent"
],
"payment_method_issuers": [
"labore magna ipsum",
"aute"
],
"payment_schemes": [
"Discover",
"Discover"
],
"accepted_currencies": {
"type": "enable_only",
"list": ["USD", "EUR"]
},
"accepted_countries": {
"type": "disable_only",
"list": ["FR", "DE","IN"]
},
"minimum_amount": 1,
"maximum_amount": 68607706,
"recurring_enabled": true,
"installment_payment_enabled": true
}
]))]
pub payment_methods_enabled: Option<Vec<PaymentMethodsEnabled>>,

/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>,max_length = 255,example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,

/// A boolean value to indicate if the connector is disabled. By default, its value is false.
#[schema(default = false, example = false)]
pub disabled: Option<bool>,

/// Contains the frm configs for the merchant connector
#[schema(example = json!(consts::FRM_CONFIGS_EG))]
pub frm_configs: Option<Vec<FrmConfigs>>,

/// identifier for the verified domains of a particular connector account
pub applepay_verified_domains: Option<Vec<String>>,

#[schema(value_type = Option<Object>)]
pub pm_auth_config: Option<pii::SecretSerdeValue>,

#[schema(value_type = ConnectorStatus, example = "inactive")]
pub status: api_enums::ConnectorStatus,

#[schema(value_type = Option<AdditionalMerchantData>)]
pub additional_merchant_data: Option<AdditionalMerchantData>,
}

#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
impl MerchantConnectorListResponse {
pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo {
MerchantConnectorInfo {
connector_label: connector_label.to_string(),
merchant_connector_id: self.id.clone(),
}
}
}

/// Create a new Merchant Connector for the merchant account. The connector could be a payment processor / facilitator / acquirer or specialized services like Fraud / Accounting etc."
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(deny_unknown_fields)]
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ v1 =[]
v2 = []
customer_v2 = []
merchant_account_v2 = []
merchant_connector_account_v2 = []
payment_v2 = []

[dependencies]
Expand Down
171 changes: 159 additions & 12 deletions crates/diesel_models/src/merchant_connector_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ use std::fmt::Debug;

use common_utils::{encryption::Encryption, id_type, pii};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use masking::Secret;

use crate::{enums as storage_enums, schema::merchant_connector_account};
use crate::enums as storage_enums;
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_connector_account_v2")
))]
use crate::schema::merchant_connector_account;
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
use crate::schema_v2::merchant_connector_account;

#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_connector_account_v2")
))]
#[derive(
Clone,
Debug,
Expand All @@ -24,20 +34,20 @@ pub struct MerchantConnectorAccount {
pub test_mode: Option<bool>,
pub disabled: Option<bool>,
pub merchant_connector_id: String,
#[diesel(deserialize_as = super::OptionalDieselArray<serde_json::Value>)]
pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
pub connector_type: storage_enums::ConnectorType,
pub metadata: Option<pii::SecretSerdeValue>,
pub connector_label: Option<String>,
pub business_country: Option<storage_enums::CountryAlpha2>,
pub business_label: Option<String>,
pub business_sub_label: Option<String>,
pub frm_configs: Option<Secret<serde_json::Value>>,
pub frm_configs: Option<pii::SecretSerdeValue>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub frm_config: Option<Vec<Secret<serde_json::Value>>>,
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
pub profile_id: Option<String>,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
Expand All @@ -47,6 +57,64 @@ pub struct MerchantConnectorAccount {
pub connector_wallets_details: Option<Encryption>,
}

#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_connector_account_v2")
))]
impl MerchantConnectorAccount {
pub fn get_id(&self) -> String {
self.merchant_connector_id.clone()
}
}

#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
#[derive(
Clone,
Debug,
serde::Serialize,
serde::Deserialize,
Identifiable,
Queryable,
Selectable,
router_derive::DebugAsDisplay,
)]
#[diesel(table_name = merchant_connector_account, check_for_backend(diesel::pg::Pg))]
pub struct MerchantConnectorAccount {
pub merchant_id: id_type::MerchantId,
pub connector_name: String,
pub connector_account_details: Encryption,
pub disabled: Option<bool>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
pub connector_type: storage_enums::ConnectorType,
pub metadata: Option<pii::SecretSerdeValue>,
pub connector_label: Option<String>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
pub profile_id: Option<String>,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
pub pm_auth_config: Option<pii::SecretSerdeValue>,
pub status: storage_enums::ConnectorStatus,
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
pub id: String,
}

#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
impl MerchantConnectorAccount {
pub fn get_id(&self) -> String {
self.id.clone()
}
}

#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_connector_account_v2")
))]
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_connector_account)]
pub struct MerchantConnectorAccountNew {
Expand All @@ -57,27 +125,58 @@ pub struct MerchantConnectorAccountNew {
pub test_mode: Option<bool>,
pub disabled: Option<bool>,
pub merchant_connector_id: String,
pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
pub metadata: Option<pii::SecretSerdeValue>,
pub connector_label: Option<String>,
pub business_country: Option<storage_enums::CountryAlpha2>,
pub business_label: Option<String>,
pub business_sub_label: Option<String>,
pub frm_configs: Option<Secret<serde_json::Value>>,
pub frm_configs: Option<pii::SecretSerdeValue>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
pub profile_id: Option<String>,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
pub pm_auth_config: Option<pii::SecretSerdeValue>,
pub status: storage_enums::ConnectorStatus,
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
}

#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_connector_account)]
pub struct MerchantConnectorAccountNew {
pub merchant_id: Option<id_type::MerchantId>,
pub connector_type: Option<storage_enums::ConnectorType>,
pub connector_name: Option<String>,
pub connector_account_details: Option<Encryption>,
pub disabled: Option<bool>,
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
pub metadata: Option<pii::SecretSerdeValue>,
pub connector_label: Option<String>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub frm_config: Option<Vec<Secret<serde_json::Value>>>,
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
pub profile_id: Option<String>,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
pub pm_auth_config: Option<pii::SecretSerdeValue>,
pub status: storage_enums::ConnectorStatus,
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
pub id: String,
}

#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_connector_account_v2")
))]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_connector_account)]
pub struct MerchantConnectorAccountUpdateInternal {
Expand All @@ -88,20 +187,45 @@ pub struct MerchantConnectorAccountUpdateInternal {
pub test_mode: Option<bool>,
pub disabled: Option<bool>,
pub merchant_connector_id: Option<String>,
pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
pub frm_configs: Option<Secret<serde_json::Value>>,
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
pub frm_configs: Option<pii::SecretSerdeValue>,
pub metadata: Option<pii::SecretSerdeValue>,
pub modified_at: Option<time::PrimitiveDateTime>,
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub frm_config: Option<Vec<Secret<serde_json::Value>>>,
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
pub pm_auth_config: Option<pii::SecretSerdeValue>,
pub status: Option<storage_enums::ConnectorStatus>,
pub connector_wallets_details: Option<Encryption>,
}

#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_connector_account)]
pub struct MerchantConnectorAccountUpdateInternal {
pub connector_type: Option<storage_enums::ConnectorType>,
pub connector_account_details: Option<Encryption>,
pub connector_label: Option<String>,
pub disabled: Option<bool>,
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
pub metadata: Option<pii::SecretSerdeValue>,
pub modified_at: Option<time::PrimitiveDateTime>,
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
pub pm_auth_config: Option<pii::SecretSerdeValue>,
pub status: Option<storage_enums::ConnectorStatus>,
pub connector_wallets_details: Option<Encryption>,
}

#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_connector_account_v2")
))]
impl MerchantConnectorAccountUpdateInternal {
pub fn create_merchant_connector_account(
self,
Expand All @@ -128,3 +252,26 @@ impl MerchantConnectorAccountUpdateInternal {
}
}
}

#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
impl MerchantConnectorAccountUpdateInternal {
pub fn create_merchant_connector_account(
self,
source: MerchantConnectorAccount,
) -> MerchantConnectorAccount {
MerchantConnectorAccount {
connector_type: self.connector_type.unwrap_or(source.connector_type),
connector_account_details: self
.connector_account_details
.unwrap_or(source.connector_account_details),
disabled: self.disabled,
payment_methods_enabled: self.payment_methods_enabled,
frm_config: self.frm_config,
modified_at: self.modified_at.unwrap_or(source.modified_at),
pm_auth_config: self.pm_auth_config,
status: self.status.unwrap_or(source.status),

..source
}
}
}
Loading
Loading