@@ -3,15 +3,44 @@ use common_utils::errors::CustomResult;
3
3
use diesel_models:: enums;
4
4
use error_stack:: { IntoReport , ResultExt } ;
5
5
use masking:: { PeekInterface , Secret } ;
6
+ use serde:: Serialize ;
6
7
7
8
use super :: { requests:: * , response:: * } ;
8
9
use crate :: {
9
10
connector:: utils,
10
11
consts,
11
12
core:: errors,
12
- types:: { self , api} ,
13
+ types:: { self , api, PaymentsAuthorizeData , PaymentsResponseData } ,
13
14
} ;
14
15
16
+ #[ derive( Debug , Serialize ) ]
17
+ pub struct WorldpayRouterData < T > {
18
+ amount : i64 ,
19
+ router_data : T ,
20
+ }
21
+ impl < T >
22
+ TryFrom < (
23
+ & types:: api:: CurrencyUnit ,
24
+ types:: storage:: enums:: Currency ,
25
+ i64 ,
26
+ T ,
27
+ ) > for WorldpayRouterData < T >
28
+ {
29
+ type Error = error_stack:: Report < errors:: ConnectorError > ;
30
+ fn try_from (
31
+ ( _currency_unit, _currency, amount, item) : (
32
+ & types:: api:: CurrencyUnit ,
33
+ types:: storage:: enums:: Currency ,
34
+ i64 ,
35
+ T ,
36
+ ) ,
37
+ ) -> Result < Self , Self :: Error > {
38
+ Ok ( Self {
39
+ amount,
40
+ router_data : item,
41
+ } )
42
+ }
43
+ }
15
44
fn fetch_payment_instrument (
16
45
payment_method : api:: PaymentMethodData ,
17
46
) -> CustomResult < PaymentInstrument , errors:: ConnectorError > {
@@ -100,29 +129,48 @@ fn fetch_payment_instrument(
100
129
}
101
130
}
102
131
103
- impl TryFrom < & types:: PaymentsAuthorizeRouterData > for WorldpayPaymentsRequest {
132
+ impl
133
+ TryFrom <
134
+ & WorldpayRouterData <
135
+ & types:: RouterData <
136
+ types:: api:: payments:: Authorize ,
137
+ PaymentsAuthorizeData ,
138
+ PaymentsResponseData ,
139
+ > ,
140
+ > ,
141
+ > for WorldpayPaymentsRequest
142
+ {
104
143
type Error = error_stack:: Report < errors:: ConnectorError > ;
105
- fn try_from ( item : & types:: PaymentsAuthorizeRouterData ) -> Result < Self , Self :: Error > {
144
+
145
+ fn try_from (
146
+ item : & WorldpayRouterData <
147
+ & types:: RouterData <
148
+ types:: api:: payments:: Authorize ,
149
+ PaymentsAuthorizeData ,
150
+ PaymentsResponseData ,
151
+ > ,
152
+ > ,
153
+ ) -> Result < Self , Self :: Error > {
106
154
Ok ( Self {
107
155
instruction : Instruction {
108
156
value : PaymentValue {
109
- amount : item. request . amount ,
110
- currency : item. request . currency . to_string ( ) ,
157
+ amount : item. amount ,
158
+ currency : item. router_data . request . currency . to_string ( ) ,
111
159
} ,
112
160
narrative : InstructionNarrative {
113
- line1 : item. merchant_id . clone ( ) . replace ( '_' , "-" ) ,
161
+ line1 : item. router_data . merchant_id . clone ( ) . replace ( '_' , "-" ) ,
114
162
..Default :: default ( )
115
163
} ,
116
164
payment_instrument : fetch_payment_instrument (
117
- item. request . payment_method_data . clone ( ) ,
165
+ item. router_data . request . payment_method_data . clone ( ) ,
118
166
) ?,
119
167
debt_repayment : None ,
120
168
} ,
121
169
merchant : Merchant {
122
- entity : item. attempt_id . clone ( ) . replace ( '_' , "-" ) ,
170
+ entity : item. router_data . attempt_id . clone ( ) . replace ( '_' , "-" ) ,
123
171
..Default :: default ( )
124
172
} ,
125
- transaction_reference : item. attempt_id . clone ( ) ,
173
+ transaction_reference : item. router_data . attempt_id . clone ( ) ,
126
174
channel : None ,
127
175
customer : None ,
128
176
} )
0 commit comments