1
+ use common_utils:: pii;
1
2
use error_stack:: ResultExt ;
2
3
use masking:: Secret ;
3
4
use serde:: { Deserialize , Serialize } ;
@@ -36,6 +37,23 @@ pub struct NoonSubscriptionData {
36
37
name : String ,
37
38
}
38
39
40
+ #[ derive( Debug , Serialize ) ]
41
+ #[ serde( rename_all = "camelCase" ) ]
42
+ pub struct NoonBillingAddress {
43
+ street : Option < Secret < String > > ,
44
+ street2 : Option < Secret < String > > ,
45
+ city : Option < String > ,
46
+ state_province : Option < Secret < String > > ,
47
+ country : Option < api_models:: enums:: CountryAlpha2 > ,
48
+ postal_code : Option < Secret < String > > ,
49
+ }
50
+
51
+ #[ derive( Debug , Serialize ) ]
52
+ #[ serde( rename_all = "camelCase" ) ]
53
+ pub struct NoonBilling {
54
+ address : NoonBillingAddress ,
55
+ }
56
+
39
57
#[ derive( Debug , Serialize ) ]
40
58
#[ serde( rename_all = "camelCase" ) ]
41
59
pub struct NoonOrder {
@@ -46,6 +64,7 @@ pub struct NoonOrder {
46
64
reference : String ,
47
65
//Short description of the order.
48
66
name : String ,
67
+ ip_address : Option < Secret < String , pii:: IpAddress > > ,
49
68
}
50
69
51
70
#[ derive( Debug , Serialize ) ]
@@ -164,6 +183,7 @@ pub struct NoonPaymentsRequest {
164
183
configuration : NoonConfiguration ,
165
184
payment_data : NoonPaymentData ,
166
185
subscription : Option < NoonSubscriptionData > ,
186
+ billing : Option < NoonBilling > ,
167
187
}
168
188
169
189
impl TryFrom < & types:: PaymentsAuthorizeRouterData > for NoonPaymentsRequest {
@@ -247,6 +267,27 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest {
247
267
. take ( 50 )
248
268
. collect ( ) ;
249
269
270
+ let ip_address = item. request . get_ip_address_as_optional ( ) ;
271
+
272
+ let channel = NoonChannels :: Web ;
273
+
274
+ let billing = item
275
+ . address
276
+ . billing
277
+ . clone ( )
278
+ . and_then ( |billing_address| billing_address. address )
279
+ . map ( |address| NoonBilling {
280
+ address : NoonBillingAddress {
281
+ street : address. line1 ,
282
+ street2 : address. line2 ,
283
+ city : address. city ,
284
+ // If state is passed in request, country becomes mandatory, keep a check while debugging failed payments
285
+ state_province : address. state ,
286
+ country : address. country ,
287
+ postal_code : address. zip ,
288
+ } ,
289
+ } ) ;
290
+
250
291
let ( subscription, tokenize_c_c) =
251
292
match item. request . setup_future_usage . is_some ( ) . then_some ( (
252
293
NoonSubscriptionData {
@@ -261,10 +302,11 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest {
261
302
let order = NoonOrder {
262
303
amount : conn_utils:: to_currency_base_unit ( item. request . amount , item. request . currency ) ?,
263
304
currency,
264
- channel : NoonChannels :: Web ,
305
+ channel,
265
306
category,
266
307
reference : item. connector_request_reference_id . clone ( ) ,
267
308
name,
309
+ ip_address,
268
310
} ;
269
311
let payment_action = if item. request . is_auto_capture ( ) ? {
270
312
NoonPaymentActions :: Sale
@@ -274,6 +316,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest {
274
316
Ok ( Self {
275
317
api_operation : NoonApiOperations :: Initiate ,
276
318
order,
319
+ billing,
277
320
configuration : NoonConfiguration {
278
321
payment_action,
279
322
return_url : item. request . router_return_url . clone ( ) ,
@@ -333,7 +376,8 @@ impl From<NoonPaymentStatus> for enums::AttemptStatus {
333
376
fn from ( item : NoonPaymentStatus ) -> Self {
334
377
match item {
335
378
NoonPaymentStatus :: Authorized => Self :: Authorized ,
336
- NoonPaymentStatus :: Captured | NoonPaymentStatus :: PartiallyCaptured => Self :: Charged ,
379
+ NoonPaymentStatus :: Captured => Self :: Charged ,
380
+ NoonPaymentStatus :: PartiallyCaptured => Self :: PartialCharged ,
337
381
NoonPaymentStatus :: Reversed => Self :: Voided ,
338
382
NoonPaymentStatus :: Cancelled | NoonPaymentStatus :: Expired => Self :: AuthenticationFailed ,
339
383
NoonPaymentStatus :: ThreeDsEnrollInitiated | NoonPaymentStatus :: ThreeDsEnrollChecked => {
@@ -444,6 +488,7 @@ pub struct NoonActionTransaction {
444
488
#[ serde( rename_all = "camelCase" ) ]
445
489
pub struct NoonActionOrder {
446
490
id : String ,
491
+ cancellation_reason : Option < String > ,
447
492
}
448
493
449
494
#[ derive( Debug , Serialize ) ]
@@ -459,6 +504,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for NoonPaymentsActionRequest {
459
504
fn try_from ( item : & types:: PaymentsCaptureRouterData ) -> Result < Self , Self :: Error > {
460
505
let order = NoonActionOrder {
461
506
id : item. request . connector_transaction_id . clone ( ) ,
507
+ cancellation_reason : None ,
462
508
} ;
463
509
let transaction = NoonActionTransaction {
464
510
amount : conn_utils:: to_currency_base_unit (
@@ -488,6 +534,11 @@ impl TryFrom<&types::PaymentsCancelRouterData> for NoonPaymentsCancelRequest {
488
534
fn try_from ( item : & types:: PaymentsCancelRouterData ) -> Result < Self , Self :: Error > {
489
535
let order = NoonActionOrder {
490
536
id : item. request . connector_transaction_id . clone ( ) ,
537
+ cancellation_reason : item
538
+ . request
539
+ . cancellation_reason
540
+ . clone ( )
541
+ . map ( |reason| reason. chars ( ) . take ( 100 ) . collect ( ) ) , // Max 100 chars
491
542
} ;
492
543
Ok ( Self {
493
544
api_operation : NoonApiOperations :: Reverse ,
@@ -501,6 +552,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for NoonPaymentsActionRequest {
501
552
fn try_from ( item : & types:: RefundsRouterData < F > ) -> Result < Self , Self :: Error > {
502
553
let order = NoonActionOrder {
503
554
id : item. request . connector_transaction_id . clone ( ) ,
555
+ cancellation_reason : None ,
504
556
} ;
505
557
let transaction = NoonActionTransaction {
506
558
amount : conn_utils:: to_currency_base_unit (
0 commit comments