@@ -9,6 +9,37 @@ use crate::{
9
9
core:: errors,
10
10
types:: { self , api, storage:: enums, transformers:: ForeignFrom } ,
11
11
} ;
12
+ #[ derive( Debug , Serialize ) ]
13
+ pub struct PayeezyRouterData < T > {
14
+ pub amount : String ,
15
+ pub router_data : T ,
16
+ }
17
+
18
+ impl < T >
19
+ TryFrom < (
20
+ & types:: api:: CurrencyUnit ,
21
+ types:: storage:: enums:: Currency ,
22
+ i64 ,
23
+ T ,
24
+ ) > for PayeezyRouterData < T >
25
+ {
26
+ type Error = error_stack:: Report < errors:: ConnectorError > ;
27
+
28
+ fn try_from (
29
+ ( currency_unit, currency, amount, router_data) : (
30
+ & types:: api:: CurrencyUnit ,
31
+ types:: storage:: enums:: Currency ,
32
+ i64 ,
33
+ T ,
34
+ ) ,
35
+ ) -> Result < Self , Self :: Error > {
36
+ let amount = utils:: get_amount_as_string ( currency_unit, amount, currency) ?;
37
+ Ok ( Self {
38
+ amount,
39
+ router_data,
40
+ } )
41
+ }
42
+ }
12
43
13
44
#[ derive( Serialize , Debug ) ]
14
45
pub struct PayeezyCard {
@@ -66,7 +97,7 @@ pub struct PayeezyPaymentsRequest {
66
97
pub merchant_ref : String ,
67
98
pub transaction_type : PayeezyTransactionType ,
68
99
pub method : PayeezyPaymentMethodType ,
69
- pub amount : i64 ,
100
+ pub amount : String ,
70
101
pub currency_code : String ,
71
102
pub credit_card : PayeezyPaymentMethod ,
72
103
pub stored_credentials : Option < StoredCredentials > ,
@@ -95,10 +126,12 @@ pub enum Initiator {
95
126
CardHolder ,
96
127
}
97
128
98
- impl TryFrom < & types:: PaymentsAuthorizeRouterData > for PayeezyPaymentsRequest {
129
+ impl TryFrom < & PayeezyRouterData < & types:: PaymentsAuthorizeRouterData > > for PayeezyPaymentsRequest {
99
130
type Error = error_stack:: Report < errors:: ConnectorError > ;
100
- fn try_from ( item : & types:: PaymentsAuthorizeRouterData ) -> Result < Self , Self :: Error > {
101
- match item. payment_method {
131
+ fn try_from (
132
+ item : & PayeezyRouterData < & types:: PaymentsAuthorizeRouterData > ,
133
+ ) -> Result < Self , Self :: Error > {
134
+ match item. router_data . payment_method {
102
135
diesel_models:: enums:: PaymentMethod :: Card => get_card_specific_payment_data ( item) ,
103
136
104
137
diesel_models:: enums:: PaymentMethod :: CardRedirect
@@ -119,14 +152,15 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PayeezyPaymentsRequest {
119
152
}
120
153
121
154
fn get_card_specific_payment_data (
122
- item : & types:: PaymentsAuthorizeRouterData ,
155
+ item : & PayeezyRouterData < & types:: PaymentsAuthorizeRouterData > ,
123
156
) -> Result < PayeezyPaymentsRequest , error_stack:: Report < errors:: ConnectorError > > {
124
- let merchant_ref = item. attempt_id . to_string ( ) ;
157
+ let merchant_ref = item. router_data . attempt_id . to_string ( ) ;
125
158
let method = PayeezyPaymentMethodType :: CreditCard ;
126
- let amount = item. request . amount ;
127
- let currency_code = item. request . currency . to_string ( ) ;
159
+ let amount = item. amount . clone ( ) ;
160
+ let currency_code = item. router_data . request . currency . to_string ( ) ;
128
161
let credit_card = get_payment_method_data ( item) ?;
129
- let ( transaction_type, stored_credentials) = get_transaction_type_and_stored_creds ( item) ?;
162
+ let ( transaction_type, stored_credentials) =
163
+ get_transaction_type_and_stored_creds ( item. router_data ) ?;
130
164
Ok ( PayeezyPaymentsRequest {
131
165
merchant_ref,
132
166
transaction_type,
@@ -135,7 +169,7 @@ fn get_card_specific_payment_data(
135
169
currency_code,
136
170
credit_card,
137
171
stored_credentials,
138
- reference : item. connector_request_reference_id . clone ( ) ,
172
+ reference : item. router_data . connector_request_reference_id . clone ( ) ,
139
173
} )
140
174
}
141
175
fn get_transaction_type_and_stored_creds (
@@ -201,9 +235,9 @@ fn is_mandate_payment(
201
235
}
202
236
203
237
fn get_payment_method_data (
204
- item : & types:: PaymentsAuthorizeRouterData ,
238
+ item : & PayeezyRouterData < & types:: PaymentsAuthorizeRouterData > ,
205
239
) -> Result < PayeezyPaymentMethod , error_stack:: Report < errors:: ConnectorError > > {
206
- match item. request . payment_method_data {
240
+ match item. router_data . request . payment_method_data {
207
241
api:: PaymentMethodData :: Card ( ref card) => {
208
242
let card_type = PayeezyCardType :: try_from ( card. get_card_issuer ( ) ?) ?;
209
243
let payeezy_card = PayeezyCard {
@@ -305,16 +339,20 @@ pub struct PayeezyCaptureOrVoidRequest {
305
339
currency_code : String ,
306
340
}
307
341
308
- impl TryFrom < & types:: PaymentsCaptureRouterData > for PayeezyCaptureOrVoidRequest {
342
+ impl TryFrom < & PayeezyRouterData < & types:: PaymentsCaptureRouterData > >
343
+ for PayeezyCaptureOrVoidRequest
344
+ {
309
345
type Error = error_stack:: Report < errors:: ConnectorError > ;
310
- fn try_from ( item : & types:: PaymentsCaptureRouterData ) -> Result < Self , Self :: Error > {
346
+ fn try_from (
347
+ item : & PayeezyRouterData < & types:: PaymentsCaptureRouterData > ,
348
+ ) -> Result < Self , Self :: Error > {
311
349
let metadata: PayeezyPaymentsMetadata =
312
- utils:: to_connector_meta ( item. request . connector_meta . clone ( ) )
350
+ utils:: to_connector_meta ( item. router_data . request . connector_meta . clone ( ) )
313
351
. change_context ( errors:: ConnectorError :: RequestEncodingFailed ) ?;
314
352
Ok ( Self {
315
353
transaction_type : PayeezyTransactionType :: Capture ,
316
- amount : item. request . amount_to_capture . to_string ( ) ,
317
- currency_code : item. request . currency . to_string ( ) ,
354
+ amount : item. amount . clone ( ) ,
355
+ currency_code : item. router_data . request . currency . to_string ( ) ,
318
356
transaction_tag : metadata. transaction_tag ,
319
357
} )
320
358
}
@@ -338,6 +376,7 @@ impl TryFrom<&types::PaymentsCancelRouterData> for PayeezyCaptureOrVoidRequest {
338
376
} )
339
377
}
340
378
}
379
+
341
380
#[ derive( Debug , Deserialize , Serialize , Default ) ]
342
381
#[ serde( rename_all = "lowercase" ) ]
343
382
pub enum PayeezyTransactionType {
@@ -442,16 +481,18 @@ pub struct PayeezyRefundRequest {
442
481
currency_code : String ,
443
482
}
444
483
445
- impl < F > TryFrom < & types:: RefundsRouterData < F > > for PayeezyRefundRequest {
484
+ impl < F > TryFrom < & PayeezyRouterData < & types:: RefundsRouterData < F > > > for PayeezyRefundRequest {
446
485
type Error = error_stack:: Report < errors:: ConnectorError > ;
447
- fn try_from ( item : & types:: RefundsRouterData < F > ) -> Result < Self , Self :: Error > {
486
+ fn try_from (
487
+ item : & PayeezyRouterData < & types:: RefundsRouterData < F > > ,
488
+ ) -> Result < Self , Self :: Error > {
448
489
let metadata: PayeezyPaymentsMetadata =
449
- utils:: to_connector_meta ( item. request . connector_metadata . clone ( ) )
490
+ utils:: to_connector_meta ( item. router_data . request . connector_metadata . clone ( ) )
450
491
. change_context ( errors:: ConnectorError :: RequestEncodingFailed ) ?;
451
492
Ok ( Self {
452
493
transaction_type : PayeezyTransactionType :: Refund ,
453
- amount : item. request . refund_amount . to_string ( ) ,
454
- currency_code : item. request . currency . to_string ( ) ,
494
+ amount : item. amount . clone ( ) ,
495
+ currency_code : item. router_data . request . currency . to_string ( ) ,
455
496
transaction_tag : metadata. transaction_tag ,
456
497
} )
457
498
}
0 commit comments