@@ -257,7 +257,8 @@ pub struct PaymentMethodMigrate {
257
257
pub billing : Option < payments:: Address > ,
258
258
259
259
/// The connector mandate details of the payment method
260
- pub connector_mandate_details : Option < PaymentsMandateReference > ,
260
+ #[ serde( deserialize_with = "deserialize_connector_mandate_details" ) ]
261
+ pub connector_mandate_details : Option < CommonMandateReference > ,
261
262
262
263
// The CIT (customer initiated transaction) transaction id associated with the payment method
263
264
pub network_transaction_id : Option < String > ,
@@ -281,19 +282,103 @@ pub struct PaymentMethodMigrateResponse {
281
282
pub network_transaction_id_migrated : Option < bool > ,
282
283
}
283
284
284
- #[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
285
+ #[ derive( Debug , Default , Clone , serde:: Serialize , serde:: Deserialize ) ]
285
286
pub struct PaymentsMandateReference (
286
287
pub HashMap < id_type:: MerchantConnectorAccountId , PaymentsMandateReferenceRecord > ,
287
288
) ;
288
289
289
- #[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
290
+ #[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
291
+ pub struct PayoutsMandateReference (
292
+ pub HashMap < id_type:: MerchantConnectorAccountId , PayoutsMandateReferenceRecord > ,
293
+ ) ;
294
+
295
+ #[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
296
+ pub struct PayoutsMandateReferenceRecord {
297
+ pub transfer_method_id : Option < String > ,
298
+ }
299
+
300
+ #[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
290
301
pub struct PaymentsMandateReferenceRecord {
291
302
pub connector_mandate_id : String ,
292
303
pub payment_method_type : Option < common_enums:: PaymentMethodType > ,
293
304
pub original_payment_authorized_amount : Option < i64 > ,
294
305
pub original_payment_authorized_currency : Option < common_enums:: Currency > ,
295
306
}
296
307
308
+ #[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
309
+ pub struct CommonMandateReference {
310
+ pub payments : Option < PaymentsMandateReference > ,
311
+ pub payouts : Option < PayoutsMandateReference > ,
312
+ }
313
+
314
+ impl From < CommonMandateReference > for PaymentsMandateReference {
315
+ fn from ( common_mandate : CommonMandateReference ) -> Self {
316
+ common_mandate. payments . unwrap_or_default ( )
317
+ }
318
+ }
319
+
320
+ impl From < PaymentsMandateReference > for CommonMandateReference {
321
+ fn from ( payments_reference : PaymentsMandateReference ) -> Self {
322
+ Self {
323
+ payments : Some ( payments_reference) ,
324
+ payouts : None ,
325
+ }
326
+ }
327
+ }
328
+
329
+ fn deserialize_connector_mandate_details < ' de , D > (
330
+ deserializer : D ,
331
+ ) -> Result < Option < CommonMandateReference > , D :: Error >
332
+ where
333
+ D : serde:: Deserializer < ' de > ,
334
+ {
335
+ let value: Option < serde_json:: Value > =
336
+ <Option < serde_json:: Value > as de:: Deserialize >:: deserialize ( deserializer) ?;
337
+
338
+ let payments_data = value
339
+ . clone ( )
340
+ . map ( |mut mandate_details| {
341
+ mandate_details
342
+ . as_object_mut ( )
343
+ . map ( |obj| obj. remove ( "payouts" ) ) ;
344
+
345
+ serde_json:: from_value :: < PaymentsMandateReference > ( mandate_details)
346
+ } )
347
+ . transpose ( )
348
+ . map_err ( |err| {
349
+ let err_msg = format ! ( "{err:?}" ) ;
350
+ de:: Error :: custom ( format_args ! (
351
+ "Failed to deserialize PaymentsMandateReference `{}`" ,
352
+ err_msg
353
+ ) )
354
+ } ) ?;
355
+
356
+ let payouts_data = value
357
+ . clone ( )
358
+ . map ( |mandate_details| {
359
+ serde_json:: from_value :: < Option < CommonMandateReference > > ( mandate_details) . map (
360
+ |optional_common_mandate_details| {
361
+ optional_common_mandate_details
362
+ . and_then ( |common_mandate_details| common_mandate_details. payouts )
363
+ } ,
364
+ )
365
+ } )
366
+ . transpose ( )
367
+ . map_err ( |err| {
368
+ let err_msg = format ! ( "{err:?}" ) ;
369
+ de:: Error :: custom ( format_args ! (
370
+ "Failed to deserialize CommonMandateReference `{}`" ,
371
+ err_msg
372
+ ) )
373
+ } ) ?
374
+ . flatten ( ) ;
375
+
376
+ Ok ( Some ( CommonMandateReference {
377
+ payments : payments_data,
378
+ payouts : payouts_data,
379
+ } ) )
380
+ }
381
+
297
382
#[ cfg( all(
298
383
any( feature = "v1" , feature = "v2" ) ,
299
384
not( feature = "payment_methods_v2" )
@@ -327,7 +412,12 @@ impl PaymentMethodCreate {
327
412
payment_method_issuer_code : payment_method_migrate. payment_method_issuer_code ,
328
413
metadata : payment_method_migrate. metadata . clone ( ) ,
329
414
payment_method_data : payment_method_migrate. payment_method_data . clone ( ) ,
330
- connector_mandate_details : payment_method_migrate. connector_mandate_details . clone ( ) ,
415
+ connector_mandate_details : payment_method_migrate
416
+ . connector_mandate_details
417
+ . clone ( )
418
+ . map ( |common_mandate_reference| {
419
+ PaymentsMandateReference :: from ( common_mandate_reference)
420
+ } ) ,
331
421
client_secret : None ,
332
422
billing : payment_method_migrate. billing . clone ( ) ,
333
423
card : card_details,
@@ -2335,7 +2425,11 @@ impl
2335
2425
} ) ,
2336
2426
email : record. email ,
2337
2427
} ) ,
2338
- connector_mandate_details,
2428
+ connector_mandate_details : connector_mandate_details. map (
2429
+ |payments_mandate_reference| {
2430
+ CommonMandateReference :: from ( payments_mandate_reference)
2431
+ } ,
2432
+ ) ,
2339
2433
metadata : None ,
2340
2434
payment_method_issuer_code : None ,
2341
2435
card_network : None ,
0 commit comments