From ad5491f15bd8f61b2a918f584fe85132986176ad Mon Sep 17 00:00:00 2001 From: chikke srujan <121822803+srujanchikke@users.noreply.github.com> Date: Wed, 29 Jan 2025 16:03:21 +0530 Subject: [PATCH] feat(connector): add template code for chargebee (#7036) Co-authored-by: Chikke Srujan Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> --- config/config.example.toml | 1 + config/deployments/integration_test.toml | 1 + config/deployments/production.toml | 1 + config/deployments/sandbox.toml | 1 + config/development.toml | 1 + config/docker_compose.toml | 1 + crates/common_enums/src/connector_enums.rs | 3 + .../hyperswitch_connectors/src/connectors.rs | 22 +- .../src/connectors/chargebee.rs | 568 ++++++++++++++++++ .../src/connectors/chargebee/transformers.rs | 228 +++++++ .../src/default_implementations.rs | 34 ++ .../src/default_implementations_v2.rs | 22 + crates/hyperswitch_interfaces/src/configs.rs | 1 + crates/router/src/connector.rs | 4 +- .../connector_integration_v2_impls.rs | 3 + crates/router/src/core/payments/flows.rs | 3 + crates/router/src/types/api.rs | 1 + crates/router/src/types/transformers.rs | 1 + crates/router/tests/connectors/chargebee.rs | 421 +++++++++++++ crates/router/tests/connectors/main.rs | 1 + .../router/tests/connectors/sample_auth.toml | 5 +- crates/test_utils/src/connector_auth.rs | 1 + loadtest/config/development.toml | 1 + scripts/add_connector.sh | 2 +- 24 files changed, 1313 insertions(+), 14 deletions(-) create mode 100644 crates/hyperswitch_connectors/src/connectors/chargebee.rs create mode 100644 crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs create mode 100644 crates/router/tests/connectors/chargebee.rs diff --git a/config/config.example.toml b/config/config.example.toml index ecc2d2127c..1d4507126f 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -193,6 +193,7 @@ bluesnap.secondary_base_url = "https://sandpay.bluesnap.com/" boku.base_url = "https://$-api4-stage.boku.com" braintree.base_url = "https://payments.sandbox.braintree-api.com/graphql" cashtocode.base_url = "https://cluster05.api-test.cashtocode.com" +chargebee.base_url = "https://$.chargebee.com/api/" checkout.base_url = "https://api.sandbox.checkout.com/" coinbase.base_url = "https://api.commerce.coinbase.com" cryptopay.base_url = "https://business-sandbox.cryptopay.me" diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml index b6e487e5a3..d606f192e4 100644 --- a/config/deployments/integration_test.toml +++ b/config/deployments/integration_test.toml @@ -39,6 +39,7 @@ bluesnap.secondary_base_url = "https://sandpay.bluesnap.com/" boku.base_url = "https://$-api4-stage.boku.com" braintree.base_url = "https://payments.sandbox.braintree-api.com/graphql" cashtocode.base_url = "https://cluster05.api-test.cashtocode.com" +chargebee.base_url = "https://$.chargebee.com/api/" checkout.base_url = "https://api.sandbox.checkout.com/" coinbase.base_url = "https://api.commerce.coinbase.com" cryptopay.base_url = "https://business-sandbox.cryptopay.me" diff --git a/config/deployments/production.toml b/config/deployments/production.toml index 90a3440363..ff5abd3fb0 100644 --- a/config/deployments/production.toml +++ b/config/deployments/production.toml @@ -43,6 +43,7 @@ bluesnap.secondary_base_url = "https://pay.bluesnap.com/" boku.base_url = "https://country-api4-stage.boku.com" braintree.base_url = "https://payments.braintree-api.com/graphql" cashtocode.base_url = "https://cluster14.api.cashtocode.com" +chargebee.base_url = "https://$.chargebee.com/api/" checkout.base_url = "https://api.checkout.com/" coinbase.base_url = "https://api.commerce.coinbase.com" cryptopay.base_url = "https://business.cryptopay.me/" diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml index 7242f26367..208621433b 100644 --- a/config/deployments/sandbox.toml +++ b/config/deployments/sandbox.toml @@ -44,6 +44,7 @@ boku.base_url = "https://$-api4-stage.boku.com" braintree.base_url = "https://payments.sandbox.braintree-api.com/graphql" cashtocode.base_url = "https://cluster05.api-test.cashtocode.com" checkout.base_url = "https://api.sandbox.checkout.com/" +chargebee.base_url = "https://$.chargebee.com/api/" coinbase.base_url = "https://api.commerce.coinbase.com" cryptopay.base_url = "https://business-sandbox.cryptopay.me" cybersource.base_url = "https://apitest.cybersource.com/" diff --git a/config/development.toml b/config/development.toml index 6bce5cb89d..b293151a98 100644 --- a/config/development.toml +++ b/config/development.toml @@ -212,6 +212,7 @@ bluesnap.secondary_base_url = "https://sandpay.bluesnap.com/" boku.base_url = "https://$-api4-stage.boku.com" braintree.base_url = "https://payments.sandbox.braintree-api.com/graphql" cashtocode.base_url = "https://cluster05.api-test.cashtocode.com" +chargebee.base_url = "https://$.chargebee.com/api/" checkout.base_url = "https://api.sandbox.checkout.com/" coinbase.base_url = "https://api.commerce.coinbase.com" cryptopay.base_url = "https://business-sandbox.cryptopay.me" diff --git a/config/docker_compose.toml b/config/docker_compose.toml index 293e9a313e..656d4fa7ec 100644 --- a/config/docker_compose.toml +++ b/config/docker_compose.toml @@ -125,6 +125,7 @@ bluesnap.secondary_base_url = "https://sandpay.bluesnap.com/" boku.base_url = "https://$-api4-stage.boku.com" braintree.base_url = "https://payments.sandbox.braintree-api.com/graphql" cashtocode.base_url = "https://cluster05.api-test.cashtocode.com" +chargebee.base_url = "https://$.chargebee.com/api/" checkout.base_url = "https://api.sandbox.checkout.com/" coinbase.base_url = "https://api.commerce.coinbase.com" cryptopay.base_url = "https://business-sandbox.cryptopay.me" diff --git a/crates/common_enums/src/connector_enums.rs b/crates/common_enums/src/connector_enums.rs index 0402ae0645..288520722c 100644 --- a/crates/common_enums/src/connector_enums.rs +++ b/crates/common_enums/src/connector_enums.rs @@ -65,6 +65,7 @@ pub enum RoutableConnectors { Boku, Braintree, Cashtocode, + // Chargebee, Checkout, Coinbase, Cryptopay, @@ -199,6 +200,7 @@ pub enum Connector { Boku, Braintree, Cashtocode, + // Chargebee, Checkout, Coinbase, Cryptopay, @@ -350,6 +352,7 @@ impl Connector { | Self::Boku | Self::Braintree | Self::Cashtocode + // | Self::Chargebee | Self::Coinbase | Self::Cryptopay | Self::Deutschebank diff --git a/crates/hyperswitch_connectors/src/connectors.rs b/crates/hyperswitch_connectors/src/connectors.rs index bd646c95eb..15345c8221 100644 --- a/crates/hyperswitch_connectors/src/connectors.rs +++ b/crates/hyperswitch_connectors/src/connectors.rs @@ -8,6 +8,7 @@ pub mod bitpay; pub mod bluesnap; pub mod boku; pub mod cashtocode; +pub mod chargebee; pub mod coinbase; pub mod cryptopay; pub mod ctp_mastercard; @@ -59,16 +60,17 @@ pub mod zsl; pub use self::{ airwallex::Airwallex, amazonpay::Amazonpay, bambora::Bambora, bamboraapac::Bamboraapac, bankofamerica::Bankofamerica, billwerk::Billwerk, bitpay::Bitpay, bluesnap::Bluesnap, - boku::Boku, cashtocode::Cashtocode, coinbase::Coinbase, cryptopay::Cryptopay, - ctp_mastercard::CtpMastercard, cybersource::Cybersource, datatrans::Datatrans, - deutschebank::Deutschebank, digitalvirgo::Digitalvirgo, dlocal::Dlocal, elavon::Elavon, - fiserv::Fiserv, fiservemea::Fiservemea, fiuu::Fiuu, forte::Forte, globepay::Globepay, - gocardless::Gocardless, helcim::Helcim, inespay::Inespay, jpmorgan::Jpmorgan, mollie::Mollie, - multisafepay::Multisafepay, nexinets::Nexinets, nexixpay::Nexixpay, nomupay::Nomupay, - novalnet::Novalnet, paybox::Paybox, payeezy::Payeezy, payu::Payu, placetopay::Placetopay, - powertranz::Powertranz, prophetpay::Prophetpay, rapyd::Rapyd, razorpay::Razorpay, - redsys::Redsys, shift4::Shift4, square::Square, stax::Stax, taxjar::Taxjar, thunes::Thunes, - tsys::Tsys, unified_authentication_service::UnifiedAuthenticationService, volt::Volt, + boku::Boku, cashtocode::Cashtocode, chargebee::Chargebee, coinbase::Coinbase, + cryptopay::Cryptopay, ctp_mastercard::CtpMastercard, cybersource::Cybersource, + datatrans::Datatrans, deutschebank::Deutschebank, digitalvirgo::Digitalvirgo, dlocal::Dlocal, + elavon::Elavon, fiserv::Fiserv, fiservemea::Fiservemea, fiuu::Fiuu, forte::Forte, + globepay::Globepay, gocardless::Gocardless, helcim::Helcim, inespay::Inespay, + jpmorgan::Jpmorgan, mollie::Mollie, multisafepay::Multisafepay, nexinets::Nexinets, + nexixpay::Nexixpay, nomupay::Nomupay, novalnet::Novalnet, paybox::Paybox, payeezy::Payeezy, + payu::Payu, placetopay::Placetopay, powertranz::Powertranz, prophetpay::Prophetpay, + rapyd::Rapyd, razorpay::Razorpay, redsys::Redsys, shift4::Shift4, square::Square, stax::Stax, + taxjar::Taxjar, thunes::Thunes, tsys::Tsys, + unified_authentication_service::UnifiedAuthenticationService, volt::Volt, wellsfargo::Wellsfargo, worldline::Worldline, worldpay::Worldpay, xendit::Xendit, zen::Zen, zsl::Zsl, }; diff --git a/crates/hyperswitch_connectors/src/connectors/chargebee.rs b/crates/hyperswitch_connectors/src/connectors/chargebee.rs new file mode 100644 index 0000000000..40dd137c28 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/chargebee.rs @@ -0,0 +1,568 @@ +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, ConnectorSpecifications, + ConnectorValidation, + }, + configs::Connectors, + errors, + events::connector_api_logs::ConnectorEvent, + types::{self, Response}, + webhooks, +}; +use masking::{ExposeInterface, Mask}; +use transformers as chargebee; + +use crate::{constants::headers, types::ResponseRouterData, utils}; + +#[derive(Clone)] +pub struct Chargebee { + amount_converter: &'static (dyn AmountConvertor + Sync), +} + +impl Chargebee { + pub fn new() -> &'static Self { + &Self { + amount_converter: &StringMinorUnitForConnector, + } + } +} + +impl api::Payment for Chargebee {} +impl api::PaymentSession for Chargebee {} +impl api::ConnectorAccessToken for Chargebee {} +impl api::MandateSetup for Chargebee {} +impl api::PaymentAuthorize for Chargebee {} +impl api::PaymentSync for Chargebee {} +impl api::PaymentCapture for Chargebee {} +impl api::PaymentVoid for Chargebee {} +impl api::Refund for Chargebee {} +impl api::RefundExecute for Chargebee {} +impl api::RefundSync for Chargebee {} +impl api::PaymentToken for Chargebee {} + +impl ConnectorIntegration + for Chargebee +{ + // Not Implemented (R) +} + +impl ConnectorCommonExt for Chargebee +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 Chargebee { + fn id(&self) -> &'static str { + "chargebee" + } + + fn get_currency_unit(&self) -> api::CurrencyUnit { + api::CurrencyUnit::Minor + } + + fn common_get_content_type(&self) -> &'static str { + "application/json" + } + + fn base_url<'a>(&self, connectors: &'a Connectors) -> &'a str { + connectors.chargebee.base_url.as_ref() + } + + fn get_auth_header( + &self, + auth_type: &ConnectorAuthType, + ) -> CustomResult)>, errors::ConnectorError> { + let auth = chargebee::ChargebeeAuthType::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: chargebee::ChargebeeErrorResponse = res + .response + .parse_struct("ChargebeeErrorResponse") + .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 Chargebee { + //TODO: implement functions when support enabled +} + +impl ConnectorIntegration for Chargebee { + //TODO: implement sessions flow +} + +impl ConnectorIntegration for Chargebee {} + +impl ConnectorIntegration + for Chargebee +{ +} + +impl ConnectorIntegration for Chargebee { + 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 = chargebee::ChargebeeRouterData::from((amount, req)); + let connector_req = chargebee::ChargebeePaymentsRequest::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: chargebee::ChargebeePaymentsResponse = res + .response + .parse_struct("Chargebee 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 Chargebee { + 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: chargebee::ChargebeePaymentsResponse = res + .response + .parse_struct("chargebee 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 Chargebee { + 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: chargebee::ChargebeePaymentsResponse = res + .response + .parse_struct("Chargebee 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 Chargebee {} + +impl ConnectorIntegration for Chargebee { + 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 = chargebee::ChargebeeRouterData::from((refund_amount, req)); + let connector_req = chargebee::ChargebeeRefundRequest::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: chargebee::RefundResponse = res + .response + .parse_struct("chargebee 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 Chargebee { + 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: chargebee::RefundResponse = res + .response + .parse_struct("chargebee 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 Chargebee { + 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)) + } +} + +impl ConnectorSpecifications for Chargebee {} diff --git a/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs b/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs new file mode 100644 index 0000000000..f825a17acb --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/chargebee/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 ChargebeeRouterData { + 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 ChargebeeRouterData { + 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 ChargebeePaymentsRequest { + amount: StringMinorUnit, + card: ChargebeeCard, +} + +#[derive(Default, Debug, Serialize, Eq, PartialEq)] +pub struct ChargebeeCard { + number: cards::CardNumber, + expiry_month: Secret, + expiry_year: Secret, + cvc: Secret, + complete: bool, +} + +impl TryFrom<&ChargebeeRouterData<&PaymentsAuthorizeRouterData>> for ChargebeePaymentsRequest { + type Error = error_stack::Report; + fn try_from( + item: &ChargebeeRouterData<&PaymentsAuthorizeRouterData>, + ) -> Result { + match item.router_data.request.payment_method_data.clone() { + PaymentMethodData::Card(req_card) => { + let card = ChargebeeCard { + 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 ChargebeeAuthType { + pub(super) api_key: Secret, +} + +impl TryFrom<&ConnectorAuthType> for ChargebeeAuthType { + 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 ChargebeePaymentStatus { + Succeeded, + Failed, + #[default] + Processing, +} + +impl From for common_enums::AttemptStatus { + fn from(item: ChargebeePaymentStatus) -> Self { + match item { + ChargebeePaymentStatus::Succeeded => Self::Charged, + ChargebeePaymentStatus::Failed => Self::Failure, + ChargebeePaymentStatus::Processing => Self::Authorizing, + } + } +} + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct ChargebeePaymentsResponse { + status: ChargebeePaymentStatus, + 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 ChargebeeRefundRequest { + pub amount: StringMinorUnit, +} + +impl TryFrom<&ChargebeeRouterData<&RefundsRouterData>> for ChargebeeRefundRequest { + type Error = error_stack::Report; + fn try_from(item: &ChargebeeRouterData<&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 ChargebeeErrorResponse { + 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 a2db7ad7b6..e70aff630e 100644 --- a/crates/hyperswitch_connectors/src/default_implementations.rs +++ b/crates/hyperswitch_connectors/src/default_implementations.rs @@ -105,6 +105,7 @@ default_imp_for_authorize_session_token!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -178,6 +179,7 @@ default_imp_for_calculate_tax!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -251,6 +253,7 @@ default_imp_for_session_update!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -325,6 +328,7 @@ default_imp_for_post_session_tokens!( connectors::Boku, connectors::Billwerk, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -398,6 +402,7 @@ default_imp_for_complete_authorize!( connectors::Bitpay, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Datatrans, @@ -463,6 +468,7 @@ default_imp_for_incremental_authorization!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Datatrans, @@ -536,6 +542,7 @@ default_imp_for_create_customer!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -608,6 +615,7 @@ default_imp_for_connector_redirect_response!( connectors::Bamboraapac, connectors::Bankofamerica, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -675,6 +683,7 @@ default_imp_for_pre_processing_steps!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Datatrans, @@ -746,6 +755,7 @@ default_imp_for_post_processing_steps!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -821,6 +831,7 @@ default_imp_for_approve!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -896,6 +907,7 @@ default_imp_for_reject!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -971,6 +983,7 @@ default_imp_for_webhook_source_verification!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1047,6 +1060,7 @@ default_imp_for_accept_dispute!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1122,6 +1136,7 @@ default_imp_for_submit_evidence!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1197,6 +1212,7 @@ default_imp_for_defend_dispute!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1281,6 +1297,7 @@ default_imp_for_file_upload!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1349,6 +1366,7 @@ default_imp_for_payouts!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Cryptopay, connectors::Datatrans, connectors::Coinbase, @@ -1424,6 +1442,7 @@ default_imp_for_payouts_create!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1501,6 +1520,7 @@ default_imp_for_payouts_retrieve!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1578,6 +1598,7 @@ default_imp_for_payouts_eligibility!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1655,6 +1676,7 @@ default_imp_for_payouts_fulfill!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Datatrans, @@ -1731,6 +1753,7 @@ default_imp_for_payouts_cancel!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1808,6 +1831,7 @@ default_imp_for_payouts_quote!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1885,6 +1909,7 @@ default_imp_for_payouts_recipient!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -1962,6 +1987,7 @@ default_imp_for_payouts_recipient_account!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -2039,6 +2065,7 @@ default_imp_for_frm_sale!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -2116,6 +2143,7 @@ default_imp_for_frm_checkout!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -2193,6 +2221,7 @@ default_imp_for_frm_transaction!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -2270,6 +2299,7 @@ default_imp_for_frm_fulfillment!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -2347,6 +2377,7 @@ default_imp_for_frm_record_return!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Cybersource, @@ -2421,6 +2452,7 @@ default_imp_for_revoking_mandates!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::Datatrans, @@ -2494,6 +2526,7 @@ default_imp_for_uas_pre_authentication!( connectors::Bitpay, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -2567,6 +2600,7 @@ default_imp_for_uas_post_authentication!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rs index 485ff86d72..9f0b319bfa 100644 --- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs +++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs @@ -215,6 +215,7 @@ default_imp_for_new_connector_integration_payment!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -291,6 +292,7 @@ default_imp_for_new_connector_integration_refund!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -362,6 +364,7 @@ default_imp_for_new_connector_integration_connector_access_token!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -439,6 +442,7 @@ default_imp_for_new_connector_integration_accept_dispute!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -514,6 +518,7 @@ default_imp_for_new_connector_integration_submit_evidence!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -589,6 +594,7 @@ default_imp_for_new_connector_integration_defend_dispute!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -675,6 +681,7 @@ default_imp_for_new_connector_integration_file_upload!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -753,6 +760,7 @@ default_imp_for_new_connector_integration_payouts_create!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -831,6 +839,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -909,6 +918,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -987,6 +997,7 @@ default_imp_for_new_connector_integration_payouts_cancel!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1065,6 +1076,7 @@ default_imp_for_new_connector_integration_payouts_quote!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1143,6 +1155,7 @@ default_imp_for_new_connector_integration_payouts_recipient!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1221,6 +1234,7 @@ default_imp_for_new_connector_integration_payouts_sync!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1299,6 +1313,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1375,6 +1390,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1453,6 +1469,7 @@ default_imp_for_new_connector_integration_frm_sale!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1531,6 +1548,7 @@ default_imp_for_new_connector_integration_frm_checkout!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1609,6 +1627,7 @@ default_imp_for_new_connector_integration_frm_transaction!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1687,6 +1706,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1765,6 +1785,7 @@ default_imp_for_new_connector_integration_frm_record_return!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, @@ -1840,6 +1861,7 @@ default_imp_for_new_connector_integration_revoking_mandates!( connectors::Bluesnap, connectors::Boku, connectors::Cashtocode, + connectors::Chargebee, connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, diff --git a/crates/hyperswitch_interfaces/src/configs.rs b/crates/hyperswitch_interfaces/src/configs.rs index 4a3b99636d..efd41aaa4a 100644 --- a/crates/hyperswitch_interfaces/src/configs.rs +++ b/crates/hyperswitch_interfaces/src/configs.rs @@ -24,6 +24,7 @@ pub struct Connectors { pub boku: ConnectorParams, pub braintree: ConnectorParams, pub cashtocode: ConnectorParams, + pub chargebee: ConnectorParams, pub checkout: ConnectorParams, pub coinbase: ConnectorParams, pub cryptopay: ConnectorParams, diff --git a/crates/router/src/connector.rs b/crates/router/src/connector.rs index 0bd9190f11..c926401107 100644 --- a/crates/router/src/connector.rs +++ b/crates/router/src/connector.rs @@ -36,8 +36,8 @@ pub use hyperswitch_connectors::connectors::{ airwallex, airwallex::Airwallex, amazonpay, amazonpay::Amazonpay, bambora, bambora::Bambora, bamboraapac, bamboraapac::Bamboraapac, bankofamerica, bankofamerica::Bankofamerica, billwerk, billwerk::Billwerk, bitpay, bitpay::Bitpay, bluesnap, bluesnap::Bluesnap, boku, boku::Boku, - cashtocode, cashtocode::Cashtocode, coinbase, coinbase::Coinbase, cryptopay, - cryptopay::Cryptopay, ctp_mastercard, ctp_mastercard::CtpMastercard, cybersource, + cashtocode, cashtocode::Cashtocode, chargebee::Chargebee, coinbase, coinbase::Coinbase, + cryptopay, cryptopay::Cryptopay, ctp_mastercard, ctp_mastercard::CtpMastercard, cybersource, cybersource::Cybersource, datatrans, datatrans::Datatrans, deutschebank, deutschebank::Deutschebank, digitalvirgo, digitalvirgo::Digitalvirgo, dlocal, dlocal::Dlocal, elavon, elavon::Elavon, fiserv, fiserv::Fiserv, fiservemea, fiservemea::Fiservemea, fiuu, diff --git a/crates/router/src/core/payments/connector_integration_v2_impls.rs b/crates/router/src/core/payments/connector_integration_v2_impls.rs index 28febe8b0b..03b1ad0340 100644 --- a/crates/router/src/core/payments/connector_integration_v2_impls.rs +++ b/crates/router/src/core/payments/connector_integration_v2_impls.rs @@ -1041,6 +1041,7 @@ default_imp_for_new_connector_integration_payouts!( connector::Boku, connector::Braintree, connector::Cashtocode, + connector::Chargebee, connector::Checkout, connector::Cryptopay, connector::Coinbase, @@ -1578,6 +1579,7 @@ default_imp_for_new_connector_integration_frm!( connector::Boku, connector::Braintree, connector::Cashtocode, + connector::Chargebee, connector::Checkout, connector::Cryptopay, connector::Coinbase, @@ -1997,6 +1999,7 @@ default_imp_for_new_connector_integration_connector_authentication!( connector::Boku, connector::Braintree, connector::Cashtocode, + connector::Chargebee, connector::Checkout, connector::Cryptopay, connector::Coinbase, diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs index 9ce3ad6c02..459d8a50a3 100644 --- a/crates/router/src/core/payments/flows.rs +++ b/crates/router/src/core/payments/flows.rs @@ -431,6 +431,7 @@ default_imp_for_connector_request_id!( connector::Boku, connector::Braintree, connector::Cashtocode, + connector::Chargebee, connector::Checkout, connector::Coinbase, connector::Cryptopay, @@ -1521,6 +1522,7 @@ default_imp_for_fraud_check!( connector::Boku, connector::Braintree, connector::Cashtocode, + connector::Chargebee, connector::Checkout, connector::Cryptopay, connector::Cybersource, @@ -2110,6 +2112,7 @@ default_imp_for_connector_authentication!( connector::Boku, connector::Braintree, connector::Cashtocode, + connector::Chargebee, connector::Checkout, connector::Cryptopay, connector::Coinbase, diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs index 243b6116e7..114a877d26 100644 --- a/crates/router/src/types/api.rs +++ b/crates/router/src/types/api.rs @@ -359,6 +359,7 @@ impl ConnectorData { Ok(ConnectorEnum::Old(Box::new(connector::Braintree::new()))) } enums::Connector::Cashtocode => { + // enums::Connector::Chargebee => Ok(ConnectorEnum::Old(Box::new(connector::Chargebee))), Ok(ConnectorEnum::Old(Box::new(connector::Cashtocode::new()))) } enums::Connector::Checkout => { diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index 06682f596e..2348fae72a 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -225,6 +225,7 @@ impl ForeignTryFrom for common_enums::RoutableConnectors { api_enums::Connector::Boku => Self::Boku, api_enums::Connector::Braintree => Self::Braintree, api_enums::Connector::Cashtocode => Self::Cashtocode, + // api_enums::Connector::Chargebee => Self::Chargebee, api_enums::Connector::Checkout => Self::Checkout, api_enums::Connector::Coinbase => Self::Coinbase, api_enums::Connector::Cryptopay => Self::Cryptopay, diff --git a/crates/router/tests/connectors/chargebee.rs b/crates/router/tests/connectors/chargebee.rs new file mode 100644 index 0000000000..33d1c8f18d --- /dev/null +++ b/crates/router/tests/connectors/chargebee.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 ChargebeeTest; +impl ConnectorActions for ChargebeeTest {} +impl utils::Connector for ChargebeeTest { + fn get_data(&self) -> api::ConnectorData { + use router::connector::Chargebee; + utils::construct_connector_data_old( + Box::new(Chargebee::new()), + types::Connector::Plaid, + api::GetToken::Connector, + None, + ) + } + + fn get_auth_token(&self) -> types::ConnectorAuthType { + utils::to_connector_auth_type( + connector_auth::ConnectorAuthentication::new() + .chargebee + .expect("Missing connector authentication configuration") + .into(), + ) + } + + fn get_name(&self) -> String { + "chargebee".to_string() + } +} + +static CONNECTOR: ChargebeeTest = ChargebeeTest {}; + +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/main.rs b/crates/router/tests/connectors/main.rs index 31ceb1a724..19f0b9f9b2 100644 --- a/crates/router/tests/connectors/main.rs +++ b/crates/router/tests/connectors/main.rs @@ -22,6 +22,7 @@ mod bitpay; mod bluesnap; mod boku; mod cashtocode; +mod chargebee; mod checkout; mod coinbase; mod cryptopay; diff --git a/crates/router/tests/connectors/sample_auth.toml b/crates/router/tests/connectors/sample_auth.toml index 10db11bb3b..44c178f3a3 100644 --- a/crates/router/tests/connectors/sample_auth.toml +++ b/crates/router/tests/connectors/sample_auth.toml @@ -304,4 +304,7 @@ api_key="API Key" api_key="API Key" [unified_authentication_service] -api_key="API Key" \ No newline at end of file +api_key="API Key" + +[chargebee] +api_key= "API Key" \ No newline at end of file diff --git a/crates/test_utils/src/connector_auth.rs b/crates/test_utils/src/connector_auth.rs index 7b6a1ba6b7..3b02661c5c 100644 --- a/crates/test_utils/src/connector_auth.rs +++ b/crates/test_utils/src/connector_auth.rs @@ -27,6 +27,7 @@ pub struct ConnectorAuthentication { pub bluesnap: Option, pub boku: Option, pub cashtocode: Option, + pub chargebee: Option, pub checkout: Option, pub coinbase: Option, pub cryptopay: Option, diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml index 61f5debb4d..ac90dc8819 100644 --- a/loadtest/config/development.toml +++ b/loadtest/config/development.toml @@ -91,6 +91,7 @@ bluesnap.secondary_base_url = "https://sandpay.bluesnap.com/" boku.base_url = "https://country-api4-stage.boku.com" braintree.base_url = "https://payments.sandbox.braintree-api.com/graphql" cashtocode.base_url = "https://cluster05.api-test.cashtocode.com" +chargebee.base_url = "https://$.chargebee.com/api/" checkout.base_url = "https://api.sandbox.checkout.com/" coinbase.base_url = "https://api.commerce.coinbase.com" cryptopay.base_url = "https://business-sandbox.cryptopay.me" diff --git a/scripts/add_connector.sh b/scripts/add_connector.sh index 108e9d8826..32d24fe47e 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 inespay 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 redsys shift4 square stax stripe taxjar threedsecureio thunes trustpay tsys unified_authentication_service volt wellsfargo wellsfargopayout wise worldline worldpay xendit zsl "$1") + connectors=(aci adyen adyenplatform airwallex amazonpay applepay authorizedotnet bambora bamboraapac bankofamerica billwerk bitpay bluesnap boku braintree cashtocode chargebee checkout coinbase cryptopay cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector ebanx elavon fiserv fiservemea fiuu forte globalpay globepay gocardless gpayments helcim iatapay inespay 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 redsys shift4 square stax stripe taxjar threedsecureio thunes trustpay tsys unified_authentication_service 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