@@ -19,6 +19,38 @@ use crate::{
19
19
20
20
type Error = error_stack:: Report < errors:: ConnectorError > ;
21
21
22
+ #[ derive( Debug , Serialize ) ]
23
+ pub struct MollieRouterData < T > {
24
+ pub amount : String ,
25
+ pub router_data : T ,
26
+ }
27
+
28
+ impl < T >
29
+ TryFrom < (
30
+ & types:: api:: CurrencyUnit ,
31
+ types:: storage:: enums:: Currency ,
32
+ i64 ,
33
+ T ,
34
+ ) > for MollieRouterData < T >
35
+ {
36
+ type Error = error_stack:: Report < errors:: ConnectorError > ;
37
+
38
+ fn try_from (
39
+ ( currency_unit, currency, amount, router_data) : (
40
+ & types:: api:: CurrencyUnit ,
41
+ types:: storage:: enums:: Currency ,
42
+ i64 ,
43
+ T ,
44
+ ) ,
45
+ ) -> Result < Self , Self :: Error > {
46
+ let amount = utils:: get_amount_as_string ( currency_unit, amount, currency) ?;
47
+ Ok ( Self {
48
+ amount,
49
+ router_data,
50
+ } )
51
+ }
52
+ }
53
+
22
54
#[ derive( Debug , Serialize ) ]
23
55
#[ serde( rename_all = "camelCase" ) ]
24
56
pub struct MolliePaymentsRequest {
@@ -120,50 +152,55 @@ pub struct MollieBrowserInfo {
120
152
language : String ,
121
153
}
122
154
123
- impl TryFrom < & types:: PaymentsAuthorizeRouterData > for MolliePaymentsRequest {
155
+ impl TryFrom < & MollieRouterData < & types:: PaymentsAuthorizeRouterData > > for MolliePaymentsRequest {
124
156
type Error = Error ;
125
- fn try_from ( item : & types:: PaymentsAuthorizeRouterData ) -> Result < Self , Self :: Error > {
157
+ fn try_from (
158
+ item : & MollieRouterData < & types:: PaymentsAuthorizeRouterData > ,
159
+ ) -> Result < Self , Self :: Error > {
126
160
let amount = Amount {
127
- currency : item. request . currency ,
128
- value : utils :: to_currency_base_unit ( item. request . amount , item . request . currency ) ? ,
161
+ currency : item. router_data . request . currency ,
162
+ value : item. amount . clone ( ) ,
129
163
} ;
130
- let description = item. get_description ( ) ?;
131
- let redirect_url = item. request . get_return_url ( ) ?;
132
- let payment_method_data = match item. request . capture_method . unwrap_or_default ( ) {
133
- enums:: CaptureMethod :: Automatic => match & item. request . payment_method_data {
134
- api_models:: payments:: PaymentMethodData :: Card ( _) => {
135
- let pm_token = item. get_payment_method_token ( ) ?;
136
- Ok ( PaymentMethodData :: CreditCard ( Box :: new (
137
- CreditCardMethodData {
138
- billing_address : get_billing_details ( item) ?,
139
- shipping_address : get_shipping_details ( item) ?,
140
- card_token : Some ( Secret :: new ( match pm_token {
141
- types:: PaymentMethodToken :: Token ( token) => token,
142
- types:: PaymentMethodToken :: ApplePayDecrypt ( _) => {
143
- Err ( errors:: ConnectorError :: InvalidWalletToken ) ?
144
- }
145
- } ) ) ,
146
- } ,
147
- ) ) )
148
- }
149
- api_models:: payments:: PaymentMethodData :: BankRedirect ( ref redirect_data) => {
150
- PaymentMethodData :: try_from ( redirect_data)
164
+ let description = item. router_data . get_description ( ) ?;
165
+ let redirect_url = item. router_data . request . get_return_url ( ) ?;
166
+ let payment_method_data = match item. router_data . request . capture_method . unwrap_or_default ( )
167
+ {
168
+ enums:: CaptureMethod :: Automatic => {
169
+ match & item. router_data . request . payment_method_data {
170
+ api_models:: payments:: PaymentMethodData :: Card ( _) => {
171
+ let pm_token = item. router_data . get_payment_method_token ( ) ?;
172
+ Ok ( PaymentMethodData :: CreditCard ( Box :: new (
173
+ CreditCardMethodData {
174
+ billing_address : get_billing_details ( item. router_data ) ?,
175
+ shipping_address : get_shipping_details ( item. router_data ) ?,
176
+ card_token : Some ( Secret :: new ( match pm_token {
177
+ types:: PaymentMethodToken :: Token ( token) => token,
178
+ types:: PaymentMethodToken :: ApplePayDecrypt ( _) => {
179
+ Err ( errors:: ConnectorError :: InvalidWalletToken ) ?
180
+ }
181
+ } ) ) ,
182
+ } ,
183
+ ) ) )
184
+ }
185
+ api_models:: payments:: PaymentMethodData :: BankRedirect ( ref redirect_data) => {
186
+ PaymentMethodData :: try_from ( redirect_data)
187
+ }
188
+ api_models:: payments:: PaymentMethodData :: Wallet ( ref wallet_data) => {
189
+ get_payment_method_for_wallet ( item. router_data , wallet_data)
190
+ }
191
+ api_models:: payments:: PaymentMethodData :: BankDebit ( ref directdebit_data) => {
192
+ PaymentMethodData :: try_from ( directdebit_data)
193
+ }
194
+ _ => Err ( errors:: ConnectorError :: NotImplemented (
195
+ "Payment Method" . to_string ( ) ,
196
+ ) )
197
+ . into_report ( ) ,
151
198
}
152
- api_models:: payments:: PaymentMethodData :: Wallet ( ref wallet_data) => {
153
- get_payment_method_for_wallet ( item, wallet_data)
154
- }
155
- api_models:: payments:: PaymentMethodData :: BankDebit ( ref directdebit_data) => {
156
- PaymentMethodData :: try_from ( directdebit_data)
157
- }
158
- _ => Err ( errors:: ConnectorError :: NotImplemented (
159
- "Payment Method" . to_string ( ) ,
160
- ) )
161
- . into_report ( ) ,
162
- } ,
199
+ }
163
200
_ => Err ( errors:: ConnectorError :: FlowNotSupported {
164
201
flow : format ! (
165
202
"{} capture" ,
166
- item. request. capture_method. unwrap_or_default( )
203
+ item. router_data . request. capture_method. unwrap_or_default( )
167
204
) ,
168
205
connector : "Mollie" . to_string ( ) ,
169
206
} )
@@ -526,16 +563,18 @@ pub struct MollieRefundRequest {
526
563
description : Option < String > ,
527
564
}
528
565
529
- impl < F > TryFrom < & types:: RefundsRouterData < F > > for MollieRefundRequest {
566
+ impl < F > TryFrom < & MollieRouterData < & types:: RefundsRouterData < F > > > for MollieRefundRequest {
530
567
type Error = Error ;
531
- fn try_from ( item : & types:: RefundsRouterData < F > ) -> Result < Self , Self :: Error > {
568
+ fn try_from (
569
+ item : & MollieRouterData < & types:: RefundsRouterData < F > > ,
570
+ ) -> Result < Self , Self :: Error > {
532
571
let amount = Amount {
533
- currency : item. request . currency ,
534
- value : utils :: to_currency_base_unit ( item. request . refund_amount , item . request . currency ) ? ,
572
+ currency : item. router_data . request . currency ,
573
+ value : item. amount . clone ( ) ,
535
574
} ;
536
575
Ok ( Self {
537
576
amount,
538
- description : item. request . reason . to_owned ( ) ,
577
+ description : item. router_data . request . reason . to_owned ( ) ,
539
578
} )
540
579
}
541
580
}
0 commit comments