From d14ed53d917f6c240a28b50f9cc71eb940f5808d Mon Sep 17 00:00:00 2001 From: Sagnik Mitra Date: Tue, 19 Nov 2024 14:41:27 +0530 Subject: [PATCH] paymentwall template --- config/config.example.toml | 1 + config/deployments/integration_test.toml | 1 + config/deployments/production.toml | 1 + config/deployments/sandbox.toml | 1 + config/development.toml | 2 + config/docker_compose.toml | 2 + crates/api_models/src/connector_enums.rs | 2 + crates/common_enums/src/connector_enums.rs | 1 + .../hyperswitch_connectors/src/connectors.rs | 3 +- .../src/connectors/paymentwall.rs | 553 ++++++++++++++++++ .../connectors/paymentwall/transformers.rs | 232 ++++++++ .../src/default_implementations.rs | 32 + .../src/default_implementations_v2.rs | 22 + crates/hyperswitch_interfaces/src/configs.rs | 1 + crates/router/src/connector.rs | 2 +- .../connector_integration_v2_impls.rs | 3 + crates/router/src/core/payments/flows.rs | 3 + crates/router/src/types/api.rs | 1 + crates/router/src/types/transformers.rs | 1 + crates/router/tests/connectors/main.rs | 1 + crates/router/tests/connectors/paymentwall.rs | 401 +++++++++++++ .../router/tests/connectors/sample_auth.toml | 3 + crates/test_utils/src/connector_auth.rs | 1 + loadtest/config/development.toml | 2 + scripts/add_connector.sh | 2 +- 25 files changed, 1271 insertions(+), 3 deletions(-) create mode 100644 crates/hyperswitch_connectors/src/connectors/paymentwall.rs create mode 100644 crates/hyperswitch_connectors/src/connectors/paymentwall/transformers.rs create mode 100644 crates/router/tests/connectors/paymentwall.rs diff --git a/config/config.example.toml b/config/config.example.toml index 289087f4a33..6516411e155 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -242,6 +242,7 @@ paybox.base_url = "https://preprod-ppps.paybox.com/PPPS.php" paybox.secondary_base_url="https://preprod-tpeweb.paybox.com/" payeezy.base_url = "https://api-cert.payeezy.com/" payme.base_url = "https://sandbox.payme.io/" +paymentwall.base_url = "https://api.paymentwall.com/" payone.base_url = "https://payment.preprod.payone.com/" paypal.base_url = "https://api-m.sandbox.paypal.com/" payu.base_url = "https://secure.snd.payu.com/" diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml index 1c7a40ea539..775cf8527ac 100644 --- a/config/deployments/integration_test.toml +++ b/config/deployments/integration_test.toml @@ -83,6 +83,7 @@ paybox.base_url = "https://preprod-ppps.paybox.com/PPPS.php" paybox.secondary_base_url="https://preprod-tpeweb.paybox.com/" payeezy.base_url = "https://api-cert.payeezy.com/" payme.base_url = "https://sandbox.payme.io/" +paymentwall.base_url = "https://api.paymentwall.com/" payone.base_url = "https://payment.preprod.payone.com/" paypal.base_url = "https://api-m.sandbox.paypal.com/" payu.base_url = "https://secure.snd.payu.com/" diff --git a/config/deployments/production.toml b/config/deployments/production.toml index 73e5794f042..ca8a758055f 100644 --- a/config/deployments/production.toml +++ b/config/deployments/production.toml @@ -87,6 +87,7 @@ paybox.base_url = "https://ppps.paybox.com/PPPS.php" paybox.secondary_base_url="https://tpeweb.paybox.com/" payeezy.base_url = "https://api.payeezy.com/" payme.base_url = "https://live.payme.io/" +paymentwall.base_url= "https://pwgateway.com/" payone.base_url = "https://payment.payone.com/" paypal.base_url = "https://api-m.paypal.com/" payu.base_url = "https://secure.payu.com/api/" diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml index 98e1e7e00d9..444c72e2203 100644 --- a/config/deployments/sandbox.toml +++ b/config/deployments/sandbox.toml @@ -87,6 +87,7 @@ paybox.base_url = "https://preprod-ppps.paybox.com/PPPS.php" paybox.secondary_base_url="https://preprod-tpeweb.paybox.com/" payeezy.base_url = "https://api-cert.payeezy.com/" payme.base_url = "https://sandbox.payme.io/" +paymentwall.base_url = "https://api.paymentwall.com/" payone.base_url = "https://payment.preprod.payone.com/" paypal.base_url = "https://api-m.sandbox.paypal.com/" payu.base_url = "https://secure.snd.payu.com/" diff --git a/config/development.toml b/config/development.toml index b6638fe1d47..b027edec26f 100644 --- a/config/development.toml +++ b/config/development.toml @@ -147,6 +147,7 @@ cards = [ "paybox", "payeezy", "payme", + "paymentwall", "payone", "paypal", "payu", @@ -256,6 +257,7 @@ paybox.base_url = "https://preprod-ppps.paybox.com/PPPS.php" paybox.secondary_base_url="https://preprod-tpeweb.paybox.com/" payeezy.base_url = "https://api-cert.payeezy.com/" payme.base_url = "https://sandbox.payme.io/" +paymentwall.base_url = "https://api.paymentwall.com/" payone.base_url = "https://payment.preprod.payone.com/" paypal.base_url = "https://api-m.sandbox.paypal.com/" payu.base_url = "https://secure.snd.payu.com/" diff --git a/config/docker_compose.toml b/config/docker_compose.toml index 7adeee8a376..e331383e623 100644 --- a/config/docker_compose.toml +++ b/config/docker_compose.toml @@ -172,6 +172,7 @@ paybox.base_url = "https://preprod-ppps.paybox.com/PPPS.php" paybox.secondary_base_url="https://preprod-tpeweb.paybox.com/" payeezy.base_url = "https://api-cert.payeezy.com/" payme.base_url = "https://sandbox.payme.io/" +paymentwall.base_url = "https://api.paymentwall.com/" payone.base_url = "https://payment.preprod.payone.com/" paypal.base_url = "https://api-m.sandbox.paypal.com/" payu.base_url = "https://secure.snd.payu.com/" @@ -265,6 +266,7 @@ cards = [ "paybox", "payeezy", "payme", + "paymentwall", "payone", "paypal", "payu", diff --git a/crates/api_models/src/connector_enums.rs b/crates/api_models/src/connector_enums.rs index 77081f49957..766e54f4027 100644 --- a/crates/api_models/src/connector_enums.rs +++ b/crates/api_models/src/connector_enums.rs @@ -103,6 +103,7 @@ pub enum Connector { Paybox, // Payeezy, As psync and rsync are not supported by this connector, it is added as template code for future usage Payme, + // Paymentwall, Payone, Paypal, Payu, @@ -239,6 +240,7 @@ impl Connector { | Self::Opennode | Self::Paybox | Self::Payme + // | Self::Paymentwall | Self::Payone | Self::Paypal | Self::Payu diff --git a/crates/common_enums/src/connector_enums.rs b/crates/common_enums/src/connector_enums.rs index 9beaed75960..3c9570fc618 100644 --- a/crates/common_enums/src/connector_enums.rs +++ b/crates/common_enums/src/connector_enums.rs @@ -98,6 +98,7 @@ pub enum RoutableConnectors { // Payeezy, As psync and rsync are not supported by this connector, it is added as template code for future usage Paybox, Payme, + // Paymentwall, Payone, Paypal, Payu, diff --git a/crates/hyperswitch_connectors/src/connectors.rs b/crates/hyperswitch_connectors/src/connectors.rs index 2bc82450096..153f89d6cd2 100644 --- a/crates/hyperswitch_connectors/src/connectors.rs +++ b/crates/hyperswitch_connectors/src/connectors.rs @@ -24,6 +24,7 @@ pub mod nexixpay; pub mod nomupay; pub mod novalnet; pub mod payeezy; +pub mod paymentwall; pub mod payu; pub mod powertranz; pub mod razorpay; @@ -46,7 +47,7 @@ pub use self::{ fiserv::Fiserv, fiservemea::Fiservemea, fiuu::Fiuu, forte::Forte, globepay::Globepay, helcim::Helcim, jpmorgan::Jpmorgan, mollie::Mollie, multisafepay::Multisafepay, nexinets::Nexinets, nexixpay::Nexixpay, nomupay::Nomupay, novalnet::Novalnet, payeezy::Payeezy, - payu::Payu, powertranz::Powertranz, razorpay::Razorpay, shift4::Shift4, square::Square, + paymentwall::Paymentwall, payu::Payu, powertranz::Powertranz, razorpay::Razorpay, shift4::Shift4, square::Square, stax::Stax, taxjar::Taxjar, thunes::Thunes, tsys::Tsys, volt::Volt, worldline::Worldline, worldpay::Worldpay, zen::Zen, zsl::Zsl, }; diff --git a/crates/hyperswitch_connectors/src/connectors/paymentwall.rs b/crates/hyperswitch_connectors/src/connectors/paymentwall.rs new file mode 100644 index 00000000000..cd0ed5c1b0f --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/paymentwall.rs @@ -0,0 +1,553 @@ +pub mod transformers; + +use error_stack::{report, ResultExt}; +use masking::{ExposeInterface, Mask}; + +use common_utils::{ + errors::CustomResult, + ext_traits::BytesExt, + types::{AmountConvertor, StringMinorUnit, StringMinorUnitForConnector}, + request::{Method, Request, RequestBuilder, RequestContent}, +}; + +use hyperswitch_domain_models::{ + router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData}, + router_flow_types::{ + access_token_auth::AccessTokenAuth, + payments::{ + Authorize, Capture, PSync, PaymentMethodToken, Session, + SetupMandate, Void, + }, + refunds::{Execute, RSync}, + }, + 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::{self, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, ConnectorValidation}, + configs::Connectors, + errors, + events::connector_api_logs::ConnectorEvent, + types::{self, Response}, + webhooks, +}; +use crate::{ + constants::headers, + types::ResponseRouterData, + utils, +}; + +use transformers as paymentwall; + +#[derive(Clone)] +pub struct Paymentwall { + amount_converter: &'static (dyn AmountConvertor + Sync) +} + +impl Paymentwall { + pub fn new() -> &'static Self { + &Self { + amount_converter: &StringMinorUnitForConnector + } + } +} + +impl api::Payment for Paymentwall {} +impl api::PaymentSession for Paymentwall {} +impl api::ConnectorAccessToken for Paymentwall {} +impl api::MandateSetup for Paymentwall {} +impl api::PaymentAuthorize for Paymentwall {} +impl api::PaymentSync for Paymentwall {} +impl api::PaymentCapture for Paymentwall {} +impl api::PaymentVoid for Paymentwall {} +impl api::Refund for Paymentwall {} +impl api::RefundExecute for Paymentwall {} +impl api::RefundSync for Paymentwall {} +impl api::PaymentToken for Paymentwall {} + +impl + ConnectorIntegration< + PaymentMethodToken, + PaymentMethodTokenizationData, + PaymentsResponseData, + > for Paymentwall +{ + // Not Implemented (R) +} + +impl ConnectorCommonExt for Paymentwall +where + Self: ConnectorIntegration,{ + fn build_headers( + &self, + req: &RouterData, + _connectors: &Connectors, + ) -> CustomResult)>, errors::ConnectorError> { + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + self.get_content_type().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 Paymentwall { + fn id(&self) -> &'static str { + "paymentwall" + } + + fn get_currency_unit(&self) -> api::CurrencyUnit { + api::CurrencyUnit::Base + // TODO! Check connector documentation, on which unit they are processing the currency. + // If the connector accepts amount in lower unit ( i.e cents for USD) then return api::CurrencyUnit::Minor, + // if connector accepts amount in base unit (i.e dollars for USD) then return api::CurrencyUnit::Base + } + + fn common_get_content_type(&self) -> &'static str { + "application/json" + } + + fn base_url<'a>(&self, connectors: &'a Connectors) -> &'a str { + connectors.paymentwall.base_url.as_ref() + } + + fn get_auth_header(&self, auth_type:&ConnectorAuthType)-> CustomResult)>,errors::ConnectorError> { + let auth = paymentwall::PaymentwallAuthType::try_from(auth_type) + .change_context(errors::ConnectorError::FailedToObtainAuthType)?; + Ok(vec![(headers::AUTHORIZATION.to_string(), auth.api_key.expose().into_masked())]) + } + + fn build_error_response( + &self, + res: Response, + event_builder: Option<&mut ConnectorEvent>, + ) -> CustomResult { + let response: paymentwall::PaymentwallErrorResponse = res + .response + .parse_struct("PaymentwallErrorResponse") + .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + + event_builder.map(|i| i.set_response_body(&response)); + router_env::logger::info!(connector_response=?response); + + Ok(ErrorResponse { + status_code: res.status_code, + code: response.code, + message: response.message, + reason: response.reason, + attempt_status: None, + connector_transaction_id: None, + }) + } +} + +impl ConnectorValidation for Paymentwall +{ + //TODO: implement functions when support enabled +} + +impl + ConnectorIntegration< + Session, + PaymentsSessionData, + PaymentsResponseData, + > for Paymentwall +{ + //TODO: implement sessions flow +} + +impl ConnectorIntegration + for Paymentwall +{ +} + +impl + ConnectorIntegration< + SetupMandate, + SetupMandateRequestData, + PaymentsResponseData, + > for Paymentwall +{ +} + +impl + ConnectorIntegration< + Authorize, + PaymentsAuthorizeData, + PaymentsResponseData, + > for Paymentwall { + fn get_headers(&self, req: &PaymentsAuthorizeRouterData, connectors: &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: &PaymentsAuthorizeRouterData, _connectors: &Connectors,) -> CustomResult { + Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) + } + + fn get_request_body(&self, req: &PaymentsAuthorizeRouterData, _connectors: &Connectors,) -> CustomResult { + let amount = utils::convert_amount( + self.amount_converter, + req.request.minor_amount, + req.request.currency, + )?; + + let connector_router_data = + paymentwall::PaymentwallRouterData::from(( + amount, + req, + )); + let connector_req = paymentwall::PaymentwallPaymentsRequest::try_from(&connector_router_data)?; + Ok(RequestContent::Json(Box::new(connector_req))) + } + + fn build_request( + &self, + req: &PaymentsAuthorizeRouterData, + connectors: &Connectors, + ) -> CustomResult, errors::ConnectorError> { + Ok(Some( + RequestBuilder::new() + .method(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: &PaymentsAuthorizeRouterData, + event_builder: Option<&mut ConnectorEvent>, + res: Response, + ) -> CustomResult { + let response: paymentwall::PaymentwallPaymentsResponse = res.response.parse_struct("Paymentwall PaymentsAuthorizeResponse").change_context(errors::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, + }) + } + + fn get_error_response(&self, res: Response, event_builder: Option<&mut ConnectorEvent>) -> CustomResult { + self.build_error_response(res, event_builder) + } +} + +impl + ConnectorIntegration + for Paymentwall +{ + fn get_headers( + &self, + req: &PaymentsSyncRouterData, + connectors: &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: &PaymentsSyncRouterData, + _connectors: &Connectors, + ) -> CustomResult { + Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) + } + + fn build_request( + &self, + req: &PaymentsSyncRouterData, + connectors: &Connectors, + ) -> CustomResult, errors::ConnectorError> { + Ok(Some( + RequestBuilder::new() + .method(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: &PaymentsSyncRouterData, + event_builder: Option<&mut ConnectorEvent>, + res: Response, + ) -> CustomResult { + let response: paymentwall:: PaymentwallPaymentsResponse = res + .response + .parse_struct("paymentwall PaymentsSyncResponse") + .change_context(errors::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, + }) + } + + fn get_error_response( + &self, + res: Response, + event_builder: Option<&mut ConnectorEvent> + ) -> CustomResult { + self.build_error_response(res, event_builder) + } +} + +impl + ConnectorIntegration< + Capture, + PaymentsCaptureData, + PaymentsResponseData, + > for Paymentwall +{ + fn get_headers( + &self, + req: &PaymentsCaptureRouterData, + connectors: &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: &PaymentsCaptureRouterData, + _connectors: &Connectors, + ) -> CustomResult { + Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) + } + + fn get_request_body( + &self, + _req: &PaymentsCaptureRouterData, + _connectors: &Connectors, + ) -> CustomResult { + Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into()) + } + + fn build_request( + &self, + req: &PaymentsCaptureRouterData, + connectors: &Connectors, + ) -> CustomResult, errors::ConnectorError> { + Ok(Some( + RequestBuilder::new() + .method(Method::Post) + .url(&types::PaymentsCaptureType::get_url(self, req, connectors)?) + .attach_default_headers() + .headers(types::PaymentsCaptureType::get_headers( + self, req, connectors, + )?) + .set_body(types::PaymentsCaptureType::get_request_body(self, req, connectors)?) + .build(), + )) + } + + fn handle_response( + &self, + data: &PaymentsCaptureRouterData, + event_builder: Option<&mut ConnectorEvent>, + res: Response, + ) -> CustomResult { + let response: paymentwall::PaymentwallPaymentsResponse = res + .response + .parse_struct("Paymentwall PaymentsCaptureResponse") + .change_context(errors::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, + }) + } + + fn get_error_response( + &self, + res: Response, + event_builder: Option<&mut ConnectorEvent> + ) -> CustomResult { + self.build_error_response(res, event_builder) + } +} + +impl + ConnectorIntegration< + Void, + PaymentsCancelData, + PaymentsResponseData, + > for Paymentwall +{} + +impl + ConnectorIntegration< + Execute, + RefundsData, + RefundsResponseData, + > for Paymentwall { + fn get_headers(&self, req: &RefundsRouterData, connectors: &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: &RefundsRouterData, _connectors: &Connectors,) -> CustomResult { + Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) + } + + fn get_request_body(&self, req: &RefundsRouterData, _connectors: &Connectors,) -> CustomResult { + let refund_amount = utils::convert_amount( + self.amount_converter, + req.request.minor_refund_amount, + req.request.currency, + )?; + + let connector_router_data = + paymentwall::PaymentwallRouterData::from(( + refund_amount, + req, + )); + let connector_req = paymentwall::PaymentwallRefundRequest::try_from(&connector_router_data)?; + Ok(RequestContent::Json(Box::new(connector_req))) + } + + fn build_request(&self, req: &RefundsRouterData, connectors: &Connectors,) -> CustomResult,errors::ConnectorError> { + let request = RequestBuilder::new() + .method(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: &RefundsRouterData, + event_builder: Option<&mut ConnectorEvent>, + res: Response, + ) -> CustomResult,errors::ConnectorError> { + let response: paymentwall::RefundResponse = res.response.parse_struct("paymentwall RefundResponse").change_context(errors::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, + }) + } + + fn get_error_response(&self, res: Response, event_builder: Option<&mut ConnectorEvent>) -> CustomResult { + self.build_error_response(res, event_builder) + } +} + +impl + ConnectorIntegration for Paymentwall { + fn get_headers(&self, req: &RefundSyncRouterData,connectors: &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: &RefundSyncRouterData,_connectors: &Connectors,) -> CustomResult { + Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) + } + + fn build_request( + &self, + req: &RefundSyncRouterData, + connectors: &Connectors, + ) -> CustomResult, errors::ConnectorError> { + Ok(Some( + RequestBuilder::new() + .method(Method::Get) + .url(&types::RefundSyncType::get_url(self, req, connectors)?) + .attach_default_headers() + .headers(types::RefundSyncType::get_headers(self, req, connectors)?) + .set_body(types::RefundSyncType::get_request_body(self, req, connectors)?) + .build(), + )) + } + + fn handle_response( + &self, + data: &RefundSyncRouterData, + event_builder: Option<&mut ConnectorEvent>, + res: Response, + ) -> CustomResult { + let response: paymentwall::RefundResponse = res.response.parse_struct("paymentwall RefundSyncResponse").change_context(errors::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, + }) + } + + 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 webhooks::IncomingWebhook for Paymentwall { + fn get_webhook_object_reference_id( + &self, + _request: &webhooks::IncomingWebhookRequestDetails<'_>, + ) -> CustomResult { + Err(report!(errors::ConnectorError::WebhooksNotImplemented)) + } + + fn get_webhook_event_type( + &self, + _request: &webhooks::IncomingWebhookRequestDetails<'_>, + ) -> CustomResult { + Err(report!(errors::ConnectorError::WebhooksNotImplemented)) + } + + fn get_webhook_resource_object( + &self, + _request: &webhooks::IncomingWebhookRequestDetails<'_>, + ) -> CustomResult, errors::ConnectorError> { + Err(report!(errors::ConnectorError::WebhooksNotImplemented)) + } +} diff --git a/crates/hyperswitch_connectors/src/connectors/paymentwall/transformers.rs b/crates/hyperswitch_connectors/src/connectors/paymentwall/transformers.rs new file mode 100644 index 00000000000..c4b5419ed69 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/paymentwall/transformers.rs @@ -0,0 +1,232 @@ +use common_enums::enums; +use serde::{Deserialize, Serialize}; +use masking::Secret; +use common_utils::types::{StringMinorUnit}; +use hyperswitch_domain_models::{ + payment_method_data::PaymentMethodData, + router_data::{ConnectorAuthType, RouterData}, + router_flow_types::refunds::{Execute, RSync}, + router_request_types::ResponseId, + router_response_types::{PaymentsResponseData, RefundsResponseData}, + types::{PaymentsAuthorizeRouterData, RefundsRouterData}, +}; +use hyperswitch_interfaces::errors; +use crate::{ + types::{RefundsResponseRouterData, ResponseRouterData}, + utils::PaymentsAuthorizeRequestData, +}; + +//TODO: Fill the struct with respective fields +pub struct PaymentwallRouterData { + pub amount: StringMinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc. + pub router_data: T, +} + +impl + From<( + StringMinorUnit, + T, + )> for PaymentwallRouterData +{ + fn from( + (amount, item): ( + StringMinorUnit, + T, + ), + ) -> Self { + //Todo : use utils to convert the amount to the type of amount that a connector accepts + Self { + amount, + router_data: item, + } + } +} + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Serialize, PartialEq)] +pub struct PaymentwallPaymentsRequest { + amount: StringMinorUnit, + card: PaymentwallCard +} + +#[derive(Default, Debug, Serialize, Eq, PartialEq)] +pub struct PaymentwallCard { + number: cards::CardNumber, + expiry_month: Secret, + expiry_year: Secret, + cvc: Secret, + complete: bool, +} + +impl TryFrom<&PaymentwallRouterData<&PaymentsAuthorizeRouterData>> for PaymentwallPaymentsRequest { + type Error = error_stack::Report; + fn try_from(item: &PaymentwallRouterData<&PaymentsAuthorizeRouterData>) -> Result { + match item.router_data.request.payment_method_data.clone() { + PaymentMethodData::Card(req_card) => { + let card = PaymentwallCard { + number: req_card.card_number, + expiry_month: req_card.card_exp_month, + expiry_year: req_card.card_exp_year, + cvc: req_card.card_cvc, + complete: item.router_data.request.is_auto_capture()?, + }; + Ok(Self { + amount: item.amount.clone(), + card, + }) + } + _ => Err(errors::ConnectorError::NotImplemented("Payment method".to_string()).into()), + } + } +} + +//TODO: Fill the struct with respective fields +// Auth Struct +pub struct PaymentwallAuthType { + pub(super) api_key: Secret +} + +impl TryFrom<&ConnectorAuthType> for PaymentwallAuthType { + type Error = error_stack::Report; + fn try_from(auth_type: &ConnectorAuthType) -> Result { + match auth_type { + ConnectorAuthType::HeaderKey { api_key } => Ok(Self { + api_key: api_key.to_owned(), + }), + _ => Err(errors::ConnectorError::FailedToObtainAuthType.into()), + } + } +} +// PaymentsResponse +//TODO: Append the remaining status flags +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum PaymentwallPaymentStatus { + Succeeded, + Failed, + #[default] + Processing, +} + +impl From for common_enums::AttemptStatus { + fn from(item: PaymentwallPaymentStatus) -> Self { + match item { + PaymentwallPaymentStatus::Succeeded => Self::Charged, + PaymentwallPaymentStatus::Failed => Self::Failure, + PaymentwallPaymentStatus::Processing => Self::Authorizing, + } + } +} + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct PaymentwallPaymentsResponse { + status: PaymentwallPaymentStatus, + id: String, +} + +impl TryFrom> for RouterData { + type Error = error_stack::Report; + fn try_from(item: ResponseRouterData) -> Result { + Ok(Self { + status: common_enums::AttemptStatus::from(item.response.status), + response: Ok(PaymentsResponseData::TransactionResponse { + resource_id: ResponseId::ConnectorTransactionId(item.response.id), + redirection_data: Box::new(None), + mandate_reference: Box::new(None), + connector_metadata: None, + network_txn_id: None, + connector_response_reference_id: None, + incremental_authorization_allowed: None, + charge_id: None, + }), + ..item.data + }) + } +} + +//TODO: Fill the struct with respective fields +// REFUND : +// Type definition for RefundRequest +#[derive(Default, Debug, Serialize)] +pub struct PaymentwallRefundRequest { + pub amount: StringMinorUnit +} + +impl TryFrom<&PaymentwallRouterData<&RefundsRouterData>> for PaymentwallRefundRequest { + type Error = error_stack::Report; + fn try_from(item: &PaymentwallRouterData<&RefundsRouterData>) -> Result { + Ok(Self { + amount: item.amount.to_owned(), + }) + } +} + +// Type definition for Refund Response + +#[allow(dead_code)] +#[derive(Debug, Serialize, Default, Deserialize, Clone)] +pub enum RefundStatus { + Succeeded, + Failed, + #[default] + Processing, +} + +impl From for enums::RefundStatus { + fn from(item: RefundStatus) -> Self { + match item { + RefundStatus::Succeeded => Self::Success, + RefundStatus::Failed => Self::Failure, + RefundStatus::Processing => Self::Pending, + //TODO: Review mapping + } + } +} + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Clone, Serialize, Deserialize)] +pub struct RefundResponse { + id: String, + status: RefundStatus +} + +impl TryFrom> + for RefundsRouterData +{ + type Error = error_stack::Report; + fn try_from( + item: RefundsResponseRouterData, + ) -> Result { + Ok(Self { + response: Ok(RefundsResponseData { + connector_refund_id: item.response.id.to_string(), + refund_status: enums::RefundStatus::from(item.response.status), + }), + ..item.data + }) + } +} + +impl TryFrom> for RefundsRouterData +{ + type Error = error_stack::Report; + fn try_from(item: RefundsResponseRouterData) -> Result { + Ok(Self { + response: Ok(RefundsResponseData { + connector_refund_id: item.response.id.to_string(), + refund_status: enums::RefundStatus::from(item.response.status), + }), + ..item.data + }) + } + } + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Serialize, Deserialize, PartialEq)] +pub struct PaymentwallErrorResponse { + pub status_code: u16, + pub code: String, + pub message: String, + pub reason: Option, +} diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs index 6ee8926f8df..8da8b9eee0e 100644 --- a/crates/hyperswitch_connectors/src/default_implementations.rs +++ b/crates/hyperswitch_connectors/src/default_implementations.rs @@ -113,6 +113,7 @@ default_imp_for_authorize_session_token!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -171,6 +172,7 @@ default_imp_for_calculate_tax!( connectors::Nomupay, connectors::Novalnet, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Razorpay, @@ -229,6 +231,7 @@ default_imp_for_session_update!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Fiuu, connectors::Globepay, @@ -286,6 +289,7 @@ default_imp_for_post_session_tokens!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Fiuu, connectors::Globepay, @@ -337,6 +341,7 @@ default_imp_for_complete_authorize!( connectors::Novalnet, connectors::Nexinets, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Razorpay, connectors::Stax, @@ -390,6 +395,7 @@ default_imp_for_incremental_authorization!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -450,6 +456,7 @@ default_imp_for_create_customer!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Razorpay, @@ -504,6 +511,7 @@ default_imp_for_connector_redirect_response!( connectors::Nexixpay, connectors::Nomupay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Razorpay, @@ -556,6 +564,7 @@ default_imp_for_pre_processing_steps!( connectors::Novalnet, connectors::Nexinets, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -613,6 +622,7 @@ default_imp_for_post_processing_steps!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -671,6 +681,7 @@ default_imp_for_approve!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -729,6 +740,7 @@ default_imp_for_reject!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -787,6 +799,7 @@ default_imp_for_webhook_source_verification!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -846,6 +859,7 @@ default_imp_for_accept_dispute!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -904,6 +918,7 @@ default_imp_for_submit_evidence!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -962,6 +977,7 @@ default_imp_for_defend_dispute!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1029,6 +1045,7 @@ default_imp_for_file_upload!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1082,6 +1099,7 @@ default_imp_for_payouts!( connectors::Nomupay, connectors::Novalnet, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Razorpay, @@ -1139,6 +1157,7 @@ default_imp_for_payouts_create!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1199,6 +1218,7 @@ default_imp_for_payouts_retrieve!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1259,6 +1279,7 @@ default_imp_for_payouts_eligibility!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1319,6 +1340,7 @@ default_imp_for_payouts_fulfill!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1379,6 +1401,7 @@ default_imp_for_payouts_cancel!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1439,6 +1462,7 @@ default_imp_for_payouts_quote!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1499,6 +1523,7 @@ default_imp_for_payouts_recipient!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1559,6 +1584,7 @@ default_imp_for_payouts_recipient_account!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1619,6 +1645,7 @@ default_imp_for_frm_sale!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1679,6 +1706,7 @@ default_imp_for_frm_checkout!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1739,6 +1767,7 @@ default_imp_for_frm_transaction!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1799,6 +1828,7 @@ default_imp_for_frm_fulfillment!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1859,6 +1889,7 @@ default_imp_for_frm_record_return!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1916,6 +1947,7 @@ default_imp_for_revoking_mandates!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rs index d747d65d73a..b28099e3aa6 100644 --- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs +++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs @@ -229,6 +229,7 @@ default_imp_for_new_connector_integration_payment!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -288,6 +289,7 @@ default_imp_for_new_connector_integration_refund!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -342,6 +344,7 @@ default_imp_for_new_connector_integration_connector_access_token!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -402,6 +405,7 @@ default_imp_for_new_connector_integration_accept_dispute!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -461,6 +465,7 @@ default_imp_for_new_connector_integration_submit_evidence!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -520,6 +525,7 @@ default_imp_for_new_connector_integration_defend_dispute!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -589,6 +595,7 @@ default_imp_for_new_connector_integration_file_upload!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -650,6 +657,7 @@ default_imp_for_new_connector_integration_payouts_create!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -711,6 +719,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -772,6 +781,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -833,6 +843,7 @@ default_imp_for_new_connector_integration_payouts_cancel!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -894,6 +905,7 @@ default_imp_for_new_connector_integration_payouts_quote!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -955,6 +967,7 @@ default_imp_for_new_connector_integration_payouts_recipient!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1016,6 +1029,7 @@ default_imp_for_new_connector_integration_payouts_sync!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1077,6 +1091,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1136,6 +1151,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1197,6 +1213,7 @@ default_imp_for_new_connector_integration_frm_sale!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1258,6 +1275,7 @@ default_imp_for_new_connector_integration_frm_checkout!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1319,6 +1337,7 @@ default_imp_for_new_connector_integration_frm_transaction!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1380,6 +1399,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1441,6 +1461,7 @@ default_imp_for_new_connector_integration_frm_record_return!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, @@ -1499,6 +1520,7 @@ default_imp_for_new_connector_integration_revoking_mandates!( connectors::Nexinets, connectors::Nexixpay, connectors::Payeezy, + connectors::Paymentwall, connectors::Payu, connectors::Powertranz, connectors::Mollie, diff --git a/crates/hyperswitch_interfaces/src/configs.rs b/crates/hyperswitch_interfaces/src/configs.rs index 58810a0cb34..18144394aab 100644 --- a/crates/hyperswitch_interfaces/src/configs.rs +++ b/crates/hyperswitch_interfaces/src/configs.rs @@ -66,6 +66,7 @@ pub struct Connectors { pub paybox: ConnectorParamsWithSecondaryBaseUrl, pub payeezy: ConnectorParams, pub payme: ConnectorParams, + pub paymentwall: ConnectorParams, pub payone: ConnectorParams, pub paypal: ConnectorParams, pub payu: ConnectorParams, diff --git a/crates/router/src/connector.rs b/crates/router/src/connector.rs index 7913d6543c8..0bcd67bf018 100644 --- a/crates/router/src/connector.rs +++ b/crates/router/src/connector.rs @@ -53,7 +53,7 @@ pub use hyperswitch_connectors::connectors::{ fiuu::Fiuu, forte, forte::Forte, globepay, globepay::Globepay, helcim, helcim::Helcim, jpmorgan, jpmorgan::Jpmorgan, mollie, mollie::Mollie, multisafepay, multisafepay::Multisafepay, nexinets, nexinets::Nexinets, nexixpay, nexixpay::Nexixpay, nomupay, nomupay::Nomupay, - novalnet, novalnet::Novalnet, payeezy, payeezy::Payeezy, payu, payu::Payu, powertranz, + novalnet, novalnet::Novalnet, payeezy, payeezy::Payeezy, paymentwall, paymentwall::Paymentwall, payu, payu::Payu, powertranz, powertranz::Powertranz, razorpay, razorpay::Razorpay, shift4, shift4::Shift4, square, square::Square, stax, stax::Stax, taxjar, taxjar::Taxjar, thunes, thunes::Thunes, tsys, tsys::Tsys, volt, volt::Volt, worldline, worldline::Worldline, worldpay, worldpay::Worldpay, diff --git a/crates/router/src/core/payments/connector_integration_v2_impls.rs b/crates/router/src/core/payments/connector_integration_v2_impls.rs index 94c531a0963..1fe789bcd72 100644 --- a/crates/router/src/core/payments/connector_integration_v2_impls.rs +++ b/crates/router/src/core/payments/connector_integration_v2_impls.rs @@ -1161,6 +1161,7 @@ default_imp_for_new_connector_integration_payouts!( connector::Paybox, connector::Payeezy, connector::Payme, + connector::Paymentwall, connector::Payone, connector::Paypal, connector::Payu, @@ -1808,6 +1809,7 @@ default_imp_for_new_connector_integration_frm!( connector::Paybox, connector::Payeezy, connector::Payme, + connector::Paymentwall, connector::Payone, connector::Paypal, connector::Payu, @@ -2303,6 +2305,7 @@ default_imp_for_new_connector_integration_connector_authentication!( connector::Paybox, connector::Payeezy, connector::Payme, + connector::Paymentwall, connector::Payone, connector::Paypal, connector::Payu, diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs index 1358bcedba1..0416202b140 100644 --- a/crates/router/src/core/payments/flows.rs +++ b/crates/router/src/core/payments/flows.rs @@ -500,6 +500,7 @@ default_imp_for_connector_request_id!( connector::Opennode, connector::Paybox, connector::Payeezy, + connector::Paymentwall, connector::Payme, connector::Payone, connector::Paypal, @@ -1788,6 +1789,7 @@ default_imp_for_fraud_check!( connector::Paybox, connector::Payeezy, connector::Payme, + connector::Paymentwall, connector::Payone, connector::Paypal, connector::Payu, @@ -2450,6 +2452,7 @@ default_imp_for_connector_authentication!( connector::Paybox, connector::Payeezy, connector::Payme, + connector::Paymentwall, connector::Payone, connector::Paypal, connector::Payu, diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs index b432c57c5d1..eeda947f143 100644 --- a/crates/router/src/types/api.rs +++ b/crates/router/src/types/api.rs @@ -460,6 +460,7 @@ impl ConnectorData { } // "payeezy" => Ok(ConnectorIntegrationEnum::Old(Box::new(&connector::Payeezy)), As psync and rsync are not supported by this connector, it is added as template code for future usage enums::Connector::Payme => { + // enums::Connector::Paymentwall => Ok(ConnectorEnum::Old(Box::new(connector::Paymentwall))), Ok(ConnectorEnum::Old(Box::new(connector::Payme::new()))) } enums::Connector::Payone => { diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index 36865f5ce09..d527f344c74 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -270,6 +270,7 @@ impl ForeignTryFrom for common_enums::RoutableConnectors { api_enums::Connector::Opennode => Self::Opennode, api_enums::Connector::Paybox => Self::Paybox, api_enums::Connector::Payme => Self::Payme, + // api_enums::Connector::Paymentwall => Self::Paymentwall, api_enums::Connector::Payone => Self::Payone, api_enums::Connector::Paypal => Self::Paypal, api_enums::Connector::Payu => Self::Payu, diff --git a/crates/router/tests/connectors/main.rs b/crates/router/tests/connectors/main.rs index 9bb079b7a16..6dd92880ea6 100644 --- a/crates/router/tests/connectors/main.rs +++ b/crates/router/tests/connectors/main.rs @@ -63,6 +63,7 @@ mod paybox; #[cfg(feature = "dummy_connector")] mod payeezy; mod payme; +mod paymentwall; mod payone; mod paypal; mod payu; diff --git a/crates/router/tests/connectors/paymentwall.rs b/crates/router/tests/connectors/paymentwall.rs new file mode 100644 index 00000000000..57eebbbc53f --- /dev/null +++ b/crates/router/tests/connectors/paymentwall.rs @@ -0,0 +1,401 @@ +use masking::Secret; +use router::types::{self, api, storage::enums}; +use hyperswitch_domain_models::payment_method_data::{Card, PaymentMethodData}; + +use crate::utils::{self, ConnectorActions}; +use test_utils::connector_auth; + +#[derive(Clone, Copy)] +struct PaymentwallTest; +impl ConnectorActions for PaymentwallTest {} +impl utils::Connector for PaymentwallTest { + fn get_data(&self) -> api::ConnectorData { + use router::connector::Paymentwall; + utils::construct_connector_data_old( + Box::new(Paymentwall::new()), + types::Connector::Plaid, + api::GetToken::Connector, + None, + ) + } + + fn get_auth_token(&self) -> types::ConnectorAuthType { + utils::to_connector_auth_type( + connector_auth::ConnectorAuthentication::new() + .paymentwall + .expect("Missing connector authentication configuration").into(), + ) + } + + fn get_name(&self) -> String { + "paymentwall".to_string() + } +} + +static CONNECTOR: PaymentwallTest = PaymentwallTest {}; + +fn get_default_payment_info() -> Option { + None +} + +fn payment_method_details() -> Option { + None +} + +// Cards Positive Tests +// Creates a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_only_authorize_payment() { + let response = CONNECTOR + .authorize_payment(payment_method_details(), get_default_payment_info()) + .await + .expect("Authorize payment response"); + assert_eq!(response.status, enums::AttemptStatus::Authorized); +} + +// Captures a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_capture_authorized_payment() { + let response = CONNECTOR + .authorize_and_capture_payment(payment_method_details(), None, get_default_payment_info()) + .await + .expect("Capture payment response"); + assert_eq!(response.status, enums::AttemptStatus::Charged); +} + +// Partially captures a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_partially_capture_authorized_payment() { + let response = CONNECTOR + .authorize_and_capture_payment( + payment_method_details(), + Some(types::PaymentsCaptureData { + amount_to_capture: 50, + ..utils::PaymentCaptureType::default().0 + }), + get_default_payment_info(), + ) + .await + .expect("Capture payment response"); + assert_eq!(response.status, enums::AttemptStatus::Charged); +} + +// Synchronizes a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_sync_authorized_payment() { + let authorize_response = CONNECTOR + .authorize_payment(payment_method_details(), get_default_payment_info()) + .await + .expect("Authorize payment response"); + let txn_id = utils::get_connector_transaction_id(authorize_response.response); + let response = CONNECTOR + .psync_retry_till_status_matches( + enums::AttemptStatus::Authorized, + Some(types::PaymentsSyncData { + connector_transaction_id: types::ResponseId::ConnectorTransactionId( + txn_id.unwrap(), + ), + ..Default::default() + }), + get_default_payment_info(), + ) + .await + .expect("PSync response"); + assert_eq!(response.status, enums::AttemptStatus::Authorized,); +} + +// Voids a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_void_authorized_payment() { + let response = CONNECTOR + .authorize_and_void_payment( + payment_method_details(), + Some(types::PaymentsCancelData { + connector_transaction_id: String::from(""), + cancellation_reason: Some("requested_by_customer".to_string()), + ..Default::default() + }), + get_default_payment_info(), + ) + .await + .expect("Void payment response"); + assert_eq!(response.status, enums::AttemptStatus::Voided); +} + +// Refunds a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_refund_manually_captured_payment() { + let response = CONNECTOR + .capture_payment_and_refund(payment_method_details(), None, None, get_default_payment_info()) + .await + .unwrap(); + assert_eq!( + response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Partially refunds a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_partially_refund_manually_captured_payment() { + let response = CONNECTOR + .capture_payment_and_refund( + payment_method_details(), + None, + Some(types::RefundsData { + refund_amount: 50, + ..utils::PaymentRefundType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Synchronizes a refund using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_sync_manually_captured_refund() { + let refund_response = CONNECTOR + .capture_payment_and_refund(payment_method_details(), None, None, get_default_payment_info()) + .await + .unwrap(); + let response = CONNECTOR + .rsync_retry_till_status_matches( + enums::RefundStatus::Success, + refund_response.response.unwrap().connector_refund_id, + None, + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Creates a payment using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_make_payment() { + let authorize_response = CONNECTOR.make_payment(payment_method_details(), get_default_payment_info()).await.unwrap(); + assert_eq!(authorize_response.status, enums::AttemptStatus::Charged); +} + +// Synchronizes a payment using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_sync_auto_captured_payment() { + let authorize_response = CONNECTOR.make_payment(payment_method_details(), get_default_payment_info()).await.unwrap(); + assert_eq!(authorize_response.status, enums::AttemptStatus::Charged); + let txn_id = utils::get_connector_transaction_id(authorize_response.response); + assert_ne!(txn_id, None, "Empty connector transaction id"); + let response = CONNECTOR + .psync_retry_till_status_matches( + enums::AttemptStatus::Charged, + Some(types::PaymentsSyncData { + connector_transaction_id: types::ResponseId::ConnectorTransactionId( + txn_id.unwrap(), + ), + capture_method: Some(enums::CaptureMethod::Automatic), + ..Default::default() + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!(response.status, enums::AttemptStatus::Charged,); +} + +// Refunds a payment using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_refund_auto_captured_payment() { + let response = CONNECTOR + .make_payment_and_refund(payment_method_details(), None, get_default_payment_info()) + .await + .unwrap(); + assert_eq!( + response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Partially refunds a payment using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_partially_refund_succeeded_payment() { + let refund_response = CONNECTOR + .make_payment_and_refund( + payment_method_details(), + Some(types::RefundsData { + refund_amount: 50, + ..utils::PaymentRefundType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + refund_response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Creates multiple refunds against a payment using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_refund_succeeded_payment_multiple_times() { + CONNECTOR + .make_payment_and_multiple_refund( + payment_method_details(), + Some(types::RefundsData { + refund_amount: 50, + ..utils::PaymentRefundType::default().0 + }), + get_default_payment_info(), + ) + .await; +} + +// Synchronizes a refund using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_sync_refund() { + let refund_response = CONNECTOR + .make_payment_and_refund(payment_method_details(), None, get_default_payment_info()) + .await + .unwrap(); + let response = CONNECTOR + .rsync_retry_till_status_matches( + enums::RefundStatus::Success, + refund_response.response.unwrap().connector_refund_id, + None, + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Cards Negative scenarios +// Creates a payment with incorrect CVC. +#[actix_web::test] +async fn should_fail_payment_for_incorrect_cvc() { + let response = CONNECTOR + .make_payment( + Some(types::PaymentsAuthorizeData { + payment_method_data: PaymentMethodData::Card(Card { + card_cvc: Secret::new("12345".to_string()), + ..utils::CCardType::default().0 + }), + ..utils::PaymentAuthorizeType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap_err().message, + "Your card's security code is invalid.".to_string(), + ); +} + +// Creates a payment with incorrect expiry month. +#[actix_web::test] +async fn should_fail_payment_for_invalid_exp_month() { + let response = CONNECTOR + .make_payment( + Some(types::PaymentsAuthorizeData { + payment_method_data: PaymentMethodData::Card(Card { + card_exp_month: Secret::new("20".to_string()), + ..utils::CCardType::default().0 + }), + ..utils::PaymentAuthorizeType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap_err().message, + "Your card's expiration month is invalid.".to_string(), + ); +} + +// Creates a payment with incorrect expiry year. +#[actix_web::test] +async fn should_fail_payment_for_incorrect_expiry_year() { + let response = CONNECTOR + .make_payment( + Some(types::PaymentsAuthorizeData { + payment_method_data: PaymentMethodData::Card(Card { + card_exp_year: Secret::new("2000".to_string()), + ..utils::CCardType::default().0 + }), + ..utils::PaymentAuthorizeType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap_err().message, + "Your card's expiration year is invalid.".to_string(), + ); +} + +// Voids a payment using automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_fail_void_payment_for_auto_capture() { + let authorize_response = CONNECTOR.make_payment(payment_method_details(), get_default_payment_info()).await.unwrap(); + assert_eq!(authorize_response.status, enums::AttemptStatus::Charged); + let txn_id = utils::get_connector_transaction_id(authorize_response.response); + assert_ne!(txn_id, None, "Empty connector transaction id"); + let void_response = CONNECTOR + .void_payment(txn_id.unwrap(), None, get_default_payment_info()) + .await + .unwrap(); + assert_eq!( + void_response.response.unwrap_err().message, + "You cannot cancel this PaymentIntent because it has a status of succeeded." + ); +} + +// Captures a payment using invalid connector payment id. +#[actix_web::test] +async fn should_fail_capture_for_invalid_payment() { + let capture_response = CONNECTOR + .capture_payment("123456789".to_string(), None, get_default_payment_info()) + .await + .unwrap(); + assert_eq!( + capture_response.response.unwrap_err().message, + String::from("No such payment_intent: '123456789'") + ); +} + +// Refunds a payment with refund amount higher than payment amount. +#[actix_web::test] +async fn should_fail_for_refund_amount_higher_than_payment_amount() { + let response = CONNECTOR + .make_payment_and_refund( + payment_method_details(), + Some(types::RefundsData { + refund_amount: 150, + ..utils::PaymentRefundType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap_err().message, + "Refund amount (₹1.50) is greater than charge amount (₹1.00)", + ); +} + +// Connector dependent test cases goes here + +// [#478]: add unit tests for non 3DS, wallets & webhooks in connector tests diff --git a/crates/router/tests/connectors/sample_auth.toml b/crates/router/tests/connectors/sample_auth.toml index d2eec724597..11a81f4d9ef 100644 --- a/crates/router/tests/connectors/sample_auth.toml +++ b/crates/router/tests/connectors/sample_auth.toml @@ -294,4 +294,7 @@ api_key="API Key" api_key="API Key" [nomupay] +api_key="API Key" + +[paymentwall] api_key="API Key" \ No newline at end of file diff --git a/crates/test_utils/src/connector_auth.rs b/crates/test_utils/src/connector_auth.rs index be02e5720fb..4bf60c20573 100644 --- a/crates/test_utils/src/connector_auth.rs +++ b/crates/test_utils/src/connector_auth.rs @@ -67,6 +67,7 @@ pub struct ConnectorAuthentication { pub paybox: Option, pub payeezy: Option, pub payme: Option, + pub paymentwall: Option, pub payone: Option, pub paypal: Option, pub payu: Option, diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml index 934b072f14a..2570be413ab 100644 --- a/loadtest/config/development.toml +++ b/loadtest/config/development.toml @@ -138,6 +138,7 @@ paybox.base_url = "https://preprod-ppps.paybox.com/PPPS.php" paybox.secondary_base_url="https://preprod-tpeweb.paybox.com/" payeezy.base_url = "https://api-cert.payeezy.com/" payme.base_url = "https://sandbox.payme.io/" +paymentwall.base_url = "https://api.paymentwall.com/" payone.base_url = "https://payment.preprod.payone.com/" paypal.base_url = "https://api-m.sandbox.paypal.com/" payu.base_url = "https://secure.snd.payu.com/" @@ -231,6 +232,7 @@ cards = [ "paybox", "payeezy", "payme", + "paymentwall", "payone", "paypal", "payu", diff --git a/scripts/add_connector.sh b/scripts/add_connector.sh index 0ed38e8ef5d..3f6369c64d9 100755 --- a/scripts/add_connector.sh +++ b/scripts/add_connector.sh @@ -6,7 +6,7 @@ function find_prev_connector() { git checkout $self cp $self $self.tmp # Add new connector to existing list and sort it - connectors=(aci adyen adyenplatform airwallex amazonpay applepay authorizedotnet bambora bamboraapac bankofamerica billwerk bitpay bluesnap boku braintree cashtocode checkout coinbase cryptopay cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector ebanx elavon fiserv fiservemea fiuu forte globalpay globepay gocardless gpayments helcim iatapay itaubank jpmorgan klarna mifinity mollie multisafepay netcetera nexinets nexixpay nomupay noon novalnet nuvei opayo opennode paybox payeezy payme payone paypal payu placetopay plaid powertranz prophetpay rapyd razorpay shift4 square stax stripe taxjar threedsecureio thunes trustpay tsys volt wellsfargo wellsfargopayout wise worldline worldpay zsl "$1") + connectors=(aci adyen adyenplatform airwallex amazonpay applepay authorizedotnet bambora bamboraapac bankofamerica billwerk bitpay bluesnap boku braintree cashtocode checkout coinbase cryptopay cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector ebanx elavon fiserv fiservemea fiuu forte globalpay globepay gocardless gpayments helcim iatapay itaubank jpmorgan klarna mifinity mollie multisafepay netcetera nexinets nexixpay nomupay noon novalnet nuvei opayo opennode paybox payeezy payme paymentwall payone paypal payu placetopay plaid powertranz prophetpay rapyd razorpay shift4 square stax stripe taxjar threedsecureio thunes trustpay tsys volt wellsfargo wellsfargopayout wise worldline worldpay zsl "$1") IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFS res="$(echo ${sorted[@]})" sed -i'' -e "s/^ connectors=.*/ connectors=($res \"\$1\")/" $self.tmp