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): [NMI] External 3DS flow for Cards (#4385)
Sakil Mostak4feda8f89049
diff --git a/crates/api_models/src/enums.rs b/crates/api_models/src/enums.rsindex 12e1e876d1..3aa2a676d4 100644--- a/crates/api_models/src/enums.rs+++ b/crates/api_models/src/enums.rs@@ -189,7 +189,6 @@ impl Connector {| Self::Mollie| Self::Multisafepay| Self::Nexinets- | Self::Nmi| Self::Nuvei| Self::Opennode| Self::Payme@@ -218,7 +217,7 @@ impl Connector {| Self::Cybersource| Self::Noon| Self::Stripe => false,- Self::Checkout => true,+ Self::Checkout | Self::Nmi => true,}#[cfg(not(feature = "dummy_connector"))]match self {diff --git a/crates/router/src/connector/airwallex.rs b/crates/router/src/connector/airwallex.rsindex 6a8f384e19..91a27fc3df 100644--- a/crates/router/src/connector/airwallex.rs+++ b/crates/router/src/connector/airwallex.rs@@ -1132,7 +1132,9 @@ impl services::ConnectorRedirectResponse for Airwallex {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/authorizedotnet.rs b/crates/router/src/connector/authorizedotnet.rsindex 946fded930..7f9cdc376e 100644--- a/crates/router/src/connector/authorizedotnet.rs+++ b/crates/router/src/connector/authorizedotnet.rs@@ -974,7 +974,9 @@ impl services::ConnectorRedirectResponse for Authorizedotnet {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/bambora.rs b/crates/router/src/connector/bambora.rsindex a9bfc54313..0717b997ba 100644--- a/crates/router/src/connector/bambora.rs+++ b/crates/router/src/connector/bambora.rs@@ -737,7 +737,9 @@ impl services::ConnectorRedirectResponse for Bambora {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/bluesnap.rs b/crates/router/src/connector/bluesnap.rsindex e32ebfc6f4..dff76576ac 100644--- a/crates/router/src/connector/bluesnap.rs+++ b/crates/router/src/connector/bluesnap.rs@@ -1159,7 +1159,10 @@ impl services::ConnectorRedirectResponse for Bluesnap {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync => Ok(payments::CallConnectorAction::Trigger),+ services::PaymentAction::PSync+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {+ Ok(payments::CallConnectorAction::Trigger)+ }services::PaymentAction::CompleteAuthorize => {let redirection_response: bluesnap::BluesnapRedirectionResponse = json_payload.ok_or(errors::ConnectorError::MissingConnectorRedirectionPayload {diff --git a/crates/router/src/connector/braintree.rs b/crates/router/src/connector/braintree.rsindex 41133e3f67..1b55f12cab 100644--- a/crates/router/src/connector/braintree.rs+++ b/crates/router/src/connector/braintree.rs@@ -1569,7 +1569,8 @@ impl services::ConnectorRedirectResponse for Braintree {}None => Ok(payments::CallConnectorAction::Avoid),},- services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/checkout.rs b/crates/router/src/connector/checkout.rsindex 33a43b0a03..ee4e04e7b1 100644--- a/crates/router/src/connector/checkout.rs+++ b/crates/router/src/connector/checkout.rs@@ -1351,7 +1351,9 @@ impl services::ConnectorRedirectResponse for Checkout {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/globalpay.rs b/crates/router/src/connector/globalpay.rsindex 447c0568dc..6397cb75cf 100644--- a/crates/router/src/connector/globalpay.rs+++ b/crates/router/src/connector/globalpay.rs@@ -975,7 +975,9 @@ impl services::ConnectorRedirectResponse for Globalpay {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/mollie.rs b/crates/router/src/connector/mollie.rsindex 84014fd6d5..cb001ef7c3 100644--- a/crates/router/src/connector/mollie.rs+++ b/crates/router/src/connector/mollie.rs@@ -631,7 +631,9 @@ impl services::ConnectorRedirectResponse for Mollie {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/nmi.rs b/crates/router/src/connector/nmi.rsindex d34b894411..a00e276b9c 100644--- a/crates/router/src/connector/nmi.rs+++ b/crates/router/src/connector/nmi.rs@@ -1007,7 +1007,10 @@ impl services::ConnectorRedirectResponse for Nmi {}}}- services::PaymentAction::PSync => Ok(payments::CallConnectorAction::Trigger),+ services::PaymentAction::PSync+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {+ Ok(payments::CallConnectorAction::Trigger)+ }}}}diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rsindex 27e0e5c2a4..84eb358bb8 100644--- a/crates/router/src/connector/nmi/transformers.rs+++ b/crates/router/src/connector/nmi/transformers.rs@@ -464,7 +464,8 @@ impl NmiMerchantDefinedField {#[derive(Debug, Serialize)]#[serde(untagged)]pub enum PaymentMethod {- Card(Box<CardData>),+ CardNonThreeDs(Box<CardData>),+ CardThreeDs(Box<CardThreeDsData>),GPay(Box<GooglePayData>),ApplePay(Box<ApplePayData>),}@@ -476,6 +477,20 @@ pub struct CardData {cvv: Secret<String>,}+#[derive(Debug, Serialize)]+pub struct CardThreeDsData {+ ccnumber: CardNumber,+ ccexp: Secret<String>,+ email: Option<Email>,+ cardholder_auth: Option<String>,+ cavv: Option<String>,+ xid: Option<String>,+ eci: Option<String>,+ cvv: Secret<String>,+ three_ds_version: Option<String>,+ directory_server_id: Option<Secret<String>>,+}+#[derive(Debug, Serialize)]pub struct GooglePayData {googlepay_payment_data: Secret<String>,@@ -497,8 +512,10 @@ impl TryFrom<&NmiRouterData<&types::PaymentsAuthorizeRouterData>> for NmiPayment};let auth_type: NmiAuthType = (&item.router_data.connector_auth_type).try_into()?;let amount = item.amount;- let payment_method =- PaymentMethod::try_from(&item.router_data.request.payment_method_data)?;+ let payment_method = PaymentMethod::try_from((+ &item.router_data.request.payment_method_data,+ Some(item.router_data),+ ))?;Ok(Self {transaction_type,@@ -517,11 +534,30 @@ impl TryFrom<&NmiRouterData<&types::PaymentsAuthorizeRouterData>> for NmiPayment}}-impl TryFrom<&domain::PaymentMethodData> for PaymentMethod {+impl+ TryFrom<(+ &domain::PaymentMethodData,+ Option<&types::PaymentsAuthorizeRouterData>,+ )> for PaymentMethod+{type Error = Error;- fn try_from(payment_method_data: &domain::PaymentMethodData) -> Result<Self, Self::Error> {- match &payment_method_data {- domain::PaymentMethodData::Card(ref card) => Ok(Self::try_from(card)?),+ fn try_from(+ item: (+ &domain::PaymentMethodData,+ Option<&types::PaymentsAuthorizeRouterData>,+ ),+ ) -> Result<Self, Self::Error> {+ let (payment_method_data, router_data) = item;+ match payment_method_data {+ domain::PaymentMethodData::Card(ref card) => match router_data {+ Some(data) => match data.auth_type {+ common_enums::AuthenticationType::NoThreeDs => Ok(Self::try_from(card)?),+ common_enums::AuthenticationType::ThreeDs => {+ Ok(Self::try_from((card, &data.request))?)+ }+ },+ None => Ok(Self::try_from(card)?),+ },domain::PaymentMethodData::Wallet(ref wallet_type) => match wallet_type {domain::WalletData::GooglePay(ref googlepay_data) => Ok(Self::from(googlepay_data)),domain::WalletData::ApplePay(ref applepay_data) => Ok(Self::from(applepay_data)),@@ -575,6 +611,35 @@ impl TryFrom<&domain::PaymentMethodData> for PaymentMethod {}}+impl TryFrom<(&domain::payments::Card, &types::PaymentsAuthorizeData)> for PaymentMethod {+ type Error = Error;+ fn try_from(+ val: (&domain::payments::Card, &types::PaymentsAuthorizeData),+ ) -> Result<Self, Self::Error> {+ let (card_data, item) = val;+ let auth_data = &item.get_authentication_data()?;+ let ccexp = utils::CardData::get_card_expiry_month_year_2_digit_with_delimiter(+ card_data,+ "".to_string(),+ )?;++ let card_3ds_details = CardThreeDsData {+ ccnumber: card_data.card_number.clone(),+ ccexp,+ cvv: card_data.card_cvc.clone(),+ email: item.email.clone(),+ cavv: Some(auth_data.cavv.clone()),+ eci: auth_data.eci.clone(),+ xid: Some(auth_data.threeds_server_transaction_id.clone()),+ cardholder_auth: None,+ three_ds_version: Some(auth_data.message_version.clone()),+ directory_server_id: None,+ };++ Ok(Self::CardThreeDs(Box::new(card_3ds_details)))+ }+}+impl TryFrom<&domain::payments::Card> for PaymentMethod {type Error = Error;fn try_from(card: &domain::payments::Card) -> Result<Self, Self::Error> {@@ -587,7 +652,7 @@ impl TryFrom<&domain::payments::Card> for PaymentMethod {ccexp,cvv: card.card_cvc.clone(),};- Ok(Self::Card(Box::new(card)))+ Ok(Self::CardNonThreeDs(Box::new(card)))}}@@ -613,7 +678,7 @@ impl TryFrom<&types::SetupMandateRouterData> for NmiPaymentsRequest {type Error = Error;fn try_from(item: &types::SetupMandateRouterData) -> Result<Self, Self::Error> {let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?;- let payment_method = PaymentMethod::try_from(&item.request.payment_method_data)?;+ let payment_method = PaymentMethod::try_from((&item.request.payment_method_data, None))?;Ok(Self {transaction_type: TransactionType::Validate,security_key: auth_type.api_key,diff --git a/crates/router/src/connector/noon.rs b/crates/router/src/connector/noon.rsindex f247a5dae1..dcbeeac960 100644--- a/crates/router/src/connector/noon.rs+++ b/crates/router/src/connector/noon.rs@@ -775,7 +775,9 @@ impl services::ConnectorRedirectResponse for Noon {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/nuvei.rs b/crates/router/src/connector/nuvei.rsindex 0e3ae84581..aa4157a68d 100644--- a/crates/router/src/connector/nuvei.rs+++ b/crates/router/src/connector/nuvei.rs@@ -998,7 +998,10 @@ impl services::ConnectorRedirectResponse for Nuvei {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync => Ok(payments::CallConnectorAction::Trigger),+ services::PaymentAction::PSync+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {+ Ok(payments::CallConnectorAction::Trigger)+ }services::PaymentAction::CompleteAuthorize => {if let Some(payload) = json_payload {let redirect_response: nuvei::NuveiRedirectionResponse =diff --git a/crates/router/src/connector/payme.rs b/crates/router/src/connector/payme.rsindex 042b506b30..b384b938cd 100644--- a/crates/router/src/connector/payme.rs+++ b/crates/router/src/connector/payme.rs@@ -381,7 +381,9 @@ impl services::ConnectorRedirectResponse for Payme {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rsindex 6292f5693a..e9e986b66f 100644--- a/crates/router/src/connector/paypal.rs+++ b/crates/router/src/connector/paypal.rs@@ -1521,7 +1521,9 @@ impl services::ConnectorRedirectResponse for Paypal {action: PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rsindex 70c08a31d7..79b3c3e239 100644--- a/crates/router/src/connector/stripe.rs+++ b/crates/router/src/connector/stripe.rs@@ -2227,7 +2227,9 @@ impl services::ConnectorRedirectResponse for Stripe {action: services::PaymentAction,) -> CustomResult<crate::core::payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/trustpay.rs b/crates/router/src/connector/trustpay.rsindex ed4978743d..1f9e77de9c 100644--- a/crates/router/src/connector/trustpay.rs+++ b/crates/router/src/connector/trustpay.rs@@ -999,7 +999,9 @@ impl services::ConnectorRedirectResponse for Trustpay {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rsindex 3aa6affc27..8254de9e3a 100644--- a/crates/router/src/connector/utils.rs+++ b/crates/router/src/connector/utils.rs@@ -25,7 +25,7 @@ use crate::{consts,core::{errors::{self, ApiErrorResponse, CustomResult},- payments::{PaymentData, RecurringMandatePaymentData},+ payments::{types::AuthenticationData, PaymentData, RecurringMandatePaymentData},},pii::PeekInterface,types::{@@ -525,6 +525,7 @@ pub trait PaymentsAuthorizeRequestData {fn get_tax_on_surcharge_amount(&self) -> Option<i64>;fn get_total_surcharge_amount(&self) -> Option<i64>;fn get_metadata_as_object(&self) -> Option<pii::SecretSerdeValue>;+ fn get_authentication_data(&self) -> Result<AuthenticationData, Error>;}pub trait PaymentMethodTokenizationRequestData {@@ -672,6 +673,12 @@ impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData {serde_json::Value::Object(_) => Some(meta_data),})}++ fn get_authentication_data(&self) -> Result<AuthenticationData, Error> {+ self.authentication_data+ .clone()+ .ok_or_else(missing_field_err("authentication_data"))+ }}pub trait ConnectorCustomerData {diff --git a/crates/router/src/connector/zen.rs b/crates/router/src/connector/zen.rsindex 540c3320c2..b28ad2e968 100644--- a/crates/router/src/connector/zen.rs+++ b/crates/router/src/connector/zen.rs@@ -710,7 +710,9 @@ impl services::ConnectorRedirectResponse for Zen {action: services::PaymentAction,) -> CustomResult<payments::CallConnectorAction, errors::ConnectorError> {match action {- services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => {+ services::PaymentAction::PSync+ | services::PaymentAction::CompleteAuthorize+ | services::PaymentAction::PaymentAuthenticateCompleteAuthorize => {Ok(payments::CallConnectorAction::Trigger)}}diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex f0a30fbe66..d9e22d4026 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -1149,7 +1149,7 @@ impl<Ctx: PaymentMethodRetrieve> PaymentRedirectFlow<Ctx> for PaymentAuthenticat}fn get_payment_action(&self) -> services::PaymentAction {- services::PaymentAction::CompleteAuthorize+ services::PaymentAction::PaymentAuthenticateCompleteAuthorize}}@@ -1709,6 +1709,12 @@ where} else if connector.connector_name == router_types::Connector::Nmi&& !matches!(format!("{operation:?}").as_str(), "CompleteAuthorize")&& router_data.auth_type == storage_enums::AuthenticationType::ThreeDs+ && !matches!(+ payment_data+ .payment_attempt+ .external_three_ds_authentication_attempted,+ Some(true)+ ){router_data = router_data.preprocessing_steps(state, connector).await?;diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rsindex 1a6246d559..df3d91bc01 100644--- a/crates/router/src/services/api.rs+++ b/crates/router/src/services/api.rs@@ -874,6 +874,7 @@ pub struct RedirectionFormData {pub enum PaymentAction {PSync,CompleteAuthorize,+ PaymentAuthenticateCompleteAuthorize,}#[derive(Debug, Eq, PartialEq, Serialize)]