1
1
use std:: collections:: HashMap ;
2
2
3
3
pub use common_utils:: request:: Method ;
4
- use common_utils:: { errors:: CustomResult , ext_traits:: ValueExt , id_type, pii:: Email } ;
4
+ use common_utils:: {
5
+ errors:: CustomResult , ext_traits:: ValueExt , id_type, pii:: Email , types:: FloatMajorUnit ,
6
+ } ;
5
7
use error_stack:: ResultExt ;
6
8
use masking:: Secret ;
7
9
use serde:: { Deserialize , Serialize } ;
@@ -16,7 +18,7 @@ use crate::{
16
18
#[ derive( Default , Debug , Serialize ) ]
17
19
#[ serde( rename_all = "camelCase" ) ]
18
20
pub struct CashtocodePaymentsRequest {
19
- amount : f64 ,
21
+ amount : FloatMajorUnit ,
20
22
transaction_id : String ,
21
23
user_id : Secret < id_type:: CustomerId > ,
22
24
currency : enums:: Currency ,
@@ -48,9 +50,11 @@ fn get_mid(
48
50
}
49
51
}
50
52
51
- impl TryFrom < & types:: PaymentsAuthorizeRouterData > for CashtocodePaymentsRequest {
53
+ impl TryFrom < ( & types:: PaymentsAuthorizeRouterData , FloatMajorUnit ) > for CashtocodePaymentsRequest {
52
54
type Error = error_stack:: Report < errors:: ConnectorError > ;
53
- fn try_from ( item : & types:: PaymentsAuthorizeRouterData ) -> Result < Self , Self :: Error > {
55
+ fn try_from (
56
+ ( item, amount) : ( & types:: PaymentsAuthorizeRouterData , FloatMajorUnit ) ,
57
+ ) -> Result < Self , Self :: Error > {
54
58
let customer_id = item. get_customer_id ( ) ?;
55
59
let url = item. request . get_router_return_url ( ) ?;
56
60
let mid = get_mid (
@@ -60,10 +64,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for CashtocodePaymentsRequest
60
64
) ?;
61
65
match item. payment_method {
62
66
diesel_models:: enums:: PaymentMethod :: Reward => Ok ( Self {
63
- amount : utils:: to_currency_base_unit_asf64 (
64
- item. request . amount ,
65
- item. request . currency ,
66
- ) ?,
67
+ amount,
67
68
transaction_id : item. attempt_id . clone ( ) ,
68
69
currency : item. request . currency ,
69
70
user_id : Secret :: new ( customer_id. to_owned ( ) ) ,
@@ -192,7 +193,7 @@ pub struct CashtocodePaymentsResponseData {
192
193
#[ serde( rename_all = "camelCase" ) ]
193
194
pub struct CashtocodePaymentsSyncResponse {
194
195
pub transaction_id : String ,
195
- pub amount : f64 ,
196
+ pub amount : FloatMajorUnit ,
196
197
}
197
198
198
199
fn get_redirect_form_data (
@@ -330,7 +331,7 @@ pub struct CashtocodeErrorResponse {
330
331
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
331
332
#[ serde( rename_all = "camelCase" ) ]
332
333
pub struct CashtocodeIncomingWebhook {
333
- pub amount : f64 ,
334
+ pub amount : FloatMajorUnit ,
334
335
pub currency : String ,
335
336
pub foreign_transaction_id : String ,
336
337
#[ serde( rename = "type" ) ]
0 commit comments