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: move Payout traits to hyperswitch_interfaces for connectors crate #6481

Merged
merged 10 commits into from
Nov 12, 2024
48 changes: 48 additions & 0 deletions crates/hyperswitch_connectors/src/default_implementations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,54 @@ default_imp_for_file_upload!(
connectors::Zsl
);

macro_rules! default_imp_for_payouts {
($($path:ident::$connector:ident),*) => {
$(
impl api::Payouts for $path::$connector {}
)*
};
}

default_imp_for_payouts!(
connectors::Airwallex,
connectors::Bambora,
connectors::Billwerk,
connectors::Bitpay,
connectors::Cashtocode,
connectors::Cryptopay,
connectors::Coinbase,
connectors::Deutschebank,
connectors::Digitalvirgo,
connectors::Dlocal,
connectors::Elavon,
connectors::Fiserv,
connectors::Fiservemea,
connectors::Fiuu,
connectors::Forte,
connectors::Globepay,
connectors::Helcim,
connectors::Jpmorgan,
connectors::Mollie,
connectors::Multisafepay,
connectors::Nexinets,
connectors::Nexixpay,
connectors::Novalnet,
connectors::Payeezy,
connectors::Payu,
connectors::Powertranz,
connectors::Razorpay,
connectors::Shift4,
connectors::Square,
connectors::Stax,
connectors::Taxjar,
connectors::Tsys,
connectors::Volt,
connectors::Worldline,
connectors::Worldpay,
connectors::Zen,
connectors::Zsl
);

#[cfg(feature = "payouts")]
macro_rules! default_imp_for_payouts_create {
($($path:ident::$connector:ident),*) => {
Expand Down
6 changes: 6 additions & 0 deletions crates/hyperswitch_interfaces/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ use masking::Maskable;
use router_env::metrics::add_attributes;
use serde_json::json;

#[cfg(feature = "payouts")]
pub use self::payouts::*;
pub use self::{payments::*, refunds::*};
use crate::{
configs::Connectors, connector_integration_v2::ConnectorIntegrationV2, consts, errors,
Expand Down Expand Up @@ -410,3 +412,7 @@ pub trait ConnectorRedirectResponse {
Ok(CallConnectorAction::Avoid)
}
}

/// Empty trait for when payouts feature is disabled
#[cfg(not(feature = "payouts"))]
pub trait Payouts {}
26 changes: 21 additions & 5 deletions crates/hyperswitch_interfaces/src/api/payouts.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Payouts interface

use hyperswitch_domain_models::router_flow_types::payouts::{
PoCancel, PoCreate, PoEligibility, PoFulfill, PoQuote, PoRecipient, PoRecipientAccount, PoSync,
};
#[cfg(feature = "payouts")]
use hyperswitch_domain_models::{
router_request_types::PayoutsData, router_response_types::PayoutsResponseData,
router_flow_types::payouts::{
PoCancel, PoCreate, PoEligibility, PoFulfill, PoQuote, PoRecipient, PoRecipientAccount,
PoSync,
},
router_request_types::PayoutsData,
router_response_types::PayoutsResponseData,
};

use super::ConnectorCommon;
use crate::api::ConnectorIntegration;

/// trait PayoutCancel
Expand Down Expand Up @@ -42,3 +44,17 @@ pub trait PayoutRecipientAccount:

/// trait PayoutSync
pub trait PayoutSync: ConnectorIntegration<PoSync, PayoutsData, PayoutsResponseData> {}

/// trait Payouts
pub trait Payouts:
ConnectorCommon
+ PayoutCancel
+ PayoutCreate
+ PayoutEligibility
+ PayoutFulfill
+ PayoutQuote
+ PayoutRecipient
+ PayoutRecipientAccount
+ PayoutSync
{
}
30 changes: 25 additions & 5 deletions crates/hyperswitch_interfaces/src/api/payouts_v2.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Payouts V2 interface
use hyperswitch_domain_models::router_flow_types::payouts::{
PoCancel, PoCreate, PoEligibility, PoFulfill, PoQuote, PoRecipient, PoRecipientAccount, PoSync,
};
#[cfg(feature = "payouts")]
use hyperswitch_domain_models::{
router_data_v2::flow_common_types::PayoutFlowData, router_request_types::PayoutsData,
router_data_v2::flow_common_types::PayoutFlowData,
router_flow_types::payouts::{
PoCancel, PoCreate, PoEligibility, PoFulfill, PoQuote, PoRecipient, PoRecipientAccount,
PoSync,
},
router_request_types::PayoutsData,
router_response_types::PayoutsResponseData,
};

use super::ConnectorCommon;
use crate::api::ConnectorIntegrationV2;

/// trait PayoutCancelV2
Expand Down Expand Up @@ -57,3 +59,21 @@ pub trait PayoutSyncV2:
ConnectorIntegrationV2<PoSync, PayoutFlowData, PayoutsData, PayoutsResponseData>
{
}

/// trait Payouts
pub trait PayoutsV2:
ConnectorCommon
+ PayoutCancelV2
+ PayoutCreateV2
+ PayoutEligibilityV2
+ PayoutFulfillV2
+ PayoutQuoteV2
+ PayoutRecipientV2
+ PayoutRecipientAccountV2
+ PayoutSyncV2
{
}

/// Empty trait for when payouts feature is disabled
#[cfg(not(feature = "payouts"))]
pub trait PayoutsV2 {}
44 changes: 4 additions & 40 deletions crates/router/src/core/payments/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod session_update_flow;
pub mod setup_mandate_flow;

use async_trait::async_trait;
use hyperswitch_interfaces::api::payouts::Payouts;

#[cfg(feature = "frm")]
use crate::types::fraud_check as frm_types;
Expand Down Expand Up @@ -967,86 +968,49 @@ default_imp_for_post_processing_steps!(
macro_rules! default_imp_for_payouts {
($($path:ident::$connector:ident),*) => {
$(
impl api::Payouts for $path::$connector {}
impl Payouts for $path::$connector {}
)*
};
}

#[cfg(feature = "dummy_connector")]
impl<const T: u8> api::Payouts for connector::DummyConnector<T> {}
impl<const T: u8> Payouts for connector::DummyConnector<T> {}

default_imp_for_payouts!(
connector::Aci,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
connector::Braintree,
connector::Cashtocode,
connector::Checkout,
connector::Cryptopay,
connector::Coinbase,
connector::Datatrans,
connector::Deutschebank,
connector::Digitalvirgo,
connector::Dlocal,
connector::Elavon,
connector::Fiserv,
connector::Fiservemea,
connector::Fiuu,
connector::Forte,
connector::Globalpay,
connector::Globepay,
connector::Gocardless,
connector::Gpayments,
connector::Helcim,
connector::Iatapay,
connector::Itaubank,
connector::Jpmorgan,
connector::Klarna,
connector::Mifinity,
connector::Mollie,
connector::Multisafepay,
connector::Netcetera,
connector::Nexinets,
connector::Nexixpay,
connector::Nmi,
connector::Noon,
connector::Novalnet,
connector::Nuvei,
connector::Opayo,
connector::Opennode,
connector::Paybox,
connector::Payeezy,
connector::Payme,
connector::Payu,
connector::Placetopay,
connector::Plaid,
connector::Powertranz,
connector::Prophetpay,
connector::Rapyd,
connector::Razorpay,
connector::Riskified,
connector::Shift4,
connector::Signifyd,
connector::Square,
connector::Stax,
connector::Taxjar,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
connector::Wellsfargo,
connector::Wellsfargopayout,
connector::Worldline,
connector::Worldpay,
connector::Zen,
connector::Zsl
connector::Wellsfargopayout
);

#[cfg(feature = "payouts")]
Expand Down
19 changes: 0 additions & 19 deletions crates/router/src/types/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,25 +562,6 @@ pub trait FraudCheck {}
#[cfg(not(feature = "frm"))]
pub trait FraudCheckV2 {}

#[cfg(feature = "payouts")]
pub trait Payouts:
ConnectorCommon
+ PayoutCancel
+ PayoutCreate
+ PayoutEligibility
+ PayoutFulfill
+ PayoutQuote
+ PayoutRecipient
+ PayoutRecipientAccount
+ PayoutSync
{
}
#[cfg(not(feature = "payouts"))]
pub trait Payouts {}

#[cfg(not(feature = "payouts"))]
pub trait PayoutsV2 {}

#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/types/api/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use hyperswitch_domain_models::router_flow_types::payouts::{
};
pub use hyperswitch_interfaces::api::payouts::{
PayoutCancel, PayoutCreate, PayoutEligibility, PayoutFulfill, PayoutQuote, PayoutRecipient,
PayoutRecipientAccount, PayoutSync,
PayoutRecipientAccount, PayoutSync, Payouts,
};

pub use super::payouts_v2::{
Expand Down
Loading