diff --git a/config/config.example.toml b/config/config.example.toml index 4ce52dfac4..29649b13c0 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -280,6 +280,7 @@ paysafe.base_url = "https://api.test.paysafe.com/paymenthub/" paystack.base_url = "https://api.paystack.co" paytm.base_url = "https://securegw-stage.paytm.in/" payu.base_url = "https://secure.snd.payu.com/" +peachpayments.base_url = "https://apitest.bankint.ppay.io/v/1" phonepe.base_url = "https://api.phonepe.com/apis/hermes/" placetopay.base_url = "https://test.placetopay.com/rest/gateway" plaid.base_url = "https://sandbox.plaid.com" diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml index 808405fa51..903b040e5f 100644 --- a/config/deployments/integration_test.toml +++ b/config/deployments/integration_test.toml @@ -117,6 +117,7 @@ paysafe.base_url = "https://api.test.paysafe.com/paymenthub/" paystack.base_url = "https://api.paystack.co" paytm.base_url = "https://securegw-stage.paytm.in/" payu.base_url = "https://secure.snd.payu.com/" +peachpayments.base_url = "https://apitest.bankint.ppay.io/v/1" phonepe.base_url = "https://api.phonepe.com/apis/hermes/" placetopay.base_url = "https://test.placetopay.com/rest/gateway" plaid.base_url = "https://sandbox.plaid.com" diff --git a/config/deployments/production.toml b/config/deployments/production.toml index 0c7a10f1c2..27034e858f 100644 --- a/config/deployments/production.toml +++ b/config/deployments/production.toml @@ -121,6 +121,7 @@ paysafe.base_url = "https://api.paysafe.com/paymenthub/" paystack.base_url = "https://api.paystack.co" paytm.base_url = "https://securegw-stage.paytm.in/" payu.base_url = "https://secure.payu.com/api/" +peachpayments.base_url = "https://api.bankint.peachpayments.com" phonepe.base_url = "https://api.phonepe.com/apis/hermes/" placetopay.base_url = "https://checkout.placetopay.com/rest/gateway" plaid.base_url = "https://production.plaid.com" diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml index 617d0c0443..c23bbac335 100644 --- a/config/deployments/sandbox.toml +++ b/config/deployments/sandbox.toml @@ -121,6 +121,7 @@ paysafe.base_url = "https://api.test.paysafe.com/paymenthub/" paystack.base_url = "https://api.paystack.co" paytm.base_url = "https://securegw-stage.paytm.in/" payu.base_url = "https://secure.snd.payu.com/" +peachpayments.base_url = "https://apitest.bankint.ppay.io/v/1" phonepe.base_url = "https://api.phonepe.com/apis/hermes/" placetopay.base_url = "https://test.placetopay.com/rest/gateway" plaid.base_url = "https://sandbox.plaid.com" diff --git a/config/development.toml b/config/development.toml index 4ea78e8149..f0cfbf4490 100644 --- a/config/development.toml +++ b/config/development.toml @@ -318,6 +318,7 @@ paysafe.base_url = "https://api.test.paysafe.com/paymenthub/" paystack.base_url = "https://api.paystack.co" paytm.base_url = "https://securegw-stage.paytm.in/" payu.base_url = "https://secure.snd.payu.com/" +peachpayments.base_url = "https://apitest.bankint.ppay.io/v/1" phonepe.base_url = "https://api.phonepe.com/apis/hermes/" placetopay.base_url = "https://test.placetopay.com/rest/gateway" plaid.base_url = "https://sandbox.plaid.com" diff --git a/config/docker_compose.toml b/config/docker_compose.toml index d299323f2c..025fd916c9 100644 --- a/config/docker_compose.toml +++ b/config/docker_compose.toml @@ -206,6 +206,7 @@ paysafe.base_url = "https://api.test.paysafe.com/paymenthub/" paystack.base_url = "https://api.paystack.co" paytm.base_url = "https://securegw-stage.paytm.in/" payu.base_url = "https://secure.snd.payu.com/" +peachpayments.base_url = "https://apitest.bankint.ppay.io/v/1" phonepe.base_url = "https://api.phonepe.com/apis/hermes/" placetopay.base_url = "https://test.placetopay.com/rest/gateway" plaid.base_url = "https://sandbox.plaid.com" diff --git a/crates/common_enums/src/connector_enums.rs b/crates/common_enums/src/connector_enums.rs index 5004ef0624..5051b03567 100644 --- a/crates/common_enums/src/connector_enums.rs +++ b/crates/common_enums/src/connector_enums.rs @@ -136,6 +136,7 @@ pub enum RoutableConnectors { Paystack, Paytm, Payu, + // Peachpayments, Phonepe, Placetopay, Powertranz, @@ -313,6 +314,7 @@ pub enum Connector { Paystack, Paytm, Payu, + // Peachpayments, Phonepe, Placetopay, Powertranz, @@ -501,6 +503,7 @@ impl Connector { | Self::Paysafe | Self::Paystack | Self::Payu + // | Self::Peachpayments | Self::Placetopay | Self::Powertranz | Self::Prophetpay @@ -680,6 +683,7 @@ impl From for Connector { RoutableConnectors::Paysafe => Self::Paysafe, RoutableConnectors::Paystack => Self::Paystack, RoutableConnectors::Payu => Self::Payu, + // RoutableConnectors::Peachpayments => Self::Peachpayments, RoutableConnectors::Placetopay => Self::Placetopay, RoutableConnectors::Powertranz => Self::Powertranz, RoutableConnectors::Prophetpay => Self::Prophetpay, @@ -814,6 +818,7 @@ impl TryFrom for RoutableConnectors { Connector::Paysafe => Ok(Self::Paysafe), Connector::Paystack => Ok(Self::Paystack), Connector::Payu => Ok(Self::Payu), + // Connector::Peachpayments => Ok(Self::Peachpayments), Connector::Placetopay => Ok(Self::Placetopay), Connector::Powertranz => Ok(Self::Powertranz), Connector::Prophetpay => Ok(Self::Prophetpay), diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs index cd4bdfcc23..060240873f 100644 --- a/crates/connector_configs/src/connector.rs +++ b/crates/connector_configs/src/connector.rs @@ -281,6 +281,7 @@ pub struct ConnectorConfig { pub paystack: Option, pub paytm: Option, pub payu: Option, + pub peachpayments: Option, pub phonepe: Option, pub placetopay: Option, pub plaid: Option, @@ -485,6 +486,7 @@ impl ConnectorConfig { Connector::Paysafe => Ok(connector_data.paysafe), Connector::Paystack => Ok(connector_data.paystack), Connector::Payu => Ok(connector_data.payu), + // Connector::Peachpayments => Ok(connector_data.peachpayments), Connector::Placetopay => Ok(connector_data.placetopay), Connector::Plaid => Ok(connector_data.plaid), Connector::Powertranz => Ok(connector_data.powertranz), diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.toml index 248a133605..8b6b0e875f 100644 --- a/crates/connector_configs/toml/development.toml +++ b/crates/connector_configs/toml/development.toml @@ -6839,3 +6839,7 @@ label="Payment Method Account ID" placeholder="Enter Account ID" required=true type="Text" + +[peachpayments] +[peachpayments.connector_auth.HeaderKey] +api_key = "API Key" diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.toml index 0bcd12a113..7501bb4c33 100644 --- a/crates/connector_configs/toml/production.toml +++ b/crates/connector_configs/toml/production.toml @@ -5508,3 +5508,7 @@ label="Payment Method Account ID" placeholder="Enter Account ID" required=true type="Text" + +[peachpayments] +[peachpayments.connector_auth.HeaderKey] +api_key = "API Key" diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.toml index a50f4b638e..8220f4f2ea 100644 --- a/crates/connector_configs/toml/sandbox.toml +++ b/crates/connector_configs/toml/sandbox.toml @@ -6822,3 +6822,7 @@ label="Payment Method Account ID" placeholder="Enter Account ID" required=true type="Text" + +[peachpayments] +[peachpayments.connector_auth.HeaderKey] +api_key = "API Key" diff --git a/crates/hyperswitch_connectors/src/connectors.rs b/crates/hyperswitch_connectors/src/connectors.rs index 60d6866bee..bf3fab9335 100644 --- a/crates/hyperswitch_connectors/src/connectors.rs +++ b/crates/hyperswitch_connectors/src/connectors.rs @@ -87,6 +87,7 @@ pub mod paysafe; pub mod paystack; pub mod paytm; pub mod payu; +pub mod peachpayments; pub mod phonepe; pub mod placetopay; pub mod plaid; @@ -150,12 +151,12 @@ pub use self::{ noon::Noon, nordea::Nordea, novalnet::Novalnet, nuvei::Nuvei, opayo::Opayo, opennode::Opennode, paybox::Paybox, payeezy::Payeezy, payload::Payload, payme::Payme, payone::Payone, paypal::Paypal, paysafe::Paysafe, paystack::Paystack, paytm::Paytm, payu::Payu, - phonepe::Phonepe, placetopay::Placetopay, plaid::Plaid, powertranz::Powertranz, - prophetpay::Prophetpay, rapyd::Rapyd, razorpay::Razorpay, recurly::Recurly, redsys::Redsys, - riskified::Riskified, santander::Santander, shift4::Shift4, sift::Sift, signifyd::Signifyd, - silverflow::Silverflow, square::Square, stax::Stax, stripe::Stripe, - stripebilling::Stripebilling, taxjar::Taxjar, threedsecureio::Threedsecureio, thunes::Thunes, - tokenio::Tokenio, trustpay::Trustpay, trustpayments::Trustpayments, tsys::Tsys, + peachpayments::Peachpayments, phonepe::Phonepe, placetopay::Placetopay, plaid::Plaid, + powertranz::Powertranz, prophetpay::Prophetpay, rapyd::Rapyd, razorpay::Razorpay, + recurly::Recurly, redsys::Redsys, riskified::Riskified, santander::Santander, shift4::Shift4, + sift::Sift, signifyd::Signifyd, silverflow::Silverflow, square::Square, stax::Stax, + stripe::Stripe, stripebilling::Stripebilling, taxjar::Taxjar, threedsecureio::Threedsecureio, + thunes::Thunes, tokenio::Tokenio, trustpay::Trustpay, trustpayments::Trustpayments, tsys::Tsys, unified_authentication_service::UnifiedAuthenticationService, vgs::Vgs, volt::Volt, wellsfargo::Wellsfargo, wellsfargopayout::Wellsfargopayout, wise::Wise, worldline::Worldline, worldpay::Worldpay, worldpayvantiv::Worldpayvantiv, worldpayxml::Worldpayxml, xendit::Xendit, diff --git a/crates/hyperswitch_connectors/src/connectors/peachpayments.rs b/crates/hyperswitch_connectors/src/connectors/peachpayments.rs new file mode 100644 index 0000000000..3c25889332 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/peachpayments.rs @@ -0,0 +1,630 @@ +pub mod transformers; + +use std::sync::LazyLock; + +use common_enums::enums; +use common_utils::{ + errors::CustomResult, + ext_traits::BytesExt, + request::{Method, Request, RequestBuilder, RequestContent}, + types::{AmountConvertor, MinorUnit, MinorUnitForConnector}, +}; +use error_stack::{report, ResultExt}; +use hyperswitch_domain_models::{ + payment_method_data::PaymentMethodData, + 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::{ + ConnectorInfo, PaymentsResponseData, RefundsResponseData, SupportedPaymentMethods, + }, + types::{ + PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData, + RefundSyncRouterData, RefundsRouterData, + }, +}; +use hyperswitch_interfaces::{ + api::{ + self, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, ConnectorSpecifications, + ConnectorValidation, + }, + configs::Connectors, + errors, + events::connector_api_logs::ConnectorEvent, + types::{self, Response}, + webhooks, +}; +use masking::{ExposeInterface, Mask}; +use transformers as peachpayments; + +use crate::{constants::headers, types::ResponseRouterData, utils}; + +#[derive(Clone)] +pub struct Peachpayments { + amount_converter: &'static (dyn AmountConvertor + Sync), +} + +impl Peachpayments { + pub fn new() -> &'static Self { + &Self { + amount_converter: &MinorUnitForConnector, + } + } +} + +impl api::Payment for Peachpayments {} +impl api::PaymentSession for Peachpayments {} +impl api::ConnectorAccessToken for Peachpayments {} +impl api::MandateSetup for Peachpayments {} +impl api::PaymentAuthorize for Peachpayments {} +impl api::PaymentSync for Peachpayments {} +impl api::PaymentCapture for Peachpayments {} +impl api::PaymentVoid for Peachpayments {} +impl api::Refund for Peachpayments {} +impl api::RefundExecute for Peachpayments {} +impl api::RefundSync for Peachpayments {} +impl api::PaymentToken for Peachpayments {} + +impl ConnectorIntegration + for Peachpayments +{ + // Not Implemented (R) +} + +impl ConnectorCommonExt for Peachpayments +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 Peachpayments { + fn id(&self) -> &'static str { + "peachpayments" + } + + fn get_currency_unit(&self) -> api::CurrencyUnit { + // PeachPayments Card Gateway accepts amounts in cents (minor unit) + api::CurrencyUnit::Minor + } + + fn common_get_content_type(&self) -> &'static str { + "application/json" + } + + fn base_url<'a>(&self, connectors: &'a Connectors) -> &'a str { + connectors.peachpayments.base_url.as_ref() + } + + fn get_auth_header( + &self, + auth_type: &ConnectorAuthType, + ) -> CustomResult)>, errors::ConnectorError> { + let auth = peachpayments::PeachpaymentsAuthType::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: peachpayments::PeachpaymentsErrorResponse = res + .response + .parse_struct("PeachpaymentsErrorResponse") + .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, + network_advice_code: None, + network_decline_code: None, + network_error_message: None, + connector_metadata: None, + }) + } +} + +impl ConnectorValidation for Peachpayments { + fn validate_mandate_payment( + &self, + _pm_type: Option, + pm_data: PaymentMethodData, + ) -> CustomResult<(), errors::ConnectorError> { + match pm_data { + PaymentMethodData::Card(_) => Err(errors::ConnectorError::NotImplemented( + "validate_mandate_payment does not support cards".to_string(), + ) + .into()), + _ => Ok(()), + } + } + + fn validate_psync_reference_id( + &self, + _data: &PaymentsSyncData, + _is_three_ds: bool, + _status: enums::AttemptStatus, + _connector_meta_data: Option, + ) -> CustomResult<(), errors::ConnectorError> { + Ok(()) + } +} + +impl ConnectorIntegration for Peachpayments { + //TODO: implement sessions flow +} + +impl ConnectorIntegration for Peachpayments {} + +impl ConnectorIntegration + for Peachpayments +{ +} + +impl ConnectorIntegration + for Peachpayments +{ + 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 = peachpayments::PeachpaymentsRouterData::from((amount, req)); + let connector_req = + peachpayments::PeachpaymentsPaymentsRequest::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: peachpayments::PeachpaymentsPaymentsResponse = res + .response + .parse_struct("Peachpayments 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 Peachpayments { + 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: peachpayments::PeachpaymentsPaymentsResponse = res + .response + .parse_struct("peachpayments 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 for Peachpayments { + 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: peachpayments::PeachpaymentsPaymentsResponse = res + .response + .parse_struct("Peachpayments 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 for Peachpayments {} + +impl ConnectorIntegration for Peachpayments { + 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 = + peachpayments::PeachpaymentsRouterData::from((refund_amount, req)); + let connector_req = + peachpayments::PeachpaymentsRefundRequest::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: peachpayments::RefundResponse = res + .response + .parse_struct("peachpayments 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 Peachpayments { + 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: peachpayments::RefundResponse = res + .response + .parse_struct("peachpayments 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 Peachpayments { + 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)) + } +} + +static PEACHPAYMENTS_SUPPORTED_PAYMENT_METHODS: LazyLock = + LazyLock::new(SupportedPaymentMethods::new); + +static PEACHPAYMENTS_CONNECTOR_INFO: ConnectorInfo = ConnectorInfo { + display_name: "Peachpayments", + description: "Peachpayments connector", + connector_type: enums::HyperswitchConnectorCategory::PaymentGateway, + integration_status: enums::ConnectorIntegrationStatus::Beta, +}; + +static PEACHPAYMENTS_SUPPORTED_WEBHOOK_FLOWS: [enums::EventClass; 0] = []; + +impl ConnectorSpecifications for Peachpayments { + fn get_connector_about(&self) -> Option<&'static ConnectorInfo> { + Some(&PEACHPAYMENTS_CONNECTOR_INFO) + } + + fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> { + Some(&*PEACHPAYMENTS_SUPPORTED_PAYMENT_METHODS) + } + + fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> { + Some(&PEACHPAYMENTS_SUPPORTED_WEBHOOK_FLOWS) + } +} diff --git a/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs b/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs new file mode 100644 index 0000000000..1d403f2632 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs @@ -0,0 +1,223 @@ +use common_enums::enums; +use common_utils::types::MinorUnit; +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 masking::Secret; +use serde::{Deserialize, Serialize}; + +use crate::types::{RefundsResponseRouterData, ResponseRouterData}; + +//TODO: Fill the struct with respective fields +pub struct PeachpaymentsRouterData { + pub amount: MinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc. + pub router_data: T, +} + +impl From<(MinorUnit, T)> for PeachpaymentsRouterData { + fn from((amount, item): (MinorUnit, 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 PeachpaymentsPaymentsRequest { + amount: MinorUnit, + card: PeachpaymentsCard, +} + +#[derive(Default, Debug, Serialize, Eq, PartialEq)] +pub struct PeachpaymentsCard { + number: cards::CardNumber, + expiry_month: Secret, + expiry_year: Secret, + cvc: Secret, + complete: bool, +} + +impl TryFrom<&PeachpaymentsRouterData<&PaymentsAuthorizeRouterData>> + for PeachpaymentsPaymentsRequest +{ + type Error = error_stack::Report; + fn try_from( + item: &PeachpaymentsRouterData<&PaymentsAuthorizeRouterData>, + ) -> Result { + match item.router_data.request.payment_method_data.clone() { + PaymentMethodData::Card(_) => Err(errors::ConnectorError::NotImplemented( + "Card payment method not implemented".to_string(), + ) + .into()), + _ => Err(errors::ConnectorError::NotImplemented("Payment method".to_string()).into()), + } + } +} + +//TODO: Fill the struct with respective fields +// Auth Struct +pub struct PeachpaymentsAuthType { + pub(super) api_key: Secret, +} + +impl TryFrom<&ConnectorAuthType> for PeachpaymentsAuthType { + 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, Copy, Default, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum PeachpaymentsPaymentStatus { + Succeeded, + Failed, + #[default] + Processing, +} + +impl From for common_enums::AttemptStatus { + fn from(item: PeachpaymentsPaymentStatus) -> Self { + match item { + PeachpaymentsPaymentStatus::Succeeded => Self::Charged, + PeachpaymentsPaymentStatus::Failed => Self::Failure, + PeachpaymentsPaymentStatus::Processing => Self::Authorizing, + } + } +} + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct PeachpaymentsPaymentsResponse { + status: PeachpaymentsPaymentStatus, + 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, + charges: None, + }), + ..item.data + }) + } +} + +//TODO: Fill the struct with respective fields +// REFUND : +// Type definition for RefundRequest +#[derive(Default, Debug, Serialize)] +pub struct PeachpaymentsRefundRequest { + pub amount: MinorUnit, +} + +impl TryFrom<&PeachpaymentsRouterData<&RefundsRouterData>> for PeachpaymentsRefundRequest { + type Error = error_stack::Report; + fn try_from( + item: &PeachpaymentsRouterData<&RefundsRouterData>, + ) -> Result { + Ok(Self { + amount: item.amount.to_owned(), + }) + } +} + +// Type definition for Refund Response + +#[allow(dead_code)] +#[derive(Debug, Copy, 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 PeachpaymentsErrorResponse { + pub status_code: u16, + pub code: String, + pub message: String, + pub reason: Option, + pub network_advice_code: Option, + pub network_decline_code: Option, + pub network_error_message: Option, +} diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs index 1a2c5c5150..1a4424ac5b 100644 --- a/crates/hyperswitch_connectors/src/default_implementations.rs +++ b/crates/hyperswitch_connectors/src/default_implementations.rs @@ -235,6 +235,7 @@ default_imp_for_authorize_session_token!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -382,6 +383,7 @@ default_imp_for_calculate_tax!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -530,6 +532,7 @@ default_imp_for_session_update!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -672,6 +675,7 @@ default_imp_for_post_session_tokens!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -813,6 +817,7 @@ default_imp_for_create_order!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -953,6 +958,7 @@ default_imp_for_update_metadata!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -1095,6 +1101,7 @@ default_imp_for_cancel_post_capture!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -1216,6 +1223,7 @@ default_imp_for_complete_authorize!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -1346,6 +1354,7 @@ default_imp_for_incremental_authorization!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -1488,6 +1497,7 @@ default_imp_for_create_customer!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -1615,6 +1625,7 @@ default_imp_for_connector_redirect_response!( connectors::Paytm, connectors::Payone, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2163,6 +2174,7 @@ default_imp_for_pre_processing_steps!( connectors::Paytm, connectors::Payone, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2301,6 +2313,7 @@ default_imp_for_post_processing_steps!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Powertranz, @@ -2444,6 +2457,7 @@ default_imp_for_approve!( connectors::Paytm, connectors::Payone, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2588,6 +2602,7 @@ default_imp_for_reject!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2731,6 +2746,7 @@ default_imp_for_webhook_source_verification!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2874,6 +2890,7 @@ default_imp_for_accept_dispute!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3015,6 +3032,7 @@ default_imp_for_submit_evidence!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3155,6 +3173,7 @@ default_imp_for_defend_dispute!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3298,6 +3317,7 @@ default_imp_for_fetch_disputes!( connectors::Paysafe, connectors::Paystack, connectors::Payu, + connectors::Peachpayments, connectors::Paytm, connectors::Phonepe, connectors::Placetopay, @@ -3441,6 +3461,7 @@ default_imp_for_dispute_sync!( connectors::Paysafe, connectors::Paystack, connectors::Payu, + connectors::Peachpayments, connectors::Paytm, connectors::Phonepe, connectors::Placetopay, @@ -3592,6 +3613,7 @@ default_imp_for_file_upload!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3725,6 +3747,7 @@ default_imp_for_payouts!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3859,6 +3882,7 @@ default_imp_for_payouts_create!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -4000,6 +4024,7 @@ default_imp_for_payouts_retrieve!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Payone, connectors::Placetopay, @@ -4143,6 +4168,7 @@ default_imp_for_payouts_eligibility!( connectors::Paytm, connectors::Payone, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -4281,6 +4307,7 @@ default_imp_for_payouts_fulfill!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -4422,6 +4449,7 @@ default_imp_for_payouts_cancel!( connectors::Paytm, connectors::Payone, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -4564,6 +4592,7 @@ default_imp_for_payouts_quote!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -4707,6 +4736,7 @@ default_imp_for_payouts_recipient!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -4850,6 +4880,7 @@ default_imp_for_payouts_recipient_account!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -4995,6 +5026,7 @@ default_imp_for_frm_sale!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -5139,6 +5171,7 @@ default_imp_for_frm_checkout!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -5283,6 +5316,7 @@ default_imp_for_frm_transaction!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -5427,6 +5461,7 @@ default_imp_for_frm_fulfillment!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -5571,6 +5606,7 @@ default_imp_for_frm_record_return!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -5709,6 +5745,7 @@ default_imp_for_revoking_mandates!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -5850,6 +5887,7 @@ default_imp_for_uas_pre_authentication!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Powertranz, connectors::Prophetpay, @@ -5991,6 +6029,7 @@ default_imp_for_uas_post_authentication!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Powertranz, connectors::Prophetpay, @@ -6131,6 +6170,7 @@ default_imp_for_uas_authentication_confirmation!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Powertranz, connectors::Prophetpay, @@ -6262,6 +6302,7 @@ default_imp_for_connector_request_id!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Payme, connectors::Payone, @@ -6401,6 +6442,7 @@ default_imp_for_fraud_check!( connectors::Paypal, connectors::Paysafe, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Powertranz, connectors::Prophetpay, @@ -6564,6 +6606,7 @@ default_imp_for_connector_authentication!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Payone, connectors::Powertranz, @@ -6703,6 +6746,7 @@ default_imp_for_uas_authentication!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Powertranz, connectors::Prophetpay, @@ -6839,6 +6883,7 @@ default_imp_for_revenue_recovery!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Paypal, connectors::Paysafe, @@ -6984,6 +7029,7 @@ default_imp_for_billing_connector_payment_sync!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Paypal, connectors::Paysafe, @@ -7127,6 +7173,7 @@ default_imp_for_revenue_recovery_record_back!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Paypal, connectors::Paysafe, @@ -7270,6 +7317,7 @@ default_imp_for_billing_connector_invoice_sync!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Paypal, connectors::Paysafe, @@ -7407,6 +7455,7 @@ default_imp_for_external_vault!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Paypal, connectors::Paysafe, @@ -7550,6 +7599,7 @@ default_imp_for_external_vault_insert!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Paypal, connectors::Paysafe, @@ -7693,6 +7743,7 @@ default_imp_for_external_vault_retrieve!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Paypal, connectors::Paysafe, @@ -7836,6 +7887,7 @@ default_imp_for_external_vault_delete!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Paypal, connectors::Paysafe, @@ -7979,6 +8031,7 @@ default_imp_for_external_vault_create!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Paypal, connectors::Paysafe, @@ -8123,6 +8176,7 @@ default_imp_for_connector_authentication_token!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Paypal, connectors::Paysafe, @@ -8274,6 +8328,7 @@ default_imp_for_external_vault_proxy_payments_create!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rs index f175c52e93..836ad796a0 100644 --- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs +++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs @@ -342,6 +342,7 @@ default_imp_for_new_connector_integration_payment!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -486,6 +487,7 @@ default_imp_for_new_connector_integration_refund!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -621,6 +623,7 @@ default_imp_for_new_connector_integration_connector_authentication_token!( connectors::Paysafe, connectors::Paystack, connectors::Payu, + connectors::Peachpayments, connectors::Placetopay, connectors::Plaid, connectors::Powertranz, @@ -757,6 +760,7 @@ default_imp_for_new_connector_integration_connector_access_token!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -901,6 +905,7 @@ default_imp_for_new_connector_integration_accept_dispute!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -1050,6 +1055,7 @@ default_imp_for_new_connector_integration_fetch_disputes!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Plaid, connectors::Placetopay, @@ -1195,6 +1201,7 @@ default_imp_for_new_connector_integration_dispute_sync!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Plaid, connectors::Placetopay, @@ -1335,6 +1342,7 @@ default_imp_for_new_connector_integration_defend_dispute!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -1477,6 +1485,7 @@ default_imp_for_new_connector_integration_submit_evidence!( connectors::Paysafe, connectors::Paystack, connectors::Payu, + connectors::Peachpayments, connectors::Paytm, connectors::Placetopay, connectors::Plaid, @@ -1632,6 +1641,7 @@ default_imp_for_new_connector_integration_file_upload!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -1778,6 +1788,7 @@ default_imp_for_new_connector_integration_payouts_create!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -1924,6 +1935,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2070,6 +2082,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2216,6 +2229,7 @@ default_imp_for_new_connector_integration_payouts_cancel!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2362,6 +2376,7 @@ default_imp_for_new_connector_integration_payouts_quote!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2508,6 +2523,7 @@ default_imp_for_new_connector_integration_payouts_recipient!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2654,6 +2670,7 @@ default_imp_for_new_connector_integration_payouts_sync!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2800,6 +2817,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -2944,6 +2962,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3090,6 +3109,7 @@ default_imp_for_new_connector_integration_frm_sale!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3236,6 +3256,7 @@ default_imp_for_new_connector_integration_frm_checkout!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3382,6 +3403,7 @@ default_imp_for_new_connector_integration_frm_transaction!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3528,6 +3550,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3674,6 +3697,7 @@ default_imp_for_new_connector_integration_frm_record_return!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3816,6 +3840,7 @@ default_imp_for_new_connector_integration_revoking_mandates!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -3934,6 +3959,7 @@ default_imp_for_new_connector_integration_frm!( connectors::Payeezy, connectors::Payload, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -4075,6 +4101,7 @@ default_imp_for_new_connector_integration_connector_authentication!( connectors::Payeezy, connectors::Payload, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -4209,6 +4236,7 @@ default_imp_for_new_connector_integration_revenue_recovery!( connectors::Payeezy, connectors::Payload, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, @@ -4371,6 +4399,7 @@ default_imp_for_new_connector_integration_external_vault!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Powertranz, @@ -4519,6 +4548,7 @@ default_imp_for_new_connector_integration_external_vault_proxy!( connectors::Paystack, connectors::Paytm, connectors::Payu, + connectors::Peachpayments, connectors::Phonepe, connectors::Placetopay, connectors::Plaid, diff --git a/crates/hyperswitch_domain_models/src/connector_endpoints.rs b/crates/hyperswitch_domain_models/src/connector_endpoints.rs index d6b62a5eb4..a9f5929c5f 100644 --- a/crates/hyperswitch_domain_models/src/connector_endpoints.rs +++ b/crates/hyperswitch_domain_models/src/connector_endpoints.rs @@ -102,6 +102,7 @@ pub struct Connectors { pub paystack: ConnectorParams, pub paytm: ConnectorParams, pub payu: ConnectorParams, + pub peachpayments: ConnectorParams, pub phonepe: ConnectorParams, pub placetopay: ConnectorParams, pub plaid: ConnectorParams, diff --git a/crates/router/src/connector.rs b/crates/router/src/connector.rs index a8e859cc5b..45d7ad513d 100644 --- a/crates/router/src/connector.rs +++ b/crates/router/src/connector.rs @@ -32,19 +32,20 @@ pub use hyperswitch_connectors::connectors::{ nordea, nordea::Nordea, novalnet, novalnet::Novalnet, nuvei, nuvei::Nuvei, opayo, opayo::Opayo, opennode, opennode::Opennode, paybox, paybox::Paybox, payeezy, payeezy::Payeezy, payload, payload::Payload, payme, payme::Payme, payone, payone::Payone, paypal, paypal::Paypal, paysafe, - paysafe::Paysafe, paystack, paystack::Paystack, paytm, paytm::Paytm, payu, payu::Payu, phonepe, - phonepe::Phonepe, placetopay, placetopay::Placetopay, plaid, plaid::Plaid, powertranz, - powertranz::Powertranz, prophetpay, prophetpay::Prophetpay, rapyd, rapyd::Rapyd, razorpay, - razorpay::Razorpay, recurly, recurly::Recurly, redsys, redsys::Redsys, riskified, - riskified::Riskified, santander, santander::Santander, shift4, shift4::Shift4, sift, - sift::Sift, signifyd, signifyd::Signifyd, silverflow, silverflow::Silverflow, square, - square::Square, stax, stax::Stax, stripe, stripe::Stripe, stripebilling, - stripebilling::Stripebilling, taxjar, taxjar::Taxjar, threedsecureio, - threedsecureio::Threedsecureio, thunes, thunes::Thunes, tokenio, tokenio::Tokenio, trustpay, - trustpay::Trustpay, trustpayments, trustpayments::Trustpayments, tsys, tsys::Tsys, - unified_authentication_service, unified_authentication_service::UnifiedAuthenticationService, - vgs, vgs::Vgs, volt, volt::Volt, wellsfargo, wellsfargo::Wellsfargo, wellsfargopayout, - wellsfargopayout::Wellsfargopayout, wise, wise::Wise, worldline, worldline::Worldline, - worldpay, worldpay::Worldpay, worldpayvantiv, worldpayvantiv::Worldpayvantiv, worldpayxml, - worldpayxml::Worldpayxml, xendit, xendit::Xendit, zen, zen::Zen, zsl, zsl::Zsl, + paysafe::Paysafe, paystack, paystack::Paystack, paytm, paytm::Paytm, payu, payu::Payu, + peachpayments, peachpayments::Peachpayments, phonepe, phonepe::Phonepe, placetopay, + placetopay::Placetopay, plaid, plaid::Plaid, powertranz, powertranz::Powertranz, prophetpay, + prophetpay::Prophetpay, rapyd, rapyd::Rapyd, razorpay, razorpay::Razorpay, recurly, + recurly::Recurly, redsys, redsys::Redsys, riskified, riskified::Riskified, santander, + santander::Santander, shift4, shift4::Shift4, sift, sift::Sift, signifyd, signifyd::Signifyd, + silverflow, silverflow::Silverflow, square, square::Square, stax, stax::Stax, stripe, + stripe::Stripe, stripebilling, stripebilling::Stripebilling, taxjar, taxjar::Taxjar, + threedsecureio, threedsecureio::Threedsecureio, thunes, thunes::Thunes, tokenio, + tokenio::Tokenio, trustpay, trustpay::Trustpay, trustpayments, trustpayments::Trustpayments, + tsys, tsys::Tsys, unified_authentication_service, + unified_authentication_service::UnifiedAuthenticationService, vgs, vgs::Vgs, volt, volt::Volt, + wellsfargo, wellsfargo::Wellsfargo, wellsfargopayout, wellsfargopayout::Wellsfargopayout, wise, + wise::Wise, worldline, worldline::Worldline, worldpay, worldpay::Worldpay, worldpayvantiv, + worldpayvantiv::Worldpayvantiv, worldpayxml, worldpayxml::Worldpayxml, xendit, xendit::Xendit, + zen, zen::Zen, zsl, zsl::Zsl, }; diff --git a/crates/router/src/core/connector_validation.rs b/crates/router/src/core/connector_validation.rs index 77e51e63f3..c6271341d6 100644 --- a/crates/router/src/core/connector_validation.rs +++ b/crates/router/src/core/connector_validation.rs @@ -415,6 +415,10 @@ impl ConnectorAuthTypeAndMetadataValidation<'_> { payu::transformers::PayuAuthType::try_from(self.auth_type)?; Ok(()) } + // api_enums::Connector::Peachpayments => { + // peachpayments::transformers::PeachpaymentsAuthType::try_from(self.auth_type)?; + // Ok(()) + // } api_enums::Connector::Placetopay => { placetopay::transformers::PlacetopayAuthType::try_from(self.auth_type)?; Ok(()) diff --git a/crates/router/src/types/api/connector_mapping.rs b/crates/router/src/types/api/connector_mapping.rs index 0e809c628f..28300ecbf2 100644 --- a/crates/router/src/types/api/connector_mapping.rs +++ b/crates/router/src/types/api/connector_mapping.rs @@ -352,6 +352,9 @@ impl ConnectorData { Ok(ConnectorEnum::Old(Box::new(connector::Payone::new()))) } enums::Connector::Payu => Ok(ConnectorEnum::Old(Box::new(connector::Payu::new()))), + // enums::Connector::Peachpayments => Ok(ConnectorEnum::Old(Box::new( + // hyperswitch_connectors::connectors::Peachpayments::new(), + // ))), enums::Connector::Placetopay => { Ok(ConnectorEnum::Old(Box::new(connector::Placetopay::new()))) } diff --git a/crates/router/src/types/api/feature_matrix.rs b/crates/router/src/types/api/feature_matrix.rs index 98e00bc893..d82c1968b0 100644 --- a/crates/router/src/types/api/feature_matrix.rs +++ b/crates/router/src/types/api/feature_matrix.rs @@ -274,6 +274,9 @@ impl FeatureMatrixConnectorData { Ok(ConnectorEnum::Old(Box::new(connector::Payone::new()))) } enums::Connector::Payu => Ok(ConnectorEnum::Old(Box::new(connector::Payu::new()))), + // enums::Connector::Peachpayments => Ok(ConnectorEnum::Old(Box::new( + // connector::Peachpayments::new(), + // ))), enums::Connector::Placetopay => { Ok(ConnectorEnum::Old(Box::new(connector::Placetopay::new()))) } diff --git a/crates/router/src/types/connector_transformers.rs b/crates/router/src/types/connector_transformers.rs index fb43e8b136..683ba60373 100644 --- a/crates/router/src/types/connector_transformers.rs +++ b/crates/router/src/types/connector_transformers.rs @@ -113,6 +113,7 @@ impl ForeignTryFrom for common_enums::RoutableConnectors { api_enums::Connector::Paysafe => Self::Paysafe, api_enums::Connector::Paystack => Self::Paystack, api_enums::Connector::Payu => Self::Payu, + // api_enums::Connector::Peachpayments => Self::Peachpayments, api_models::enums::Connector::Placetopay => Self::Placetopay, api_enums::Connector::Plaid => Self::Plaid, api_enums::Connector::Powertranz => Self::Powertranz, diff --git a/crates/router/tests/connectors/main.rs b/crates/router/tests/connectors/main.rs index 87434a0e6d..d03e5e18af 100644 --- a/crates/router/tests/connectors/main.rs +++ b/crates/router/tests/connectors/main.rs @@ -91,6 +91,7 @@ mod paysafe; mod paystack; mod paytm; mod payu; +mod peachpayments; mod phonepe; mod placetopay; mod plaid; diff --git a/crates/router/tests/connectors/peachpayments.rs b/crates/router/tests/connectors/peachpayments.rs new file mode 100644 index 0000000000..f7da85872a --- /dev/null +++ b/crates/router/tests/connectors/peachpayments.rs @@ -0,0 +1,421 @@ +use hyperswitch_domain_models::payment_method_data::{Card, PaymentMethodData}; +use masking::Secret; +use router::types::{self, api, storage::enums}; +use test_utils::connector_auth; + +use crate::utils::{self, ConnectorActions}; + +#[derive(Clone, Copy)] +struct PeachpaymentsTest; +impl ConnectorActions for PeachpaymentsTest {} +impl utils::Connector for PeachpaymentsTest { + fn get_data(&self) -> api::ConnectorData { + use router::connector::Peachpayments; + utils::construct_connector_data_old( + Box::new(Peachpayments::new()), + types::Connector::Plaid, + api::GetToken::Connector, + None, + ) + } + + fn get_auth_token(&self) -> types::ConnectorAuthType { + utils::to_connector_auth_type( + connector_auth::ConnectorAuthentication::new() + .peachpayments + .expect("Missing connector authentication configuration") + .into(), + ) + } + + fn get_name(&self) -> String { + "peachpayments".to_string() + } +} + +static CONNECTOR: PeachpaymentsTest = PeachpaymentsTest {}; + +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 5faf7bbafb..5b79c5ef2e 100644 --- a/crates/router/tests/connectors/sample_auth.toml +++ b/crates/router/tests/connectors/sample_auth.toml @@ -366,3 +366,7 @@ api_key="API Key" [bluecode] api_key="EOrder Token" + +[peachpayments] +api_key="API Key" +key1="Tenant ID" \ 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 f6deae24e2..6793f54a8d 100644 --- a/crates/test_utils/src/connector_auth.rs +++ b/crates/test_utils/src/connector_auth.rs @@ -98,6 +98,7 @@ pub struct ConnectorAuthentication { pub paystack: Option, pub paytm: Option, pub payu: Option, + pub peachpayments: Option, pub phonepe: Option, pub placetopay: Option, pub plaid: Option, diff --git a/crates/test_utils/tests/sample_auth.toml b/crates/test_utils/tests/sample_auth.toml index c7ec4f12c5..c11c637ece 100644 --- a/crates/test_utils/tests/sample_auth.toml +++ b/crates/test_utils/tests/sample_auth.toml @@ -168,4 +168,8 @@ api_key="API Key" [boku] api_key="API Key" -key1 = "transaction key" \ No newline at end of file +key1 = "transaction key" + +[peachpayments] +api_key="API Key" +key1="Tenant ID" \ No newline at end of file diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml index 7508208069..9075da96e6 100644 --- a/loadtest/config/development.toml +++ b/loadtest/config/development.toml @@ -173,6 +173,7 @@ paysafe.base_url = "https://api.test.paysafe.com/paymenthub/" paystack.base_url = "https://api.paystack.co" paytm.base_url = "https://securegw-stage.paytm.in/" payu.base_url = "https://secure.snd.payu.com/" +peachpayments.base_url = "https://apitest.bankint.ppay.io/v/1" phonepe.base_url = "https://api.phonepe.com/apis/hermes/" placetopay.base_url = "https://test.placetopay.com/rest/gateway" plaid.base_url = "https://sandbox.plaid.com" diff --git a/scripts/add_connector.sh b/scripts/add_connector.sh index 6f041b8fa0..b42835e091 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 affirm airwallex amazonpay applepay archipel authipay authorizedotnet bambora bamboraapac bankofamerica barclaycard billwerk bitpay blackhawknetwork bluecode bluesnap boku braintree breadpay cashtocode celero chargebee checkbook checkout coinbase cryptopay ctp_visa custombilling cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector dwolla ebanx elavon facilitapay fiserv fiservemea fiuu flexiti forte getnet globalpay globepay gocardless gpayments helcim hipay hyperswitch_vault hyperwallet hyperwallet iatapay inespay itaubank jpmorgan juspaythreedsserver katapult klarna mifinity mollie moneris mpgs multisafepay netcetera nexinets nexixpay nomupay noon nordea novalnet nuvei opayo opennode paybox payeezy payload payme payone paypal paysafe paystack paytm payu phonepe placetopay plaid powertranz prophetpay rapyd razorpay recurly redsys santander shift4 sift silverflow square stax stripe stripebilling taxjar threedsecureio thunes tokenio trustpay trustpayments tsys unified_authentication_service vgs volt wellsfargo wellsfargopayout wise worldline worldpay worldpayvantiv worldpayxml xendit zsl "$1") + connectors=(aci adyen adyenplatform affirm airwallex amazonpay applepay archipel authipay authorizedotnet bambora bamboraapac bankofamerica barclaycard billwerk bitpay blackhawknetwork bluecode bluesnap boku braintree breadpay cashtocode celero chargebee checkbook checkout coinbase cryptopay ctp_visa custombilling cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector dwolla ebanx elavon facilitapay fiserv fiservemea fiuu flexiti forte getnet globalpay globepay gocardless gpayments helcim hipay hyperswitch_vault hyperwallet hyperwallet iatapay inespay itaubank jpmorgan juspaythreedsserver katapult klarna mifinity mollie moneris mpgs multisafepay netcetera nexinets nexixpay nomupay noon nordea novalnet nuvei opayo opennode paybox payeezy payload payme payone paypal paysafe paystack paytm payu peachpayments phonepe placetopay plaid powertranz prophetpay rapyd razorpay recurly redsys santander shift4 sift silverflow square stax stripe stripebilling taxjar threedsecureio thunes tokenio trustpay trustpayments tsys unified_authentication_service vgs volt wellsfargo wellsfargopayout wise worldline worldpay worldpayvantiv worldpayxml xendit zsl "$1") IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFS