1
+ use std:: collections:: HashMap ;
2
+
1
3
use api_models:: payments;
2
4
use base64:: Engine ;
3
5
use common_utils:: pii;
4
6
use masking:: { PeekInterface , Secret } ;
5
7
use serde:: { Deserialize , Serialize } ;
8
+ use serde_json:: Value ;
6
9
7
10
use crate :: {
8
11
connector:: utils:: {
@@ -83,6 +86,8 @@ pub struct BankOfAmericaPaymentsRequest {
83
86
payment_information : PaymentInformation ,
84
87
order_information : OrderInformationWithBill ,
85
88
client_reference_information : ClientReferenceInformation ,
89
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
90
+ merchant_defined_information : Option < Vec < MerchantDefinedInformation > > ,
86
91
}
87
92
88
93
#[ derive( Debug , Serialize ) ]
@@ -92,6 +97,13 @@ pub struct ProcessingInformation {
92
97
payment_solution : Option < String > ,
93
98
}
94
99
100
+ #[ derive( Debug , Serialize ) ]
101
+ #[ serde( rename_all = "camelCase" ) ]
102
+ pub struct MerchantDefinedInformation {
103
+ key : u8 ,
104
+ value : String ,
105
+ }
106
+
95
107
#[ derive( Debug , Serialize ) ]
96
108
#[ serde( rename_all = "camelCase" ) ]
97
109
pub struct CaptureOptions {
@@ -309,6 +321,23 @@ impl From<&BankOfAmericaRouterData<&types::PaymentsAuthorizeRouterData>>
309
321
}
310
322
}
311
323
324
+ impl ForeignFrom < Value > for Vec < MerchantDefinedInformation > {
325
+ fn foreign_from ( metadata : Value ) -> Self {
326
+ let hashmap: HashMap < String , Value > =
327
+ serde_json:: from_str ( & metadata. to_string ( ) ) . unwrap_or ( HashMap :: new ( ) ) ;
328
+ let mut vector: Self = Self :: new ( ) ;
329
+ let mut iter = 1 ;
330
+ for ( key, value) in hashmap {
331
+ vector. push ( MerchantDefinedInformation {
332
+ key : iter,
333
+ value : format ! ( "{key}={value}" ) ,
334
+ } ) ;
335
+ iter += 1 ;
336
+ }
337
+ vector
338
+ }
339
+ }
340
+
312
341
#[ derive( Clone , Debug , Deserialize , Serialize ) ]
313
342
#[ serde( rename_all = "camelCase" ) ]
314
343
pub struct ClientReferenceInformation {
@@ -331,13 +360,11 @@ impl
331
360
let email = item. router_data . request . get_email ( ) ?;
332
361
let bill_to = build_bill_to ( item. router_data . get_billing ( ) ?, email) ?;
333
362
let order_information = OrderInformationWithBill :: from ( ( item, bill_to) ) ;
334
-
335
363
let card_issuer = ccard. get_card_issuer ( ) ;
336
364
let card_type = match card_issuer {
337
365
Ok ( issuer) => Some ( String :: from ( issuer) ) ,
338
366
Err ( _) => None ,
339
367
} ;
340
-
341
368
let payment_information = PaymentInformation :: Cards ( CardPaymentInformation {
342
369
card : Card {
343
370
number : ccard. card_number ,
@@ -347,15 +374,19 @@ impl
347
374
card_type,
348
375
} ,
349
376
} ) ;
350
-
351
377
let processing_information = ProcessingInformation :: from ( ( item, None ) ) ;
352
378
let client_reference_information = ClientReferenceInformation :: from ( item) ;
379
+ let merchant_defined_information =
380
+ item. router_data . request . metadata . clone ( ) . map ( |metadata| {
381
+ Vec :: < MerchantDefinedInformation > :: foreign_from ( metadata. peek ( ) . to_owned ( ) )
382
+ } ) ;
353
383
354
384
Ok ( Self {
355
385
processing_information,
356
386
payment_information,
357
387
order_information,
358
388
client_reference_information,
389
+ merchant_defined_information,
359
390
} )
360
391
}
361
392
}
@@ -379,10 +410,8 @@ impl
379
410
let processing_information =
380
411
ProcessingInformation :: from ( ( item, Some ( PaymentSolution :: ApplePay ) ) ) ;
381
412
let client_reference_information = ClientReferenceInformation :: from ( item) ;
382
-
383
413
let expiration_month = apple_pay_data. get_expiry_month ( ) ?;
384
414
let expiration_year = apple_pay_data. get_four_digit_expiry_year ( ) ?;
385
-
386
415
let payment_information = PaymentInformation :: ApplePay ( ApplePayPaymentInformation {
387
416
tokenized_card : TokenizedCard {
388
417
number : apple_pay_data. application_primary_account_number ,
@@ -392,12 +421,17 @@ impl
392
421
expiration_month,
393
422
} ,
394
423
} ) ;
424
+ let merchant_defined_information =
425
+ item. router_data . request . metadata . clone ( ) . map ( |metadata| {
426
+ Vec :: < MerchantDefinedInformation > :: foreign_from ( metadata. peek ( ) . to_owned ( ) )
427
+ } ) ;
395
428
396
429
Ok ( Self {
397
430
processing_information,
398
431
payment_information,
399
432
order_information,
400
433
client_reference_information,
434
+ merchant_defined_information,
401
435
} )
402
436
}
403
437
}
@@ -418,24 +452,27 @@ impl
418
452
let email = item. router_data . request . get_email ( ) ?;
419
453
let bill_to = build_bill_to ( item. router_data . get_billing ( ) ?, email) ?;
420
454
let order_information = OrderInformationWithBill :: from ( ( item, bill_to) ) ;
421
-
422
455
let payment_information = PaymentInformation :: GooglePay ( GooglePayPaymentInformation {
423
456
fluid_data : FluidData {
424
457
value : Secret :: from (
425
458
consts:: BASE64_ENGINE . encode ( google_pay_data. tokenization_data . token ) ,
426
459
) ,
427
460
} ,
428
461
} ) ;
429
-
430
462
let processing_information =
431
463
ProcessingInformation :: from ( ( item, Some ( PaymentSolution :: GooglePay ) ) ) ;
432
464
let client_reference_information = ClientReferenceInformation :: from ( item) ;
465
+ let merchant_defined_information =
466
+ item. router_data . request . metadata . clone ( ) . map ( |metadata| {
467
+ Vec :: < MerchantDefinedInformation > :: foreign_from ( metadata. peek ( ) . to_owned ( ) )
468
+ } ) ;
433
469
434
470
Ok ( Self {
435
471
processing_information,
436
472
payment_information,
437
473
order_information,
438
474
client_reference_information,
475
+ merchant_defined_information,
439
476
} )
440
477
}
441
478
}
@@ -480,10 +517,17 @@ impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsAuthorizeRouterData>>
480
517
} ,
481
518
} ,
482
519
) ;
520
+ let merchant_defined_information =
521
+ item. router_data . request . metadata . clone ( ) . map ( |metadata| {
522
+ Vec :: < MerchantDefinedInformation > :: foreign_from (
523
+ metadata. peek ( ) . to_owned ( ) ,
524
+ )
525
+ } ) ;
483
526
Ok ( Self {
484
527
processing_information,
485
528
payment_information,
486
529
order_information,
530
+ merchant_defined_information,
487
531
client_reference_information,
488
532
} )
489
533
}
0 commit comments