1
1
use api_models:: payments;
2
- use common_utils:: pii;
2
+ use common_utils:: { pii, types :: MinorUnit } ;
3
3
use error_stack:: { report, ResultExt } ;
4
4
use hyperswitch_domain_models:: router_data:: KlarnaSdkResponse ;
5
5
use masking:: { ExposeInterface , Secret } ;
@@ -15,25 +15,21 @@ use crate::{
15
15
16
16
#[ derive( Debug , Serialize ) ]
17
17
pub struct KlarnaRouterData < T > {
18
- amount : i64 ,
18
+ amount : MinorUnit ,
19
19
router_data : T ,
20
20
}
21
21
22
- impl < T > TryFrom < ( & api:: CurrencyUnit , enums:: Currency , i64 , T ) > for KlarnaRouterData < T > {
23
- type Error = error_stack:: Report < errors:: ConnectorError > ;
24
-
25
- fn try_from (
26
- ( _currency_unit, _currency, amount, router_data) : (
27
- & api:: CurrencyUnit ,
28
- enums:: Currency ,
29
- i64 ,
22
+ impl < T > From < ( MinorUnit , T ) > for KlarnaRouterData < T > {
23
+ fn from (
24
+ ( amount, router_data) : (
25
+ MinorUnit ,
30
26
T ,
31
27
) ,
32
- ) -> Result < Self , Self :: Error > {
33
- Ok ( Self {
28
+ ) -> Self {
29
+ Self {
34
30
amount,
35
31
router_data,
36
- } )
32
+ }
37
33
}
38
34
}
39
35
@@ -74,7 +70,7 @@ impl TryFrom<&Option<pii::SecretSerdeValue>> for KlarnaConnectorMetadataObject {
74
70
pub struct KlarnaPaymentsRequest {
75
71
auto_capture : bool ,
76
72
order_lines : Vec < OrderLines > ,
77
- order_amount : i64 ,
73
+ order_amount : MinorUnit ,
78
74
purchase_country : enums:: CountryAlpha2 ,
79
75
purchase_currency : enums:: Currency ,
80
76
merchant_reference1 : Option < String > ,
@@ -110,7 +106,7 @@ pub struct KlarnaSessionRequest {
110
106
intent : KlarnaSessionIntent ,
111
107
purchase_country : enums:: CountryAlpha2 ,
112
108
purchase_currency : enums:: Currency ,
113
- order_amount : i64 ,
109
+ order_amount : MinorUnit ,
114
110
order_lines : Vec < OrderLines > ,
115
111
shipping_address : Option < KlarnaShippingAddress > ,
116
112
}
@@ -156,8 +152,8 @@ impl TryFrom<&KlarnaRouterData<&types::PaymentsSessionRouterData>> for KlarnaSes
156
152
. map ( |data| OrderLines {
157
153
name : data. product_name . clone ( ) ,
158
154
quantity : data. quantity ,
159
- unit_price : data. amount ,
160
- total_amount : i64:: from ( data. quantity ) * ( data. amount ) ,
155
+ unit_price : data. minor_amount ,
156
+ total_amount : MinorUnit :: new ( i64:: from ( data. quantity ) * ( data. minor_amount . get_amount_as_i64 ( ) ) ) ,
161
157
} )
162
158
. collect ( ) ,
163
159
shipping_address : get_address_info ( item. router_data . get_optional_shipping ( ) )
@@ -209,8 +205,8 @@ impl TryFrom<&KlarnaRouterData<&types::PaymentsAuthorizeRouterData>> for KlarnaP
209
205
. map ( |data| OrderLines {
210
206
name : data. product_name . clone ( ) ,
211
207
quantity : data. quantity ,
212
- unit_price : data. amount ,
213
- total_amount : i64:: from ( data. quantity ) * ( data. amount ) ,
208
+ unit_price : data. minor_amount ,
209
+ total_amount : MinorUnit :: new ( i64:: from ( data. quantity ) * ( data. minor_amount . get_amount_as_i64 ( ) ) ) ,
214
210
} )
215
211
. collect ( ) ,
216
212
merchant_reference1 : Some ( item. router_data . connector_request_reference_id . clone ( ) ) ,
@@ -294,8 +290,8 @@ impl TryFrom<types::PaymentsResponseRouterData<KlarnaPaymentsResponse>>
294
290
pub struct OrderLines {
295
291
name : String ,
296
292
quantity : u16 ,
297
- unit_price : i64 ,
298
- total_amount : i64 ,
293
+ unit_price : MinorUnit ,
294
+ total_amount : MinorUnit ,
299
295
}
300
296
301
297
#[ derive( Debug , Serialize ) ]
@@ -412,7 +408,7 @@ impl<F, T>
412
408
413
409
#[ derive( Debug , Serialize ) ]
414
410
pub struct KlarnaCaptureRequest {
415
- captured_amount : i64 ,
411
+ captured_amount : MinorUnit ,
416
412
reference : Option < String > ,
417
413
}
418
414
@@ -490,7 +486,7 @@ impl<F>
490
486
491
487
#[ derive( Default , Debug , Serialize ) ]
492
488
pub struct KlarnaRefundRequest {
493
- refunded_amount : i64 ,
489
+ refunded_amount : MinorUnit ,
494
490
reference : Option < String > ,
495
491
}
496
492
0 commit comments