Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

chore: introduce RouterDataNew and FlowSpecificData models (#4961)

Hrithikesh656fb3e09a15
diff --git a/crates/hyperswitch_domain_models/src/lib.rs b/crates/hyperswitch_domain_models/src/lib.rs
index d9778353cd..863d1070c0 100644
--- a/crates/hyperswitch_domain_models/src/lib.rs
+++ b/crates/hyperswitch_domain_models/src/lib.rs
@@ -6,6 +6,7 @@ pub mod payments;
#[cfg(feature = "payouts")]
pub mod payouts;
pub mod router_data;
+pub mod router_data_new;
pub mod router_flow_types;
pub mod router_request_types;
pub mod router_response_types;
diff --git a/crates/hyperswitch_domain_models/src/router_data_new.rs b/crates/hyperswitch_domain_models/src/router_data_new.rs
new file mode 100644
index 0000000000..fb5291933b
--- /dev/null
+++ b/crates/hyperswitch_domain_models/src/router_data_new.rs
@@ -0,0 +1,27 @@
+pub mod flow_common_types;
+
+use std::{marker::PhantomData, ops::Deref};
+
+pub use flow_common_types::*;
+
+use crate::router_data::{ConnectorAuthType, ErrorResponse};
+
+#[derive(Debug, Clone)]
+pub struct RouterDataNew<Flow, ResourceCommonData, FlowSpecificRequest, FlowSpecificResponse> {
+ pub flow: PhantomData<Flow>,
+ pub resource_common_data: ResourceCommonData,
+ pub connector_auth_type: ConnectorAuthType,
+ /// Contains flow-specific data required to construct a request and send it to the connector.
+ pub request: FlowSpecificRequest,
+ /// Contains flow-specific data that the connector responds with.
+ pub response: Result<FlowSpecificResponse, ErrorResponse>,
+}
+
+impl<Flow, ResourceCommonData, FlowSpecificRequest, FlowSpecificResponse> Deref
+ for RouterDataNew<Flow, ResourceCommonData, FlowSpecificRequest, FlowSpecificResponse>
+{
+ type Target = ResourceCommonData;
+ fn deref(&self) -> &Self::Target {
+ &self.resource_common_data
+ }
+}
diff --git a/crates/hyperswitch_domain_models/src/router_data_new/flow_common_types.rs b/crates/hyperswitch_domain_models/src/router_data_new/flow_common_types.rs
new file mode 100644
index 0000000000..f4b21f3ef0
--- /dev/null
+++ b/crates/hyperswitch_domain_models/src/router_data_new/flow_common_types.rs
@@ -0,0 +1,150 @@
+use common_utils::{pii, types::MinorUnit};
+
+use crate::{
+ payment_address::PaymentAddress,
+ payment_method_data::ApplePayFlow,
+ router_data::{
+ AccessToken, ConnectorResponseData, PaymentMethodBalance, PaymentMethodToken,
+ RecurringMandatePaymentData,
+ },
+};
+
+#[derive(Debug, Clone)]
+pub struct PaymentFlowData {
+ pub merchant_id: String,
+ pub customer_id: Option<String>,
+ pub connector_customer: Option<String>,
+ pub payment_id: String,
+ pub attempt_id: String,
+ pub status: common_enums::AttemptStatus,
+ pub payment_method: common_enums::PaymentMethod,
+ pub description: Option<String>,
+ pub return_url: Option<String>,
+ pub address: PaymentAddress,
+ pub auth_type: common_enums::AuthenticationType,
+ pub connector_meta_data: Option<pii::SecretSerdeValue>,
+ pub amount_captured: Option<i64>,
+ // minor amount for amount framework
+ pub minor_amount_captured: Option<MinorUnit>,
+ pub access_token: Option<AccessToken>,
+ pub session_token: Option<String>,
+ pub reference_id: Option<String>,
+ pub payment_method_token: Option<PaymentMethodToken>,
+ pub recurring_mandate_payment_data: Option<RecurringMandatePaymentData>,
+ pub preprocessing_id: Option<String>,
+ /// This is the balance amount for gift cards or voucher
+ pub payment_method_balance: Option<PaymentMethodBalance>,
+
+ ///for switching between two different versions of the same connector
+ pub connector_api_version: Option<String>,
+ /// Contains a reference ID that should be sent in the connector request
+ pub connector_request_reference_id: String,
+
+ pub test_mode: Option<bool>,
+ pub connector_http_status_code: Option<u16>,
+ pub external_latency: Option<u128>,
+ /// Contains apple pay flow type simplified or manual
+ pub apple_pay_flow: Option<ApplePayFlow>,
+
+ /// This field is used to store various data regarding the response from connector
+ pub connector_response: Option<ConnectorResponseData>,
+ pub payment_method_status: Option<common_enums::PaymentMethodStatus>,
+}
+
+#[derive(Debug, Clone)]
+pub struct RefundFlowData {
+ pub merchant_id: String,
+ pub customer_id: Option<String>,
+ pub payment_id: String,
+ pub attempt_id: String,
+ pub status: common_enums::AttemptStatus,
+ pub payment_method: common_enums::PaymentMethod,
+ pub return_url: Option<String>,
+ pub connector_meta_data: Option<pii::SecretSerdeValue>,
+ pub amount_captured: Option<i64>,
+ // minor amount for amount framework
+ pub minor_amount_captured: Option<MinorUnit>,
+ /// Contains a reference ID that should be sent in the connector request
+ pub connector_request_reference_id: String,
+ pub refund_id: String,
+}
+
+#[cfg(feature = "payouts")]
+#[derive(Debug, Clone)]
+pub struct PayoutFlowData {
+ pub merchant_id: String,
+ pub customer_id: Option<String>,
+ pub connector_customer: Option<String>,
+ pub return_url: Option<String>,
+ pub address: PaymentAddress,
+ pub connector_meta_data: Option<pii::SecretSerdeValue>,
+ pub connector_wallets_details: Option<pii::SecretSerdeValue>,
+ /// Contains a reference ID that should be sent in the connector request
+ pub connector_request_reference_id: String,
+ pub payout_method_data: Option<api_models::payouts::PayoutMethodData>,
+ pub quote_id: Option<String>,
+}
+
+#[derive(Debug, Clone)]
+pub struct FrmFlowData {
+ pub merchant_id: String,
+ pub payment_id: String,
+ pub attempt_id: String,
+ pub payment_method: common_enums::enums::PaymentMethod,
+ pub connector_request_reference_id: String,
+ pub return_url: Option<String>,
+ pub auth_type: common_enums::enums::AuthenticationType,
+ pub connector_wallets_details: Option<pii::SecretSerdeValue>,
+ pub connector_meta_data: Option<pii::SecretSerdeValue>,
+ pub amount_captured: Option<i64>,
+ // minor amount for amount framework
+ pub minor_amount_captured: Option<MinorUnit>,
+}
+
+#[derive(Debug, Clone)]
+pub struct ExternalAuthenticationFlowData {
+ pub merchant_id: String,
+ pub connector_meta_data: Option<pii::SecretSerdeValue>,
+ pub address: PaymentAddress,
+}
+
+#[derive(Debug, Clone)]
+pub struct DisputesFlowData {
+ pub merchant_id: String,
+ pub payment_id: String,
+ pub attempt_id: String,
+ pub payment_method: common_enums::enums::PaymentMethod,
+ pub return_url: Option<String>,
+ pub connector_meta_data: Option<pii::SecretSerdeValue>,
+ pub amount_captured: Option<i64>,
+ // minor amount for amount framework
+ pub minor_amount_captured: Option<MinorUnit>,
+ /// Contains a reference ID that should be sent in the connector request
+ pub connector_request_reference_id: String,
+ pub dispute_id: String,
+}
+
+#[derive(Debug, Clone)]
+pub struct MandateRevokeFlowData {
+ pub merchant_id: String,
+ pub customer_id: String,
+ pub payment_id: Option<String>,
+}
+
+#[derive(Debug, Clone)]
+pub struct WebhookSourceVerifyData {
+ pub merchant_id: String,
+}
+
+#[derive(Debug, Clone)]
+pub struct AccessTokenFlowData {}
+
+#[derive(Debug, Clone)]
+pub struct FilesFlowData {
+ pub merchant_id: String,
+ pub payment_id: String,
+ pub attempt_id: String,
+ pub return_url: Option<String>,
+ pub connector_meta_data: Option<pii::SecretSerdeValue>,
+ pub connector_request_reference_id: String,
+}