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): Add client_unqiue_id in Nuvei Pyament Request (#10366)
awasthi21bc4440633b1a
diff --git a/crates/hyperswitch_connectors/src/connectors/nuvei.rs b/crates/hyperswitch_connectors/src/connectors/nuvei.rsindex b3dd853eda..1be74a5039 100644--- a/crates/hyperswitch_connectors/src/connectors/nuvei.rs+++ b/crates/hyperswitch_connectors/src/connectors/nuvei.rs@@ -951,7 +951,8 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsRespreq: &PaymentsPreProcessingRouterData,_connectors: &Connectors,) -> CustomResult<RequestContent, errors::ConnectorError> {- let connector_req = nuvei::NuveiPaymentsRequest::try_from((req, req.get_session_token()?))?;+ let connector_req =+ nuvei::NuveiThreeDSInitPaymentRequest::try_from((req, req.get_session_token()?))?;Ok(RequestContent::Json(Box::new(connector_req)))}diff --git a/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rsindex f9ad90de91..b299284d42 100644--- a/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs@@ -1,7 +1,8 @@use common_enums::{enums, CaptureMethod, FutureUsage, GooglePayCardFundingSource, PaymentChannel};use common_types::{payments::{- ApplePayPaymentData, ApplePayPredecryptData, GPayPredecryptData, GpayTokenizationData,+ ApplePayPaymentData, ApplePayPredecryptData, BillingDescriptor, GPayPredecryptData,+ GpayTokenizationData,},primitive_wrappers,};@@ -17,7 +18,7 @@ use common_utils::{};use error_stack::ResultExt;use hyperswitch_domain_models::{- address::{Address, AddressDetails},+ address::Address,payment_method_data::{self, ApplePayWalletData, BankRedirectData, CardDetailsForNetworkTransactionId,GooglePayWalletData, PayLaterData, PaymentMethodData, WalletData,@@ -32,7 +33,7 @@ use hyperswitch_domain_models::{},router_request_types::{authentication::MessageExtensionAttribute, AuthenticationData, BrowserInformation,- PaymentsAuthorizeData, PaymentsPreProcessingData, ResponseId, SetupMandateRequestData,+ CompleteAuthorizeData, PaymentsAuthorizeData, ResponseId, SetupMandateRequestData,},router_response_types::{MandateReference, PaymentsResponseData, RedirectForm, RefundsResponseData,@@ -60,22 +61,14 @@ use crate::{utils::{self, convert_amount, missing_field_err, AddressData, AddressDetailsData,BrowserInformationData, CardData, ForeignTryFrom, PaymentsAuthorizeRequestData,- PaymentsCancelRequestData, PaymentsPreProcessingRequestData,- PaymentsSetupMandateRequestData, RouterData as _,+ PaymentsCancelRequestData, PaymentsCompleteAuthorizeRequestData,+ PaymentsPreProcessingRequestData, PaymentsSetupMandateRequestData, RouterData as _,},};-pub static NUVEI_AMOUNT_CONVERTOR: &StringMajorUnitForConnector = &StringMajorUnitForConnector;-fn to_boolean(string: String) -> bool {let str = string.as_str();- match str {- "true" => true,- "false" => false,- "yes" => true,- "no" => false,- _ => false,- }+ matches!(str, "true" | "yes")}// The dimensions of the challenge window for full screen.@@ -83,2315 +76,1267 @@ const CHALLENGE_WINDOW_SIZE: &str = "05";// The challenge preference for the challenge flow.const CHALLENGE_PREFERENCE: &str = "01";-trait NuveiAuthorizePreprocessingCommon {- fn get_browser_info(&self) -> Option<BrowserInformation>;- fn get_related_transaction_id(&self) -> Option<String>;- fn get_complete_authorize_url(&self) -> Option<String>;- fn get_is_moto(&self) -> Option<bool>;- fn get_ntid(&self) -> Option<String>;- fn get_connector_mandate_id(&self) -> Option<String>;- fn get_return_url_required(- &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_customer_id_optional(&self) -> Option<CustomerId>;- fn get_email_required(&self) -> Result<Email, error_stack::Report<errors::ConnectorError>>;- fn get_currency_required(- &self,- ) -> Result<enums::Currency, error_stack::Report<errors::ConnectorError>>;- fn get_payment_method_data_required(- &self,- ) -> Result<PaymentMethodData, error_stack::Report<errors::ConnectorError>>;- fn get_is_partial_approval(&self) -> Option<PartialApprovalFlag>;- fn is_customer_initiated_mandate_payment(&self) -> bool;- fn get_auth_data(- &self,- ) -> Result<Option<AuthenticationData>, error_stack::Report<errors::ConnectorError>> {- Ok(None)- }- fn get_is_stored_credential(&self) -> Option<StoredCredentialMode>;- fn get_dynamic_descriptor(- &self,- ) -> Result<Option<NuveiDynamicDescriptor>, error_stack::Report<errors::ConnectorError>>;+#[serde_with::skip_serializing_none]+#[derive(Debug, Serialize, Default)]+#[serde(rename_all = "camelCase")]+pub struct NuveiThreeDSInitPaymentRequest {+ pub session_token: Secret<String>,+ pub merchant_id: Secret<String>,+ pub merchant_site_id: Secret<String>,+ pub client_unique_id: String,+ pub client_request_id: Secret<String>,+ pub amount: StringMajorUnit,+ pub payment_option: CardPaymentOption,+ pub device_details: DeviceDetails,+ pub currency: enums::Currency,+ pub user_token_id: Option<CustomerId>,+ pub billing_address: Option<BillingAddress>,+ pub url_details: UrlDetails,}-impl NuveiAuthorizePreprocessingCommon for SetupMandateRequestData {- fn get_browser_info(&self) -> Option<BrowserInformation> {- self.browser_info.clone()- }+#[derive(Debug, Clone, Default, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct CardPaymentOption {+ pub card: Card,+}- fn get_related_transaction_id(&self) -> Option<String> {- self.related_transaction_id.clone()- }- fn get_is_moto(&self) -> Option<bool> {- match self.payment_channel {- Some(PaymentChannel::MailOrder) | Some(PaymentChannel::TelephoneOrder) => Some(true),- _ => None,- }- }+impl TryFrom<(&types::PaymentsPreProcessingRouterData, String)> for NuveiThreeDSInitPaymentRequest {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(+ (item, session_token): (&types::PaymentsPreProcessingRouterData, 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 payment_method_data = item.request.get_payment_method_data()?.clone();+ let card = match payment_method_data {+ PaymentMethodData::Card(card) => card,+ _ => Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("nuvei"),+ ))?,+ };- fn get_customer_id_optional(&self) -> Option<CustomerId> {- self.customer_id.clone()- }+ let browser_info = item+ .request+ .browser_info+ .clone()+ .ok_or_else(missing_field_err("browser_info"))?;- fn get_complete_authorize_url(&self) -> Option<String> {- self.complete_authorize_url.clone()- }+ let return_url = item+ .request+ .router_return_url+ .clone()+ .ok_or_else(missing_field_err("return_url"))?;- fn get_connector_mandate_id(&self) -> Option<String> {- self.mandate_id.as_ref().and_then(|mandate_ids| {- mandate_ids.mandate_reference_id.as_ref().and_then(- |mandate_ref_id| match mandate_ref_id {- api_models::payments::MandateReferenceId::ConnectorMandateId(id) => {- id.get_connector_mandate_id()- }- _ => None,+ let billing_address = item.get_billing().ok().map(|billing| billing.into());++ Ok(Self {+ session_token: session_token.into(),+ merchant_id: connector_auth.merchant_id,+ merchant_site_id: connector_auth.merchant_site_id,+ client_request_id: item.connector_request_reference_id.clone().into(),+ client_unique_id: item.connector_request_reference_id.clone(),+ amount,+ currency,+ payment_option: CardPaymentOption {+ card: Card {+ card_number: Some(card.card_number),+ card_holder_name: item.get_optional_billing_full_name(),+ expiration_month: Some(card.card_exp_month),+ expiration_year: Some(card.card_exp_year),+ cvv: Some(card.card_cvc),+ ..Default::default()},- )+ },+ device_details: DeviceDetails {+ ip_address: browser_info.get_ip_address()?,+ },+ user_token_id: item.customer_id.clone(),+ billing_address,+ url_details: UrlDetails {+ success_url: return_url.clone(),+ failure_url: return_url.clone(),+ pending_url: return_url,+ },})}-- fn get_return_url_required(- &self,- ) -> Result<String, error_stack::Report<errors::ConnectorError>> {- self.get_router_return_url()+}+#[derive(Debug, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct NuveiSessionRequest {+ pub merchant_id: Secret<String>,+ pub merchant_site_id: Secret<String>,+ pub client_request_id: String,+ pub time_stamp: date_time::DateTime<date_time::YYYYMMDDHHmmss>,+ pub checksum: Secret<String>,+}+impl TryFrom<&types::PaymentsAuthorizeSessionTokenRouterData> for NuveiSessionRequest {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(+ item: &types::PaymentsAuthorizeSessionTokenRouterData,+ ) -> Result<Self, Self::Error> {+ let connector_meta: NuveiAuthType = NuveiAuthType::try_from(&item.connector_auth_type)?;+ let merchant_id = connector_meta.merchant_id;+ let merchant_site_id = connector_meta.merchant_site_id;+ let client_request_id = item.connector_request_reference_id.clone();+ let time_stamp = date_time::DateTime::<date_time::YYYYMMDDHHmmss>::from(date_time::now());+ let merchant_secret = connector_meta.merchant_secret;+ Ok(Self {+ merchant_id: merchant_id.clone(),+ merchant_site_id: merchant_site_id.clone(),+ client_request_id: client_request_id.clone(),+ time_stamp: time_stamp.clone(),+ checksum: Secret::new(encode_payload(&[+ merchant_id.peek(),+ merchant_site_id.peek(),+ &client_request_id,+ &time_stamp.to_string(),+ merchant_secret.peek(),+ ])?),+ })}-- fn get_capture_method(&self) -> Option<CaptureMethod> {- self.capture_method+}+#[derive(Debug, Serialize, Default, Clone, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct NuveiSessionResponse {+ pub session_token: Secret<String>,+ pub status: String,+ pub err_code: i64,+ pub reason: String,+ pub merchant_id: Secret<String>,+ pub merchant_site_id: Secret<String>,+ pub client_request_id: String,+}+impl<F, T> TryFrom<ResponseRouterData<F, NuveiSessionResponse, T, PaymentsResponseData>>+ for RouterData<F, T, PaymentsResponseData>+{+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(+ item: ResponseRouterData<F, NuveiSessionResponse, T, PaymentsResponseData>,+ ) -> Result<Self, Self::Error> {+ Ok(Self {+ status: enums::AttemptStatus::Pending,+ session_token: Some(item.response.session_token.clone().expose()),+ response: Ok(PaymentsResponseData::SessionTokenResponse {+ session_token: item.response.session_token.expose(),+ }),+ ..item.data+ })}+}+#[serde_with::skip_serializing_none]+#[derive(Debug, Serialize, Default)]+#[serde(rename_all = "camelCase")]+pub struct NuveiPaymentBaseRequest {+ pub time_stamp: String,+ pub session_token: Secret<String>,+ pub merchant_id: Secret<String>,+ pub merchant_site_id: Secret<String>,+ pub client_request_id: Secret<String>,+ pub client_unique_id: String,+ pub amount: StringMajorUnit,+ pub currency: enums::Currency,+ pub checksum: Secret<String>,+ pub transaction_type: TransactionType,+ pub dynamic_descriptor: Option<NuveiDynamicDescriptor>,+ pub is_partial_approval: Option<PartialApprovalFlag>,+ pub items: Option<Vec<NuveiItem>>,+ pub amount_details: Option<NuveiAmountDetails>,+ pub user_token_id: Option<CustomerId>,+ pub is_rebilling: Option<IsRebilling>,+}- fn get_currency_required(- &self,- ) -> Result<enums::Currency, error_stack::Report<errors::ConnectorError>> {- Ok(self.currency)- }- fn get_payment_method_data_required(- &self,- ) -> Result<PaymentMethodData, error_stack::Report<errors::ConnectorError>> {- Ok(self.payment_method_data.clone())- }+impl<F, Req> TryFrom<(&RouterData<F, Req, PaymentsResponseData>, String)>+ for NuveiPaymentBaseRequest+where+ F: std::fmt::Debug,+ Req: NuveiAuthorizePreprocessingCommon + std::fmt::Debug,+{+ type Error = error_stack::Report<errors::ConnectorError>;- fn get_minor_amount_required(- &self,- ) -> Result<MinorUnit, error_stack::Report<errors::ConnectorError>> {- self.minor_amount- .ok_or_else(missing_field_err("minor_amount"))- }+ fn try_from(+ value: (&RouterData<F, Req, PaymentsResponseData>, String),+ ) -> Result<Self, Self::Error> {+ let (item, session_token) = value;- fn get_is_partial_approval(&self) -> Option<PartialApprovalFlag> {- self.enable_partial_authorization- .map(PartialApprovalFlag::from)- }+ let currency = item.request.get_currency();+ let amount = item+ .request+ .get_minor_amount_required()?+ .to_nuvei_amount(currency)?;- fn get_email_required(&self) -> Result<Email, error_stack::Report<errors::ConnectorError>> {- self.email.clone().ok_or_else(missing_field_err("email"))- }- fn is_customer_initiated_mandate_payment(&self) -> bool {- (self.customer_acceptance.is_some() || self.setup_mandate_details.is_some())- && self.setup_future_usage == Some(FutureUsage::OffSession)- }- fn get_ntid(&self) -> Option<String> {- None- }+ fp_utils::when(session_token.is_empty(), || {+ Err(errors::ConnectorError::MissingRequiredField {+ field_name: "session_token",+ })+ })?;- fn get_is_stored_credential(&self) -> Option<StoredCredentialMode> {- StoredCredentialMode::get_optional_stored_credential(self.is_stored_credential)- }+ let auth = NuveiAuthType::try_from(&item.connector_auth_type)?;+ let client_request_id = item.connector_request_reference_id.clone();- fn get_dynamic_descriptor(- &self,- ) -> Result<Option<NuveiDynamicDescriptor>, error_stack::Report<errors::ConnectorError>> {- if let Some(descriptor) = self.billing_descriptor.as_ref() {- if let Some(phone) = descriptor.phone.as_ref() {- if phone.clone().expose().len() > 13 {- //Nuvei allows max 13 characters for merchant phone in dynamic descriptor- return Err(errors::ConnectorError::MaxFieldLengthViolated {- connector: "Nuvei".to_string(),- field_name: "dynamic_descriptor.merchant_phone".to_string(),- max_length: 13,- received_length: phone.clone().expose().len(),- }- .into());- }+ let time_stamp =+ date_time::format_date(date_time::now(), date_time::DateFormat::YYYYMMDDHHmmss)+ .change_context(errors::ConnectorError::RequestEncodingFailed)?;+ let (is_rebilling, user_token_id) = match (+ item.request.get_payment_method_data_required()?,+ item.request.is_customer_initiated_mandate_payment(),+ ) {+ (PaymentMethodData::Card(_) | PaymentMethodData::Wallet(_), true) => {+ (Some(IsRebilling::False), item.customer_id.clone())}-- let dynamic_descriptor = NuveiDynamicDescriptor {- merchant_name: descriptor.name.as_ref().map(|name| {- Secret::new(name.clone().expose().trim().chars().take(25).collect())- //Nuvei allows max 25 characters for merchant name in dynamic descriptor- }),- merchant_phone: descriptor.phone.clone(),- };-- Ok(Some(dynamic_descriptor))- } else {- Ok(None)- }- }-}--impl NuveiAuthorizePreprocessingCommon for PaymentsAuthorizeData {- fn get_browser_info(&self) -> Option<BrowserInformation> {- self.browser_info.clone()- }- fn get_ntid(&self) -> Option<String> {- self.get_optional_network_transaction_id()- }- fn get_related_transaction_id(&self) -> Option<String> {- self.related_transaction_id.clone()- }- fn get_is_moto(&self) -> Option<bool> {- match self.payment_channel {- Some(PaymentChannel::MailOrder) | Some(PaymentChannel::TelephoneOrder) => Some(true),- _ => None,- }- }- fn get_auth_data(- &self,- ) -> Result<Option<AuthenticationData>, error_stack::Report<errors::ConnectorError>> {- Ok(self.authentication_data.clone())- }- fn get_customer_id_optional(&self) -> Option<CustomerId> {- self.customer_id.clone()- }-- fn get_connector_mandate_id(&self) -> Option<String> {- self.connector_mandate_id().clone()- }-- fn get_return_url_required(- &self,- ) -> Result<String, error_stack::Report<errors::ConnectorError>> {- self.get_router_return_url()- }-- fn get_capture_method(&self) -> Option<CaptureMethod> {- self.capture_method- }-- fn get_complete_authorize_url(&self) -> Option<String> {- self.complete_authorize_url.clone()- }-- fn get_minor_amount_required(- &self,- ) -> Result<MinorUnit, error_stack::Report<errors::ConnectorError>> {- Ok(self.minor_amount)- }-- fn get_currency_required(- &self,- ) -> Result<enums::Currency, error_stack::Report<errors::ConnectorError>> {- Ok(self.currency)- }- fn get_payment_method_data_required(- &self,- ) -> Result<PaymentMethodData, error_stack::Report<errors::ConnectorError>> {- Ok(self.payment_method_data.clone())- }-- fn get_email_required(&self) -> Result<Email, error_stack::Report<errors::ConnectorError>> {- self.get_email()- }- fn is_customer_initiated_mandate_payment(&self) -> bool {- (self.customer_acceptance.is_some() || self.setup_mandate_details.is_some())- && self.setup_future_usage == Some(FutureUsage::OffSession)- }- fn get_is_partial_approval(&self) -> Option<PartialApprovalFlag> {- self.enable_partial_authorization- .map(PartialApprovalFlag::from)- }-- fn get_is_stored_credential(&self) -> Option<StoredCredentialMode> {- StoredCredentialMode::get_optional_stored_credential(self.is_stored_credential)- }-- fn get_dynamic_descriptor(- &self,- ) -> Result<Option<NuveiDynamicDescriptor>, error_stack::Report<errors::ConnectorError>> {- if let Some(descriptor) = self.billing_descriptor.as_ref() {- if let Some(phone) = descriptor.phone.as_ref() {- if phone.clone().expose().len() > 13 {- //Nuvei allows max 13 characters for merchant phone in dynamic descriptor- return Err(errors::ConnectorError::MaxFieldLengthViolated {- connector: "Nuvei".to_string(),- field_name: "dynamic_descriptor.merchant_phone".to_string(),- max_length: 13,- received_length: phone.clone().expose().len(),- }- .into());- }- }-- let dynamic_descriptor = NuveiDynamicDescriptor {- merchant_name: descriptor.name.as_ref().map(|name| {- Secret::new(name.clone().expose().trim().chars().take(25).collect())- //Nuvei allows max 25 characters for merchant name in dynamic descriptor- }),- merchant_phone: descriptor.phone.clone(),- };-- Ok(Some(dynamic_descriptor))- } else {- Ok(None)- }- }-}--impl NuveiAuthorizePreprocessingCommon for PaymentsPreProcessingData {- fn get_browser_info(&self) -> Option<BrowserInformation> {- self.browser_info.clone()- }-- fn get_related_transaction_id(&self) -> Option<String> {- self.related_transaction_id.clone()- }-- fn get_is_moto(&self) -> Option<bool> {- None- }-- fn get_customer_id_optional(&self) -> Option<CustomerId> {- None- }- fn get_email_required(&self) -> Result<Email, error_stack::Report<errors::ConnectorError>> {- self.get_email()- }- fn is_customer_initiated_mandate_payment(&self) -> bool {- (self.customer_acceptance.is_some() || self.setup_mandate_details.is_some())- && self.setup_future_usage == Some(FutureUsage::OffSession)- }-- fn get_connector_mandate_id(&self) -> Option<String> {- self.connector_mandate_id()- }-- fn get_return_url_required(- &self,- ) -> Result<String, error_stack::Report<errors::ConnectorError>> {- self.get_router_return_url()- }-- fn get_capture_method(&self) -> Option<CaptureMethod> {- self.capture_method- }-- fn get_complete_authorize_url(&self) -> Option<String> {- self.complete_authorize_url.clone()- }-- fn get_minor_amount_required(- &self,- ) -> Result<MinorUnit, error_stack::Report<errors::ConnectorError>> {- self.get_minor_amount()- }-- fn get_currency_required(- &self,- ) -> Result<enums::Currency, error_stack::Report<errors::ConnectorError>> {- self.get_currency()- }- fn get_payment_method_data_required(- &self,- ) -> Result<PaymentMethodData, error_stack::Report<errors::ConnectorError>> {- self.payment_method_data.clone().ok_or(- errors::ConnectorError::MissingRequiredField {- field_name: "payment_method_data",- }- .into(),- )- }-- fn get_is_partial_approval(&self) -> Option<PartialApprovalFlag> {- None- }-- fn get_ntid(&self) -> Option<String> {- None- }-- fn get_is_stored_credential(&self) -> Option<StoredCredentialMode> {- StoredCredentialMode::get_optional_stored_credential(self.is_stored_credential)- }-- fn get_dynamic_descriptor(- &self,- ) -> Result<Option<NuveiDynamicDescriptor>, error_stack::Report<errors::ConnectorError>> {- Ok(None)+ (+ PaymentMethodData::MandatePayment+ | PaymentMethodData::CardDetailsForNetworkTransactionId(_),+ _,+ ) => (+ Some(IsRebilling::True),+ Some(+ item.customer_id+ .clone()+ .ok_or_else(missing_field_err("customer_id"))?,+ ),+ ),+ _ => (None, None),+ };+ Ok(Self {+ merchant_id: auth.merchant_id.clone(),+ merchant_site_id: auth.merchant_site_id.clone(),+ client_request_id: Secret::new(client_request_id.clone()),+ client_unique_id: client_request_id.clone(),+ time_stamp: time_stamp.clone(),+ session_token: Secret::new(session_token),+ user_token_id,+ is_rebilling,+ amount: amount.clone(),+ currency,+ dynamic_descriptor: item.request.get_dynamic_descriptor()?,+ is_partial_approval: item.request.get_is_partial_approval(),+ items: get_l2_l3_items(&item.l2_l3_data, currency)?,+ amount_details: get_amount_details(&item.l2_l3_data, currency)?,+ transaction_type: TransactionType::get_from_capture_method_and_amount_string(+ item.request.get_capture_method().unwrap_or_default(),+ &amount.get_amount_as_string(),+ ),+ checksum: Secret::new(+ encode_payload(&[+ auth.merchant_id.peek(),+ auth.merchant_site_id.peek(),+ &client_request_id,+ &amount.get_amount_as_string(),+ ¤cy.to_string(),+ &time_stamp,+ auth.merchant_secret.peek(),+ ])+ .change_context(errors::ConnectorError::RequestEncodingFailed)?,+ ),+ })}}-#[derive(Debug, Serialize, Default, Deserialize)]-pub struct NuveiMeta {- pub session_token: Secret<String>,-}--#[derive(Debug, Serialize, Default, Deserialize)]-pub struct NuveiMandateMeta {- pub frequency: String,+#[serde_with::skip_serializing_none]+#[derive(Debug, Serialize, Default)]+#[serde(rename_all = "camelCase")]+pub struct NuveiPaymentsRequest {+ #[serde(flatten)]+ pub base: NuveiPaymentBaseRequest,+ pub payment_option: PaymentOption,+ pub device_details: DeviceDetails,+ pub billing_address: Option<BillingAddress>,+ pub shipping_address: Option<ShippingAddress>,+ pub related_transaction_id: Option<String>,+ pub external_scheme_details: Option<ExternalSchemeDetails>,+ pub is_moto: Option<bool>,+ pub url_details: Option<UrlDetails>,}-#[derive(Debug, Serialize, Deserialize)]+/// Handles payment request for capture, void and refund flows+#[derive(Debug, Serialize, Default)]#[serde(rename_all = "camelCase")]-pub struct NuveiSessionRequest {+pub struct NuveiPaymentFlowRequest {+ pub time_stamp: String,pub merchant_id: Secret<String>,pub merchant_site_id: Secret<String>,pub client_request_id: String,- pub time_stamp: date_time::DateTime<date_time::YYYYMMDDHHmmss>,+ pub client_unique_id: String,+ pub amount: StringMajorUnit,+ pub currency: enums::Currency,+ pub related_transaction_id: Option<String>,pub checksum: Secret<String>,}-#[derive(Debug, Serialize, Default, Clone, Deserialize)]+#[derive(Debug, Serialize, Default)]#[serde(rename_all = "camelCase")]-pub struct NuveiSessionResponse {- pub session_token: Secret<String>,- pub internal_request_id: i64,- pub status: String,- pub err_code: i64,- pub reason: String,+pub struct NuveiPaymentSyncRequest {pub merchant_id: Secret<String>,pub merchant_site_id: Secret<String>,- pub version: String,- pub client_request_id: String,+ pub client_unique_id: String,+ pub time_stamp: String,+ pub checksum: Secret<String>,+ pub transaction_id: String,}-#[derive(Debug, Serialize, Default)]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]+pub enum TransactionType {+ Auth,+ #[default]+ Sale,+}++#[serde_with::skip_serializing_none]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]-pub struct NuveiAmountDetails {- pub total_tax: Option<StringMajorUnit>,- pub total_shipping: Option<StringMajorUnit>,- pub total_handling: Option<StringMajorUnit>,- pub total_discount: Option<StringMajorUnit>,+pub struct PaymentOption {+ pub card: Option<Card>,+ pub redirect_url: Option<Url>,+ pub user_payment_option_id: Option<String>,+ pub alternative_payment_method: Option<AlternativePaymentMethod>,}-#[derive(Debug, Serialize, Deserialize, Clone, Default)]-#[serde(rename_all = "snake_case")]-pub enum NuveiItemType {- #[default]- Physical,- Discount,- #[serde(rename = "Shipping_fee")]- ShippingFee,- Digital,- #[serde(rename = "Gift_card")]- GiftCard,- #[serde(rename = "Store_credit")]- StoreCredit,- Surcharge,- #[serde(rename = "Sales_tax")]- SalesTax,-}-impl From<Option<enums::ProductType>> for NuveiItemType {- fn from(value: Option<enums::ProductType>) -> Self {- match value {- Some(enums::ProductType::Digital) => Self::Digital,- Some(enums::ProductType::Physical) => Self::Physical,- Some(enums::ProductType::Ride)- | Some(enums::ProductType::Travel)- | Some(enums::ProductType::Accommodation) => Self::ShippingFee,- _ => Self::Physical,- }- }+#[serde_with::skip_serializing_none]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct Card {+ pub card_number: Option<cards::CardNumber>,+ pub card_holder_name: Option<Secret<String>>,+ pub expiration_month: Option<Secret<String>>,+ pub expiration_year: Option<Secret<String>>,+ #[serde(rename = "CVV")]+ pub cvv: Option<Secret<String>>,+ pub three_d: Option<ThreeD>,+ pub cc_card_number: Option<Secret<String>>,+ pub bin: Option<Secret<String>>,+ pub last4_digits: Option<Secret<String>>,+ pub cc_exp_month: Option<Secret<String>>,+ pub cc_exp_year: Option<Secret<String>>,+ pub acquirer_id: Option<Secret<String>>,+ pub cvv2_reply: Option<String>,+ pub avs_code: Option<String>,+ pub card_type: Option<String>,+ pub brand: Option<String>,+ pub issuer_bank_name: Option<String>,+ pub issuer_country: Option<String>,+ pub external_token: Option<ExternalToken>,+ pub stored_credentials: Option<StoredCredentialMode>,}-#[serde_with::skip_serializing_none]-#[derive(Debug, Serialize, Default)]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]-pub struct NuveiItem {- pub name: String,- #[serde(rename = "type")]- pub item_type: NuveiItemType,- pub price: StringMajorUnit,- pub quantity: String,- pub group_id: Option<String>,- pub discount: Option<StringMajorUnit>,- pub discount_rate: Option<String>,- pub shipping: Option<StringMajorUnit>,- pub shipping_tax: Option<StringMajorUnit>,- pub shipping_tax_rate: Option<String>,- pub tax: Option<StringMajorUnit>,- pub tax_rate: Option<String>,- pub image_url: Option<String>,- pub product_url: Option<String>,+pub struct ExternalToken {+ pub external_token_provider: ExternalTokenProvider,+ pub mobile_token: Option<Secret<String>>,+ pub cryptogram: Option<Secret<String>>,+ pub eci_provider: Option<String>,}-#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]-pub enum IsRebilling {- #[serde(rename = "1")]- True,- #[serde(rename = "0")]- False,++#[derive(Debug, Clone, Default, Serialize, Deserialize)]+#[serde(rename_all = "PascalCase")]+pub enum ExternalTokenProvider {+ #[default]+ GooglePay,+ ApplePay,}#[serde_with::skip_serializing_none]-#[derive(Debug, Serialize, Default)]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]-pub struct NuveiDynamicDescriptor {- pub merchant_name: Option<Secret<String>>,- pub merchant_phone: Option<Secret<String>>,+pub struct ExternalMpi {+ pub eci: Option<String>,+ pub cavv: Secret<String>,+ #[serde(rename = "dsTransID")]+ pub ds_trans_id: Option<String>,+ pub challenge_preference: Option<String>,+ pub exemption_request_reason: Option<String>,}#[serde_with::skip_serializing_none]-#[derive(Debug, Serialize, Default)]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]-pub struct NuveiPaymentsRequest {- pub time_stamp: String,- pub session_token: Secret<String>,- pub merchant_id: Secret<String>,- pub merchant_site_id: Secret<String>,- pub client_request_id: Secret<String>,- pub amount: StringMajorUnit,- pub currency: enums::Currency,- /// This ID uniquely identifies your consumer/user in your system.- pub user_token_id: Option<CustomerId>,- //unique transaction id- pub client_unique_id: String,- pub transaction_type: TransactionType,- pub is_rebilling: Option<IsRebilling>,- pub payment_option: PaymentOption,- pub is_moto: Option<bool>,- pub device_details: DeviceDetails,- pub checksum: Secret<String>,- pub billing_address: Option<BillingAddress>,- pub shipping_address: Option<ShippingAddress>,- pub related_transaction_id: Option<String>,- pub url_details: Option<UrlDetails>,- pub amount_details: Option<NuveiAmountDetails>,- pub items: Option<Vec<NuveiItem>>,- pub is_partial_approval: Option<PartialApprovalFlag>,- pub external_scheme_details: Option<ExternalSchemeDetails>,- pub dynamic_descriptor: Option<NuveiDynamicDescriptor>,+pub struct ThreeD {+ pub method_completion_ind: Option<MethodCompletion>,+ pub browser_details: Option<BrowserDetails>,+ #[serde(rename = "notificationURL")]+ pub notification_url: Option<String>,+ #[serde(rename = "merchantURL")]+ pub merchant_url: Option<String>,+ pub acs_url: Option<String>,+ pub c_req: Option<Secret<String>>,+ pub external_mpi: Option<ExternalMpi>,+ pub transaction_id: Option<String>,+ pub platform_type: Option<PlatformType>,+ pub v2supported: Option<String>,+ pub v2_additional_params: Option<V2AdditionalParams>,}-#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]-#[serde(rename_all = "UPPERCASE")]-pub enum PartialApprovalFlag {- #[serde(rename = "1")]- Enabled,- #[serde(rename = "0")]- Disabled,+#[derive(Debug, Clone, Default, Serialize, Deserialize)]+pub enum MethodCompletion {+ #[serde(rename = "Y")]+ Success,+ #[serde(rename = "N")]+ Failure,+ #[serde(rename = "U")]+ #[default]+ Unavailable,}-impl From<primitive_wrappers::EnablePartialAuthorizationBool> for PartialApprovalFlag {- fn from(value: primitive_wrappers::EnablePartialAuthorizationBool) -> Self {- if value.is_true() {- Self::Enabled- } else {- Self::Disabled- }- }+#[derive(Debug, Clone, Default, Serialize, Deserialize)]+pub enum PlatformType {+ #[serde(rename = "01")]+ App,+ #[serde(rename = "02")]+ #[default]+ Browser,}-#[derive(Debug, Serialize, Default)]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]-pub struct UrlDetails {- pub success_url: String,- pub failure_url: String,- pub pending_url: String,-}--#[derive(Debug, Serialize, Default)]-pub struct NuveiInitPaymentRequest {- pub session_token: Secret<String>,- pub merchant_id: Secret<String>,- pub merchant_site_id: Secret<String>,- pub client_request_id: String,- pub amount: StringMajorUnit,- pub currency: String,- pub payment_option: PaymentOption,- pub checksum: Secret<String>,+pub struct BrowserDetails {+ pub accept_header: String,+ pub ip: Secret<String, IpAddress>,+ pub java_enabled: String,+ pub java_script_enabled: String,+ pub language: String,+ pub color_depth: u8,+ pub screen_height: u32,+ pub screen_width: u32,+ pub time_zone: i32,+ pub user_agent: String,}-/// Handles payment request for capture, void and refund flows-#[derive(Debug, Serialize, Default)]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]-pub struct NuveiPaymentFlowRequest {- pub time_stamp: String,- pub merchant_id: Secret<String>,- pub merchant_site_id: Secret<String>,- pub client_request_id: String,- pub amount: StringMajorUnit,- pub currency: enums::Currency,- pub related_transaction_id: Option<String>,- pub checksum: Secret<String>,+pub struct V2AdditionalParams {+ pub challenge_window_size: Option<String>,+ /// Recurring Expiry in format YYYYMMDD. REQUIRED if isRebilling = 0, We recommend setting rebillExpiry to a value of no more than 5 years from the date of the initial transaction processing date.+ pub rebill_expiry: Option<String>,+ /// Recurring Frequency in days+ pub rebill_frequency: Option<String>,+ pub challenge_preference: Option<String>,}-#[derive(Debug, Serialize, Default)]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]-pub struct NuveiPaymentSyncRequest {- pub merchant_id: Secret<String>,- pub merchant_site_id: Secret<String>,- pub time_stamp: String,- pub checksum: Secret<String>,- pub transaction_id: String,+pub struct DeviceDetails {+ pub ip_address: Secret<String, IpAddress>,}-#[derive(Debug, Default, Serialize, Deserialize)]-pub enum TransactionType {- Auth,- #[default]- Sale,+impl TransactionType {+ fn get_from_capture_method_and_amount_string(+ capture_method: CaptureMethod,+ amount: &str,+ ) -> Self {+ let amount_value = amount.parse::<f64>();+ if capture_method == CaptureMethod::Manual || amount_value == Ok(0.0) {+ Self::Auth+ } else {+ Self::Sale+ }+ }}-#[serde_with::skip_serializing_none]-#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct PaymentOption {- pub card: Option<Card>,- pub redirect_url: Option<Url>,- pub user_payment_option_id: Option<String>,- pub alternative_payment_method: Option<AlternativePaymentMethod>,- pub billing_address: Option<BillingAddress>,- pub shipping_address: Option<BillingAddress>,+#[derive(Debug, Serialize, Deserialize)]+pub struct NuveiRedirectionResponse {+ pub cres: Secret<String>,}--#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "snake_case")]-pub enum NuveiBIC {- #[serde(rename = "ABNANL2A")]- Abnamro,- #[serde(rename = "ASNBNL21")]- ASNBank,- #[serde(rename = "BUNQNL2A")]- Bunq,- #[serde(rename = "INGBNL2A")]- Ing,- #[serde(rename = "KNABNL2H")]- Knab,- #[serde(rename = "RABONL2U")]- Rabobank,- #[serde(rename = "RBRBNL21")]- RegioBank,- #[serde(rename = "SNSBNL2A")]- SNSBank,- #[serde(rename = "TRIONL2U")]- TriodosBank,- #[serde(rename = "FVLBNL22")]- VanLanschotBankiers,- #[serde(rename = "MOYONL21")]- Moneyou,+#[derive(Debug, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct NuveiACSResponse {+ #[serde(rename = "threeDSServerTransID")]+ pub three_ds_server_trans_id: Secret<String>,+ #[serde(rename = "acsTransID")]+ pub acs_trans_id: Secret<String>,+ pub message_type: String,+ pub message_version: String,+ pub trans_status: Option<LiabilityShift>,+ pub message_extension: Option<Vec<MessageExtensionAttribute>>,+ pub acs_signed_content: Option<serde_json::Value>,}-#[derive(Debug, Clone, Serialize)]-#[serde(rename_all = "UPPERCASE")]-pub enum NuveiCardType {- Visa,- MasterCard,- AmericanExpress,- Discover,- DinersClub,- Interac,- JCB,- UnionPay,- CartesBancaires,+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+pub enum LiabilityShift {+ #[serde(rename = "Y", alias = "1", alias = "y")]+ Success,+ #[serde(rename = "N", alias = "0", alias = "n")]+ Failed,}-impl TryFrom<common_enums::CardNetwork> for NuveiCardType {- type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(card_network: common_enums::CardNetwork) -> Result<Self, Self::Error> {- match card_network {- common_enums::CardNetwork::Visa => Ok(Self::Visa),- common_enums::CardNetwork::Mastercard => Ok(Self::MasterCard),- common_enums::CardNetwork::AmericanExpress => Ok(Self::AmericanExpress),- common_enums::CardNetwork::Discover => Ok(Self::Discover),- common_enums::CardNetwork::DinersClub => Ok(Self::DinersClub),- common_enums::CardNetwork::JCB => Ok(Self::JCB),- common_enums::CardNetwork::UnionPay => Ok(Self::UnionPay),- common_enums::CardNetwork::CartesBancaires => Ok(Self::CartesBancaires),- common_enums::CardNetwork::Interac => Ok(Self::Interac),- _ => Err(errors::ConnectorError::NotSupported {- message: "Card network".to_string(),- connector: "nuvei",- }- .into()),- }- }+pub fn encode_payload(+ payload: &[&str],+) -> Result<String, error_stack::Report<errors::ConnectorError>> {+ let data = payload.join("");+ let digest = crypto::Sha256+ .generate_digest(data.as_bytes())+ .change_context(errors::ConnectorError::RequestEncodingFailed)+ .attach_printable("error encoding nuvie payload")?;+ Ok(hex::encode(digest))}-impl TryFrom<&utils::CardIssuer> for NuveiCardType {- type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(card_issuer: &utils::CardIssuer) -> Result<Self, Self::Error> {- match card_issuer {- utils::CardIssuer::Visa => Ok(Self::Visa),- utils::CardIssuer::Master => Ok(Self::MasterCard),- utils::CardIssuer::AmericanExpress => Ok(Self::AmericanExpress),- utils::CardIssuer::Discover => Ok(Self::Discover),- utils::CardIssuer::DinersClub => Ok(Self::DinersClub),- utils::CardIssuer::JCB => Ok(Self::JCB),- utils::CardIssuer::CartesBancaires => Ok(Self::CartesBancaires),- &utils::CardIssuer::UnionPay => Ok(Self::UnionPay),- _ => Err(errors::ConnectorError::NotSupported {- message: "Card network".to_string(),- connector: "nuvei",+impl From<NuveiPaymentSyncResponse> for NuveiTransactionSyncResponse {+ fn from(value: NuveiPaymentSyncResponse) -> Self {+ match value {+ NuveiPaymentSyncResponse::NuveiDmn(payment_dmn_notification) => {+ Self::from(*payment_dmn_notification)+ }+ NuveiPaymentSyncResponse::NuveiApi(nuvei_transaction_sync_response) => {+ *nuvei_transaction_sync_response}- .into()),}}}-#[serde_with::skip_serializing_none]-#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct AlternativePaymentMethod {- pub payment_method: AlternativePaymentMethodType,- #[serde(rename = "BIC")]- pub bank_id: Option<NuveiBIC>,+#[derive(Debug)]+pub struct NuveiCardDetails {+ card: payment_method_data::Card,+ three_d: Option<ThreeD>,+ card_holder_name: Option<Secret<String>>,+ stored_credentials: Option<StoredCredentialMode>,}-#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "snake_case")]-pub enum AlternativePaymentMethodType {- #[default]- #[serde(rename = "apmgw_expresscheckout")]- Expresscheckout,- #[serde(rename = "apmgw_Giropay")]- Giropay,- #[serde(rename = "apmgw_Sofort")]- Sofort,- #[serde(rename = "apmgw_iDeal")]- Ideal,- #[serde(rename = "apmgw_EPS")]- Eps,- #[serde(rename = "apmgw_Afterpay")]- AfterPay,- #[serde(rename = "apmgw_Klarna")]- Klarna,+// Define new structs with camelCase serialization+#[derive(Serialize, Debug)]+#[serde(rename_all = "camelCase")]+struct GooglePayCamelCase {+ pm_type: Secret<String>,+ description: Secret<String>,+ info: GooglePayInfoCamelCase,+ tokenization_data: GooglePayTokenizationDataCamelCase,}-#[serde_with::skip_serializing_none]-#[derive(Debug, Clone, Default, Serialize, Deserialize)]+#[derive(Serialize, Debug)]#[serde(rename_all = "camelCase")]-pub struct BillingAddress {- pub email: Email,- pub first_name: Option<Secret<String>>,- pub last_name: Option<Secret<String>>,- pub country: api_models::enums::CountryAlpha2,- pub phone: Option<Secret<String>>,- pub city: Option<Secret<String>>,- pub address: Option<Secret<String>>,- pub street_number: Option<Secret<String>>,- pub zip: Option<Secret<String>>,- pub state: Option<Secret<String>>,- pub cell: Option<Secret<String>>,- pub address_match: Option<Secret<String>>,- pub address_line2: Option<Secret<String>>,- pub address_line3: Option<Secret<String>>,- pub home_phone: Option<Secret<String>>,- pub work_phone: Option<Secret<String>>,+struct GooglePayInfoCamelCase {+ card_network: Secret<String>,+ card_details: Secret<String>,+ assurance_details: Option<GooglePayAssuranceDetailsCamelCase>,+ card_funding_source: Option<GooglePayCardFundingSource>,}--#[serde_with::skip_serializing_none]-#[derive(Debug, Clone, Default, Serialize, Deserialize)]+#[derive(Debug, Serialize)]#[serde(rename_all = "camelCase")]-pub struct ShippingAddress {- pub salutation: Option<Secret<String>>,- pub first_name: Option<Secret<String>>,- pub last_name: Option<Secret<String>>,- pub address: Option<Secret<String>>,- pub cell: Option<Secret<String>>,- pub phone: Option<Secret<String>>,- pub zip: Option<Secret<String>>,- pub city: Option<Secret<String>>,- pub country: api_models::enums::CountryAlpha2,- pub state: Option<Secret<String>>,- pub email: Email,- pub county: Option<Secret<String>>,- pub address_line2: Option<Secret<String>>,- pub address_line3: Option<Secret<String>>,- pub street_number: Option<Secret<String>>,- pub company_name: Option<Secret<String>>,- pub care_of: Option<Secret<String>>,+pub struct ExternalSchemeDetails {+ transaction_id: Secret<String>, // This is sensitive information+ brand: Option<NuveiCardType>,}--impl From<&Address> for BillingAddress {- fn from(address: &Address) -> Self {- let address_details = address.address.as_ref();- Self {- email: address.email.clone().unwrap_or_default(),- first_name: address.get_optional_first_name(),- last_name: address_details.and_then(|address| address.get_optional_last_name()),- country: address_details- .and_then(|address| address.get_optional_country())- .unwrap_or_default(),- phone: address- .phone- .as_ref()- .and_then(|phone| phone.number.clone()),- city: address_details- .and_then(|address| address.get_optional_city().map(|city| city.into())),- address: address_details.and_then(|address| address.get_optional_line1()),- street_number: None,- zip: address_details.and_then(|details| details.get_optional_zip()),- state: address_details.and_then(|details| details.to_state_code_as_optional().ok()?),- cell: None,- address_match: None,- address_line2: address_details.and_then(|address| address.get_optional_line2()),- address_line3: address_details.and_then(|address| address.get_optional_line3()),- home_phone: None,- work_phone: None,- }- }+#[derive(Serialize, Debug)]+#[serde(rename_all = "camelCase")]+struct GooglePayAssuranceDetailsCamelCase {+ card_holder_authenticated: bool,+ account_verified: bool,}-impl From<&Address> for ShippingAddress {- fn from(address: &Address) -> Self {- let address_details = address.address.as_ref();+#[derive(Serialize, Debug)]+#[serde(rename_all = "camelCase")]+struct GooglePayTokenizationDataCamelCase {+ #[serde(rename = "type")]+ token_type: Secret<String>,+ token: Secret<String>,+}- Self {- email: address.email.clone().unwrap_or_default(),- first_name: address_details.and_then(|details| details.get_optional_first_name()),- last_name: address_details.and_then(|details| details.get_optional_last_name()),- country: address_details- .and_then(|details| details.get_optional_country())- .unwrap_or_default(),- phone: address- .phone- .as_ref()- .and_then(|phone| phone.number.clone()),- city: address_details- .and_then(|details| details.get_optional_city().map(|city| city.into())),- address: address_details.and_then(|details| details.get_optional_line1()),- street_number: None,- zip: address_details.and_then(|details| details.get_optional_zip()),- state: None,- cell: None,- address_line2: address_details.and_then(|details| details.get_optional_line2()),- address_line3: address_details.and_then(|details| details.get_optional_line3()),- county: None,- company_name: None,- care_of: None,- salutation: None,- }- }+// Define ApplePay structs with camelCase serialization+#[derive(Serialize, Debug)]+#[serde(rename_all = "camelCase")]+struct ApplePayCamelCase {+ payment_data: Secret<String>,+ payment_method: ApplePayPaymentMethodCamelCase,+ transaction_identifier: Secret<String>,}-#[serde_with::skip_serializing_none]-#[derive(Debug, Clone, Default, Serialize, Deserialize)]++#[derive(Serialize, Debug)]#[serde(rename_all = "camelCase")]-pub struct Card {- pub card_number: Option<cards::CardNumber>,- pub card_holder_name: Option<Secret<String>>,- pub expiration_month: Option<Secret<String>>,- pub expiration_year: Option<Secret<String>>,- #[serde(rename = "CVV")]- pub cvv: Option<Secret<String>>,- pub three_d: Option<ThreeD>,- pub cc_card_number: Option<Secret<String>>,- pub bin: Option<Secret<String>>,- pub last4_digits: Option<Secret<String>>,- pub cc_exp_month: Option<Secret<String>>,- pub cc_exp_year: Option<Secret<String>>,- pub acquirer_id: Option<Secret<String>>,- pub cvv2_reply: Option<String>,- pub avs_code: Option<String>,- pub card_type: Option<String>,- pub brand: Option<String>,- pub issuer_bank_name: Option<String>,- pub issuer_country: Option<String>,- pub is_prepaid: Option<String>,- pub external_token: Option<ExternalToken>,- pub stored_credentials: Option<StoredCredentialMode>,-}--#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct StoredCredentialMode {- pub stored_credentials_mode: Option<StoredCredentialModeType>,+struct ApplePayPaymentMethodCamelCase {+ display_name: Secret<String>,+ network: Secret<String>,+ #[serde(rename = "type")]+ pm_type: Secret<String>,}-#[derive(Debug, Clone, Serialize, Deserialize)]-pub enum StoredCredentialModeType {- #[serde(rename = "0")]- First,- #[serde(rename = "1")]- Used,+fn get_google_pay_decrypt_data(+ predecrypt_data: &GPayPredecryptData,+ brand: Option<String>,+) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>> {+ Ok(NuveiPaymentsRequest {+ payment_option: PaymentOption {+ card: Some(Card {+ brand,+ card_number: Some(predecrypt_data.application_primary_account_number.clone()),+ last4_digits: Some(Secret::new(+ predecrypt_data+ .application_primary_account_number+ .clone()+ .get_last4(),+ )),+ expiration_month: Some(predecrypt_data.card_exp_month.clone()),+ expiration_year: Some(predecrypt_data.card_exp_year.clone()),+ external_token: Some(ExternalToken {+ external_token_provider: ExternalTokenProvider::GooglePay,+ mobile_token: None,+ cryptogram: predecrypt_data.cryptogram.clone(),+ eci_provider: predecrypt_data.eci_indicator.clone(),+ }),+ ..Default::default()+ }),+ ..Default::default()+ },+ ..Default::default()+ })}-impl StoredCredentialMode {- pub fn get_optional_stored_credential(is_stored_credential: Option<bool>) -> Option<Self> {- is_stored_credential.and_then(|is_stored_credential| {- if is_stored_credential {- Some(Self {- stored_credentials_mode: Some(StoredCredentialModeType::Used),- })- } else {- None- }- })+fn get_googlepay_info<F, Req>(+ item: &RouterData<F, Req, PaymentsResponseData>,+ gpay_data: &GooglePayWalletData,+) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>>+where+ Req: NuveiAuthorizePreprocessingCommon,+{+ if let Ok(PaymentMethodToken::GooglePayDecrypt(ref token)) = item.get_payment_method_token() {+ return get_google_pay_decrypt_data(token, Some(gpay_data.info.card_network.clone()));}-}-#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct ExternalToken {- pub external_token_provider: ExternalTokenProvider,- pub mobile_token: Option<Secret<String>>,- pub cryptogram: Option<Secret<String>>,- pub eci_provider: Option<String>,-}-#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "PascalCase")]-pub enum ExternalTokenProvider {- #[default]- GooglePay,- ApplePay,-}+ match &gpay_data.tokenization_data {+ GpayTokenizationData::Decrypted(gpay_predecrypt_data) => get_google_pay_decrypt_data(+ gpay_predecrypt_data,+ Some(gpay_data.info.card_network.clone()),+ ),+ GpayTokenizationData::Encrypted(ref encrypted_data) => Ok(NuveiPaymentsRequest {+ payment_option: PaymentOption {+ card: Some(Card {+ external_token: Some(ExternalToken {+ external_token_provider: ExternalTokenProvider::GooglePay,-#[serde_with::skip_serializing_none]-#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct ExternalMpi {- pub eci: Option<String>,- pub cavv: Secret<String>,- #[serde(rename = "dsTransID")]- pub ds_trans_id: Option<String>,- pub challenge_preference: Option<String>,- pub exemption_request_reason: Option<String>,-}+ mobile_token: {+ let (token_type, token) = (+ encrypted_data.token_type.clone(),+ encrypted_data.token.clone(),+ );-#[serde_with::skip_serializing_none]-#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct ThreeD {- pub method_completion_ind: Option<MethodCompletion>,- pub browser_details: Option<BrowserDetails>,- pub version: Option<String>,- #[serde(rename = "notificationURL")]- pub notification_url: Option<String>,- #[serde(rename = "merchantURL")]- pub merchant_url: Option<String>,- pub acs_url: Option<String>,- pub acs_challenge_mandate: Option<String>,- pub c_req: Option<Secret<String>>,- pub three_d_flow: Option<String>,- pub external_mpi: Option<ExternalMpi>,- pub external_transaction_id: Option<String>,- pub transaction_id: Option<String>,- pub three_d_reason_id: Option<String>,- pub three_d_reason: Option<String>,- pub challenge_preference_reason: Option<String>,- pub challenge_cancel_reason_id: Option<String>,- pub challenge_cancel_reason: Option<String>,- pub is_liability_on_issuer: Option<String>,- pub is_exemption_request_in_authentication: Option<String>,- pub flow: Option<String>,- pub acquirer_decision: Option<String>,- pub decision_reason: Option<String>,- pub platform_type: Option<PlatformType>,- pub v2supported: Option<String>,- pub v2_additional_params: Option<V2AdditionalParams>,+ let google_pay: GooglePayCamelCase = GooglePayCamelCase {+ pm_type: Secret::new(gpay_data.pm_type.clone()),+ description: Secret::new(gpay_data.description.clone()),+ info: GooglePayInfoCamelCase {+ card_network: Secret::new(gpay_data.info.card_network.clone()),+ card_details: Secret::new(gpay_data.info.card_details.clone()),+ assurance_details: gpay_data+ .info+ .assurance_details+ .as_ref()+ .map(|details| GooglePayAssuranceDetailsCamelCase {+ card_holder_authenticated: details+ .card_holder_authenticated,+ account_verified: details.account_verified,+ }),+ card_funding_source: gpay_data.info.card_funding_source.clone(),+ },+ tokenization_data: GooglePayTokenizationDataCamelCase {+ token_type: token_type.into(),+ token: token.into(),+ },+ };+ Some(Secret::new(+ google_pay.encode_to_string_of_json().change_context(+ errors::ConnectorError::RequestEncodingFailed,+ )?,+ ))+ },+ cryptogram: None,+ eci_provider: None,+ }),+ ..Default::default()+ }),+ ..Default::default()+ },+ ..Default::default()+ }),+ }}-#[derive(Debug, Clone, Default, Serialize, Deserialize)]-pub enum MethodCompletion {- #[serde(rename = "Y")]- Success,- #[serde(rename = "N")]- Failure,- #[serde(rename = "U")]- #[default]- Unavailable,+fn get_apple_pay_decrypt_data(+ apple_pay_predecrypt_data: &ApplePayPredecryptData,+ network: String,+) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>> {+ Ok(NuveiPaymentsRequest {+ payment_option: PaymentOption {+ card: Some(Card {+ brand: Some(network),+ card_number: Some(+ apple_pay_predecrypt_data+ .application_primary_account_number+ .clone(),+ ),+ last4_digits: Some(Secret::new(+ apple_pay_predecrypt_data+ .application_primary_account_number+ .get_last4(),+ )),+ expiration_month: Some(+ apple_pay_predecrypt_data+ .application_expiration_month+ .clone(),+ ),+ expiration_year: Some(+ apple_pay_predecrypt_data+ .application_expiration_year+ .clone(),+ ),+ external_token: Some(ExternalToken {+ external_token_provider: ExternalTokenProvider::ApplePay,+ mobile_token: None,+ cryptogram: Some(+ apple_pay_predecrypt_data+ .payment_data+ .online_payment_cryptogram+ .clone(),+ ),+ eci_provider: apple_pay_predecrypt_data.payment_data.eci_indicator.clone(),+ }),+ ..Default::default()+ }),+ ..Default::default()+ },+ ..Default::default()+ })}+fn get_applepay_info<F, Req>(+ item: &RouterData<F, Req, PaymentsResponseData>,+ apple_pay_data: &ApplePayWalletData,+) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>>+where+ Req: NuveiAuthorizePreprocessingCommon,+{+ if let Ok(PaymentMethodToken::ApplePayDecrypt(ref token)) = item.get_payment_method_token() {+ return get_apple_pay_decrypt_data(token, apple_pay_data.payment_method.network.clone());+ }+ match apple_pay_data.payment_data {+ ApplePayPaymentData::Decrypted(ref apple_pay_predecrypt_data) => {+ get_apple_pay_decrypt_data(+ apple_pay_predecrypt_data,+ apple_pay_data.payment_method.network.clone(),+ )+ }-#[derive(Debug, Clone, Default, Serialize, Deserialize)]-pub enum PlatformType {- #[serde(rename = "01")]- App,- #[serde(rename = "02")]- #[default]- Browser,-}--#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct BrowserDetails {- pub accept_header: String,- pub ip: Secret<String, IpAddress>,- pub java_enabled: String,- pub java_script_enabled: String,- pub language: String,- pub color_depth: u8,- pub screen_height: u32,- pub screen_width: u32,- pub time_zone: i32,- pub user_agent: String,-}--#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct V2AdditionalParams {- pub challenge_window_size: Option<String>,- /// Recurring Expiry in format YYYYMMDD. REQUIRED if isRebilling = 0, We recommend setting rebillExpiry to a value of no more than 5 years from the date of the initial transaction processing date.- pub rebill_expiry: Option<String>,- /// Recurring Frequency in days- pub rebill_frequency: Option<String>,- pub challenge_preference: Option<String>,-}--#[derive(Debug, Clone, Default, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct DeviceDetails {- pub ip_address: Secret<String, IpAddress>,-}+ ApplePayPaymentData::Encrypted(ref encrypted_data) => Ok(NuveiPaymentsRequest {+ payment_option: PaymentOption {+ card: Some(Card {+ external_token: Some(ExternalToken {+ external_token_provider: ExternalTokenProvider::ApplePay,+ mobile_token: {+ let apple_pay: ApplePayCamelCase = ApplePayCamelCase {+ payment_data: encrypted_data.to_string().into(),+ payment_method: ApplePayPaymentMethodCamelCase {+ display_name: Secret::new(+ apple_pay_data.payment_method.display_name.clone(),+ ),+ network: Secret::new(+ apple_pay_data.payment_method.network.clone(),+ ),+ pm_type: Secret::new(+ apple_pay_data.payment_method.pm_type.clone(),+ ),+ },+ transaction_identifier: Secret::new(+ apple_pay_data.transaction_identifier.clone(),+ ),+ };-impl TransactionType {- fn get_from_capture_method_and_amount_string(- capture_method: CaptureMethod,- amount: &str,- ) -> Self {- let amount_value = amount.parse::<f64>();- if capture_method == CaptureMethod::Manual || amount_value == Ok(0.0) {- Self::Auth- } else {- Self::Sale- }+ Some(Secret::new(+ apple_pay.encode_to_string_of_json().change_context(+ errors::ConnectorError::RequestEncodingFailed,+ )?,+ ))+ },+ cryptogram: None,+ eci_provider: None,+ }),+ ..Default::default()+ }),+ ..Default::default()+ },+ ..Default::default()+ }),}}-#[derive(Debug, Serialize, Deserialize)]-pub struct NuveiRedirectionResponse {- pub cres: Secret<String>,-}-#[derive(Debug, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct NuveiACSResponse {- #[serde(rename = "threeDSServerTransID")]- pub three_ds_server_trans_id: Secret<String>,- #[serde(rename = "acsTransID")]- pub acs_trans_id: Secret<String>,- pub message_type: String,- pub message_version: String,- pub trans_status: Option<LiabilityShift>,- pub message_extension: Option<Vec<MessageExtensionAttribute>>,- pub acs_signed_content: Option<serde_json::Value>,-}--#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]-pub enum LiabilityShift {- #[serde(rename = "Y", alias = "1", alias = "y")]- Success,- #[serde(rename = "N", alias = "0", alias = "n")]- Failed,-}--pub fn encode_payload(- payload: &[&str],-) -> Result<String, error_stack::Report<errors::ConnectorError>> {- let data = payload.join("");- let digest = crypto::Sha256- .generate_digest(data.as_bytes())- .change_context(errors::ConnectorError::RequestEncodingFailed)- .attach_printable("error encoding nuvie payload")?;- Ok(hex::encode(digest))-}+impl TryFrom<enums::BankNames> for NuveiBIC {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(bank: enums::BankNames) -> Result<Self, Self::Error> {+ match bank {+ enums::BankNames::AbnAmro => Ok(Self::Abnamro),+ enums::BankNames::AsnBank => Ok(Self::ASNBank),+ enums::BankNames::Bunq => Ok(Self::Bunq),+ enums::BankNames::Ing => Ok(Self::Ing),+ enums::BankNames::Knab => Ok(Self::Knab),+ enums::BankNames::Rabobank => Ok(Self::Rabobank),+ enums::BankNames::SnsBank => Ok(Self::SNSBank),+ enums::BankNames::TriodosBank => Ok(Self::TriodosBank),+ enums::BankNames::VanLanschot => Ok(Self::VanLanschotBankiers),+ enums::BankNames::Moneyou => Ok(Self::Moneyou),-impl From<NuveiPaymentSyncResponse> for NuveiTransactionSyncResponse {- fn from(value: NuveiPaymentSyncResponse) -> Self {- match value {- NuveiPaymentSyncResponse::NuveiDmn(payment_dmn_notification) => {- Self::from(*payment_dmn_notification)- }- NuveiPaymentSyncResponse::NuveiApi(nuvei_transaction_sync_response) => {- *nuvei_transaction_sync_response- }+ _ => Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("Nuvei"),+ ))?,}}}-impl TryFrom<&types::PaymentsAuthorizeSessionTokenRouterData> for NuveiSessionRequest {+impl<F, Req>+ ForeignTryFrom<(+ AlternativePaymentMethodType,+ Option<BankRedirectData>,+ &RouterData<F, Req, PaymentsResponseData>,+ )> for NuveiPaymentsRequest+where+ Req: NuveiAuthorizePreprocessingCommon,+{type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(- item: &types::PaymentsAuthorizeSessionTokenRouterData,+ fn foreign_try_from(+ data: (+ AlternativePaymentMethodType,+ Option<BankRedirectData>,+ &RouterData<F, Req, PaymentsResponseData>,+ ),) -> Result<Self, Self::Error> {- let connector_meta: NuveiAuthType = NuveiAuthType::try_from(&item.connector_auth_type)?;- let merchant_id = connector_meta.merchant_id;- let merchant_site_id = connector_meta.merchant_site_id;- let client_request_id = item.connector_request_reference_id.clone();- let time_stamp = date_time::DateTime::<date_time::YYYYMMDDHHmmss>::from(date_time::now());- let merchant_secret = connector_meta.merchant_secret;+ let (payment_method, redirect, item) = data;+ let bank_id = match (&payment_method, redirect) {+ (AlternativePaymentMethodType::Expresscheckout, _) => None,+ (AlternativePaymentMethodType::Giropay, _) => None,+ (AlternativePaymentMethodType::Sofort, _) | (AlternativePaymentMethodType::Eps, _) => {+ None+ }+ (+ AlternativePaymentMethodType::Ideal,+ Some(BankRedirectData::Ideal { bank_name, .. }),+ ) => bank_name.map(NuveiBIC::try_from).transpose()?,+ _ => Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("Nuvei"),+ ))?,+ };Ok(Self {- merchant_id: merchant_id.clone(),- merchant_site_id: merchant_site_id.clone(),- client_request_id: client_request_id.clone(),- time_stamp: time_stamp.clone(),- checksum: Secret::new(encode_payload(&[- merchant_id.peek(),- merchant_site_id.peek(),- &client_request_id,- &time_stamp.to_string(),- merchant_secret.peek(),- ])?),+ payment_option: PaymentOption {+ alternative_payment_method: Some(AlternativePaymentMethod {+ payment_method,+ bank_id,+ }),+ ..Default::default()+ },+ billing_address: item.get_billing().ok().map(|billing| billing.into()),+ ..Default::default()})}}-impl<F, T> TryFrom<ResponseRouterData<F, NuveiSessionResponse, T, PaymentsResponseData>>- for RouterData<F, T, PaymentsResponseData>+fn get_pay_later_info<F, Req>(+ payment_method_type: AlternativePaymentMethodType,+ item: &RouterData<F, Req, PaymentsResponseData>,+) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>>+where+ Req: NuveiAuthorizePreprocessingCommon,{- type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(- item: ResponseRouterData<F, NuveiSessionResponse, T, PaymentsResponseData>,- ) -> Result<Self, Self::Error> {- Ok(Self {- status: enums::AttemptStatus::Pending,- session_token: Some(item.response.session_token.clone().expose()),- response: Ok(PaymentsResponseData::SessionTokenResponse {- session_token: item.response.session_token.expose(),+ let address = item+ .get_billing()?+ .address+ .as_ref()+ .ok_or_else(missing_field_err("billing.address"))?;+ address.get_first_name()?;+ address.get_country()?; //country is necessary check+ item.request.get_email_required()?;+ Ok(NuveiPaymentsRequest {+ payment_option: PaymentOption {+ alternative_payment_method: Some(AlternativePaymentMethod {+ payment_method: payment_method_type,+ ..Default::default()}),- ..item.data- })- }+ ..Default::default()+ },+ ..Default::default()+ })}-#[derive(Debug)]-pub struct NuveiCardDetails {- card: payment_method_data::Card,- three_d: Option<ThreeD>,- card_holder_name: Option<Secret<String>>,- stored_credentials: Option<StoredCredentialMode>,-}+fn get_ntid_card_info<F, Req>(+ router_data: &RouterData<F, Req, PaymentsResponseData>,+ data: CardDetailsForNetworkTransactionId,+) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>>+where+ Req: NuveiAuthorizePreprocessingCommon,+{+ let card_type = match data.card_network.clone() {+ Some(card_type) => NuveiCardType::try_from(card_type)?,+ None => NuveiCardType::try_from(&data.get_card_issuer()?)?,+ };-// Define new structs with camelCase serialization-#[derive(Serialize, Debug)]-#[serde(rename_all = "camelCase")]-struct GooglePayCamelCase {- pm_type: Secret<String>,- description: Secret<String>,- info: GooglePayInfoCamelCase,- tokenization_data: GooglePayTokenizationDataCamelCase,-}--#[derive(Serialize, Debug)]-#[serde(rename_all = "camelCase")]-struct GooglePayInfoCamelCase {- card_network: Secret<String>,- card_details: Secret<String>,- assurance_details: Option<GooglePayAssuranceDetailsCamelCase>,- card_funding_source: Option<GooglePayCardFundingSource>,-}-#[derive(Debug, Serialize)]-#[serde(rename_all = "camelCase")]-pub struct ExternalSchemeDetails {- transaction_id: Secret<String>, // This is sensitive information- brand: Option<NuveiCardType>,-}-#[derive(Serialize, Debug)]-#[serde(rename_all = "camelCase")]-struct GooglePayAssuranceDetailsCamelCase {- card_holder_authenticated: bool,- account_verified: bool,-}--#[derive(Serialize, Debug)]-#[serde(rename_all = "camelCase")]-struct GooglePayTokenizationDataCamelCase {- #[serde(rename = "type")]- token_type: Secret<String>,- token: Secret<String>,-}--// Define ApplePay structs with camelCase serialization-#[derive(Serialize, Debug)]-#[serde(rename_all = "camelCase")]-struct ApplePayCamelCase {- payment_data: Secret<String>,- payment_method: ApplePayPaymentMethodCamelCase,- transaction_identifier: Secret<String>,+ let external_scheme_details = Some(ExternalSchemeDetails {+ transaction_id: router_data+ .request+ .get_ntid()+ .ok_or_else(missing_field_err("network_transaction_id"))+ .attach_printable("Nuvei unable to find NTID for MIT")?+ .into(),+ brand: Some(card_type),+ });+ let payment_option: PaymentOption = PaymentOption {+ card: Some(Card {+ card_number: Some(data.card_number),+ card_holder_name: data.card_holder_name,+ expiration_month: Some(data.card_exp_month),+ expiration_year: Some(data.card_exp_year),+ ..Default::default() // CVV should be disabled by nuvei+ }),+ ..Default::default()+ };+ Ok(NuveiPaymentsRequest {+ external_scheme_details,+ payment_option,+ ..Default::default()+ })}-#[derive(Serialize, Debug)]-#[serde(rename_all = "camelCase")]-struct ApplePayPaymentMethodCamelCase {- display_name: Secret<String>,- network: Secret<String>,- #[serde(rename = "type")]- pm_type: Secret<String>,-}+impl<F, Req> TryFrom<(&RouterData<F, Req, PaymentsResponseData>, String)> for NuveiPaymentsRequest+where+ Req: NuveiAuthorizePreprocessingCommon + std::fmt::Debug,+ F: std::fmt::Debug,+{+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(+ data: (&RouterData<F, Req, PaymentsResponseData>, String),+ ) -> Result<Self, Self::Error> {+ let (item, session_token) = data;+ let base = NuveiPaymentBaseRequest::try_from((item, session_token))?;-fn get_google_pay_decrypt_data(- predecrypt_data: &GPayPredecryptData,- is_rebilling: Option<IsRebilling>,- brand: Option<String>,- user_token_id: Option<CustomerId>,-) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>> {- Ok(NuveiPaymentsRequest {- is_rebilling,- user_token_id,- payment_option: PaymentOption {- card: Some(Card {- brand,- card_number: Some(predecrypt_data.application_primary_account_number.clone()),- last4_digits: Some(Secret::new(- predecrypt_data- .application_primary_account_number- .clone()- .get_last4(),+ let return_url = item.request.get_return_url_required()?;+ let address = {+ let mut billing_address = item.get_billing()?.clone();+ billing_address.email = Some(+ item.get_billing_email()+ .or_else(|_| item.request.get_email_required())?,+ );+ Some(billing_address)+ };+ let request_data = match item.request.get_payment_method_data_required()?.clone() {+ PaymentMethodData::Card(card) => get_card_info(item, &card),+ PaymentMethodData::MandatePayment => Self::try_from(item),+ PaymentMethodData::CardDetailsForNetworkTransactionId(data) => {+ get_ntid_card_info(item, data)+ }+ PaymentMethodData::Wallet(wallet) => match wallet {+ WalletData::GooglePay(gpay_data) => get_googlepay_info(item, &gpay_data),+ WalletData::ApplePay(apple_pay_data) => get_applepay_info(item, &apple_pay_data),+ WalletData::PaypalRedirect(_) => Self::foreign_try_from((+ AlternativePaymentMethodType::Expresscheckout,+ None,+ item,)),- expiration_month: Some(predecrypt_data.card_exp_month.clone()),- expiration_year: Some(predecrypt_data.card_exp_year.clone()),- external_token: Some(ExternalToken {- external_token_provider: ExternalTokenProvider::GooglePay,- mobile_token: None,- cryptogram: predecrypt_data.cryptogram.clone(),- eci_provider: predecrypt_data.eci_indicator.clone(),- }),- ..Default::default()+ _ => Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("nuvei"),+ )+ .into()),+ },+ PaymentMethodData::BankRedirect(redirect) => match redirect {+ BankRedirectData::Eps { .. } => Self::foreign_try_from((+ AlternativePaymentMethodType::Eps,+ Some(redirect),+ item,+ )),+ BankRedirectData::Giropay { .. } => Self::foreign_try_from((+ AlternativePaymentMethodType::Giropay,+ Some(redirect),+ item,+ )),+ BankRedirectData::Ideal { .. } => Self::foreign_try_from((+ AlternativePaymentMethodType::Ideal,+ Some(redirect),+ item,+ )),+ BankRedirectData::Sofort { .. } => Self::foreign_try_from((+ AlternativePaymentMethodType::Sofort,+ Some(redirect),+ item,+ )),+ _ => Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("nuvei"),+ )+ .into()),+ },+ PaymentMethodData::PayLater(pay_later_data) => match pay_later_data {+ PayLaterData::KlarnaRedirect { .. } => {+ get_pay_later_info(AlternativePaymentMethodType::Klarna, item)+ }+ PayLaterData::AfterpayClearpayRedirect { .. } => {+ get_pay_later_info(AlternativePaymentMethodType::AfterPay, item)+ }+ _ => Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("nuvei"),+ )+ .into()),+ },+ _ => Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("nuvei"),+ )+ .into()),+ }?;+ let device_details = if request_data+ .device_details+ .ip_address+ .clone()+ .expose()+ .is_empty()+ {+ DeviceDetails::foreign_try_from(&item.request.get_browser_info().clone())?+ } else {+ request_data.device_details.clone()+ };+ Ok(Self {+ base,+ related_transaction_id: request_data.related_transaction_id,+ payment_option: request_data.payment_option,+ billing_address: address.clone().map(|ref address| address.into()),+ shipping_address: item.get_optional_shipping().map(|address| address.into()),+ device_details,+ external_scheme_details: request_data.external_scheme_details,+ url_details: Some(UrlDetails {+ success_url: return_url.clone(),+ failure_url: return_url.clone(),+ pending_url: return_url,}),- ..Default::default()- },- ..Default::default()- })+ ..request_data+ })+ }}-fn get_googlepay_info<F, Req>(+fn get_card_info<F, Req>(item: &RouterData<F, Req, PaymentsResponseData>,- gpay_data: &GooglePayWalletData,+ card_details: &payment_method_data::Card,) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>>whereReq: NuveiAuthorizePreprocessingCommon,{- let is_rebilling = if item.request.is_customer_initiated_mandate_payment() {- Some(IsRebilling::False)- } else {- None+ let additional_params = match item.request.is_customer_initiated_mandate_payment() {+ true => Some(V2AdditionalParams {+ rebill_expiry: Some(+ time::OffsetDateTime::now_utc()+ .replace_year(time::OffsetDateTime::now_utc().year() + 5)+ .map_err(|_| errors::ConnectorError::DateFormattingFailed)?+ .date()+ .format(&time::macros::format_description!("[year][month][day]"))+ .map_err(|_| errors::ConnectorError::DateFormattingFailed)?,+ ),+ rebill_frequency: Some("0".to_string()),+ challenge_window_size: Some(CHALLENGE_WINDOW_SIZE.to_string()),+ challenge_preference: Some(CHALLENGE_PREFERENCE.to_string()),+ }),+ // non mandate transactions+ false => Some(V2AdditionalParams {+ rebill_expiry: None,+ rebill_frequency: None,+ challenge_window_size: Some(CHALLENGE_WINDOW_SIZE.to_string()),+ challenge_preference: Some(CHALLENGE_PREFERENCE.to_string()),+ }),};- let user_token_id = if item.request.is_customer_initiated_mandate_payment() {- item.request.get_customer_id_optional()+ let three_d = if let Some(auth_data) = item.request.get_auth_data()? {+ Some(ThreeD {+ external_mpi: Some(ExternalMpi {+ eci: auth_data.eci,+ cavv: auth_data.cavv,+ ds_trans_id: auth_data.ds_trans_id,+ challenge_preference: None,+ exemption_request_reason: None,+ }),+ ..Default::default()+ })+ } else if item.is_three_ds() {+ Some(ThreeD {+ browser_details: item+ .request+ .get_browser_info()+ .map(BrowserDetails::try_from)+ .transpose()?,+ v2_additional_params: additional_params,+ notification_url: item.request.get_complete_authorize_url().clone(),+ merchant_url: Some(item.request.get_return_url_required()?),+ platform_type: Some(PlatformType::Browser),+ method_completion_ind: Some(MethodCompletion::Unavailable),+ ..Default::default()+ })} else {None};- if let Ok(PaymentMethodToken::GooglePayDecrypt(ref token)) = item.get_payment_method_token() {- return get_google_pay_decrypt_data(- token,- is_rebilling,- Some(gpay_data.info.card_network.clone()),- user_token_id,- );- }-- match &gpay_data.tokenization_data {- GpayTokenizationData::Decrypted(gpay_predecrypt_data) => get_google_pay_decrypt_data(- gpay_predecrypt_data,- is_rebilling,- Some(gpay_data.info.card_network.clone()),- user_token_id,- ),- GpayTokenizationData::Encrypted(ref encrypted_data) => Ok(NuveiPaymentsRequest {- is_rebilling,- user_token_id,- payment_option: PaymentOption {- card: Some(Card {- external_token: Some(ExternalToken {- external_token_provider: ExternalTokenProvider::GooglePay,-- mobile_token: {- let (token_type, token) = (- encrypted_data.token_type.clone(),- encrypted_data.token.clone(),- );-- let google_pay: GooglePayCamelCase = GooglePayCamelCase {- pm_type: Secret::new(gpay_data.pm_type.clone()),- description: Secret::new(gpay_data.description.clone()),- info: GooglePayInfoCamelCase {- card_network: Secret::new(gpay_data.info.card_network.clone()),- card_details: Secret::new(gpay_data.info.card_details.clone()),- assurance_details: gpay_data- .info- .assurance_details- .as_ref()- .map(|details| GooglePayAssuranceDetailsCamelCase {- card_holder_authenticated: details- .card_holder_authenticated,- account_verified: details.account_verified,- }),- card_funding_source: gpay_data.info.card_funding_source.clone(),- },- tokenization_data: GooglePayTokenizationDataCamelCase {- token_type: token_type.into(),- token: token.into(),- },- };- Some(Secret::new(- google_pay.encode_to_string_of_json().change_context(- errors::ConnectorError::RequestEncodingFailed,- )?,- ))- },- cryptogram: None,- eci_provider: None,- }),- ..Default::default()- }),- ..Default::default()- },- ..Default::default()- }),- }-}--fn get_apple_pay_decrypt_data(- apple_pay_predecrypt_data: &ApplePayPredecryptData,- is_rebilling: Option<IsRebilling>,- network: String,- user_token_id: Option<CustomerId>,-) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>> {Ok(NuveiPaymentsRequest {- is_rebilling,- user_token_id,- payment_option: PaymentOption {- card: Some(Card {- brand: Some(network),- card_number: Some(- apple_pay_predecrypt_data- .application_primary_account_number- .clone(),- ),- last4_digits: Some(Secret::new(- apple_pay_predecrypt_data- .application_primary_account_number- .get_last4(),- )),- expiration_month: Some(- apple_pay_predecrypt_data- .application_expiration_month- .clone(),- ),- expiration_year: Some(- apple_pay_predecrypt_data- .application_expiration_year- .clone(),- ),- external_token: Some(ExternalToken {- external_token_provider: ExternalTokenProvider::ApplePay,- mobile_token: None,- cryptogram: Some(- apple_pay_predecrypt_data- .payment_data- .online_payment_cryptogram- .clone(),- ),- eci_provider: apple_pay_predecrypt_data.payment_data.eci_indicator.clone(),- }),- ..Default::default()- }),- ..Default::default()- },+ related_transaction_id: item.request.get_related_transaction_id().clone(),+ device_details: DeviceDetails::foreign_try_from(&item.request.get_browser_info().clone())?,+ payment_option: PaymentOption::from(NuveiCardDetails {+ card: card_details.clone(),+ three_d,+ card_holder_name: item.get_optional_billing_full_name(),+ stored_credentials: item.request.get_is_stored_credential(),+ }),+ is_moto: item.request.get_is_moto(),..Default::default()})}-fn get_applepay_info<F, Req>(- item: &RouterData<F, Req, PaymentsResponseData>,- apple_pay_data: &ApplePayWalletData,-) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>>-where- Req: NuveiAuthorizePreprocessingCommon,-{- let is_rebilling = if item.request.is_customer_initiated_mandate_payment() {- Some(IsRebilling::False)- } else {- None- };- let user_token_id = if item.request.is_customer_initiated_mandate_payment() {- item.request.get_customer_id_optional()- } else {- None- };- if let Ok(PaymentMethodToken::ApplePayDecrypt(ref token)) = item.get_payment_method_token() {- return get_apple_pay_decrypt_data(- token,- is_rebilling,- apple_pay_data.payment_method.network.clone(),- user_token_id,- );- }- match apple_pay_data.payment_data {- ApplePayPaymentData::Decrypted(ref apple_pay_predecrypt_data) => {- get_apple_pay_decrypt_data(- apple_pay_predecrypt_data,- is_rebilling,- apple_pay_data.payment_method.network.clone(),- user_token_id,- )- }-- ApplePayPaymentData::Encrypted(ref encrypted_data) => Ok(NuveiPaymentsRequest {- is_rebilling,- user_token_id,- payment_option: PaymentOption {- card: Some(Card {- external_token: Some(ExternalToken {- external_token_provider: ExternalTokenProvider::ApplePay,- mobile_token: {- let apple_pay: ApplePayCamelCase = ApplePayCamelCase {- payment_data: encrypted_data.to_string().into(),- payment_method: ApplePayPaymentMethodCamelCase {- display_name: Secret::new(- apple_pay_data.payment_method.display_name.clone(),- ),- network: Secret::new(- apple_pay_data.payment_method.network.clone(),- ),- pm_type: Secret::new(- apple_pay_data.payment_method.pm_type.clone(),- ),- },- transaction_identifier: Secret::new(- apple_pay_data.transaction_identifier.clone(),- ),- };-- Some(Secret::new(- apple_pay.encode_to_string_of_json().change_context(- errors::ConnectorError::RequestEncodingFailed,- )?,- ))- },- cryptogram: None,- eci_provider: None,- }),- ..Default::default()- }),+impl From<NuveiCardDetails> for PaymentOption {+ fn from(card_details: NuveiCardDetails) -> Self {+ let card = card_details.card;+ Self {+ card: Some(Card {+ card_number: Some(card.card_number),+ card_holder_name: card_details.card_holder_name,+ expiration_month: Some(card.card_exp_month),+ expiration_year: Some(card.card_exp_year),+ three_d: card_details.three_d,+ cvv: Some(card.card_cvc),+ stored_credentials: card_details.stored_credentials,..Default::default()- },+ }),..Default::default()- }),- }-}--impl TryFrom<enums::BankNames> for NuveiBIC {- type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(bank: enums::BankNames) -> Result<Self, Self::Error> {- match bank {- enums::BankNames::AbnAmro => Ok(Self::Abnamro),- enums::BankNames::AsnBank => Ok(Self::ASNBank),- enums::BankNames::Bunq => Ok(Self::Bunq),- enums::BankNames::Ing => Ok(Self::Ing),- enums::BankNames::Knab => Ok(Self::Knab),- enums::BankNames::Rabobank => Ok(Self::Rabobank),- enums::BankNames::SnsBank => Ok(Self::SNSBank),- enums::BankNames::TriodosBank => Ok(Self::TriodosBank),- enums::BankNames::VanLanschot => Ok(Self::VanLanschotBankiers),- enums::BankNames::Moneyou => Ok(Self::Moneyou),-- enums::BankNames::AmericanExpress- | enums::BankNames::AffinBank- | enums::BankNames::AgroBank- | enums::BankNames::AllianceBank- | enums::BankNames::AmBank- | enums::BankNames::BankOfAmerica- | enums::BankNames::BankOfChina- | enums::BankNames::BankIslam- | enums::BankNames::BankMuamalat- | enums::BankNames::BankRakyat- | enums::BankNames::BankSimpananNasional- | enums::BankNames::Barclays- | enums::BankNames::BlikPSP- | enums::BankNames::CapitalOne- | enums::BankNames::Chase- | enums::BankNames::Citi- | enums::BankNames::CimbBank- | enums::BankNames::Discover- | enums::BankNames::NavyFederalCreditUnion- | enums::BankNames::PentagonFederalCreditUnion- | enums::BankNames::SynchronyBank- | enums::BankNames::WellsFargo- | enums::BankNames::Handelsbanken- | enums::BankNames::HongLeongBank- | enums::BankNames::HsbcBank- | enums::BankNames::KuwaitFinanceHouse- | enums::BankNames::Regiobank- | enums::BankNames::Revolut- | enums::BankNames::ArzteUndApothekerBank- | enums::BankNames::AustrianAnadiBankAg- | enums::BankNames::BankAustria- | enums::BankNames::Bank99Ag- | enums::BankNames::BankhausCarlSpangler- | enums::BankNames::BankhausSchelhammerUndSchatteraAg- | enums::BankNames::BankMillennium- | enums::BankNames::BankPEKAOSA- | enums::BankNames::BawagPskAg- | enums::BankNames::BksBankAg- | enums::BankNames::BrullKallmusBankAg- | enums::BankNames::BtvVierLanderBank- | enums::BankNames::CapitalBankGraweGruppeAg- | enums::BankNames::CeskaSporitelna- | enums::BankNames::Dolomitenbank- | enums::BankNames::EasybankAg- | enums::BankNames::EPlatbyVUB- | enums::BankNames::ErsteBankUndSparkassen- | enums::BankNames::FrieslandBank- | enums::BankNames::HypoAlpeadriabankInternationalAg- | enums::BankNames::HypoNoeLbFurNiederosterreichUWien- | enums::BankNames::HypoOberosterreichSalzburgSteiermark- | enums::BankNames::HypoTirolBankAg- | enums::BankNames::HypoVorarlbergBankAg- | enums::BankNames::HypoBankBurgenlandAktiengesellschaft- | enums::BankNames::KomercniBanka- | enums::BankNames::MBank- | enums::BankNames::MarchfelderBank- | enums::BankNames::Maybank- | enums::BankNames::OberbankAg- | enums::BankNames::OsterreichischeArzteUndApothekerbank- | enums::BankNames::OcbcBank- | enums::BankNames::PayWithING- | enums::BankNames::PlaceZIPKO- | enums::BankNames::PlatnoscOnlineKartaPlatnicza- | enums::BankNames::PosojilnicaBankEGen- | enums::BankNames::PostovaBanka- | enums::BankNames::PublicBank- | enums::BankNames::RaiffeisenBankengruppeOsterreich- | enums::BankNames::RhbBank- | enums::BankNames::SchelhammerCapitalBankAg- | enums::BankNames::StandardCharteredBank- | enums::BankNames::SchoellerbankAg- | enums::BankNames::SpardaBankWien- | enums::BankNames::SporoPay- | enums::BankNames::SantanderPrzelew24- | enums::BankNames::TatraPay- | enums::BankNames::Viamo- | enums::BankNames::VolksbankGruppe- | enums::BankNames::VolkskreditbankAg- | enums::BankNames::VrBankBraunau- | enums::BankNames::UobBank- | enums::BankNames::PayWithAliorBank- | enums::BankNames::BankiSpoldzielcze- | enums::BankNames::PayWithInteligo- | enums::BankNames::BNPParibasPoland- | enums::BankNames::BankNowySA- | enums::BankNames::CreditAgricole- | enums::BankNames::PayWithBOS- | enums::BankNames::PayWithCitiHandlowy- | enums::BankNames::PayWithPlusBank- | enums::BankNames::ToyotaBank- | enums::BankNames::VeloBank- | enums::BankNames::ETransferPocztowy24- | enums::BankNames::PlusBank- | enums::BankNames::EtransferPocztowy24- | enums::BankNames::BankiSpbdzielcze- | enums::BankNames::BankNowyBfgSa- | enums::BankNames::GetinBank- | enums::BankNames::Blik- | enums::BankNames::NoblePay- | enums::BankNames::IdeaBank- | enums::BankNames::EnveloBank- | enums::BankNames::NestPrzelew- | enums::BankNames::MbankMtransfer- | enums::BankNames::Inteligo- | enums::BankNames::PbacZIpko- | enums::BankNames::BnpParibas- | enums::BankNames::BankPekaoSa- | enums::BankNames::VolkswagenBank- | enums::BankNames::AliorBank- | enums::BankNames::Boz- | enums::BankNames::BangkokBank- | enums::BankNames::KrungsriBank- | enums::BankNames::KrungThaiBank- | enums::BankNames::TheSiamCommercialBank- | enums::BankNames::KasikornBank- | enums::BankNames::OpenBankSuccess- | enums::BankNames::OpenBankFailure- | enums::BankNames::OpenBankCancelled- | enums::BankNames::Aib- | enums::BankNames::BankOfScotland- | enums::BankNames::DanskeBank- | enums::BankNames::FirstDirect- | enums::BankNames::FirstTrust- | enums::BankNames::Halifax- | enums::BankNames::Lloyds- | enums::BankNames::Monzo- | enums::BankNames::NatWest- | enums::BankNames::NationwideBank- | enums::BankNames::RoyalBankOfScotland- | enums::BankNames::Starling- | enums::BankNames::TsbBank- | enums::BankNames::TescoBank- | enums::BankNames::Yoursafe- | enums::BankNames::N26- | enums::BankNames::NationaleNederlanden- | enums::BankNames::UlsterBank => Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("Nuvei"),- ))?,}}}-impl<F, Req>- ForeignTryFrom<(- AlternativePaymentMethodType,- Option<BankRedirectData>,- &RouterData<F, Req, PaymentsResponseData>,- )> for NuveiPaymentsRequest-where- Req: NuveiAuthorizePreprocessingCommon,+impl TryFrom<(&types::PaymentsCompleteAuthorizeRouterData, Secret<String>)>+ for NuveiPaymentsRequest{type Error = error_stack::Report<errors::ConnectorError>;- fn foreign_try_from(- data: (- AlternativePaymentMethodType,- Option<BankRedirectData>,- &RouterData<F, Req, PaymentsResponseData>,- ),+ fn try_from(+ data: (&types::PaymentsCompleteAuthorizeRouterData, Secret<String>),) -> Result<Self, Self::Error> {- let (payment_method, redirect, item) = data;- let bank_id = match (&payment_method, redirect) {- (AlternativePaymentMethodType::Expresscheckout, _) => None,- (AlternativePaymentMethodType::Giropay, _) => None,- (AlternativePaymentMethodType::Sofort, _) | (AlternativePaymentMethodType::Eps, _) => {- let address = item.get_billing_address()?;- address.get_first_name()?;- item.request.get_email_required()?;- item.get_billing_country()?;- None- }- (- AlternativePaymentMethodType::Ideal,- Some(BankRedirectData::Ideal { bank_name, .. }),- ) => {- let address = item.get_billing_address()?;- address.get_first_name()?;- item.request.get_email_required()?;- item.get_billing_country()?;- bank_name.map(NuveiBIC::try_from).transpose()?- }- _ => Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("Nuvei"),- ))?,- };- let billing_address: Option<BillingAddress> =- item.get_billing().ok().map(|billing| billing.into());- Ok(Self {- payment_option: PaymentOption {- alternative_payment_method: Some(AlternativePaymentMethod {- payment_method,- bank_id,+ let (item, session_token) = data;+ let request_data = match item.request.payment_method_data.clone() {+ Some(PaymentMethodData::Card(card)) => Ok(Self {+ payment_option: PaymentOption::from(NuveiCardDetails {+ card,+ three_d: None,+ card_holder_name: item.get_optional_billing_full_name(),+ stored_credentials: StoredCredentialMode::get_optional_stored_credential(+ item.request.is_stored_credential,+ ),}),+ device_details: DeviceDetails::foreign_try_from(&item.request.browser_info)?,..Default::default()- },- billing_address,- ..Default::default()+ }),+ _ => Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("nuvei"),+ )),+ }?;+ Ok(Self {+ related_transaction_id: item.request.connector_transaction_id.clone(),+ payment_option: request_data.payment_option,+ device_details: request_data.device_details,+ base: NuveiPaymentBaseRequest::try_from((item, session_token.peek().to_string()))?,+ ..request_data})}}-fn get_pay_later_info<F, Req>(- payment_method_type: AlternativePaymentMethodType,- item: &RouterData<F, Req, PaymentsResponseData>,-) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>>-where- Req: NuveiAuthorizePreprocessingCommon,-{- let address = item- .get_billing()?- .address- .as_ref()- .ok_or_else(missing_field_err("billing.address"))?;- address.get_first_name()?;- let payment_method = payment_method_type;- address.get_country()?; //country is necessary check- item.request.get_email_required()?;- Ok(NuveiPaymentsRequest {- payment_option: PaymentOption {- alternative_payment_method: Some(AlternativePaymentMethod {- payment_method,- ..Default::default()- }),- billing_address: item.get_billing().ok().map(|billing| billing.into()),- ..Default::default()- },- ..Default::default()- })+impl TryFrom<NuveiPaymentRequestData> for NuveiPaymentFlowRequest {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(request: NuveiPaymentRequestData) -> Result<Self, Self::Error> {+ let connector_meta: NuveiAuthType = NuveiAuthType::try_from(&request.connector_auth_type)?;+ let merchant_id = connector_meta.merchant_id;+ let merchant_site_id = connector_meta.merchant_site_id;+ let client_request_id = request.client_request_id;+ let time_stamp =+ date_time::format_date(date_time::now(), date_time::DateFormat::YYYYMMDDHHmmss)+ .change_context(errors::ConnectorError::RequestEncodingFailed)?;+ let merchant_secret = connector_meta.merchant_secret;+ Ok(Self {+ merchant_id: merchant_id.to_owned(),+ merchant_site_id: merchant_site_id.to_owned(),+ client_request_id: client_request_id.clone(),+ client_unique_id: client_request_id.clone(),+ time_stamp: time_stamp.clone(),+ checksum: Secret::new(encode_payload(&[+ merchant_id.peek(),+ merchant_site_id.peek(),+ &client_request_id,+ &client_request_id.clone(),+ &request.amount.get_amount_as_string(),+ &request.currency.to_string(),+ &request.related_transaction_id.clone().unwrap_or_default(),+ &time_stamp,+ merchant_secret.peek(),+ ])?),+ amount: request.amount,+ currency: request.currency,+ related_transaction_id: request.related_transaction_id,+ })+ }}-fn get_ntid_card_info<F, Req>(- router_data: &RouterData<F, Req, PaymentsResponseData>,- data: CardDetailsForNetworkTransactionId,-) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>>-where- Req: NuveiAuthorizePreprocessingCommon,-{- let card_type = match data.card_network.clone() {- Some(card_type) => NuveiCardType::try_from(card_type)?,- None => NuveiCardType::try_from(&data.get_card_issuer()?)?,- };-- let external_scheme_details = Some(ExternalSchemeDetails {- transaction_id: router_data- .request- .get_ntid()- .ok_or_else(missing_field_err("network_transaction_id"))- .attach_printable("Nuvei unable to find NTID for MIT")?- .into(),- brand: Some(card_type),- });- let payment_option: PaymentOption = PaymentOption {- card: Some(Card {- card_number: Some(data.card_number),- card_holder_name: data.card_holder_name,- expiration_month: Some(data.card_exp_month),- expiration_year: Some(data.card_exp_year),- ..Default::default() // CVV should be disabled by nuvei- }),- redirect_url: None,- user_payment_option_id: None,- alternative_payment_method: None,- billing_address: None,- shipping_address: None,- };- let is_rebilling = Some(IsRebilling::True);-- Ok(NuveiPaymentsRequest {- external_scheme_details,- payment_option,- user_token_id: Some(- router_data- .request- .get_customer_id_optional()- .ok_or_else(missing_field_err("customer_id"))?,- ),- is_rebilling,- ..Default::default()- })-}-fn get_l2_l3_items(- l2_l3_data: &Option<Box<L2L3Data>>,- currency: enums::Currency,-) -> Result<Option<Vec<NuveiItem>>, error_stack::Report<errors::ConnectorError>> {- l2_l3_data.as_ref().map_or(Ok(None), |data| {- data.get_order_details()- .map_or(Ok(None), |order_details_list| {- // Map each order to a Result<NuveiItem>- let results: Vec<Result<NuveiItem, error_stack::Report<errors::ConnectorError>>> =- order_details_list- .iter()- .map(|order| {- let discount = order- .unit_discount_amount- .map(|amount| {- convert_amount(NUVEI_AMOUNT_CONVERTOR, amount, currency)- })- .transpose()?;- let tax = order- .total_tax_amount- .map(|amount| {- convert_amount(NUVEI_AMOUNT_CONVERTOR, amount, currency)- })- .transpose()?;- Ok(NuveiItem {- name: order.product_name.clone(),- item_type: order.product_type.clone().into(),- price: convert_amount(- NUVEI_AMOUNT_CONVERTOR,- order.amount,- currency,- )?,- quantity: order.quantity.to_string(),- group_id: order.product_id.clone(),- discount,- discount_rate: None,- shipping: None,- shipping_tax: None,- shipping_tax_rate: None,- tax,- tax_rate: order.tax_rate.map(|rate| rate.to_string()),- image_url: order.product_img_link.clone(),- product_url: None,- })- })- .collect();- let mut items = Vec::with_capacity(results.len());- for result in results {- match result {- Ok(item) => items.push(item),- Err(err) => return Err(err),- }- }- Ok(Some(items))- })- })+#[derive(Debug, Clone, Default)]+pub struct NuveiPaymentRequestData {+ pub amount: StringMajorUnit,+ pub currency: enums::Currency,+ pub related_transaction_id: Option<String>,+ pub client_request_id: String,+ pub client_unique_id: String,+ pub connector_auth_type: ConnectorAuthType,+ pub session_token: Secret<String>,+ pub capture_method: Option<CaptureMethod>,}-fn get_amount_details(- l2_l3_data: &Option<Box<L2L3Data>>,- currency: enums::Currency,-) -> Result<Option<NuveiAmountDetails>, error_stack::Report<errors::ConnectorError>> {- l2_l3_data.as_ref().map_or(Ok(None), |data| {- let total_tax = data- .get_order_tax_amount()- .map(|amount| convert_amount(NUVEI_AMOUNT_CONVERTOR, amount, currency))- .transpose()?;- let total_shipping = data- .get_shipping_cost()- .map(|amount| convert_amount(NUVEI_AMOUNT_CONVERTOR, amount, currency))- .transpose()?;- let total_discount = data- .get_discount_amount()- .map(|amount| convert_amount(NUVEI_AMOUNT_CONVERTOR, amount, currency))- .transpose()?;- let total_handling = data- .get_duty_amount()- .map(|amount| convert_amount(NUVEI_AMOUNT_CONVERTOR, amount, currency))- .transpose()?;- Ok(Some(NuveiAmountDetails {- total_tax,- total_shipping,- total_handling,- total_discount,- }))- })-}-impl<F, Req> TryFrom<(&RouterData<F, Req, PaymentsResponseData>, String)> for NuveiPaymentsRequest-where- Req: NuveiAuthorizePreprocessingCommon + std::fmt::Debug,- F: std::fmt::Debug,-{+impl TryFrom<&types::PaymentsCaptureRouterData> for NuveiPaymentFlowRequest {type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(- data: (&RouterData<F, Req, PaymentsResponseData>, String),- ) -> Result<Self, Self::Error> {- let item = data.0;-- let request_data = match item.request.get_payment_method_data_required()?.clone() {- PaymentMethodData::Card(card) => get_card_info(item, &card),- PaymentMethodData::MandatePayment => Self::try_from(item),- PaymentMethodData::CardDetailsForNetworkTransactionId(data) => {- get_ntid_card_info(item, data)- }- PaymentMethodData::Wallet(wallet) => match wallet {- WalletData::GooglePay(gpay_data) => get_googlepay_info(item, &gpay_data),- WalletData::ApplePay(apple_pay_data) => get_applepay_info(item, &apple_pay_data),- WalletData::PaypalRedirect(_) => Self::foreign_try_from((- AlternativePaymentMethodType::Expresscheckout,- None,- item,- )),- WalletData::AliPayQr(_)- | WalletData::AliPayRedirect(_)- | WalletData::AliPayHkRedirect(_)- | WalletData::AmazonPay(_)- | WalletData::AmazonPayRedirect(_)- | WalletData::Paysera(_)- | WalletData::Skrill(_)- | WalletData::BluecodeRedirect {}- | WalletData::MomoRedirect(_)- | WalletData::KakaoPayRedirect(_)- | WalletData::GoPayRedirect(_)- | WalletData::GcashRedirect(_)- | WalletData::ApplePayRedirect(_)- | WalletData::ApplePayThirdPartySdk(_)- | WalletData::DanaRedirect {}- | WalletData::GooglePayRedirect(_)- | WalletData::GooglePayThirdPartySdk(_)- | WalletData::MbWayRedirect(_)- | WalletData::MobilePayRedirect(_)- | WalletData::PaypalSdk(_)- | WalletData::Paze(_)- | WalletData::SamsungPay(_)- | WalletData::TwintRedirect {}- | WalletData::VippsRedirect {}- | WalletData::TouchNGoRedirect(_)- | WalletData::WeChatPayRedirect(_)- | WalletData::CashappQr(_)- | WalletData::SwishQr(_)- | WalletData::WeChatPayQr(_)- | WalletData::RevolutPay(_)- | WalletData::Mifinity(_) => Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("nuvei"),- )- .into()),- },- PaymentMethodData::BankRedirect(redirect) => match redirect {- BankRedirectData::Eps { .. } => Self::foreign_try_from((- AlternativePaymentMethodType::Eps,- Some(redirect),- item,- )),- BankRedirectData::Giropay { .. } => Self::foreign_try_from((- AlternativePaymentMethodType::Giropay,- Some(redirect),- item,- )),- BankRedirectData::Ideal { .. } => Self::foreign_try_from((- AlternativePaymentMethodType::Ideal,- Some(redirect),- item,- )),- BankRedirectData::Sofort { .. } => Self::foreign_try_from((- AlternativePaymentMethodType::Sofort,- Some(redirect),- item,- )),- BankRedirectData::BancontactCard { .. }- | BankRedirectData::Bizum {}- | BankRedirectData::Blik { .. }- | BankRedirectData::Eft { .. }- | BankRedirectData::Interac { .. }- | BankRedirectData::OnlineBankingCzechRepublic { .. }- | BankRedirectData::OnlineBankingFinland { .. }- | BankRedirectData::OnlineBankingPoland { .. }- | BankRedirectData::OnlineBankingSlovakia { .. }- | BankRedirectData::Przelewy24 { .. }- | BankRedirectData::Trustly { .. }- | BankRedirectData::OnlineBankingFpx { .. }- | BankRedirectData::OnlineBankingThailand { .. }- | BankRedirectData::OpenBankingUk { .. }- | BankRedirectData::LocalBankRedirect {} => {- Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("nuvei"),- )- .into())- }- },- PaymentMethodData::PayLater(pay_later_data) => match pay_later_data {- PayLaterData::KlarnaRedirect { .. } => {- get_pay_later_info(AlternativePaymentMethodType::Klarna, item)- }- PayLaterData::AfterpayClearpayRedirect { .. } => {- get_pay_later_info(AlternativePaymentMethodType::AfterPay, item)- }- PayLaterData::KlarnaSdk { .. }- | PayLaterData::FlexitiRedirect {}- | PayLaterData::AffirmRedirect {}- | PayLaterData::PayBrightRedirect {}- | PayLaterData::WalleyRedirect {}- | PayLaterData::AlmaRedirect {}- | PayLaterData::AtomeRedirect {}- | PayLaterData::BreadpayRedirect {}- | PayLaterData::PayjustnowRedirect {} => {- Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("nuvei"),- )- .into())- }- },- PaymentMethodData::BankDebit(_)- | PaymentMethodData::BankTransfer(_)- | PaymentMethodData::Crypto(_)- | PaymentMethodData::Reward- | PaymentMethodData::RealTimePayment(_)- | PaymentMethodData::MobilePayment(_)- | PaymentMethodData::Upi(_)- | PaymentMethodData::Voucher(_)- | PaymentMethodData::CardRedirect(_)- | PaymentMethodData::GiftCard(_)- | PaymentMethodData::OpenBanking(_)- | PaymentMethodData::CardToken(_)- | PaymentMethodData::NetworkToken(_) => Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("nuvei"),- )- .into()),- }?;- let currency = item.request.get_currency_required()?;- let request = Self::try_from(NuveiPaymentRequestData {- amount: convert_amount(- NUVEI_AMOUNT_CONVERTOR,- item.request.get_minor_amount_required()?,- currency,- )?,- currency,+ fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {+ Self::try_from(NuveiPaymentRequestData {+ client_request_id: item.connector_request_reference_id.clone(),+ client_unique_id: item.connector_request_reference_id.clone(),connector_auth_type: item.connector_auth_type.clone(),+ amount: item+ .request+ .minor_amount_to_capture+ .to_nuvei_amount(item.request.currency)?,+ currency: item.request.currency,+ related_transaction_id: Some(item.request.connector_transaction_id.clone()),+ ..Default::default()+ })+ }+}+impl TryFrom<&types::RefundExecuteRouterData> for NuveiPaymentFlowRequest {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(item: &types::RefundExecuteRouterData) -> Result<Self, Self::Error> {+ Self::try_from(NuveiPaymentRequestData {client_request_id: item.connector_request_reference_id.clone(),- session_token: Secret::new(data.1),- capture_method: item.request.get_capture_method(),-+ client_unique_id: item.connector_request_reference_id.clone(),+ connector_auth_type: item.connector_auth_type.clone(),+ amount: item+ .request+ .minor_refund_amount+ .to_nuvei_amount(item.request.currency)?,+ currency: item.request.currency,+ related_transaction_id: Some(item.request.connector_transaction_id.clone()),..Default::default()- })?;- let return_url = item.request.get_return_url_required()?;-- let amount_details = get_amount_details(&item.l2_l3_data, currency)?;- let l2_l3_items: Option<Vec<NuveiItem>> = get_l2_l3_items(&item.l2_l3_data, currency)?;- let address = {- let mut billing_address = item.get_billing()?.clone();- item.get_billing_first_name()?;- billing_address.email = match item.get_billing_email() {- Ok(email) => Some(email),- Err(_) => Some(item.request.get_email_required()?),- };- item.get_billing_country()?;- Some(billing_address)- };-- let shipping_address: Option<ShippingAddress> =- item.get_optional_shipping().map(|address| address.into());+ })+ }+}- let billing_address: Option<BillingAddress> =- address.clone().map(|ref address| address.into());- let device_details = if request_data- .device_details- .ip_address+impl TryFrom<&types::PaymentsSyncRouterData> for NuveiPaymentSyncRequest {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(value: &types::PaymentsSyncRouterData) -> Result<Self, Self::Error> {+ let connector_meta: NuveiAuthType = NuveiAuthType::try_from(&value.connector_auth_type)?;+ let merchant_id = connector_meta.merchant_id.clone();+ let merchant_site_id = connector_meta.merchant_site_id.clone();+ let merchant_secret = connector_meta.merchant_secret.clone();+ let time_stamp =+ date_time::format_date(date_time::now(), date_time::DateFormat::YYYYMMDDHHmmss)+ .change_context(errors::ConnectorError::RequestEncodingFailed)?;+ let client_unique_id = value.connector_request_reference_id.clone();+ let transaction_id = value+ .request+ .connector_transaction_id.clone()- .expose()- .is_empty()- {- DeviceDetails::foreign_try_from(&item.request.get_browser_info())?- } else {- request_data.device_details.clone()- };-- let dynamic_descriptor = item.request.get_dynamic_descriptor()?;+ .get_connector_transaction_id()+ .change_context(errors::ConnectorError::MissingConnectorTransactionID)?;+ let checksum = Secret::new(encode_payload(&[+ merchant_id.peek(),+ merchant_site_id.peek(),+ &transaction_id,+ &client_unique_id,+ &time_stamp,+ merchant_secret.peek(),+ ])?);Ok(Self {- is_rebilling: request_data.is_rebilling,- user_token_id: request_data.user_token_id,- related_transaction_id: request_data.related_transaction_id,- payment_option: request_data.payment_option,- billing_address,- shipping_address,- device_details,- url_details: Some(UrlDetails {- success_url: return_url.clone(),- failure_url: return_url.clone(),- pending_url: return_url.clone(),- }),- amount_details,- items: l2_l3_items,- is_partial_approval: item.request.get_is_partial_approval(),- external_scheme_details: request_data.external_scheme_details,- dynamic_descriptor,- ..request- })- }-}--fn get_card_info<F, Req>(- item: &RouterData<F, Req, PaymentsResponseData>,- card_details: &payment_method_data::Card,-) -> Result<NuveiPaymentsRequest, error_stack::Report<errors::ConnectorError>>-where- Req: NuveiAuthorizePreprocessingCommon,-{- let browser_information = item.request.get_browser_info().clone();- let related_transaction_id = if item.is_three_ds() {- item.request.get_related_transaction_id().clone()- } else {- None- };-- let address: Option<&AddressDetails> = item- .get_optional_billing()- .and_then(|billing_details| billing_details.address.as_ref());-- if let Some(address) = address {- // mandatory fields check- address.get_first_name()?;- item.request.get_email_required()?;- item.get_billing_country()?;- }-- let (is_rebilling, additional_params, user_token_id) =- match item.request.is_customer_initiated_mandate_payment() {- true => {- (- Some(IsRebilling::False), // In case of first installment, rebilling should be 0- Some(V2AdditionalParams {- rebill_expiry: Some(- time::OffsetDateTime::now_utc()- .replace_year(time::OffsetDateTime::now_utc().year() + 5)- .map_err(|_| errors::ConnectorError::DateFormattingFailed)?- .date()- .format(&time::macros::format_description!("[year][month][day]"))- .map_err(|_| errors::ConnectorError::DateFormattingFailed)?,- ),- rebill_frequency: Some("0".to_string()),- challenge_window_size: Some(CHALLENGE_WINDOW_SIZE.to_string()),- challenge_preference: Some(CHALLENGE_PREFERENCE.to_string()),- }),- item.request.get_customer_id_optional(),- )- }- // non mandate transactions- false => (- None,- Some(V2AdditionalParams {- rebill_expiry: None,- rebill_frequency: None,- challenge_window_size: Some(CHALLENGE_WINDOW_SIZE.to_string()),- challenge_preference: Some(CHALLENGE_PREFERENCE.to_string()),- }),- None,- ),- };- let three_d = if let Some(auth_data) = item.request.get_auth_data()? {- Some(ThreeD {- external_mpi: Some(ExternalMpi {- eci: auth_data.eci,- cavv: auth_data.cavv,- ds_trans_id: auth_data.ds_trans_id,- challenge_preference: None,- exemption_request_reason: None,- }),- ..Default::default()- })- } else if item.is_three_ds() {- let browser_details = match &browser_information {- Some(browser_info) => Some(BrowserDetails {- accept_header: browser_info.get_accept_header()?,- ip: browser_info.get_ip_address()?,- java_enabled: browser_info.get_java_enabled()?.to_string().to_uppercase(),- java_script_enabled: browser_info- .get_java_script_enabled()?- .to_string()- .to_uppercase(),- language: browser_info.get_language()?,- screen_height: browser_info.get_screen_height()?,- screen_width: browser_info.get_screen_width()?,- color_depth: browser_info.get_color_depth()?,- user_agent: browser_info.get_user_agent()?,- time_zone: browser_info.get_time_zone()?,- }),- None => None,- };- Some(ThreeD {- browser_details,- v2_additional_params: additional_params,- notification_url: item.request.get_complete_authorize_url().clone(),- merchant_url: Some(item.request.get_return_url_required()?),- platform_type: Some(PlatformType::Browser),- method_completion_ind: Some(MethodCompletion::Unavailable),- ..Default::default()- })- } else {- None- };- let is_moto = item.request.get_is_moto();- Ok(NuveiPaymentsRequest {- related_transaction_id,- is_rebilling,- user_token_id,- device_details: DeviceDetails::foreign_try_from(&item.request.get_browser_info().clone())?,- payment_option: PaymentOption::from(NuveiCardDetails {- card: card_details.clone(),- three_d,- card_holder_name: item.get_optional_billing_full_name(),- stored_credentials: item.request.get_is_stored_credential(),- }),- is_moto,- ..Default::default()- })-}-impl From<NuveiCardDetails> for PaymentOption {- fn from(card_details: NuveiCardDetails) -> Self {- let card = card_details.card;- Self {- card: Some(Card {- card_number: Some(card.card_number),- card_holder_name: card_details.card_holder_name,- expiration_month: Some(card.card_exp_month),- expiration_year: Some(card.card_exp_year),- three_d: card_details.three_d,- cvv: Some(card.card_cvc),- stored_credentials: card_details.stored_credentials,- ..Default::default()- }),- ..Default::default()- }- }-}--impl TryFrom<(&types::PaymentsCompleteAuthorizeRouterData, Secret<String>)>- for NuveiPaymentsRequest-{- type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(- data: (&types::PaymentsCompleteAuthorizeRouterData, Secret<String>),- ) -> Result<Self, Self::Error> {- let item = data.0;- let request_data = match item.request.payment_method_data.clone() {- Some(PaymentMethodData::Card(card)) => {- let device_details = DeviceDetails::foreign_try_from(&item.request.browser_info)?;- Ok(Self {- payment_option: PaymentOption::from(NuveiCardDetails {- card,- three_d: None,- card_holder_name: item.get_optional_billing_full_name(),- stored_credentials: StoredCredentialMode::get_optional_stored_credential(- item.request.is_stored_credential,- ),- }),- device_details,- ..Default::default()- })- }- _ => Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("nuvei"),- )),- }?;- let request = Self::try_from(NuveiPaymentRequestData {- amount: convert_amount(- NUVEI_AMOUNT_CONVERTOR,- item.request.minor_amount,- item.request.currency,- )?,- currency: item.request.currency,- connector_auth_type: item.connector_auth_type.clone(),- client_request_id: item.connector_request_reference_id.clone(),- session_token: data.1,- capture_method: item.request.capture_method,- ..Default::default()- })?;- Ok(Self {- related_transaction_id: item.request.connector_transaction_id.clone(),- payment_option: request_data.payment_option,- device_details: request_data.device_details,- ..request- })- }-}--impl TryFrom<NuveiPaymentRequestData> for NuveiPaymentsRequest {- type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(request: NuveiPaymentRequestData) -> Result<Self, Self::Error> {- let session_token = request.session_token;- fp_utils::when(session_token.clone().expose().is_empty(), || {- Err(errors::ConnectorError::FailedToObtainAuthType)- })?;- let connector_meta: NuveiAuthType = NuveiAuthType::try_from(&request.connector_auth_type)?;- let merchant_id = connector_meta.merchant_id;- let merchant_site_id = connector_meta.merchant_site_id;- let client_request_id = request.client_request_id;- let time_stamp =- date_time::format_date(date_time::now(), date_time::DateFormat::YYYYMMDDHHmmss)- .change_context(errors::ConnectorError::RequestEncodingFailed)?;- let merchant_secret = connector_meta.merchant_secret;- let transaction_type = TransactionType::get_from_capture_method_and_amount_string(- request.capture_method.unwrap_or_default(),- &request.amount.get_amount_as_string(),- );- Ok(Self {- merchant_id: merchant_id.clone(),- merchant_site_id: merchant_site_id.clone(),- client_request_id: Secret::new(client_request_id.clone()),- time_stamp: time_stamp.clone(),- session_token,- transaction_type,- checksum: Secret::new(encode_payload(&[- merchant_id.peek(),- merchant_site_id.peek(),- &client_request_id,- &request.amount.get_amount_as_string(),- &request.currency.to_string(),- &time_stamp,- merchant_secret.peek(),- ])?),- amount: request.amount,- user_token_id: None,- currency: request.currency,- ..Default::default()- })- }-}--impl TryFrom<NuveiPaymentRequestData> for NuveiPaymentFlowRequest {- type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(request: NuveiPaymentRequestData) -> Result<Self, Self::Error> {- let connector_meta: NuveiAuthType = NuveiAuthType::try_from(&request.connector_auth_type)?;- let merchant_id = connector_meta.merchant_id;- let merchant_site_id = connector_meta.merchant_site_id;- let client_request_id = request.client_request_id;- let time_stamp =- date_time::format_date(date_time::now(), date_time::DateFormat::YYYYMMDDHHmmss)- .change_context(errors::ConnectorError::RequestEncodingFailed)?;- let merchant_secret = connector_meta.merchant_secret;- Ok(Self {- merchant_id: merchant_id.to_owned(),- merchant_site_id: merchant_site_id.to_owned(),- client_request_id: client_request_id.clone(),- time_stamp: time_stamp.clone(),- checksum: Secret::new(encode_payload(&[- merchant_id.peek(),- merchant_site_id.peek(),- &client_request_id,- &request.amount.get_amount_as_string(),- &request.currency.to_string(),- &request.related_transaction_id.clone().unwrap_or_default(),- &time_stamp,- merchant_secret.peek(),- ])?),- amount: request.amount,- currency: request.currency,- related_transaction_id: request.related_transaction_id,- })- }-}--#[derive(Debug, Clone, Default)]-pub struct NuveiPaymentRequestData {- pub amount: StringMajorUnit,- pub currency: enums::Currency,- pub related_transaction_id: Option<String>,- pub client_request_id: String,- pub connector_auth_type: ConnectorAuthType,- pub session_token: Secret<String>,- pub capture_method: Option<CaptureMethod>,-}--impl TryFrom<&types::PaymentsCaptureRouterData> for NuveiPaymentFlowRequest {- type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {- Self::try_from(NuveiPaymentRequestData {- client_request_id: item.connector_request_reference_id.clone(),- connector_auth_type: item.connector_auth_type.clone(),- amount: convert_amount(- NUVEI_AMOUNT_CONVERTOR,- item.request.minor_amount_to_capture,- item.request.currency,- )?,- currency: item.request.currency,- related_transaction_id: Some(item.request.connector_transaction_id.clone()),- ..Default::default()- })- }-}-impl TryFrom<&types::RefundExecuteRouterData> for NuveiPaymentFlowRequest {- type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(item: &types::RefundExecuteRouterData) -> Result<Self, Self::Error> {- Self::try_from(NuveiPaymentRequestData {- client_request_id: item.connector_request_reference_id.clone(),- connector_auth_type: item.connector_auth_type.clone(),- amount: convert_amount(- NUVEI_AMOUNT_CONVERTOR,- item.request.minor_refund_amount,- item.request.currency,- )?,- currency: item.request.currency,- related_transaction_id: Some(item.request.connector_transaction_id.clone()),- ..Default::default()- })- }-}--impl TryFrom<&types::PaymentsSyncRouterData> for NuveiPaymentSyncRequest {- type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(value: &types::PaymentsSyncRouterData) -> Result<Self, Self::Error> {- let connector_meta: NuveiAuthType = NuveiAuthType::try_from(&value.connector_auth_type)?;- let merchant_id = connector_meta.merchant_id.clone();- let merchant_site_id = connector_meta.merchant_site_id.clone();- let merchant_secret = connector_meta.merchant_secret.clone();- let time_stamp =- date_time::format_date(date_time::now(), date_time::DateFormat::YYYYMMDDHHmmss)- .change_context(errors::ConnectorError::RequestEncodingFailed)?;- let transaction_id = value- .request- .connector_transaction_id- .clone()- .get_connector_transaction_id()- .change_context(errors::ConnectorError::MissingConnectorTransactionID)?;- let checksum = Secret::new(encode_payload(&[- merchant_id.peek(),- merchant_site_id.peek(),- &transaction_id,- &time_stamp,- merchant_secret.peek(),- ])?);-- Ok(Self {- merchant_id,- merchant_site_id,- time_stamp,- checksum,- transaction_id,+ merchant_id,+ merchant_site_id,+ client_unique_id,+ time_stamp,+ checksum,+ transaction_id,})}}@@ -2452,14 +1397,13 @@ impl TryFrom<&types::PaymentsCancelRouterData> for NuveiPaymentFlowRequest {fn try_from(item: &types::PaymentsCancelRouterData) -> Result<Self, Self::Error> {Self::try_from(NuveiPaymentRequestData {client_request_id: item.connector_request_reference_id.clone(),+ client_unique_id: item.connector_request_reference_id.clone(),connector_auth_type: item.connector_auth_type.clone(),- amount: convert_amount(- NUVEI_AMOUNT_CONVERTOR,- item.request- .minor_amount- .ok_or_else(missing_field_err("amount"))?,- item.request.get_currency()?,- )?,+ amount: item+ .request+ .minor_amount+ .ok_or_else(missing_field_err("amount"))?+ .to_nuvei_amount(item.request.get_currency()?)?,currency: item.request.get_currency()?,related_transaction_id: Some(item.request.connector_transaction_id.clone()),..Default::default()@@ -2591,11 +1535,10 @@ impl<F> TryFrom<&types::PayoutsRouterData<F>> for NuveiPayoutRequest {fn try_from(item: &types::PayoutsRouterData<F>) -> Result<Self, Self::Error> {let connector_auth: NuveiAuthType = NuveiAuthType::try_from(&item.connector_auth_type)?;- let amount = convert_amount(- NUVEI_AMOUNT_CONVERTOR,- item.request.minor_amount,- item.request.destination_currency,- )?;+ let amount = item+ .request+ .minor_amount+ .to_nuvei_amount(item.request.destination_currency)?;let time_stamp =date_time::format_date(date_time::now(), date_time::DateFormat::YYYYMMDDHHmmss)@@ -2768,23 +1711,18 @@ pub struct NuveiPaymentsResponse {pub issuer_decline_reason: Option<String>,pub transaction_type: Option<NuveiTransactionType>,pub transaction_id: Option<String>,- pub external_transaction_id: Option<String>,pub auth_code: Option<String>,- pub custom_data: Option<String>,- pub fraud_details: Option<FraudDetails>,// NTIDpub external_scheme_transaction_id: Option<Secret<String>>,pub session_token: Option<Secret<String>>,pub partial_approval: Option<NuveiPartialApproval>,//The ID of the transaction in the merchant’s system.pub client_unique_id: Option<String>,- pub internal_request_id: Option<i64>,pub status: NuveiPaymentStatus,pub err_code: Option<i64>,pub reason: Option<String>,pub merchant_id: Option<Secret<String>>,pub merchant_site_id: Option<Secret<String>>,- pub version: Option<String>,pub client_request_id: Option<String>,pub merchant_advice_code: Option<String>,}@@ -2816,18 +1754,14 @@ pub struct NuveiTransactionSyncResponseDetails {pub struct NuveiTransactionSyncResponse {pub payment_option: Option<PaymentOption>,pub partial_approval: Option<NuveiTxnPartialApproval>,- pub is_currency_converted: Option<bool>,pub transaction_details: Option<NuveiTransactionSyncResponseDetails>,- pub fraud_details: Option<FraudDetails>,pub client_unique_id: Option<String>,- pub internal_request_id: Option<i64>,// API response statuspub status: NuveiPaymentStatus,pub err_code: Option<i64>,pub reason: Option<String>,pub merchant_id: Option<Secret<String>>,pub merchant_site_id: Option<Secret<String>>,- pub version: Option<String>,pub client_request_id: Option<String>,pub merchant_advice_code: Option<String>,}@@ -2869,7 +1803,7 @@ pub fn get_amount_captured(match partial_approval_data {Some(partial_approval) => {let amount = utils::convert_back_amount_to_minor_units(- NUVEI_AMOUNT_CONVERTOR,+ &StringMajorUnitForConnector,partial_approval.processed_amount.clone(),partial_approval.processed_currency,)?;@@ -2903,12 +1837,6 @@ pub enum NuveiTransactionType {Void,}-#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct FraudDetails {- pub final_decision: String,-}-fn get_payment_status(amount: Option<i64>,is_post_capture_void: bool,@@ -3634,40 +2562,29 @@ whereReq: NuveiAuthorizePreprocessingCommon,{type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(data: &RouterData<F, Req, PaymentsResponseData>) -> Result<Self, Self::Error> {+ fn try_from(item: &RouterData<F, Req, PaymentsResponseData>) -> Result<Self, Self::Error> {{- let item = data;- let connector_mandate_id = &item.request.get_connector_mandate_id();- let customer_id = item- .request- .get_customer_id_optional()- .ok_or(missing_field_err("customer_id")())?;- let related_transaction_id = item.request.get_related_transaction_id().clone();-- let ip_address = data- .recurring_mandate_payment_data- .as_ref()- .and_then(|r| r.mandate_metadata.as_ref())- .ok_or(errors::ConnectorError::MissingRequiredField {- field_name: "browser_info.ip_address",- })?- .clone()- .expose()- .as_str()- .ok_or(errors::ConnectorError::MissingRequiredField {- field_name: "browser_info.ip_address",- })?- .to_owned();-Ok(Self {- related_transaction_id,+ related_transaction_id: item.request.get_related_transaction_id().clone(),device_details: DeviceDetails {- ip_address: Secret::new(ip_address),+ ip_address: Secret::new(+ item.recurring_mandate_payment_data+ .as_ref()+ .and_then(|r| r.mandate_metadata.as_ref())+ .ok_or(errors::ConnectorError::MissingRequiredField {+ field_name: "browser_info.ip_address",+ })?+ .clone()+ .expose()+ .as_str()+ .ok_or(errors::ConnectorError::MissingRequiredField {+ field_name: "browser_info.ip_address",+ })?+ .to_owned(),+ ),},- is_rebilling: Some(IsRebilling::True), // In case of second installment, rebilling should be 1- user_token_id: Some(customer_id),payment_option: PaymentOption {- user_payment_option_id: connector_mandate_id.clone(),+ user_payment_option_id: item.request.get_connector_mandate_id().clone(),..Default::default()},..Default::default()@@ -3693,37 +2610,32 @@ fn get_refund_response(http_code: u16,txn_id: String,) -> Result<RefundsResponseData, Box<ErrorResponse>> {- let refund_status = response- .transaction_status- .clone()- .map(enums::RefundStatus::from)- .unwrap_or(enums::RefundStatus::Failure);- match response.status {- NuveiPaymentStatus::Error => Err(Box::new(get_error_response(+ // Check if either status or transaction_status indicates an error+ if matches!(response.status, NuveiPaymentStatus::Error)+ || matches!(+ response.transaction_status,+ Some(NuveiTransactionStatus::Error)+ )+ {+ return Err(Box::new(get_error_response(response.err_code,response.reason.clone(),http_code,response.merchant_advice_code,response.gw_error_code.map(|e| e.to_string()),response.gw_error_reason,- Some(txn_id.clone()),- ))),- _ => match response.transaction_status {- Some(NuveiTransactionStatus::Error) => Err(Box::new(get_error_response(- response.err_code,- response.reason,- http_code,- response.merchant_advice_code,- response.gw_error_code.map(|e| e.to_string()),- response.gw_error_reason,- Some(txn_id.clone()),- ))),- _ => Ok(RefundsResponseData {- connector_refund_id: txn_id,- refund_status,- }),- },+ Some(txn_id),+ )));}+ let refund_status = response+ .transaction_status+ .clone()+ .map(enums::RefundStatus::from)+ .unwrap_or(enums::RefundStatus::Failure);+ Ok(RefundsResponseData {+ connector_refund_id: txn_id,+ refund_status,+ })}fn get_error_response(@@ -3791,7 +2703,6 @@ pub struct ChargebackNotification {pub chargeback: ChargebackData,pub transaction_details: ChargebackTransactionDetails,pub event_id: Option<String>,- pub event_date: Option<String>,pub processing_entity_type: Option<String>,pub processing_entity_id: Option<i64>,}@@ -4069,8 +2980,6 @@ pub struct PaymentDmnNotification {pub payment_method: Option<String>,#[serde(rename = "responseTimeStamp")]pub response_time_stamp: String,- #[serde(rename = "invoice_id")]- pub invoice_id: Option<String>,#[serde(rename = "merchant_id")]pub merchant_id: Option<Secret<String>>,#[serde(rename = "merchant_site_id")]@@ -4464,3 +3373,681 @@ fn bypass_error_for_no_payments_found(err_code: Option<i64>) -> bool {_ => false,}}++impl TryFrom<BrowserInformation> for BrowserDetails {+ type Error = error_stack::Report<errors::ConnectorError>;++ fn try_from(browser_info: BrowserInformation) -> Result<Self, Self::Error> {+ Ok(Self {+ accept_header: browser_info.get_accept_header()?,+ ip: browser_info.get_ip_address()?,+ java_enabled: browser_info.get_java_enabled()?.to_string().to_uppercase(),+ java_script_enabled: browser_info+ .get_java_script_enabled()?+ .to_string()+ .to_uppercase(),+ language: browser_info.get_language()?,+ screen_height: browser_info.get_screen_height()?,+ screen_width: browser_info.get_screen_width()?,+ color_depth: browser_info.get_color_depth()?,+ user_agent: browser_info.get_user_agent()?,+ time_zone: browser_info.get_time_zone()?,+ })+ }+}+trait NuveiAmountExt {+ fn to_nuvei_amount(+ &self,+ currency: enums::Currency,+ ) -> Result<StringMajorUnit, error_stack::Report<errors::ConnectorError>>;+}++impl NuveiAmountExt for MinorUnit {+ fn to_nuvei_amount(+ &self,+ currency: enums::Currency,+ ) -> Result<StringMajorUnit, error_stack::Report<errors::ConnectorError>> {+ convert_amount(&StringMajorUnitForConnector, *self, currency)+ }+}+#[derive(Debug, Clone, Serialize)]+#[serde(rename_all = "UPPERCASE")]+pub enum NuveiCardType {+ Visa,+ MasterCard,+ AmericanExpress,+ Discover,+ DinersClub,+ Interac,+ JCB,+ UnionPay,+ CartesBancaires,+}++impl TryFrom<common_enums::CardNetwork> for NuveiCardType {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(card_network: common_enums::CardNetwork) -> Result<Self, Self::Error> {+ match card_network {+ common_enums::CardNetwork::Visa => Ok(Self::Visa),+ common_enums::CardNetwork::Mastercard => Ok(Self::MasterCard),+ common_enums::CardNetwork::AmericanExpress => Ok(Self::AmericanExpress),+ common_enums::CardNetwork::Discover => Ok(Self::Discover),+ common_enums::CardNetwork::DinersClub => Ok(Self::DinersClub),+ common_enums::CardNetwork::JCB => Ok(Self::JCB),+ common_enums::CardNetwork::UnionPay => Ok(Self::UnionPay),+ common_enums::CardNetwork::CartesBancaires => Ok(Self::CartesBancaires),+ common_enums::CardNetwork::Interac => Ok(Self::Interac),+ _ => Err(errors::ConnectorError::NotSupported {+ message: "Card network".to_string(),+ connector: "nuvei",+ }+ .into()),+ }+ }+}++impl TryFrom<&utils::CardIssuer> for NuveiCardType {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(card_issuer: &utils::CardIssuer) -> Result<Self, Self::Error> {+ match card_issuer {+ utils::CardIssuer::Visa => Ok(Self::Visa),+ utils::CardIssuer::Master => Ok(Self::MasterCard),+ utils::CardIssuer::AmericanExpress => Ok(Self::AmericanExpress),+ utils::CardIssuer::Discover => Ok(Self::Discover),+ utils::CardIssuer::DinersClub => Ok(Self::DinersClub),+ utils::CardIssuer::JCB => Ok(Self::JCB),+ utils::CardIssuer::CartesBancaires => Ok(Self::CartesBancaires),+ &utils::CardIssuer::UnionPay => Ok(Self::UnionPay),+ _ => Err(errors::ConnectorError::NotSupported {+ message: "Card network".to_string(),+ connector: "nuvei",+ }+ .into()),+ }+ }+}++#[derive(Debug, Clone, Default, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct StoredCredentialMode {+ pub stored_credentials_mode: Option<StoredCredentialModeType>,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+pub enum StoredCredentialModeType {+ #[serde(rename = "0")]+ First,+ #[serde(rename = "1")]+ Used,+}++impl StoredCredentialMode {+ pub fn get_optional_stored_credential(is_stored_credential: Option<bool>) -> Option<Self> {+ is_stored_credential.and_then(|is_stored_credential| {+ if is_stored_credential {+ Some(Self {+ stored_credentials_mode: Some(StoredCredentialModeType::Used),+ })+ } else {+ None+ }+ })+ }+}+#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]+pub enum IsRebilling {+ #[serde(rename = "1")]+ True,+ #[serde(rename = "0")]+ False,+}+#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]+#[serde(rename_all = "UPPERCASE")]+pub enum PartialApprovalFlag {+ #[serde(rename = "1")]+ Enabled,+ #[serde(rename = "0")]+ Disabled,+}++impl From<primitive_wrappers::EnablePartialAuthorizationBool> for PartialApprovalFlag {+ fn from(value: primitive_wrappers::EnablePartialAuthorizationBool) -> Self {+ if value.is_true() {+ Self::Enabled+ } else {+ Self::Disabled+ }+ }+}++trait NuveiAuthorizePreprocessingCommon {+ fn get_browser_info(&self) -> Option<BrowserInformation>;+ fn get_complete_authorize_url(&self) -> Option<String>;+ fn get_related_transaction_id(&self) -> Option<String> {+ None+ }+ fn get_billing_descriptor(&self) -> Option<&BillingDescriptor> {+ None+ }+ fn get_auth_data(+ &self,+ ) -> Result<Option<AuthenticationData>, error_stack::Report<errors::ConnectorError>> {+ Ok(None)+ }+ fn get_is_partial_approval(&self) -> Option<PartialApprovalFlag> {+ None+ }+ fn get_is_moto(&self) -> Option<bool> {+ None+ }+ fn get_ntid(&self) -> Option<String> {+ None+ }+ fn get_connector_mandate_id(&self) -> Option<String> {+ None+ }+ fn get_return_url_required(+ &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_email_required(&self) -> Result<Email, error_stack::Report<errors::ConnectorError>>;+ fn get_currency(&self) -> enums::Currency;+ fn get_payment_method_data_required(+ &self,+ ) -> Result<PaymentMethodData, error_stack::Report<errors::ConnectorError>>;++ fn is_customer_initiated_mandate_payment(&self) -> bool;++ fn get_is_stored_credential(&self) -> Option<StoredCredentialMode>;++ fn get_dynamic_descriptor(+ &self,+ ) -> Result<Option<NuveiDynamicDescriptor>, error_stack::Report<errors::ConnectorError>> {+ if let Some(descriptor) = self.get_billing_descriptor() {+ if let Some(phone) = descriptor.phone.as_ref() {+ if phone.clone().expose().len() > 13 {+ return Err(errors::ConnectorError::MaxFieldLengthViolated {+ connector: "Nuvei".to_string(),+ field_name: "dynamic_descriptor.merchant_phone".to_string(),+ max_length: 13,+ received_length: phone.clone().expose().len(),+ }+ .into());+ }+ }++ let dynamic_descriptor = NuveiDynamicDescriptor {+ merchant_name: descriptor.name.as_ref().map(|name| {+ Secret::new(name.clone().expose().trim().chars().take(25).collect())+ }),+ merchant_phone: descriptor.phone.clone(),+ };++ Ok(Some(dynamic_descriptor))+ } else {+ Ok(None)+ }+ }+}+impl NuveiAuthorizePreprocessingCommon for CompleteAuthorizeData {+ fn get_currency(&self) -> enums::Currency {+ self.currency+ }+ fn get_return_url_required(+ &self,+ ) -> Result<String, error_stack::Report<errors::ConnectorError>> {+ self.get_router_return_url()+ }++ fn get_minor_amount_required(+ &self,+ ) -> Result<MinorUnit, error_stack::Report<errors::ConnectorError>> {+ Ok(self.minor_amount)+ }++ fn get_payment_method_data_required(+ &self,+ ) -> Result<PaymentMethodData, error_stack::Report<errors::ConnectorError>> {+ self.payment_method_data+ .clone()+ .ok_or_else(missing_field_err("payment_method_data"))+ }++ fn is_customer_initiated_mandate_payment(&self) -> bool {+ self.mandate_id.is_some()+ }++ fn get_capture_method(&self) -> Option<CaptureMethod> {+ self.capture_method+ }++ fn get_email_required(&self) -> Result<Email, error_stack::Report<errors::ConnectorError>> {+ self.email.clone().ok_or_else(missing_field_err("email"))+ }++ fn get_browser_info(&self) -> Option<BrowserInformation> {+ self.browser_info.clone()+ }++ fn get_complete_authorize_url(&self) -> Option<String> {+ self.complete_authorize_url.clone()+ }++ fn get_is_stored_credential(&self) -> Option<StoredCredentialMode> {+ StoredCredentialMode::get_optional_stored_credential(self.is_stored_credential)+ }+}+impl NuveiAuthorizePreprocessingCommon for SetupMandateRequestData {+ fn get_browser_info(&self) -> Option<BrowserInformation> {+ self.browser_info.clone()+ }+ fn get_billing_descriptor(&self) -> Option<&BillingDescriptor> {+ self.billing_descriptor.as_ref()+ }++ fn get_related_transaction_id(&self) -> Option<String> {+ self.related_transaction_id.clone()+ }+ fn get_is_moto(&self) -> Option<bool> {+ match self.payment_channel {+ Some(PaymentChannel::MailOrder) | Some(PaymentChannel::TelephoneOrder) => Some(true),+ _ => None,+ }+ }+ fn get_complete_authorize_url(&self) -> Option<String> {+ self.complete_authorize_url.clone()+ }++ fn get_connector_mandate_id(&self) -> Option<String> {+ self.mandate_id.as_ref().and_then(|mandate_ids| {+ mandate_ids.mandate_reference_id.as_ref().and_then(+ |mandate_ref_id| match mandate_ref_id {+ api_models::payments::MandateReferenceId::ConnectorMandateId(id) => {+ id.get_connector_mandate_id()+ }+ _ => None,+ },+ )+ })+ }++ fn get_return_url_required(+ &self,+ ) -> Result<String, error_stack::Report<errors::ConnectorError>> {+ self.get_router_return_url()+ }++ fn get_capture_method(&self) -> Option<CaptureMethod> {+ self.capture_method+ }+ fn get_currency(&self) -> enums::Currency {+ self.currency+ }+ fn get_payment_method_data_required(+ &self,+ ) -> Result<PaymentMethodData, error_stack::Report<errors::ConnectorError>> {+ Ok(self.payment_method_data.clone())+ }++ fn get_minor_amount_required(+ &self,+ ) -> Result<MinorUnit, error_stack::Report<errors::ConnectorError>> {+ self.minor_amount+ .ok_or_else(missing_field_err("minor_amount"))+ }++ fn get_is_partial_approval(&self) -> Option<PartialApprovalFlag> {+ self.enable_partial_authorization+ .map(PartialApprovalFlag::from)+ }++ fn get_email_required(&self) -> Result<Email, error_stack::Report<errors::ConnectorError>> {+ self.email.clone().ok_or_else(missing_field_err("email"))+ }+ fn is_customer_initiated_mandate_payment(&self) -> bool {+ (self.customer_acceptance.is_some() || self.setup_mandate_details.is_some())+ && self.setup_future_usage == Some(FutureUsage::OffSession)+ }+ fn get_is_stored_credential(&self) -> Option<StoredCredentialMode> {+ StoredCredentialMode::get_optional_stored_credential(self.is_stored_credential)+ }+}++impl NuveiAuthorizePreprocessingCommon for PaymentsAuthorizeData {+ fn get_browser_info(&self) -> Option<BrowserInformation> {+ self.browser_info.clone()+ }+ fn get_billing_descriptor(&self) -> Option<&BillingDescriptor> {+ self.billing_descriptor.as_ref()+ }+ fn get_ntid(&self) -> Option<String> {+ self.get_optional_network_transaction_id()+ }+ fn get_related_transaction_id(&self) -> Option<String> {+ self.related_transaction_id.clone()+ }+ fn get_is_moto(&self) -> Option<bool> {+ match self.payment_channel {+ Some(PaymentChannel::MailOrder) | Some(PaymentChannel::TelephoneOrder) => Some(true),+ _ => None,+ }+ }+ fn get_auth_data(+ &self,+ ) -> Result<Option<AuthenticationData>, error_stack::Report<errors::ConnectorError>> {+ Ok(self.authentication_data.clone())+ }+ fn get_connector_mandate_id(&self) -> Option<String> {+ self.connector_mandate_id().clone()+ }++ fn get_return_url_required(+ &self,+ ) -> Result<String, error_stack::Report<errors::ConnectorError>> {+ self.get_router_return_url()+ }++ fn get_capture_method(&self) -> Option<CaptureMethod> {+ self.capture_method+ }++ fn get_complete_authorize_url(&self) -> Option<String> {+ self.complete_authorize_url.clone()+ }++ fn get_minor_amount_required(+ &self,+ ) -> Result<MinorUnit, error_stack::Report<errors::ConnectorError>> {+ Ok(self.minor_amount)+ }++ fn get_currency(&self) -> enums::Currency {+ self.currency+ }+ fn get_payment_method_data_required(+ &self,+ ) -> Result<PaymentMethodData, error_stack::Report<errors::ConnectorError>> {+ Ok(self.payment_method_data.clone())+ }++ fn get_email_required(&self) -> Result<Email, error_stack::Report<errors::ConnectorError>> {+ self.get_email()+ }+ fn is_customer_initiated_mandate_payment(&self) -> bool {+ (self.customer_acceptance.is_some() || self.setup_mandate_details.is_some())+ && self.setup_future_usage == Some(FutureUsage::OffSession)+ }+ fn get_is_partial_approval(&self) -> Option<PartialApprovalFlag> {+ self.enable_partial_authorization+ .map(PartialApprovalFlag::from)+ }++ fn get_is_stored_credential(&self) -> Option<StoredCredentialMode> {+ StoredCredentialMode::get_optional_stored_credential(self.is_stored_credential)+ }+}+#[derive(Debug, Serialize, Default, Deserialize)]+pub struct NuveiMeta {+ pub session_token: Secret<String>,+}++#[serde_with::skip_serializing_none]+#[derive(Debug, Serialize, Default)]+#[serde(rename_all = "camelCase")]+pub struct NuveiItem {+ pub name: String,+ #[serde(rename = "type")]+ pub item_type: NuveiItemType,+ pub price: StringMajorUnit,+ pub quantity: String,+ pub group_id: Option<String>,+ pub discount: Option<StringMajorUnit>,+ pub tax: Option<StringMajorUnit>,+ pub tax_rate: Option<String>,+ pub image_url: Option<String>,+}+fn get_l2_l3_items(+ l2_l3_data: &Option<Box<L2L3Data>>,+ currency: enums::Currency,+) -> Result<Option<Vec<NuveiItem>>, error_stack::Report<errors::ConnectorError>> {+ l2_l3_data+ .as_ref()+ .and_then(|data| data.get_order_details())+ .map(|order_details_list| {+ order_details_list+ .iter()+ .map(|order| {+ Ok(NuveiItem {+ name: order.product_name.clone(),+ item_type: order.product_type.clone().into(),+ price: order.amount.to_nuvei_amount(currency)?,+ quantity: order.quantity.to_string(),+ group_id: order.product_id.clone(),+ discount: order+ .unit_discount_amount+ .map(|amount| amount.to_nuvei_amount(currency))+ .transpose()?,+ tax: order+ .total_tax_amount+ .map(|amount| amount.to_nuvei_amount(currency))+ .transpose()?,+ tax_rate: order.tax_rate.map(|rate| rate.to_string()),+ image_url: order.product_img_link.clone(),+ })+ })+ .collect::<Result<Vec<_>, _>>()+ })+ .transpose()+}+fn get_amount_details(+ l2_l3_data: &Option<Box<L2L3Data>>,+ currency: enums::Currency,+) -> Result<Option<NuveiAmountDetails>, error_stack::Report<errors::ConnectorError>> {+ let cv = |a| convert_amount(&StringMajorUnitForConnector, a, currency);+ l2_l3_data+ .as_deref()+ .map(|d| {+ Ok(NuveiAmountDetails {+ total_tax: d.get_order_tax_amount().map(cv).transpose()?,+ total_shipping: d.get_shipping_cost().map(cv).transpose()?,+ total_discount: d.get_discount_amount().map(cv).transpose()?,+ total_handling: d.get_duty_amount().map(cv).transpose()?,+ })+ })+ .transpose()+}+#[derive(Debug, Serialize, Default)]+#[serde(rename_all = "camelCase")]+pub struct NuveiAmountDetails {+ pub total_tax: Option<StringMajorUnit>,+ pub total_shipping: Option<StringMajorUnit>,+ pub total_handling: Option<StringMajorUnit>,+ pub total_discount: Option<StringMajorUnit>,+}++#[derive(Debug, Serialize, Default)]+#[serde(rename_all = "camelCase")]+pub struct UrlDetails {+ pub success_url: String,+ pub failure_url: String,+ pub pending_url: String,+}++#[derive(Debug, Serialize, Deserialize, Clone, Default)]+#[serde(rename_all = "snake_case")]+pub enum NuveiItemType {+ #[default]+ Physical,+ Discount,+ #[serde(rename = "Shipping_fee")]+ ShippingFee,+ Digital,+ #[serde(rename = "Gift_card")]+ GiftCard,+ #[serde(rename = "Store_credit")]+ StoreCredit,+ Surcharge,+ #[serde(rename = "Sales_tax")]+ SalesTax,+}+impl From<Option<enums::ProductType>> for NuveiItemType {+ fn from(value: Option<enums::ProductType>) -> Self {+ match value {+ Some(enums::ProductType::Digital) => Self::Digital,+ Some(enums::ProductType::Physical) => Self::Physical,+ Some(enums::ProductType::Ride)+ | Some(enums::ProductType::Travel)+ | Some(enums::ProductType::Accommodation) => Self::ShippingFee,+ _ => Self::Physical,+ }+ }+}++#[serde_with::skip_serializing_none]+#[derive(Debug, Serialize, Default)]+#[serde(rename_all = "camelCase")]+pub struct NuveiDynamicDescriptor {+ pub merchant_name: Option<Secret<String>>,+ pub merchant_phone: Option<Secret<String>>,+}++#[serde_with::skip_serializing_none]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct BillingAddress {+ pub email: Email,+ pub first_name: Option<Secret<String>>,+ pub last_name: Option<Secret<String>>,+ pub country: api_models::enums::CountryAlpha2,+ pub phone: Option<Secret<String>>,+ pub city: Option<Secret<String>>,+ pub address: Option<Secret<String>>,+ pub zip: Option<Secret<String>>,+ pub state: Option<Secret<String>>,+ pub address_line2: Option<Secret<String>>,+ pub address_line3: Option<Secret<String>>,+}++#[serde_with::skip_serializing_none]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct ShippingAddress {+ pub first_name: Option<Secret<String>>,+ pub last_name: Option<Secret<String>>,+ pub address: Option<Secret<String>>,+ pub phone: Option<Secret<String>>,+ pub zip: Option<Secret<String>>,+ pub city: Option<Secret<String>>,+ pub country: api_models::enums::CountryAlpha2,+ pub email: Email,+ pub address_line2: Option<Secret<String>>,+ pub address_line3: Option<Secret<String>>,+}++impl From<&Address> for BillingAddress {+ fn from(address: &Address) -> Self {+ let address_details = address.address.as_ref();+ Self {+ email: address.email.clone().unwrap_or_default(),+ first_name: address.get_optional_first_name(),+ last_name: address_details.and_then(|address| address.get_optional_last_name()),+ country: address_details+ .and_then(|address| address.get_optional_country())+ .unwrap_or_default(),+ phone: address+ .phone+ .as_ref()+ .and_then(|phone| phone.number.clone()),+ city: address_details+ .and_then(|address| address.get_optional_city().map(|city| city.into())),+ address: address_details.and_then(|address| address.get_optional_line1()),+ zip: address_details.and_then(|details| details.get_optional_zip()),+ state: address_details.and_then(|details| details.to_state_code_as_optional().ok()?),+ address_line2: address_details.and_then(|address| address.get_optional_line2()),+ address_line3: address_details.and_then(|address| address.get_optional_line3()),+ }+ }+}++impl From<&Address> for ShippingAddress {+ fn from(address: &Address) -> Self {+ let address_details = address.address.as_ref();++ Self {+ email: address.email.clone().unwrap_or_default(),+ first_name: address_details.and_then(|details| details.get_optional_first_name()),+ last_name: address_details.and_then(|details| details.get_optional_last_name()),+ country: address_details+ .and_then(|details| details.get_optional_country())+ .unwrap_or_default(),+ phone: address+ .phone+ .as_ref()+ .and_then(|phone| phone.number.clone()),+ city: address_details+ .and_then(|details| details.get_optional_city().map(|city| city.into())),+ address: address_details.and_then(|details| details.get_optional_line1()),+ zip: address_details.and_then(|details| details.get_optional_zip()),+ address_line2: address_details.and_then(|details| details.get_optional_line2()),+ address_line3: address_details.and_then(|details| details.get_optional_line3()),+ }+ }+}+#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum NuveiBIC {+ #[serde(rename = "ABNANL2A")]+ Abnamro,+ #[serde(rename = "ASNBNL21")]+ ASNBank,+ #[serde(rename = "BUNQNL2A")]+ Bunq,+ #[serde(rename = "INGBNL2A")]+ Ing,+ #[serde(rename = "KNABNL2H")]+ Knab,+ #[serde(rename = "RABONL2U")]+ Rabobank,+ #[serde(rename = "RBRBNL21")]+ RegioBank,+ #[serde(rename = "SNSBNL2A")]+ SNSBank,+ #[serde(rename = "TRIONL2U")]+ TriodosBank,+ #[serde(rename = "FVLBNL22")]+ VanLanschotBankiers,+ #[serde(rename = "MOYONL21")]+ Moneyou,+}++#[serde_with::skip_serializing_none]+#[derive(Debug, Clone, Default, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct AlternativePaymentMethod {+ pub payment_method: AlternativePaymentMethodType,+ #[serde(rename = "BIC")]+ pub bank_id: Option<NuveiBIC>,+}++#[derive(Debug, Clone, Default, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum AlternativePaymentMethodType {+ #[default]+ #[serde(rename = "apmgw_expresscheckout")]+ Expresscheckout,+ #[serde(rename = "apmgw_Giropay")]+ Giropay,+ #[serde(rename = "apmgw_Sofort")]+ Sofort,+ #[serde(rename = "apmgw_iDeal")]+ Ideal,+ #[serde(rename = "apmgw_EPS")]+ Eps,+ #[serde(rename = "apmgw_Afterpay")]+ AfterPay,+ #[serde(rename = "apmgw_Klarna")]+ Klarna,+}diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rsindex 414c3676d8..5565579af8 100644--- a/crates/hyperswitch_connectors/src/utils.rs+++ b/crates/hyperswitch_connectors/src/utils.rs@@ -2620,6 +2620,7 @@ pub trait PaymentsCompleteAuthorizeRequestData {fn get_browser_info(&self) -> Result<BrowserInformation, Error>;fn get_threeds_method_comp_ind(&self) -> Result<payments::ThreeDsCompletionIndicator, Error>;fn get_connector_mandate_id(&self) -> Option<String>;+ fn get_router_return_url(&self) -> Result<String, Error>;}impl PaymentsCompleteAuthorizeRequestData for CompleteAuthorizeData {@@ -2632,6 +2633,11 @@ impl PaymentsCompleteAuthorizeRequestData for CompleteAuthorizeData {Some(_) => Err(errors::ConnectorError::CaptureMethodNotSupported.into()),}}+ fn get_router_return_url(&self) -> Result<String, Error> {+ self.router_return_url+ .clone()+ .ok_or_else(missing_field_err("router_return_url"))+ }fn get_email(&self) -> Result<Email, Error> {self.email.clone().ok_or_else(missing_field_err("email"))}diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rsindex f9a5ff8ad5..f414a58e86 100644--- a/crates/hyperswitch_domain_models/src/router_request_types.rs+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs@@ -830,6 +830,7 @@ pub struct CompleteAuthorizeData {pub threeds_method_comp_ind: Option<api_models::payments::ThreeDsCompletionIndicator>,pub is_stored_credential: Option<bool>,pub tokenization: Option<common_enums::Tokenization>,+ pub router_return_url: Option<String>,}#[derive(Debug, Clone, Serialize)]diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex 4ceb0dcde1..9da558d990 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -6026,7 +6026,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthorizfield_name: "browser_info",})?;- let redirect_response = payment_data.redirect_response.map(|redirect| {+ let redirect_response = payment_data.redirect_response.clone().map(|redirect| {types::CompleteAuthorizeRedirectResponse {params: redirect.param,payload: redirect.json_payload,@@ -6062,6 +6062,12 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthorizpayment_data.payment_intent.off_session,);+ let router_return_url = Some(helpers::create_redirect_url(+ &additional_data.router_base_url.to_string(),+ &payment_data.payment_attempt,+ connector_name,+ payment_data.clone().get_creds_identifier(),+ ));Ok(Self {setup_future_usage: payment_data.payment_intent.setup_future_usage,mandate_id: payment_data.mandate_id.clone(),@@ -6096,6 +6102,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthoriz.map(router_request_types::UcsAuthenticationData::foreign_try_from).transpose()?,tokenization: payment_data.payment_intent.tokenization,+ router_return_url,})}}