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

This commit is contained in:
Ayush Anand
2025-10-21 15:11:28 +05:30
committed by GitHub
parent 819ef0e92d
commit 99b58d16f8
2 changed files with 38 additions and 1 deletions

View File

@ -9,6 +9,8 @@ use common_utils::{
request::{Method, Request, RequestBuilder, RequestContent}, request::{Method, Request, RequestBuilder, RequestContent},
}; };
use error_stack::{report, ResultExt}; use error_stack::{report, ResultExt};
#[cfg(feature = "v2")]
use hyperswitch_domain_models::payments::PaymentIntent;
use hyperswitch_domain_models::{ use hyperswitch_domain_models::{
errors::api_error_response::ApiErrorResponse, errors::api_error_response::ApiErrorResponse,
payment_method_data::PaymentMethodData, payment_method_data::PaymentMethodData,
@ -882,6 +884,24 @@ impl ConnectorSpecifications for Nexinets {
fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> { fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {
Some(&NEXINETS_SUPPORTED_WEBHOOK_FLOWS) 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 { impl ConnectorTransactionId for Nexinets {

View File

@ -30,6 +30,10 @@ use crate::{
}, },
}; };
pub mod nexinets_constants {
pub const MAX_PAYMENT_REFERENCE_ID_LENGTH: usize = 30;
}
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct NexinetsPaymentsRequest { pub struct NexinetsPaymentsRequest {
@ -187,7 +191,20 @@ impl TryFrom<&PaymentsAuthorizeRouterData> for NexinetsPaymentsRequest {
let (payment, product) = get_payment_details_and_product(item)?; let (payment, product) = get_payment_details_and_product(item)?;
let merchant_order_id = match item.payment_method { let merchant_order_id = match item.payment_method {
// Merchant order id is sent only in case of card payment // 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, _ => None,
}; };
Ok(Self { Ok(Self {