From dd333298f8b4e8ff3c15fc79fbc528a61fa1b63f Mon Sep 17 00:00:00 2001 From: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com> Date: Wed, 29 May 2024 13:29:33 +0530 Subject: [PATCH] refactor(core): move router data response and request models to hyperswitch domain models crate (#4789) --- crates/hyperswitch_domain_models/src/lib.rs | 1 + .../src/router_request_types.rs | 196 +++++++- .../router_request_types/authentication.rs | 26 +- .../src/router_response_types.rs | 234 +++++++++ .../src/router_response_types/disputes.rs | 17 + .../src/router_response_types/fraud_check.rs | 30 ++ crates/router/src/connector/adyen.rs | 2 +- crates/router/src/connector/nuvei.rs | 2 +- .../src/connector/stripe/transformers.rs | 10 +- .../router/src/core/authentication/types.rs | 55 +-- .../src/core/payments/flows/authorize_flow.rs | 83 +--- .../payments/flows/complete_authorize_flow.rs | 18 +- .../core/payments/flows/setup_mandate_flow.rs | 29 +- .../payments/operations/payment_response.rs | 7 +- .../router/src/core/payments/transformers.rs | 6 +- crates/router/src/core/payments/types.rs | 11 +- crates/router/src/routes/fraud_check.rs | 8 - crates/router/src/services/api.rs | 60 +-- crates/router/src/types.rs | 444 +----------------- crates/router/src/types/authentication.rs | 130 +---- crates/router/src/types/fraud_check.rs | 33 +- 21 files changed, 543 insertions(+), 859 deletions(-) create mode 100644 crates/hyperswitch_domain_models/src/router_response_types.rs create mode 100644 crates/hyperswitch_domain_models/src/router_response_types/disputes.rs create mode 100644 crates/hyperswitch_domain_models/src/router_response_types/fraud_check.rs diff --git a/crates/hyperswitch_domain_models/src/lib.rs b/crates/hyperswitch_domain_models/src/lib.rs index ba6ccdf839..ac1ab08893 100644 --- a/crates/hyperswitch_domain_models/src/lib.rs +++ b/crates/hyperswitch_domain_models/src/lib.rs @@ -7,6 +7,7 @@ pub mod payments; pub mod payouts; pub mod router_data; pub mod router_request_types; +pub mod router_response_types; #[cfg(not(feature = "payouts"))] pub trait PayoutAttemptInterface {} diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs index 026a191977..56a4ba739c 100644 --- a/crates/hyperswitch_domain_models/src/router_request_types.rs +++ b/crates/hyperswitch_domain_models/src/router_request_types.rs @@ -1,7 +1,7 @@ pub mod authentication; pub mod fraud_check; use api_models::payments::RequestSurchargeDetails; -use common_utils::{consts, errors, pii}; +use common_utils::{consts, errors, ext_traits::OptionExt, pii}; use diesel_models::enums as storage_enums; use error_stack::ResultExt; use masking::Secret; @@ -9,7 +9,12 @@ use serde::Serialize; use serde_with::serde_as; use super::payment_method_data::PaymentMethodData; -use crate::{errors::api_error_response, mandates, payments, router_data}; +use crate::{ + errors::api_error_response::ApiErrorResponse, + mandates, payments, + router_data::{self, RouterData}, + router_response_types as response_types, +}; #[derive(Debug, Clone)] pub struct PaymentsAuthorizeData { pub payment_method_data: PaymentMethodData, @@ -51,6 +56,14 @@ pub struct PaymentsAuthorizeData { pub request_incremental_authorization: bool, pub metadata: Option, pub authentication_data: Option, + pub charges: Option, +} + +#[derive(Debug, serde::Deserialize, Clone)] +pub struct PaymentCharges { + pub charge_type: api_models::enums::PaymentChargeType, + pub fees: i64, + pub transfer_account_id: String, } #[derive(Debug, Clone, Default)] @@ -99,6 +112,38 @@ pub struct ConnectorCustomerData { pub payment_method_data: PaymentMethodData, } +impl TryFrom for ConnectorCustomerData { + type Error = error_stack::Report; + fn try_from(data: SetupMandateRequestData) -> Result { + Ok(Self { + email: data.email, + payment_method_data: data.payment_method_data, + description: None, + phone: None, + name: None, + preprocessing_id: None, + }) + } +} +impl TryFrom<&RouterData> + for ConnectorCustomerData +{ + type Error = error_stack::Report; + + fn try_from( + data: &RouterData, + ) -> Result { + Ok(Self { + email: data.request.email.clone(), + payment_method_data: data.request.payment_method_data.clone(), + description: None, + phone: None, + name: data.request.customer_name.clone(), + preprocessing_id: data.preprocessing_id.clone(), + }) + } +} + #[derive(Debug, Clone)] pub struct PaymentMethodTokenizationData { pub payment_method_data: PaymentMethodData, @@ -107,6 +152,64 @@ pub struct PaymentMethodTokenizationData { pub amount: Option, } +impl TryFrom for PaymentMethodTokenizationData { + type Error = error_stack::Report; + + fn try_from(data: SetupMandateRequestData) -> Result { + Ok(Self { + payment_method_data: data.payment_method_data, + browser_info: None, + currency: data.currency, + amount: data.amount, + }) + } +} +impl From<&RouterData> + for PaymentMethodTokenizationData +{ + fn from( + data: &RouterData, + ) -> Self { + Self { + payment_method_data: data.request.payment_method_data.clone(), + browser_info: None, + currency: data.request.currency, + amount: Some(data.request.amount), + } + } +} + +impl TryFrom for PaymentMethodTokenizationData { + type Error = error_stack::Report; + + fn try_from(data: PaymentsAuthorizeData) -> Result { + Ok(Self { + payment_method_data: data.payment_method_data, + browser_info: data.browser_info, + currency: data.currency, + amount: Some(data.amount), + }) + } +} + +impl TryFrom for PaymentMethodTokenizationData { + type Error = error_stack::Report; + + fn try_from(data: CompleteAuthorizeData) -> Result { + Ok(Self { + payment_method_data: data + .payment_method_data + .get_required_value("payment_method_data") + .change_context(ApiErrorResponse::MissingRequiredField { + field_name: "payment_method_data", + })?, + browser_info: data.browser_info, + currency: data.currency, + amount: Some(data.amount), + }) + } +} + #[derive(Debug, Clone)] pub struct PaymentsPreProcessingData { pub payment_method_data: Option, @@ -126,6 +229,53 @@ pub struct PaymentsPreProcessingData { pub redirect_response: Option, } +impl TryFrom for PaymentsPreProcessingData { + type Error = error_stack::Report; + + fn try_from(data: PaymentsAuthorizeData) -> Result { + Ok(Self { + payment_method_data: Some(data.payment_method_data), + amount: Some(data.amount), + email: data.email, + currency: Some(data.currency), + payment_method_type: data.payment_method_type, + setup_mandate_details: data.setup_mandate_details, + capture_method: data.capture_method, + order_details: data.order_details, + router_return_url: data.router_return_url, + webhook_url: data.webhook_url, + complete_authorize_url: data.complete_authorize_url, + browser_info: data.browser_info, + surcharge_details: data.surcharge_details, + connector_transaction_id: None, + redirect_response: None, + }) + } +} + +impl TryFrom for PaymentsPreProcessingData { + type Error = error_stack::Report; + + fn try_from(data: CompleteAuthorizeData) -> Result { + Ok(Self { + payment_method_data: data.payment_method_data, + amount: Some(data.amount), + email: data.email, + currency: Some(data.currency), + payment_method_type: None, + setup_mandate_details: data.setup_mandate_details, + capture_method: data.capture_method, + order_details: None, + router_return_url: None, + webhook_url: None, + complete_authorize_url: data.complete_authorize_url, + browser_info: data.browser_info, + surcharge_details: None, + connector_transaction_id: data.connector_transaction_id, + redirect_response: data.redirect_response, + }) + } +} #[derive(Debug, Clone)] pub struct CompleteAuthorizeData { pub payment_method_data: Option, @@ -165,6 +315,7 @@ pub struct PaymentsSyncData { pub mandate_id: Option, pub payment_method_type: Option, pub currency: storage_enums::Currency, + pub payment_experience: Option, } #[derive(Debug, Default, Clone)] @@ -352,7 +503,7 @@ pub struct AccessTokenRequestData { } impl TryFrom for AccessTokenRequestData { - type Error = api_error_response::ApiErrorResponse; + type Error = ApiErrorResponse; fn try_from(connector_auth: router_data::ConnectorAuthType) -> Result { match connector_auth { router_data::ConnectorAuthType::HeaderKey { api_key } => Ok(Self { @@ -372,7 +523,7 @@ impl TryFrom for AccessTokenRequestData { id: Some(key1), }), - _ => Err(api_error_response::ApiErrorResponse::InvalidDataValue { + _ => Err(ApiErrorResponse::InvalidDataValue { field_name: "connector_account_details", }), } @@ -478,3 +629,40 @@ pub struct VerifyWebhookSourceRequestData { pub webhook_body: Vec, pub merchant_secret: api_models::webhooks::ConnectorWebhookSecrets, } + +#[derive(Debug, Clone)] +pub struct MandateRevokeRequestData { + pub mandate_id: String, + pub connector_mandate_id: Option, +} + +#[derive(Debug, Clone)] +pub struct PaymentsSessionData { + pub amount: i64, + pub currency: common_enums::Currency, + pub country: Option, + pub surcharge_details: Option, + pub order_details: Option>, +} + +#[derive(Debug, Clone)] +pub struct SetupMandateRequestData { + pub currency: storage_enums::Currency, + pub payment_method_data: PaymentMethodData, + pub amount: Option, + pub confirm: bool, + pub statement_descriptor_suffix: Option, + pub customer_acceptance: Option, + pub mandate_id: Option, + pub setup_future_usage: Option, + pub off_session: Option, + pub setup_mandate_details: Option, + pub router_return_url: Option, + pub browser_info: Option, + pub email: Option, + pub customer_name: Option>, + pub return_url: Option, + pub payment_method_type: Option, + pub request_incremental_authorization: bool, + pub metadata: Option, +} diff --git a/crates/hyperswitch_domain_models/src/router_request_types/authentication.rs b/crates/hyperswitch_domain_models/src/router_request_types/authentication.rs index 1a554e8054..3f2feaf4c2 100644 --- a/crates/hyperswitch_domain_models/src/router_request_types/authentication.rs +++ b/crates/hyperswitch_domain_models/src/router_request_types/authentication.rs @@ -8,29 +8,6 @@ use crate::{ router_request_types::BrowserInformation, }; -#[derive(Debug, Clone)] -pub enum AuthenticationResponseData { - PreAuthNResponse { - threeds_server_transaction_id: String, - maximum_supported_3ds_version: common_utils::types::SemanticVersion, - connector_authentication_id: String, - three_ds_method_data: Option, - three_ds_method_url: Option, - message_version: common_utils::types::SemanticVersion, - connector_metadata: Option, - }, - AuthNResponse { - authn_flow_type: AuthNFlowType, - authentication_value: Option, - trans_status: common_enums::TransactionStatus, - }, - PostAuthNResponse { - trans_status: common_enums::TransactionStatus, - authentication_value: Option, - eci: Option, - }, -} - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ChallengeParams { pub acs_url: Option, @@ -94,8 +71,7 @@ impl AuthNFlowType { #[derive(Clone, Default, Debug)] pub struct PreAuthNRequestData { // card number - #[allow(dead_code)] - pub(crate) card_holder_account_number: CardNumber, + pub card_holder_account_number: CardNumber, } #[derive(Clone, Debug)] diff --git a/crates/hyperswitch_domain_models/src/router_response_types.rs b/crates/hyperswitch_domain_models/src/router_response_types.rs new file mode 100644 index 0000000000..3d89163b3d --- /dev/null +++ b/crates/hyperswitch_domain_models/src/router_response_types.rs @@ -0,0 +1,234 @@ +pub mod disputes; +pub mod fraud_check; +use std::collections::HashMap; + +use common_utils::{request::Method, types::MinorUnit}; +pub use disputes::{AcceptDisputeResponse, DefendDisputeResponse, SubmitEvidenceResponse}; + +use crate::router_request_types::{authentication::AuthNFlowType, ResponseId}; +#[derive(Debug, Clone)] +pub struct RefundsResponseData { + pub connector_refund_id: String, + pub refund_status: common_enums::RefundStatus, + // pub amount_received: Option, // Calculation for amount received not in place yet +} + +#[derive(Debug, Clone)] +pub enum PaymentsResponseData { + TransactionResponse { + resource_id: ResponseId, + redirection_data: Option, + mandate_reference: Option, + connector_metadata: Option, + network_txn_id: Option, + connector_response_reference_id: Option, + incremental_authorization_allowed: Option, + charge_id: Option, + }, + MultipleCaptureResponse { + // pending_capture_id_list: Vec, + capture_sync_response_list: HashMap, + }, + SessionResponse { + session_token: api_models::payments::SessionToken, + }, + SessionTokenResponse { + session_token: String, + }, + TransactionUnresolvedResponse { + resource_id: ResponseId, + //to add more info on cypto response, like `unresolved` reason(overpaid, underpaid, delayed) + reason: Option, + connector_response_reference_id: Option, + }, + TokenizationResponse { + token: String, + }, + + ConnectorCustomerResponse { + connector_customer_id: String, + }, + + ThreeDSEnrollmentResponse { + enrolled_v2: bool, + related_transaction_id: Option, + }, + PreProcessingResponse { + pre_processing_id: PreprocessingResponseId, + connector_metadata: Option, + session_token: Option, + connector_response_reference_id: Option, + }, + IncrementalAuthorizationResponse { + status: common_enums::AuthorizationStatus, + connector_authorization_id: Option, + error_code: Option, + error_message: Option, + }, +} + +#[derive(serde::Serialize, Debug, Clone)] +pub struct MandateReference { + pub connector_mandate_id: Option, + pub payment_method_id: Option, +} + +#[derive(Debug, Clone)] +pub enum CaptureSyncResponse { + Success { + resource_id: ResponseId, + status: common_enums::AttemptStatus, + connector_response_reference_id: Option, + amount: Option, + }, + Error { + code: String, + message: String, + reason: Option, + status_code: u16, + amount: Option, + }, +} + +impl CaptureSyncResponse { + pub fn get_amount_captured(&self) -> Option { + match self { + Self::Success { amount, .. } | Self::Error { amount, .. } => *amount, + } + } + pub fn get_connector_response_reference_id(&self) -> Option { + match self { + Self::Success { + connector_response_reference_id, + .. + } => connector_response_reference_id.clone(), + Self::Error { .. } => None, + } + } +} + +#[derive(Debug, Clone)] +pub enum PreprocessingResponseId { + PreProcessingId(String), + ConnectorTransactionId(String), +} + +#[derive(Debug, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)] +pub enum RedirectForm { + Form { + endpoint: String, + method: Method, + form_fields: HashMap, + }, + Html { + html_data: String, + }, + BlueSnap { + payment_fields_token: String, // payment-field-token + }, + CybersourceAuthSetup { + access_token: String, + ddc_url: String, + reference_id: String, + }, + CybersourceConsumerAuth { + access_token: String, + step_up_url: String, + }, + Payme, + Braintree { + client_token: String, + card_token: String, + bin: String, + }, + Nmi { + amount: String, + currency: common_enums::Currency, + public_key: masking::Secret, + customer_vault_id: String, + order_id: String, + }, +} + +impl From<(url::Url, Method)> for RedirectForm { + fn from((mut redirect_url, method): (url::Url, Method)) -> Self { + let form_fields = HashMap::from_iter( + redirect_url + .query_pairs() + .map(|(key, value)| (key.to_string(), value.to_string())), + ); + + // Do not include query params in the endpoint + redirect_url.set_query(None); + + Self::Form { + endpoint: redirect_url.to_string(), + method, + form_fields, + } + } +} + +#[derive(Default, Clone, Debug)] +pub struct UploadFileResponse { + pub provider_file_id: String, +} +#[derive(Clone, Debug)] +pub struct RetrieveFileResponse { + pub file_data: Vec, +} + +#[cfg(feature = "payouts")] +#[derive(Clone, Debug, Default)] +pub struct PayoutsResponseData { + pub status: Option, + pub connector_payout_id: String, + pub payout_eligible: Option, + pub should_add_next_step_to_process_tracker: bool, +} + +#[derive(Debug, Clone)] +pub struct VerifyWebhookSourceResponseData { + pub verify_webhook_status: VerifyWebhookStatus, +} + +#[derive(Debug, Clone)] +pub enum VerifyWebhookStatus { + SourceVerified, + SourceNotVerified, +} + +#[derive(Debug, Clone)] +pub struct MandateRevokeResponseData { + pub mandate_status: common_enums::MandateStatus, +} + +#[derive(Debug, Clone)] +pub enum AuthenticationResponseData { + PreAuthNResponse { + threeds_server_transaction_id: String, + maximum_supported_3ds_version: common_utils::types::SemanticVersion, + connector_authentication_id: String, + three_ds_method_data: Option, + three_ds_method_url: Option, + message_version: common_utils::types::SemanticVersion, + connector_metadata: Option, + directory_server_id: Option, + }, + AuthNResponse { + authn_flow_type: AuthNFlowType, + authentication_value: Option, + trans_status: common_enums::TransactionStatus, + }, + PostAuthNResponse { + trans_status: common_enums::TransactionStatus, + authentication_value: Option, + eci: Option, + }, +} + +#[derive(Debug, Clone)] +pub struct CompleteAuthorizeRedirectResponse { + pub params: Option>, + pub payload: Option, +} diff --git a/crates/hyperswitch_domain_models/src/router_response_types/disputes.rs b/crates/hyperswitch_domain_models/src/router_response_types/disputes.rs new file mode 100644 index 0000000000..478cedd440 --- /dev/null +++ b/crates/hyperswitch_domain_models/src/router_response_types/disputes.rs @@ -0,0 +1,17 @@ +#[derive(Default, Clone, Debug)] +pub struct AcceptDisputeResponse { + pub dispute_status: api_models::enums::DisputeStatus, + pub connector_status: Option, +} + +#[derive(Default, Clone, Debug)] +pub struct SubmitEvidenceResponse { + pub dispute_status: api_models::enums::DisputeStatus, + pub connector_status: Option, +} + +#[derive(Default, Debug, Clone)] +pub struct DefendDisputeResponse { + pub dispute_status: api_models::enums::DisputeStatus, + pub connector_status: Option, +} diff --git a/crates/hyperswitch_domain_models/src/router_response_types/fraud_check.rs b/crates/hyperswitch_domain_models/src/router_response_types/fraud_check.rs new file mode 100644 index 0000000000..52c2b5b7a8 --- /dev/null +++ b/crates/hyperswitch_domain_models/src/router_response_types/fraud_check.rs @@ -0,0 +1,30 @@ +use serde::Serialize; + +use crate::router_response_types::ResponseId; + +#[derive(Debug, Clone, Serialize)] +#[serde(untagged)] +pub enum FraudCheckResponseData { + TransactionResponse { + resource_id: ResponseId, + status: diesel_models::enums::FraudCheckStatus, + connector_metadata: Option, + reason: Option, + score: Option, + }, + FulfillmentResponse { + order_id: String, + shipment_ids: Vec, + }, + RecordReturnResponse { + resource_id: ResponseId, + connector_metadata: Option, + return_id: Option, + }, +} + +impl common_utils::events::ApiEventMetric for FraudCheckResponseData { + fn get_api_event_type(&self) -> Option { + Some(common_utils::events::ApiEventsType::FraudCheck) + } +} diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rs index 1a63dc50c9..e38edeaa85 100644 --- a/crates/router/src/connector/adyen.rs +++ b/crates/router/src/connector/adyen.rs @@ -367,7 +367,7 @@ impl ) -> CustomResult { let authorize_req = types::PaymentsAuthorizeRouterData::foreign_from(( req, - types::PaymentsAuthorizeData::from(req), + types::PaymentsAuthorizeData::foreign_from(req), )); let connector_router_data = adyen::AdyenRouterData::try_from(( &self.get_currency_unit(), diff --git a/crates/router/src/connector/nuvei.rs b/crates/router/src/connector/nuvei.rs index e4d6ab0be4..bc556336c3 100644 --- a/crates/router/src/connector/nuvei.rs +++ b/crates/router/src/connector/nuvei.rs @@ -539,7 +539,7 @@ impl ConnectorIntegration = Box::new(&Self); let authorize_data = &types::PaymentsAuthorizeSessionTokenRouterData::foreign_from(( &router_data.to_owned(), - types::AuthorizeSessionTokenData::from(&router_data), + types::AuthorizeSessionTokenData::foreign_from(&router_data), )); let resp = services::execute_connector_processing_step( app_state, diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 83bca39626..5bc2dfa2af 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -2377,7 +2377,7 @@ impl let status = enums::AttemptStatus::from(item.response.status); let response = if connector_util::is_payment_failure(status) { - types::PaymentsResponseData::try_from(( + types::PaymentsResponseData::foreign_try_from(( &item.response.last_payment_error, item.http_code, item.response.id.clone(), @@ -2558,7 +2558,7 @@ impl .and_then(extract_payment_method_connector_response_from_latest_charge); let response = if connector_util::is_payment_failure(status) { - types::PaymentsResponseData::try_from(( + types::PaymentsResponseData::foreign_try_from(( &item.response.payment_intent_fields.last_payment_error, item.http_code, item.response.id.clone(), @@ -2639,7 +2639,7 @@ impl .and_then(extract_payment_method_connector_response_from_latest_attempt); let response = if connector_util::is_payment_failure(status) { - types::PaymentsResponseData::try_from(( + types::PaymentsResponseData::foreign_try_from(( &item.response.last_setup_error, item.http_code, item.response.id.clone(), @@ -3910,9 +3910,9 @@ fn get_transaction_metadata( meta_data } -impl TryFrom<(&Option, u16, String)> for types::PaymentsResponseData { +impl ForeignTryFrom<(&Option, u16, String)> for types::PaymentsResponseData { type Error = types::ErrorResponse; - fn try_from( + fn foreign_try_from( (response, http_code, response_id): (&Option, u16, String), ) -> Result { let (code, error_message) = match response { diff --git a/crates/router/src/core/authentication/types.rs b/crates/router/src/core/authentication/types.rs index 4815f4569d..0492e51e0a 100644 --- a/crates/router/src/core/authentication/types.rs +++ b/crates/router/src/core/authentication/types.rs @@ -1,43 +1,13 @@ -use cards::CardNumber; use error_stack::{Report, ResultExt}; -use serde::{Deserialize, Serialize}; +pub use hyperswitch_domain_models::router_request_types::authentication::{ + AcquirerDetails, ExternalThreeDSConnectorMetadata, PreAuthenticationData, ThreeDsMethodData, +}; use crate::{ - core::{errors, payments}, + core::errors, types::{storage, transformers::ForeignTryFrom}, utils::OptionExt, }; -pub enum PreAuthenthenticationFlowInput<'a, F: Clone> { - PaymentAuthNFlow { - payment_data: &'a mut payments::PaymentData, - should_continue_confirm_transaction: &'a mut bool, - card_number: CardNumber, - }, - PaymentMethodAuthNFlow { - card_number: CardNumber, - other_fields: String, //should be expanded when implementation begins - }, -} - -pub enum PostAuthenthenticationFlowInput<'a, F: Clone> { - PaymentAuthNFlow { - payment_data: &'a mut payments::PaymentData, - authentication: storage::Authentication, - should_continue_confirm_transaction: &'a mut bool, - }, - PaymentMethodAuthNFlow { - other_fields: String, //should be expanded when implementation begins - }, -} - -#[derive(Clone, Debug)] -pub struct PreAuthenticationData { - pub threeds_server_transaction_id: String, - pub message_version: common_utils::types::SemanticVersion, - pub acquirer_bin: Option, - pub acquirer_merchant_id: Option, - pub connector_metadata: Option, -} impl ForeignTryFrom<&storage::Authentication> for PreAuthenticationData { type Error = Report; @@ -62,20 +32,3 @@ impl ForeignTryFrom<&storage::Authentication> for PreAuthenticationData { }) } } - -#[derive(Clone, Default, Debug, Serialize, Deserialize)] -pub struct ThreeDsMethodData { - pub three_ds_method_data_submission: bool, - pub three_ds_method_data: String, - pub three_ds_method_url: Option, -} -#[derive(Clone, Default, Debug, Serialize, Deserialize)] -pub struct AcquirerDetails { - pub acquirer_bin: String, - pub acquirer_merchant_id: String, -} - -#[derive(Clone, Debug, Deserialize)] -pub struct ExternalThreeDSConnectorMetadata { - pub pull_mechanism_for_external_3ds_enabled: Option, -} diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index 75bbb5bda8..931ea26a9f 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -1,11 +1,10 @@ use async_trait::async_trait; -use error_stack; // use router_env::tracing::Instrument; use super::{ConstructFlowSpecificData, Feature}; use crate::{ core::{ - errors::{self, ConnectorErrorExt, RouterResult}, + errors::{ConnectorErrorExt, RouterResult}, mandate, payments::{ self, access_token, customers, helpers, tokenization, transformers, PaymentData, @@ -335,83 +334,3 @@ pub async fn authorize_preprocessing_steps( Ok(router_data.clone()) } } - -impl TryFrom<&types::RouterData> - for types::ConnectorCustomerData -{ - type Error = error_stack::Report; - - fn try_from( - data: &types::RouterData, - ) -> Result { - Ok(Self { - email: data.request.email.clone(), - payment_method_data: data.request.payment_method_data.clone(), - description: None, - phone: None, - name: data.request.customer_name.clone(), - preprocessing_id: data.preprocessing_id.clone(), - }) - } -} - -impl TryFrom for types::PaymentMethodTokenizationData { - type Error = error_stack::Report; - - fn try_from(data: types::PaymentsAuthorizeData) -> Result { - Ok(Self { - payment_method_data: data.payment_method_data, - browser_info: data.browser_info, - currency: data.currency, - amount: Some(data.amount), - }) - } -} - -impl TryFrom for types::PaymentsPreProcessingData { - type Error = error_stack::Report; - - fn try_from(data: types::PaymentsAuthorizeData) -> Result { - Ok(Self { - payment_method_data: Some(data.payment_method_data), - amount: Some(data.amount), - email: data.email, - currency: Some(data.currency), - payment_method_type: data.payment_method_type, - setup_mandate_details: data.setup_mandate_details, - capture_method: data.capture_method, - order_details: data.order_details, - router_return_url: data.router_return_url, - webhook_url: data.webhook_url, - complete_authorize_url: data.complete_authorize_url, - browser_info: data.browser_info, - surcharge_details: data.surcharge_details, - connector_transaction_id: None, - redirect_response: None, - }) - } -} - -impl TryFrom for types::PaymentsPreProcessingData { - type Error = error_stack::Report; - - fn try_from(data: types::CompleteAuthorizeData) -> Result { - Ok(Self { - payment_method_data: data.payment_method_data, - amount: Some(data.amount), - email: data.email, - currency: Some(data.currency), - payment_method_type: None, - setup_mandate_details: data.setup_mandate_details, - capture_method: data.capture_method, - order_details: None, - router_return_url: None, - webhook_url: None, - complete_authorize_url: data.complete_authorize_url, - browser_info: data.browser_info, - surcharge_details: None, - connector_transaction_id: data.connector_transaction_id, - redirect_response: data.redirect_response, - }) - } -} diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rs index 4e9bf47232..c14cf6c808 100644 --- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs +++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs @@ -3,13 +3,12 @@ use async_trait::async_trait; use super::{ConstructFlowSpecificData, Feature}; use crate::{ core::{ - errors::{self, ConnectorErrorExt, RouterResult}, + errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, routes::{metrics, AppState}, services, types::{self, api, domain, storage}, - utils::OptionExt, }; #[async_trait] @@ -221,18 +220,3 @@ pub async fn complete_authorize_preprocessing_steps( Ok(router_data.clone()) } } - -impl TryFrom for types::PaymentMethodTokenizationData { - type Error = error_stack::Report; - - fn try_from(data: types::CompleteAuthorizeData) -> Result { - Ok(Self { - payment_method_data: data - .payment_method_data - .get_required_value("payment_method_data")?, - browser_info: data.browser_info, - currency: data.currency, - amount: Some(data.amount), - }) - } -} diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs index cdadb355d4..b0fa39d525 100644 --- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs +++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use super::{ConstructFlowSpecificData, Feature}; use crate::{ core::{ - errors::{self, ConnectorErrorExt, RouterResult}, + errors::{ConnectorErrorExt, RouterResult}, mandate, payments::{ self, access_token, customers, helpers, tokenization, transformers, PaymentData, @@ -143,20 +143,6 @@ impl Feature for types::Setup } } -impl TryFrom for types::ConnectorCustomerData { - type Error = error_stack::Report; - fn try_from(data: types::SetupMandateRequestData) -> Result { - Ok(Self { - email: data.email, - payment_method_data: data.payment_method_data, - description: None, - phone: None, - name: None, - preprocessing_id: None, - }) - } -} - impl mandate::MandateBehaviour for types::SetupMandateRequestData { fn get_amount(&self) -> i64 { 0 @@ -187,16 +173,3 @@ impl mandate::MandateBehaviour for types::SetupMandateRequestData { self.customer_acceptance.clone().map(From::from) } } - -impl TryFrom for types::PaymentMethodTokenizationData { - type Error = error_stack::Report; - - fn try_from(data: types::SetupMandateRequestData) -> Result { - Ok(Self { - payment_method_data: data.payment_method_data, - browser_info: None, - currency: data.currency, - amount: data.amount, - }) - } -} diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 047eb35037..3b5bd9fd43 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1314,7 +1314,10 @@ fn response_to_capture_update( let capture = multiple_capture_data.get_capture_by_connector_capture_id(connector_capture_id); if let Some(capture) = capture { - capture_update_list.push((capture.clone(), capture_sync_response.try_into()?)) + capture_update_list.push(( + capture.clone(), + storage::CaptureUpdate::foreign_try_from(capture_sync_response)?, + )) } else { // connector_capture_id may not be populated in the captures table in some case // if so, we try to map the unmapped capture response and captures in DB. @@ -1350,7 +1353,7 @@ fn get_capture_update_for_unmapped_capture_responses( { result.push(( capture.clone(), - storage::CaptureUpdate::try_from(capture_sync_response)?, + storage::CaptureUpdate::foreign_try_from(capture_sync_response)?, )) } } diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 8f6af2f89b..d8a7092455 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -1617,10 +1617,12 @@ impl TryFrom> for types::SetupMandateRequ } } -impl TryFrom for storage::CaptureUpdate { +impl ForeignTryFrom for storage::CaptureUpdate { type Error = error_stack::Report; - fn try_from(capture_sync_response: types::CaptureSyncResponse) -> Result { + fn foreign_try_from( + capture_sync_response: types::CaptureSyncResponse, + ) -> Result { match capture_sync_response { types::CaptureSyncResponse::Success { resource_id, diff --git a/crates/router/src/core/payments/types.rs b/crates/router/src/core/payments/types.rs index eb3a711b5b..d39527b422 100644 --- a/crates/router/src/core/payments/types.rs +++ b/crates/router/src/core/payments/types.rs @@ -9,7 +9,9 @@ use common_utils::{ use diesel_models::business_profile::BusinessProfile; use error_stack::ResultExt; use hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt; -pub use hyperswitch_domain_models::router_request_types::{AuthenticationData, SurchargeDetails}; +pub use hyperswitch_domain_models::router_request_types::{ + AuthenticationData, PaymentCharges, SurchargeDetails, +}; use redis_interface::errors::RedisError; use router_env::{instrument, tracing}; @@ -374,10 +376,3 @@ impl ForeignTryFrom<&storage::Authentication> for AuthenticationData { } } } - -#[derive(Debug, serde::Deserialize, Clone)] -pub struct PaymentCharges { - pub charge_type: api_models::enums::PaymentChargeType, - pub fees: i64, - pub transfer_account_id: String, -} diff --git a/crates/router/src/routes/fraud_check.rs b/crates/router/src/routes/fraud_check.rs index 70bd55b710..20609502c1 100644 --- a/crates/router/src/routes/fraud_check.rs +++ b/crates/router/src/routes/fraud_check.rs @@ -1,11 +1,9 @@ use actix_web::{web, HttpRequest, HttpResponse}; -use common_utils::events::{ApiEventMetric, ApiEventsType}; use router_env::Flow; use crate::{ core::{api_locking, fraud_check as frm_core}, services::{self, api}, - types::fraud_check::FraudCheckResponseData, AppState, }; @@ -28,9 +26,3 @@ pub async fn frm_fulfillment( )) .await } - -impl ApiEventMetric for FraudCheckResponseData { - fn get_api_event_type(&self) -> Option { - Some(ApiEventsType::FraudCheck) - } -} diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 287f98cdb7..5f69a9d403 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -15,7 +15,6 @@ use actix_web::{ }; use api_models::enums::{CaptureMethod, PaymentMethodType}; pub use client::{proxy_bypass_urls, ApiClient, MockApiClient, ProxyClient}; -use common_enums::Currency; pub use common_utils::request::{ContentType, Method, Request, RequestBuilder}; use common_utils::{ consts::X_HS_LATENCY, @@ -23,7 +22,8 @@ use common_utils::{ request::RequestContent, }; use error_stack::{report, Report, ResultExt}; -use masking::{Maskable, PeekInterface, Secret}; +pub use hyperswitch_domain_models::router_response_types::RedirectForm; +use masking::{Maskable, PeekInterface}; use router_env::{instrument, tracing, tracing_actix_web::RequestId, Tag}; use serde::Serialize; use serde_json::json; @@ -901,62 +901,6 @@ pub struct ApplicationRedirectResponse { pub url: String, } -#[derive(Debug, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)] -pub enum RedirectForm { - Form { - endpoint: String, - method: Method, - form_fields: HashMap, - }, - Html { - html_data: String, - }, - BlueSnap { - payment_fields_token: String, // payment-field-token - }, - CybersourceAuthSetup { - access_token: String, - ddc_url: String, - reference_id: String, - }, - CybersourceConsumerAuth { - access_token: String, - step_up_url: String, - }, - Payme, - Braintree { - client_token: String, - card_token: String, - bin: String, - }, - Nmi { - amount: String, - currency: Currency, - public_key: Secret, - customer_vault_id: String, - order_id: String, - }, -} - -impl From<(url::Url, Method)> for RedirectForm { - fn from((mut redirect_url, method): (url::Url, Method)) -> Self { - let form_fields = HashMap::from_iter( - redirect_url - .query_pairs() - .map(|(key, value)| (key.to_string(), value.to_string())), - ); - - // Do not include query params in the endpoint - redirect_url.set_query(None); - - Self::Form { - endpoint: redirect_url.to_string(), - method, - form_fields, - } - } -} - #[derive(Clone, Copy, PartialEq, Eq)] pub enum AuthFlow { Client, diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 89c2629c10..fc1b59f431 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -16,17 +16,16 @@ pub mod pm_auth; pub mod storage; pub mod transformers; -use std::{collections::HashMap, marker::PhantomData}; +use std::marker::PhantomData; pub use api_models::{enums::Connector, mandates}; #[cfg(feature = "payouts")] pub use api_models::{enums::PayoutConnectors, payouts as payout_types}; -use common_enums::MandateStatus; pub use common_utils::request::RequestContent; -use common_utils::{pii, pii::Email, types::MinorUnit}; -use hyperswitch_domain_models::mandates::{CustomerAcceptance, MandateData}; #[cfg(feature = "payouts")] pub use hyperswitch_domain_models::router_request_types::PayoutsData; +#[cfg(feature = "payouts")] +pub use hyperswitch_domain_models::router_response_types::PayoutsResponseData; pub use hyperswitch_domain_models::{ payment_address::PaymentAddress, router_data::{ @@ -35,15 +34,25 @@ pub use hyperswitch_domain_models::{ PaymentMethodBalance, PaymentMethodToken, RecurringMandatePaymentData, RouterData, }, router_request_types::{ - AcceptDisputeRequestData, AccessTokenRequestData, BrowserInformation, ChargeRefunds, - ChargeRefundsOptions, DefendDisputeRequestData, DestinationChargeRefund, - DirectChargeRefund, RefundsData, ResponseId, RetrieveFileRequestData, - SubmitEvidenceRequestData, UploadFileRequestData, VerifyWebhookSourceRequestData, + AcceptDisputeRequestData, AccessTokenRequestData, AuthorizeSessionTokenData, + BrowserInformation, ChargeRefunds, ChargeRefundsOptions, CompleteAuthorizeData, + CompleteAuthorizeRedirectResponse, ConnectorCustomerData, DefendDisputeRequestData, + DestinationChargeRefund, DirectChargeRefund, MandateRevokeRequestData, + MultipleCaptureRequestData, PaymentMethodTokenizationData, PaymentsApproveData, + PaymentsAuthorizeData, PaymentsCancelData, PaymentsCaptureData, + PaymentsIncrementalAuthorizationData, PaymentsPreProcessingData, PaymentsRejectData, + PaymentsSessionData, PaymentsSyncData, RefundsData, ResponseId, RetrieveFileRequestData, + SetupMandateRequestData, SubmitEvidenceRequestData, SyncRequestType, UploadFileRequestData, + VerifyWebhookSourceRequestData, + }, + router_response_types::{ + AcceptDisputeResponse, CaptureSyncResponse, DefendDisputeResponse, MandateReference, + MandateRevokeResponseData, PaymentsResponseData, PreprocessingResponseId, + RefundsResponseData, RetrieveFileResponse, SubmitEvidenceResponse, UploadFileResponse, + VerifyWebhookSourceResponseData, VerifyWebhookStatus, }, }; -use masking::Secret; -use self::storage::enums as storage_enums; pub use crate::core::payments::CustomerDetails; #[cfg(feature = "payouts")] use crate::{ @@ -54,13 +63,10 @@ use crate::{ consts, core::{ errors::{self}, - payments::{types, PaymentData}, + payments::PaymentData, }, services, - types::{ - transformers::{ForeignFrom, ForeignTryFrom}, - types::AuthenticationData, - }, + types::transformers::{ForeignFrom, ForeignTryFrom}, }; pub type PaymentsAuthorizeRouterData = RouterData; @@ -300,237 +306,6 @@ impl PayoutIndividualDetailsExt for api_models::payouts::PayoutIndividualDetails } } -#[cfg(feature = "payouts")] -#[derive(Clone, Debug, Default)] -pub struct PayoutsResponseData { - pub status: Option, - pub connector_payout_id: String, - pub payout_eligible: Option, - pub should_add_next_step_to_process_tracker: bool, -} - -#[derive(Debug, Clone)] -pub struct PaymentsAuthorizeData { - pub payment_method_data: domain::payments::PaymentMethodData, - /// total amount (original_amount + surcharge_amount + tax_on_surcharge_amount) - /// If connector supports separate field for surcharge amount, consider using below functions defined on `PaymentsAuthorizeData` to fetch original amount and surcharge amount separately - /// ``` - /// get_original_amount() - /// get_surcharge_amount() - /// get_tax_on_surcharge_amount() - /// get_total_surcharge_amount() // returns surcharge_amount + tax_on_surcharge_amount - /// ``` - pub amount: i64, - pub email: Option, - pub customer_name: Option>, - pub currency: storage_enums::Currency, - pub confirm: bool, - pub statement_descriptor_suffix: Option, - pub statement_descriptor: Option, - pub capture_method: Option, - pub router_return_url: Option, - pub webhook_url: Option, - pub complete_authorize_url: Option, - // Mandates - pub setup_future_usage: Option, - pub mandate_id: Option, - pub off_session: Option, - pub customer_acceptance: Option, - pub setup_mandate_details: Option, - pub browser_info: Option, - pub order_details: Option>, - pub order_category: Option, - pub session_token: Option, - pub enrolled_for_3ds: bool, - pub related_transaction_id: Option, - pub payment_experience: Option, - pub payment_method_type: Option, - pub surcharge_details: Option, - pub customer_id: Option, - pub request_incremental_authorization: bool, - pub metadata: Option, - pub authentication_data: Option, - pub charges: Option, -} - -#[derive(Debug, Clone, Default)] -pub struct PaymentsCaptureData { - pub amount_to_capture: i64, - pub currency: storage_enums::Currency, - pub connector_transaction_id: String, - pub payment_amount: i64, - pub multiple_capture_data: Option, - pub connector_meta: Option, - pub browser_info: Option, - pub metadata: Option, - // This metadata is used to store the metadata shared during the payment intent request. -} - -#[derive(Debug, Clone, Default)] -pub struct PaymentsIncrementalAuthorizationData { - pub total_amount: i64, - pub additional_amount: i64, - pub currency: storage_enums::Currency, - pub reason: Option, - pub connector_transaction_id: String, -} - -#[allow(dead_code)] -#[derive(Debug, Clone, Default)] -pub struct MultipleCaptureRequestData { - pub capture_sequence: i16, - pub capture_reference: String, -} - -#[derive(Debug, Clone)] -pub struct AuthorizeSessionTokenData { - pub amount_to_capture: Option, - pub currency: storage_enums::Currency, - pub connector_transaction_id: String, - pub amount: Option, -} - -#[derive(Debug, Clone)] -pub struct ConnectorCustomerData { - pub description: Option, - pub email: Option, - pub phone: Option>, - pub name: Option>, - pub preprocessing_id: Option, - pub payment_method_data: domain::PaymentMethodData, -} - -#[derive(Debug, Clone)] -pub struct PaymentMethodTokenizationData { - pub payment_method_data: domain::payments::PaymentMethodData, - pub browser_info: Option, - pub currency: storage_enums::Currency, - pub amount: Option, -} - -#[derive(Debug, Clone)] -pub struct PaymentsPreProcessingData { - pub payment_method_data: Option, - pub amount: Option, - pub email: Option, - pub currency: Option, - pub payment_method_type: Option, - pub setup_mandate_details: Option, - pub capture_method: Option, - pub order_details: Option>, - pub router_return_url: Option, - pub webhook_url: Option, - pub complete_authorize_url: Option, - pub surcharge_details: Option, - pub browser_info: Option, - pub connector_transaction_id: Option, - pub redirect_response: Option, -} - -#[derive(Debug, Clone)] -pub struct CompleteAuthorizeData { - pub payment_method_data: Option, - pub amount: i64, - pub email: Option, - pub currency: storage_enums::Currency, - pub confirm: bool, - pub statement_descriptor_suffix: Option, - pub capture_method: Option, - // Mandates - pub setup_future_usage: Option, - pub mandate_id: Option, - pub off_session: Option, - pub setup_mandate_details: Option, - pub redirect_response: Option, - pub browser_info: Option, - pub connector_transaction_id: Option, - pub connector_meta: Option, - pub complete_authorize_url: Option, - pub metadata: Option, -} - -#[derive(Debug, Clone)] -pub struct CompleteAuthorizeRedirectResponse { - pub params: Option>, - pub payload: Option, -} - -#[derive(Debug, Default, Clone)] -pub struct PaymentsSyncData { - //TODO : add fields based on the connector requirements - pub connector_transaction_id: ResponseId, - pub encoded_data: Option, - pub capture_method: Option, - pub connector_meta: Option, - pub sync_type: SyncRequestType, - pub mandate_id: Option, - pub payment_method_type: Option, - pub currency: storage_enums::Currency, - pub payment_experience: Option, -} - -#[derive(Debug, Default, Clone)] -pub enum SyncRequestType { - MultipleCaptureSync(Vec), - #[default] - SinglePaymentSync, -} - -#[derive(Debug, Default, Clone)] -pub struct PaymentsCancelData { - pub amount: Option, - pub currency: Option, - pub connector_transaction_id: String, - pub cancellation_reason: Option, - pub connector_meta: Option, - pub browser_info: Option, - pub metadata: Option, - // This metadata is used to store the metadata shared during the payment intent request. -} - -#[derive(Debug, Default, Clone)] -pub struct PaymentsRejectData { - pub amount: Option, - pub currency: Option, -} - -#[derive(Debug, Default, Clone)] -pub struct PaymentsApproveData { - pub amount: Option, - pub currency: Option, -} - -#[derive(Debug, Clone)] -pub struct PaymentsSessionData { - pub amount: i64, - pub currency: storage_enums::Currency, - pub country: Option, - pub surcharge_details: Option, - pub order_details: Option>, -} - -#[derive(Debug, Clone)] -pub struct SetupMandateRequestData { - pub currency: storage_enums::Currency, - pub payment_method_data: domain::PaymentMethodData, - pub amount: Option, - pub confirm: bool, - pub statement_descriptor_suffix: Option, - pub customer_acceptance: Option, - pub mandate_id: Option, - pub setup_future_usage: Option, - pub off_session: Option, - pub setup_mandate_details: Option, - pub router_return_url: Option, - pub browser_info: Option, - pub email: Option, - pub customer_name: Option>, - pub return_url: Option, - pub payment_method_type: Option, - pub request_incremental_authorization: bool, - pub metadata: Option, -} - pub trait Capturable { fn get_captured_amount(&self, _payment_data: &PaymentData) -> Option where @@ -759,157 +534,12 @@ pub struct AddAccessTokenResult { pub connector_supports_access_token: bool, } -#[derive(serde::Serialize, Debug, Clone)] -pub struct MandateReference { - pub connector_mandate_id: Option, - pub payment_method_id: Option, -} - -#[derive(Debug, Clone)] -pub enum CaptureSyncResponse { - Success { - resource_id: ResponseId, - status: storage_enums::AttemptStatus, - connector_response_reference_id: Option, - amount: Option, - }, - Error { - code: String, - message: String, - reason: Option, - status_code: u16, - amount: Option, - }, -} - -impl CaptureSyncResponse { - pub fn get_amount_captured(&self) -> Option { - match self { - Self::Success { amount, .. } | Self::Error { amount, .. } => *amount, - } - } - pub fn get_connector_response_reference_id(&self) -> Option { - match self { - Self::Success { - connector_response_reference_id, - .. - } => connector_response_reference_id.clone(), - Self::Error { .. } => None, - } - } -} - -#[derive(Debug, Clone)] -pub enum PaymentsResponseData { - TransactionResponse { - resource_id: ResponseId, - redirection_data: Option, - mandate_reference: Option, - connector_metadata: Option, - network_txn_id: Option, - connector_response_reference_id: Option, - incremental_authorization_allowed: Option, - charge_id: Option, - }, - MultipleCaptureResponse { - // pending_capture_id_list: Vec, - capture_sync_response_list: HashMap, - }, - SessionResponse { - session_token: api::SessionToken, - }, - SessionTokenResponse { - session_token: String, - }, - TransactionUnresolvedResponse { - resource_id: ResponseId, - //to add more info on cypto response, like `unresolved` reason(overpaid, underpaid, delayed) - reason: Option, - connector_response_reference_id: Option, - }, - TokenizationResponse { - token: String, - }, - - ConnectorCustomerResponse { - connector_customer_id: String, - }, - - ThreeDSEnrollmentResponse { - enrolled_v2: bool, - related_transaction_id: Option, - }, - PreProcessingResponse { - pre_processing_id: PreprocessingResponseId, - connector_metadata: Option, - session_token: Option, - connector_response_reference_id: Option, - }, - IncrementalAuthorizationResponse { - status: common_enums::AuthorizationStatus, - connector_authorization_id: Option, - error_code: Option, - error_message: Option, - }, -} - -#[derive(Debug, Clone)] -pub enum PreprocessingResponseId { - PreProcessingId(String), - ConnectorTransactionId(String), -} - -#[derive(Debug, Clone)] -pub struct RefundsResponseData { - pub connector_refund_id: String, - pub refund_status: storage_enums::RefundStatus, - // pub amount_received: Option, // Calculation for amount received not in place yet -} - #[derive(Debug, Clone, Copy)] pub enum Redirection { Redirect, NoRedirect, } -#[derive(Debug, Clone)] -pub struct VerifyWebhookSourceResponseData { - pub verify_webhook_status: VerifyWebhookStatus, -} - -#[derive(Debug, Clone)] -pub enum VerifyWebhookStatus { - SourceVerified, - SourceNotVerified, -} - -#[derive(Default, Clone, Debug)] -pub struct AcceptDisputeResponse { - pub dispute_status: api_models::enums::DisputeStatus, - pub connector_status: Option, -} - -#[derive(Default, Clone, Debug)] -pub struct SubmitEvidenceResponse { - pub dispute_status: api_models::enums::DisputeStatus, - pub connector_status: Option, -} - -#[derive(Default, Debug, Clone)] -pub struct DefendDisputeResponse { - pub dispute_status: api_models::enums::DisputeStatus, - pub connector_status: Option, -} - -#[derive(Default, Clone, Debug)] -pub struct UploadFileResponse { - pub provider_file_id: String, -} -#[derive(Clone, Debug)] -pub struct RetrieveFileResponse { - pub file_data: Vec, -} - #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] pub struct PollConfig { pub delay_in_secs: i8, @@ -961,17 +591,6 @@ pub struct ResponseRouterData { pub http_code: u16, } -#[derive(Debug, Clone)] -pub struct MandateRevokeRequestData { - pub mandate_id: String, - pub connector_mandate_id: Option, -} - -#[derive(Debug, Clone)] -pub struct MandateRevokeResponseData { - pub mandate_status: MandateStatus, -} - impl ForeignFrom for ConnectorAuthType { fn foreign_from(value: api_models::admin::ConnectorAuthType) -> Self { match value { @@ -1098,8 +717,8 @@ impl ForeignTryFrom for AccessTokenRequestData { } } -impl From<&&mut PaymentsAuthorizeRouterData> for AuthorizeSessionTokenData { - fn from(data: &&mut PaymentsAuthorizeRouterData) -> Self { +impl ForeignFrom<&&mut PaymentsAuthorizeRouterData> for AuthorizeSessionTokenData { + fn foreign_from(data: &&mut PaymentsAuthorizeRouterData) -> Self { Self { amount_to_capture: data.amount_captured, currency: data.request.currency, @@ -1109,19 +728,6 @@ impl From<&&mut PaymentsAuthorizeRouterData> for AuthorizeSessionTokenData { } } -impl From<&RouterData> - for PaymentMethodTokenizationData -{ - fn from(data: &RouterData) -> Self { - Self { - payment_method_data: data.request.payment_method_data.clone(), - browser_info: None, - currency: data.request.currency, - amount: Some(data.request.amount), - } - } -} - pub trait Tokenizable { fn set_session_token(&mut self, token: Option); } @@ -1140,8 +746,8 @@ impl Tokenizable for CompleteAuthorizeData { fn set_session_token(&mut self, _token: Option) {} } -impl From<&SetupMandateRouterData> for PaymentsAuthorizeData { - fn from(data: &SetupMandateRouterData) -> Self { +impl ForeignFrom<&SetupMandateRouterData> for PaymentsAuthorizeData { + fn foreign_from(data: &SetupMandateRouterData) -> Self { Self { currency: data.request.currency, payment_method_data: data.request.payment_method_data.clone(), diff --git a/crates/router/src/types/authentication.rs b/crates/router/src/types/authentication.rs index 97ad8506d4..2ca918f76f 100644 --- a/crates/router/src/types/authentication.rs +++ b/crates/router/src/types/authentication.rs @@ -1,128 +1,14 @@ -use cards::CardNumber; -use common_utils::pii::Email; -use serde::{Deserialize, Serialize}; - -use super::{ - api::{self, authentication}, - domain, BrowserInformation, RouterData, +pub use hyperswitch_domain_models::{ + router_request_types::authentication::{ + AcquirerDetails, AuthNFlowType, ChallengeParams, ConnectorAuthenticationRequestData, + ConnectorPostAuthenticationRequestData, PreAuthNRequestData, PreAuthenticationData, + }, + router_response_types::AuthenticationResponseData, }; + +use super::{api, RouterData}; use crate::services; -#[derive(Debug, Clone)] -pub enum AuthenticationResponseData { - PreAuthNResponse { - threeds_server_transaction_id: String, - maximum_supported_3ds_version: common_utils::types::SemanticVersion, - connector_authentication_id: String, - three_ds_method_data: Option, - three_ds_method_url: Option, - message_version: common_utils::types::SemanticVersion, - connector_metadata: Option, - directory_server_id: Option, - }, - AuthNResponse { - authn_flow_type: AuthNFlowType, - authentication_value: Option, - trans_status: common_enums::TransactionStatus, - }, - PostAuthNResponse { - trans_status: common_enums::TransactionStatus, - authentication_value: Option, - eci: Option, - }, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct ChallengeParams { - pub acs_url: Option, - pub challenge_request: Option, - pub acs_reference_number: Option, - pub acs_trans_id: Option, - pub three_dsserver_trans_id: Option, - pub acs_signed_content: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub enum AuthNFlowType { - Challenge(Box), - Frictionless, -} - -impl AuthNFlowType { - pub fn get_acs_url(&self) -> Option { - if let Self::Challenge(challenge_params) = self { - challenge_params.acs_url.as_ref().map(ToString::to_string) - } else { - None - } - } - pub fn get_challenge_request(&self) -> Option { - if let Self::Challenge(challenge_params) = self { - challenge_params.challenge_request.clone() - } else { - None - } - } - pub fn get_acs_reference_number(&self) -> Option { - if let Self::Challenge(challenge_params) = self { - challenge_params.acs_reference_number.clone() - } else { - None - } - } - pub fn get_acs_trans_id(&self) -> Option { - if let Self::Challenge(challenge_params) = self { - challenge_params.acs_trans_id.clone() - } else { - None - } - } - pub fn get_acs_signed_content(&self) -> Option { - if let Self::Challenge(challenge_params) = self { - challenge_params.acs_signed_content.clone() - } else { - None - } - } - pub fn get_decoupled_authentication_type(&self) -> common_enums::DecoupledAuthenticationType { - match self { - Self::Challenge(_) => common_enums::DecoupledAuthenticationType::Challenge, - Self::Frictionless => common_enums::DecoupledAuthenticationType::Frictionless, - } - } -} - -#[derive(Clone, Default, Debug)] -pub struct PreAuthNRequestData { - // card number - #[allow(dead_code)] - pub(crate) card_holder_account_number: CardNumber, -} - -#[derive(Clone, Debug)] -pub struct ConnectorAuthenticationRequestData { - pub payment_method_data: domain::PaymentMethodData, - pub billing_address: api_models::payments::Address, - pub shipping_address: Option, - pub browser_details: Option, - pub amount: Option, - pub currency: Option, - pub message_category: authentication::MessageCategory, - pub device_channel: api_models::payments::DeviceChannel, - pub pre_authentication_data: crate::core::authentication::types::PreAuthenticationData, - pub return_url: Option, - pub sdk_information: Option, - pub email: Option, - pub threeds_method_comp_ind: api_models::payments::ThreeDsCompletionIndicator, - pub three_ds_requestor_url: String, - pub webhook_url: String, -} - -#[derive(Clone, Debug)] -pub struct ConnectorPostAuthenticationRequestData { - pub threeds_server_transaction_id: String, -} - pub type PreAuthNRouterData = RouterData; diff --git a/crates/router/src/types/fraud_check.rs b/crates/router/src/types/fraud_check.rs index 59be546b1c..da9e961031 100644 --- a/crates/router/src/types/fraud_check.rs +++ b/crates/router/src/types/fraud_check.rs @@ -1,12 +1,14 @@ -pub use hyperswitch_domain_models::router_request_types::fraud_check::{ - FraudCheckCheckoutData, FraudCheckFulfillmentData, FraudCheckRecordReturnData, - FraudCheckSaleData, FraudCheckTransactionData, RefundMethod, +pub use hyperswitch_domain_models::{ + router_request_types::fraud_check::{ + FraudCheckCheckoutData, FraudCheckFulfillmentData, FraudCheckRecordReturnData, + FraudCheckSaleData, FraudCheckTransactionData, RefundMethod, + }, + router_response_types::fraud_check::FraudCheckResponseData, }; use crate::{ - pii::Serialize, services, - types::{api, storage_enums, ErrorResponse, ResponseId, RouterData}, + types::{api, ErrorResponse, RouterData}, }; pub type FrmSaleRouterData = RouterData; @@ -40,27 +42,6 @@ pub enum FrmResponse { RecordReturn(Result), } -#[derive(Debug, Clone, Serialize)] -#[serde(untagged)] -pub enum FraudCheckResponseData { - TransactionResponse { - resource_id: ResponseId, - status: storage_enums::FraudCheckStatus, - connector_metadata: Option, - reason: Option, - score: Option, - }, - FulfillmentResponse { - order_id: String, - shipment_ids: Vec, - }, - RecordReturnResponse { - resource_id: ResponseId, - connector_metadata: Option, - return_id: Option, - }, -} - pub type FrmCheckoutRouterData = RouterData;