@@ -243,7 +243,8 @@ pub struct PaymentMethodMigrate {
243
243
pub billing : Option < payments:: Address > ,
244
244
245
245
/// The connector mandate details of the payment method
246
- pub connector_mandate_details : Option < PaymentsMandateReference > ,
246
+ #[ serde( deserialize_with = "deserialize_connector_mandate_details" ) ]
247
+ pub connector_mandate_details : Option < CommonMandateReference > ,
247
248
248
249
// The CIT (customer initiated transaction) transaction id associated with the payment method
249
250
pub network_transaction_id : Option < String > ,
@@ -267,19 +268,103 @@ pub struct PaymentMethodMigrateResponse {
267
268
pub network_transaction_id_migrated : Option < bool > ,
268
269
}
269
270
270
- #[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
271
+ #[ derive( Debug , Default , Clone , serde:: Serialize , serde:: Deserialize ) ]
271
272
pub struct PaymentsMandateReference (
272
273
pub HashMap < id_type:: MerchantConnectorAccountId , PaymentsMandateReferenceRecord > ,
273
274
) ;
274
275
275
- #[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
276
+ #[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
277
+ pub struct PayoutsMandateReference (
278
+ pub HashMap < id_type:: MerchantConnectorAccountId , PayoutsMandateReferenceRecord > ,
279
+ ) ;
280
+
281
+ #[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
282
+ pub struct PayoutsMandateReferenceRecord {
283
+ pub transfer_method_id : Option < String > ,
284
+ }
285
+
286
+ #[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
276
287
pub struct PaymentsMandateReferenceRecord {
277
288
pub connector_mandate_id : String ,
278
289
pub payment_method_type : Option < common_enums:: PaymentMethodType > ,
279
290
pub original_payment_authorized_amount : Option < i64 > ,
280
291
pub original_payment_authorized_currency : Option < common_enums:: Currency > ,
281
292
}
282
293
294
+ #[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
295
+ pub struct CommonMandateReference {
296
+ pub payments : Option < PaymentsMandateReference > ,
297
+ pub payouts : Option < PayoutsMandateReference > ,
298
+ }
299
+
300
+ impl From < CommonMandateReference > for PaymentsMandateReference {
301
+ fn from ( common_mandate : CommonMandateReference ) -> Self {
302
+ common_mandate. payments . unwrap_or_default ( )
303
+ }
304
+ }
305
+
306
+ impl From < PaymentsMandateReference > for CommonMandateReference {
307
+ fn from ( payments_reference : PaymentsMandateReference ) -> Self {
308
+ Self {
309
+ payments : Some ( payments_reference) ,
310
+ payouts : None ,
311
+ }
312
+ }
313
+ }
314
+
315
+ fn deserialize_connector_mandate_details < ' de , D > (
316
+ deserializer : D ,
317
+ ) -> Result < Option < CommonMandateReference > , D :: Error >
318
+ where
319
+ D : serde:: Deserializer < ' de > ,
320
+ {
321
+ let value: Option < serde_json:: Value > =
322
+ <Option < serde_json:: Value > as de:: Deserialize >:: deserialize ( deserializer) ?;
323
+
324
+ let payments_data = value
325
+ . clone ( )
326
+ . map ( |mut mandate_details| {
327
+ mandate_details
328
+ . as_object_mut ( )
329
+ . map ( |obj| obj. remove ( "payouts" ) ) ;
330
+
331
+ serde_json:: from_value :: < PaymentsMandateReference > ( mandate_details)
332
+ } )
333
+ . transpose ( )
334
+ . map_err ( |err| {
335
+ let err_msg = format ! ( "{err:?}" ) ;
336
+ de:: Error :: custom ( format_args ! (
337
+ "Failed to deserialize PaymentsMandateReference `{}`" ,
338
+ err_msg
339
+ ) )
340
+ } ) ?;
341
+
342
+ let payouts_data = value
343
+ . clone ( )
344
+ . map ( |mandate_details| {
345
+ serde_json:: from_value :: < Option < CommonMandateReference > > ( mandate_details) . map (
346
+ |optional_common_mandate_details| {
347
+ optional_common_mandate_details
348
+ . and_then ( |common_mandate_details| common_mandate_details. payouts )
349
+ } ,
350
+ )
351
+ } )
352
+ . transpose ( )
353
+ . map_err ( |err| {
354
+ let err_msg = format ! ( "{err:?}" ) ;
355
+ de:: Error :: custom ( format_args ! (
356
+ "Failed to deserialize CommonMandateReference `{}`" ,
357
+ err_msg
358
+ ) )
359
+ } ) ?
360
+ . flatten ( ) ;
361
+
362
+ Ok ( Some ( CommonMandateReference {
363
+ payments : payments_data,
364
+ payouts : payouts_data,
365
+ } ) )
366
+ }
367
+
283
368
#[ cfg( all(
284
369
any( feature = "v1" , feature = "v2" ) ,
285
370
not( feature = "payment_methods_v2" )
@@ -313,7 +398,12 @@ impl PaymentMethodCreate {
313
398
payment_method_issuer_code : payment_method_migrate. payment_method_issuer_code ,
314
399
metadata : payment_method_migrate. metadata . clone ( ) ,
315
400
payment_method_data : payment_method_migrate. payment_method_data . clone ( ) ,
316
- connector_mandate_details : payment_method_migrate. connector_mandate_details . clone ( ) ,
401
+ connector_mandate_details : payment_method_migrate
402
+ . connector_mandate_details
403
+ . clone ( )
404
+ . map ( |common_mandate_reference| {
405
+ PaymentsMandateReference :: from ( common_mandate_reference)
406
+ } ) ,
317
407
client_secret : None ,
318
408
billing : payment_method_migrate. billing . clone ( ) ,
319
409
card : card_details,
@@ -2328,7 +2418,11 @@ impl
2328
2418
} ) ,
2329
2419
email : record. email ,
2330
2420
} ) ,
2331
- connector_mandate_details,
2421
+ connector_mandate_details : connector_mandate_details. map (
2422
+ |payments_mandate_reference| {
2423
+ CommonMandateReference :: from ( payments_mandate_reference)
2424
+ } ,
2425
+ ) ,
2332
2426
metadata : None ,
2333
2427
payment_method_issuer_code : None ,
2334
2428
card_network : None ,
0 commit comments