@@ -6,7 +6,7 @@ use time::PrimitiveDateTime;
6
6
7
7
use crate :: { encryption:: Encryption , enums as storage_enums, schema:: payment_methods} ;
8
8
9
- #[ derive( Clone , Debug , Eq , PartialEq , Identifiable , Queryable ) ]
9
+ #[ derive( Clone , Debug , Eq , PartialEq , Identifiable , Queryable , Serialize , Deserialize ) ]
10
10
#[ diesel( table_name = payment_methods) ]
11
11
pub struct PaymentMethod {
12
12
pub id : i32 ,
@@ -41,7 +41,9 @@ pub struct PaymentMethod {
41
41
pub network_transaction_id : Option < String > ,
42
42
}
43
43
44
- #[ derive( Clone , Debug , Eq , PartialEq , Insertable , router_derive:: DebugAsDisplay ) ]
44
+ #[ derive(
45
+ Clone , Debug , Eq , PartialEq , Insertable , router_derive:: DebugAsDisplay , Serialize , Deserialize ,
46
+ ) ]
45
47
#[ diesel( table_name = payment_methods) ]
46
48
pub struct PaymentMethodNew {
47
49
pub customer_id : String ,
@@ -138,7 +140,9 @@ pub enum PaymentMethodUpdate {
138
140
} ,
139
141
}
140
142
141
- #[ derive( Clone , Debug , Default , AsChangeset , router_derive:: DebugAsDisplay ) ]
143
+ #[ derive(
144
+ Clone , Debug , Default , AsChangeset , router_derive:: DebugAsDisplay , Serialize , Deserialize ,
145
+ ) ]
142
146
#[ diesel( table_name = payment_methods) ]
143
147
pub struct PaymentMethodUpdateInternal {
144
148
metadata : Option < serde_json:: Value > ,
@@ -155,6 +159,29 @@ impl PaymentMethodUpdateInternal {
155
159
156
160
PaymentMethod { metadata, ..source }
157
161
}
162
+
163
+ pub fn apply_changeset ( self , source : PaymentMethod ) -> PaymentMethod {
164
+ let Self {
165
+ metadata,
166
+ payment_method_data,
167
+ last_used_at,
168
+ network_transaction_id,
169
+ status,
170
+ connector_mandate_details,
171
+ } = self ;
172
+
173
+ PaymentMethod {
174
+ metadata : metadata. map_or ( source. metadata , |v| Some ( v. into ( ) ) ) ,
175
+ payment_method_data : payment_method_data. map_or ( source. payment_method_data , Some ) ,
176
+ last_used_at : last_used_at. unwrap_or ( source. last_used_at ) ,
177
+ network_transaction_id : network_transaction_id
178
+ . map_or ( source. network_transaction_id , Some ) ,
179
+ status : status. unwrap_or ( source. status ) ,
180
+ connector_mandate_details : connector_mandate_details
181
+ . map_or ( source. connector_mandate_details , Some ) ,
182
+ ..source
183
+ }
184
+ }
158
185
}
159
186
160
187
impl From < PaymentMethodUpdate > for PaymentMethodUpdateInternal {
@@ -218,3 +245,38 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
218
245
}
219
246
}
220
247
}
248
+
249
+ impl From < & PaymentMethodNew > for PaymentMethod {
250
+ fn from ( payment_method_new : & PaymentMethodNew ) -> Self {
251
+ Self {
252
+ id : 0i32 ,
253
+ customer_id : payment_method_new. customer_id . clone ( ) ,
254
+ merchant_id : payment_method_new. merchant_id . clone ( ) ,
255
+ payment_method_id : payment_method_new. payment_method_id . clone ( ) ,
256
+ locker_id : payment_method_new. locker_id . clone ( ) ,
257
+ accepted_currency : payment_method_new. accepted_currency . clone ( ) ,
258
+ scheme : payment_method_new. scheme . clone ( ) ,
259
+ token : payment_method_new. token . clone ( ) ,
260
+ cardholder_name : payment_method_new. cardholder_name . clone ( ) ,
261
+ issuer_name : payment_method_new. issuer_name . clone ( ) ,
262
+ issuer_country : payment_method_new. issuer_country . clone ( ) ,
263
+ payer_country : payment_method_new. payer_country . clone ( ) ,
264
+ is_stored : payment_method_new. is_stored ,
265
+ swift_code : payment_method_new. swift_code . clone ( ) ,
266
+ direct_debit_token : payment_method_new. direct_debit_token . clone ( ) ,
267
+ created_at : payment_method_new. created_at ,
268
+ last_modified : payment_method_new. last_modified ,
269
+ payment_method : payment_method_new. payment_method ,
270
+ payment_method_type : payment_method_new. payment_method_type ,
271
+ payment_method_issuer : payment_method_new. payment_method_issuer . clone ( ) ,
272
+ payment_method_issuer_code : payment_method_new. payment_method_issuer_code ,
273
+ metadata : payment_method_new. metadata . clone ( ) ,
274
+ payment_method_data : payment_method_new. payment_method_data . clone ( ) ,
275
+ last_used_at : payment_method_new. last_used_at ,
276
+ connector_mandate_details : payment_method_new. connector_mandate_details . clone ( ) ,
277
+ customer_acceptance : payment_method_new. customer_acceptance . clone ( ) ,
278
+ status : payment_method_new. status ,
279
+ network_transaction_id : payment_method_new. network_transaction_id . clone ( ) ,
280
+ }
281
+ }
282
+ }
0 commit comments