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

refactor: Invoking Pre Auth flow for Nuvei (#10809)

Amitsingh Tanwarb2016cd63aa3
diff --git a/crates/hyperswitch_connectors/src/connectors/adyen.rs b/crates/hyperswitch_connectors/src/connectors/adyen.rs
index 41f39dfe64..c3f2bd35d0 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyen.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyen.rs
@@ -1028,12 +1028,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
field_name: "currency",
})?,
};
- let amount = match data.request.minor_amount {
- Some(amount) => amount,
- None => Err(errors::ConnectorError::MissingRequiredField {
- field_name: "amount",
- })?,
- };
+ let amount = data.request.minor_amount;
let amount = convert_amount(self.amount_converter, amount, currency)?;
diff --git a/crates/hyperswitch_connectors/src/connectors/barclaycard.rs b/crates/hyperswitch_connectors/src/connectors/barclaycard.rs
index f63dcb803e..3bf9d53e9d 100644
--- a/crates/hyperswitch_connectors/src/connectors/barclaycard.rs
+++ b/crates/hyperswitch_connectors/src/connectors/barclaycard.rs
@@ -64,8 +64,8 @@ use crate::{
constants::{self, headers},
types::ResponseRouterData,
utils::{
- convert_amount, PaymentsAuthorizeRequestData, RefundsRequestData,
- RouterData as OtherRouterData,
+ convert_amount, PaymentsAuthorizeRequestData, PaymentsPreAuthenticateRequestData,
+ RefundsRequestData, RouterData as OtherRouterData,
},
};
@@ -384,13 +384,8 @@ impl ConnectorIntegration<PreAuthenticate, PaymentsPreAuthenticateData, Payments
req: &PaymentsPreAuthenticateRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let minor_amount = req.request.minor_amount;
- let currency =
- req.request
- .currency
- .ok_or(errors::ConnectorError::MissingRequiredField {
- field_name: "currency",
- })?;
+ let minor_amount = req.request.get_minor_amount();
+ let currency = req.request.get_currency()?;
let amount = convert_amount(self.amount_converter, minor_amount, currency)?;
@@ -679,11 +674,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
req: &PaymentsPreProcessingRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let amount_in_minor_unit = MinorUnit::new(req.request.amount.ok_or(
- errors::ConnectorError::MissingRequiredField {
- field_name: "amount",
- },
- )?);
+ let amount_in_minor_unit = MinorUnit::new(req.request.amount);
let amount = convert_amount(
self.amount_converter,
amount_in_minor_unit,
@@ -1652,6 +1643,7 @@ impl ConnectorSpecifications for Barclaycard {
} => *auth_type == common_enums::AuthenticationType::ThreeDs && request_data.is_card(),
// No alternate flow for complete authorize
api::CurrentFlowInfo::CompleteAuthorize { .. } => false,
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
/// Check if authentication flow is required
@@ -1675,6 +1667,7 @@ impl ConnectorSpecifications for Barclaycard {
Some(_) | None => false,
}
}
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
/// Check if post-authentication flow is required
@@ -1698,6 +1691,7 @@ impl ConnectorSpecifications for Barclaycard {
Some(_) | None => true,
}
}
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {
diff --git a/crates/hyperswitch_connectors/src/connectors/cybersource.rs b/crates/hyperswitch_connectors/src/connectors/cybersource.rs
index b85e6f335b..240670538d 100644
--- a/crates/hyperswitch_connectors/src/connectors/cybersource.rs
+++ b/crates/hyperswitch_connectors/src/connectors/cybersource.rs
@@ -82,7 +82,7 @@ use crate::{
types::ResponseRouterData,
utils::{
self, convert_amount, PaymentMethodDataType, PaymentsAuthorizeRequestData,
- RefundsRequestData, RouterData as OtherRouterData,
+ PaymentsPreAuthenticateRequestData, RefundsRequestData, RouterData as OtherRouterData,
},
};
@@ -665,12 +665,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
req: &PaymentsPreProcessingRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let minor_amount =
- req.request
- .minor_amount
- .ok_or(errors::ConnectorError::MissingRequiredField {
- field_name: "minor_amount",
- })?;
+ let minor_amount = req.request.minor_amount;
let currency =
req.request
.currency
@@ -759,14 +754,8 @@ impl ConnectorIntegration<PreAuthenticate, PaymentsPreAuthenticateData, Payments
req: &PaymentsPreAuthenticateRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let minor_amount = req.request.minor_amount;
- let currency =
- req.request
- .currency
- .ok_or(errors::ConnectorError::MissingRequiredField {
- field_name: "currency",
- })?;
-
+ let minor_amount = req.request.get_minor_amount();
+ let currency = req.request.get_currency()?;
let amount = convert_amount(self.amount_converter, minor_amount, currency)?;
let connector_router_data = cybersource::CybersourceRouterData::from((amount, req));
@@ -2312,6 +2301,7 @@ impl ConnectorSpecifications for Cybersource {
Some(_) | None => Some(api::PreProcessingFlowName::PostAuthenticate),
}
}
+ api::CurrentFlowInfo::SetupMandate { .. } => None,
}
}
fn get_alternate_flow_if_needed(
@@ -2331,6 +2321,7 @@ impl ConnectorSpecifications for Cybersource {
}
// No alternate flow for complete authorize
api::CurrentFlowInfo::CompleteAuthorize { .. } => None,
+ api::CurrentFlowInfo::SetupMandate { .. } => None,
}
}
fn is_pre_authentication_flow_required(&self, current_flow: api::CurrentFlowInfo<'_>) -> bool {
@@ -2341,6 +2332,7 @@ impl ConnectorSpecifications for Cybersource {
} => self.is_3ds_setup_required(request_data, *auth_type),
// No alternate flow for complete authorize
api::CurrentFlowInfo::CompleteAuthorize { .. } => false,
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
/// Check if authentication flow is required
@@ -2364,6 +2356,7 @@ impl ConnectorSpecifications for Cybersource {
Some(_) | None => false,
}
}
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
/// Check if post-authentication flow is required
@@ -2387,6 +2380,7 @@ impl ConnectorSpecifications for Cybersource {
Some(_) | None => true,
}
}
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
}
diff --git a/crates/hyperswitch_connectors/src/connectors/nexixpay.rs b/crates/hyperswitch_connectors/src/connectors/nexixpay.rs
index 26b9efd228..19f298228e 100644
--- a/crates/hyperswitch_connectors/src/connectors/nexixpay.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nexixpay.rs
@@ -1253,6 +1253,7 @@ impl ConnectorSpecifications for Nexixpay {
.and_then(|redirect_response| redirect_response.payload.as_ref())
.is_some()
}
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
diff --git a/crates/hyperswitch_connectors/src/connectors/nmi.rs b/crates/hyperswitch_connectors/src/connectors/nmi.rs
index 6baf851baf..5727f97821 100644
--- a/crates/hyperswitch_connectors/src/connectors/nmi.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nmi.rs
@@ -1192,6 +1192,9 @@ impl ConnectorSpecifications for Nmi {
auth_type,
} => *auth_type == enums::AuthenticationType::ThreeDs,
api::CurrentFlowInfo::CompleteAuthorize { .. } => false,
+ api::CurrentFlowInfo::SetupMandate { auth_type } => {
+ *auth_type == enums::AuthenticationType::ThreeDs
+ }
}
}
fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {
diff --git a/crates/hyperswitch_connectors/src/connectors/nmi/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nmi/transformers.rs
index f40141ead9..4d18c4fa45 100644
--- a/crates/hyperswitch_connectors/src/connectors/nmi/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nmi/transformers.rs
@@ -194,16 +194,14 @@ pub struct NmiVaultResponse {
fn process_nmi_vault_response(
connector_auth_type: &ConnectorAuthType,
- amount: Option<i64>,
+ amount: i64,
currency: Option<Currency>,
vault_response: &NmiVaultResponse,
http_code: u16,
connector_request_reference_id: String,
) -> Result<(Result<PaymentsResponseData, ErrorResponse>, AttemptStatus), Error> {
let auth_type: NmiAuthType = connector_auth_type.try_into()?;
- let amount_data = amount.ok_or(ConnectorError::MissingRequiredField {
- field_name: "amount",
- })?;
+ let amount_data = amount;
let currency_data = currency.ok_or(ConnectorError::MissingRequiredField {
field_name: "currency",
})?;
@@ -311,7 +309,7 @@ impl TryFrom<PaymentsPreAuthenticateResponseRouterData<NmiVaultResponse>>
) -> Result<Self, Self::Error> {
let (response, status) = process_nmi_vault_response(
&item.data.connector_auth_type,
- Some(item.data.request.amount),
+ item.data.request.amount,
item.data.request.currency,
&item.response,
item.http_code,
@@ -907,108 +905,102 @@ impl TryFrom<(&ApplePayWalletData, Option<PaymentMethodToken>)> for PaymentMetho
impl TryFrom<&SetupMandateRouterData> for NmiValidateRequest {
type Error = Error;
fn try_from(item: &SetupMandateRouterData) -> Result<Self, Self::Error> {
- match item.request.amount {
- Some(amount) if amount > 0 => Err(ConnectorError::FlowNotSupported {
+ if item.request.amount > 0 {
+ Err(ConnectorError::FlowNotSupported {
flow: "Setup Mandate with non zero amount".to_string(),
connector: "NMI".to_string(),
}
- .into()),
- _ => {
- if let PaymentMethodData::Card(card_details) = &item.request.payment_method_data {
- let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?;
-
- let card_data = CardData {
- ccnumber: card_details.card_number.clone(),
- ccexp: card_details
- .get_card_expiry_month_year_2_digit_with_delimiter("".to_string())?,
- cvv: card_details.card_cvc.clone(),
+ .into())
+ } else if let PaymentMethodData::Card(card_details) = &item.request.payment_method_data {
+ let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?;
+
+ let card_data = CardData {
+ ccnumber: card_details.card_number.clone(),
+ ccexp: card_details
+ .get_card_expiry_month_year_2_digit_with_delimiter("".to_string())?,
+ cvv: card_details.card_cvc.clone(),
+ };
+ Ok(Self {
+ transaction_type: TransactionType::Validate,
+ security_key: auth_type.api_key,
+ payment_data: NmiValidatePaymentData::Card(Box::new(card_data)),
+ orderid: item.connector_request_reference_id.clone(),
+ customer_vault: CustomerAction::AddCustomer,
+ })
+ } else if let PaymentMethodData::Wallet(WalletData::ApplePay(apple_pay_wallet_data)) =
+ &item.request.payment_method_data
+ {
+ let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?;
+
+ let payment_data = match item.payment_method_token.clone() {
+ Some(payment_method_token) => match payment_method_token {
+ PaymentMethodToken::ApplePayDecrypt(apple_pay_decrypt_data) => {
+ Ok(NmiValidatePaymentData::ApplePayDecrypt(Box::new(
+ ApplePayDecryptedData {
+ decrypted_applepay_data: "1".to_string(), // Set to "1" to indicate decrypted data is being sent
+ ccnumber: apple_pay_decrypt_data
+ .application_primary_account_number
+ .clone(),
+ ccexp: apple_pay_decrypt_data
+ .get_expiry_date_as_mmyy()
+ .change_context(ConnectorError::InvalidDataFormat {
+ field_name: "application_expiration_date",
+ })?,
+ cavv: apple_pay_decrypt_data
+ .payment_data
+ .online_payment_cryptogram
+ .clone(),
+ eci: apple_pay_decrypt_data.payment_data.eci_indicator.clone(),
+ },
+ )))
+ }
+ PaymentMethodToken::Token(_) => {
+ Err(unimplemented_payment_method!("Apple Pay", "Manual", "NMI"))
+ }
+ PaymentMethodToken::PazeDecrypt(_) => {
+ Err(unimplemented_payment_method!("Paze", "NMI"))
+ }
+ PaymentMethodToken::GooglePayDecrypt(_) => {
+ Err(unimplemented_payment_method!("Google Pay", "NMI"))
+ }
+ },
+ None => {
+ let apple_pay_encrypted_data = apple_pay_wallet_data
+ .payment_data
+ .get_encrypted_apple_pay_payment_data_mandatory()
+ .change_context(ConnectorError::MissingRequiredField {
+ field_name: "Apple pay encrypted data",
+ })?;
+
+ let base64_decoded_apple_pay_data = base64::prelude::BASE64_STANDARD
+ .decode(apple_pay_encrypted_data)
+ .change_context(ConnectorError::InvalidDataFormat {
+ field_name: "apple_pay_encrypted_data",
+ })?;
+
+ let hex_encoded_apple_pay_data = hex::encode(base64_decoded_apple_pay_data);
+
+ let apple_pay_data = ApplePayData {
+ applepay_payment_data: Secret::new(hex_encoded_apple_pay_data),
};
- Ok(Self {
- transaction_type: TransactionType::Validate,
- security_key: auth_type.api_key,
- payment_data: NmiValidatePaymentData::Card(Box::new(card_data)),
- orderid: item.connector_request_reference_id.clone(),
- customer_vault: CustomerAction::AddCustomer,
- })
- } else if let PaymentMethodData::Wallet(WalletData::ApplePay(
- apple_pay_wallet_data,
- )) = &item.request.payment_method_data
- {
- let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?;
-
- let payment_data = match item.payment_method_token.clone() {
- Some(payment_method_token) => match payment_method_token {
- PaymentMethodToken::ApplePayDecrypt(apple_pay_decrypt_data) => {
- Ok(NmiValidatePaymentData::ApplePayDecrypt(Box::new(
- ApplePayDecryptedData {
- decrypted_applepay_data: "1".to_string(), // Set to "1" to indicate decrypted data is being sent
- ccnumber: apple_pay_decrypt_data
- .application_primary_account_number
- .clone(),
- ccexp: apple_pay_decrypt_data
- .get_expiry_date_as_mmyy()
- .change_context(ConnectorError::InvalidDataFormat {
- field_name: "application_expiration_date",
- })?,
- cavv: apple_pay_decrypt_data
- .payment_data
- .online_payment_cryptogram
- .clone(),
- eci: apple_pay_decrypt_data
- .payment_data
- .eci_indicator
- .clone(),
- },
- )))
- }
- PaymentMethodToken::Token(_) => {
- Err(unimplemented_payment_method!("Apple Pay", "Manual", "NMI"))
- }
- PaymentMethodToken::PazeDecrypt(_) => {
- Err(unimplemented_payment_method!("Paze", "NMI"))
- }
- PaymentMethodToken::GooglePayDecrypt(_) => {
- Err(unimplemented_payment_method!("Google Pay", "NMI"))
- }
- },
- None => {
- let apple_pay_encrypted_data = apple_pay_wallet_data
- .payment_data
- .get_encrypted_apple_pay_payment_data_mandatory()
- .change_context(ConnectorError::MissingRequiredField {
- field_name: "Apple pay encrypted data",
- })?;
-
- let base64_decoded_apple_pay_data = base64::prelude::BASE64_STANDARD
- .decode(apple_pay_encrypted_data)
- .change_context(ConnectorError::InvalidDataFormat {
- field_name: "apple_pay_encrypted_data",
- })?;
-
- let hex_encoded_apple_pay_data =
- hex::encode(base64_decoded_apple_pay_data);
-
- let apple_pay_data = ApplePayData {
- applepay_payment_data: Secret::new(hex_encoded_apple_pay_data),
- };
- Ok(NmiValidatePaymentData::ApplePay(Box::new(apple_pay_data)))
- }
- }?;
-
- Ok(Self {
- transaction_type: TransactionType::Validate,
- security_key: auth_type.api_key,
- payment_data,
- orderid: item.connector_request_reference_id.clone(),
- customer_vault: CustomerAction::AddCustomer,
- })
- } else {
- Err(ConnectorError::NotImplemented(
- get_unimplemented_payment_method_error_message("Nmi"),
- )
- .into())
+ Ok(NmiValidatePaymentData::ApplePay(Box::new(apple_pay_data)))
}
- }
+ }?;
+
+ Ok(Self {
+ transaction_type: TransactionType::Validate,
+ security_key: auth_type.api_key,
+ payment_data,
+ orderid: item.connector_request_reference_id.clone(),
+ customer_vault: CustomerAction::AddCustomer,
+ })
+ } else {
+ Err(
+ ConnectorError::NotImplemented(get_unimplemented_payment_method_error_message(
+ "Nmi",
+ ))
+ .into(),
+ )
}
}
}
diff --git a/crates/hyperswitch_connectors/src/connectors/nordea.rs b/crates/hyperswitch_connectors/src/connectors/nordea.rs
index 440519e1f1..cbaa7a1c8d 100644
--- a/crates/hyperswitch_connectors/src/connectors/nordea.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nordea.rs
@@ -914,12 +914,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
req: &PaymentsPreProcessingRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let minor_amount =
- req.request
- .minor_amount
- .ok_or(errors::ConnectorError::MissingRequiredField {
- field_name: "minor_amount",
- })?;
+ let minor_amount = req.request.minor_amount;
let currency =
req.request
.currency
diff --git a/crates/hyperswitch_connectors/src/connectors/nuvei.rs b/crates/hyperswitch_connectors/src/connectors/nuvei.rs
index 028a0b50a7..9b50a9e43e 100644
--- a/crates/hyperswitch_connectors/src/connectors/nuvei.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nuvei.rs
@@ -1669,6 +1669,19 @@ impl ConnectorSpecifications for Nuvei {
Some(&NUVEI_CONNECTOR_INFO)
}
+ fn is_pre_authentication_flow_required(&self, current_flow: api::CurrentFlowInfo<'_>) -> bool {
+ match current_flow {
+ api::CurrentFlowInfo::Authorize {
+ auth_type,
+ request_data: _,
+ } => *auth_type == enums::AuthenticationType::ThreeDs,
+ api::CurrentFlowInfo::CompleteAuthorize { .. } => false,
+ api::CurrentFlowInfo::SetupMandate { auth_type } => {
+ *auth_type == enums::AuthenticationType::ThreeDs
+ }
+ }
+ }
+
fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {
Some(&*NUVEI_SUPPORTED_PAYMENT_METHODS)
}
diff --git a/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs
index cb8517c792..668bc5bb2b 100644
--- a/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs
@@ -111,7 +111,7 @@ impl TryFrom<(&types::PaymentsPreAuthenticateRouterData, String)>
) -> Result<Self, Self::Error> {
let currency = item.request.get_currency()?;
let connector_auth: NuveiAuthType = NuveiAuthType::try_from(&item.connector_auth_type)?;
- let amount = item.request.get_minor_amount()?.to_nuvei_amount(currency)?;
+ let amount = item.request.get_minor_amount().to_nuvei_amount(currency)?;
let payment_method_data = item.request.get_payment_method_data()?.clone();
let card = match payment_method_data {
PaymentMethodData::Card(card) => card,
@@ -173,7 +173,7 @@ impl TryFrom<(&types::PaymentsPreProcessingRouterData, String)> for NuveiThreeDS
) -> Result<Self, Self::Error> {
let currency = item.request.get_currency()?;
let connector_auth: NuveiAuthType = NuveiAuthType::try_from(&item.connector_auth_type)?;
- let amount = item.request.get_minor_amount()?.to_nuvei_amount(currency)?;
+ let amount = item.request.get_minor_amount().to_nuvei_amount(currency)?;
let payment_method_data = item.request.get_payment_method_data()?.clone();
let card = match payment_method_data {
PaymentMethodData::Card(card) => card,
@@ -328,7 +328,7 @@ where
let currency = item.request.get_currency();
let amount = item
.request
- .get_minor_amount_required()?
+ .get_minor_amount_required()
.to_nuvei_amount(currency)?;
fp_utils::when(session_token.is_empty(), || {
@@ -2083,7 +2083,7 @@ impl
let amount = item.data.request.amount;
let response = &item.response;
let (status, redirection_data, connector_response_data) = process_nuvei_payment_response(
- NuveiPaymentResponseData::new(amount, false, item.data.payment_method, response),
+ NuveiPaymentResponseData::new(Some(amount), false, item.data.payment_method, response),
)?;
let (amount_captured, minor_amount_capturable) = get_amount_captured(
@@ -2557,7 +2557,7 @@ impl TryFrom<PaymentsPreprocessingResponseRouterData<NuveiPaymentsResponse>>
.unwrap_or_default();
Ok(Self {
status: get_payment_status(
- item.data.request.amount,
+ Some(item.data.request.amount),
false,
response.transaction_type,
response.transaction_status,
@@ -3665,9 +3665,7 @@ trait NuveiAuthorizePreprocessingCommon {
&self,
) -> Result<String, error_stack::Report<errors::ConnectorError>>;
fn get_capture_method(&self) -> Option<CaptureMethod>;
- fn get_minor_amount_required(
- &self,
- ) -> Result<MinorUnit, error_stack::Report<errors::ConnectorError>>;
+ fn get_minor_amount_required(&self) -> MinorUnit;
fn get_email_required(&self) -> Result<Email, error_stack::Report<errors::ConnectorError>>;
fn get_currency(&self) -> enums::Currency;
fn get_payment_method_data_required(
@@ -3717,10 +3715,8 @@ impl NuveiAuthorizePreprocessingCommon for CompleteAuthorizeData {
self.get_router_return_url()
}
- fn get_minor_amount_required(
- &self,
- ) -> Result<MinorUnit, error_stack::Report<errors::ConnectorError>> {
- Ok(self.minor_amount)
+ fn get_minor_amount_required(&self) -> MinorUnit {
+ self.minor_amount
}
fn get_payment_method_data_required(
@@ -3807,11 +3803,8 @@ impl NuveiAuthorizePreprocessingCommon for SetupMandateRequestData {
Ok(self.payment_method_data.clone())
}
- fn get_minor_amount_required(
- &self,
- ) -> Result<MinorUnit, error_stack::Report<errors::ConnectorError>> {
+ fn get_minor_amount_required(&self) -> MinorUnit {
self.minor_amount
- .ok_or_else(missing_field_err("minor_amount"))
}
fn get_is_partial_approval(&self) -> Option<PartialApprovalFlag> {
@@ -3873,10 +3866,8 @@ impl NuveiAuthorizePreprocessingCommon for PaymentsAuthorizeData {
self.complete_authorize_url.clone()
}
- fn get_minor_amount_required(
- &self,
- ) -> Result<MinorUnit, error_stack::Report<errors::ConnectorError>> {
- Ok(self.minor_amount)
+ fn get_minor_amount_required(&self) -> MinorUnit {
+ self.minor_amount
}
fn get_currency(&self) -> enums::Currency {
diff --git a/crates/hyperswitch_connectors/src/connectors/payload/transformers.rs b/crates/hyperswitch_connectors/src/connectors/payload/transformers.rs
index 9729643feb..22bd4b1f3d 100644
--- a/crates/hyperswitch_connectors/src/connectors/payload/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/payload/transformers.rs
@@ -244,28 +244,27 @@ impl TryFrom<&ConnectorAuthType> for PayloadAuthType {
impl TryFrom<&SetupMandateRouterData> for requests::PayloadPaymentRequestData {
type Error = Error;
fn try_from(item: &SetupMandateRouterData) -> Result<Self, Self::Error> {
- match item.request.amount {
- Some(amount) if amount > 0 => Err(errors::ConnectorError::FlowNotSupported {
+ if item.request.amount > 0 {
+ Err(errors::ConnectorError::FlowNotSupported {
flow: "Setup mandate with non zero amount".to_string(),
connector: "Payload".to_string(),
}
- .into()),
- _ => {
- let billing_address = item.get_billing_address()?;
- let is_mandate = item.request.is_customer_initiated_mandate_payment();
-
- build_payload_payment_request_data(
- &item.request.payment_method_data,
- &item.connector_auth_type,
- item.request.currency,
- StringMajorUnit::zero(),
- billing_address,
- item.request.capture_method,
- is_mandate,
- item.get_connector_customer_id()?.into(),
- item.is_three_ds(),
- )
- }
+ .into())
+ } else {
+ let billing_address = item.get_billing_address()?;
+ let is_mandate = item.request.is_customer_initiated_mandate_payment();
+
+ build_payload_payment_request_data(
+ &item.request.payment_method_data,
+ &item.connector_auth_type,
+ item.request.currency,
+ StringMajorUnit::zero(),
+ billing_address,
+ item.request.capture_method,
+ is_mandate,
+ item.get_connector_customer_id()?.into(),
+ item.is_three_ds(),
+ )
}
}
}
diff --git a/crates/hyperswitch_connectors/src/connectors/payme.rs b/crates/hyperswitch_connectors/src/connectors/payme.rs
index d6bb34dcf8..9e9e13ee50 100644
--- a/crates/hyperswitch_connectors/src/connectors/payme.rs
+++ b/crates/hyperswitch_connectors/src/connectors/payme.rs
@@ -435,7 +435,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
req: &PaymentsPreProcessingRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let req_amount = req.request.get_minor_amount()?;
+ let req_amount = req.request.get_minor_amount();
let req_currency = req.request.get_currency()?;
let amount = utils::convert_amount(self.amount_converter, req_amount, req_currency)?;
let connector_router_data = payme::PaymeRouterData::try_from((amount, req))?;
@@ -475,7 +475,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
.parse_struct("Payme GenerateSaleResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
- let req_amount = data.request.get_minor_amount()?;
+ let req_amount = data.request.get_minor_amount();
let req_currency = data.request.get_currency()?;
let apple_pay_amount = utils::convert_amount(
@@ -1466,6 +1466,7 @@ impl ConnectorSpecifications for Payme {
PaymentMethodData::Card(_) | PaymentMethodData::Wallet(_)
),
api::CurrentFlowInfo::CompleteAuthorize { .. } => false,
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {
diff --git a/crates/hyperswitch_connectors/src/connectors/paypal.rs b/crates/hyperswitch_connectors/src/connectors/paypal.rs
index ecc71118d9..b32ece545f 100644
--- a/crates/hyperswitch_connectors/src/connectors/paypal.rs
+++ b/crates/hyperswitch_connectors/src/connectors/paypal.rs
@@ -2578,6 +2578,7 @@ impl ConnectorSpecifications for Paypal {
request_data: _,
payment_method,
} => payment_method == Some(enums::PaymentMethod::Card),
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {
diff --git a/crates/hyperswitch_connectors/src/connectors/paysafe.rs b/crates/hyperswitch_connectors/src/connectors/paysafe.rs
index 9b5476426c..f7b8f65fd8 100644
--- a/crates/hyperswitch_connectors/src/connectors/paysafe.rs
+++ b/crates/hyperswitch_connectors/src/connectors/paysafe.rs
@@ -129,12 +129,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
req: &PaymentsPreProcessingRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let minor_amount =
- req.request
- .minor_amount
- .ok_or(errors::ConnectorError::MissingRequiredField {
- field_name: "minor_amount",
- })?;
+ let minor_amount = req.request.minor_amount;
let currency =
req.request
.currency
@@ -242,6 +237,7 @@ impl ConnectorIntegration<PaymentMethodToken, PaymentMethodTokenizationData, Pay
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "amount",
})?;
+
let amount = MinorUnit::new(amount_value);
let connector_router_data = paysafe::PaysafeRouterData::from((amount, req));
diff --git a/crates/hyperswitch_connectors/src/connectors/redsys.rs b/crates/hyperswitch_connectors/src/connectors/redsys.rs
index 5aa5445c60..9a9a78b137 100644
--- a/crates/hyperswitch_connectors/src/connectors/redsys.rs
+++ b/crates/hyperswitch_connectors/src/connectors/redsys.rs
@@ -52,7 +52,10 @@ use hyperswitch_interfaces::{
};
use transformers as redsys;
-use crate::{constants::headers, types::ResponseRouterData, utils as connector_utils};
+use crate::{
+ constants::headers, types::ResponseRouterData, utils as connector_utils,
+ utils::PaymentsPreAuthenticateRequestData,
+};
#[derive(Clone)]
pub struct Redsys {
@@ -190,12 +193,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
req: &PaymentsPreProcessingRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let minor_amount =
- req.request
- .minor_amount
- .ok_or(errors::ConnectorError::MissingRequiredField {
- field_name: "minor_amount",
- })?;
+ let minor_amount = req.request.minor_amount;
let currency =
req.request
.currency
@@ -275,14 +273,8 @@ impl ConnectorIntegration<PreAuthenticate, PaymentsPreAuthenticateData, Payments
req: &PaymentsPreAuthenticateRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let minor_amount = req.request.minor_amount;
- let currency =
- req.request
- .currency
- .ok_or(errors::ConnectorError::MissingRequiredField {
- field_name: "currency",
- })?;
-
+ let minor_amount = req.request.get_minor_amount();
+ let currency = req.request.get_currency()?;
let amount =
connector_utils::convert_amount(self.amount_converter, minor_amount, currency)?;
let connector_router_data = redsys::RedsysRouterData::from((amount, req, currency));
@@ -987,6 +979,7 @@ impl ConnectorSpecifications for Redsys {
*auth_type == common_enums::AuthenticationType::ThreeDs
}
api::CurrentFlowInfo::CompleteAuthorize { .. } => false,
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
diff --git a/crates/hyperswitch_connectors/src/connectors/shift4.rs b/crates/hyperswitch_connectors/src/connectors/shift4.rs
index d68757b20d..b7bf72e4d4 100644
--- a/crates/hyperswitch_connectors/src/connectors/shift4.rs
+++ b/crates/hyperswitch_connectors/src/connectors/shift4.rs
@@ -499,11 +499,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
) -> CustomResult<RequestContent, errors::ConnectorError> {
let amount = convert_amount(
self.amount_converter,
- req.request.minor_amount.ok_or_else(|| {
- errors::ConnectorError::MissingRequiredField {
- field_name: "minor_amount",
- }
- })?,
+ req.request.minor_amount,
req.request
.currency
.ok_or_else(|| errors::ConnectorError::MissingRequiredField {
diff --git a/crates/hyperswitch_connectors/src/connectors/trustpay.rs b/crates/hyperswitch_connectors/src/connectors/trustpay.rs
index a10e7664b4..7e4d0b71e4 100644
--- a/crates/hyperswitch_connectors/src/connectors/trustpay.rs
+++ b/crates/hyperswitch_connectors/src/connectors/trustpay.rs
@@ -634,7 +634,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
let req_currency = req.request.get_currency()?;
- let req_amount = req.request.get_minor_amount()?;
+ let req_amount = req.request.get_minor_amount();
let amount = utils::convert_amount(self.amount_converter, req_amount, req_currency)?;
@@ -1459,6 +1459,7 @@ impl ConnectorSpecifications for Trustpay {
payment_method_data::PaymentMethodData::Wallet(_)
),
api::CurrentFlowInfo::CompleteAuthorize { .. } => false,
+ api::CurrentFlowInfo::SetupMandate { .. } => false,
}
}
fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {
diff --git a/crates/hyperswitch_connectors/src/connectors/worldpay.rs b/crates/hyperswitch_connectors/src/connectors/worldpay.rs
index c932f26b3c..5996115acd 100644
--- a/crates/hyperswitch_connectors/src/connectors/worldpay.rs
+++ b/crates/hyperswitch_connectors/src/connectors/worldpay.rs
@@ -241,7 +241,7 @@ impl ConnectorIntegration<SetupMandate, SetupMandateRequestData, PaymentsRespons
let connector_router_data = worldpay::WorldpayRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
- req.request.minor_amount.unwrap_or_default(),
+ req.request.minor_amount,
req,
))?;
let connector_req =
@@ -295,7 +295,7 @@ impl ConnectorIntegration<SetupMandate, SetupMandateRequestData, PaymentsRespons
http_code: res.status_code,
},
optional_correlation_id,
- data.request.amount.unwrap_or(0),
+ data.request.amount,
))
.change_context(errors::ConnectorError::ResponseHandlingFailed)
}
diff --git a/crates/hyperswitch_connectors/src/connectors/zift/transformers.rs b/crates/hyperswitch_connectors/src/connectors/zift/transformers.rs
index 84b4eba567..76cf2167bf 100644
--- a/crates/hyperswitch_connectors/src/connectors/zift/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/zift/transformers.rs
@@ -913,14 +913,12 @@ impl TryFrom<&SetupMandateRouterData> for ZiftSetupMandateRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &SetupMandateRouterData) -> Result<Self, Self::Error> {
- if let Some(amount) = item.request.amount {
- if amount > 0 {
- return Err(errors::ConnectorError::FlowNotSupported {
- flow: "Setup Mandate with non zero amount".to_string(),
- connector: "Zift".to_string(),
- }
- .into());
+ if item.request.amount > 0 {
+ return Err(errors::ConnectorError::FlowNotSupported {
+ flow: "Setup Mandate with non zero amount".to_string(),
+ connector: "Zift".to_string(),
}
+ .into());
}
let auth = ZiftAuthType::try_from(&item.connector_auth_type)?;
diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs
index 376509f0f4..f4d5fcb348 100644
--- a/crates/hyperswitch_connectors/src/utils.rs
+++ b/crates/hyperswitch_connectors/src/utils.rs
@@ -2837,7 +2837,7 @@ pub trait PaymentsPreAuthenticateRequestData {
fn get_webhook_url(&self) -> Result<String, Error>;
fn is_auto_capture(&self) -> Result<bool, Error>;
fn get_payment_method_data(&self) -> Result<PaymentMethodData, Error>;
- fn get_minor_amount(&self) -> Result<MinorUnit, Error>;
+ fn get_minor_amount(&self) -> MinorUnit;
fn get_currency(&self) -> Result<enums::Currency, Error>;
}
impl PaymentsPreAuthenticateRequestData for PaymentsPreAuthenticateData {
@@ -2860,8 +2860,8 @@ impl PaymentsPreAuthenticateRequestData for PaymentsPreAuthenticateData {
fn get_payment_method_data(&self) -> Result<PaymentMethodData, Error> {
Ok(self.payment_method_data.clone())
}
- fn get_minor_amount(&self) -> Result<MinorUnit, Error> {
- Ok(self.minor_amount)
+ fn get_minor_amount(&self) -> MinorUnit {
+ self.minor_amount
}
fn get_currency(&self) -> Result<enums::Currency, Error> {
self.currency.ok_or_else(missing_field_err("currency"))
@@ -2872,8 +2872,8 @@ pub trait PaymentsPreProcessingRequestData {
fn get_email(&self) -> Result<Email, Error>;
fn get_payment_method_type(&self) -> Result<enums::PaymentMethodType, Error>;
fn get_currency(&self) -> Result<enums::Currency, Error>;
- fn get_amount(&self) -> Result<i64, Error>;
- fn get_minor_amount(&self) -> Result<MinorUnit, Error>;
+ fn get_amount(&self) -> i64;
+ fn get_minor_amount(&self) -> MinorUnit;
fn is_auto_capture(&self) -> Result<bool, Error>;
fn get_order_details(&self) -> Result<Vec<OrderDetailsWithAmount>, Error>;
fn get_webhook_url(&self) -> Result<String, Error>;
@@ -2902,13 +2902,13 @@ impl PaymentsPreProcessingRequestData for PaymentsPreProcessingData {
fn get_currency(&self) -> Result<enums::Currency, Error> {
self.currency.ok_or_else(missing_field_err("currency"))
}
- fn get_amount(&self) -> Result<i64, Error> {
- self.amount.ok_or_else(missing_field_err("amount"))
+ fn get_amount(&self) -> i64 {
+ self.amount
}
// New minor amount function for amount framework
- fn get_minor_amount(&self) -> Result<MinorUnit, Error> {
- self.minor_amount.ok_or_else(missing_field_err("amount"))
+ fn get_minor_amount(&self) -> MinorUnit {
+ self.minor_amount
}
fn is_auto_capture(&self) -> Result<bool, Error> {
match self.capture_method {
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index e1b6af2456..81a8539019 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -438,7 +438,7 @@ impl TryFrom<SetupMandateRequestData> for PaymentMethodTokenizationData {
payment_method_data: data.payment_method_data,
browser_info: data.browser_info,
currency: data.currency,
- amount: data.amount,
+ amount: Some(data.amount),
split_payments: data.split_payments,
customer_acceptance: data.customer_acceptance,
setup_future_usage: data.setup_future_usage,
@@ -600,7 +600,7 @@ impl TryFrom<ExternalVaultProxyPaymentsData> for CreateOrderRequestData {
#[derive(Debug, Clone, Serialize)]
pub struct PaymentsPreProcessingData {
pub payment_method_data: Option<PaymentMethodData>,
- pub amount: Option<i64>,
+ pub amount: i64,
pub email: Option<pii::Email>,
pub currency: Option<storage_enums::Currency>,
pub payment_method_type: Option<storage_enums::PaymentMethodType>,
@@ -622,7 +622,7 @@ pub struct PaymentsPreProcessingData {
pub customer_acceptance: Option<common_payments_types::CustomerAcceptance>,
pub setup_future_usage: Option<storage_enums::FutureUsage>,
// New amount for amount frame work
- pub minor_amount: Option<MinorUnit>,
+ pub minor_amount: MinorUnit,
pub is_stored_credential: Option<bool>,
}
@@ -639,8 +639,8 @@ impl TryFrom<PaymentsAuthorizeData> for PaymentsPreProcessingData {
fn try_from(data: PaymentsAuthorizeData) -> Result<Self, Self::Error> {
Ok(Self {
payment_method_data: Some(data.payment_method_data),
- amount: Some(data.amount),
- minor_amount: Some(data.minor_amount),
+ amount: data.amount,
+ minor_amount: data.minor_amount,
email: data.email,
currency: Some(data.currency),
payment_method_type: data.payment_method_type,
@@ -708,6 +708,29 @@ impl TryFrom<PaymentsAuthorizeData> for PaymentsPreAuthenticateData {
}
}
+impl TryFrom<SetupMandateRequestData> for PaymentsPreAuthenticateData {
+ type Error = error_stack::Report<ApiErrorResponse>;
+
+ fn try_from(data: SetupMandateRequestData) -> Result<Self, Self::Error> {
+ Ok(Self {
+ payment_method_data: data.payment_method_data,
+ customer_name: data.customer_name,
+ metadata: data.metadata,
+ amount: data.amount,
+ minor_amount: data.minor_amount,
+ email: data.email,
+ capture_method: data.capture_method,
+ currency: Some(data.currency),
+ payment_method_type: data.payment_method_type,
+ router_return_url: data.router_return_url,
+ complete_authorize_url: data.complete_authorize_url,
+ browser_info: data.browser_info,
+ enrolled_for_3ds: data.enrolled_for_3ds,
+ webhook_url: data.webhook_url,
+ })
+ }
+}
+
#[derive(Debug, Clone, Serialize)]
pub struct PaymentsAuthenticateData {
pub payment_method_data: Option<PaymentMethodData>,
@@ -781,8 +804,8 @@ impl TryFrom<CompleteAuthorizeData> for PaymentsPreProcessingData {
fn try_from(data: CompleteAuthorizeData) -> Result<Self, Self::Error> {
Ok(Self {
payment_method_data: data.payment_method_data,
- amount: Some(data.amount),
- minor_amount: Some(data.minor_amount),
+ amount: data.amount,
+ minor_amount: data.minor_amount,
email: data.email,
currency: Some(data.currency),
payment_method_type: None,
@@ -1498,7 +1521,7 @@ pub struct SdkPaymentsSessionUpdateData {
pub struct SetupMandateRequestData {
pub currency: storage_enums::Currency,
pub payment_method_data: PaymentMethodData,
- pub amount: Option<i64>,
+ pub amount: i64,
pub confirm: bool,
pub customer_acceptance: Option<common_payments_types::CustomerAcceptance>,
pub mandate_id: Option<api_models::payments::MandateIds>,
@@ -1520,7 +1543,7 @@ pub struct SetupMandateRequestData {
pub related_transaction_id: Option<String>,
// MinorUnit for amount framework
- pub minor_amount: Option<MinorUnit>,
+ pub minor_amount: MinorUnit,
pub shipping_cost: Option<MinorUnit>,
pub connector_testing_data: Option<pii::SecretSerdeValue>,
pub customer_id: Option<id_type::CustomerId>,
diff --git a/crates/hyperswitch_interfaces/src/api.rs b/crates/hyperswitch_interfaces/src/api.rs
index b9d3734f78..d78fc83014 100644
--- a/crates/hyperswitch_interfaces/src/api.rs
+++ b/crates/hyperswitch_interfaces/src/api.rs
@@ -405,6 +405,12 @@ pub enum CurrentFlowInfo<'a> {
/// The payment method that is used
payment_method: Option<PaymentMethod>,
},
+
+ /// SetupMandate flow information
+ SetupMandate {
+ /// The authentication type being used
+ auth_type: &'a enums::AuthenticationType,
+ },
}
/// Alternate API flow that must be made instead of the current flow.
diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs
index 15dc4a7591..6279fa2af8 100644
--- a/crates/router/src/connector/utils.rs
+++ b/crates/router/src/connector/utils.rs
@@ -781,8 +781,8 @@ pub trait PaymentsPreProcessingData {
fn get_email(&self) -> Result<Email, Error>;
fn get_payment_method_type(&self) -> Result<enums::PaymentMethodType, Error>;
fn get_currency(&self) -> Result<enums::Currency, Error>;
- fn get_amount(&self) -> Result<i64, Error>;
- fn get_minor_amount(&self) -> Result<MinorUnit, Error>;
+ fn get_amount(&self) -> i64;
+ fn get_minor_amount(&self) -> MinorUnit;
fn is_auto_capture(&self) -> Result<bool, Error>;
fn get_order_details(&self) -> Result<Vec<OrderDetailsWithAmount>, Error>;
fn get_webhook_url(&self) -> Result<String, Error>;
@@ -804,13 +804,13 @@ impl PaymentsPreProcessingData for types::PaymentsPreProcessingData {
fn get_currency(&self) -> Result<enums::Currency, Error> {
self.currency.ok_or_else(missing_field_err("currency"))
}
- fn get_amount(&self) -> Result<i64, Error> {
- self.amount.ok_or_else(missing_field_err("amount"))
+ fn get_amount(&self) -> i64 {
+ self.amount
}
// New minor amount function for amount framework
- fn get_minor_amount(&self) -> Result<MinorUnit, Error> {
- self.minor_amount.ok_or_else(missing_field_err("amount"))
+ fn get_minor_amount(&self) -> MinorUnit {
+ self.minor_amount
}
fn is_auto_capture(&self) -> Result<bool, Error> {
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 3592208b85..5af55de438 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -4175,8 +4175,8 @@ where
.authentication_bloated_connectors
.contains(&connector.connector_name)
&& payment_data
- .get_payment_attempt()
- .external_three_ds_authentication_attempted
+ .get_payment_intent()
+ .request_external_three_ds_authentication
!= Some(true)
}) {
logger::info!(
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index 0c1dd59789..793cb53772 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -366,12 +366,22 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
.await?;
// Convert back to CompleteAuthorize router data while preserving preprocessing response data
let pre_authenticate_response = pre_authenticate_router_data.response.clone();
- let authorize_router_data =
+ let mut authorize_router_data =
helpers::router_data_type_conversion::<_, api::Authorize, _, _, _, _>(
pre_authenticate_router_data,
authorize_request_data,
pre_authenticate_response,
);
+ if let Ok(types::PaymentsResponseData::ThreeDSEnrollmentResponse {
+ enrolled_v2,
+ related_transaction_id,
+ }) = &authorize_router_data.response
+ {
+ let (enrolled_for_3ds, related_transaction_id) =
+ (*enrolled_v2, related_transaction_id.clone());
+ authorize_router_data.request.enrolled_for_3ds = enrolled_for_3ds;
+ authorize_router_data.request.related_transaction_id = related_transaction_id;
+ }
let should_continue_after_preauthenticate = match connector.connector_name {
api_models::enums::Connector::Redsys => match &authorize_router_data.response {
Ok(types::PaymentsResponseData::TransactionResponse {
@@ -389,6 +399,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
}
_ => false,
},
+ api_models::enums::Connector::Nuvei => true,
_ => false,
};
Ok((authorize_router_data, should_continue_after_preauthenticate))
diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs
index d9468d10e2..5ba5fdd302 100644
--- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs
+++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs
@@ -1,8 +1,8 @@
use async_trait::async_trait;
use common_enums;
use common_types::payments as common_payments_types;
-use hyperswitch_domain_models::payments as domain_payments;
-use hyperswitch_interfaces::api::{gateway, ConnectorSpecifications};
+use hyperswitch_domain_models::{payments as domain_payments, router_data_v2::PaymentFlowData};
+use hyperswitch_interfaces::api::{self as api_interface, gateway, ConnectorSpecifications};
use router_env::logger;
use super::{ConstructFlowSpecificData, Feature};
@@ -11,8 +11,9 @@ use crate::{
errors::{ConnectorErrorExt, RouterResult},
mandate,
payments::{
- self, access_token, customers, gateway::context as gateway_context, helpers,
- session_token, tokenization, transformers, PaymentData,
+ self, access_token, customers, gateway as payments_gateway,
+ gateway::context as gateway_context, helpers, session_token, tokenization,
+ transformers, PaymentData,
},
},
routes::SessionState,
@@ -207,6 +208,81 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup
}
}
+ async fn pre_authentication_step<'a>(
+ self,
+ state: &SessionState,
+ connector: &api::ConnectorData,
+ gateway_context: &gateway_context::RouterGatewayContext,
+ ) -> RouterResult<(Self, bool)>
+ where
+ Self: Sized,
+ {
+ if connector.connector.is_pre_authentication_flow_required(
+ api_interface::CurrentFlowInfo::SetupMandate {
+ auth_type: &self.auth_type,
+ },
+ ) {
+ logger::info!(
+ "Pre-authentication flow is required for connector: {}",
+ connector.connector_name
+ );
+ let setup_mandate_request_data = self.request.clone();
+ let pre_authenticate_request_data =
+ types::PaymentsPreAuthenticateData::try_from(self.request.to_owned())?;
+ let pre_authenticate_response_data: Result<
+ types::PaymentsResponseData,
+ types::ErrorResponse,
+ > = Err(types::ErrorResponse::default());
+ let pre_authenticate_router_data =
+ helpers::router_data_type_conversion::<_, api::PreAuthenticate, _, _, _, _>(
+ self.clone(),
+ pre_authenticate_request_data,
+ pre_authenticate_response_data,
+ );
+ let pre_authenticate_router_data = Box::pin(payments_gateway::handle_gateway_call::<
+ _,
+ _,
+ _,
+ PaymentFlowData,
+ _,
+ >(
+ state,
+ pre_authenticate_router_data,
+ connector,
+ gateway_context,
+ ))
+ .await?;
+ let pre_authenticate_response = pre_authenticate_router_data.response.clone();
+ let mut setup_mandate_router_data =
+ helpers::router_data_type_conversion::<_, api::SetupMandate, _, _, _, _>(
+ pre_authenticate_router_data,
+ setup_mandate_request_data,
+ pre_authenticate_response,
+ );
+
+ if let Ok(types::PaymentsResponseData::ThreeDSEnrollmentResponse {
+ enrolled_v2,
+ related_transaction_id,
+ }) = &setup_mandate_router_data.response
+ {
+ let (enrolled_for_3ds, related_transaction_id) =
+ (*enrolled_v2, related_transaction_id.clone());
+ setup_mandate_router_data.request.enrolled_for_3ds = enrolled_for_3ds;
+ setup_mandate_router_data.request.related_transaction_id = related_transaction_id;
+ }
+
+ let should_continue = setup_mandate_router_data.response.is_ok();
+
+ Ok((setup_mandate_router_data, should_continue))
+ } else {
+ logger::info!(
+ "Pre-authentication flow is not required for connector: {} for Setup Mandate flow",
+ connector.connector_name
+ );
+ Ok((self, true))
+ }
+ }
+
async fn create_connector_customer<'a>(
&self,
state: &SessionState,
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index b365fb5a25..643a6f58b5 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -1511,13 +1511,11 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>(
payment_method_data: payment_data
.payment_method_data
.get_required_value("payment_method_data")?,
- amount: Some(
- payment_data
- .payment_attempt
- .amount_details
- .get_net_amount()
- .get_amount_as_i64(),
- ),
+ amount: payment_data
+ .payment_attempt
+ .amount_details
+ .get_net_amount()
+ .get_amount_as_i64(),
confirm: true,
customer_acceptance: None,
mandate_id: None,
@@ -1539,7 +1537,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>(
RequestIncrementalAuthorization::True
),
metadata: payment_data.payment_intent.metadata,
- minor_amount: Some(payment_data.payment_attempt.amount_details.get_net_amount()),
+ minor_amount: payment_data.payment_attempt.amount_details.get_net_amount(),
shipping_cost: payment_data.payment_intent.amount_details.shipping_cost,
capture_method: Some(payment_data.payment_intent.capture_method),
complete_authorize_url,
@@ -5967,8 +5965,8 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ
Ok(Self {
currency: payment_data.currency,
confirm: true,
- amount: Some(amount.get_amount_as_i64()), //need to change once we move to connector module
- minor_amount: Some(amount),
+ amount: amount.get_amount_as_i64(), //need to change once we move to connector module
+ minor_amount: amount,
payment_method_data: (payment_data
.payment_method_data
.get_required_value("payment_method_data")?),
@@ -6264,8 +6262,8 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
payment_method_data,
email: payment_data.email,
currency: Some(payment_data.currency),
- amount: Some(amount.get_amount_as_i64()), // need to change this once we move to connector module
- minor_amount: Some(amount),
+ amount: amount.get_amount_as_i64(), // need to change this once we move to connector module
+ minor_amount: amount,
payment_method_type: payment_data.payment_attempt.payment_method_type,
setup_mandate_details: payment_data.setup_mandate,
capture_method: payment_data.payment_attempt.capture_method,
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rs
index 35775ee130..1cfbf4fced 100644
--- a/crates/router/src/core/unified_connector_service/transformers.rs
+++ b/crates/router/src/core/unified_connector_service/transformers.rs
@@ -1005,15 +1005,18 @@ impl
.map(|val| convert_value_map_to_hashmap(val.peek()))
.transpose()?
.unwrap_or_default();
+ let amount = router_data.request.amount;
+ let minor_amount = router_data.request.minor_amount;
+
Ok(Self {
request_ref_id: Some(Identifier {
id_type: Some(payments_grpc::identifier::IdType::Id(
router_data.connector_request_reference_id.clone(),
)),
}),
- amount: router_data.request.amount,
+ amount,
currency: currency.into(),
- minor_amount: router_data.request.minor_amount.get_amount_as_i64(),
+ minor_amount: minor_amount.get_amount_as_i64(),
payment_method,
email: router_data
.request
@@ -1659,7 +1662,7 @@ impl
}),
currency: currency.into(),
payment_method,
- minor_amount: router_data.request.amount,
+ minor_amount: Some(router_data.request.amount),
email: router_data
.request
.email
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index c22bdf7196..5499313e30 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -1245,10 +1245,10 @@ impl ForeignFrom<&ExternalVaultProxyPaymentsRouterData> for AuthorizeSessionToke
impl<'a> ForeignFrom<&'a SetupMandateRouterData> for AuthorizeSessionTokenData {
fn foreign_from(data: &'a SetupMandateRouterData) -> Self {
Self {
- amount_to_capture: data.request.amount,
+ amount_to_capture: Some(data.request.amount),
currency: data.request.currency,
connector_transaction_id: data.payment_id.clone(),
- amount: data.request.amount,
+ amount: Some(data.request.amount),
}
}
}