Skip to content

Commit 85209d1

Browse files
refactor(router): domain and diesel model changes for merchant_connector_account create v2 flow (#5462)
1 parent b4e7717 commit 85209d1

36 files changed

+2105
-472
lines changed

crates/api_models/src/admin.rs

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ pub struct MerchantConnectorResponse {
951951

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

956956
/// Identifier for the business profile, if not provided default will be chosen from merchant account
957957
#[schema(max_length = 64)]
@@ -1032,7 +1032,7 @@ impl MerchantConnectorResponse {
10321032
pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo {
10331033
MerchantConnectorInfo {
10341034
connector_label: connector_label.to_string(),
1035-
merchant_connector_id: self.connector_id.clone(),
1035+
merchant_connector_id: self.id.clone(),
10361036
}
10371037
}
10381038
}
@@ -1162,6 +1162,10 @@ impl MerchantConnectorResponse {
11621162
}
11631163
}
11641164

1165+
#[cfg(all(
1166+
any(feature = "v1", feature = "v2"),
1167+
not(feature = "merchant_connector_account_v2")
1168+
))]
11651169
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
11661170
#[serde(deny_unknown_fields)]
11671171
pub struct MerchantConnectorListResponse {
@@ -1257,6 +1261,10 @@ pub struct MerchantConnectorListResponse {
12571261
pub additional_merchant_data: Option<AdditionalMerchantData>,
12581262
}
12591263

1264+
#[cfg(all(
1265+
any(feature = "v1", feature = "v2"),
1266+
not(feature = "merchant_connector_account_v2")
1267+
))]
12601268
impl MerchantConnectorListResponse {
12611269
pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo {
12621270
MerchantConnectorInfo {
@@ -1266,6 +1274,96 @@ impl MerchantConnectorListResponse {
12661274
}
12671275
}
12681276

1277+
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
1278+
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
1279+
#[serde(deny_unknown_fields)]
1280+
pub struct MerchantConnectorListResponse {
1281+
/// Type of the Connector for the financial use case. Could range from Payments to Accounting to Banking.
1282+
#[schema(value_type = ConnectorType, example = "payment_processor")]
1283+
pub connector_type: api_enums::ConnectorType,
1284+
/// Name of the Connector
1285+
#[schema(value_type = Connector, example = "stripe")]
1286+
pub connector_name: String,
1287+
1288+
/// A unique label to identify the connector account created under a business profile
1289+
#[schema(example = "stripe_US_travel")]
1290+
pub connector_label: Option<String>,
1291+
1292+
/// Unique ID of the merchant connector account
1293+
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
1294+
pub id: String,
1295+
1296+
/// Identifier for the business profile, if not provided default will be chosen from merchant account
1297+
#[schema(max_length = 64)]
1298+
pub profile_id: Option<String>,
1299+
1300+
/// An object containing the details about the payment methods that need to be enabled under this merchant connector account
1301+
#[schema(example = json!([
1302+
{
1303+
"payment_method": "wallet",
1304+
"payment_method_types": [
1305+
"upi_collect",
1306+
"upi_intent"
1307+
],
1308+
"payment_method_issuers": [
1309+
"labore magna ipsum",
1310+
"aute"
1311+
],
1312+
"payment_schemes": [
1313+
"Discover",
1314+
"Discover"
1315+
],
1316+
"accepted_currencies": {
1317+
"type": "enable_only",
1318+
"list": ["USD", "EUR"]
1319+
},
1320+
"accepted_countries": {
1321+
"type": "disable_only",
1322+
"list": ["FR", "DE","IN"]
1323+
},
1324+
"minimum_amount": 1,
1325+
"maximum_amount": 68607706,
1326+
"recurring_enabled": true,
1327+
"installment_payment_enabled": true
1328+
}
1329+
]))]
1330+
pub payment_methods_enabled: Option<Vec<PaymentMethodsEnabled>>,
1331+
1332+
/// 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.
1333+
#[schema(value_type = Option<Object>,max_length = 255,example = json!({ "city": "NY", "unit": "245" }))]
1334+
pub metadata: Option<pii::SecretSerdeValue>,
1335+
1336+
/// A boolean value to indicate if the connector is disabled. By default, its value is false.
1337+
#[schema(default = false, example = false)]
1338+
pub disabled: Option<bool>,
1339+
1340+
/// Contains the frm configs for the merchant connector
1341+
#[schema(example = json!(consts::FRM_CONFIGS_EG))]
1342+
pub frm_configs: Option<Vec<FrmConfigs>>,
1343+
1344+
/// identifier for the verified domains of a particular connector account
1345+
pub applepay_verified_domains: Option<Vec<String>>,
1346+
1347+
#[schema(value_type = Option<Object>)]
1348+
pub pm_auth_config: Option<pii::SecretSerdeValue>,
1349+
1350+
#[schema(value_type = ConnectorStatus, example = "inactive")]
1351+
pub status: api_enums::ConnectorStatus,
1352+
1353+
#[schema(value_type = Option<AdditionalMerchantData>)]
1354+
pub additional_merchant_data: Option<AdditionalMerchantData>,
1355+
}
1356+
1357+
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
1358+
impl MerchantConnectorListResponse {
1359+
pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo {
1360+
MerchantConnectorInfo {
1361+
connector_label: connector_label.to_string(),
1362+
merchant_connector_id: self.id.clone(),
1363+
}
1364+
}
1365+
}
1366+
12691367
/// 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."
12701368
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
12711369
#[serde(deny_unknown_fields)]

crates/diesel_models/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ v1 =[]
1414
v2 = []
1515
customer_v2 = []
1616
merchant_account_v2 = []
17+
merchant_connector_account_v2 = []
1718
payment_v2 = []
1819

1920
[dependencies]

crates/diesel_models/src/merchant_connector_account.rs

Lines changed: 159 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@ use std::fmt::Debug;
22

33
use common_utils::{encryption::Encryption, id_type, pii};
44
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
5-
use masking::Secret;
65

7-
use crate::{enums as storage_enums, schema::merchant_connector_account};
6+
use crate::enums as storage_enums;
7+
#[cfg(all(
8+
any(feature = "v1", feature = "v2"),
9+
not(feature = "merchant_connector_account_v2")
10+
))]
11+
use crate::schema::merchant_connector_account;
12+
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
13+
use crate::schema_v2::merchant_connector_account;
814

15+
#[cfg(all(
16+
any(feature = "v1", feature = "v2"),
17+
not(feature = "merchant_connector_account_v2")
18+
))]
919
#[derive(
1020
Clone,
1121
Debug,
@@ -24,20 +34,20 @@ pub struct MerchantConnectorAccount {
2434
pub test_mode: Option<bool>,
2535
pub disabled: Option<bool>,
2636
pub merchant_connector_id: String,
27-
#[diesel(deserialize_as = super::OptionalDieselArray<serde_json::Value>)]
28-
pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
37+
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
38+
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
2939
pub connector_type: storage_enums::ConnectorType,
3040
pub metadata: Option<pii::SecretSerdeValue>,
3141
pub connector_label: Option<String>,
3242
pub business_country: Option<storage_enums::CountryAlpha2>,
3343
pub business_label: Option<String>,
3444
pub business_sub_label: Option<String>,
35-
pub frm_configs: Option<Secret<serde_json::Value>>,
45+
pub frm_configs: Option<pii::SecretSerdeValue>,
3646
pub created_at: time::PrimitiveDateTime,
3747
pub modified_at: time::PrimitiveDateTime,
3848
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
3949
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
40-
pub frm_config: Option<Vec<Secret<serde_json::Value>>>,
50+
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
4151
pub profile_id: Option<String>,
4252
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
4353
pub applepay_verified_domains: Option<Vec<String>>,
@@ -47,6 +57,64 @@ pub struct MerchantConnectorAccount {
4757
pub connector_wallets_details: Option<Encryption>,
4858
}
4959

60+
#[cfg(all(
61+
any(feature = "v1", feature = "v2"),
62+
not(feature = "merchant_connector_account_v2")
63+
))]
64+
impl MerchantConnectorAccount {
65+
pub fn get_id(&self) -> String {
66+
self.merchant_connector_id.clone()
67+
}
68+
}
69+
70+
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
71+
#[derive(
72+
Clone,
73+
Debug,
74+
serde::Serialize,
75+
serde::Deserialize,
76+
Identifiable,
77+
Queryable,
78+
Selectable,
79+
router_derive::DebugAsDisplay,
80+
)]
81+
#[diesel(table_name = merchant_connector_account, check_for_backend(diesel::pg::Pg))]
82+
pub struct MerchantConnectorAccount {
83+
pub merchant_id: id_type::MerchantId,
84+
pub connector_name: String,
85+
pub connector_account_details: Encryption,
86+
pub disabled: Option<bool>,
87+
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
88+
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
89+
pub connector_type: storage_enums::ConnectorType,
90+
pub metadata: Option<pii::SecretSerdeValue>,
91+
pub connector_label: Option<String>,
92+
pub created_at: time::PrimitiveDateTime,
93+
pub modified_at: time::PrimitiveDateTime,
94+
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
95+
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
96+
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
97+
pub profile_id: Option<String>,
98+
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
99+
pub applepay_verified_domains: Option<Vec<String>>,
100+
pub pm_auth_config: Option<pii::SecretSerdeValue>,
101+
pub status: storage_enums::ConnectorStatus,
102+
pub additional_merchant_data: Option<Encryption>,
103+
pub connector_wallets_details: Option<Encryption>,
104+
pub id: String,
105+
}
106+
107+
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
108+
impl MerchantConnectorAccount {
109+
pub fn get_id(&self) -> String {
110+
self.id.clone()
111+
}
112+
}
113+
114+
#[cfg(all(
115+
any(feature = "v1", feature = "v2"),
116+
not(feature = "merchant_connector_account_v2")
117+
))]
50118
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
51119
#[diesel(table_name = merchant_connector_account)]
52120
pub struct MerchantConnectorAccountNew {
@@ -57,27 +125,58 @@ pub struct MerchantConnectorAccountNew {
57125
pub test_mode: Option<bool>,
58126
pub disabled: Option<bool>,
59127
pub merchant_connector_id: String,
60-
pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
128+
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
61129
pub metadata: Option<pii::SecretSerdeValue>,
62130
pub connector_label: Option<String>,
63131
pub business_country: Option<storage_enums::CountryAlpha2>,
64132
pub business_label: Option<String>,
65133
pub business_sub_label: Option<String>,
66-
pub frm_configs: Option<Secret<serde_json::Value>>,
134+
pub frm_configs: Option<pii::SecretSerdeValue>,
135+
pub created_at: time::PrimitiveDateTime,
136+
pub modified_at: time::PrimitiveDateTime,
137+
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
138+
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
139+
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
140+
pub profile_id: Option<String>,
141+
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
142+
pub applepay_verified_domains: Option<Vec<String>>,
143+
pub pm_auth_config: Option<pii::SecretSerdeValue>,
144+
pub status: storage_enums::ConnectorStatus,
145+
pub additional_merchant_data: Option<Encryption>,
146+
pub connector_wallets_details: Option<Encryption>,
147+
}
148+
149+
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
150+
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
151+
#[diesel(table_name = merchant_connector_account)]
152+
pub struct MerchantConnectorAccountNew {
153+
pub merchant_id: Option<id_type::MerchantId>,
154+
pub connector_type: Option<storage_enums::ConnectorType>,
155+
pub connector_name: Option<String>,
156+
pub connector_account_details: Option<Encryption>,
157+
pub disabled: Option<bool>,
158+
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
159+
pub metadata: Option<pii::SecretSerdeValue>,
160+
pub connector_label: Option<String>,
67161
pub created_at: time::PrimitiveDateTime,
68162
pub modified_at: time::PrimitiveDateTime,
69163
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
70164
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
71-
pub frm_config: Option<Vec<Secret<serde_json::Value>>>,
165+
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
72166
pub profile_id: Option<String>,
73167
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
74168
pub applepay_verified_domains: Option<Vec<String>>,
75169
pub pm_auth_config: Option<pii::SecretSerdeValue>,
76170
pub status: storage_enums::ConnectorStatus,
77171
pub additional_merchant_data: Option<Encryption>,
78172
pub connector_wallets_details: Option<Encryption>,
173+
pub id: String,
79174
}
80175

176+
#[cfg(all(
177+
any(feature = "v1", feature = "v2"),
178+
not(feature = "merchant_connector_account_v2")
179+
))]
81180
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
82181
#[diesel(table_name = merchant_connector_account)]
83182
pub struct MerchantConnectorAccountUpdateInternal {
@@ -88,20 +187,45 @@ pub struct MerchantConnectorAccountUpdateInternal {
88187
pub test_mode: Option<bool>,
89188
pub disabled: Option<bool>,
90189
pub merchant_connector_id: Option<String>,
91-
pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
92-
pub frm_configs: Option<Secret<serde_json::Value>>,
190+
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
191+
pub frm_configs: Option<pii::SecretSerdeValue>,
93192
pub metadata: Option<pii::SecretSerdeValue>,
94193
pub modified_at: Option<time::PrimitiveDateTime>,
95194
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
96195
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
97-
pub frm_config: Option<Vec<Secret<serde_json::Value>>>,
196+
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
98197
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
99198
pub applepay_verified_domains: Option<Vec<String>>,
100199
pub pm_auth_config: Option<pii::SecretSerdeValue>,
101200
pub status: Option<storage_enums::ConnectorStatus>,
102201
pub connector_wallets_details: Option<Encryption>,
103202
}
104203

204+
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
205+
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
206+
#[diesel(table_name = merchant_connector_account)]
207+
pub struct MerchantConnectorAccountUpdateInternal {
208+
pub connector_type: Option<storage_enums::ConnectorType>,
209+
pub connector_account_details: Option<Encryption>,
210+
pub connector_label: Option<String>,
211+
pub disabled: Option<bool>,
212+
pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
213+
pub metadata: Option<pii::SecretSerdeValue>,
214+
pub modified_at: Option<time::PrimitiveDateTime>,
215+
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
216+
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
217+
pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
218+
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
219+
pub applepay_verified_domains: Option<Vec<String>>,
220+
pub pm_auth_config: Option<pii::SecretSerdeValue>,
221+
pub status: Option<storage_enums::ConnectorStatus>,
222+
pub connector_wallets_details: Option<Encryption>,
223+
}
224+
225+
#[cfg(all(
226+
any(feature = "v1", feature = "v2"),
227+
not(feature = "merchant_connector_account_v2")
228+
))]
105229
impl MerchantConnectorAccountUpdateInternal {
106230
pub fn create_merchant_connector_account(
107231
self,
@@ -128,3 +252,26 @@ impl MerchantConnectorAccountUpdateInternal {
128252
}
129253
}
130254
}
255+
256+
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
257+
impl MerchantConnectorAccountUpdateInternal {
258+
pub fn create_merchant_connector_account(
259+
self,
260+
source: MerchantConnectorAccount,
261+
) -> MerchantConnectorAccount {
262+
MerchantConnectorAccount {
263+
connector_type: self.connector_type.unwrap_or(source.connector_type),
264+
connector_account_details: self
265+
.connector_account_details
266+
.unwrap_or(source.connector_account_details),
267+
disabled: self.disabled,
268+
payment_methods_enabled: self.payment_methods_enabled,
269+
frm_config: self.frm_config,
270+
modified_at: self.modified_at.unwrap_or(source.modified_at),
271+
pm_auth_config: self.pm_auth_config,
272+
status: self.status.unwrap_or(source.status),
273+
274+
..source
275+
}
276+
}
277+
}

0 commit comments

Comments
 (0)