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

This commit is contained in:
Hrithikesh
2024-05-30 20:24:50 +05:30
committed by GitHub
parent 08eefdba4a
commit 61e67e4272
18 changed files with 148 additions and 116 deletions

View File

@ -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;

View File

@ -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::*;

View File

@ -0,0 +1,2 @@
#[derive(Clone, Debug)]
pub struct AccessTokenAuth;

View File

@ -0,0 +1,7 @@
#[derive(Debug, Clone)]
pub struct Accept;
#[derive(Debug, Clone)]
pub struct Evidence;
#[derive(Debug, Clone)]
pub struct Defend;

View File

@ -0,0 +1,5 @@
#[derive(Debug, Clone)]
pub struct Retrieve;
#[derive(Debug, Clone)]
pub struct Upload;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,4 @@
#[derive(Debug, Clone)]
pub struct Execute;
#[derive(Debug, Clone)]
pub struct RSync;

View File

@ -0,0 +1,2 @@
#[derive(Clone, Debug)]
pub struct VerifyWebhookSource;

View File

@ -15,7 +15,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 {
@ -134,13 +134,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(),

View File

@ -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::*;
@ -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>
{
@ -66,9 +65,6 @@ pub enum ConnectorCallType {
SessionMultiple(Vec<SessionConnectorData>),
}
#[derive(Clone, Debug)]
pub struct VerifyWebhookSource;
pub trait ConnectorVerifyWebhookSource:
ConnectorIntegration<
VerifyWebhookSource,

View File

@ -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,
@ -58,9 +60,6 @@ pub enum EvidenceType {
UncategorizedFile,
}
#[derive(Debug, Clone)]
pub struct Accept;
pub trait AcceptDispute:
services::ConnectorIntegration<
Accept,
@ -70,9 +69,6 @@ pub trait AcceptDispute:
{
}
#[derive(Debug, Clone)]
pub struct Evidence;
pub trait SubmitEvidence:
services::ConnectorIntegration<
Evidence,
@ -82,9 +78,6 @@ pub trait SubmitEvidence:
{
}
#[derive(Debug, Clone)]
pub struct Defend;
pub trait DefendDispute:
services::ConnectorIntegration<
Defend,

View File

@ -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;
@ -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,

View File

@ -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::{
@ -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>
{

View File

@ -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,
@ -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>;
}

View File

@ -4,30 +4,12 @@ pub use api_models::payouts::{
PayoutListFilters, PayoutListResponse, PayoutMethodData, PayoutRequest, PayoutRetrieveBody,
PayoutRetrieveRequest, PixBankTransfer, SepaBankTransfer, Wallet as WalletPayout,
};
pub use hyperswitch_domain_models::router_flow_types::payouts::{
PoCancel, PoCreate, PoEligibility, PoFulfill, PoQuote, PoRecipient, PoRecipientAccount,
};
use crate::{services::api, types};
#[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;
pub trait PayoutCancel:
api::ConnectorIntegration<PoCancel, types::PayoutsData, types::PayoutsResponseData>
{

View File

@ -2,6 +2,7 @@ pub use api_models::refunds::{
RefundRequest, RefundResponse, RefundStatus, RefundType, RefundUpdateRequest,
RefundsRetrieveRequest,
};
pub use hyperswitch_domain_models::router_flow_types::refunds::{Execute, RSync};
use super::ConnectorCommon;
use crate::{
@ -21,11 +22,6 @@ impl ForeignFrom<storage_enums::RefundStatus> for RefundStatus {
}
}
#[derive(Debug, Clone)]
pub struct Execute;
#[derive(Debug, Clone)]
pub struct RSync;
pub trait RefundExecute:
api::ConnectorIntegration<Execute, types::RefundsData, types::RefundsResponseData>
{