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

feat(connector): Added UCS flow for Nexixpay (#10451)

Yashasvi Kapil6ade1297aaeb
diff --git a/crates/hyperswitch_connectors/src/connectors/nexixpay.rs b/crates/hyperswitch_connectors/src/connectors/nexixpay.rs
index dc55e6cc47..3b4742da88 100644
--- a/crates/hyperswitch_connectors/src/connectors/nexixpay.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nexixpay.rs
@@ -20,12 +20,13 @@ use hyperswitch_domain_models::{
},
refunds::{Execute, RSync},
unified_authentication_service::PostAuthenticate,
+ PreAuthenticate,
},
router_request_types::{
AccessTokenRequestData, CompleteAuthorizeData, PaymentMethodTokenizationData,
PaymentsAuthorizeData, PaymentsCancelData, PaymentsCaptureData,
- PaymentsPostAuthenticateData, PaymentsPreProcessingData, PaymentsSessionData,
- PaymentsSyncData, RefundsData, SetupMandateRequestData,
+ PaymentsPostAuthenticateData, PaymentsPreAuthenticateData, PaymentsPreProcessingData,
+ PaymentsSessionData, PaymentsSyncData, RefundsData, SetupMandateRequestData,
},
router_response_types::{
ConnectorInfo, PaymentMethodDetails, PaymentsResponseData, RefundsResponseData,
@@ -34,8 +35,8 @@ use hyperswitch_domain_models::{
types::{
PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
PaymentsCompleteAuthorizeRouterData, PaymentsPostAuthenticateRouterData,
- PaymentsPreProcessingRouterData, PaymentsSyncRouterData, RefundSyncRouterData,
- RefundsRouterData, SetupMandateRouterData,
+ PaymentsPreAuthenticateRouterData, PaymentsPreProcessingRouterData, PaymentsSyncRouterData,
+ RefundSyncRouterData, RefundsRouterData, SetupMandateRouterData,
},
};
use hyperswitch_interfaces::{
@@ -46,7 +47,7 @@ use hyperswitch_interfaces::{
configs::Connectors,
consts, errors,
events::connector_api_logs::ConnectorEvent,
- types::{self, Response},
+ types::{self, PaymentsPreAuthenticateType, Response},
webhooks,
};
use lazy_static::lazy_static;
@@ -58,7 +59,7 @@ use uuid::Uuid;
use crate::{
constants::headers,
types::ResponseRouterData,
- utils::{self, PaymentMethodDataType, RefundsRequestData},
+ utils::{self, PaymentMethodDataType, PaymentsAuthorizeRequestData, RefundsRequestData},
};
#[derive(Clone)]
@@ -72,6 +73,18 @@ impl Nexixpay {
amount_converter: &StringMinorUnitForConnector,
}
}
+
+ pub fn is_3ds_setup_required(
+ &self,
+ request: &PaymentsAuthorizeData,
+ auth_type: common_enums::AuthenticationType,
+ ) -> bool {
+ auth_type.is_three_ds()
+ && request.is_card()
+ && (request.connector_mandate_id().is_none()
+ && request.get_optional_network_transaction_id().is_none())
+ && request.authentication_data.is_none()
+ }
}
impl api::Payment for Nexixpay {}
@@ -89,6 +102,7 @@ impl api::RefundSync for Nexixpay {}
impl api::PaymentToken for Nexixpay {}
impl api::PaymentsCompleteAuthorize for Nexixpay {}
impl api::PaymentsPostAuthenticate for Nexixpay {}
+impl api::PaymentsPreAuthenticate for Nexixpay {}
impl ConnectorIntegration<PaymentMethodToken, PaymentMethodTokenizationData, PaymentsResponseData>
for Nexixpay
@@ -407,6 +421,97 @@ impl ConnectorIntegration<PostAuthenticate, PaymentsPostAuthenticateData, Paymen
}
}
+impl ConnectorIntegration<PreAuthenticate, PaymentsPreAuthenticateData, PaymentsResponseData>
+ for Nexixpay
+{
+ fn get_headers(
+ &self,
+ req: &PaymentsPreAuthenticateRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
+
+ fn get_url(
+ &self,
+ _req: &PaymentsPreAuthenticateRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Ok(format!("{}/orders/3steps/init", self.base_url(connectors)))
+ }
+
+ fn get_request_body(
+ &self,
+ req: &PaymentsPreAuthenticateRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let amount = utils::convert_amount(
+ self.amount_converter,
+ req.request.minor_amount,
+ req.request
+ .currency
+ .ok_or(errors::ConnectorError::MissingRequiredField {
+ field_name: "currency",
+ })?,
+ )?;
+
+ let connector_router_data = nexixpay::NexixpayRouterData::from((amount, req));
+ let connector_req = nexixpay::NexixpayPaymentsRequest::try_from(&connector_router_data)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
+
+ fn build_request(
+ &self,
+ req: &PaymentsPreAuthenticateRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Ok(Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .url(&PaymentsPreAuthenticateType::get_url(
+ self, req, connectors,
+ )?)
+ .attach_default_headers()
+ .headers(PaymentsPreAuthenticateType::get_headers(
+ self, req, connectors,
+ )?)
+ .set_body(self.get_request_body(req, connectors)?)
+ .build(),
+ ))
+ }
+
+ fn handle_response(
+ &self,
+ data: &PaymentsPreAuthenticateRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PaymentsPreAuthenticateRouterData, errors::ConnectorError> {
+ let response: nexixpay::NexixpayPaymentsResponse = res
+ .response
+ .parse_struct("NexixpayPaymentsResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
+
impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResponseData>
for Nexixpay
{
@@ -1259,4 +1364,23 @@ impl ConnectorSpecifications for Nexixpay {
fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {
Some(&*NEXIXPAY_SUPPORTED_WEBHOOK_FLOWS)
}
+
+ fn is_pre_authentication_flow_required(&self, current_flow: api::CurrentFlowInfo<'_>) -> bool {
+ match current_flow {
+ api::CurrentFlowInfo::Authorize {
+ request_data,
+ auth_type,
+ } => {
+ // Mandate payments should skip pre-authentication and go directly to authorize
+ if request_data.is_mandate_payment() {
+ false
+ } else {
+ self.is_3ds_setup_required(request_data, *auth_type)
+ }
+ }
+ // No alternate flow for complete authorize
+ api::CurrentFlowInfo::CompleteAuthorize { .. } => false,
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
+ }
+ }
}
diff --git a/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs
index f86092d126..56adfbb960 100644
--- a/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs
@@ -28,20 +28,22 @@ use hyperswitch_domain_models::{
types::{
PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
PaymentsCompleteAuthorizeRouterData, PaymentsPostAuthenticateRouterData,
- PaymentsPreProcessingRouterData, PaymentsSyncRouterData, RefundsRouterData,
+ PaymentsPreAuthenticateRouterData, PaymentsPreProcessingRouterData, PaymentsSyncRouterData,
+ RefundsRouterData,
},
};
use hyperswitch_interfaces::{consts::NO_ERROR_CODE, errors};
use masking::{ExposeInterface, Secret};
use serde::{Deserialize, Serialize};
+use serde_with::skip_serializing_none;
use strum::Display;
use crate::{
types::{
PaymentsCancelResponseRouterData, PaymentsCaptureResponseRouterData,
- PaymentsPostAuthenticateResponseRouterData, PaymentsPreprocessingResponseRouterData,
- PaymentsResponseRouterData, PaymentsSyncResponseRouterData, RefundsResponseRouterData,
- ResponseRouterData,
+ PaymentsPostAuthenticateResponseRouterData, PaymentsPreAuthenticateResponseRouterData,
+ PaymentsPreprocessingResponseRouterData, PaymentsResponseRouterData,
+ PaymentsSyncResponseRouterData, RefundsResponseRouterData, ResponseRouterData,
},
utils::{
get_unimplemented_payment_method_error_message, to_connector_meta,
@@ -454,24 +456,38 @@ pub enum NexixpayPaymentsResponse {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
+#[skip_serializing_none]
pub struct ThreeDSAuthResult {
authentication_value: Option<Secret<String>>,
+ eci: Option<String>,
+ xid: Option<String>,
+ status: Option<String>,
+ version: Option<String>,
}
-impl ForeignTryFrom<&ThreeDSAuthResult> for UcsAuthenticationData {
+impl ForeignTryFrom<(&ThreeDSAuthResult, String)> for UcsAuthenticationData {
type Error = error_stack::Report<errors::ConnectorError>;
- fn foreign_try_from(value: &ThreeDSAuthResult) -> Result<Self, Self::Error> {
+ fn foreign_try_from(
+ (auth_result, operation_id): (&ThreeDSAuthResult, String),
+ ) -> Result<Self, Self::Error> {
Ok(Self {
- eci: None,
- cavv: value.authentication_value.clone(),
- threeds_server_transaction_id: None,
- message_version: None,
+ trans_status: auth_result
+ .status
+ .as_ref()
+ .and_then(|s| s.parse::<common_enums::TransactionStatus>().ok()),
+ eci: auth_result.eci.clone(),
+ cavv: auth_result.authentication_value.clone(),
+ ucaf_collection_indicator: None,
+ threeds_server_transaction_id: auth_result.xid.clone(),
+ message_version: auth_result
+ .version
+ .as_ref()
+ .and_then(|v| v.parse::<common_utils::types::SemanticVersion>().ok()),
ds_trans_id: None,
acs_trans_id: None,
- trans_status: None,
- transaction_id: None,
- ucaf_collection_indicator: None,
+ // CRITICAL: Store operationId in transaction_id for Authorize flow
+ transaction_id: Some(operation_id),
})
}
}
@@ -747,9 +763,12 @@ fn process_nexixpay_preprocessing_response(
})?);
let status = AttemptStatus::from(response.operation.operation_result.clone());
- let authentication_data = UcsAuthenticationData::foreign_try_from(&three_ds_data)
- .ok()
- .map(Box::new);
+ let authentication_data = UcsAuthenticationData::foreign_try_from((
+ &three_ds_data,
+ response.operation.operation_id.clone(),
+ ))
+ .ok()
+ .map(Box::new);
let result = match status {
AttemptStatus::Failure => Err(get_error_response(
response.operation.operation_result.clone(),
@@ -981,6 +1000,129 @@ impl TryFrom<&NexixpayRouterData<&PaymentsAuthorizeRouterData>> for NexixpayPaym
}
}
+impl TryFrom<&NexixpayRouterData<&PaymentsPreAuthenticateRouterData>> for NexixpayPaymentsRequest {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: &NexixpayRouterData<&PaymentsPreAuthenticateRouterData>,
+ ) -> Result<Self, Self::Error> {
+ let order_id = get_nexi_order_id(&item.router_data.payment_id)?;
+
+ let billing_address = get_validated_billing_address(item.router_data)?;
+ let shipping_address = get_validated_shipping_address(item.router_data)?;
+
+ let customer_info = CustomerInfo {
+ card_holder_name: match item.router_data.get_billing_full_name()? {
+ name if name.clone().expose().len() <= MAX_CARD_HOLDER_LENGTH => name,
+ _ => {
+ return Err(error_stack::Report::from(
+ errors::ConnectorError::MaxFieldLengthViolated {
+ field_name: "billing.address.first_name & billing.address.last_name"
+ .to_string(),
+ connector: "Nexixpay".to_string(),
+ max_length: MAX_CARD_HOLDER_LENGTH,
+ received_length: item
+ .router_data
+ .get_billing_full_name()?
+ .expose()
+ .len(),
+ },
+ ))
+ }
+ },
+ billing_address: billing_address.clone(),
+ shipping_address: shipping_address.clone(),
+ };
+
+ let order = Order {
+ order_id,
+ amount: item.amount.clone(),
+ currency: item.router_data.request.currency.ok_or(
+ errors::ConnectorError::MissingRequiredField {
+ field_name: "currency",
+ },
+ )?,
+ description: item.router_data.description.clone(),
+ customer_info,
+ };
+
+ let payment_data = NexixpayPaymentsRequestData::try_from(item)?;
+
+ Ok(Self {
+ order,
+ payment_data,
+ })
+ }
+}
+
+impl TryFrom<&NexixpayRouterData<&PaymentsPreAuthenticateRouterData>>
+ for NexixpayPaymentsRequestData
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: &NexixpayRouterData<&PaymentsPreAuthenticateRouterData>,
+ ) -> Result<Self, Self::Error> {
+ // PreAuthenticate flow does not support mandates
+ let recurrence_request_obj = RecurrenceRequest {
+ action: NexixpayRecurringAction::NoRecurring,
+ contract_id: None,
+ contract_type: None,
+ };
+
+ match item.router_data.request.payment_method_data {
+ PaymentMethodData::Card(ref req_card) => {
+ if item.router_data.is_three_ds() {
+ Ok(Self::NexixpayNonMandatePaymentRequest(Box::new(
+ NexixpayNonMandatePaymentRequest {
+ card: NexixpayCard {
+ pan: req_card.card_number.clone(),
+ expiry_date: req_card.get_expiry_date_as_mmyy()?,
+ cvv: req_card.card_cvc.clone(),
+ },
+ recurrence: recurrence_request_obj,
+ action_type: if item.router_data.request.minor_amount
+ == MinorUnit::zero()
+ {
+ Some(NexixpayPaymentRequestActionType::Verify)
+ } else {
+ None
+ },
+ },
+ )))
+ } else {
+ Err(errors::ConnectorError::NotSupported {
+ message: "No threeds is not supported".to_string(),
+ connector: "nexixpay",
+ }
+ .into())
+ }
+ }
+ PaymentMethodData::CardRedirect(_)
+ | PaymentMethodData::Wallet(_)
+ | PaymentMethodData::PayLater(_)
+ | PaymentMethodData::BankRedirect(_)
+ | PaymentMethodData::BankDebit(_)
+ | PaymentMethodData::BankTransfer(_)
+ | PaymentMethodData::Crypto(_)
+ | PaymentMethodData::MandatePayment
+ | PaymentMethodData::Reward
+ | PaymentMethodData::RealTimePayment(_)
+ | PaymentMethodData::Upi(_)
+ | PaymentMethodData::MobilePayment(_)
+ | PaymentMethodData::Voucher(_)
+ | PaymentMethodData::GiftCard(_)
+ | PaymentMethodData::OpenBanking(_)
+ | PaymentMethodData::CardToken(_)
+ | PaymentMethodData::CardDetailsForNetworkTransactionId(_)
+ | PaymentMethodData::CardWithLimitedDetails(_)
+ | PaymentMethodData::NetworkTokenDetailsForNetworkTransactionId(_)
+ | PaymentMethodData::NetworkToken(_) => Err(errors::ConnectorError::NotImplemented(
+ get_unimplemented_payment_method_error_message("nexixpay"),
+ )
+ .into()),
+ }
+ }
+}
+
pub struct NexixpayAuthType {
pub(super) api_key: Secret<String>,
}
@@ -1273,6 +1415,123 @@ impl TryFrom<PaymentsResponseRouterData<NexixpayPaymentsResponse>> for PaymentsA
}
}
+impl TryFrom<PaymentsPreAuthenticateResponseRouterData<NexixpayPaymentsResponse>>
+ for PaymentsPreAuthenticateRouterData
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: PaymentsPreAuthenticateResponseRouterData<NexixpayPaymentsResponse>,
+ ) -> Result<Self, Self::Error> {
+ match item.response {
+ NexixpayPaymentsResponse::PaymentResponse(ref response_body) => {
+ let complete_authorize_url =
+ item.data.request.complete_authorize_url.clone().ok_or(
+ errors::ConnectorError::MissingRequiredField {
+ field_name: "complete_authorize_url",
+ },
+ )?;
+ let operation_id: String = response_body.operation.operation_id.clone();
+ let redirection_form = nexixpay_threeds_link(NexixpayRedirectionRequest {
+ three_d_s_auth_url: response_body
+ .three_d_s_auth_url
+ .clone()
+ .expose()
+ .to_string(),
+ three_ds_request: response_body.three_d_s_auth_request.clone(),
+ return_url: complete_authorize_url,
+ transaction_id: operation_id.clone(),
+ })?;
+ let connector_metadata = Some(serde_json::json!(NexixpayConnectorMetaData {
+ three_d_s_auth_result: None,
+ three_d_s_auth_response: None,
+ authorization_operation_id: Some(operation_id.clone()),
+ cancel_operation_id: None,
+ capture_operation_id: None,
+ psync_flow: NexixpayPaymentIntent::Authorize
+ }));
+ // PreAuthenticate doesn't support mandates
+ let mandate_reference = Box::new(None);
+ let status = AttemptStatus::from(response_body.operation.operation_result.clone());
+ match status {
+ AttemptStatus::Failure => {
+ let response = Err(get_error_response(
+ response_body.operation.operation_result.clone(),
+ item.http_code,
+ ));
+ Ok(Self {
+ response,
+ ..item.data
+ })
+ }
+ _ => Ok(Self {
+ status,
+ response: Ok(PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::ConnectorTransactionId(
+ response_body.operation.order_id.clone(),
+ ),
+ redirection_data: Box::new(Some(redirection_form.clone())),
+ mandate_reference,
+ connector_metadata,
+ network_txn_id: None,
+ connector_response_reference_id: Some(
+ response_body.operation.order_id.clone(),
+ ),
+ incremental_authorization_allowed: None,
+ authentication_data: None,
+ charges: None,
+ }),
+ ..item.data
+ }),
+ }
+ }
+ NexixpayPaymentsResponse::MandateResponse(ref mandate_response) => {
+ let status =
+ AttemptStatus::from(mandate_response.operation.operation_result.clone());
+ let operation_id = mandate_response.operation.operation_id.clone();
+ let connector_metadata = Some(serde_json::json!(NexixpayConnectorMetaData {
+ three_d_s_auth_result: None,
+ three_d_s_auth_response: None,
+ authorization_operation_id: Some(operation_id.clone()),
+ cancel_operation_id: None,
+ capture_operation_id: None,
+ psync_flow: NexixpayPaymentIntent::Authorize
+ }));
+ match status {
+ AttemptStatus::Failure => {
+ let response = Err(get_error_response(
+ mandate_response.operation.operation_result.clone(),
+ item.http_code,
+ ));
+ Ok(Self {
+ response,
+ ..item.data
+ })
+ }
+ _ => Ok(Self {
+ status,
+ response: Ok(PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::ConnectorTransactionId(
+ mandate_response.operation.order_id.clone(),
+ ),
+ redirection_data: Box::new(None),
+ mandate_reference: Box::new(None),
+ connector_metadata,
+ network_txn_id: None,
+ connector_response_reference_id: Some(
+ mandate_response.operation.order_id.clone(),
+ ),
+ incremental_authorization_allowed: None,
+ authentication_data: None,
+ charges: None,
+ }),
+ ..item.data
+ }),
+ }
+ }
+ }
+ }
+}
+
fn nexixpay_threeds_link(
request: NexixpayRedirectionRequest,
) -> CustomResult<RedirectForm, errors::ConnectorError> {
diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs
index 0ad866803e..53c05da94a 100644
--- a/crates/hyperswitch_connectors/src/default_implementations.rs
+++ b/crates/hyperswitch_connectors/src/default_implementations.rs
@@ -2203,7 +2203,6 @@ default_imp_for_pre_authenticate_steps!(
connectors::Multisafepay,
connectors::Netcetera,
connectors::Nexinets,
- connectors::Nexixpay,
connectors::Nomupay,
connectors::Noon,
connectors::Nordea,