-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathmerchant_connector_account.rs
304 lines (286 loc) · 13.2 KB
/
merchant_connector_account.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#[cfg(feature = "v2")]
use std::collections::HashMap;
use std::fmt::Debug;
use common_utils::{encryption::Encryption, id_type, pii};
#[cfg(feature = "v2")]
use diesel::{sql_types::Jsonb, AsExpression};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use crate::enums as storage_enums;
#[cfg(feature = "v1")]
use crate::schema::merchant_connector_account;
#[cfg(feature = "v2")]
use crate::{enums, schema_v2::merchant_connector_account, types};
#[cfg(feature = "v1")]
#[derive(
Clone,
Debug,
serde::Serialize,
serde::Deserialize,
Identifiable,
Queryable,
Selectable,
router_derive::DebugAsDisplay,
)]
#[diesel(table_name = merchant_connector_account, primary_key(merchant_connector_id), 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 test_mode: Option<bool>,
pub disabled: Option<bool>,
pub merchant_connector_id: id_type::MerchantConnectorAccountId,
#[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<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<id_type::ProfileId>,
#[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 version: common_enums::ApiVersion,
pub id: Option<id_type::MerchantConnectorAccountId>,
}
#[cfg(feature = "v1")]
impl MerchantConnectorAccount {
pub fn get_id(&self) -> id_type::MerchantConnectorAccountId {
self.merchant_connector_id.clone()
}
}
#[cfg(feature = "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: common_enums::connector_enums::Connector,
pub connector_account_details: Encryption,
pub disabled: Option<bool>,
#[diesel(deserialize_as = super::OptionalDieselArray<common_types::payment_methods::PaymentMethodsEnabled>)]
pub payment_methods_enabled: Option<Vec<common_types::payment_methods::PaymentMethodsEnabled>>,
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: id_type::ProfileId,
#[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 version: common_enums::ApiVersion,
pub id: id_type::MerchantConnectorAccountId,
pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
}
#[cfg(feature = "v2")]
impl MerchantConnectorAccount {
pub fn get_id(&self) -> id_type::MerchantConnectorAccountId {
self.id.clone()
}
}
#[cfg(feature = "v1")]
#[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 test_mode: Option<bool>,
pub disabled: Option<bool>,
pub merchant_connector_id: id_type::MerchantConnectorAccountId,
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<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<id_type::ProfileId>,
#[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 version: common_enums::ApiVersion,
pub id: Option<id_type::MerchantConnectorAccountId>,
}
#[cfg(feature = "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<common_enums::connector_enums::Connector>,
pub connector_account_details: Option<Encryption>,
pub disabled: Option<bool>,
#[diesel(deserialize_as = super::OptionalDieselArray<common_types::payment_methods::PaymentMethodsEnabled>)]
pub payment_methods_enabled: Option<Vec<common_types::payment_methods::PaymentMethodsEnabled>>,
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: id_type::ProfileId,
#[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 version: common_enums::ApiVersion,
pub id: id_type::MerchantConnectorAccountId,
pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
}
#[cfg(feature = "v1")]
#[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_name: Option<String>,
pub connector_account_details: Option<Encryption>,
pub connector_label: Option<String>,
pub test_mode: Option<bool>,
pub disabled: Option<bool>,
pub merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
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<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>,
pub additional_merchant_data: Option<Encryption>,
}
#[cfg(feature = "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>,
#[diesel(deserialize_as = super::OptionalDieselArray<common_types::payment_methods::PaymentMethodsEnabled>)]
pub payment_methods_enabled: Option<Vec<common_types::payment_methods::PaymentMethodsEnabled>>,
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>,
pub additional_merchant_data: Option<Encryption>,
pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
}
#[cfg(feature = "v1")]
impl MerchantConnectorAccountUpdateInternal {
pub fn create_merchant_connector_account(
self,
source: MerchantConnectorAccount,
) -> MerchantConnectorAccount {
MerchantConnectorAccount {
merchant_id: source.merchant_id,
connector_type: self.connector_type.unwrap_or(source.connector_type),
connector_account_details: self
.connector_account_details
.unwrap_or(source.connector_account_details),
test_mode: self.test_mode,
disabled: self.disabled,
merchant_connector_id: self
.merchant_connector_id
.unwrap_or(source.merchant_connector_id),
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
}
}
}
#[cfg(feature = "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),
feature_metadata: self.feature_metadata,
..source
}
}
}
#[cfg(feature = "v2")]
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, AsExpression)]
#[diesel(sql_type = Jsonb)]
pub struct MerchantConnectorAccountFeatureMetadata {
pub revenue_recovery: Option<RevenueRecoveryMetadata>,
}
#[cfg(feature = "v2")]
common_utils::impl_to_sql_from_sql_json!(MerchantConnectorAccountFeatureMetadata);
#[cfg(feature = "v2")]
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RevenueRecoveryMetadata {
/// The maximum number of retries allowed for an invoice. This limit is set by the merchant for each `billing connector`.Once this limit is reached, no further retries will be attempted.
pub max_retry_count: u16,
/// Maximum number of `billing connector` retries before revenue recovery can start executing retries.
pub billing_connector_retry_threshold: u16,
/// Billing account reference id is payment gateway id at billing connector end.
/// Merchants need to provide a mapping between these merchant connector account and the corresponding
/// account reference IDs for each `billing connector`.
pub billing_account_reference: BillingAccountReference,
}
#[cfg(feature = "v2")]
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct BillingAccountReference(pub HashMap<id_type::MerchantConnectorAccountId, String>);