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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(connector): [Nuvei] enable UCS ThreeDS, SetupMandate, RepeatPayment and IncomingWebhook (#14316)
Tushar Shukla8b153c59f2d2
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rsindex ca0ece6d62..025b0c4b98 100644--- a/crates/hyperswitch_domain_models/src/router_request_types.rs+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs@@ -880,6 +880,7 @@ impl TryFrom<PaymentsAuthorizeData> for PaymentsAuthenticateData {device_channel,webhook_url: data.webhook_url,force_3ds_challenge: data.force_3ds_challenge,+ router_return_url: data.router_return_url,})}}@@ -901,6 +902,8 @@ pub struct PaymentsAuthenticateData {pub device_channel: Option<api_models::payments::DeviceChannel>,pub webhook_url: Option<String>,pub force_3ds_challenge: Option<bool>,+ /// Merchant return URL, forwarded to the authentication leg.+ pub router_return_url: Option<String>,}impl TryFrom<CompleteAuthorizeData> for PaymentsAuthenticateData {@@ -926,6 +929,7 @@ impl TryFrom<CompleteAuthorizeData> for PaymentsAuthenticateData {device_channel,webhook_url: None,force_3ds_challenge: data.force_3ds_challenge,+ router_return_url: data.router_return_url,})}}@@ -1047,6 +1051,12 @@ pub struct CompleteAuthorizeData {pub connector_intent_metadata: Option<ConnectorMetadata>,pub order_id: Option<String>,pub force_3ds_challenge: Option<bool>,+ pub customer_id: Option<id_type::CustomerId>,+ pub billing_descriptor: Option<common_types::payments::BillingDescriptor>,+ pub payment_channel: Option<common_enums::PaymentChannel>,+ pub enable_partial_authorization:+ Option<common_types::primitive_wrappers::EnablePartialAuthorizationBool>,+ pub order_details: Option<Vec<OrderDetailsWithAmount>>,pub enable_overcapture: Option<common_types::primitive_wrappers::EnableOvercaptureBool>,}diff --git a/crates/router/src/core/authentication.rs b/crates/router/src/core/authentication.rsindex f088d0be88..fcb2eb5743 100644--- a/crates/router/src/core/authentication.rs+++ b/crates/router/src/core/authentication.rs@@ -1348,6 +1348,7 @@ async fn call_ucs_authenticate_proxy(device_channel: Some(device_channel.clone()),webhook_url: None,force_3ds_challenge: None,+ router_return_url: None,};let payment_address = hyperswitch_domain_models::payment_address::PaymentAddress::new(diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rsindex a10e1da129..cd4884ad39 100644--- a/crates/router/src/core/payments/flows/authorize_flow.rs+++ b/crates/router/src/core/payments/flows/authorize_flow.rs@@ -587,7 +587,8 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu_ => false,},api_models::enums::Connector::Shift4 => true,- api_models::enums::Connector::Nuvei => true,+ // Nuvei: never run the next leg after a failed initPayment+ api_models::enums::Connector::Nuvei => authorize_router_data.response.is_ok(),// Paysafe card + 3DS: PreAuthenticate mints the handle. When Paysafe returns no ACS// redirect (frictionless / no challenge), continue straight to the settle Authorize// in this flow; when it returns a redirect, break so the shopper completes thediff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex 7766415b20..eff7db8d0c 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -7520,6 +7520,25 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthoriz.get_connector_metadata_from_intent().change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to parse connector metadata")?;+ let order_details = payment_data+ .payment_intent+ .order_details+ .as_ref()+ .map(|order_details| {+ order_details+ .iter()+ .map(|data| {+ data.to_owned()+ .parse_value("OrderDetailsWithAmount")+ .change_context(errors::ApiErrorResponse::InvalidDataValue {+ field_name: "OrderDetailsWithAmount".into(),+ })+ .attach_printable("Unable to parse OrderDetailsWithAmount")+ })+ .collect::<Result<Vec<_>, _>>()+ })+ .transpose()?;+ let billing_descriptor = payment_data.payment_intent.get_billing_descriptor();let connector = api_models::enums::Connector::from_str(connector_name).change_context(errors::ConnectorError::InvalidConnectorName).change_context(errors::ApiErrorResponse::InvalidDataValue {@@ -7601,6 +7620,11 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthoriz.force_3ds_challenge_trigger.filter(|trigger| *trigger).or(payment_data.payment_intent.force_3ds_challenge),+ customer_id: additional_data.customer_id.clone(),+ billing_descriptor,+ payment_channel: payment_data.payment_intent.payment_channel,+ enable_partial_authorization: payment_data.payment_intent.enable_partial_authorization,+ order_details,enable_overcapture: payment_data.payment_intent.enable_overcapture,})}diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rsindex 8d58d741fc..cb487745f5 100644--- a/crates/router/src/core/unified_connector_service/transformers.rs+++ b/crates/router/src/core/unified_connector_service/transformers.rs@@ -636,6 +636,49 @@ impl}}+fn is_nuvei_connector(connector: &str) -> bool {+ matches!(+ common_enums::connector_enums::Connector::from_str(connector),+ Ok(common_enums::connector_enums::Connector::Nuvei)+ )+}++/// Nuvei's order-bound session token for UCS legs whose request has no `session_token` field+/// (PreAuthenticate, recurring Charge): carried in `connector_feature_data` in the UCS Nuvei+/// connector-state shape `{"session_token": ...}`. `None` for every other connector.+fn build_nuvei_session_token_feature_data(+ connector: &str,+ session_token: Option<&String>,+) -> Result<Option<Secret<String>>, error_stack::Report<UnifiedConnectorServiceError>> {+ session_token+ .filter(|_| is_nuvei_connector(connector))+ .map(|session_token| {+ serde_json::to_string(&serde_json::json!({ "session_token": session_token }))+ .change_context(UnifiedConnectorServiceError::RequestEncodingFailed)+ .map(Secret::new)+ })+ .transpose()+}++/// Nuvei 3DS: the connector state of the preceding UCS leg (Authenticate, else PreAuthenticate)+/// is still on the router data response when Authorize continues in the same call.+fn get_nuvei_previous_leg_feature_data(+ router_data: &RouterData<Authorize, PaymentsAuthorizeData, PaymentsResponseData>,+) -> Result<Option<Secret<String>>, error_stack::Report<UnifiedConnectorServiceError>> {+ if !is_nuvei_connector(&router_data.connector) {+ return Ok(None);+ }+ match &router_data.response {+ Ok(PaymentsResponseData::TransactionResponse {+ connector_metadata: Some(connector_metadata),+ ..+ }) => serde_json::to_string(connector_metadata)+ .change_context(UnifiedConnectorServiceError::RequestEncodingFailed)+ .map(|data| Some(Secret::new(data))),+ _ => Ok(None),+ }+}+impltransformers::ForeignTryFrom<(&RouterData<Authorize, PaymentsAuthorizeData, PaymentsResponseData>,@@ -830,7 +873,7 @@ impl.map(payments_grpc::PaymentChannel::foreign_try_from).transpose()?.map(|payment_channel| payment_channel.into()),- connector_feature_data: None,+ connector_feature_data: get_nuvei_previous_leg_feature_data(router_data)?,locale: router_data.request.locale.clone(),continue_redirection_url: router_data.request.complete_authorize_url.clone(),redirection_response: None,@@ -1011,6 +1054,8 @@ impl.access_token.as_ref().map(ConnectorState::foreign_from);+ let order_details = build_ucs_order_details(router_data.request.order_details.as_deref());+ let l2_l3_data = build_ucs_l2_l3_data(router_data.l2_l3_data.as_deref());Ok(Self {split_settlement: None,@@ -1040,7 +1085,11 @@ impl.clone().map(|e| e.expose().expose().into()),- id: None,+ id: router_data+ .request+ .customer_id+ .as_ref()+ .map(|id| id.get_string_repr().to_string()),connector_customer_id: router_data.connector_customer.clone(),phone_number: None,phone_country_code: None,@@ -1064,7 +1113,7 @@ implpayment_experience: None,authentication_data,request_extended_authorization: None,- merchant_order_id: None,+ merchant_order_id: router_data.request.merchant_order_reference_id.clone(),shipping_cost: None,merchant_transaction_id: Some(router_data.connector_request_reference_id.clone()),metadata,@@ -1079,7 +1128,7 @@ impl.transpose()?,statement_descriptor_name: None,statement_descriptor_suffix: None,- order_details: vec![],+ order_details,// Forward the connector metadata stored at Authorize (which holds the// Paysafe paymentHandleToken) so CompleteAuthorize can settle the handle.// Mirrors the PSync request builder.@@ -1091,9 +1140,22 @@ impl.transpose().change_context(UnifiedConnectorServiceError::RequestEncodingFailed)?.map(|s| s.into()),- enable_partial_authorization: None,- payment_channel: None,- billing_descriptor: None,+ enable_partial_authorization: router_data+ .request+ .enable_partial_authorization+ .map(|e| e.is_true()),+ payment_channel: router_data+ .request+ .payment_channel+ .as_ref()+ .map(payments_grpc::PaymentChannel::foreign_try_from)+ .transpose()?+ .map(|payment_channel| payment_channel.into()),+ billing_descriptor: router_data+ .request+ .billing_descriptor+ .as_ref()+ .map(payments_grpc::BillingDescriptor::foreign_from),locale: None,continue_redirection_url: router_data.request.complete_authorize_url.clone(),redirection_response: router_data@@ -1114,7 +1176,7 @@ impl.tokenization.map(payments_grpc::Tokenization::foreign_from).map(Into::into),- l2_l3_data: build_ucs_l2_l3_data(router_data.l2_l3_data.as_deref()),+ l2_l3_data,connector_order_id: router_data.request.order_id@@ -1579,7 +1641,7 @@ impladdress: Some(address),authentication_data,metadata: None,- return_url: None,+ return_url: router_data.request.router_return_url.clone(),continue_redirection_url: router_data.request.complete_authorize_url.clone(),state: None,redirection_response: router_data@@ -1703,7 +1765,7 @@ impl.attach_printable("Failed to serialize device_channel/sdk_information metadata")?.into(),),- return_url: None,+ return_url: router_data.request.router_return_url.clone(),continue_redirection_url: router_data.request.complete_authorize_url.clone(),state: None,redirection_response: router_data@@ -2037,7 +2099,10 @@ impl.clone().map(payments_grpc::BrowserInformation::foreign_try_from).transpose()?,- connector_feature_data: None,+ connector_feature_data: build_nuvei_session_token_feature_data(+ &router_data.connector,+ router_data.session_token.as_ref(),+ )?,capture_method: capture_method.map(|capture_method| capture_method.into()),description: router_data.description.clone(),merchant_transaction_id: None,@@ -2145,7 +2210,10 @@ impl.clone().map(payments_grpc::BrowserInformation::foreign_try_from).transpose()?,- connector_feature_data: None,+ connector_feature_data: build_nuvei_session_token_feature_data(+ &router_data.connector,+ router_data.session_token.as_ref(),+ )?,capture_method: capture_method.map(|capture_method| capture_method.into()),description: router_data.description.clone(),merchant_transaction_id: Some(router_data.connector_request_reference_id.clone()),@@ -2983,7 +3051,7 @@ implreturn_url: router_data.request.router_return_url.clone(),webhook_url: router_data.request.webhook_url.clone(),complete_authorize_url: router_data.request.complete_authorize_url.clone(),- session_token: None,+ session_token: router_data.session_token.clone(),order_tax_amount: None,order_category: None,merchant_order_id: None,@@ -3510,7 +3578,10 @@ impl.shipping_cost.map(|shipping_cost| shipping_cost.get_amount_as_i64()),authentication_data,- connector_feature_data: None,+ connector_feature_data: build_nuvei_session_token_feature_data(+ &router_data.connector,+ router_data.session_token.as_ref(),+ )?,locale: router_data.request.locale.clone(),connector_testing_data: router_data.requestdiff --git a/crates/router/src/core/webhooks/gateway.rs b/crates/router/src/core/webhooks/gateway.rsindex c86c7cee17..f392165c90 100644--- a/crates/router/src/core/webhooks/gateway.rs+++ b/crates/router/src/core/webhooks/gateway.rs@@ -949,6 +949,8 @@ fn event_reference_to_object_ref(})}}+ // The payment attempt is looked up by the payment's connector transaction id; the+ // dispute id only identifies the payment when no transaction id is givenResource::Dispute(dispute) => dispute.connector_transaction_id.as_ref()