Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): move router data flow types to hyperswitch domain models crate #4801

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/hyperswitch_domain_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod payments;
#[cfg(feature = "payouts")]
pub mod payouts;
pub mod router_data;
pub mod router_flow_types;
pub mod router_request_types;
pub mod router_response_types;

Expand Down
17 changes: 17 additions & 0 deletions crates/hyperswitch_domain_models/src/router_flow_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub mod access_token_auth;
pub mod dispute;
pub mod files;
pub mod fraud_check;
pub mod payments;
pub mod payouts;
pub mod refunds;
pub mod webhooks;

pub use access_token_auth::*;
pub use dispute::*;
pub use files::*;
pub use fraud_check::*;
pub use payments::*;
pub use payouts::*;
pub use refunds::*;
pub use webhooks::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(Clone, Debug)]
pub struct AccessTokenAuth;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Debug, Clone)]
pub struct Accept;
#[derive(Debug, Clone)]
pub struct Evidence;

#[derive(Debug, Clone)]
pub struct Defend;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[derive(Debug, Clone)]
pub struct Retrieve;

#[derive(Debug, Clone)]
pub struct Upload;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[derive(Debug, Clone)]
pub struct Sale;

#[derive(Debug, Clone)]
pub struct Checkout;

#[derive(Debug, Clone)]
pub struct Transaction;

#[derive(Debug, Clone)]
pub struct Fulfillment;

#[derive(Debug, Clone)]
pub struct RecordReturn;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Core related api layer.
#[derive(Debug, Clone)]
pub struct Authorize;

#[derive(Debug, Clone)]
pub struct AuthorizeSessionToken;

#[derive(Debug, Clone)]
pub struct CompleteAuthorize;

#[derive(Debug, Clone)]
pub struct Approve;

// Used in gift cards balance check
#[derive(Debug, Clone)]
pub struct Balance;

#[derive(Debug, Clone)]
pub struct InitPayment;

#[derive(Debug, Clone)]
pub struct Capture;

#[derive(Debug, Clone)]
pub struct PSync;
#[derive(Debug, Clone)]
pub struct Void;

#[derive(Debug, Clone)]
pub struct Reject;

#[derive(Debug, Clone)]
pub struct Session;

#[derive(Debug, Clone)]
pub struct PaymentMethodToken;

#[derive(Debug, Clone)]
pub struct CreateConnectorCustomer;

#[derive(Debug, Clone)]
pub struct SetupMandate;

#[derive(Debug, Clone)]
pub struct PreProcessing;

#[derive(Debug, Clone)]
pub struct IncrementalAuthorization;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[derive(Debug, Clone)]
pub struct PoCancel;

#[derive(Debug, Clone)]
pub struct PoCreate;

#[derive(Debug, Clone)]
pub struct PoEligibility;

#[derive(Debug, Clone)]
pub struct PoFulfill;

#[derive(Debug, Clone)]
pub struct PoQuote;

#[derive(Debug, Clone)]
pub struct PoRecipient;

#[derive(Debug, Clone)]
pub struct PoRecipientAccount;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[derive(Debug, Clone)]
pub struct Execute;
#[derive(Debug, Clone)]
pub struct RSync;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(Clone, Debug)]
pub struct VerifyWebhookSource;
14 changes: 10 additions & 4 deletions crates/hyperswitch_domain_models/src/router_request_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
errors::api_error_response::ApiErrorResponse,
mandates, payments,
router_data::{self, RouterData},
router_response_types as response_types,
router_flow_types as flows, router_response_types as response_types,
};
#[derive(Debug, Clone)]
pub struct PaymentsAuthorizeData {
Expand Down Expand Up @@ -125,13 +125,19 @@ impl TryFrom<SetupMandateRequestData> for ConnectorCustomerData {
})
}
}
impl<F> TryFrom<&RouterData<F, PaymentsAuthorizeData, response_types::PaymentsResponseData>>
for ConnectorCustomerData
impl
TryFrom<
&RouterData<flows::Authorize, PaymentsAuthorizeData, response_types::PaymentsResponseData>,
> for ConnectorCustomerData
{
type Error = error_stack::Report<ApiErrorResponse>;

fn try_from(
data: &RouterData<F, PaymentsAuthorizeData, response_types::PaymentsResponseData>,
data: &RouterData<
flows::Authorize,
PaymentsAuthorizeData,
response_types::PaymentsResponseData,
>,
) -> Result<Self, Self::Error> {
Ok(Self {
email: data.request.email.clone(),
Expand Down
10 changes: 3 additions & 7 deletions crates/router/src/types/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub mod webhooks;
use std::{fmt::Debug, str::FromStr};

use error_stack::{report, ResultExt};
pub use hyperswitch_domain_models::router_flow_types::{
access_token_auth::AccessTokenAuth, webhooks::VerifyWebhookSource,
};

#[cfg(feature = "frm")]
pub use self::fraud_check::*;
Expand All @@ -50,10 +53,6 @@ use crate::{
services::{request, ConnectorIntegration, ConnectorRedirectResponse, ConnectorValidation},
types::{self, api::enums as api_enums},
};

#[derive(Clone, Debug)]
pub struct AccessTokenAuth;

pub trait ConnectorAccessToken:
ConnectorIntegration<AccessTokenAuth, types::AccessTokenRequestData, types::AccessToken>
{
Expand All @@ -66,9 +65,6 @@ pub enum ConnectorCallType {
SessionMultiple(Vec<SessionConnectorData>),
}

#[derive(Clone, Debug)]
pub struct VerifyWebhookSource;

pub trait ConnectorVerifyWebhookSource:
ConnectorIntegration<
VerifyWebhookSource,
Expand Down
11 changes: 2 additions & 9 deletions crates/router/src/types/api/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub struct DisputeId {
pub dispute_id: String,
}

pub use hyperswitch_domain_models::router_flow_types::dispute::{Accept, Defend, Evidence};

#[derive(Default, Debug)]
pub struct DisputePayload {
pub amount: String,
Expand Down Expand Up @@ -58,9 +60,6 @@ pub enum EvidenceType {
UncategorizedFile,
}

#[derive(Debug, Clone)]
pub struct Accept;

pub trait AcceptDispute:
services::ConnectorIntegration<
Accept,
Expand All @@ -70,9 +69,6 @@ pub trait AcceptDispute:
{
}

#[derive(Debug, Clone)]
pub struct Evidence;

pub trait SubmitEvidence:
services::ConnectorIntegration<
Evidence,
Expand All @@ -82,9 +78,6 @@ pub trait SubmitEvidence:
{
}

#[derive(Debug, Clone)]
pub struct Defend;

pub trait DefendDispute:
services::ConnectorIntegration<
Defend,
Expand Down
7 changes: 1 addition & 6 deletions crates/router/src/types/api/files.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use api_models::enums::FileUploadProvider;
pub use hyperswitch_domain_models::router_flow_types::files::{Retrieve, Upload};
use masking::{Deserialize, Serialize};
use serde_with::serde_as;

Expand Down Expand Up @@ -67,17 +68,11 @@ pub enum FilePurpose {
DisputeEvidence,
}

#[derive(Debug, Clone)]
pub struct Upload;

pub trait UploadFile:
services::ConnectorIntegration<Upload, types::UploadFileRequestData, types::UploadFileResponse>
{
}

#[derive(Debug, Clone)]
pub struct Retrieve;

pub trait RetrieveFile:
services::ConnectorIntegration<
Retrieve,
Expand Down
18 changes: 3 additions & 15 deletions crates/router/src/types/api/fraud_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use std::str::FromStr;
use api_models::enums;
use common_utils::errors::CustomResult;
use error_stack::ResultExt;
pub use hyperswitch_domain_models::router_flow_types::fraud_check::{
Checkout, Fulfillment, RecordReturn, Sale, Transaction,
};

use super::{BoxedConnector, ConnectorData, SessionConnectorData};
use crate::{
Expand All @@ -15,41 +18,26 @@ use crate::{
},
};

#[derive(Debug, Clone)]
pub struct Sale;

pub trait FraudCheckSale:
api::ConnectorIntegration<Sale, FraudCheckSaleData, FraudCheckResponseData>
{
}

#[derive(Debug, Clone)]
pub struct Checkout;

pub trait FraudCheckCheckout:
api::ConnectorIntegration<Checkout, FraudCheckCheckoutData, FraudCheckResponseData>
{
}

#[derive(Debug, Clone)]
pub struct Transaction;

pub trait FraudCheckTransaction:
api::ConnectorIntegration<Transaction, FraudCheckTransactionData, FraudCheckResponseData>
{
}

#[derive(Debug, Clone)]
pub struct Fulfillment;

pub trait FraudCheckFulfillment:
api::ConnectorIntegration<Fulfillment, FraudCheckFulfillmentData, FraudCheckResponseData>
{
}

#[derive(Debug, Clone)]
pub struct RecordReturn;

pub trait FraudCheckRecordReturn:
api::ConnectorIntegration<RecordReturn, FraudCheckRecordReturnData, FraudCheckResponseData>
{
Expand Down
54 changes: 5 additions & 49 deletions crates/router/src/types/api/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pub use api_models::payments::{
WalletData,
};
use error_stack::ResultExt;
pub use hyperswitch_domain_models::router_flow_types::payments::{
Approve, Authorize, AuthorizeSessionToken, Balance, Capture, CompleteAuthorize,
CreateConnectorCustomer, IncrementalAuthorization, InitPayment, PSync, PaymentMethodToken,
PreProcessing, Reject, Session, SetupMandate, Void,
};

use crate::{
core::errors,
Expand All @@ -24,55 +29,6 @@ use crate::{

impl super::Router for PaymentsRequest {}

// Core related api layer.
#[derive(Debug, Clone)]
pub struct Authorize;

#[derive(Debug, Clone)]
pub struct AuthorizeSessionToken;

#[derive(Debug, Clone)]
pub struct CompleteAuthorize;

#[derive(Debug, Clone)]
pub struct Approve;

// Used in gift cards balance check
#[derive(Debug, Clone)]
pub struct Balance;

#[derive(Debug, Clone)]
pub struct InitPayment;

#[derive(Debug, Clone)]
pub struct Capture;

#[derive(Debug, Clone)]
pub struct PSync;
#[derive(Debug, Clone)]
pub struct Void;

#[derive(Debug, Clone)]
pub struct Reject;

#[derive(Debug, Clone)]
pub struct Session;

#[derive(Debug, Clone)]
pub struct PaymentMethodToken;

#[derive(Debug, Clone)]
pub struct CreateConnectorCustomer;

#[derive(Debug, Clone)]
pub struct SetupMandate;

#[derive(Debug, Clone)]
pub struct PreProcessing;

#[derive(Debug, Clone)]
pub struct IncrementalAuthorization;

pub trait PaymentIdTypeExt {
fn get_payment_intent_id(&self) -> errors::CustomResult<String, errors::ValidationError>;
}
Expand Down
Loading
Loading