From 9bc363f140afcdc3d4dc624d6410a42c33afaeed Mon Sep 17 00:00:00 2001 From: AmeyWale-HS Date: Thu, 21 Nov 2024 23:35:31 +0530 Subject: [PATCH] feat(connector): [Xendit] Template PR (#6593) Co-authored-by: Amey Wale --- api-reference-v2/openapi_spec.json | 1 + api-reference/openapi_spec.json | 1 + config/config.example.toml | 2 + 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 + crates/connector_configs/src/connector.rs | 1 + .../hyperswitch_connectors/src/connectors.rs | 3 +- .../src/connectors/xendit.rs | 563 ++++++++++++++++++ .../src/connectors/xendit/transformers.rs | 228 +++++++ .../src/default_implementations.rs | 32 + .../src/default_implementations_v2.rs | 22 + crates/hyperswitch_interfaces/src/configs.rs | 1 + crates/router/src/connector.rs | 2 +- crates/router/src/types/api.rs | 3 + crates/router/src/types/transformers.rs | 1 + crates/router/tests/connectors/xendit.rs | 402 +++++++++++++ crates/test_utils/src/connector_auth.rs | 1 + loadtest/config/development.toml | 2 + scripts/add_connector.sh | 2 +- 24 files changed, 1274 insertions(+), 3 deletions(-) create mode 100644 crates/hyperswitch_connectors/src/connectors/xendit.rs create mode 100644 crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs create mode 100644 crates/router/tests/connectors/xendit.rs diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index 661e51f6c1..095e386d98 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -18167,6 +18167,7 @@ "wise", "worldline", "worldpay", + "xendit", "zen", "plaid", "zsl" diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index 801b32b490..247b308bd6 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -22815,6 +22815,7 @@ "wise", "worldline", "worldpay", + "xendit", "zen", "plaid", "zsl" diff --git a/config/config.example.toml b/config/config.example.toml index 289087f4a3..08a32035c4 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -271,6 +271,7 @@ wellsfargopayout.base_url = "https://api-sandbox.wellsfargo.com/" wise.base_url = "https://api.sandbox.transferwise.tech/" worldline.base_url = "https://eu.sandbox.api-ingenico.com/" worldpay.base_url = "https://try.access.worldpay.com/" +xendit.base_url = "https://api.xendit.co" zsl.base_url = "https://api.sitoffalb.net/" zen.base_url = "https://api.zen-test.com/" zen.secondary_base_url = "https://secure.zen-test.com/" @@ -329,6 +330,7 @@ cards = [ "threedsecureio", "thunes", "worldpay", + "xendit", "zen", "zsl", ] diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml index 1c7a40ea53..e1ea99bc8d 100644 --- a/config/deployments/integration_test.toml +++ b/config/deployments/integration_test.toml @@ -111,6 +111,7 @@ wellsfargopayout.base_url = "https://api-sandbox.wellsfargo.com/" wise.base_url = "https://api.sandbox.transferwise.tech/" worldline.base_url = "https://eu.sandbox.api-ingenico.com/" worldpay.base_url = "https://try.access.worldpay.com/" +xendit.base_url = "https://api.xendit.co" zen.base_url = "https://api.zen-test.com/" zen.secondary_base_url = "https://secure.zen-test.com/" zsl.base_url = "https://api.sitoffalb.net/" diff --git a/config/deployments/production.toml b/config/deployments/production.toml index 76f42085f9..58b6a49fed 100644 --- a/config/deployments/production.toml +++ b/config/deployments/production.toml @@ -115,6 +115,7 @@ wellsfargopayout.base_url = "https://api.wellsfargo.com/" wise.base_url = "https://api.sandbox.transferwise.tech/" worldline.base_url = "https://eu.sandbox.api-ingenico.com/" worldpay.base_url = "https://try.access.worldpay.com/" +xendit.base_url = "https://api.xendit.co" zen.base_url = "https://api.zen.com/" zen.secondary_base_url = "https://secure.zen.com/" zsl.base_url = "https://apirh.prodoffalb.net/" diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml index 98e1e7e00d..4421d1b1e9 100644 --- a/config/deployments/sandbox.toml +++ b/config/deployments/sandbox.toml @@ -115,6 +115,7 @@ wellsfargopayout.base_url = "https://api-sandbox.wellsfargo.com/" wise.base_url = "https://api.sandbox.transferwise.tech/" worldline.base_url = "https://eu.sandbox.api-ingenico.com/" worldpay.base_url = "https://try.access.worldpay.com/" +xendit.base_url = "https://api.xendit.co" zen.base_url = "https://api.zen-test.com/" zen.secondary_base_url = "https://secure.zen-test.com/" zsl.base_url = "https://api.sitoffalb.net/" diff --git a/config/development.toml b/config/development.toml index 97739c3f5c..a58497f4a5 100644 --- a/config/development.toml +++ b/config/development.toml @@ -169,6 +169,7 @@ cards = [ "wise", "worldline", "worldpay", + "xendit", "zen", "zsl", ] @@ -279,6 +280,7 @@ stripe.base_url_file_upload = "https://files.stripe.com/" wise.base_url = "https://api.sandbox.transferwise.tech/" worldline.base_url = "https://eu.sandbox.api-ingenico.com/" worldpay.base_url = "https://try.access.worldpay.com/" +xendit.base_url = "https://api.xendit.co" trustpay.base_url = "https://test-tpgw.trustpay.eu/" tsys.base_url = "https://stagegw.transnox.com/" volt.base_url = "https://api.sandbox.volt.io/" diff --git a/config/docker_compose.toml b/config/docker_compose.toml index d71be95848..c293a7ac82 100644 --- a/config/docker_compose.toml +++ b/config/docker_compose.toml @@ -201,6 +201,7 @@ wellsfargopayout.base_url = "https://api-sandbox.wellsfargo.com/" wise.base_url = "https://api.sandbox.transferwise.tech/" worldline.base_url = "https://eu.sandbox.api-ingenico.com/" worldpay.base_url = "https://try.access.worldpay.com/" +xendit.base_url = "https://api.xendit.co" zen.base_url = "https://api.zen-test.com/" zen.secondary_base_url = "https://secure.zen-test.com/" zsl.base_url = "https://api.sitoffalb.net/" @@ -287,6 +288,7 @@ cards = [ "wise", "worldline", "worldpay", + "xendit", "zen", "zsl", ] diff --git a/crates/api_models/src/connector_enums.rs b/crates/api_models/src/connector_enums.rs index 77081f4995..11b3840092 100644 --- a/crates/api_models/src/connector_enums.rs +++ b/crates/api_models/src/connector_enums.rs @@ -129,6 +129,7 @@ pub enum Connector { Signifyd, Plaid, Riskified, + // Xendit, Zen, Zsl, } @@ -259,6 +260,7 @@ impl Connector { | Self::Wise | Self::Worldline | Self::Worldpay + // | Self::Xendit | Self::Zen | Self::Zsl | Self::Signifyd diff --git a/crates/common_enums/src/connector_enums.rs b/crates/common_enums/src/connector_enums.rs index 9beaed7596..e75a4038c0 100644 --- a/crates/common_enums/src/connector_enums.rs +++ b/crates/common_enums/src/connector_enums.rs @@ -123,6 +123,7 @@ pub enum RoutableConnectors { Wise, Worldline, Worldpay, + Xendit, Zen, Plaid, Zsl, diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs index 3634fe730c..b1cf0bd9f9 100644 --- a/crates/connector_configs/src/connector.rs +++ b/crates/connector_configs/src/connector.rs @@ -231,6 +231,7 @@ pub struct ConnectorConfig { pub wise_payout: Option, pub worldline: Option, pub worldpay: Option, + pub xendit: Option, pub square: Option, pub stax: Option, pub dummy_connector: Option, diff --git a/crates/hyperswitch_connectors/src/connectors.rs b/crates/hyperswitch_connectors/src/connectors.rs index 2bc8245009..b764ab5b44 100644 --- a/crates/hyperswitch_connectors/src/connectors.rs +++ b/crates/hyperswitch_connectors/src/connectors.rs @@ -36,6 +36,7 @@ pub mod tsys; pub mod volt; pub mod worldline; pub mod worldpay; +pub mod xendit; pub mod zen; pub mod zsl; @@ -48,5 +49,5 @@ pub use self::{ nexinets::Nexinets, nexixpay::Nexixpay, nomupay::Nomupay, novalnet::Novalnet, payeezy::Payeezy, 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, + worldpay::Worldpay, xendit::Xendit, zen::Zen, zsl::Zsl, }; diff --git a/crates/hyperswitch_connectors/src/connectors/xendit.rs b/crates/hyperswitch_connectors/src/connectors/xendit.rs new file mode 100644 index 0000000000..c3f75a7673 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/xendit.rs @@ -0,0 +1,563 @@ +pub mod transformers; + +use common_utils::{ + errors::CustomResult, + ext_traits::BytesExt, + request::{Method, Request, RequestBuilder, RequestContent}, + types::{AmountConvertor, StringMinorUnit, StringMinorUnitForConnector}, +}; +use error_stack::{report, ResultExt}; +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 masking::{ExposeInterface, Mask}; +use transformers as xendit; + +use crate::{constants::headers, types::ResponseRouterData, utils}; + +#[derive(Clone)] +pub struct Xendit { + amount_converter: &'static (dyn AmountConvertor + Sync), +} + +impl Xendit { + pub fn new() -> &'static Self { + &Self { + amount_converter: &StringMinorUnitForConnector, + } + } +} + +impl api::Payment for Xendit {} +impl api::PaymentSession for Xendit {} +impl api::ConnectorAccessToken for Xendit {} +impl api::MandateSetup for Xendit {} +impl api::PaymentAuthorize for Xendit {} +impl api::PaymentSync for Xendit {} +impl api::PaymentCapture for Xendit {} +impl api::PaymentVoid for Xendit {} +impl api::Refund for Xendit {} +impl api::RefundExecute for Xendit {} +impl api::RefundSync for Xendit {} +impl api::PaymentToken for Xendit {} + +impl ConnectorIntegration + for Xendit +{ + // Not Implemented (R) +} + +impl ConnectorCommonExt for Xendit +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 Xendit { + fn id(&self) -> &'static str { + "xendit" + } + + 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.xendit.base_url.as_ref() + } + + fn get_auth_header( + &self, + auth_type: &ConnectorAuthType, + ) -> CustomResult)>, errors::ConnectorError> { + let auth = xendit::XenditAuthType::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: xendit::XenditErrorResponse = res + .response + .parse_struct("XenditErrorResponse") + .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 Xendit { + //TODO: implement functions when support enabled +} + +impl ConnectorIntegration for Xendit { + //TODO: implement sessions flow +} + +impl ConnectorIntegration for Xendit {} + +impl ConnectorIntegration for Xendit {} + +impl ConnectorIntegration for Xendit { + 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 = xendit::XenditRouterData::from((amount, req)); + let connector_req = xendit::XenditPaymentsRequest::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: xendit::XenditPaymentsResponse = res + .response + .parse_struct("Xendit 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 Xendit { + 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: xendit::XenditPaymentsResponse = res + .response + .parse_struct("xendit 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 Xendit { + 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: xendit::XenditPaymentsResponse = res + .response + .parse_struct("Xendit 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 Xendit {} + +impl ConnectorIntegration for Xendit { + 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 = xendit::XenditRouterData::from((refund_amount, req)); + let connector_req = xendit::XenditRefundRequest::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: xendit::RefundResponse = + res.response + .parse_struct("xendit 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 Xendit { + 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: xendit::RefundResponse = res + .response + .parse_struct("xendit 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 Xendit { + 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/xendit/transformers.rs b/crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs new file mode 100644 index 0000000000..c9d4cd2583 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs @@ -0,0 +1,228 @@ +use common_enums::enums; +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 masking::Secret; +use serde::{Deserialize, Serialize}; + +use crate::{ + types::{RefundsResponseRouterData, ResponseRouterData}, + utils::PaymentsAuthorizeRequestData, +}; + +//TODO: Fill the struct with respective fields +pub struct XenditRouterData { + 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 XenditRouterData { + 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 XenditPaymentsRequest { + amount: StringMinorUnit, + card: XenditCard, +} + +#[derive(Default, Debug, Serialize, Eq, PartialEq)] +pub struct XenditCard { + number: cards::CardNumber, + expiry_month: Secret, + expiry_year: Secret, + cvc: Secret, + complete: bool, +} + +impl TryFrom<&XenditRouterData<&PaymentsAuthorizeRouterData>> for XenditPaymentsRequest { + type Error = error_stack::Report; + fn try_from( + item: &XenditRouterData<&PaymentsAuthorizeRouterData>, + ) -> Result { + match item.router_data.request.payment_method_data.clone() { + PaymentMethodData::Card(req_card) => { + let card = XenditCard { + 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 XenditAuthType { + pub(super) api_key: Secret, +} + +impl TryFrom<&ConnectorAuthType> for XenditAuthType { + 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 XenditPaymentStatus { + Succeeded, + Failed, + #[default] + Processing, +} + +impl From for common_enums::AttemptStatus { + fn from(item: XenditPaymentStatus) -> Self { + match item { + XenditPaymentStatus::Succeeded => Self::Charged, + XenditPaymentStatus::Failed => Self::Failure, + XenditPaymentStatus::Processing => Self::Authorizing, + } + } +} + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct XenditPaymentsResponse { + status: XenditPaymentStatus, + 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 XenditRefundRequest { + pub amount: StringMinorUnit, +} + +impl TryFrom<&XenditRouterData<&RefundsRouterData>> for XenditRefundRequest { + type Error = error_stack::Report; + fn try_from(item: &XenditRouterData<&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 XenditErrorResponse { + 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 6ee8926f8d..bc86e71350 100644 --- a/crates/hyperswitch_connectors/src/default_implementations.rs +++ b/crates/hyperswitch_connectors/src/default_implementations.rs @@ -126,6 +126,7 @@ default_imp_for_authorize_session_token!( connectors::Tsys, connectors::Worldline, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -182,6 +183,7 @@ default_imp_for_calculate_tax!( connectors::Volt, connectors::Worldline, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -234,6 +236,7 @@ default_imp_for_session_update!( connectors::Globepay, connectors::Worldline, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl, connectors::Powertranz, @@ -291,6 +294,7 @@ default_imp_for_post_session_tokens!( connectors::Globepay, connectors::Worldline, connectors::Worldpay, + connectors::Xendit, connectors::Powertranz, connectors::Thunes, connectors::Tsys, @@ -346,6 +350,7 @@ default_imp_for_complete_authorize!( connectors::Tsys, connectors::Worldline, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -404,6 +409,7 @@ default_imp_for_incremental_authorization!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -461,6 +467,7 @@ default_imp_for_create_customer!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -515,6 +522,7 @@ default_imp_for_connector_redirect_response!( connectors::Tsys, connectors::Worldline, connectors::Volt, + connectors::Xendit, connectors::Zsl ); @@ -569,6 +577,7 @@ default_imp_for_pre_processing_steps!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -627,6 +636,7 @@ default_imp_for_post_processing_steps!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -685,6 +695,7 @@ default_imp_for_approve!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -743,6 +754,7 @@ default_imp_for_reject!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -801,6 +813,7 @@ default_imp_for_webhook_source_verification!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -860,6 +873,7 @@ default_imp_for_accept_dispute!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -918,6 +932,7 @@ default_imp_for_submit_evidence!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -976,6 +991,7 @@ default_imp_for_defend_dispute!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1043,6 +1059,7 @@ default_imp_for_file_upload!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1093,6 +1110,7 @@ default_imp_for_payouts!( connectors::Volt, connectors::Worldline, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1153,6 +1171,7 @@ default_imp_for_payouts_create!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1213,6 +1232,7 @@ default_imp_for_payouts_retrieve!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1273,6 +1293,7 @@ default_imp_for_payouts_eligibility!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1333,6 +1354,7 @@ default_imp_for_payouts_fulfill!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1393,6 +1415,7 @@ default_imp_for_payouts_cancel!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1453,6 +1476,7 @@ default_imp_for_payouts_quote!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1513,6 +1537,7 @@ default_imp_for_payouts_recipient!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1573,6 +1598,7 @@ default_imp_for_payouts_recipient_account!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1633,6 +1659,7 @@ default_imp_for_frm_sale!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1693,6 +1720,7 @@ default_imp_for_frm_checkout!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1753,6 +1781,7 @@ default_imp_for_frm_transaction!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1813,6 +1842,7 @@ default_imp_for_frm_fulfillment!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1873,6 +1903,7 @@ default_imp_for_frm_record_return!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1930,6 +1961,7 @@ default_imp_for_revoking_mandates!( connectors::Worldline, connectors::Worldpay, connectors::Volt, + connectors::Xendit, connectors::Zen, connectors::Zsl ); diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rs index d747d65d73..75cbf192e5 100644 --- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs +++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs @@ -243,6 +243,7 @@ default_imp_for_new_connector_integration_payment!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -302,6 +303,7 @@ default_imp_for_new_connector_integration_refund!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -356,6 +358,7 @@ default_imp_for_new_connector_integration_connector_access_token!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -416,6 +419,7 @@ default_imp_for_new_connector_integration_accept_dispute!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -475,6 +479,7 @@ default_imp_for_new_connector_integration_submit_evidence!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -534,6 +539,7 @@ default_imp_for_new_connector_integration_defend_dispute!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -603,6 +609,7 @@ default_imp_for_new_connector_integration_file_upload!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -664,6 +671,7 @@ default_imp_for_new_connector_integration_payouts_create!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -725,6 +733,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -786,6 +795,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -847,6 +857,7 @@ default_imp_for_new_connector_integration_payouts_cancel!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -908,6 +919,7 @@ default_imp_for_new_connector_integration_payouts_quote!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -969,6 +981,7 @@ default_imp_for_new_connector_integration_payouts_recipient!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1030,6 +1043,7 @@ default_imp_for_new_connector_integration_payouts_sync!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1091,6 +1105,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1150,6 +1165,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1211,6 +1227,7 @@ default_imp_for_new_connector_integration_frm_sale!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1272,6 +1289,7 @@ default_imp_for_new_connector_integration_frm_checkout!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1333,6 +1351,7 @@ default_imp_for_new_connector_integration_frm_transaction!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1394,6 +1413,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1455,6 +1475,7 @@ default_imp_for_new_connector_integration_frm_record_return!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); @@ -1513,6 +1534,7 @@ default_imp_for_new_connector_integration_revoking_mandates!( connectors::Worldline, connectors::Volt, connectors::Worldpay, + connectors::Xendit, connectors::Zen, connectors::Zsl ); diff --git a/crates/hyperswitch_interfaces/src/configs.rs b/crates/hyperswitch_interfaces/src/configs.rs index 58810a0cb3..5e5eeea31b 100644 --- a/crates/hyperswitch_interfaces/src/configs.rs +++ b/crates/hyperswitch_interfaces/src/configs.rs @@ -92,6 +92,7 @@ pub struct Connectors { pub wise: ConnectorParams, pub worldline: ConnectorParams, pub worldpay: ConnectorParams, + pub xendit: ConnectorParams, pub zen: ConnectorParams, pub zsl: ConnectorParams, } diff --git a/crates/router/src/connector.rs b/crates/router/src/connector.rs index 7913d6543c..e98730d006 100644 --- a/crates/router/src/connector.rs +++ b/crates/router/src/connector.rs @@ -57,7 +57,7 @@ pub use hyperswitch_connectors::connectors::{ 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, - zen, zen::Zen, zsl, zsl::Zsl, + xendit, xendit::Xendit, zen, zen::Zen, zsl, zsl::Zsl, }; #[cfg(feature = "dummy_connector")] diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs index b432c57c5d..f7909a9719 100644 --- a/crates/router/src/types/api.rs +++ b/crates/router/src/types/api.rs @@ -496,6 +496,9 @@ impl ConnectorData { enums::Connector::Worldpay => { Ok(ConnectorEnum::Old(Box::new(connector::Worldpay::new()))) } + // enums::Connector::Xendit => { + // Ok(ConnectorEnum::Old(Box::new(connector::Xendit::new()))) + // } enums::Connector::Mifinity => { Ok(ConnectorEnum::Old(Box::new(connector::Mifinity::new()))) } diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index c47c0ca342..ecec821144 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -303,6 +303,7 @@ impl ForeignTryFrom for common_enums::RoutableConnectors { api_enums::Connector::Wise => Self::Wise, api_enums::Connector::Worldline => Self::Worldline, api_enums::Connector::Worldpay => Self::Worldpay, + // api_enums::Connector::Xendit => Self::Xendit, api_enums::Connector::Zen => Self::Zen, api_enums::Connector::Zsl => Self::Zsl, #[cfg(feature = "dummy_connector")] diff --git a/crates/router/tests/connectors/xendit.rs b/crates/router/tests/connectors/xendit.rs new file mode 100644 index 0000000000..452f22a112 --- /dev/null +++ b/crates/router/tests/connectors/xendit.rs @@ -0,0 +1,402 @@ +use masking::Secret; +use router::{ + types::{self, api, storage::enums, +}}; + +use crate::utils::{self, ConnectorActions}; +use test_utils::connector_auth; + +#[derive(Clone, Copy)] +struct XenditTest; +impl ConnectorActions for XenditTest {} +impl utils::Connector for XenditTest { + fn get_data(&self) -> api::ConnectorData { + use router::connector::Xendit; + api::ConnectorData { + connector: Box::new(Xendit::new()), + connector_name: types::Connector::Xendit, + get_token: types::api::GetToken::Connector, + merchant_connector_id: None, + } + } + + fn get_auth_token(&self) -> types::ConnectorAuthType { + utils::to_connector_auth_type( + connector_auth::ConnectorAuthentication::new() + .xendit + .expect("Missing connector authentication configuration").into(), + ) + } + + fn get_name(&self) -> String { + "xendit".to_string() + } +} + +static CONNECTOR: XenditTest = XenditTest {}; + +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: types::api::PaymentMethodData::Card(api::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: api::PaymentMethodData::Card(api::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: api::PaymentMethodData::Card(api::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/test_utils/src/connector_auth.rs b/crates/test_utils/src/connector_auth.rs index be02e5720f..2b2dc14311 100644 --- a/crates/test_utils/src/connector_auth.rs +++ b/crates/test_utils/src/connector_auth.rs @@ -92,6 +92,7 @@ pub struct ConnectorAuthentication { // pub wellsfargopayout: Option, pub wise: Option, pub worldpay: Option, + pub xendit: Option, pub worldline: Option, pub zen: Option, pub zsl: Option, diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml index 288e72164c..b7a6fca7de 100644 --- a/loadtest/config/development.toml +++ b/loadtest/config/development.toml @@ -166,6 +166,7 @@ wellsfargo.base_url = "https://apitest.cybersource.com/" wellsfargopayout.base_url = "https://api-sandbox.wellsfargo.com/" worldline.base_url = "https://eu.sandbox.api-ingenico.com/" worldpay.base_url = "https://try.access.worldpay.com/" +xendit.base_url = "https://api.xendit.co" wise.base_url = "https://api.sandbox.transferwise.tech/" zen.base_url = "https://api.zen-test.com/" zen.secondary_base_url = "https://secure.zen-test.com/" @@ -253,6 +254,7 @@ cards = [ "wise", "worldline", "worldpay", + "xendit", "zen", "zsl", ] diff --git a/scripts/add_connector.sh b/scripts/add_connector.sh index 0ed38e8ef5..9f1992bfa4 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 payone paypal payu placetopay plaid powertranz prophetpay rapyd razorpay shift4 square stax stripe taxjar threedsecureio thunes trustpay tsys volt wellsfargo wellsfargopayout wise worldline worldpay xendit zsl "$1") IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFS res="$(echo ${sorted[@]})" sed -i'' -e "s/^ connectors=.*/ connectors=($res \"\$1\")/" $self.tmp