1
+ use std:: collections:: BTreeMap ;
2
+
1
3
use common_utils:: {
2
4
errors:: CustomResult ,
3
5
ext_traits:: { Encode , ValueExt } ,
@@ -6,6 +8,7 @@ use error_stack::ResultExt;
6
8
use masking:: { ExposeInterface , PeekInterface , Secret , StrongSecret } ;
7
9
use rand:: distributions:: { Alphanumeric , DistString } ;
8
10
use serde:: { Deserialize , Serialize } ;
11
+ use serde_json:: Value ;
9
12
10
13
use crate :: {
11
14
connector:: utils:: {
@@ -143,12 +146,27 @@ struct TransactionRequest {
143
146
#[ serde( skip_serializing_if = "Option::is_none" ) ]
144
147
bill_to : Option < BillTo > ,
145
148
#[ serde( skip_serializing_if = "Option::is_none" ) ]
149
+ user_fields : Option < UserFields > ,
150
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
146
151
processing_options : Option < ProcessingOptions > ,
147
152
#[ serde( skip_serializing_if = "Option::is_none" ) ]
148
153
subsequent_auth_information : Option < SubsequentAuthInformation > ,
149
154
authorization_indicator_type : Option < AuthorizationIndicator > ,
150
155
}
151
156
157
+ #[ derive( Debug , Serialize ) ]
158
+ #[ serde( rename_all = "camelCase" ) ]
159
+ pub struct UserFields {
160
+ user_field : Vec < UserField > ,
161
+ }
162
+
163
+ #[ derive( Debug , Serialize ) ]
164
+ #[ serde( rename_all = "camelCase" ) ]
165
+ pub struct UserField {
166
+ name : String ,
167
+ value : String ,
168
+ }
169
+
152
170
#[ derive( Serialize , Deserialize , Debug ) ]
153
171
#[ serde( untagged) ]
154
172
enum ProfileDetails {
@@ -299,6 +317,25 @@ pub enum ValidationMode {
299
317
LiveMode ,
300
318
}
301
319
320
+ impl ForeignTryFrom < Value > for Vec < UserField > {
321
+ type Error = error_stack:: Report < errors:: ConnectorError > ;
322
+ fn foreign_try_from ( metadata : Value ) -> Result < Self , Self :: Error > {
323
+ let hashmap: BTreeMap < String , Value > = serde_json:: from_str ( & metadata. to_string ( ) )
324
+ . change_context ( errors:: ConnectorError :: RequestEncodingFailedWithReason (
325
+ "Failed to serialize request metadata" . to_owned ( ) ,
326
+ ) )
327
+ . attach_printable ( "" ) ?;
328
+ let mut vector: Self = Self :: new ( ) ;
329
+ for ( key, value) in hashmap {
330
+ vector. push ( UserField {
331
+ name : key,
332
+ value : value. to_string ( ) ,
333
+ } ) ;
334
+ }
335
+ Ok ( vector)
336
+ }
337
+ }
338
+
302
339
impl TryFrom < & types:: SetupMandateRouterData > for CreateCustomerProfileRequest {
303
340
type Error = error_stack:: Report < errors:: ConnectorError > ;
304
341
fn try_from ( item : & types:: SetupMandateRouterData ) -> Result < Self , Self :: Error > {
@@ -622,6 +659,12 @@ impl
622
659
zip : address. zip . clone ( ) ,
623
660
country : address. country ,
624
661
} ) ,
662
+ user_fields : match item. router_data . request . metadata . clone ( ) {
663
+ Some ( metadata) => Some ( UserFields {
664
+ user_field : Vec :: < UserField > :: foreign_try_from ( metadata) ?,
665
+ } ) ,
666
+ None => None ,
667
+ } ,
625
668
processing_options : Some ( ProcessingOptions {
626
669
is_subsequent_auth : true ,
627
670
} ) ,
@@ -675,6 +718,12 @@ impl
675
718
} ,
676
719
customer : None ,
677
720
bill_to : None ,
721
+ user_fields : match item. router_data . request . metadata . clone ( ) {
722
+ Some ( metadata) => Some ( UserFields {
723
+ user_field : Vec :: < UserField > :: foreign_try_from ( metadata) ?,
724
+ } ) ,
725
+ None => None ,
726
+ } ,
678
727
processing_options : Some ( ProcessingOptions {
679
728
is_subsequent_auth : true ,
680
729
} ) ,
@@ -764,6 +813,12 @@ impl
764
813
zip : address. zip . clone ( ) ,
765
814
country : address. country ,
766
815
} ) ,
816
+ user_fields : match item. router_data . request . metadata . clone ( ) {
817
+ Some ( metadata) => Some ( UserFields {
818
+ user_field : Vec :: < UserField > :: foreign_try_from ( metadata) ?,
819
+ } ) ,
820
+ None => None ,
821
+ } ,
767
822
processing_options : None ,
768
823
subsequent_auth_information : None ,
769
824
authorization_indicator_type : match item. router_data . request . capture_method {
@@ -815,6 +870,12 @@ impl
815
870
zip : address. zip . clone ( ) ,
816
871
country : address. country ,
817
872
} ) ,
873
+ user_fields : match item. router_data . request . metadata . clone ( ) {
874
+ Some ( metadata) => Some ( UserFields {
875
+ user_field : Vec :: < UserField > :: foreign_try_from ( metadata) ?,
876
+ } ) ,
877
+ None => None ,
878
+ } ,
818
879
processing_options : None ,
819
880
subsequent_auth_information : None ,
820
881
authorization_indicator_type : match item. router_data . request . capture_method {
0 commit comments