mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
fix(nexinets): limit connector_request_reference_id to 30 characters using nanoid (#9874)
This commit is contained in:
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user