@@ -40,6 +40,37 @@ impl TryFrom<&ConnectorAuthType> for NmiAuthType {
40
40
}
41
41
}
42
42
43
+ #[ derive( Debug , Serialize ) ]
44
+ pub struct NmiRouterData < T > {
45
+ pub amount : f64 ,
46
+ pub router_data : T ,
47
+ }
48
+
49
+ impl < T >
50
+ TryFrom < (
51
+ & types:: api:: CurrencyUnit ,
52
+ types:: storage:: enums:: Currency ,
53
+ i64 ,
54
+ T ,
55
+ ) > for NmiRouterData < T >
56
+ {
57
+ type Error = Report < errors:: ConnectorError > ;
58
+
59
+ fn try_from (
60
+ ( _currency_unit, currency, amount, router_data) : (
61
+ & types:: api:: CurrencyUnit ,
62
+ types:: storage:: enums:: Currency ,
63
+ i64 ,
64
+ T ,
65
+ ) ,
66
+ ) -> Result < Self , Self :: Error > {
67
+ Ok ( Self {
68
+ amount : utils:: to_currency_base_unit_asf64 ( amount, currency) ?,
69
+ router_data,
70
+ } )
71
+ }
72
+ }
73
+
43
74
#[ derive( Debug , Serialize ) ]
44
75
pub struct NmiPaymentsRequest {
45
76
#[ serde( rename = "type" ) ]
@@ -77,25 +108,27 @@ pub struct ApplePayData {
77
108
applepay_payment_data : Secret < String > ,
78
109
}
79
110
80
- impl TryFrom < & types:: PaymentsAuthorizeRouterData > for NmiPaymentsRequest {
111
+ impl TryFrom < & NmiRouterData < & types:: PaymentsAuthorizeRouterData > > for NmiPaymentsRequest {
81
112
type Error = Error ;
82
- fn try_from ( item : & types:: PaymentsAuthorizeRouterData ) -> Result < Self , Self :: Error > {
83
- let transaction_type = match item. request . is_auto_capture ( ) ? {
113
+ fn try_from (
114
+ item : & NmiRouterData < & types:: PaymentsAuthorizeRouterData > ,
115
+ ) -> Result < Self , Self :: Error > {
116
+ let transaction_type = match item. router_data . request . is_auto_capture ( ) ? {
84
117
true => TransactionType :: Sale ,
85
118
false => TransactionType :: Auth ,
86
119
} ;
87
- let auth_type: NmiAuthType = ( & item. connector_auth_type ) . try_into ( ) ?;
88
- let amount =
89
- utils :: to_currency_base_unit_asf64 ( item . request . amount , item . request . currency ) ? ;
90
- let payment_method = PaymentMethod :: try_from ( & item. request . payment_method_data ) ?;
120
+ let auth_type: NmiAuthType = ( & item. router_data . connector_auth_type ) . try_into ( ) ?;
121
+ let amount = item . amount ;
122
+ let payment_method =
123
+ PaymentMethod :: try_from ( & item. router_data . request . payment_method_data ) ?;
91
124
92
125
Ok ( Self {
93
126
transaction_type,
94
127
security_key : auth_type. api_key ,
95
128
amount,
96
- currency : item. request . currency ,
129
+ currency : item. router_data . request . currency ,
97
130
payment_method,
98
- orderid : item. connector_request_reference_id . clone ( ) ,
131
+ orderid : item. router_data . connector_request_reference_id . clone ( ) ,
99
132
} )
100
133
}
101
134
}
@@ -243,18 +276,17 @@ pub struct NmiCaptureRequest {
243
276
pub amount : Option < f64 > ,
244
277
}
245
278
246
- impl TryFrom < & types:: PaymentsCaptureRouterData > for NmiCaptureRequest {
279
+ impl TryFrom < & NmiRouterData < & types:: PaymentsCaptureRouterData > > for NmiCaptureRequest {
247
280
type Error = Error ;
248
- fn try_from ( item : & types:: PaymentsCaptureRouterData ) -> Result < Self , Self :: Error > {
249
- let auth = NmiAuthType :: try_from ( & item. connector_auth_type ) ?;
281
+ fn try_from (
282
+ item : & NmiRouterData < & types:: PaymentsCaptureRouterData > ,
283
+ ) -> Result < Self , Self :: Error > {
284
+ let auth = NmiAuthType :: try_from ( & item. router_data . connector_auth_type ) ?;
250
285
Ok ( Self {
251
286
transaction_type : TransactionType :: Capture ,
252
287
security_key : auth. api_key ,
253
- transactionid : item. request . connector_transaction_id . clone ( ) ,
254
- amount : Some ( utils:: to_currency_base_unit_asf64 (
255
- item. request . amount_to_capture ,
256
- item. request . currency ,
257
- ) ?) ,
288
+ transactionid : item. router_data . request . connector_transaction_id . clone ( ) ,
289
+ amount : Some ( item. amount ) ,
258
290
} )
259
291
}
260
292
}
@@ -577,18 +609,15 @@ pub struct NmiRefundRequest {
577
609
amount : f64 ,
578
610
}
579
611
580
- impl < F > TryFrom < & types:: RefundsRouterData < F > > for NmiRefundRequest {
612
+ impl < F > TryFrom < & NmiRouterData < & types:: RefundsRouterData < F > > > for NmiRefundRequest {
581
613
type Error = Error ;
582
- fn try_from ( item : & types:: RefundsRouterData < F > ) -> Result < Self , Self :: Error > {
583
- let auth_type: NmiAuthType = ( & item. connector_auth_type ) . try_into ( ) ?;
614
+ fn try_from ( item : & NmiRouterData < & types:: RefundsRouterData < F > > ) -> Result < Self , Self :: Error > {
615
+ let auth_type: NmiAuthType = ( & item. router_data . connector_auth_type ) . try_into ( ) ?;
584
616
Ok ( Self {
585
617
transaction_type : TransactionType :: Refund ,
586
618
security_key : auth_type. api_key ,
587
- transactionid : item. request . connector_transaction_id . clone ( ) ,
588
- amount : utils:: to_currency_base_unit_asf64 (
589
- item. request . refund_amount ,
590
- item. request . currency ,
591
- ) ?,
619
+ transactionid : item. router_data . request . connector_transaction_id . clone ( ) ,
620
+ amount : item. amount ,
592
621
} )
593
622
}
594
623
}
0 commit comments