Skip to content

Commit 2bdcaa6

Browse files
Sayak BhattacharyaSayak Bhattacharya
authored andcommitted
fix(connector): [NEXIXPAY] Limit OrderId length to 18 characters
1 parent 42827d2 commit 2bdcaa6

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use hyperswitch_domain_models::{
2727
};
2828
use hyperswitch_interfaces::{consts::NO_ERROR_CODE, errors};
2929
use masking::{ExposeInterface, Secret};
30+
use rand::distributions::{Alphanumeric, DistString};
3031
use serde::{Deserialize, Serialize};
3132
use strum::Display;
3233

@@ -40,6 +41,12 @@ use crate::{
4041
},
4142
};
4243

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+
4350
pub struct NexixpayRouterData<T> {
4451
pub amount: StringMinorUnit,
4552
pub router_data: T,
@@ -480,6 +487,12 @@ impl TryFrom<&NexixpayRouterData<&PaymentsAuthorizeRouterData>> for NexixpayPaym
480487
fn try_from(
481488
item: &NexixpayRouterData<&PaymentsAuthorizeRouterData>,
482489
) -> 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+
};
483496
let billing_address_street = match (
484497
item.router_data.get_optional_billing_line1(),
485498
item.router_data.get_optional_billing_line2(),
@@ -533,7 +546,7 @@ impl TryFrom<&NexixpayRouterData<&PaymentsAuthorizeRouterData>> for NexixpayPaym
533546
shipping_address: shipping_address.clone(),
534547
};
535548
let order = Order {
536-
order_id: item.router_data.connector_request_reference_id.clone(),
549+
order_id,
537550
amount: item.amount.clone(),
538551
currency: item.router_data.request.currency,
539552
description: item.router_data.description.clone(),
@@ -1089,7 +1102,12 @@ impl TryFrom<&NexixpayRouterData<&PaymentsCompleteAuthorizeRouterData>>
10891102
)?;
10901103
let capture_type = get_nexixpay_capture_type(item.router_data.request.capture_method)?;
10911104

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+
};
10931111
let amount = item.amount.clone();
10941112
let billing_address_street = match (
10951113
item.router_data.get_optional_billing_line1(),

0 commit comments

Comments
 (0)