From 293d93f68b16b14e2e6ceafebf7630d6ce6ff485 Mon Sep 17 00:00:00 2001 From: Nithin N <57832822+Nithin1506200@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:21:43 +0530 Subject: [PATCH] feat(connector): [DUMMY_CONNECTOR] crate restructuring (#8372) --- crates/hyperswitch_connectors/Cargo.toml | 5 + .../hyperswitch_connectors/src/connectors.rs | 4 + .../src/connectors/dummyconnector.rs | 627 +++++++++++++++++ .../dummyconnector/transformers.rs | 212 +++--- .../src/default_implementations.rs | 553 ++++++++++++++- crates/router/Cargo.toml | 2 +- crates/router/src/connector.rs | 7 +- crates/router/src/connector/dummyconnector.rs | 630 ----------------- crates/router/src/connector/utils.rs | 11 - crates/router/src/core/admin.rs | 2 +- crates/router/src/core/payments/flows.rs | 637 +----------------- 11 files changed, 1283 insertions(+), 1407 deletions(-) create mode 100644 crates/hyperswitch_connectors/src/connectors/dummyconnector.rs rename crates/{router/src/connector => hyperswitch_connectors/src/connectors}/dummyconnector/transformers.rs (54%) delete mode 100644 crates/router/src/connector/dummyconnector.rs diff --git a/crates/hyperswitch_connectors/Cargo.toml b/crates/hyperswitch_connectors/Cargo.toml index 9233aa9bc5..9e4996d14c 100644 --- a/crates/hyperswitch_connectors/Cargo.toml +++ b/crates/hyperswitch_connectors/Cargo.toml @@ -11,6 +11,11 @@ payouts = ["hyperswitch_domain_models/payouts", "api_models/payouts", "hyperswit v1 = ["api_models/v1", "hyperswitch_domain_models/v1", "common_utils/v1"] v2 = ["api_models/v2", "hyperswitch_domain_models/v2", "common_utils/v2", "hyperswitch_interfaces/v2"] revenue_recovery = ["hyperswitch_interfaces/revenue_recovery", "hyperswitch_domain_models/revenue_recovery"] +default = ["dummy_connector"] +dummy_connector = [ + "hyperswitch_interfaces/dummy_connector", + "hyperswitch_domain_models/dummy_connector", +] [dependencies] actix-web = "4.11.0" diff --git a/crates/hyperswitch_connectors/src/connectors.rs b/crates/hyperswitch_connectors/src/connectors.rs index b603923d98..15dc705db5 100644 --- a/crates/hyperswitch_connectors/src/connectors.rs +++ b/crates/hyperswitch_connectors/src/connectors.rs @@ -26,6 +26,8 @@ pub mod datatrans; pub mod deutschebank; pub mod digitalvirgo; pub mod dlocal; +#[cfg(feature = "dummy_connector")] +pub mod dummyconnector; pub mod ebanx; pub mod elavon; pub mod facilitapay; @@ -103,6 +105,8 @@ pub mod worldpayxml; pub mod xendit; pub mod zen; pub mod zsl; +#[cfg(feature = "dummy_connector")] +pub use self::dummyconnector::DummyConnector; pub use self::{ aci::Aci, adyen::Adyen, adyenplatform::Adyenplatform, airwallex::Airwallex, amazonpay::Amazonpay, archipel::Archipel, authorizedotnet::Authorizedotnet, bambora::Bambora, diff --git a/crates/hyperswitch_connectors/src/connectors/dummyconnector.rs b/crates/hyperswitch_connectors/src/connectors/dummyconnector.rs new file mode 100644 index 0000000000..c86ca3cb21 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/dummyconnector.rs @@ -0,0 +1,627 @@ +pub mod transformers; + +use std::fmt::Debug; + +use api_models::webhooks::{IncomingWebhookEvent, ObjectReferenceId}; +use common_enums::{CaptureMethod, PaymentMethod, PaymentMethodType}; +use common_utils::{ + consts as common_consts, + errors::CustomResult, + ext_traits::BytesExt, + request::{Method, Request, RequestBuilder, RequestContent}, +}; +use error_stack::{report, ResultExt}; +use hyperswitch_domain_models::{ + router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData}, + router_flow_types::{ + AccessTokenAuth, Authorize, Capture, Execute, PSync, PaymentMethodToken, RSync, Session, + SetupMandate, Void, + }, + router_request_types::{ + AccessTokenRequestData, PaymentMethodTokenizationData, PaymentsAuthorizeData, + PaymentsCancelData, PaymentsCaptureData, PaymentsSessionData, PaymentsSyncData, + RefundsData, SetupMandateRequestData, + }, + router_response_types::{PaymentsResponseData, RefundsResponseData}, + types::{ + PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData, + RefundSyncRouterData, RefundsRouterData, + }, +}; +use hyperswitch_interfaces::{ + api::{ + ConnectorAccessToken, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, + ConnectorSpecifications, ConnectorValidation, MandateSetup, Payment, PaymentAuthorize, + PaymentCapture, PaymentSession, PaymentSync, PaymentToken, PaymentVoid, Refund, + RefundExecute, RefundSync, + }, + configs::Connectors, + errors::ConnectorError, + events::connector_api_logs::ConnectorEvent, + types::{ + PaymentsAuthorizeType, PaymentsCaptureType, PaymentsSyncType, RefundExecuteType, + RefundSyncType, Response, + }, + webhooks::{IncomingWebhook, IncomingWebhookRequestDetails}, +}; +use masking::{Mask as _, Maskable}; + +use crate::{ + constants::headers, + types::ResponseRouterData, + utils::{construct_not_supported_error_report, RefundsRequestData as _}, +}; + +#[derive(Debug, Clone)] +pub struct DummyConnector; + +impl Payment for DummyConnector {} +impl PaymentSession for DummyConnector {} +impl ConnectorAccessToken for DummyConnector {} +impl MandateSetup for DummyConnector {} +impl PaymentAuthorize for DummyConnector {} +impl PaymentSync for DummyConnector {} +impl PaymentCapture for DummyConnector {} +impl PaymentVoid for DummyConnector {} +impl Refund for DummyConnector {} +impl RefundExecute for DummyConnector {} +impl RefundSync for DummyConnector {} +impl PaymentToken for DummyConnector {} + +impl + ConnectorIntegration + for DummyConnector +{ + // Not Implemented (R) +} + +impl ConnectorCommonExt + for DummyConnector +where + Self: ConnectorIntegration, +{ + fn build_headers( + &self, + req: &RouterData, + _connectors: &Connectors, + ) -> CustomResult)>, ConnectorError> { + let mut header = vec![ + ( + headers::CONTENT_TYPE.to_string(), + PaymentsAuthorizeType::get_content_type(self) + .to_string() + .into(), + ), + ( + common_consts::TENANT_HEADER.to_string(), + req.tenant_id.get_string_repr().to_string().into(), + ), + ]; + let mut api_key = self.get_auth_header(&req.connector_auth_type)?; + header.append(&mut api_key); + Ok(header) + } +} + +impl ConnectorCommon for DummyConnector { + fn id(&self) -> &'static str { + Into::::into(T).get_dummy_connector_id() + } + + fn common_get_content_type(&self) -> &'static str { + "application/json" + } + + fn base_url<'a>(&self, connectors: &'a Connectors) -> &'a str { + connectors.dummyconnector.base_url.as_ref() + } + + fn get_auth_header( + &self, + auth_type: &ConnectorAuthType, + ) -> CustomResult)>, ConnectorError> { + let auth = transformers::DummyConnectorAuthType::try_from(auth_type) + .change_context(ConnectorError::FailedToObtainAuthType)?; + Ok(vec![( + headers::AUTHORIZATION.to_string(), + auth.api_key.into_masked(), + )]) + } + + fn build_error_response( + &self, + res: Response, + event_builder: Option<&mut ConnectorEvent>, + ) -> CustomResult { + let response: transformers::DummyConnectorErrorResponse = res + .response + .parse_struct("DummyConnectorErrorResponse") + .change_context(ConnectorError::ResponseDeserializationFailed)?; + + event_builder.map(|i| i.set_error_response_body(&response)); + router_env::logger::info!(connector_response=?response); + + Ok(ErrorResponse { + status_code: res.status_code, + code: response.error.code, + message: response.error.message, + reason: response.error.reason, + attempt_status: None, + connector_transaction_id: None, + network_advice_code: None, + network_decline_code: None, + network_error_message: None, + }) + } +} + +impl ConnectorValidation for DummyConnector { + fn validate_connector_against_payment_request( + &self, + capture_method: Option, + _payment_method: PaymentMethod, + _pmt: Option, + ) -> CustomResult<(), ConnectorError> { + let capture_method = capture_method.unwrap_or_default(); + match capture_method { + CaptureMethod::Automatic + | CaptureMethod::Manual + | CaptureMethod::SequentialAutomatic => Ok(()), + CaptureMethod::ManualMultiple | CaptureMethod::Scheduled => Err( + construct_not_supported_error_report(capture_method, self.id()), + ), + } + } +} + +impl ConnectorIntegration + for DummyConnector +{ + //TODO: implement sessions flow +} + +impl ConnectorIntegration + for DummyConnector +{ +} + +impl ConnectorIntegration + for DummyConnector +{ + fn build_request( + &self, + _req: &RouterData, + _connectors: &Connectors, + ) -> CustomResult, ConnectorError> { + Err( + ConnectorError::NotImplemented("Setup Mandate flow for DummyConnector".to_string()) + .into(), + ) + } +} + +impl ConnectorIntegration + for DummyConnector +{ + fn get_headers( + &self, + req: &PaymentsAuthorizeRouterData, + connectors: &Connectors, + ) -> CustomResult)>, ConnectorError> { + self.build_headers(req, connectors) + } + + fn get_content_type(&self) -> &'static str { + self.common_get_content_type() + } + + fn get_url( + &self, + req: &PaymentsAuthorizeRouterData, + connectors: &Connectors, + ) -> CustomResult { + match req.payment_method { + PaymentMethod::Card + | PaymentMethod::Upi + | PaymentMethod::Wallet + | PaymentMethod::PayLater => Ok(format!("{}/payment", self.base_url(connectors))), + _ => Err(error_stack::report!(ConnectorError::NotSupported { + message: format!("The payment method {} is not supported", req.payment_method), + connector: Into::::into(T).get_dummy_connector_id(), + })), + } + } + + fn get_request_body( + &self, + req: &PaymentsAuthorizeRouterData, + _connectors: &Connectors, + ) -> CustomResult { + let connector_req = transformers::DummyConnectorPaymentsRequest::::try_from(req)?; + Ok(RequestContent::Json(Box::new(connector_req))) + } + + fn build_request( + &self, + req: &PaymentsAuthorizeRouterData, + connectors: &Connectors, + ) -> CustomResult, ConnectorError> { + Ok(Some( + RequestBuilder::new() + .method(Method::Post) + .url(&PaymentsAuthorizeType::get_url(self, req, connectors)?) + .attach_default_headers() + .headers(PaymentsAuthorizeType::get_headers(self, req, connectors)?) + .set_body(PaymentsAuthorizeType::get_request_body( + self, req, connectors, + )?) + .build(), + )) + } + + fn handle_response( + &self, + data: &PaymentsAuthorizeRouterData, + event_builder: Option<&mut ConnectorEvent>, + res: Response, + ) -> CustomResult { + let response: transformers::PaymentsResponse = res + .response + .parse_struct("DummyConnector PaymentsResponse") + .change_context(ConnectorError::ResponseDeserializationFailed)?; + event_builder.map(|i| i.set_response_body(&response)); + router_env::logger::info!(connector_response=?response); + RouterData::try_from(ResponseRouterData { + response, + data: data.clone(), + http_code: res.status_code, + }) + .change_context(ConnectorError::ResponseHandlingFailed) + } + + fn get_error_response( + &self, + res: Response, + event_builder: Option<&mut ConnectorEvent>, + ) -> CustomResult { + self.build_error_response(res, event_builder) + } +} + +impl ConnectorIntegration + for DummyConnector +{ + fn get_headers( + &self, + req: &PaymentsSyncRouterData, + connectors: &Connectors, + ) -> CustomResult)>, ConnectorError> { + self.build_headers(req, connectors) + } + + fn get_content_type(&self) -> &'static str { + self.common_get_content_type() + } + + fn get_url( + &self, + req: &PaymentsSyncRouterData, + connectors: &Connectors, + ) -> CustomResult { + match req + .request + .connector_transaction_id + .get_connector_transaction_id() + { + Ok(transaction_id) => Ok(format!( + "{}/payments/{}", + self.base_url(connectors), + transaction_id + )), + Err(_) => Err(error_stack::report!( + ConnectorError::MissingConnectorTransactionID + )), + } + } + + fn build_request( + &self, + req: &PaymentsSyncRouterData, + connectors: &Connectors, + ) -> CustomResult, ConnectorError> { + Ok(Some( + RequestBuilder::new() + .method(Method::Get) + .url(&PaymentsSyncType::get_url(self, req, connectors)?) + .attach_default_headers() + .headers(PaymentsSyncType::get_headers(self, req, connectors)?) + .build(), + )) + } + + fn handle_response( + &self, + data: &PaymentsSyncRouterData, + event_builder: Option<&mut ConnectorEvent>, + res: Response, + ) -> CustomResult { + let response: transformers::PaymentsResponse = res + .response + .parse_struct("dummyconnector PaymentsSyncResponse") + .change_context(ConnectorError::ResponseDeserializationFailed)?; + event_builder.map(|i| i.set_response_body(&response)); + router_env::logger::info!(connector_response=?response); + RouterData::try_from(ResponseRouterData { + response, + data: data.clone(), + http_code: res.status_code, + }) + .change_context(ConnectorError::ResponseHandlingFailed) + } + + fn get_error_response( + &self, + res: Response, + event_builder: Option<&mut ConnectorEvent>, + ) -> CustomResult { + self.build_error_response(res, event_builder) + } +} + +impl ConnectorIntegration + for DummyConnector +{ + fn get_headers( + &self, + req: &PaymentsCaptureRouterData, + connectors: &Connectors, + ) -> CustomResult)>, ConnectorError> { + self.build_headers(req, connectors) + } + + fn get_content_type(&self) -> &'static str { + self.common_get_content_type() + } + + fn get_url( + &self, + _req: &PaymentsCaptureRouterData, + _connectors: &Connectors, + ) -> CustomResult { + Err(ConnectorError::NotImplemented("get_url method".to_string()).into()) + } + + fn get_request_body( + &self, + _req: &PaymentsCaptureRouterData, + _connectors: &Connectors, + ) -> CustomResult { + Err(ConnectorError::NotImplemented("get_request_body method".to_string()).into()) + } + + fn build_request( + &self, + req: &PaymentsCaptureRouterData, + connectors: &Connectors, + ) -> CustomResult, ConnectorError> { + Ok(Some( + RequestBuilder::new() + .method(Method::Post) + .url(&PaymentsCaptureType::get_url(self, req, connectors)?) + .attach_default_headers() + .headers(PaymentsCaptureType::get_headers(self, req, connectors)?) + .build(), + )) + } + + fn handle_response( + &self, + data: &PaymentsCaptureRouterData, + event_builder: Option<&mut ConnectorEvent>, + res: Response, + ) -> CustomResult { + let response: transformers::PaymentsResponse = res + .response + .parse_struct("transformers PaymentsCaptureResponse") + .change_context(ConnectorError::ResponseDeserializationFailed)?; + event_builder.map(|i| i.set_response_body(&response)); + router_env::logger::info!(connector_response=?response); + RouterData::try_from(ResponseRouterData { + response, + data: data.clone(), + http_code: res.status_code, + }) + .change_context(ConnectorError::ResponseHandlingFailed) + } + + fn get_error_response( + &self, + res: Response, + event_builder: Option<&mut ConnectorEvent>, + ) -> CustomResult { + self.build_error_response(res, event_builder) + } +} + +impl ConnectorIntegration + for DummyConnector +{ +} + +impl ConnectorIntegration + for DummyConnector +{ + fn get_headers( + &self, + req: &RefundsRouterData, + connectors: &Connectors, + ) -> CustomResult)>, ConnectorError> { + self.build_headers(req, connectors) + } + + fn get_content_type(&self) -> &'static str { + self.common_get_content_type() + } + + fn get_url( + &self, + req: &RefundsRouterData, + connectors: &Connectors, + ) -> CustomResult { + Ok(format!( + "{}/{}/refund", + self.base_url(connectors), + req.request.connector_transaction_id + )) + } + + fn get_request_body( + &self, + req: &RefundsRouterData, + _connectors: &Connectors, + ) -> CustomResult { + let connector_req = transformers::DummyConnectorRefundRequest::try_from(req)?; + Ok(RequestContent::Json(Box::new(connector_req))) + } + + fn build_request( + &self, + req: &RefundsRouterData, + connectors: &Connectors, + ) -> CustomResult, ConnectorError> { + let request = RequestBuilder::new() + .method(Method::Post) + .url(&RefundExecuteType::get_url(self, req, connectors)?) + .attach_default_headers() + .headers(RefundExecuteType::get_headers(self, req, connectors)?) + .set_body(RefundExecuteType::get_request_body(self, req, connectors)?) + .build(); + Ok(Some(request)) + } + + fn handle_response( + &self, + data: &RefundsRouterData, + event_builder: Option<&mut ConnectorEvent>, + res: Response, + ) -> CustomResult, ConnectorError> { + let response: transformers::RefundResponse = res + .response + .parse_struct("transformers RefundResponse") + .change_context(ConnectorError::ResponseDeserializationFailed)?; + event_builder.map(|i| i.set_response_body(&response)); + router_env::logger::info!(connector_response=?response); + RouterData::try_from(ResponseRouterData { + response, + data: data.clone(), + http_code: res.status_code, + }) + .change_context(ConnectorError::ResponseHandlingFailed) + } + + fn get_error_response( + &self, + res: Response, + event_builder: Option<&mut ConnectorEvent>, + ) -> CustomResult { + self.build_error_response(res, event_builder) + } +} + +impl ConnectorIntegration + for DummyConnector +{ + fn get_headers( + &self, + req: &RefundSyncRouterData, + connectors: &Connectors, + ) -> CustomResult)>, ConnectorError> { + self.build_headers(req, connectors) + } + + fn get_content_type(&self) -> &'static str { + self.common_get_content_type() + } + + fn get_url( + &self, + req: &RefundSyncRouterData, + connectors: &Connectors, + ) -> CustomResult { + let refund_id = req.request.get_connector_refund_id()?; + Ok(format!( + "{}/refunds/{}", + self.base_url(connectors), + refund_id + )) + } + + fn build_request( + &self, + req: &RefundSyncRouterData, + connectors: &Connectors, + ) -> CustomResult, ConnectorError> { + Ok(Some( + RequestBuilder::new() + .method(Method::Get) + .url(&RefundSyncType::get_url(self, req, connectors)?) + .attach_default_headers() + .headers(RefundSyncType::get_headers(self, req, connectors)?) + .build(), + )) + } + + fn handle_response( + &self, + data: &RefundSyncRouterData, + event_builder: Option<&mut ConnectorEvent>, + res: Response, + ) -> CustomResult { + let response: transformers::RefundResponse = res + .response + .parse_struct("transformers RefundSyncResponse") + .change_context(ConnectorError::ResponseDeserializationFailed)?; + event_builder.map(|i| i.set_response_body(&response)); + router_env::logger::info!(connector_response=?response); + RouterData::try_from(ResponseRouterData { + response, + data: data.clone(), + http_code: res.status_code, + }) + .change_context(ConnectorError::ResponseHandlingFailed) + } + + fn get_error_response( + &self, + res: Response, + event_builder: Option<&mut ConnectorEvent>, + ) -> CustomResult { + self.build_error_response(res, event_builder) + } +} + +#[async_trait::async_trait] +impl IncomingWebhook for DummyConnector { + fn get_webhook_object_reference_id( + &self, + _request: &IncomingWebhookRequestDetails<'_>, + ) -> CustomResult { + Err(report!(ConnectorError::WebhooksNotImplemented)) + } + + fn get_webhook_event_type( + &self, + _request: &IncomingWebhookRequestDetails<'_>, + ) -> CustomResult { + Ok(IncomingWebhookEvent::EventNotSupported) + } + + fn get_webhook_resource_object( + &self, + _request: &IncomingWebhookRequestDetails<'_>, + ) -> CustomResult, ConnectorError> { + Err(report!(ConnectorError::WebhooksNotImplemented)) + } +} + +impl ConnectorSpecifications for DummyConnector {} diff --git a/crates/router/src/connector/dummyconnector/transformers.rs b/crates/hyperswitch_connectors/src/connectors/dummyconnector/transformers.rs similarity index 54% rename from crates/router/src/connector/dummyconnector/transformers.rs rename to crates/hyperswitch_connectors/src/connectors/dummyconnector/transformers.rs index 392a2249d9..d0662e8612 100644 --- a/crates/router/src/connector/dummyconnector/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/dummyconnector/transformers.rs @@ -1,14 +1,23 @@ -use common_utils::pii; -use diesel_models::enums::Currency; +use common_enums::{AttemptStatus, Currency, RefundStatus}; +use common_utils::{pii, request::Method}; +use hyperswitch_domain_models::{ + payment_method_data::{ + Card, PayLaterData, PaymentMethodData, UpiCollectData, UpiData, WalletData, + }, + router_data::{ConnectorAuthType, RouterData}, + router_flow_types::{Execute, RSync}, + router_request_types::ResponseId, + router_response_types::{PaymentsResponseData, RedirectForm, RefundsResponseData}, + types::{PaymentsAuthorizeRouterData, RefundsRouterData}, +}; +use hyperswitch_interfaces::errors::ConnectorError; use masking::Secret; use serde::{Deserialize, Serialize}; use url::Url; use crate::{ - connector::utils::RouterData, - core::errors, - services, - types::{self, api, domain, storage::enums}, + types::{RefundsResponseRouterData, ResponseRouterData}, + utils::RouterData as _, }; #[derive(Debug, Serialize, strum::Display, Eq, PartialEq)] @@ -63,14 +72,14 @@ impl From for DummyConnectors { pub struct DummyConnectorPaymentsRequest { amount: i64, currency: Currency, - payment_method_data: PaymentMethodData, + payment_method_data: DummyPaymentMethodData, return_url: Option, connector: DummyConnectors, } #[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "lowercase")] -pub enum PaymentMethodData { +pub enum DummyPaymentMethodData { Card(DummyConnectorCard), Wallet(DummyConnectorWallet), PayLater(DummyConnectorPayLater), @@ -88,15 +97,13 @@ pub struct DummyConnectorUpiCollect { vpa_id: Secret, } -impl TryFrom for DummyConnectorUpi { - type Error = error_stack::Report; - fn try_from(value: domain::UpiCollectData) -> Result { +impl TryFrom for DummyConnectorUpi { + type Error = error_stack::Report; + fn try_from(value: UpiCollectData) -> Result { Ok(Self::UpiCollect(DummyConnectorUpiCollect { - vpa_id: value - .vpa_id - .ok_or(errors::ConnectorError::MissingRequiredField { - field_name: "vpa_id", - })?, + vpa_id: value.vpa_id.ok_or(ConnectorError::MissingRequiredField { + field_name: "vpa_id", + })?, })) } } @@ -110,10 +117,10 @@ pub struct DummyConnectorCard { cvc: Secret, } -impl TryFrom<(domain::Card, Option>)> for DummyConnectorCard { - type Error = error_stack::Report; +impl TryFrom<(Card, Option>)> for DummyConnectorCard { + type Error = error_stack::Report; fn try_from( - (value, card_holder_name): (domain::Card, Option>), + (value, card_holder_name): (Card, Option>), ) -> Result { Ok(Self { name: card_holder_name.unwrap_or(Secret::new("".to_string())), @@ -135,17 +142,17 @@ pub enum DummyConnectorWallet { AliPayHK, } -impl TryFrom for DummyConnectorWallet { - type Error = error_stack::Report; - fn try_from(value: domain::WalletData) -> Result { +impl TryFrom for DummyConnectorWallet { + type Error = error_stack::Report; + fn try_from(value: WalletData) -> Result { match value { - domain::WalletData::GooglePayRedirect(_) => Ok(Self::GooglePay), - domain::WalletData::PaypalRedirect(_) => Ok(Self::Paypal), - domain::WalletData::WeChatPayRedirect(_) => Ok(Self::WeChatPay), - domain::WalletData::MbWayRedirect(_) => Ok(Self::MbWay), - domain::WalletData::AliPayRedirect(_) => Ok(Self::AliPay), - domain::WalletData::AliPayHkRedirect(_) => Ok(Self::AliPayHK), - _ => Err(errors::ConnectorError::NotImplemented("Dummy wallet".to_string()).into()), + WalletData::GooglePayRedirect(_) => Ok(Self::GooglePay), + WalletData::PaypalRedirect(_) => Ok(Self::Paypal), + WalletData::WeChatPayRedirect(_) => Ok(Self::WeChatPay), + WalletData::MbWayRedirect(_) => Ok(Self::MbWay), + WalletData::AliPayRedirect(_) => Ok(Self::AliPay), + WalletData::AliPayHkRedirect(_) => Ok(Self::AliPayHK), + _ => Err(ConnectorError::NotImplemented("Dummy wallet".to_string()).into()), } } } @@ -157,52 +164,45 @@ pub enum DummyConnectorPayLater { AfterPayClearPay, } -impl TryFrom for DummyConnectorPayLater { - type Error = error_stack::Report; - fn try_from(value: domain::payments::PayLaterData) -> Result { +impl TryFrom for DummyConnectorPayLater { + type Error = error_stack::Report; + fn try_from(value: PayLaterData) -> Result { match value { - domain::payments::PayLaterData::KlarnaRedirect { .. } => Ok(Self::Klarna), - domain::payments::PayLaterData::AffirmRedirect {} => Ok(Self::Affirm), - domain::payments::PayLaterData::AfterpayClearpayRedirect { .. } => { - Ok(Self::AfterPayClearPay) - } - _ => Err(errors::ConnectorError::NotImplemented("Dummy pay later".to_string()).into()), + PayLaterData::KlarnaRedirect { .. } => Ok(Self::Klarna), + PayLaterData::AffirmRedirect {} => Ok(Self::Affirm), + PayLaterData::AfterpayClearpayRedirect { .. } => Ok(Self::AfterPayClearPay), + _ => Err(ConnectorError::NotImplemented("Dummy pay later".to_string()).into()), } } } -impl TryFrom<&types::PaymentsAuthorizeRouterData> - for DummyConnectorPaymentsRequest -{ - type Error = error_stack::Report; - fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result { - let payment_method_data: Result = match item - .request - .payment_method_data - { - domain::PaymentMethodData::Card(ref req_card) => { - let card_holder_name = item.get_optional_billing_full_name(); - Ok(PaymentMethodData::Card(DummyConnectorCard::try_from(( - req_card.clone(), - card_holder_name, - ))?)) - } - domain::PaymentMethodData::Upi(ref req_upi_data) => match req_upi_data { - domain::UpiData::UpiCollect(data) => Ok(PaymentMethodData::Upi( - DummyConnectorUpi::try_from(data.clone())?, - )), - domain::UpiData::UpiIntent(_) => { - Err(errors::ConnectorError::NotImplemented("UPI Intent".to_string()).into()) +impl TryFrom<&PaymentsAuthorizeRouterData> for DummyConnectorPaymentsRequest { + type Error = error_stack::Report; + fn try_from(item: &PaymentsAuthorizeRouterData) -> Result { + let payment_method_data: Result = + match item.request.payment_method_data { + PaymentMethodData::Card(ref req_card) => { + let card_holder_name = item.get_optional_billing_full_name(); + Ok(DummyPaymentMethodData::Card(DummyConnectorCard::try_from( + (req_card.clone(), card_holder_name), + )?)) } - }, - domain::PaymentMethodData::Wallet(ref wallet_data) => { - Ok(PaymentMethodData::Wallet(wallet_data.clone().try_into()?)) - } - domain::PaymentMethodData::PayLater(ref pay_later_data) => Ok( - PaymentMethodData::PayLater(pay_later_data.clone().try_into()?), - ), - _ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()), - }; + PaymentMethodData::Upi(ref req_upi_data) => match req_upi_data { + UpiData::UpiCollect(data) => Ok(DummyPaymentMethodData::Upi( + DummyConnectorUpi::try_from(data.clone())?, + )), + UpiData::UpiIntent(_) => { + Err(ConnectorError::NotImplemented("UPI Intent".to_string()).into()) + } + }, + PaymentMethodData::Wallet(ref wallet_data) => Ok(DummyPaymentMethodData::Wallet( + wallet_data.clone().try_into()?, + )), + PaymentMethodData::PayLater(ref pay_later_data) => Ok( + DummyPaymentMethodData::PayLater(pay_later_data.clone().try_into()?), + ), + _ => Err(ConnectorError::NotImplemented("Payment methods".to_string()).into()), + }; Ok(Self { amount: item.request.amount, currency: item.request.currency, @@ -218,14 +218,14 @@ pub struct DummyConnectorAuthType { pub(super) api_key: Secret, } -impl TryFrom<&types::ConnectorAuthType> for DummyConnectorAuthType { - type Error = error_stack::Report; - fn try_from(auth_type: &types::ConnectorAuthType) -> Result { +impl TryFrom<&ConnectorAuthType> for DummyConnectorAuthType { + type Error = error_stack::Report; + fn try_from(auth_type: &ConnectorAuthType) -> Result { match auth_type { - types::ConnectorAuthType::HeaderKey { api_key } => Ok(Self { + ConnectorAuthType::HeaderKey { api_key } => Ok(Self { api_key: api_key.to_owned(), }), - _ => Err(errors::ConnectorError::FailedToObtainAuthType.into()), + _ => Err(ConnectorError::FailedToObtainAuthType.into()), } } } @@ -240,7 +240,7 @@ pub enum DummyConnectorPaymentStatus { Processing, } -impl From for enums::AttemptStatus { +impl From for AttemptStatus { fn from(item: DummyConnectorPaymentStatus) -> Self { match item { DummyConnectorPaymentStatus::Succeeded => Self::Charged, @@ -275,24 +275,22 @@ pub enum DummyConnectorUpiType { UpiCollect, } -impl TryFrom> - for types::RouterData +impl TryFrom> + for RouterData { - type Error = error_stack::Report; + type Error = error_stack::Report; fn try_from( - item: types::ResponseRouterData, + item: ResponseRouterData, ) -> Result { let redirection_data = item .response .next_action .and_then(|redirection_data| redirection_data.get_url()) - .map(|redirection_url| { - services::RedirectForm::from((redirection_url, services::Method::Get)) - }); + .map(|redirection_url| RedirectForm::from((redirection_url, Method::Get))); Ok(Self { - status: enums::AttemptStatus::from(item.response.status), - response: Ok(types::PaymentsResponseData::TransactionResponse { - resource_id: types::ResponseId::ConnectorTransactionId(item.response.id), + status: AttemptStatus::from(item.response.status), + response: Ok(PaymentsResponseData::TransactionResponse { + resource_id: ResponseId::ConnectorTransactionId(item.response.id), redirection_data: Box::new(redirection_data), mandate_reference: Box::new(None), connector_metadata: None, @@ -327,9 +325,9 @@ pub struct DummyConnectorRefundRequest { pub amount: i64, } -impl TryFrom<&types::RefundsRouterData> for DummyConnectorRefundRequest { - type Error = error_stack::Report; - fn try_from(item: &types::RefundsRouterData) -> Result { +impl TryFrom<&RefundsRouterData> for DummyConnectorRefundRequest { + type Error = error_stack::Report; + fn try_from(item: &RefundsRouterData) -> Result { Ok(Self { amount: item.request.refund_amount, }) @@ -341,19 +339,19 @@ impl TryFrom<&types::RefundsRouterData> for DummyConnectorRefundRequest { #[allow(dead_code)] #[derive(Debug, Serialize, Default, Deserialize, Clone)] #[serde(rename_all = "lowercase")] -pub enum RefundStatus { +pub enum DummyRefundStatus { Succeeded, Failed, #[default] Processing, } -impl From for enums::RefundStatus { - fn from(item: RefundStatus) -> Self { +impl From for RefundStatus { + fn from(item: DummyRefundStatus) -> Self { match item { - RefundStatus::Succeeded => Self::Success, - RefundStatus::Failed => Self::Failure, - RefundStatus::Processing => Self::Pending, + DummyRefundStatus::Succeeded => Self::Success, + DummyRefundStatus::Failed => Self::Failure, + DummyRefundStatus::Processing => Self::Pending, //TODO: Review mapping } } @@ -362,41 +360,37 @@ impl From for enums::RefundStatus { #[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct RefundResponse { id: String, - status: RefundStatus, + status: DummyRefundStatus, currency: Currency, created: String, payment_amount: i64, refund_amount: i64, } -impl TryFrom> - for types::RefundsRouterData -{ - type Error = error_stack::Report; +impl TryFrom> for RefundsRouterData { + type Error = error_stack::Report; fn try_from( - item: types::RefundsResponseRouterData, + item: RefundsResponseRouterData, ) -> Result { Ok(Self { - response: Ok(types::RefundsResponseData { + response: Ok(RefundsResponseData { connector_refund_id: item.response.id.to_string(), - refund_status: enums::RefundStatus::from(item.response.status), + refund_status: RefundStatus::from(item.response.status), }), ..item.data }) } } -impl TryFrom> - for types::RefundsRouterData -{ - type Error = error_stack::Report; +impl TryFrom> for RefundsRouterData { + type Error = error_stack::Report; fn try_from( - item: types::RefundsResponseRouterData, + item: RefundsResponseRouterData, ) -> Result { Ok(Self { - response: Ok(types::RefundsResponseData { + response: Ok(RefundsResponseData { connector_refund_id: item.response.id.to_string(), - refund_status: enums::RefundStatus::from(item.response.status), + refund_status: RefundStatus::from(item.response.status), }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs index 7c46a8ffc0..e78067e24e 100644 --- a/crates/hyperswitch_connectors/src/default_implementations.rs +++ b/crates/hyperswitch_connectors/src/default_implementations.rs @@ -1,9 +1,29 @@ +#[cfg(feature = "dummy_connector")] +use common_enums::{CallConnectorAction, PaymentAction}; // impl api::PaymentIncrementalAuthorization for Helcim {} // impl api::ConnectorCustomer for Helcim {} // impl api::PaymentsPreProcessing for Helcim {} // impl api::PaymentReject for Helcim {} // impl api::PaymentApprove for Helcim {} use common_utils::errors::CustomResult; +#[cfg(all(feature = "v2", feature = "revenue_recovery"))] +use hyperswitch_domain_models::router_flow_types::{ + BillingConnectorInvoiceSync, BillingConnectorPaymentsSync, RecoveryRecordBack, +}; +#[cfg(feature = "dummy_connector")] +use hyperswitch_domain_models::router_request_types::authentication::{ + ConnectorAuthenticationRequestData, ConnectorPostAuthenticationRequestData, PreAuthNRequestData, +}; +#[cfg(all(feature = "v2", feature = "revenue_recovery"))] +use hyperswitch_domain_models::router_request_types::revenue_recovery::{ + BillingConnectorInvoiceSyncRequest, BillingConnectorPaymentsSyncRequest, + RevenueRecoveryRecordBackRequest, +}; +#[cfg(all(feature = "v2", feature = "revenue_recovery"))] +use hyperswitch_domain_models::router_response_types::revenue_recovery::{ + BillingConnectorInvoiceSyncResponse, BillingConnectorPaymentsSyncResponse, + RevenueRecoveryRecordBackResponse, +}; #[cfg(feature = "frm")] use hyperswitch_domain_models::{ router_flow_types::fraud_check::{Checkout, Fulfillment, RecordReturn, Sale, Transaction}, @@ -22,12 +42,6 @@ use hyperswitch_domain_models::{ router_request_types::PayoutsData, router_response_types::PayoutsResponseData, }; -#[cfg(all(feature = "v2", feature = "revenue_recovery"))] -use hyperswitch_domain_models::{ - router_flow_types::revenue_recovery as recovery_router_flows, - router_request_types::revenue_recovery as recovery_request, - router_response_types::revenue_recovery as recovery_response, -}; use hyperswitch_domain_models::{ router_flow_types::{ authentication::{ @@ -79,6 +93,12 @@ use hyperswitch_interfaces::api::payouts::{ }; #[cfg(all(feature = "v2", feature = "revenue_recovery"))] use hyperswitch_interfaces::api::revenue_recovery as recovery_traits; +#[cfg(all(feature = "v2", feature = "revenue_recovery"))] +use hyperswitch_interfaces::api::revenue_recovery::{ + BillingConnectorInvoiceSyncIntegration, BillingConnectorPaymentsSyncIntegration, +}; +#[cfg(feature = "dummy_connector")] +use hyperswitch_interfaces::api::ConnectorVerifyWebhookSource; use hyperswitch_interfaces::{ api::{ self, @@ -5144,9 +5164,9 @@ macro_rules! default_imp_for_billing_connector_payment_sync { $( impl recovery_traits::BillingConnectorPaymentsSyncIntegration for $path::$connector {} impl ConnectorIntegration< - recovery_router_flows::BillingConnectorPaymentsSync, - recovery_request::BillingConnectorPaymentsSyncRequest, - recovery_response::BillingConnectorPaymentsSyncResponse + BillingConnectorPaymentsSync, + BillingConnectorPaymentsSyncRequest, + BillingConnectorPaymentsSyncResponse > for $path::$connector {} )* @@ -5267,9 +5287,9 @@ macro_rules! default_imp_for_revenue_recovery_record_back { $( impl recovery_traits::RevenueRecoveryRecordBack for $path::$connector {} impl ConnectorIntegration< - recovery_router_flows::RecoveryRecordBack, - recovery_request::RevenueRecoveryRecordBackRequest, - recovery_response::RevenueRecoveryRecordBackResponse + RecoveryRecordBack, + RevenueRecoveryRecordBackRequest, + RevenueRecoveryRecordBackResponse > for $path::$connector {} )* @@ -5389,9 +5409,9 @@ macro_rules! default_imp_for_billing_connector_invoice_sync { $( impl recovery_traits::BillingConnectorInvoiceSyncIntegration for $path::$connector {} impl ConnectorIntegration< - recovery_router_flows::BillingConnectorInvoiceSync, - recovery_request::BillingConnectorInvoiceSyncRequest, - recovery_response::BillingConnectorInvoiceSyncResponse + BillingConnectorInvoiceSync, + BillingConnectorInvoiceSyncRequest, + BillingConnectorInvoiceSyncResponse > for $path::$connector {} )* @@ -6108,3 +6128,506 @@ default_imp_for_external_vault_create!( connectors::Zen, connectors::Zsl ); + +#[cfg(feature = "dummy_connector")] +impl PaymentsCompleteAuthorize for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl ConnectorVerifyWebhookSource for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + VerifyWebhookSource, + VerifyWebhookSourceRequestData, + VerifyWebhookSourceResponseData, + > for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl ConnectorCustomer for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl ConnectorRedirectResponse for connectors::DummyConnector { + fn get_flow_type( + &self, + _query_params: &str, + _json_payload: Option, + _action: PaymentAction, + ) -> CustomResult { + Ok(CallConnectorAction::Trigger) + } +} + +#[cfg(feature = "dummy_connector")] +impl ConnectorTransactionId for connectors::DummyConnector {} + +#[cfg(feature = "dummy_connector")] +impl Dispute for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl AcceptDispute for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl FileUpload for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl UploadFile for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} +#[cfg(feature = "dummy_connector")] +impl RetrieveFile for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl SubmitEvidence for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl DefendDispute for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl PaymentsPreProcessing for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl PaymentsPostProcessing for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl api::Payouts for connectors::DummyConnector {} + +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl PayoutCreate for connectors::DummyConnector {} +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl PayoutSync for connectors::DummyConnector {} +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl PayoutEligibility for connectors::DummyConnector {} +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl PayoutFulfill for connectors::DummyConnector {} +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl PayoutCancel for connectors::DummyConnector {} +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl PayoutQuote for connectors::DummyConnector {} +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl PayoutRecipient for connectors::DummyConnector {} +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl PayoutRecipientAccount for connectors::DummyConnector {} +#[cfg(feature = "payouts")] +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl PaymentApprove for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl PaymentReject for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl FraudCheck for connectors::DummyConnector {} + +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl FraudCheckSale for connectors::DummyConnector {} +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl FraudCheckCheckout for connectors::DummyConnector {} +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl FraudCheckTransaction for connectors::DummyConnector {} +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl FraudCheckFulfillment for connectors::DummyConnector {} +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl FraudCheckRecordReturn for connectors::DummyConnector {} +#[cfg(all(feature = "frm", feature = "dummy_connector"))] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl PaymentIncrementalAuthorization for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + IncrementalAuthorization, + PaymentsIncrementalAuthorizationData, + PaymentsResponseData, + > for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl ConnectorMandateRevoke for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl ExternalAuthentication for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorPreAuthentication for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorPreAuthenticationVersionCall for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorAuthentication for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorPostAuthentication for connectors::DummyConnector {} + +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + Authentication, + ConnectorAuthenticationRequestData, + AuthenticationResponseData, + > for connectors::DummyConnector +{ +} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + PreAuthenticationVersionCall, + PreAuthNRequestData, + AuthenticationResponseData, + > for connectors::DummyConnector +{ +} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + PostAuthentication, + ConnectorPostAuthenticationRequestData, + AuthenticationResponseData, + > for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl PaymentAuthorizeSessionToken for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl TaxCalculation for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl PaymentSessionUpdate for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl PaymentPostSessionTokens for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl PaymentsCreateOrder for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl PaymentUpdateMetadata for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl UasPreAuthentication for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl UnifiedAuthenticationService for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + PreAuthenticate, + UasPreAuthenticationRequestData, + UasAuthenticationResponseData, + > for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl UasPostAuthentication for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + PostAuthenticate, + UasPostAuthenticationRequestData, + UasAuthenticationResponseData, + > for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl UasAuthenticationConfirmation for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + AuthenticationConfirmation, + UasConfirmationRequestData, + UasAuthenticationResponseData, + > for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl UasAuthentication for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl RevenueRecovery for connectors::DummyConnector {} + +#[cfg(all(feature = "v2", feature = "revenue_recovery"))] +#[cfg(feature = "dummy_connector")] +impl api::revenue_recovery::BillingConnectorPaymentsSyncIntegration + for connectors::DummyConnector +{ +} +#[cfg(all(feature = "v2", feature = "revenue_recovery"))] +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + BillingConnectorPaymentsSync, + BillingConnectorPaymentsSyncRequest, + BillingConnectorPaymentsSyncResponse, + > for connectors::DummyConnector +{ +} + +#[cfg(all(feature = "v2", feature = "revenue_recovery"))] +#[cfg(feature = "dummy_connector")] +impl api::revenue_recovery::RevenueRecoveryRecordBack + for connectors::DummyConnector +{ +} +#[cfg(all(feature = "v2", feature = "revenue_recovery"))] +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + RecoveryRecordBack, + RevenueRecoveryRecordBackRequest, + RevenueRecoveryRecordBackResponse, + > for connectors::DummyConnector +{ +} + +#[cfg(all(feature = "v2", feature = "revenue_recovery"))] +#[cfg(feature = "dummy_connector")] +impl BillingConnectorInvoiceSyncIntegration for connectors::DummyConnector {} +#[cfg(all(feature = "v2", feature = "revenue_recovery"))] +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration< + BillingConnectorInvoiceSync, + BillingConnectorInvoiceSyncRequest, + BillingConnectorInvoiceSyncResponse, + > for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl ExternalVault for connectors::DummyConnector {} + +#[cfg(feature = "dummy_connector")] +impl ExternalVaultInsert for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl ExternalVaultRetrieve for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl + ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl ExternalVaultDelete for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} + +#[cfg(feature = "dummy_connector")] +impl ExternalVaultCreate for connectors::DummyConnector {} +#[cfg(feature = "dummy_connector")] +impl ConnectorIntegration + for connectors::DummyConnector +{ +} diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml index 82ea494594..e0ae9fe878 100644 --- a/crates/router/Cargo.toml +++ b/crates/router/Cargo.toml @@ -26,7 +26,7 @@ oltp = ["storage_impl/oltp"] kv_store = ["scheduler/kv_store"] accounts_cache = [] vergen = ["router_env/vergen"] -dummy_connector = ["api_models/dummy_connector", "euclid/dummy_connector", "hyperswitch_interfaces/dummy_connector", "kgraph_utils/dummy_connector", "payment_methods/dummy_connector", "hyperswitch_domain_models/dummy_connector"] +dummy_connector = ["api_models/dummy_connector", "euclid/dummy_connector", "hyperswitch_interfaces/dummy_connector", "kgraph_utils/dummy_connector", "payment_methods/dummy_connector", "hyperswitch_domain_models/dummy_connector","hyperswitch_connectors/dummy_connector"] external_access_dc = ["dummy_connector"] detailed_errors = ["api_models/detailed_errors", "error-stack/serde"] payouts = ["api_models/payouts", "common_enums/payouts", "hyperswitch_connectors/payouts", "hyperswitch_domain_models/payouts", "storage_impl/payouts", "payment_methods/payouts"] diff --git a/crates/router/src/connector.rs b/crates/router/src/connector.rs index a5af15325f..4a6ae9b668 100644 --- a/crates/router/src/connector.rs +++ b/crates/router/src/connector.rs @@ -1,7 +1,7 @@ -#[cfg(feature = "dummy_connector")] -pub mod dummyconnector; pub mod utils; +#[cfg(feature = "dummy_connector")] +pub use hyperswitch_connectors::connectors::DummyConnector; pub use hyperswitch_connectors::connectors::{ aci, aci::Aci, adyen, adyen::Adyen, adyenplatform, adyenplatform::Adyenplatform, airwallex, airwallex::Airwallex, amazonpay, amazonpay::Amazonpay, archipel, archipel::Archipel, @@ -41,6 +41,3 @@ pub use hyperswitch_connectors::connectors::{ worldpayvantiv::Worldpayvantiv, worldpayxml, worldpayxml::Worldpayxml, xendit, xendit::Xendit, zen, zen::Zen, zsl, zsl::Zsl, }; - -#[cfg(feature = "dummy_connector")] -pub use self::dummyconnector::DummyConnector; diff --git a/crates/router/src/connector/dummyconnector.rs b/crates/router/src/connector/dummyconnector.rs deleted file mode 100644 index ea63a27102..0000000000 --- a/crates/router/src/connector/dummyconnector.rs +++ /dev/null @@ -1,630 +0,0 @@ -pub mod transformers; - -use std::fmt::Debug; - -use common_utils::{consts as common_consts, request::RequestContent}; -use diesel_models::enums; -use error_stack::{report, ResultExt}; - -use super::utils::RefundsRequestData; -use crate::{ - configs::settings, - connector::utils as connector_utils, - core::errors::{self, CustomResult}, - events::connector_api_logs::ConnectorEvent, - headers, - services::{ - self, - request::{self, Mask}, - ConnectorIntegration, ConnectorSpecifications, ConnectorValidation, - }, - types::{ - self, - api::{self, ConnectorCommon, ConnectorCommonExt}, - ErrorResponse, Response, - }, - utils::BytesExt, -}; - -#[derive(Debug, Clone)] -pub struct DummyConnector; - -impl api::Payment for DummyConnector {} -impl api::PaymentSession for DummyConnector {} -impl api::ConnectorAccessToken for DummyConnector {} -impl api::MandateSetup for DummyConnector {} -impl api::PaymentAuthorize for DummyConnector {} -impl api::PaymentSync for DummyConnector {} -impl api::PaymentCapture for DummyConnector {} -impl api::PaymentVoid for DummyConnector {} -impl api::Refund for DummyConnector {} -impl api::RefundExecute for DummyConnector {} -impl api::RefundSync for DummyConnector {} -impl api::PaymentToken for DummyConnector {} - -impl - ConnectorIntegration< - api::PaymentMethodToken, - types::PaymentMethodTokenizationData, - types::PaymentsResponseData, - > for DummyConnector -{ - // Not Implemented (R) -} - -impl ConnectorCommonExt - for DummyConnector -where - Self: ConnectorIntegration, -{ - fn build_headers( - &self, - req: &types::RouterData, - _connectors: &settings::Connectors, - ) -> CustomResult)>, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self) - .to_string() - .into(), - ), - ( - common_consts::TENANT_HEADER.to_string(), - req.tenant_id.get_string_repr().to_string().into(), - ), - ]; - let mut api_key = self.get_auth_header(&req.connector_auth_type)?; - header.append(&mut api_key); - Ok(header) - } -} - -impl ConnectorCommon for DummyConnector { - fn id(&self) -> &'static str { - Into::::into(T).get_dummy_connector_id() - } - - fn common_get_content_type(&self) -> &'static str { - "application/json" - } - - fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str { - connectors.dummyconnector.base_url.as_ref() - } - - fn get_auth_header( - &self, - auth_type: &types::ConnectorAuthType, - ) -> CustomResult)>, errors::ConnectorError> { - let auth = transformers::DummyConnectorAuthType::try_from(auth_type) - .change_context(errors::ConnectorError::FailedToObtainAuthType)?; - Ok(vec![( - headers::AUTHORIZATION.to_string(), - auth.api_key.into_masked(), - )]) - } - - fn build_error_response( - &self, - res: Response, - event_builder: Option<&mut ConnectorEvent>, - ) -> CustomResult { - let response: transformers::DummyConnectorErrorResponse = res - .response - .parse_struct("DummyConnectorErrorResponse") - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - - event_builder.map(|i| i.set_error_response_body(&response)); - router_env::logger::info!(connector_response=?response); - - Ok(ErrorResponse { - status_code: res.status_code, - code: response.error.code, - message: response.error.message, - reason: response.error.reason, - attempt_status: None, - connector_transaction_id: None, - network_advice_code: None, - network_decline_code: None, - network_error_message: None, - }) - } -} - -impl ConnectorValidation for DummyConnector { - fn validate_connector_against_payment_request( - &self, - capture_method: Option, - _payment_method: enums::PaymentMethod, - _pmt: Option, - ) -> CustomResult<(), errors::ConnectorError> { - let capture_method = capture_method.unwrap_or_default(); - match capture_method { - enums::CaptureMethod::Automatic - | enums::CaptureMethod::Manual - | enums::CaptureMethod::SequentialAutomatic => Ok(()), - enums::CaptureMethod::ManualMultiple | enums::CaptureMethod::Scheduled => Err( - connector_utils::construct_not_supported_error_report(capture_method, self.id()), - ), - } - } -} - -impl - ConnectorIntegration - for DummyConnector -{ - //TODO: implement sessions flow -} - -impl - ConnectorIntegration - for DummyConnector -{ -} - -impl - ConnectorIntegration< - api::SetupMandate, - types::SetupMandateRequestData, - types::PaymentsResponseData, - > for DummyConnector -{ - fn build_request( - &self, - _req: &types::RouterData< - api::SetupMandate, - types::SetupMandateRequestData, - types::PaymentsResponseData, - >, - _connectors: &settings::Connectors, - ) -> CustomResult, errors::ConnectorError> { - Err(errors::ConnectorError::NotImplemented( - "Setup Mandate flow for DummyConnector".to_string(), - ) - .into()) - } -} - -impl - ConnectorIntegration - for DummyConnector -{ - fn get_headers( - &self, - req: &types::PaymentsAuthorizeRouterData, - connectors: &settings::Connectors, - ) -> CustomResult)>, errors::ConnectorError> { - self.build_headers(req, connectors) - } - - fn get_content_type(&self) -> &'static str { - self.common_get_content_type() - } - - fn get_url( - &self, - req: &types::PaymentsAuthorizeRouterData, - connectors: &settings::Connectors, - ) -> CustomResult { - match req.payment_method { - enums::PaymentMethod::Card - | enums::PaymentMethod::Upi - | enums::PaymentMethod::Wallet - | enums::PaymentMethod::PayLater => { - Ok(format!("{}/payment", self.base_url(connectors))) - } - _ => Err(error_stack::report!(errors::ConnectorError::NotSupported { - message: format!("The payment method {} is not supported", req.payment_method), - connector: Into::::into(T).get_dummy_connector_id(), - })), - } - } - - fn get_request_body( - &self, - req: &types::PaymentsAuthorizeRouterData, - _connectors: &settings::Connectors, - ) -> CustomResult { - let connector_req = transformers::DummyConnectorPaymentsRequest::::try_from(req)?; - Ok(RequestContent::Json(Box::new(connector_req))) - } - - fn build_request( - &self, - req: &types::PaymentsAuthorizeRouterData, - connectors: &settings::Connectors, - ) -> CustomResult, errors::ConnectorError> { - Ok(Some( - services::RequestBuilder::new() - .method(services::Method::Post) - .url(&types::PaymentsAuthorizeType::get_url( - self, req, connectors, - )?) - .attach_default_headers() - .headers(types::PaymentsAuthorizeType::get_headers( - self, req, connectors, - )?) - .set_body(types::PaymentsAuthorizeType::get_request_body( - self, req, connectors, - )?) - .build(), - )) - } - - fn handle_response( - &self, - data: &types::PaymentsAuthorizeRouterData, - event_builder: Option<&mut ConnectorEvent>, - res: Response, - ) -> CustomResult { - let response: transformers::PaymentsResponse = res - .response - .parse_struct("DummyConnector PaymentsResponse") - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - event_builder.map(|i| i.set_response_body(&response)); - router_env::logger::info!(connector_response=?response); - types::RouterData::try_from(types::ResponseRouterData { - response, - data: data.clone(), - http_code: res.status_code, - }) - .change_context(errors::ConnectorError::ResponseHandlingFailed) - } - - fn get_error_response( - &self, - res: Response, - event_builder: Option<&mut ConnectorEvent>, - ) -> CustomResult { - self.build_error_response(res, event_builder) - } -} - -impl - ConnectorIntegration - for DummyConnector -{ - fn get_headers( - &self, - req: &types::PaymentsSyncRouterData, - connectors: &settings::Connectors, - ) -> CustomResult)>, errors::ConnectorError> { - self.build_headers(req, connectors) - } - - fn get_content_type(&self) -> &'static str { - self.common_get_content_type() - } - - fn get_url( - &self, - req: &types::PaymentsSyncRouterData, - connectors: &settings::Connectors, - ) -> CustomResult { - match req - .request - .connector_transaction_id - .get_connector_transaction_id() - { - Ok(transaction_id) => Ok(format!( - "{}/payments/{}", - self.base_url(connectors), - transaction_id - )), - Err(_) => Err(error_stack::report!( - errors::ConnectorError::MissingConnectorTransactionID - )), - } - } - - fn build_request( - &self, - req: &types::PaymentsSyncRouterData, - connectors: &settings::Connectors, - ) -> CustomResult, errors::ConnectorError> { - Ok(Some( - services::RequestBuilder::new() - .method(services::Method::Get) - .url(&types::PaymentsSyncType::get_url(self, req, connectors)?) - .attach_default_headers() - .headers(types::PaymentsSyncType::get_headers(self, req, connectors)?) - .build(), - )) - } - - fn handle_response( - &self, - data: &types::PaymentsSyncRouterData, - event_builder: Option<&mut ConnectorEvent>, - res: Response, - ) -> CustomResult { - let response: transformers::PaymentsResponse = res - .response - .parse_struct("dummyconnector PaymentsSyncResponse") - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - event_builder.map(|i| i.set_response_body(&response)); - router_env::logger::info!(connector_response=?response); - types::RouterData::try_from(types::ResponseRouterData { - response, - data: data.clone(), - http_code: res.status_code, - }) - .change_context(errors::ConnectorError::ResponseHandlingFailed) - } - - fn get_error_response( - &self, - res: Response, - event_builder: Option<&mut ConnectorEvent>, - ) -> CustomResult { - self.build_error_response(res, event_builder) - } -} - -impl - ConnectorIntegration - for DummyConnector -{ - fn get_headers( - &self, - req: &types::PaymentsCaptureRouterData, - connectors: &settings::Connectors, - ) -> CustomResult)>, errors::ConnectorError> { - self.build_headers(req, connectors) - } - - fn get_content_type(&self) -> &'static str { - self.common_get_content_type() - } - - fn get_url( - &self, - _req: &types::PaymentsCaptureRouterData, - _connectors: &settings::Connectors, - ) -> CustomResult { - Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) - } - - fn get_request_body( - &self, - _req: &types::PaymentsCaptureRouterData, - _connectors: &settings::Connectors, - ) -> CustomResult { - Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into()) - } - - fn build_request( - &self, - req: &types::PaymentsCaptureRouterData, - connectors: &settings::Connectors, - ) -> CustomResult, errors::ConnectorError> { - Ok(Some( - services::RequestBuilder::new() - .method(services::Method::Post) - .url(&types::PaymentsCaptureType::get_url(self, req, connectors)?) - .attach_default_headers() - .headers(types::PaymentsCaptureType::get_headers( - self, req, connectors, - )?) - .build(), - )) - } - - fn handle_response( - &self, - data: &types::PaymentsCaptureRouterData, - event_builder: Option<&mut ConnectorEvent>, - res: Response, - ) -> CustomResult { - let response: transformers::PaymentsResponse = res - .response - .parse_struct("transformers PaymentsCaptureResponse") - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - event_builder.map(|i| i.set_response_body(&response)); - router_env::logger::info!(connector_response=?response); - types::RouterData::try_from(types::ResponseRouterData { - response, - data: data.clone(), - http_code: res.status_code, - }) - .change_context(errors::ConnectorError::ResponseHandlingFailed) - } - - fn get_error_response( - &self, - res: Response, - event_builder: Option<&mut ConnectorEvent>, - ) -> CustomResult { - self.build_error_response(res, event_builder) - } -} - -impl - ConnectorIntegration - for DummyConnector -{ -} - -impl ConnectorIntegration - for DummyConnector -{ - fn get_headers( - &self, - req: &types::RefundsRouterData, - connectors: &settings::Connectors, - ) -> CustomResult)>, errors::ConnectorError> { - self.build_headers(req, connectors) - } - - fn get_content_type(&self) -> &'static str { - self.common_get_content_type() - } - - fn get_url( - &self, - req: &types::RefundsRouterData, - connectors: &settings::Connectors, - ) -> CustomResult { - Ok(format!( - "{}/{}/refund", - self.base_url(connectors), - req.request.connector_transaction_id - )) - } - - fn get_request_body( - &self, - req: &types::RefundsRouterData, - _connectors: &settings::Connectors, - ) -> CustomResult { - let connector_req = transformers::DummyConnectorRefundRequest::try_from(req)?; - Ok(RequestContent::Json(Box::new(connector_req))) - } - - fn build_request( - &self, - req: &types::RefundsRouterData, - connectors: &settings::Connectors, - ) -> CustomResult, errors::ConnectorError> { - let request = services::RequestBuilder::new() - .method(services::Method::Post) - .url(&types::RefundExecuteType::get_url(self, req, connectors)?) - .attach_default_headers() - .headers(types::RefundExecuteType::get_headers( - self, req, connectors, - )?) - .set_body(types::RefundExecuteType::get_request_body( - self, req, connectors, - )?) - .build(); - Ok(Some(request)) - } - - fn handle_response( - &self, - data: &types::RefundsRouterData, - event_builder: Option<&mut ConnectorEvent>, - res: Response, - ) -> CustomResult, errors::ConnectorError> { - let response: transformers::RefundResponse = res - .response - .parse_struct("transformers RefundResponse") - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - event_builder.map(|i| i.set_response_body(&response)); - router_env::logger::info!(connector_response=?response); - types::RouterData::try_from(types::ResponseRouterData { - response, - data: data.clone(), - http_code: res.status_code, - }) - .change_context(errors::ConnectorError::ResponseHandlingFailed) - } - - fn get_error_response( - &self, - res: Response, - event_builder: Option<&mut ConnectorEvent>, - ) -> CustomResult { - self.build_error_response(res, event_builder) - } -} - -impl ConnectorIntegration - for DummyConnector -{ - fn get_headers( - &self, - req: &types::RefundSyncRouterData, - connectors: &settings::Connectors, - ) -> CustomResult)>, errors::ConnectorError> { - self.build_headers(req, connectors) - } - - fn get_content_type(&self) -> &'static str { - self.common_get_content_type() - } - - fn get_url( - &self, - req: &types::RefundSyncRouterData, - connectors: &settings::Connectors, - ) -> CustomResult { - let refund_id = req.request.get_connector_refund_id()?; - Ok(format!( - "{}/refunds/{}", - self.base_url(connectors), - refund_id - )) - } - - fn build_request( - &self, - req: &types::RefundSyncRouterData, - connectors: &settings::Connectors, - ) -> CustomResult, errors::ConnectorError> { - Ok(Some( - services::RequestBuilder::new() - .method(services::Method::Get) - .url(&types::RefundSyncType::get_url(self, req, connectors)?) - .attach_default_headers() - .headers(types::RefundSyncType::get_headers(self, req, connectors)?) - .build(), - )) - } - - fn handle_response( - &self, - data: &types::RefundSyncRouterData, - event_builder: Option<&mut ConnectorEvent>, - res: Response, - ) -> CustomResult { - let response: transformers::RefundResponse = res - .response - .parse_struct("transformers RefundSyncResponse") - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - event_builder.map(|i| i.set_response_body(&response)); - router_env::logger::info!(connector_response=?response); - types::RouterData::try_from(types::ResponseRouterData { - response, - data: data.clone(), - http_code: res.status_code, - }) - .change_context(errors::ConnectorError::ResponseHandlingFailed) - } - - fn get_error_response( - &self, - res: Response, - event_builder: Option<&mut ConnectorEvent>, - ) -> CustomResult { - self.build_error_response(res, event_builder) - } -} - -#[async_trait::async_trait] -impl api::IncomingWebhook for DummyConnector { - fn get_webhook_object_reference_id( - &self, - _request: &api::IncomingWebhookRequestDetails<'_>, - ) -> CustomResult { - Err(report!(errors::ConnectorError::WebhooksNotImplemented)) - } - - fn get_webhook_event_type( - &self, - _request: &api::IncomingWebhookRequestDetails<'_>, - ) -> CustomResult { - Ok(api::IncomingWebhookEvent::EventNotSupported) - } - - fn get_webhook_resource_object( - &self, - _request: &api::IncomingWebhookRequestDetails<'_>, - ) -> CustomResult, errors::ConnectorError> { - Err(report!(errors::ConnectorError::WebhooksNotImplemented)) - } -} - -impl ConnectorSpecifications for DummyConnector {} diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 2a7026dd26..c518c42ad1 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -1959,17 +1959,6 @@ where json.parse_value(std::any::type_name::()).switch() } -pub fn construct_not_supported_error_report( - capture_method: enums::CaptureMethod, - connector_name: &'static str, -) -> error_stack::Report { - errors::ConnectorError::NotSupported { - message: capture_method.to_string(), - connector: connector_name, - } - .into() -} - impl ForeignTryFrom for UsStatesAbbreviation { type Error = error_stack::Report; fn foreign_try_from(value: String) -> Result { diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index be009c127d..ae4da756d7 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -1383,7 +1383,7 @@ impl ConnectorAuthTypeAndMetadataValidation<'_> { | api_enums::Connector::DummyConnector5 | api_enums::Connector::DummyConnector6 | api_enums::Connector::DummyConnector7 => { - dummyconnector::transformers::DummyConnectorAuthType::try_from(self.auth_type)?; + hyperswitch_connectors::connectors::dummyconnector::transformers::DummyConnectorAuthType::try_from(self.auth_type)?; Ok(()) } api_enums::Connector::Aci => { diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs index 212aab9826..fa951af010 100644 --- a/crates/router/src/core/payments/flows.rs +++ b/crates/router/src/core/payments/flows.rs @@ -17,34 +17,13 @@ use async_trait::async_trait; use hyperswitch_domain_models::router_flow_types::{ BillingConnectorInvoiceSync, BillingConnectorPaymentsSync, RecoveryRecordBack, }; -#[cfg(feature = "dummy_connector")] -use hyperswitch_domain_models::router_flow_types::{ - ExternalVaultCreateFlow, ExternalVaultDeleteFlow, ExternalVaultInsertFlow, - ExternalVaultRetrieveFlow, -}; use hyperswitch_domain_models::{ - mandates::CustomerAcceptance, - router_flow_types::{ - Authenticate, AuthenticationConfirmation, PostAuthenticate, PreAuthenticate, - }, - router_request_types::PaymentsCaptureData, -}; -#[cfg(feature = "dummy_connector")] -use hyperswitch_interfaces::api::vault::{ - ExternalVault, ExternalVaultCreate, ExternalVaultDelete, ExternalVaultInsert, - ExternalVaultRetrieve, -}; -use hyperswitch_interfaces::api::{ - payouts::Payouts, UasAuthentication, UasAuthenticationConfirmation, UasPostAuthentication, - UasPreAuthentication, UnifiedAuthenticationService, + mandates::CustomerAcceptance, router_request_types::PaymentsCaptureData, }; -#[cfg(feature = "frm")] -use crate::types::fraud_check as frm_types; use crate::{ - connector, core::{ - errors::{ApiErrorResponse, ConnectorError, CustomResult, RouterResult}, + errors::{ApiErrorResponse, RouterResult}, payments::{self, helpers}, }, logger, @@ -215,522 +194,6 @@ pub trait Feature { } } -#[cfg(feature = "dummy_connector")] -impl api::PaymentsCompleteAuthorize for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::CompleteAuthorize, - types::CompleteAuthorizeData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::ConnectorVerifyWebhookSource for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::VerifyWebhookSource, - types::VerifyWebhookSourceRequestData, - types::VerifyWebhookSourceResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::ConnectorCustomer for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::CreateConnectorCustomer, - types::ConnectorCustomerData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl services::ConnectorRedirectResponse for connector::DummyConnector { - fn get_flow_type( - &self, - _query_params: &str, - _json_payload: Option, - _action: services::PaymentAction, - ) -> CustomResult { - Ok(payments::CallConnectorAction::Trigger) - } -} - -#[cfg(feature = "dummy_connector")] -impl api::ConnectorTransactionId for connector::DummyConnector {} - -#[cfg(feature = "dummy_connector")] -impl api::Dispute for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl api::AcceptDispute for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::Accept, - types::AcceptDisputeRequestData, - types::AcceptDisputeResponse, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::FileUpload for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl api::UploadFile for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::Upload, - types::UploadFileRequestData, - types::UploadFileResponse, - > for connector::DummyConnector -{ -} -#[cfg(feature = "dummy_connector")] -impl api::RetrieveFile for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::Retrieve, - types::RetrieveFileRequestData, - types::RetrieveFileResponse, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::SubmitEvidence for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::Evidence, - types::SubmitEvidenceRequestData, - types::SubmitEvidenceResponse, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::DefendDispute for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::Defend, - types::DefendDisputeRequestData, - types::DefendDisputeResponse, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::PaymentsPreProcessing for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::PreProcessing, - types::PaymentsPreProcessingData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::PaymentsPostProcessing for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::PostProcessing, - types::PaymentsPostProcessingData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl Payouts for connector::DummyConnector {} - -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl api::PayoutCreate for connector::DummyConnector {} -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration - for connector::DummyConnector -{ -} - -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl api::PayoutSync for connector::DummyConnector {} -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration - for connector::DummyConnector -{ -} - -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl api::PayoutEligibility for connector::DummyConnector {} -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::PoEligibility, - types::PayoutsData, - types::PayoutsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl api::PayoutFulfill for connector::DummyConnector {} -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration - for connector::DummyConnector -{ -} - -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl api::PayoutCancel for connector::DummyConnector {} -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration - for connector::DummyConnector -{ -} - -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl api::PayoutQuote for connector::DummyConnector {} -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration - for connector::DummyConnector -{ -} - -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl api::PayoutRecipient for connector::DummyConnector {} -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration - for connector::DummyConnector -{ -} - -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl api::PayoutRecipientAccount for connector::DummyConnector {} -#[cfg(feature = "payouts")] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::PoRecipientAccount, - types::PayoutsData, - types::PayoutsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::PaymentApprove for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::Approve, - types::PaymentsApproveData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::PaymentReject for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::Reject, - types::PaymentsRejectData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::FraudCheck for connector::DummyConnector {} - -#[cfg(all(feature = "frm", feature = "dummy_connector"))] -impl api::FraudCheckSale for connector::DummyConnector {} -#[cfg(all(feature = "frm", feature = "dummy_connector"))] -impl - services::ConnectorIntegration< - api::Sale, - frm_types::FraudCheckSaleData, - frm_types::FraudCheckResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(all(feature = "frm", feature = "dummy_connector"))] -impl api::FraudCheckCheckout for connector::DummyConnector {} -#[cfg(all(feature = "frm", feature = "dummy_connector"))] -impl - services::ConnectorIntegration< - api::Checkout, - frm_types::FraudCheckCheckoutData, - frm_types::FraudCheckResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(all(feature = "frm", feature = "dummy_connector"))] -impl api::FraudCheckTransaction for connector::DummyConnector {} -#[cfg(all(feature = "frm", feature = "dummy_connector"))] -impl - services::ConnectorIntegration< - api::Transaction, - frm_types::FraudCheckTransactionData, - frm_types::FraudCheckResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(all(feature = "frm", feature = "dummy_connector"))] -impl api::FraudCheckFulfillment for connector::DummyConnector {} -#[cfg(all(feature = "frm", feature = "dummy_connector"))] -impl - services::ConnectorIntegration< - api::Fulfillment, - frm_types::FraudCheckFulfillmentData, - frm_types::FraudCheckResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(all(feature = "frm", feature = "dummy_connector"))] -impl api::FraudCheckRecordReturn for connector::DummyConnector {} -#[cfg(all(feature = "frm", feature = "dummy_connector"))] -impl - services::ConnectorIntegration< - api::RecordReturn, - frm_types::FraudCheckRecordReturnData, - frm_types::FraudCheckResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::PaymentIncrementalAuthorization for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::IncrementalAuthorization, - types::PaymentsIncrementalAuthorizationData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::ConnectorMandateRevoke for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::MandateRevoke, - types::MandateRevokeRequestData, - types::MandateRevokeResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::ExternalAuthentication for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl api::ConnectorPreAuthentication for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl api::ConnectorPreAuthenticationVersionCall for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl api::ConnectorAuthentication for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl api::ConnectorPostAuthentication for connector::DummyConnector {} - -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::Authentication, - types::authentication::ConnectorAuthenticationRequestData, - types::authentication::AuthenticationResponseData, - > for connector::DummyConnector -{ -} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::PreAuthentication, - types::authentication::PreAuthNRequestData, - types::authentication::AuthenticationResponseData, - > for connector::DummyConnector -{ -} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::PreAuthenticationVersionCall, - types::authentication::PreAuthNRequestData, - types::authentication::AuthenticationResponseData, - > for connector::DummyConnector -{ -} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::PostAuthentication, - types::authentication::ConnectorPostAuthenticationRequestData, - types::authentication::AuthenticationResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::PaymentAuthorizeSessionToken for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::AuthorizeSessionToken, - types::AuthorizeSessionTokenData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::TaxCalculation for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::CalculateTax, - types::PaymentsTaxCalculationData, - types::TaxCalculationResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::PaymentSessionUpdate for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::SdkSessionUpdate, - types::SdkPaymentsSessionUpdateData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::PaymentPostSessionTokens for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::PostSessionTokens, - types::PaymentsPostSessionTokensData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::PaymentsCreateOrder for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::CreateOrder, - types::CreateOrderRequestData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl api::PaymentUpdateMetadata for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - api::UpdateMetadata, - types::PaymentsUpdateMetadataData, - types::PaymentsResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl UasPreAuthentication for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl UnifiedAuthenticationService for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - PreAuthenticate, - types::UasPreAuthenticationRequestData, - types::UasAuthenticationResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl UasPostAuthentication for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - PostAuthenticate, - types::UasPostAuthenticationRequestData, - types::UasAuthenticationResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl UasAuthenticationConfirmation for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - AuthenticationConfirmation, - types::UasConfirmationRequestData, - types::UasAuthenticationResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl UasAuthentication for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - Authenticate, - types::UasAuthenticationRequestData, - types::UasAuthenticationResponseData, - > for connector::DummyConnector -{ -} - /// Determines whether a capture API call should be made for a payment attempt /// This function evaluates whether an authorized payment should proceed with a capture API call /// based on various payment parameters. It's primarily used in two-step (auth + capture) payment flows for CaptureMethod SequentialAutomatic @@ -841,99 +304,3 @@ fn handle_post_capture_response( } } } - -#[cfg(feature = "dummy_connector")] -impl api::RevenueRecovery for connector::DummyConnector {} - -#[cfg(all(feature = "v2", feature = "revenue_recovery"))] -#[cfg(feature = "dummy_connector")] -impl api::BillingConnectorPaymentsSyncIntegration for connector::DummyConnector {} -#[cfg(all(feature = "v2", feature = "revenue_recovery"))] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - BillingConnectorPaymentsSync, - types::BillingConnectorPaymentsSyncRequest, - types::BillingConnectorPaymentsSyncResponse, - > for connector::DummyConnector -{ -} - -#[cfg(all(feature = "v2", feature = "revenue_recovery"))] -#[cfg(feature = "dummy_connector")] -impl api::RevenueRecoveryRecordBack for connector::DummyConnector {} -#[cfg(all(feature = "v2", feature = "revenue_recovery"))] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - RecoveryRecordBack, - types::RevenueRecoveryRecordBackRequest, - types::RevenueRecoveryRecordBackResponse, - > for connector::DummyConnector -{ -} - -#[cfg(all(feature = "v2", feature = "revenue_recovery"))] -#[cfg(feature = "dummy_connector")] -impl api::BillingConnectorInvoiceSyncIntegration for connector::DummyConnector {} -#[cfg(all(feature = "v2", feature = "revenue_recovery"))] -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - BillingConnectorInvoiceSync, - types::BillingConnectorInvoiceSyncRequest, - types::BillingConnectorInvoiceSyncResponse, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl ExternalVault for connector::DummyConnector {} - -#[cfg(feature = "dummy_connector")] -impl ExternalVaultInsert for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - ExternalVaultInsertFlow, - types::VaultRequestData, - types::VaultResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl ExternalVaultRetrieve for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - ExternalVaultRetrieveFlow, - types::VaultRequestData, - types::VaultResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl ExternalVaultDelete for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - ExternalVaultDeleteFlow, - types::VaultRequestData, - types::VaultResponseData, - > for connector::DummyConnector -{ -} - -#[cfg(feature = "dummy_connector")] -impl ExternalVaultCreate for connector::DummyConnector {} -#[cfg(feature = "dummy_connector")] -impl - services::ConnectorIntegration< - ExternalVaultCreateFlow, - types::VaultRequestData, - types::VaultResponseData, - > for connector::DummyConnector -{ -}