From 110beaff9a809f30a704b5ef9cb7dc75cc31a7bf Mon Sep 17 00:00:00 2001 From: CHALLA NISHANTH BABU <115225644+NISHANTH1221@users.noreply.github.com> Date: Tue, 22 Jul 2025 00:38:33 +0530 Subject: [PATCH] refactor(payments): fetch payment method information in attempts list api v2 and add custom billing connector template (#8681) Co-authored-by: Nishanth Challa Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> --- api-reference/v1/openapi_spec_v1.json | 2 + api-reference/v2/openapi_spec_v2.json | 10 + config/docker_compose.toml | 1 + crates/api_models/src/enums.rs | 1 + crates/api_models/src/payments.rs | 3 + crates/common_enums/src/connector_enums.rs | 5 + crates/connector_configs/src/connector.rs | 2 + .../hyperswitch_connectors/src/connectors.rs | 11 +- .../src/connectors/custombilling.rs | 579 ++++++++++++++++++ .../connectors/custombilling/transformers.rs | 232 +++++++ .../src/default_implementations.rs | 50 ++ .../src/default_implementations_v2.rs | 26 + .../src/connector_endpoints.rs | 1 + crates/router/src/connector.rs | 61 +- .../router/src/core/connector_validation.rs | 1 + .../router/src/core/payments/transformers.rs | 7 + .../router/src/types/api/connector_mapping.rs | 3 + .../src/types/connector_transformers.rs | 1 + .../router/tests/connectors/custombilling.rs | 402 ++++++++++++ loadtest/config/development.toml | 1 + scripts/add_connector.sh | 2 +- 21 files changed, 1365 insertions(+), 36 deletions(-) create mode 100644 crates/hyperswitch_connectors/src/connectors/custombilling.rs create mode 100644 crates/hyperswitch_connectors/src/connectors/custombilling/transformers.rs create mode 100644 crates/router/tests/connectors/custombilling.rs diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json index de49d53ada..36a2896008 100644 --- a/api-reference/v1/openapi_spec_v1.json +++ b/api-reference/v1/openapi_spec_v1.json @@ -11089,6 +11089,7 @@ "checkout", "coinbase", "coingate", + "custombilling", "cryptopay", "ctp_mastercard", "ctp_visa", @@ -28183,6 +28184,7 @@ "cashtocode", "celero", "chargebee", + "custombilling", "checkout", "coinbase", "coingate", diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json index 266aa6cec9..671658dc29 100644 --- a/api-reference/v2/openapi_spec_v2.json +++ b/api-reference/v2/openapi_spec_v2.json @@ -8153,6 +8153,7 @@ "checkout", "coinbase", "coingate", + "custombilling", "cryptopay", "ctp_mastercard", "ctp_visa", @@ -15740,6 +15741,14 @@ } ], "nullable": true + }, + "payment_method_data": { + "allOf": [ + { + "$ref": "#/components/schemas/PaymentMethodDataResponseWithBilling" + } + ], + "nullable": true } } }, @@ -22738,6 +22747,7 @@ "cashtocode", "celero", "chargebee", + "custombilling", "checkout", "coinbase", "coingate", diff --git a/config/docker_compose.toml b/config/docker_compose.toml index 2e37da5728..faf1d25e3c 100644 --- a/config/docker_compose.toml +++ b/config/docker_compose.toml @@ -272,6 +272,7 @@ cards = [ "coingate", "cryptopay", "ctp_visa", + "custombilling", "cybersource", "datatrans", "deutschebank", diff --git a/crates/api_models/src/enums.rs b/crates/api_models/src/enums.rs index cad510b26d..ac0cd70735 100644 --- a/crates/api_models/src/enums.rs +++ b/crates/api_models/src/enums.rs @@ -166,6 +166,7 @@ pub enum BillingConnectors { Chargebee, Recurly, Stripebilling, + Custombilling, #[cfg(feature = "dummy_connector")] DummyBillingConnector, } diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index d1e0403752..3d91e73406 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -1629,6 +1629,9 @@ pub struct PaymentAttemptResponse { /// Additional data that might be required by hyperswitch, to enable some specific features. pub feature_metadata: Option, + + /// The payment method information for the payment attempt + pub payment_method_data: Option, } #[cfg(feature = "v2")] diff --git a/crates/common_enums/src/connector_enums.rs b/crates/common_enums/src/connector_enums.rs index 41563d56f2..cb5195925c 100644 --- a/crates/common_enums/src/connector_enums.rs +++ b/crates/common_enums/src/connector_enums.rs @@ -77,6 +77,7 @@ pub enum RoutableConnectors { Cashtocode, Celero, Chargebee, + Custombilling, // Checkbook, Checkout, Coinbase, @@ -241,6 +242,7 @@ pub enum Connector { Checkout, Coinbase, Coingate, + Custombilling, Cryptopay, CtpMastercard, CtpVisa, @@ -428,6 +430,7 @@ impl Connector { | Self::Coinbase | Self::Coingate | Self::Cryptopay + | Self::Custombilling | Self::Deutschebank | Self::Digitalvirgo | Self::Dlocal @@ -589,6 +592,7 @@ impl From for Connector { RoutableConnectors::Cashtocode => Self::Cashtocode, RoutableConnectors::Celero => Self::Celero, RoutableConnectors::Chargebee => Self::Chargebee, + RoutableConnectors::Custombilling => Self::Custombilling, // RoutableConnectors::Checkbook => Self::Checkbook, RoutableConnectors::Checkout => Self::Checkout, RoutableConnectors::Coinbase => Self::Coinbase, @@ -717,6 +721,7 @@ impl TryFrom for RoutableConnectors { Connector::Coinbase => Ok(Self::Coinbase), Connector::Coingate => Ok(Self::Coingate), Connector::Cryptopay => Ok(Self::Cryptopay), + Connector::Custombilling => Ok(Self::Custombilling), Connector::Cybersource => Ok(Self::Cybersource), Connector::Datatrans => Ok(Self::Datatrans), Connector::Deutschebank => Ok(Self::Deutschebank), diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs index f69efb673b..fdc85a1fbc 100644 --- a/crates/connector_configs/src/connector.rs +++ b/crates/connector_configs/src/connector.rs @@ -194,6 +194,7 @@ pub struct ConnectorConfig { pub cashtocode: Option, pub celero: Option, pub chargebee: Option, + pub custombilling: Option, pub checkbook: Option, pub checkout: Option, pub coinbase: Option, @@ -393,6 +394,7 @@ impl ConnectorConfig { Connector::Coingate => Ok(connector_data.coingate), Connector::Cryptopay => Ok(connector_data.cryptopay), Connector::CtpVisa => Ok(connector_data.ctp_visa), + Connector::Custombilling => Ok(connector_data.custombilling), Connector::Cybersource => Ok(connector_data.cybersource), #[cfg(feature = "dummy_connector")] Connector::DummyBillingConnector => Ok(connector_data.dummy_connector), diff --git a/crates/hyperswitch_connectors/src/connectors.rs b/crates/hyperswitch_connectors/src/connectors.rs index f560a84cd8..6815f288d0 100644 --- a/crates/hyperswitch_connectors/src/connectors.rs +++ b/crates/hyperswitch_connectors/src/connectors.rs @@ -26,6 +26,7 @@ pub mod coinbase; pub mod coingate; pub mod cryptopay; pub mod ctp_mastercard; +pub mod custombilling; pub mod cybersource; pub mod datatrans; pub mod deutschebank; @@ -124,11 +125,11 @@ pub use self::{ blackhawknetwork::Blackhawknetwork, bluesnap::Bluesnap, boku::Boku, braintree::Braintree, cashtocode::Cashtocode, celero::Celero, chargebee::Chargebee, checkbook::Checkbook, checkout::Checkout, coinbase::Coinbase, coingate::Coingate, cryptopay::Cryptopay, - ctp_mastercard::CtpMastercard, cybersource::Cybersource, datatrans::Datatrans, - deutschebank::Deutschebank, digitalvirgo::Digitalvirgo, dlocal::Dlocal, dwolla::Dwolla, - ebanx::Ebanx, elavon::Elavon, facilitapay::Facilitapay, fiserv::Fiserv, fiservemea::Fiservemea, - fiuu::Fiuu, forte::Forte, getnet::Getnet, globalpay::Globalpay, globepay::Globepay, - gocardless::Gocardless, gpayments::Gpayments, helcim::Helcim, hipay::Hipay, + ctp_mastercard::CtpMastercard, custombilling::Custombilling, cybersource::Cybersource, + datatrans::Datatrans, deutschebank::Deutschebank, digitalvirgo::Digitalvirgo, dlocal::Dlocal, + dwolla::Dwolla, ebanx::Ebanx, elavon::Elavon, facilitapay::Facilitapay, fiserv::Fiserv, + fiservemea::Fiservemea, fiuu::Fiuu, forte::Forte, getnet::Getnet, globalpay::Globalpay, + globepay::Globepay, gocardless::Gocardless, gpayments::Gpayments, helcim::Helcim, hipay::Hipay, hyperswitch_vault::HyperswitchVault, iatapay::Iatapay, inespay::Inespay, itaubank::Itaubank, jpmorgan::Jpmorgan, juspaythreedsserver::Juspaythreedsserver, klarna::Klarna, mifinity::Mifinity, mollie::Mollie, moneris::Moneris, multisafepay::Multisafepay, diff --git a/crates/hyperswitch_connectors/src/connectors/custombilling.rs b/crates/hyperswitch_connectors/src/connectors/custombilling.rs new file mode 100644 index 0000000000..85904369e5 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/custombilling.rs @@ -0,0 +1,579 @@ +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 custombilling; + +use crate::{constants::headers, types::ResponseRouterData, utils}; + +#[derive(Clone)] +pub struct Custombilling { + amount_converter: &'static (dyn AmountConvertor + Sync), +} + +impl Custombilling { + pub fn new() -> &'static Self { + &Self { + amount_converter: &StringMinorUnitForConnector, + } + } +} + +impl api::Payment for Custombilling {} +impl api::PaymentSession for Custombilling {} +impl api::ConnectorAccessToken for Custombilling {} +impl api::MandateSetup for Custombilling {} +impl api::PaymentAuthorize for Custombilling {} +impl api::PaymentSync for Custombilling {} +impl api::PaymentCapture for Custombilling {} +impl api::PaymentVoid for Custombilling {} +impl api::Refund for Custombilling {} +impl api::RefundExecute for Custombilling {} +impl api::RefundSync for Custombilling {} +impl api::PaymentToken for Custombilling {} + +impl ConnectorIntegration + for Custombilling +{ + // Not Implemented (R) +} + +impl ConnectorCommonExt for Custombilling +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 Custombilling { + fn id(&self) -> &'static str { + "custombilling" + } + + fn get_currency_unit(&self) -> api::CurrencyUnit { + api::CurrencyUnit::Minor + // 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 { + "" + } + + fn get_auth_header( + &self, + auth_type: &ConnectorAuthType, + ) -> CustomResult)>, errors::ConnectorError> { + let auth = custombilling::CustombillingAuthType::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: custombilling::CustombillingErrorResponse = res + .response + .parse_struct("CustombillingErrorResponse") + .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + + event_builder.map(|i| i.set_response_body(&response)); + router_env::logger::info!(connector_response=?response); + + Ok(ErrorResponse { + status_code: res.status_code, + code: response.code, + message: response.message, + reason: response.reason, + attempt_status: None, + connector_transaction_id: None, + network_advice_code: None, + network_decline_code: None, + network_error_message: None, + }) + } +} + +impl ConnectorValidation for Custombilling { + //TODO: implement functions when support enabled +} + +impl ConnectorIntegration for Custombilling { + //TODO: implement sessions flow +} + +impl ConnectorIntegration for Custombilling {} + +impl ConnectorIntegration + for Custombilling +{ +} + +impl ConnectorIntegration + for Custombilling +{ + 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 = custombilling::CustombillingRouterData::from((amount, req)); + let connector_req = + custombilling::CustombillingPaymentsRequest::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: custombilling::CustombillingPaymentsResponse = res + .response + .parse_struct("Custombilling 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 Custombilling { + 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: custombilling::CustombillingPaymentsResponse = res + .response + .parse_struct("custombilling 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 Custombilling { + 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: custombilling::CustombillingPaymentsResponse = res + .response + .parse_struct("Custombilling 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 Custombilling {} + +impl ConnectorIntegration for Custombilling { + 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 = + custombilling::CustombillingRouterData::from((refund_amount, req)); + let connector_req = + custombilling::CustombillingRefundRequest::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: custombilling::RefundResponse = res + .response + .parse_struct("custombilling 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 Custombilling { + 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: custombilling::RefundResponse = res + .response + .parse_struct("custombilling 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 Custombilling { + 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 Custombilling {} diff --git a/crates/hyperswitch_connectors/src/connectors/custombilling/transformers.rs b/crates/hyperswitch_connectors/src/connectors/custombilling/transformers.rs new file mode 100644 index 0000000000..bb8e8f83e3 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/custombilling/transformers.rs @@ -0,0 +1,232 @@ +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 CustombillingRouterData { + 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 CustombillingRouterData { + 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 CustombillingPaymentsRequest { + amount: StringMinorUnit, + card: CustombillingCard, +} + +#[derive(Default, Debug, Serialize, Eq, PartialEq)] +pub struct CustombillingCard { + number: cards::CardNumber, + expiry_month: Secret, + expiry_year: Secret, + cvc: Secret, + complete: bool, +} + +impl TryFrom<&CustombillingRouterData<&PaymentsAuthorizeRouterData>> + for CustombillingPaymentsRequest +{ + type Error = error_stack::Report; + fn try_from( + item: &CustombillingRouterData<&PaymentsAuthorizeRouterData>, + ) -> Result { + match item.router_data.request.payment_method_data.clone() { + PaymentMethodData::Card(req_card) => { + let card = CustombillingCard { + 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 CustombillingAuthType { + pub(super) api_key: Secret, +} + +impl TryFrom<&ConnectorAuthType> for CustombillingAuthType { + 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 CustombillingPaymentStatus { + Succeeded, + Failed, + #[default] + Processing, +} + +impl From for common_enums::AttemptStatus { + fn from(item: CustombillingPaymentStatus) -> Self { + match item { + CustombillingPaymentStatus::Succeeded => Self::Charged, + CustombillingPaymentStatus::Failed => Self::Failure, + CustombillingPaymentStatus::Processing => Self::Authorizing, + } + } +} + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct CustombillingPaymentsResponse { + status: CustombillingPaymentStatus, + id: String, +} + +impl TryFrom> + for RouterData +{ + type Error = error_stack::Report; + fn try_from( + item: ResponseRouterData, + ) -> Result { + Ok(Self { + status: common_enums::AttemptStatus::from(item.response.status), + response: Ok(PaymentsResponseData::TransactionResponse { + resource_id: ResponseId::ConnectorTransactionId(item.response.id), + redirection_data: Box::new(None), + mandate_reference: Box::new(None), + connector_metadata: None, + network_txn_id: None, + connector_response_reference_id: None, + incremental_authorization_allowed: None, + charges: None, + }), + ..item.data + }) + } +} + +//TODO: Fill the struct with respective fields +// REFUND : +// Type definition for RefundRequest +#[derive(Default, Debug, Serialize)] +pub struct CustombillingRefundRequest { + pub amount: StringMinorUnit, +} + +impl TryFrom<&CustombillingRouterData<&RefundsRouterData>> for CustombillingRefundRequest { + type Error = error_stack::Report; + fn try_from( + item: &CustombillingRouterData<&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 CustombillingErrorResponse { + 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 2e585b1c09..16bb27e06b 100644 --- a/crates/hyperswitch_connectors/src/default_implementations.rs +++ b/crates/hyperswitch_connectors/src/default_implementations.rs @@ -169,6 +169,7 @@ default_imp_for_authorize_session_token!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -298,6 +299,7 @@ default_imp_for_calculate_tax!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -428,6 +430,7 @@ default_imp_for_session_update!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Digitalvirgo, @@ -558,6 +561,7 @@ default_imp_for_post_session_tokens!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Digitalvirgo, @@ -687,6 +691,7 @@ default_imp_for_create_order!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Digitalvirgo, @@ -817,6 +822,7 @@ default_imp_for_update_metadata!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Digitalvirgo, @@ -946,6 +952,7 @@ default_imp_for_complete_authorize!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Datatrans, connectors::Dlocal, connectors::Dwolla, @@ -1060,6 +1067,7 @@ default_imp_for_incremental_authorization!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Datatrans, connectors::Deutschebank, connectors::Digitalvirgo, @@ -1189,6 +1197,7 @@ default_imp_for_create_customer!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1312,6 +1321,7 @@ default_imp_for_connector_redirect_response!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1427,6 +1437,7 @@ default_imp_for_pre_processing_steps!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Datatrans, connectors::Deutschebank, connectors::Digitalvirgo, @@ -1547,6 +1558,7 @@ default_imp_for_post_processing_steps!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1678,6 +1690,7 @@ default_imp_for_approve!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1810,6 +1823,7 @@ default_imp_for_reject!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1942,6 +1956,7 @@ default_imp_for_webhook_source_verification!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2072,6 +2087,7 @@ default_imp_for_accept_dispute!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2202,6 +2218,7 @@ default_imp_for_submit_evidence!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2331,6 +2348,7 @@ default_imp_for_defend_dispute!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2470,6 +2488,7 @@ default_imp_for_file_upload!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2593,6 +2612,7 @@ default_imp_for_payouts!( connectors::Datatrans, connectors::Coinbase, connectors::Coingate, + connectors::Custombilling, connectors::Deutschebank, connectors::Digitalvirgo, connectors::Dlocal, @@ -2717,6 +2737,7 @@ default_imp_for_payouts_create!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2846,6 +2867,7 @@ default_imp_for_payouts_retrieve!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2977,6 +2999,7 @@ default_imp_for_payouts_eligibility!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -3106,6 +3129,7 @@ default_imp_for_payouts_fulfill!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Datatrans, connectors::Deutschebank, connectors::Digitalvirgo, @@ -3232,6 +3256,7 @@ default_imp_for_payouts_cancel!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -3362,6 +3387,7 @@ default_imp_for_payouts_quote!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -3493,6 +3519,7 @@ default_imp_for_payouts_recipient!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -3623,6 +3650,7 @@ default_imp_for_payouts_recipient_account!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -3755,6 +3783,7 @@ default_imp_for_frm_sale!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -3887,6 +3916,7 @@ default_imp_for_frm_checkout!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -4019,6 +4049,7 @@ default_imp_for_frm_transaction!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -4151,6 +4182,7 @@ default_imp_for_frm_fulfillment!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -4283,6 +4315,7 @@ default_imp_for_frm_record_return!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -4411,6 +4444,7 @@ default_imp_for_revoking_mandates!( connectors::Coinbase, connectors::Coingate, connectors::Cryptopay, + connectors::Custombilling, connectors::Datatrans, connectors::Deutschebank, connectors::Digitalvirgo, @@ -4540,6 +4574,7 @@ default_imp_for_uas_pre_authentication!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -4669,6 +4704,7 @@ default_imp_for_uas_post_authentication!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -4799,6 +4835,7 @@ default_imp_for_uas_authentication_confirmation!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -4921,6 +4958,7 @@ default_imp_for_connector_request_id!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -5045,6 +5083,7 @@ default_imp_for_fraud_check!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -5199,6 +5238,7 @@ default_imp_for_connector_authentication!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -5326,6 +5366,7 @@ default_imp_for_uas_authentication!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -5448,6 +5489,7 @@ default_imp_for_revenue_recovery!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -5581,6 +5623,7 @@ default_imp_for_billing_connector_payment_sync!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -5712,6 +5755,7 @@ default_imp_for_revenue_recovery_record_back!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -5843,6 +5887,7 @@ default_imp_for_billing_connector_invoice_sync!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -5968,6 +6013,7 @@ default_imp_for_external_vault!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -6099,6 +6145,7 @@ default_imp_for_external_vault_insert!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -6230,6 +6277,7 @@ default_imp_for_external_vault_retrieve!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -6361,6 +6409,7 @@ default_imp_for_external_vault_delete!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -6492,6 +6541,7 @@ default_imp_for_external_vault_create!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rs index 7e8ddbee35..42a500b8e9 100644 --- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs +++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs @@ -275,6 +275,7 @@ default_imp_for_new_connector_integration_payment!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -407,6 +408,7 @@ default_imp_for_new_connector_integration_refund!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -534,6 +536,7 @@ default_imp_for_new_connector_integration_connector_access_token!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -667,6 +670,7 @@ default_imp_for_new_connector_integration_accept_dispute!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Datatrans, connectors::Deutschebank, connectors::Digitalvirgo, @@ -798,6 +802,7 @@ default_imp_for_new_connector_integration_submit_evidence!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Datatrans, connectors::Deutschebank, connectors::Digitalvirgo, @@ -929,6 +934,7 @@ default_imp_for_new_connector_integration_defend_dispute!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1071,6 +1077,7 @@ default_imp_for_new_connector_integration_file_upload!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1205,6 +1212,7 @@ default_imp_for_new_connector_integration_payouts_create!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1339,6 +1347,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1473,6 +1482,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1607,6 +1617,7 @@ default_imp_for_new_connector_integration_payouts_cancel!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1741,6 +1752,7 @@ default_imp_for_new_connector_integration_payouts_quote!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -1875,6 +1887,7 @@ default_imp_for_new_connector_integration_payouts_recipient!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2009,6 +2022,7 @@ default_imp_for_new_connector_integration_payouts_sync!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2143,6 +2157,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2275,6 +2290,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2409,6 +2425,7 @@ default_imp_for_new_connector_integration_frm_sale!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2543,6 +2560,7 @@ default_imp_for_new_connector_integration_frm_checkout!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2677,6 +2695,7 @@ default_imp_for_new_connector_integration_frm_transaction!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2811,6 +2830,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -2945,6 +2965,7 @@ default_imp_for_new_connector_integration_frm_record_return!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -3076,6 +3097,7 @@ default_imp_for_new_connector_integration_revoking_mandates!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, @@ -3192,6 +3214,7 @@ default_imp_for_new_connector_integration_frm!( connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Datatrans, connectors::Deutschebank, connectors::Digitalvirgo, @@ -3323,6 +3346,7 @@ default_imp_for_new_connector_integration_connector_authentication!( connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Datatrans, connectors::Deutschebank, connectors::Digitalvirgo, @@ -3443,6 +3467,7 @@ default_imp_for_new_connector_integration_revenue_recovery!( connectors::Coinbase, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Datatrans, connectors::Deutschebank, connectors::Digitalvirgo, @@ -3582,6 +3607,7 @@ default_imp_for_new_connector_integration_external_vault!( connectors::Coingate, connectors::Cryptopay, connectors::CtpMastercard, + connectors::Custombilling, connectors::Cybersource, connectors::Datatrans, connectors::Deutschebank, diff --git a/crates/hyperswitch_domain_models/src/connector_endpoints.rs b/crates/hyperswitch_domain_models/src/connector_endpoints.rs index 6d2b63bf9b..63c00ed2e3 100644 --- a/crates/hyperswitch_domain_models/src/connector_endpoints.rs +++ b/crates/hyperswitch_domain_models/src/connector_endpoints.rs @@ -41,6 +41,7 @@ pub struct Connectors { pub cryptopay: ConnectorParams, pub ctp_mastercard: NoParams, pub ctp_visa: NoParams, + pub custombilling: NoParams, pub cybersource: ConnectorParams, pub datatrans: ConnectorParamsWithSecondaryBaseUrl, pub deutschebank: ConnectorParams, diff --git a/crates/router/src/connector.rs b/crates/router/src/connector.rs index 581ba5fb69..189108d2cb 100644 --- a/crates/router/src/connector.rs +++ b/crates/router/src/connector.rs @@ -13,34 +13,35 @@ pub use hyperswitch_connectors::connectors::{ boku::Boku, braintree, braintree::Braintree, cashtocode, cashtocode::Cashtocode, celero, celero::Celero, chargebee, chargebee::Chargebee, checkbook, checkbook::Checkbook, checkout, checkout::Checkout, coinbase, coinbase::Coinbase, coingate, coingate::Coingate, cryptopay, - cryptopay::Cryptopay, ctp_mastercard, ctp_mastercard::CtpMastercard, cybersource, - cybersource::Cybersource, datatrans, datatrans::Datatrans, deutschebank, - deutschebank::Deutschebank, digitalvirgo, digitalvirgo::Digitalvirgo, dlocal, dlocal::Dlocal, - dwolla, dwolla::Dwolla, ebanx, ebanx::Ebanx, elavon, elavon::Elavon, facilitapay, - facilitapay::Facilitapay, fiserv, fiserv::Fiserv, fiservemea, fiservemea::Fiservemea, fiuu, - fiuu::Fiuu, forte, forte::Forte, getnet, getnet::Getnet, globalpay, globalpay::Globalpay, - globepay, globepay::Globepay, gocardless, gocardless::Gocardless, gpayments, - gpayments::Gpayments, helcim, helcim::Helcim, hipay, hipay::Hipay, hyperswitch_vault, - hyperswitch_vault::HyperswitchVault, iatapay, iatapay::Iatapay, inespay, inespay::Inespay, - itaubank, itaubank::Itaubank, jpmorgan, jpmorgan::Jpmorgan, juspaythreedsserver, - juspaythreedsserver::Juspaythreedsserver, klarna, klarna::Klarna, mifinity, mifinity::Mifinity, - mollie, mollie::Mollie, moneris, moneris::Moneris, multisafepay, multisafepay::Multisafepay, - netcetera, netcetera::Netcetera, nexinets, nexinets::Nexinets, nexixpay, nexixpay::Nexixpay, - nmi, nmi::Nmi, nomupay, nomupay::Nomupay, noon, noon::Noon, nordea, nordea::Nordea, novalnet, - novalnet::Novalnet, nuvei, nuvei::Nuvei, opayo, opayo::Opayo, opennode, opennode::Opennode, - paybox, paybox::Paybox, payeezy, payeezy::Payeezy, payload, payload::Payload, payme, - payme::Payme, payone, payone::Payone, paypal, paypal::Paypal, paystack, paystack::Paystack, - payu, payu::Payu, placetopay, placetopay::Placetopay, plaid, plaid::Plaid, powertranz, - powertranz::Powertranz, prophetpay, prophetpay::Prophetpay, rapyd, rapyd::Rapyd, razorpay, - razorpay::Razorpay, recurly, recurly::Recurly, redsys, redsys::Redsys, riskified, - riskified::Riskified, santander, santander::Santander, shift4, shift4::Shift4, signifyd, - signifyd::Signifyd, silverflow, silverflow::Silverflow, square, square::Square, stax, - stax::Stax, stripe, stripe::Stripe, stripebilling, stripebilling::Stripebilling, taxjar, - taxjar::Taxjar, threedsecureio, threedsecureio::Threedsecureio, thunes, thunes::Thunes, - tokenio, tokenio::Tokenio, trustpay, trustpay::Trustpay, tsys, tsys::Tsys, - unified_authentication_service, unified_authentication_service::UnifiedAuthenticationService, - vgs, vgs::Vgs, volt, volt::Volt, wellsfargo, wellsfargo::Wellsfargo, wellsfargopayout, - wellsfargopayout::Wellsfargopayout, wise, wise::Wise, worldline, worldline::Worldline, - worldpay, worldpay::Worldpay, worldpayvantiv, worldpayvantiv::Worldpayvantiv, worldpayxml, - worldpayxml::Worldpayxml, xendit, xendit::Xendit, zen, zen::Zen, zsl, zsl::Zsl, + cryptopay::Cryptopay, ctp_mastercard, ctp_mastercard::CtpMastercard, custombilling, + custombilling::Custombilling, cybersource, cybersource::Cybersource, datatrans, + datatrans::Datatrans, deutschebank, deutschebank::Deutschebank, digitalvirgo, + digitalvirgo::Digitalvirgo, dlocal, dlocal::Dlocal, dwolla, dwolla::Dwolla, ebanx, + ebanx::Ebanx, elavon, elavon::Elavon, facilitapay, facilitapay::Facilitapay, fiserv, + fiserv::Fiserv, fiservemea, fiservemea::Fiservemea, fiuu, fiuu::Fiuu, forte, forte::Forte, + getnet, getnet::Getnet, globalpay, globalpay::Globalpay, globepay, globepay::Globepay, + gocardless, gocardless::Gocardless, gpayments, gpayments::Gpayments, helcim, helcim::Helcim, + hipay, hipay::Hipay, hyperswitch_vault, hyperswitch_vault::HyperswitchVault, iatapay, + iatapay::Iatapay, inespay, inespay::Inespay, itaubank, itaubank::Itaubank, jpmorgan, + jpmorgan::Jpmorgan, juspaythreedsserver, juspaythreedsserver::Juspaythreedsserver, klarna, + klarna::Klarna, mifinity, mifinity::Mifinity, mollie, mollie::Mollie, moneris, + moneris::Moneris, multisafepay, multisafepay::Multisafepay, netcetera, netcetera::Netcetera, + nexinets, nexinets::Nexinets, nexixpay, nexixpay::Nexixpay, nmi, nmi::Nmi, nomupay, + nomupay::Nomupay, noon, noon::Noon, nordea, nordea::Nordea, novalnet, novalnet::Novalnet, + nuvei, nuvei::Nuvei, opayo, opayo::Opayo, opennode, opennode::Opennode, paybox, paybox::Paybox, + payeezy, payeezy::Payeezy, payload, payload::Payload, payme, payme::Payme, payone, + payone::Payone, paypal, paypal::Paypal, paystack, paystack::Paystack, payu, payu::Payu, + placetopay, placetopay::Placetopay, plaid, plaid::Plaid, powertranz, powertranz::Powertranz, + prophetpay, prophetpay::Prophetpay, rapyd, rapyd::Rapyd, razorpay, razorpay::Razorpay, recurly, + recurly::Recurly, redsys, redsys::Redsys, riskified, riskified::Riskified, santander, + santander::Santander, shift4, shift4::Shift4, signifyd, signifyd::Signifyd, silverflow, + silverflow::Silverflow, square, square::Square, stax, stax::Stax, stripe, stripe::Stripe, + stripebilling, stripebilling::Stripebilling, taxjar, taxjar::Taxjar, threedsecureio, + threedsecureio::Threedsecureio, thunes, thunes::Thunes, tokenio, tokenio::Tokenio, trustpay, + trustpay::Trustpay, tsys, tsys::Tsys, unified_authentication_service, + unified_authentication_service::UnifiedAuthenticationService, vgs, vgs::Vgs, volt, volt::Volt, + wellsfargo, wellsfargo::Wellsfargo, wellsfargopayout, wellsfargopayout::Wellsfargopayout, wise, + wise::Wise, worldline, worldline::Worldline, worldpay, worldpay::Worldpay, worldpayvantiv, + worldpayvantiv::Worldpayvantiv, worldpayxml, worldpayxml::Worldpayxml, xendit, xendit::Xendit, + zen, zen::Zen, zsl, zsl::Zsl, }; diff --git a/crates/router/src/core/connector_validation.rs b/crates/router/src/core/connector_validation.rs index 6fb5a340ba..f04edb139f 100644 --- a/crates/router/src/core/connector_validation.rs +++ b/crates/router/src/core/connector_validation.rs @@ -171,6 +171,7 @@ impl ConnectorAuthTypeAndMetadataValidation<'_> { Ok(()) } api_enums::Connector::CtpMastercard => Ok(()), + api_enums::Connector::Custombilling => Ok(()), api_enums::Connector::CtpVisa => Ok(()), api_enums::Connector::Cybersource => { cybersource::transformers::CybersourceAuthType::try_from(self.auth_type)?; diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 6785e42998..1974fd3e42 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -5047,6 +5047,12 @@ impl ForeignFrom<&hyperswitch_domain_models::payments::payment_attempt::PaymentA fn foreign_from( attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt, ) -> Self { + let payment_method_data: Option< + api_models::payments::PaymentMethodDataResponseWithBilling, + > = attempt + .payment_method_data + .clone() + .and_then(|data| serde_json::from_value(data.expose().clone()).ok()); Self { id: attempt.get_id().to_owned(), status: attempt.status, @@ -5078,6 +5084,7 @@ impl ForeignFrom<&hyperswitch_domain_models::payments::payment_attempt::PaymentA .feature_metadata .as_ref() .map(api_models::payments::PaymentAttemptFeatureMetadata::foreign_from), + payment_method_data, } } } diff --git a/crates/router/src/types/api/connector_mapping.rs b/crates/router/src/types/api/connector_mapping.rs index 3dbb241622..e80d75a7ec 100644 --- a/crates/router/src/types/api/connector_mapping.rs +++ b/crates/router/src/types/api/connector_mapping.rs @@ -175,6 +175,9 @@ impl ConnectorData { enums::Connector::CtpMastercard => { Ok(ConnectorEnum::Old(Box::new(&connector::CtpMastercard))) } + enums::Connector::Custombilling => Ok(ConnectorEnum::Old(Box::new( + connector::Custombilling::new(), + ))), enums::Connector::CtpVisa => Ok(ConnectorEnum::Old(Box::new( connector::UnifiedAuthenticationService::new(), ))), diff --git a/crates/router/src/types/connector_transformers.rs b/crates/router/src/types/connector_transformers.rs index 75b32b3ec1..47cdf592aa 100644 --- a/crates/router/src/types/connector_transformers.rs +++ b/crates/router/src/types/connector_transformers.rs @@ -32,6 +32,7 @@ impl ForeignTryFrom for common_enums::RoutableConnectors { api_enums::Connector::Coinbase => Self::Coinbase, api_enums::Connector::Coingate => Self::Coingate, api_enums::Connector::Cryptopay => Self::Cryptopay, + api_enums::Connector::Custombilling => Self::Custombilling, api_enums::Connector::CtpVisa => { Err(common_utils::errors::ValidationError::InvalidValue { message: "ctp visa is not a routable connector".to_string(), diff --git a/crates/router/tests/connectors/custombilling.rs b/crates/router/tests/connectors/custombilling.rs new file mode 100644 index 0000000000..f92552ab14 --- /dev/null +++ b/crates/router/tests/connectors/custombilling.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 CustombillingTest; +impl ConnectorActions for CustombillingTest {} +impl utils::Connector for CustombillingTest { + fn get_data(&self) -> api::ConnectorData { + use router::connector::Custombilling; + api::ConnectorData { + connector: Box::new(Custombilling::new()), + connector_name: types::Connector::Custombilling, + 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() + .custombilling + .expect("Missing connector authentication configuration").into(), + ) + } + + fn get_name(&self) -> String { + "custombilling".to_string() + } +} + +static CONNECTOR: CustombillingTest = CustombillingTest {}; + +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/loadtest/config/development.toml b/loadtest/config/development.toml index 0a64bdbba0..857d43091b 100644 --- a/loadtest/config/development.toml +++ b/loadtest/config/development.toml @@ -238,6 +238,7 @@ cards = [ "coingate", "cryptopay", "ctp_visa", + "custombilling", "cybersource", "datatrans", "deutschebank", diff --git a/scripts/add_connector.sh b/scripts/add_connector.sh index fffc5800f6..685175b79a 100755 --- a/scripts/add_connector.sh +++ b/scripts/add_connector.sh @@ -6,7 +6,7 @@ function find_prev_connector() { git checkout $self cp $self $self.tmp # Add new connector to existing list and sort it - connectors=(aci adyen adyenplatform affirm airwallex amazonpay applepay archipel authipay authorizedotnet bambora bamboraapac bankofamerica barclaycard billwerk bitpay blackhawknetwork bluesnap boku braintree cashtocode celero chargebee checkbook checkout coinbase cryptopay ctp_visa cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector dwolla ebanx elavon facilitapay fiserv fiservemea fiuu forte getnet globalpay globepay gocardless gpayments helcim hipay hyperswitch_vault iatapay inespay itaubank jpmorgan juspaythreedsserver klarna mifinity mollie moneris multisafepay netcetera nexinets nexixpay nomupay noon nordea novalnet nuvei opayo opennode paybox payeezy payload payme payone paypal paystack payu placetopay plaid powertranz prophetpay rapyd razorpay recurly redsys santander shift4 silverflow square stax stripe stripebilling taxjar threedsecureio thunes tokenio trustpay tsys unified_authentication_service vgs volt wellsfargo wellsfargopayout wise worldline worldpay worldpayvantiv worldpayxml xendit zsl "$1") + connectors=(aci adyen adyenplatform affirm airwallex amazonpay applepay archipel authipay authorizedotnet bambora bamboraapac bankofamerica barclaycard billwerk bitpay blackhawknetwork bluesnap boku braintree cashtocode celero chargebee checkbook checkout coinbase cryptopay ctp_visa custombilling cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector dwolla ebanx elavon facilitapay fiserv fiservemea fiuu forte getnet globalpay globepay gocardless gpayments helcim hipay hyperswitch_vault iatapay inespay itaubank jpmorgan juspaythreedsserver klarna mifinity mollie moneris multisafepay netcetera nexinets nexixpay nomupay noon nordea novalnet nuvei opayo opennode paybox payeezy payload payme payone paypal paystack payu placetopay plaid powertranz prophetpay rapyd razorpay recurly redsys santander shift4 silverflow square stax stripe stripebilling taxjar threedsecureio thunes tokenio trustpay tsys unified_authentication_service vgs volt wellsfargo wellsfargopayout wise worldline worldpay worldpayvantiv worldpayxml xendit zsl "$1") IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFS res="$(echo ${sorted[@]})"