@@ -2,7 +2,7 @@ use std::collections::HashMap;
2
2
3
3
use cards:: CardNumber ;
4
4
use common_enums:: enums;
5
- use common_utils:: { pii, request:: Method , types:: MinorUnit } ;
5
+ use common_utils:: { pii, request:: Method , types:: FloatMajorUnit } ;
6
6
use hyperswitch_domain_models:: {
7
7
payment_method_data:: PaymentMethodData ,
8
8
router_data:: { ConnectorAuthType , ErrorResponse , RouterData } ,
@@ -20,7 +20,7 @@ use hyperswitch_interfaces::{
20
20
consts:: { NO_ERROR_CODE , NO_ERROR_MESSAGE } ,
21
21
errors,
22
22
} ;
23
- use masking:: { ExposeInterface , Secret } ;
23
+ use masking:: { ExposeInterface , PeekInterface , Secret } ;
24
24
use serde:: { Deserialize , Serialize } ;
25
25
26
26
use crate :: {
@@ -33,7 +33,7 @@ use crate::{
33
33
34
34
//TODO: Fill the struct with respective fields
35
35
pub struct XenditRouterData < T > {
36
- pub amount : MinorUnit , // The type of amount that a connector accepts, for example, String, i64, f64, etc.
36
+ pub amount : FloatMajorUnit , // The type of amount that a connector accepts, for example, String, i64, f64, etc.
37
37
pub router_data : T ,
38
38
}
39
39
@@ -58,11 +58,11 @@ pub struct CardPaymentRequest {
58
58
pub payment_type : PaymentMethodType ,
59
59
pub card : CardInfo ,
60
60
pub reusability : TransactionType ,
61
- pub reference_id : String ,
61
+ pub reference_id : Secret < String > ,
62
62
}
63
63
#[ derive( Serialize , Deserialize , Debug ) ]
64
64
pub struct MandatePaymentRequest {
65
- pub amount : MinorUnit ,
65
+ pub amount : FloatMajorUnit ,
66
66
pub currency : common_enums:: Currency ,
67
67
pub capture_method : String ,
68
68
pub payment_method_id : Secret < String > ,
@@ -74,11 +74,11 @@ pub struct XenditRedirectionResponse {
74
74
}
75
75
#[ derive( Serialize , Deserialize , Debug ) ]
76
76
pub struct XenditPaymentsCaptureRequest {
77
- pub capture_amount : MinorUnit ,
77
+ pub capture_amount : FloatMajorUnit ,
78
78
}
79
79
#[ derive( Serialize , Deserialize , Debug ) ]
80
80
pub struct XenditPaymentsRequest {
81
- pub amount : MinorUnit ,
81
+ pub amount : FloatMajorUnit ,
82
82
pub currency : common_enums:: Currency ,
83
83
pub capture_method : String ,
84
84
#[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -133,7 +133,7 @@ pub struct XenditPaymentResponse {
133
133
pub actions : Option < Vec < Action > > ,
134
134
pub payment_method : PaymentMethodInfo ,
135
135
pub failure_code : Option < String > ,
136
- pub reference_id : String ,
136
+ pub reference_id : Secret < String > ,
137
137
}
138
138
139
139
fn map_payment_response_to_attempt_status (
@@ -142,13 +142,14 @@ fn map_payment_response_to_attempt_status(
142
142
) -> enums:: AttemptStatus {
143
143
match response. status {
144
144
PaymentStatus :: Failed => enums:: AttemptStatus :: Failure ,
145
- PaymentStatus :: Succeeded | PaymentStatus :: Pending | PaymentStatus :: Verified => {
145
+ PaymentStatus :: Succeeded | PaymentStatus :: Verified => {
146
146
if is_auto_capture {
147
147
enums:: AttemptStatus :: Charged
148
148
} else {
149
149
enums:: AttemptStatus :: Authorized
150
150
}
151
151
}
152
+ PaymentStatus :: Pending => enums:: AttemptStatus :: Pending ,
152
153
PaymentStatus :: RequiresAction => enums:: AttemptStatus :: AuthenticationPending ,
153
154
PaymentStatus :: AwaitingCapture => enums:: AttemptStatus :: Authorized ,
154
155
}
@@ -182,17 +183,13 @@ impl TryFrom<XenditRouterData<&PaymentsAuthorizeRouterData>> for XenditPaymentsR
182
183
amount : item. amount ,
183
184
payment_method : Some ( PaymentMethod :: Card ( CardPaymentRequest {
184
185
payment_type : PaymentMethodType :: CARD ,
185
- reference_id : item. router_data . connector_request_reference_id . clone ( ) ,
186
+ reference_id : Secret :: new (
187
+ item. router_data . connector_request_reference_id . clone ( ) ,
188
+ ) ,
186
189
card : CardInfo {
187
190
channel_properties : ChannelProperties {
188
- success_return_url : item
189
- . router_data
190
- . request
191
- . get_complete_authorize_url ( ) ?,
192
- failure_return_url : item
193
- . router_data
194
- . request
195
- . get_complete_authorize_url ( ) ?,
191
+ success_return_url : item. router_data . request . get_router_return_url ( ) ?,
192
+ failure_return_url : item. router_data . request . get_router_return_url ( ) ?,
196
193
skip_three_d_secure : !item. router_data . is_three_ds ( ) ,
197
194
} ,
198
195
card_information : CardInformation {
@@ -220,8 +217,8 @@ impl TryFrom<XenditRouterData<&PaymentsAuthorizeRouterData>> for XenditPaymentsR
220
217
} ) ,
221
218
PaymentMethodData :: MandatePayment => Ok ( Self {
222
219
channel_properties : Some ( ChannelProperties {
223
- success_return_url : item. router_data . request . get_complete_authorize_url ( ) ?,
224
- failure_return_url : item. router_data . request . get_complete_authorize_url ( ) ?,
220
+ success_return_url : item. router_data . request . get_router_return_url ( ) ?,
221
+ failure_return_url : item. router_data . request . get_router_return_url ( ) ?,
225
222
skip_three_d_secure : true ,
226
223
} ) ,
227
224
capture_method : match item. router_data . request . is_auto_capture ( ) ? {
@@ -291,7 +288,7 @@ impl<F>
291
288
status_code : item. http_code ,
292
289
} )
293
290
} else {
294
- let x = Ok ( PaymentsResponseData :: TransactionResponse {
291
+ Ok ( PaymentsResponseData :: TransactionResponse {
295
292
resource_id : ResponseId :: ConnectorTransactionId ( item. response . id . clone ( ) ) ,
296
293
redirection_data : match item. response . actions {
297
294
Some ( actions) if !actions. is_empty ( ) => {
@@ -319,11 +316,12 @@ impl<F>
319
316
} ,
320
317
connector_metadata : None ,
321
318
network_txn_id : None ,
322
- connector_response_reference_id : Some ( item. response . reference_id ) ,
319
+ connector_response_reference_id : Some (
320
+ item. response . reference_id . peek ( ) . to_string ( ) ,
321
+ ) ,
323
322
incremental_authorization_allowed : None ,
324
323
charge_id : None ,
325
- } ) ;
326
- x
324
+ } )
327
325
} ;
328
326
Ok ( Self {
329
327
status,
@@ -376,7 +374,9 @@ impl<F>
376
374
mandate_reference : Box :: new ( None ) ,
377
375
connector_metadata : None ,
378
376
network_txn_id : None ,
379
- connector_response_reference_id : Some ( item. response . reference_id ) ,
377
+ connector_response_reference_id : Some (
378
+ item. response . reference_id . peek ( ) . to_string ( ) ,
379
+ ) ,
380
380
incremental_authorization_allowed : None ,
381
381
charge_id : None ,
382
382
} )
@@ -420,7 +420,7 @@ impl TryFrom<PaymentsSyncResponseRouterData<XenditPaymentResponse>> for Payments
420
420
} )
421
421
} else {
422
422
Ok ( PaymentsResponseData :: TransactionResponse {
423
- resource_id : ResponseId :: ConnectorTransactionId ( item . response . id . clone ( ) ) ,
423
+ resource_id : ResponseId :: NoResponseId ,
424
424
redirection_data : Box :: new ( None ) ,
425
425
mandate_reference : Box :: new ( None ) ,
426
426
connector_metadata : None ,
@@ -437,8 +437,8 @@ impl TryFrom<PaymentsSyncResponseRouterData<XenditPaymentResponse>> for Payments
437
437
} )
438
438
}
439
439
}
440
- impl < T > From < ( MinorUnit , T ) > for XenditRouterData < T > {
441
- fn from ( ( amount, item) : ( MinorUnit , T ) ) -> Self {
440
+ impl < T > From < ( FloatMajorUnit , T ) > for XenditRouterData < T > {
441
+ fn from ( ( amount, item) : ( FloatMajorUnit , T ) ) -> Self {
442
442
Self {
443
443
amount,
444
444
router_data : item,
@@ -469,7 +469,7 @@ impl TryFrom<&ConnectorAuthType> for XenditAuthType {
469
469
// Type definition for RefundRequest
470
470
#[ derive( Default , Debug , Serialize ) ]
471
471
pub struct XenditRefundRequest {
472
- pub amount : MinorUnit ,
472
+ pub amount : FloatMajorUnit ,
473
473
pub payment_request_id : String ,
474
474
pub reason : String ,
475
475
}
0 commit comments