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
refactor(core): move router data response and request models to hyperswitch domain models crate (#4789)
Hrithikeshdd333298f8b4
diff --git a/crates/hyperswitch_domain_models/src/lib.rs b/crates/hyperswitch_domain_models/src/lib.rsindex 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.rsindex 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<pii::SecretSerdeValue>,pub authentication_data: Option<AuthenticationData>,+ pub charges: Option<PaymentCharges>,+}++#[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<SetupMandateRequestData> for ConnectorCustomerData {+ type Error = error_stack::Report<ApiErrorResponse>;+ fn try_from(data: SetupMandateRequestData) -> Result<Self, Self::Error> {+ Ok(Self {+ email: data.email,+ payment_method_data: data.payment_method_data,+ description: None,+ phone: None,+ name: None,+ preprocessing_id: None,+ })+ }+}+impl<F> TryFrom<&RouterData<F, PaymentsAuthorizeData, response_types::PaymentsResponseData>>+ for ConnectorCustomerData+{+ type Error = error_stack::Report<ApiErrorResponse>;++ fn try_from(+ data: &RouterData<F, PaymentsAuthorizeData, response_types::PaymentsResponseData>,+ ) -> Result<Self, Self::Error> {+ 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<i64>,}+impl TryFrom<SetupMandateRequestData> for PaymentMethodTokenizationData {+ type Error = error_stack::Report<ApiErrorResponse>;++ fn try_from(data: SetupMandateRequestData) -> Result<Self, Self::Error> {+ Ok(Self {+ payment_method_data: data.payment_method_data,+ browser_info: None,+ currency: data.currency,+ amount: data.amount,+ })+ }+}+impl<F> From<&RouterData<F, PaymentsAuthorizeData, response_types::PaymentsResponseData>>+ for PaymentMethodTokenizationData+{+ fn from(+ data: &RouterData<F, PaymentsAuthorizeData, response_types::PaymentsResponseData>,+ ) -> 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<PaymentsAuthorizeData> for PaymentMethodTokenizationData {+ type Error = error_stack::Report<ApiErrorResponse>;++ fn try_from(data: PaymentsAuthorizeData) -> Result<Self, Self::Error> {+ Ok(Self {+ payment_method_data: data.payment_method_data,+ browser_info: data.browser_info,+ currency: data.currency,+ amount: Some(data.amount),+ })+ }+}++impl TryFrom<CompleteAuthorizeData> for PaymentMethodTokenizationData {+ type Error = error_stack::Report<ApiErrorResponse>;++ fn try_from(data: CompleteAuthorizeData) -> Result<Self, Self::Error> {+ 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<PaymentMethodData>,@@ -126,6 +229,53 @@ pub struct PaymentsPreProcessingData {pub redirect_response: Option<CompleteAuthorizeRedirectResponse>,}+impl TryFrom<PaymentsAuthorizeData> for PaymentsPreProcessingData {+ type Error = error_stack::Report<ApiErrorResponse>;++ fn try_from(data: PaymentsAuthorizeData) -> Result<Self, Self::Error> {+ 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<CompleteAuthorizeData> for PaymentsPreProcessingData {+ type Error = error_stack::Report<ApiErrorResponse>;++ fn try_from(data: CompleteAuthorizeData) -> Result<Self, Self::Error> {+ 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<PaymentMethodData>,@@ -165,6 +315,7 @@ pub struct PaymentsSyncData {pub mandate_id: Option<api_models::payments::MandateIds>,pub payment_method_type: Option<storage_enums::PaymentMethodType>,pub currency: storage_enums::Currency,+ pub payment_experience: Option<common_enums::PaymentExperience>,}#[derive(Debug, Default, Clone)]@@ -352,7 +503,7 @@ pub struct AccessTokenRequestData {}impl TryFrom<router_data::ConnectorAuthType> for AccessTokenRequestData {- type Error = api_error_response::ApiErrorResponse;+ type Error = ApiErrorResponse;fn try_from(connector_auth: router_data::ConnectorAuthType) -> Result<Self, Self::Error> {match connector_auth {router_data::ConnectorAuthType::HeaderKey { api_key } => Ok(Self {@@ -372,7 +523,7 @@ impl TryFrom<router_data::ConnectorAuthType> 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<u8>,pub merchant_secret: api_models::webhooks::ConnectorWebhookSecrets,}++#[derive(Debug, Clone)]+pub struct MandateRevokeRequestData {+ pub mandate_id: String,+ pub connector_mandate_id: Option<String>,+}++#[derive(Debug, Clone)]+pub struct PaymentsSessionData {+ pub amount: i64,+ pub currency: common_enums::Currency,+ pub country: Option<common_enums::CountryAlpha2>,+ pub surcharge_details: Option<SurchargeDetails>,+ pub order_details: Option<Vec<api_models::payments::OrderDetailsWithAmount>>,+}++#[derive(Debug, Clone)]+pub struct SetupMandateRequestData {+ pub currency: storage_enums::Currency,+ pub payment_method_data: PaymentMethodData,+ pub amount: Option<i64>,+ pub confirm: bool,+ pub statement_descriptor_suffix: Option<String>,+ pub customer_acceptance: Option<mandates::CustomerAcceptance>,+ pub mandate_id: Option<api_models::payments::MandateIds>,+ pub setup_future_usage: Option<storage_enums::FutureUsage>,+ pub off_session: Option<bool>,+ pub setup_mandate_details: Option<mandates::MandateData>,+ pub router_return_url: Option<String>,+ pub browser_info: Option<BrowserInformation>,+ pub email: Option<pii::Email>,+ pub customer_name: Option<Secret<String>>,+ pub return_url: Option<String>,+ pub payment_method_type: Option<storage_enums::PaymentMethodType>,+ pub request_incremental_authorization: bool,+ pub metadata: Option<pii::SecretSerdeValue>,+}diff --git a/crates/hyperswitch_domain_models/src/router_request_types/authentication.rs b/crates/hyperswitch_domain_models/src/router_request_types/authentication.rsindex 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<String>,- three_ds_method_url: Option<String>,- message_version: common_utils::types::SemanticVersion,- connector_metadata: Option<serde_json::Value>,- },- AuthNResponse {- authn_flow_type: AuthNFlowType,- authentication_value: Option<String>,- trans_status: common_enums::TransactionStatus,- },- PostAuthNResponse {- trans_status: common_enums::TransactionStatus,- authentication_value: Option<String>,- eci: Option<String>,- },-}-#[derive(Clone, Debug, Serialize, Deserialize)]pub struct ChallengeParams {pub acs_url: Option<url::Url>,@@ -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.rsnew file mode 100644index 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<i32>, // Calculation for amount received not in place yet+}++#[derive(Debug, Clone)]+pub enum PaymentsResponseData {+ TransactionResponse {+ resource_id: ResponseId,+ redirection_data: Option<RedirectForm>,+ mandate_reference: Option<MandateReference>,+ connector_metadata: Option<serde_json::Value>,+ network_txn_id: Option<String>,+ connector_response_reference_id: Option<String>,+ incremental_authorization_allowed: Option<bool>,+ charge_id: Option<String>,+ },+ MultipleCaptureResponse {+ // pending_capture_id_list: Vec<String>,+ capture_sync_response_list: HashMap<String, CaptureSyncResponse>,+ },+ 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<api_models::enums::UnresolvedResponseReason>,+ connector_response_reference_id: Option<String>,+ },+ TokenizationResponse {+ token: String,+ },++ ConnectorCustomerResponse {+ connector_customer_id: String,+ },++ ThreeDSEnrollmentResponse {+ enrolled_v2: bool,+ related_transaction_id: Option<String>,+ },+ PreProcessingResponse {+ pre_processing_id: PreprocessingResponseId,+ connector_metadata: Option<serde_json::Value>,+ session_token: Option<api_models::payments::SessionToken>,+ connector_response_reference_id: Option<String>,+ },+ IncrementalAuthorizationResponse {+ status: common_enums::AuthorizationStatus,+ connector_authorization_id: Option<String>,+ error_code: Option<String>,+ error_message: Option<String>,+ },+}++#[derive(serde::Serialize, Debug, Clone)]+pub struct MandateReference {+ pub connector_mandate_id: Option<String>,+ pub payment_method_id: Option<String>,+}++#[derive(Debug, Clone)]+pub enum CaptureSyncResponse {+ Success {+ resource_id: ResponseId,+ status: common_enums::AttemptStatus,+ connector_response_reference_id: Option<String>,+ amount: Option<MinorUnit>,+ },+ Error {+ code: String,+ message: String,+ reason: Option<String>,+ status_code: u16,+ amount: Option<MinorUnit>,+ },+}++impl CaptureSyncResponse {+ pub fn get_amount_captured(&self) -> Option<MinorUnit> {+ match self {+ Self::Success { amount, .. } | Self::Error { amount, .. } => *amount,+ }+ }+ pub fn get_connector_response_reference_id(&self) -> Option<String> {+ 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<String, String>,+ },+ 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<String>,+ 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<u8>,+}++#[cfg(feature = "payouts")]+#[derive(Clone, Debug, Default)]+pub struct PayoutsResponseData {+ pub status: Option<common_enums::PayoutStatus>,+ pub connector_payout_id: String,+ pub payout_eligible: Option<bool>,+ 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<String>,+ three_ds_method_url: Option<String>,+ message_version: common_utils::types::SemanticVersion,+ connector_metadata: Option<serde_json::Value>,+ directory_server_id: Option<String>,+ },+ AuthNResponse {+ authn_flow_type: AuthNFlowType,+ authentication_value: Option<String>,+ trans_status: common_enums::TransactionStatus,+ },+ PostAuthNResponse {+ trans_status: common_enums::TransactionStatus,+ authentication_value: Option<String>,+ eci: Option<String>,+ },+}++#[derive(Debug, Clone)]+pub struct CompleteAuthorizeRedirectResponse {+ pub params: Option<masking::Secret<String>>,+ pub payload: Option<common_utils::pii::SecretSerdeValue>,+}diff --git a/crates/hyperswitch_domain_models/src/router_response_types/disputes.rs b/crates/hyperswitch_domain_models/src/router_response_types/disputes.rsnew file mode 100644index 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<String>,+}++#[derive(Default, Clone, Debug)]+pub struct SubmitEvidenceResponse {+ pub dispute_status: api_models::enums::DisputeStatus,+ pub connector_status: Option<String>,+}++#[derive(Default, Debug, Clone)]+pub struct DefendDisputeResponse {+ pub dispute_status: api_models::enums::DisputeStatus,+ pub connector_status: Option<String>,+}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.rsnew file mode 100644index 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<serde_json::Value>,+ reason: Option<serde_json::Value>,+ score: Option<i32>,+ },+ FulfillmentResponse {+ order_id: String,+ shipment_ids: Vec<String>,+ },+ RecordReturnResponse {+ resource_id: ResponseId,+ connector_metadata: Option<serde_json::Value>,+ return_id: Option<String>,+ },+}++impl common_utils::events::ApiEventMetric for FraudCheckResponseData {+ fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {+ Some(common_utils::events::ApiEventsType::FraudCheck)+ }+}diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rsindex 1a63dc50c9..e38edeaa85 100644--- a/crates/router/src/connector/adyen.rs+++ b/crates/router/src/connector/adyen.rs@@ -367,7 +367,7 @@ impl) -> CustomResult<RequestContent, errors::ConnectorError> {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.rsindex e4d6ab0be4..bc556336c3 100644--- a/crates/router/src/connector/nuvei.rs+++ b/crates/router/src/connector/nuvei.rs@@ -539,7 +539,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P> = 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.rsindex 83bca39626..5bc2dfa2af 100644--- a/crates/router/src/connector/stripe/transformers.rs+++ b/crates/router/src/connector/stripe/transformers.rs@@ -2377,7 +2377,7 @@ impl<F, T>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<F, T>.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<F, T>.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<ErrorDetails>, u16, String)> for types::PaymentsResponseData {+impl ForeignTryFrom<(&Option<ErrorDetails>, u16, String)> for types::PaymentsResponseData {type Error = types::ErrorResponse;- fn try_from(+ fn foreign_try_from((response, http_code, response_id): (&Option<ErrorDetails>, u16, String),) -> Result<Self, Self::Error> {let (code, error_message) = match response {diff --git a/crates/router/src/core/authentication/types.rs b/crates/router/src/core/authentication/types.rsindex 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<F>,- 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<F>,- 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<String>,- pub acquirer_merchant_id: Option<String>,- pub connector_metadata: Option<serde_json::Value>,-}impl ForeignTryFrom<&storage::Authentication> for PreAuthenticationData {type Error = Report<errors::ApiErrorResponse>;@@ -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<String>,-}-#[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<bool>,-}diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rsindex 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<F: Clone>(Ok(router_data.clone())}}--impl<F> TryFrom<&types::RouterData<F, types::PaymentsAuthorizeData, types::PaymentsResponseData>>- for types::ConnectorCustomerData-{- type Error = error_stack::Report<errors::ApiErrorResponse>;-- fn try_from(- data: &types::RouterData<F, types::PaymentsAuthorizeData, types::PaymentsResponseData>,- ) -> Result<Self, Self::Error> {- 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<types::PaymentsAuthorizeData> for types::PaymentMethodTokenizationData {- type Error = error_stack::Report<errors::ApiErrorResponse>;-- fn try_from(data: types::PaymentsAuthorizeData) -> Result<Self, Self::Error> {- Ok(Self {- payment_method_data: data.payment_method_data,- browser_info: data.browser_info,- currency: data.currency,- amount: Some(data.amount),- })- }-}--impl TryFrom<types::PaymentsAuthorizeData> for types::PaymentsPreProcessingData {- type Error = error_stack::Report<errors::ApiErrorResponse>;-- fn try_from(data: types::PaymentsAuthorizeData) -> Result<Self, Self::Error> {- 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<types::CompleteAuthorizeData> for types::PaymentsPreProcessingData {- type Error = error_stack::Report<errors::ApiErrorResponse>;-- fn try_from(data: types::CompleteAuthorizeData) -> Result<Self, Self::Error> {- 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.rsindex 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<F: Clone>(Ok(router_data.clone())}}--impl TryFrom<types::CompleteAuthorizeData> for types::PaymentMethodTokenizationData {- type Error = error_stack::Report<errors::ApiErrorResponse>;-- fn try_from(data: types::CompleteAuthorizeData) -> Result<Self, Self::Error> {- 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.rsindex 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<api::SetupMandate, types::SetupMandateRequestData> for types::Setup}}-impl TryFrom<types::SetupMandateRequestData> for types::ConnectorCustomerData {- type Error = error_stack::Report<errors::ApiErrorResponse>;- fn try_from(data: types::SetupMandateRequestData) -> Result<Self, Self::Error> {- 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<types::SetupMandateRequestData> for types::PaymentMethodTokenizationData {- type Error = error_stack::Report<errors::ApiErrorResponse>;-- fn try_from(data: types::SetupMandateRequestData) -> Result<Self, Self::Error> {- 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.rsindex 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.rsindex 8f6af2f89b..d8a7092455 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -1617,10 +1617,12 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ}}-impl TryFrom<types::CaptureSyncResponse> for storage::CaptureUpdate {+impl ForeignTryFrom<types::CaptureSyncResponse> for storage::CaptureUpdate {type Error = error_stack::Report<errors::ApiErrorResponse>;- fn try_from(capture_sync_response: types::CaptureSyncResponse) -> Result<Self, Self::Error> {+ fn foreign_try_from(+ capture_sync_response: types::CaptureSyncResponse,+ ) -> Result<Self, Self::Error> {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.rsindex 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.rsindex 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<ApiEventsType> {- Some(ApiEventsType::FraudCheck)- }-}diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rsindex 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<String, String>,- },- 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<String>,- 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.rsindex 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<api::Authorize, PaymentsAuthorizeData, PaymentsResponseData>;@@ -300,237 +306,6 @@ impl PayoutIndividualDetailsExt for api_models::payouts::PayoutIndividualDetails}}-#[cfg(feature = "payouts")]-#[derive(Clone, Debug, Default)]-pub struct PayoutsResponseData {- pub status: Option<storage_enums::PayoutStatus>,- pub connector_payout_id: String,- pub payout_eligible: Option<bool>,- 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<Email>,- pub customer_name: Option<Secret<String>>,- pub currency: storage_enums::Currency,- pub confirm: bool,- pub statement_descriptor_suffix: Option<String>,- pub statement_descriptor: Option<String>,- pub capture_method: Option<storage_enums::CaptureMethod>,- pub router_return_url: Option<String>,- pub webhook_url: Option<String>,- pub complete_authorize_url: Option<String>,- // Mandates- pub setup_future_usage: Option<storage_enums::FutureUsage>,- pub mandate_id: Option<api_models::payments::MandateIds>,- pub off_session: Option<bool>,- pub customer_acceptance: Option<CustomerAcceptance>,- pub setup_mandate_details: Option<MandateData>,- pub browser_info: Option<BrowserInformation>,- pub order_details: Option<Vec<api_models::payments::OrderDetailsWithAmount>>,- pub order_category: Option<String>,- pub session_token: Option<String>,- pub enrolled_for_3ds: bool,- pub related_transaction_id: Option<String>,- pub payment_experience: Option<storage_enums::PaymentExperience>,- pub payment_method_type: Option<storage_enums::PaymentMethodType>,- pub surcharge_details: Option<types::SurchargeDetails>,- pub customer_id: Option<String>,- pub request_incremental_authorization: bool,- pub metadata: Option<pii::SecretSerdeValue>,- pub authentication_data: Option<AuthenticationData>,- pub charges: Option<types::PaymentCharges>,-}--#[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<MultipleCaptureRequestData>,- pub connector_meta: Option<serde_json::Value>,- pub browser_info: Option<BrowserInformation>,- pub metadata: Option<pii::SecretSerdeValue>,- // 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<String>,- 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<i64>,- pub currency: storage_enums::Currency,- pub connector_transaction_id: String,- pub amount: Option<i64>,-}--#[derive(Debug, Clone)]-pub struct ConnectorCustomerData {- pub description: Option<String>,- pub email: Option<Email>,- pub phone: Option<Secret<String>>,- pub name: Option<Secret<String>>,- pub preprocessing_id: Option<String>,- pub payment_method_data: domain::PaymentMethodData,-}--#[derive(Debug, Clone)]-pub struct PaymentMethodTokenizationData {- pub payment_method_data: domain::payments::PaymentMethodData,- pub browser_info: Option<BrowserInformation>,- pub currency: storage_enums::Currency,- pub amount: Option<i64>,-}--#[derive(Debug, Clone)]-pub struct PaymentsPreProcessingData {- pub payment_method_data: Option<domain::payments::PaymentMethodData>,- pub amount: Option<i64>,- pub email: Option<Email>,- pub currency: Option<storage_enums::Currency>,- pub payment_method_type: Option<storage_enums::PaymentMethodType>,- pub setup_mandate_details: Option<MandateData>,- pub capture_method: Option<storage_enums::CaptureMethod>,- pub order_details: Option<Vec<api_models::payments::OrderDetailsWithAmount>>,- pub router_return_url: Option<String>,- pub webhook_url: Option<String>,- pub complete_authorize_url: Option<String>,- pub surcharge_details: Option<types::SurchargeDetails>,- pub browser_info: Option<BrowserInformation>,- pub connector_transaction_id: Option<String>,- pub redirect_response: Option<CompleteAuthorizeRedirectResponse>,-}--#[derive(Debug, Clone)]-pub struct CompleteAuthorizeData {- pub payment_method_data: Option<domain::PaymentMethodData>,- pub amount: i64,- pub email: Option<Email>,- pub currency: storage_enums::Currency,- pub confirm: bool,- pub statement_descriptor_suffix: Option<String>,- pub capture_method: Option<storage_enums::CaptureMethod>,- // Mandates- pub setup_future_usage: Option<storage_enums::FutureUsage>,- pub mandate_id: Option<api_models::payments::MandateIds>,- pub off_session: Option<bool>,- pub setup_mandate_details: Option<MandateData>,- pub redirect_response: Option<CompleteAuthorizeRedirectResponse>,- pub browser_info: Option<BrowserInformation>,- pub connector_transaction_id: Option<String>,- pub connector_meta: Option<serde_json::Value>,- pub complete_authorize_url: Option<String>,- pub metadata: Option<pii::SecretSerdeValue>,-}--#[derive(Debug, Clone)]-pub struct CompleteAuthorizeRedirectResponse {- pub params: Option<Secret<String>>,- pub payload: Option<pii::SecretSerdeValue>,-}--#[derive(Debug, Default, Clone)]-pub struct PaymentsSyncData {- //TODO : add fields based on the connector requirements- pub connector_transaction_id: ResponseId,- pub encoded_data: Option<String>,- pub capture_method: Option<storage_enums::CaptureMethod>,- pub connector_meta: Option<serde_json::Value>,- pub sync_type: SyncRequestType,- pub mandate_id: Option<api_models::payments::MandateIds>,- pub payment_method_type: Option<storage_enums::PaymentMethodType>,- pub currency: storage_enums::Currency,- pub payment_experience: Option<storage_enums::PaymentExperience>,-}--#[derive(Debug, Default, Clone)]-pub enum SyncRequestType {- MultipleCaptureSync(Vec<String>),- #[default]- SinglePaymentSync,-}--#[derive(Debug, Default, Clone)]-pub struct PaymentsCancelData {- pub amount: Option<i64>,- pub currency: Option<storage_enums::Currency>,- pub connector_transaction_id: String,- pub cancellation_reason: Option<String>,- pub connector_meta: Option<serde_json::Value>,- pub browser_info: Option<BrowserInformation>,- pub metadata: Option<pii::SecretSerdeValue>,- // This metadata is used to store the metadata shared during the payment intent request.-}--#[derive(Debug, Default, Clone)]-pub struct PaymentsRejectData {- pub amount: Option<i64>,- pub currency: Option<storage_enums::Currency>,-}--#[derive(Debug, Default, Clone)]-pub struct PaymentsApproveData {- pub amount: Option<i64>,- pub currency: Option<storage_enums::Currency>,-}--#[derive(Debug, Clone)]-pub struct PaymentsSessionData {- pub amount: i64,- pub currency: storage_enums::Currency,- pub country: Option<api::enums::CountryAlpha2>,- pub surcharge_details: Option<types::SurchargeDetails>,- pub order_details: Option<Vec<api_models::payments::OrderDetailsWithAmount>>,-}--#[derive(Debug, Clone)]-pub struct SetupMandateRequestData {- pub currency: storage_enums::Currency,- pub payment_method_data: domain::PaymentMethodData,- pub amount: Option<i64>,- pub confirm: bool,- pub statement_descriptor_suffix: Option<String>,- pub customer_acceptance: Option<CustomerAcceptance>,- pub mandate_id: Option<api_models::payments::MandateIds>,- pub setup_future_usage: Option<storage_enums::FutureUsage>,- pub off_session: Option<bool>,- pub setup_mandate_details: Option<MandateData>,- pub router_return_url: Option<String>,- pub browser_info: Option<BrowserInformation>,- pub email: Option<Email>,- pub customer_name: Option<Secret<String>>,- pub return_url: Option<String>,- pub payment_method_type: Option<storage_enums::PaymentMethodType>,- pub request_incremental_authorization: bool,- pub metadata: Option<pii::SecretSerdeValue>,-}-pub trait Capturable {fn get_captured_amount<F>(&self, _payment_data: &PaymentData<F>) -> Option<i64>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<String>,- pub payment_method_id: Option<String>,-}--#[derive(Debug, Clone)]-pub enum CaptureSyncResponse {- Success {- resource_id: ResponseId,- status: storage_enums::AttemptStatus,- connector_response_reference_id: Option<String>,- amount: Option<MinorUnit>,- },- Error {- code: String,- message: String,- reason: Option<String>,- status_code: u16,- amount: Option<MinorUnit>,- },-}--impl CaptureSyncResponse {- pub fn get_amount_captured(&self) -> Option<MinorUnit> {- match self {- Self::Success { amount, .. } | Self::Error { amount, .. } => *amount,- }- }- pub fn get_connector_response_reference_id(&self) -> Option<String> {- 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<services::RedirectForm>,- mandate_reference: Option<MandateReference>,- connector_metadata: Option<serde_json::Value>,- network_txn_id: Option<String>,- connector_response_reference_id: Option<String>,- incremental_authorization_allowed: Option<bool>,- charge_id: Option<String>,- },- MultipleCaptureResponse {- // pending_capture_id_list: Vec<String>,- capture_sync_response_list: HashMap<String, CaptureSyncResponse>,- },- 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<api::enums::UnresolvedResponseReason>,- connector_response_reference_id: Option<String>,- },- TokenizationResponse {- token: String,- },-- ConnectorCustomerResponse {- connector_customer_id: String,- },-- ThreeDSEnrollmentResponse {- enrolled_v2: bool,- related_transaction_id: Option<String>,- },- PreProcessingResponse {- pre_processing_id: PreprocessingResponseId,- connector_metadata: Option<serde_json::Value>,- session_token: Option<api::SessionToken>,- connector_response_reference_id: Option<String>,- },- IncrementalAuthorizationResponse {- status: common_enums::AuthorizationStatus,- connector_authorization_id: Option<String>,- error_code: Option<String>,- error_message: Option<String>,- },-}--#[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<i32>, // 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<String>,-}--#[derive(Default, Clone, Debug)]-pub struct SubmitEvidenceResponse {- pub dispute_status: api_models::enums::DisputeStatus,- pub connector_status: Option<String>,-}--#[derive(Default, Debug, Clone)]-pub struct DefendDisputeResponse {- pub dispute_status: api_models::enums::DisputeStatus,- pub connector_status: Option<String>,-}--#[derive(Default, Clone, Debug)]-pub struct UploadFileResponse {- pub provider_file_id: String,-}-#[derive(Clone, Debug)]-pub struct RetrieveFileResponse {- pub file_data: Vec<u8>,-}-#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]pub struct PollConfig {pub delay_in_secs: i8,@@ -961,17 +591,6 @@ pub struct ResponseRouterData<Flow, R, Request, Response> {pub http_code: u16,}-#[derive(Debug, Clone)]-pub struct MandateRevokeRequestData {- pub mandate_id: String,- pub connector_mandate_id: Option<String>,-}--#[derive(Debug, Clone)]-pub struct MandateRevokeResponseData {- pub mandate_status: MandateStatus,-}-impl ForeignFrom<api_models::admin::ConnectorAuthType> for ConnectorAuthType {fn foreign_from(value: api_models::admin::ConnectorAuthType) -> Self {match value {@@ -1098,8 +717,8 @@ impl ForeignTryFrom<ConnectorAuthType> 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<F> From<&RouterData<F, PaymentsAuthorizeData, PaymentsResponseData>>- for PaymentMethodTokenizationData-{- fn from(data: &RouterData<F, PaymentsAuthorizeData, PaymentsResponseData>) -> 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<String>);}@@ -1140,8 +746,8 @@ impl Tokenizable for CompleteAuthorizeData {fn set_session_token(&mut self, _token: Option<String>) {}}-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.rsindex 97ad8506d4..2ca918f76f 100644--- a/crates/router/src/types/authentication.rs+++ b/crates/router/src/types/authentication.rs@@ -1,127 +1,13 @@-use cards::CardNumber;-use common_utils::pii::Email;-use serde::{Deserialize, Serialize};--use super::{- api::{self, authentication},- domain, BrowserInformation, 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<String>,- three_ds_method_url: Option<String>,- message_version: common_utils::types::SemanticVersion,- connector_metadata: Option<serde_json::Value>,- directory_server_id: Option<String>,+pub use hyperswitch_domain_models::{+ router_request_types::authentication::{+ AcquirerDetails, AuthNFlowType, ChallengeParams, ConnectorAuthenticationRequestData,+ ConnectorPostAuthenticationRequestData, PreAuthNRequestData, PreAuthenticationData,},- AuthNResponse {- authn_flow_type: AuthNFlowType,- authentication_value: Option<String>,- trans_status: common_enums::TransactionStatus,- },- PostAuthNResponse {- trans_status: common_enums::TransactionStatus,- authentication_value: Option<String>,- eci: Option<String>,- },-}--#[derive(Clone, Debug, Serialize, Deserialize)]-pub struct ChallengeParams {- pub acs_url: Option<url::Url>,- pub challenge_request: Option<String>,- pub acs_reference_number: Option<String>,- pub acs_trans_id: Option<String>,- pub three_dsserver_trans_id: Option<String>,- pub acs_signed_content: Option<String>,-}--#[derive(Clone, Debug, Serialize, Deserialize)]-pub enum AuthNFlowType {- Challenge(Box<ChallengeParams>),- Frictionless,-}--impl AuthNFlowType {- pub fn get_acs_url(&self) -> Option<String> {- 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<String> {- if let Self::Challenge(challenge_params) = self {- challenge_params.challenge_request.clone()- } else {- None- }- }- pub fn get_acs_reference_number(&self) -> Option<String> {- if let Self::Challenge(challenge_params) = self {- challenge_params.acs_reference_number.clone()- } else {- None- }- }- pub fn get_acs_trans_id(&self) -> Option<String> {- if let Self::Challenge(challenge_params) = self {- challenge_params.acs_trans_id.clone()- } else {- None- }- }- pub fn get_acs_signed_content(&self) -> Option<String> {- 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<api_models::payments::Address>,- pub browser_details: Option<BrowserInformation>,- pub amount: Option<i64>,- pub currency: Option<common_enums::Currency>,- 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<String>,- pub sdk_information: Option<api_models::payments::SdkInformation>,- pub email: Option<Email>,- pub threeds_method_comp_ind: api_models::payments::ThreeDsCompletionIndicator,- pub three_ds_requestor_url: String,- pub webhook_url: String,-}+ router_response_types::AuthenticationResponseData,+};-#[derive(Clone, Debug)]-pub struct ConnectorPostAuthenticationRequestData {- pub threeds_server_transaction_id: String,-}+use super::{api, RouterData};+use crate::services;pub type PreAuthNRouterData =RouterData<api::PreAuthentication, PreAuthNRequestData, AuthenticationResponseData>;diff --git a/crates/router/src/types/fraud_check.rs b/crates/router/src/types/fraud_check.rsindex 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<api::Sale, FraudCheckSaleData, FraudCheckResponseData>;@@ -40,27 +42,6 @@ pub enum FrmResponse {RecordReturn(Result<FraudCheckResponseData, ErrorResponse>),}-#[derive(Debug, Clone, Serialize)]-#[serde(untagged)]-pub enum FraudCheckResponseData {- TransactionResponse {- resource_id: ResponseId,- status: storage_enums::FraudCheckStatus,- connector_metadata: Option<serde_json::Value>,- reason: Option<serde_json::Value>,- score: Option<i32>,- },- FulfillmentResponse {- order_id: String,- shipment_ids: Vec<String>,- },- RecordReturnResponse {- resource_id: ResponseId,- connector_metadata: Option<serde_json::Value>,- return_id: Option<String>,- },-}-pub type FrmCheckoutRouterData =RouterData<api::Checkout, FraudCheckCheckoutData, FraudCheckResponseData>;