Repository: juspay/hyperswitch
File: crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs (Rust)

Code before:
                    ),
                    redirection_data: Box::new(None),
                    mandate_reference: Box::new(None),
                    connector_metadata,
                    network_txn_id: None,
                    connector_response_reference_id: Some(item.response.operation.order_id),
                    incremental_authorization_allowed: None,
                    charges: None,
                }),
                ..item.data
            }),
        }
    }
}

impl TryFrom<&NexixpayRouterData<&PaymentsAuthorizeRouterData>> for NexixpayPaymentsRequest {
    type Error = error_stack::Report<errors::ConnectorError>;
    fn try_from(
        item: &NexixpayRouterData<&PaymentsAuthorizeRouterData>,
    ) -> Result<Self, Self::Error> {
        let order_id =
            if item.router_data.connector_request_reference_id.len() <= MAX_ORDER_ID_LENGTH {
                item.router_data.connector_request_reference_id.clone()
            } else {
                get_random_string()
            };
        let billing_address_street = match (
            item.router_data.get_optional_billing_line1(),
            item.router_data.get_optional_billing_line2(),
        ) {
            (Some(line1), Some(line2)) => Some(Secret::new(format!(
                "{}, {}",
                line1.expose(),
                line2.expose()
            ))),
            (Some(line1), None) => Some(line1),
            (None, Some(line2)) => Some(line2),
            (None, None) => None,
        };

        let billing_address = item
            .router_data
            .get_optional_billing()
            .map(|_| {
                let name = item.router_data.get_optional_billing_full_name();
                if let Some(ref val) = name {
                    if val.clone().expose().len() > MAX_BILLING_ADDRESS_NAME_LENGTH {
                        return Err(error_stack::Report::from(
                            errors::ConnectorError::MaxFieldLengthViolated {
                                field_name: "Billing Name".to_string(),
                                connector: "Nexixpay".to_string(),

Review comment (bug):
We need to throw a validation error here, and all other places

We should not send a random orderId which is not stored in HS

Code after:

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateNexixpayConnectorMetaData {
    pub three_d_s_auth_result: Option<ThreeDSAuthResult>,
    pub three_d_s_auth_response: Option<Secret<String>>,
    pub authorization_operation_id: Option<String>,
    pub capture_operation_id: Option<String>,
    pub cancel_operation_id: Option<String>,
    pub psync_flow: Option<NexixpayPaymentIntent>,
    pub meta_data: serde_json::Value,
    pub is_auto_capture: bool,
}

fn update_nexi_meta_data(
    update_request: UpdateNexixpayConnectorMetaData,
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
    let nexixpay_meta_data =
        serde_json::from_value::<NexixpayConnectorMetaData>(update_request.meta_data)
            .change_context(errors::ConnectorError::ParsingFailed)?;

    Ok(serde_json::json!(NexixpayConnectorMetaData {
        three_d_s_auth_result: nexixpay_meta_data
            .three_d_s_auth_result
            .or(update_request.three_d_s_auth_result),
        three_d_s_auth_response: nexixpay_meta_data
            .three_d_s_auth_response
            .or(update_request.three_d_s_auth_response),
        authorization_operation_id: nexixpay_meta_data
            .authorization_operation_id
            .clone()
            .or(update_request.authorization_operation_id.clone()),
        capture_operation_id: {
            nexixpay_meta_data
                .capture_operation_id
                .or(if update_request.is_auto_capture {
                    nexixpay_meta_data
                        .authorization_operation_id
                        .or(update_request.authorization_operation_id.clone())
                } else {
                    update_request.capture_operation_id
                })
        },
        cancel_operation_id: nexixpay_meta_data
            .cancel_operation_id
            .or(update_request.cancel_operation_id),
        psync_flow: update_request
            .psync_flow
            .unwrap_or(nexixpay_meta_data.psync_flow)
    }))
}