@@ -27,6 +27,7 @@ use hyperswitch_domain_models::{
27
27
} ;
28
28
use hyperswitch_interfaces:: { consts:: NO_ERROR_CODE , errors} ;
29
29
use masking:: { ExposeInterface , Secret } ;
30
+ use rand:: distributions:: { Alphanumeric , DistString } ;
30
31
use serde:: { Deserialize , Serialize } ;
31
32
use strum:: Display ;
32
33
@@ -40,6 +41,12 @@ use crate::{
40
41
} ,
41
42
} ;
42
43
44
+ const MAX_ORDER_ID_LENGTH : usize = 18 ;
45
+
46
+ fn get_random_string ( ) -> String {
47
+ Alphanumeric . sample_string ( & mut rand:: thread_rng ( ) , MAX_ORDER_ID_LENGTH )
48
+ }
49
+
43
50
pub struct NexixpayRouterData < T > {
44
51
pub amount : StringMinorUnit ,
45
52
pub router_data : T ,
@@ -480,6 +487,12 @@ impl TryFrom<&NexixpayRouterData<&PaymentsAuthorizeRouterData>> for NexixpayPaym
480
487
fn try_from (
481
488
item : & NexixpayRouterData < & PaymentsAuthorizeRouterData > ,
482
489
) -> Result < Self , Self :: Error > {
490
+ let order_id =
491
+ if item. router_data . connector_request_reference_id . len ( ) <= MAX_ORDER_ID_LENGTH {
492
+ item. router_data . connector_request_reference_id . clone ( )
493
+ } else {
494
+ get_random_string ( )
495
+ } ;
483
496
let billing_address_street = match (
484
497
item. router_data . get_optional_billing_line1 ( ) ,
485
498
item. router_data . get_optional_billing_line2 ( ) ,
@@ -533,7 +546,7 @@ impl TryFrom<&NexixpayRouterData<&PaymentsAuthorizeRouterData>> for NexixpayPaym
533
546
shipping_address : shipping_address. clone ( ) ,
534
547
} ;
535
548
let order = Order {
536
- order_id : item . router_data . connector_request_reference_id . clone ( ) ,
549
+ order_id,
537
550
amount : item. amount . clone ( ) ,
538
551
currency : item. router_data . request . currency ,
539
552
description : item. router_data . description . clone ( ) ,
@@ -1089,7 +1102,12 @@ impl TryFrom<&NexixpayRouterData<&PaymentsCompleteAuthorizeRouterData>>
1089
1102
) ?;
1090
1103
let capture_type = get_nexixpay_capture_type ( item. router_data . request . capture_method ) ?;
1091
1104
1092
- let order_id = item. router_data . connector_request_reference_id . clone ( ) ;
1105
+ let order_id =
1106
+ if item. router_data . connector_request_reference_id . len ( ) <= MAX_ORDER_ID_LENGTH {
1107
+ item. router_data . connector_request_reference_id . clone ( )
1108
+ } else {
1109
+ get_random_string ( )
1110
+ } ;
1093
1111
let amount = item. amount . clone ( ) ;
1094
1112
let billing_address_street = match (
1095
1113
item. router_data . get_optional_billing_line1 ( ) ,
0 commit comments