Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(nexinets): limit connector_request_reference_id to 30 characters using nanoid (#9874)

Ayush Anand99b58d16f845
diff --git a/crates/hyperswitch_connectors/src/connectors/nexinets.rs b/crates/hyperswitch_connectors/src/connectors/nexinets.rs
index a90e0d8fe8..0aad1260b3 100644
--- a/crates/hyperswitch_connectors/src/connectors/nexinets.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nexinets.rs
@@ -9,6 +9,8 @@ use common_utils::{
request::{Method, Request, RequestBuilder, RequestContent},
};
use error_stack::{report, ResultExt};
+#[cfg(feature = "v2")]
+use hyperswitch_domain_models::payments::PaymentIntent;
use hyperswitch_domain_models::{
errors::api_error_response::ApiErrorResponse,
payment_method_data::PaymentMethodData,
@@ -882,6 +884,24 @@ impl ConnectorSpecifications for Nexinets {
fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {
Some(&NEXINETS_SUPPORTED_WEBHOOK_FLOWS)
}
+
+ #[cfg(feature = "v2")]
+ fn generate_connector_request_reference_id(
+ &self,
+ payment_intent: &PaymentIntent,
+ _payment_attempt: &PaymentAttempt,
+ ) -> String {
+ // The length of merchantOrderId for Nexinets should not exceed 30 characters.
+ payment_intent
+ .merchant_reference_id
+ .as_ref()
+ .map(|id| id.get_string_repr().to_owned())
+ .unwrap_or_else(|| {
+ let max_payment_reference_id_length =
+ nexinets::nexinets_constants::MAX_PAYMENT_REFERENCE_ID_LENGTH;
+ nanoid::nanoid!(max_payment_reference_id_length)
+ })
+ }
}
impl ConnectorTransactionId for Nexinets {
diff --git a/crates/hyperswitch_connectors/src/connectors/nexinets/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nexinets/transformers.rs
index cc8ada03d0..8717c63c05 100644
--- a/crates/hyperswitch_connectors/src/connectors/nexinets/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nexinets/transformers.rs
@@ -30,6 +30,10 @@ use crate::{
},
};
+pub mod nexinets_constants {
+ pub const MAX_PAYMENT_REFERENCE_ID_LENGTH: usize = 30;
+}
+
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NexinetsPaymentsRequest {
@@ -187,7 +191,20 @@ impl TryFrom<&PaymentsAuthorizeRouterData> for NexinetsPaymentsRequest {
let (payment, product) = get_payment_details_and_product(item)?;
let merchant_order_id = match item.payment_method {
// Merchant order id is sent only in case of card payment
- enums::PaymentMethod::Card => Some(item.connector_request_reference_id.clone()),
+ enums::PaymentMethod::Card => {
+ if item.connector_request_reference_id.len()
+ <= nexinets_constants::MAX_PAYMENT_REFERENCE_ID_LENGTH
+ {
+ Ok(Some(item.connector_request_reference_id.clone()))
+ } else {
+ Err(errors::ConnectorError::MaxFieldLengthViolated {
+ connector: "Nexinets".to_string(),
+ field_name: "merchant_order_id".to_string(),
+ max_length: nexinets_constants::MAX_PAYMENT_REFERENCE_ID_LENGTH,
+ received_length: item.connector_request_reference_id.len(),
+ })
+ }
+ }?,
_ => None,
};
Ok(Self {