@@ -11,6 +11,37 @@ use crate::{
11
11
types:: { self , api, storage:: enums} ,
12
12
} ;
13
13
14
+ #[ derive( Debug , Serialize ) ]
15
+ pub struct StaxRouterData < T > {
16
+ pub amount : f64 ,
17
+ pub router_data : T ,
18
+ }
19
+
20
+ impl < T >
21
+ TryFrom < (
22
+ & types:: api:: CurrencyUnit ,
23
+ types:: storage:: enums:: Currency ,
24
+ i64 ,
25
+ T ,
26
+ ) > for StaxRouterData < T >
27
+ {
28
+ type Error = error_stack:: Report < errors:: ConnectorError > ;
29
+ fn try_from (
30
+ ( currency_unit, currency, amount, item) : (
31
+ & types:: api:: CurrencyUnit ,
32
+ types:: storage:: enums:: Currency ,
33
+ i64 ,
34
+ T ,
35
+ ) ,
36
+ ) -> Result < Self , Self :: Error > {
37
+ let amount = utils:: get_amount_as_f64 ( currency_unit, amount, currency) ?;
38
+ Ok ( Self {
39
+ amount,
40
+ router_data : item,
41
+ } )
42
+ }
43
+ }
44
+
14
45
#[ derive( Debug , Serialize ) ]
15
46
pub struct StaxPaymentsRequestMetaData {
16
47
tax : i64 ,
@@ -26,21 +57,23 @@ pub struct StaxPaymentsRequest {
26
57
idempotency_id : Option < String > ,
27
58
}
28
59
29
- impl TryFrom < & types:: PaymentsAuthorizeRouterData > for StaxPaymentsRequest {
60
+ impl TryFrom < & StaxRouterData < & types:: PaymentsAuthorizeRouterData > > for StaxPaymentsRequest {
30
61
type Error = error_stack:: Report < errors:: ConnectorError > ;
31
- fn try_from ( item : & types:: PaymentsAuthorizeRouterData ) -> Result < Self , Self :: Error > {
32
- if item. request . currency != enums:: Currency :: USD {
62
+ fn try_from (
63
+ item : & StaxRouterData < & types:: PaymentsAuthorizeRouterData > ,
64
+ ) -> Result < Self , Self :: Error > {
65
+ if item. router_data . request . currency != enums:: Currency :: USD {
33
66
Err ( errors:: ConnectorError :: NotSupported {
34
- message : item. request . currency . to_string ( ) ,
67
+ message : item. router_data . request . currency . to_string ( ) ,
35
68
connector : "Stax" ,
36
69
} ) ?
37
70
}
38
- let total = utils :: to_currency_base_unit_asf64 ( item. request . amount , item . request . currency ) ? ;
71
+ let total = item. amount ;
39
72
40
- match item. request . payment_method_data . clone ( ) {
73
+ match item. router_data . request . payment_method_data . clone ( ) {
41
74
api:: PaymentMethodData :: Card ( _) => {
42
- let pm_token = item. get_payment_method_token ( ) ?;
43
- let pre_auth = !item. request . is_auto_capture ( ) ?;
75
+ let pm_token = item. router_data . get_payment_method_token ( ) ?;
76
+ let pre_auth = !item. router_data . request . is_auto_capture ( ) ?;
44
77
Ok ( Self {
45
78
meta : StaxPaymentsRequestMetaData { tax : 0 } ,
46
79
total,
@@ -52,14 +85,14 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for StaxPaymentsRequest {
52
85
Err ( errors:: ConnectorError :: InvalidWalletToken ) ?
53
86
}
54
87
} ) ,
55
- idempotency_id : Some ( item. connector_request_reference_id . clone ( ) ) ,
88
+ idempotency_id : Some ( item. router_data . connector_request_reference_id . clone ( ) ) ,
56
89
} )
57
90
}
58
91
api:: PaymentMethodData :: BankDebit (
59
92
api_models:: payments:: BankDebitData :: AchBankDebit { .. } ,
60
93
) => {
61
- let pm_token = item. get_payment_method_token ( ) ?;
62
- let pre_auth = !item. request . is_auto_capture ( ) ?;
94
+ let pm_token = item. router_data . get_payment_method_token ( ) ?;
95
+ let pre_auth = !item. router_data . request . is_auto_capture ( ) ?;
63
96
Ok ( Self {
64
97
meta : StaxPaymentsRequestMetaData { tax : 0 } ,
65
98
total,
@@ -71,7 +104,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for StaxPaymentsRequest {
71
104
Err ( errors:: ConnectorError :: InvalidWalletToken ) ?
72
105
}
73
106
} ) ,
74
- idempotency_id : Some ( item. connector_request_reference_id . clone ( ) ) ,
107
+ idempotency_id : Some ( item. router_data . connector_request_reference_id . clone ( ) ) ,
75
108
} )
76
109
}
77
110
api:: PaymentMethodData :: BankDebit ( _)
@@ -347,13 +380,12 @@ pub struct StaxCaptureRequest {
347
380
total : Option < f64 > ,
348
381
}
349
382
350
- impl TryFrom < & types:: PaymentsCaptureRouterData > for StaxCaptureRequest {
383
+ impl TryFrom < & StaxRouterData < & types:: PaymentsCaptureRouterData > > for StaxCaptureRequest {
351
384
type Error = error_stack:: Report < errors:: ConnectorError > ;
352
- fn try_from ( item : & types:: PaymentsCaptureRouterData ) -> Result < Self , Self :: Error > {
353
- let total = utils:: to_currency_base_unit_asf64 (
354
- item. request . amount_to_capture ,
355
- item. request . currency ,
356
- ) ?;
385
+ fn try_from (
386
+ item : & StaxRouterData < & types:: PaymentsCaptureRouterData > ,
387
+ ) -> Result < Self , Self :: Error > {
388
+ let total = item. amount ;
357
389
Ok ( Self { total : Some ( total) } )
358
390
}
359
391
}
@@ -365,15 +397,10 @@ pub struct StaxRefundRequest {
365
397
pub total : f64 ,
366
398
}
367
399
368
- impl < F > TryFrom < & types:: RefundsRouterData < F > > for StaxRefundRequest {
400
+ impl < F > TryFrom < & StaxRouterData < & types:: RefundsRouterData < F > > > for StaxRefundRequest {
369
401
type Error = error_stack:: Report < errors:: ConnectorError > ;
370
- fn try_from ( item : & types:: RefundsRouterData < F > ) -> Result < Self , Self :: Error > {
371
- Ok ( Self {
372
- total : utils:: to_currency_base_unit_asf64 (
373
- item. request . refund_amount ,
374
- item. request . currency ,
375
- ) ?,
376
- } )
402
+ fn try_from ( item : & StaxRouterData < & types:: RefundsRouterData < F > > ) -> Result < Self , Self :: Error > {
403
+ Ok ( Self { total : item. amount } )
377
404
}
378
405
}
379
406
0 commit comments