diff --git a/config/config.example.toml b/config/config.example.toml index ebadc9edae79..d71846dab6f2 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -223,6 +223,7 @@ netcetera.base_url = "https://{{merchant_endpoint_prefix}}.3ds-server.prev.netce nexinets.base_url = "https://apitest.payengine.de/v1" nmi.base_url = "https://secure.nmi.com/" noon.base_url = "https://api-test.noonpayments.com/" +novalnet.base_url = "https://payport.novalnet.de/v2" noon.key_mode = "Test" nuvei.base_url = "https://ppp-test.nuvei.com/" opayo.base_url = "https://pi-test.sagepay.com/" diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml index 84652e11b0a4..dc95ef112341 100644 --- a/config/deployments/integration_test.toml +++ b/config/deployments/integration_test.toml @@ -46,6 +46,7 @@ dummyconnector.base_url = "http://localhost:8080/dummy-connector" ebanx.base_url = "https://sandbox.ebanxpay.com/" fiserv.base_url = "https://cert.api.fiservapps.com/" fiservemea.base_url = "https://prod.emea.api.fiservapps.com/sandbox/ipp/payments-gateway/v2" +novalnet.base_url = "https://payport.novalnet.de/v2" forte.base_url = "https://sandbox.forte.net/api/v3" globalpay.base_url = "https://apis.sandbox.globalpay.com/ucp/" globepay.base_url = "https://pay.globepay.co/" diff --git a/config/deployments/production.toml b/config/deployments/production.toml index bac5ec206e6e..259a84e86515 100644 --- a/config/deployments/production.toml +++ b/config/deployments/production.toml @@ -50,6 +50,7 @@ dummyconnector.base_url = "http://localhost:8080/dummy-connector" ebanx.base_url = "https://sandbox.ebanxpay.com/" fiserv.base_url = "https://cert.api.fiservapps.com/" fiservemea.base_url = "https://prod.emea.api.fiservapps.com/ipp/payments-gateway/v2" +novalnet.base_url = "https://payport.novalnet.de/v2" forte.base_url = "https://sandbox.forte.net/api/v3" globalpay.base_url = "https://apis.sandbox.globalpay.com/ucp/" globepay.base_url = "https://pay.globepay.co/" diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml index 669daa10162c..b5d385850f7f 100644 --- a/config/deployments/sandbox.toml +++ b/config/deployments/sandbox.toml @@ -50,6 +50,7 @@ dummyconnector.base_url = "http://localhost:8080/dummy-connector" ebanx.base_url = "https://sandbox.ebanxpay.com/" fiserv.base_url = "https://cert.api.fiservapps.com/" fiservemea.base_url = "https://prod.emea.api.fiservapps.com/sandbox/ipp/payments-gateway/v2" +novalnet.base_url = "https://payport.novalnet.de/v2" forte.base_url = "https://sandbox.forte.net/api/v3" globalpay.base_url = "https://apis.sandbox.globalpay.com/ucp/" globepay.base_url = "https://pay.globepay.co/" diff --git a/config/development.toml b/config/development.toml index 8facb9e803b0..dc5f66e4293c 100644 --- a/config/development.toml +++ b/config/development.toml @@ -133,6 +133,7 @@ cards = [ "nexinets", "nmi", "noon", + "novalnet", "nuvei", "opayo", "opennode", @@ -227,6 +228,7 @@ netcetera.base_url = "https://{{merchant_endpoint_prefix}}.3ds-server.prev.netce nexinets.base_url = "https://apitest.payengine.de/v1" nmi.base_url = "https://secure.nmi.com/" noon.base_url = "https://api-test.noonpayments.com/" +novalnet.base_url = "https://payport.novalnet.de/v2" noon.key_mode = "Test" nuvei.base_url = "https://ppp-test.nuvei.com/" opayo.base_url = "https://pi-test.sagepay.com/" diff --git a/config/docker_compose.toml b/config/docker_compose.toml index 41f9cf6cfafe..4435488cd7ec 100644 --- a/config/docker_compose.toml +++ b/config/docker_compose.toml @@ -152,6 +152,7 @@ netcetera.base_url = "https://{{merchant_endpoint_prefix}}.3ds-server.prev.netce nexinets.base_url = "https://apitest.payengine.de/v1" nmi.base_url = "https://secure.nmi.com/" noon.base_url = "https://api-test.noonpayments.com/" +novalnet.base_url = "https://payport.novalnet.de/v2" noon.key_mode = "Test" nuvei.base_url = "https://ppp-test.nuvei.com/" opayo.base_url = "https://pi-test.sagepay.com/" @@ -236,6 +237,7 @@ cards = [ "nexinets", "nmi", "noon", + "novalnet", "nuvei", "opayo", "opennode", diff --git a/crates/api_models/src/enums.rs b/crates/api_models/src/enums.rs index a7738133ca0c..86d6421c3e20 100644 --- a/crates/api_models/src/enums.rs +++ b/crates/api_models/src/enums.rs @@ -46,6 +46,7 @@ pub enum RoutingAlgorithm { #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] pub enum Connector { + // Novalnet, // Fiservemea, Adyenplatform, #[cfg(feature = "dummy_connector")] @@ -209,6 +210,7 @@ impl Connector { | Self::DummyConnector7 => false, Self::Aci // Add Separate authentication support for connectors + // | Self::Novalnet // | Self::Taxjar // | Self::Fiservemea | Self::Adyen diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 8df5885e7b6b..617d121c63cb 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -225,6 +225,7 @@ pub enum RoutableConnectors { Nexinets, Nmi, Noon, + // Novalnet, Nuvei, // Opayo, added as template code for future usage Opennode, diff --git a/crates/hyperswitch_connectors/src/connectors.rs b/crates/hyperswitch_connectors/src/connectors.rs index ae0fa945799b..dfaffd02662d 100644 --- a/crates/hyperswitch_connectors/src/connectors.rs +++ b/crates/hyperswitch_connectors/src/connectors.rs @@ -3,10 +3,11 @@ pub mod bitpay; pub mod fiserv; pub mod fiservemea; pub mod helcim; +pub mod novalnet; pub mod stax; pub mod taxjar; pub use self::{ bambora::Bambora, bitpay::Bitpay, fiserv::Fiserv, fiservemea::Fiservemea, helcim::Helcim, - stax::Stax, taxjar::Taxjar, + novalnet::Novalnet, stax::Stax, taxjar::Taxjar, }; diff --git a/crates/hyperswitch_connectors/src/connectors/novalnet.rs b/crates/hyperswitch_connectors/src/connectors/novalnet.rs new file mode 100644 index 000000000000..83a8015e73c6 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/novalnet.rs @@ -0,0 +1,566 @@ +pub mod transformers; + +use common_utils::{ + errors::CustomResult, + ext_traits::BytesExt, + request::{Method, Request, RequestBuilder, RequestContent}, + types::{AmountConvertor, StringMinorUnit, StringMinorUnitForConnector}, +}; +use error_stack::{report, ResultExt}; +use hyperswitch_domain_models::{ + router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData}, + router_flow_types::{ + access_token_auth::AccessTokenAuth, + payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void}, + refunds::{Execute, RSync}, + }, + router_request_types::{ + AccessTokenRequestData, PaymentMethodTokenizationData, PaymentsAuthorizeData, + PaymentsCancelData, PaymentsCaptureData, PaymentsSessionData, PaymentsSyncData, + RefundsData, SetupMandateRequestData, + }, + router_response_types::{PaymentsResponseData, RefundsResponseData}, + types::{ + PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData, + RefundSyncRouterData, RefundsRouterData, + }, +}; +use hyperswitch_interfaces::{ + api::{self, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, ConnectorValidation}, + configs::Connectors, + errors, + events::connector_api_logs::ConnectorEvent, + types::{self, Response}, + webhooks, +}; +use masking::{ExposeInterface, Mask}; +use transformers as novalnet; + +use crate::{constants::headers, types::ResponseRouterData, utils}; + +#[derive(Clone)] +pub struct Novalnet { + amount_converter: &'static (dyn AmountConvertor + Sync), +} + +impl Novalnet { + pub fn new() -> &'static Self { + &Self { + amount_converter: &StringMinorUnitForConnector, + } + } +} + +impl api::Payment for Novalnet {} +impl api::PaymentSession for Novalnet {} +impl api::ConnectorAccessToken for Novalnet {} +impl api::MandateSetup for Novalnet {} +impl api::PaymentAuthorize for Novalnet {} +impl api::PaymentSync for Novalnet {} +impl api::PaymentCapture for Novalnet {} +impl api::PaymentVoid for Novalnet {} +impl api::Refund for Novalnet {} +impl api::RefundExecute for Novalnet {} +impl api::RefundSync for Novalnet {} +impl api::PaymentToken for Novalnet {} + +impl ConnectorIntegration + for Novalnet +{ + // Not Implemented (R) +} + +impl ConnectorCommonExt for Novalnet +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 Novalnet { + fn id(&self) -> &'static str { + "novalnet" + } + + fn get_currency_unit(&self) -> api::CurrencyUnit { + api::CurrencyUnit::Base + // TODO! Check connector documentation, on which unit they are processing the currency. + // If the connector accepts amount in lower unit ( i.e cents for USD) then return api::CurrencyUnit::Minor, + // if connector accepts amount in base unit (i.e dollars for USD) then return api::CurrencyUnit::Base + } + + fn common_get_content_type(&self) -> &'static str { + "application/json" + } + + fn base_url<'a>(&self, connectors: &'a Connectors) -> &'a str { + connectors.novalnet.base_url.as_ref() + } + + fn get_auth_header( + &self, + auth_type: &ConnectorAuthType, + ) -> CustomResult)>, errors::ConnectorError> { + let auth = novalnet::NovalnetAuthType::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: novalnet::NovalnetErrorResponse = res + .response + .parse_struct("NovalnetErrorResponse") + .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 Novalnet { + //TODO: implement functions when support enabled +} + +impl ConnectorIntegration for Novalnet { + //TODO: implement sessions flow +} + +impl ConnectorIntegration for Novalnet {} + +impl ConnectorIntegration + for Novalnet +{ +} + +impl ConnectorIntegration for Novalnet { + 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 = novalnet::NovalnetRouterData::from((amount, req)); + let connector_req = novalnet::NovalnetPaymentsRequest::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: novalnet::NovalnetPaymentsResponse = res + .response + .parse_struct("Novalnet 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 Novalnet { + 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: novalnet::NovalnetPaymentsResponse = res + .response + .parse_struct("novalnet 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 Novalnet { + 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: novalnet::NovalnetPaymentsResponse = res + .response + .parse_struct("Novalnet 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 Novalnet {} + +impl ConnectorIntegration for Novalnet { + 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 = novalnet::NovalnetRouterData::from((refund_amount, req)); + let connector_req = novalnet::NovalnetRefundRequest::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: novalnet::RefundResponse = res + .response + .parse_struct("novalnet 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 Novalnet { + 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: novalnet::RefundResponse = res + .response + .parse_struct("novalnet 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 Novalnet { + fn get_webhook_object_reference_id( + &self, + _request: &webhooks::IncomingWebhookRequestDetails<'_>, + ) -> CustomResult { + Err(report!(errors::ConnectorError::WebhooksNotImplemented)) + } + + fn get_webhook_event_type( + &self, + _request: &webhooks::IncomingWebhookRequestDetails<'_>, + ) -> CustomResult { + Err(report!(errors::ConnectorError::WebhooksNotImplemented)) + } + + fn get_webhook_resource_object( + &self, + _request: &webhooks::IncomingWebhookRequestDetails<'_>, + ) -> CustomResult, errors::ConnectorError> { + Err(report!(errors::ConnectorError::WebhooksNotImplemented)) + } +} diff --git a/crates/hyperswitch_connectors/src/connectors/novalnet/transformers.rs b/crates/hyperswitch_connectors/src/connectors/novalnet/transformers.rs new file mode 100644 index 000000000000..de63e9b48c00 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/novalnet/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 NovalnetRouterData { + 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 NovalnetRouterData { + 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 NovalnetPaymentsRequest { + amount: StringMinorUnit, + card: NovalnetCard, +} + +#[derive(Default, Debug, Serialize, Eq, PartialEq)] +pub struct NovalnetCard { + number: cards::CardNumber, + expiry_month: Secret, + expiry_year: Secret, + cvc: Secret, + complete: bool, +} + +impl TryFrom<&NovalnetRouterData<&PaymentsAuthorizeRouterData>> for NovalnetPaymentsRequest { + type Error = error_stack::Report; + fn try_from( + item: &NovalnetRouterData<&PaymentsAuthorizeRouterData>, + ) -> Result { + match item.router_data.request.payment_method_data.clone() { + PaymentMethodData::Card(req_card) => { + let card = NovalnetCard { + 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 methods".to_string()).into()), + } + } +} + +//TODO: Fill the struct with respective fields +// Auth Struct +pub struct NovalnetAuthType { + pub(super) api_key: Secret, +} + +impl TryFrom<&ConnectorAuthType> for NovalnetAuthType { + 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 NovalnetPaymentStatus { + Succeeded, + Failed, + #[default] + Processing, +} + +impl From for common_enums::AttemptStatus { + fn from(item: NovalnetPaymentStatus) -> Self { + match item { + NovalnetPaymentStatus::Succeeded => Self::Charged, + NovalnetPaymentStatus::Failed => Self::Failure, + NovalnetPaymentStatus::Processing => Self::Authorizing, + } + } +} + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct NovalnetPaymentsResponse { + status: NovalnetPaymentStatus, + 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: None, + mandate_reference: 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 NovalnetRefundRequest { + pub amount: StringMinorUnit, +} + +impl TryFrom<&NovalnetRouterData<&RefundsRouterData>> for NovalnetRefundRequest { + type Error = error_stack::Report; + fn try_from(item: &NovalnetRouterData<&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 NovalnetErrorResponse { + 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 9165a1cba531..8da17ae28b0e 100644 --- a/crates/hyperswitch_connectors/src/default_implementations.rs +++ b/crates/hyperswitch_connectors/src/default_implementations.rs @@ -91,6 +91,7 @@ default_imp_for_authorize_session_token!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -116,6 +117,7 @@ default_imp_for_complete_authorize!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -141,6 +143,7 @@ default_imp_for_incremental_authorization!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -166,6 +169,7 @@ default_imp_for_create_customer!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Taxjar ); @@ -191,6 +195,7 @@ default_imp_for_connector_redirect_response!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -216,6 +221,7 @@ default_imp_for_pre_processing_steps!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -241,6 +247,7 @@ default_imp_for_post_processing_steps!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -266,6 +273,7 @@ default_imp_for_approve!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -291,6 +299,7 @@ default_imp_for_reject!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -316,6 +325,7 @@ default_imp_for_webhook_source_verification!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -342,6 +352,7 @@ default_imp_for_accept_dispute!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -367,6 +378,7 @@ default_imp_for_submit_evidence!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -392,6 +404,7 @@ default_imp_for_defend_dispute!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -426,6 +439,7 @@ default_imp_for_file_upload!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -453,6 +467,7 @@ default_imp_for_payouts_create!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -480,6 +495,7 @@ default_imp_for_payouts_retrieve!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -507,6 +523,7 @@ default_imp_for_payouts_eligibility!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -534,6 +551,7 @@ default_imp_for_payouts_fulfill!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -561,6 +579,7 @@ default_imp_for_payouts_cancel!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -588,6 +607,7 @@ default_imp_for_payouts_quote!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -615,6 +635,7 @@ default_imp_for_payouts_recipient!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -642,6 +663,7 @@ default_imp_for_payouts_recipient_account!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -669,6 +691,7 @@ default_imp_for_frm_sale!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -696,6 +719,7 @@ default_imp_for_frm_checkout!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -723,6 +747,7 @@ default_imp_for_frm_transaction!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -750,6 +775,7 @@ default_imp_for_frm_fulfillment!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -777,6 +803,7 @@ default_imp_for_frm_record_return!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -801,6 +828,7 @@ default_imp_for_revoking_mandates!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rs index c9a1cfde7454..4ebd335ce8f2 100644 --- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs +++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs @@ -186,6 +186,7 @@ default_imp_for_new_connector_integration_payment!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -212,6 +213,7 @@ default_imp_for_new_connector_integration_refund!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -233,6 +235,7 @@ default_imp_for_new_connector_integration_connector_access_token!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -260,6 +263,7 @@ default_imp_for_new_connector_integration_accept_dispute!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -286,6 +290,7 @@ default_imp_for_new_connector_integration_submit_evidence!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -312,6 +317,7 @@ default_imp_for_new_connector_integration_defend_dispute!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -348,6 +354,7 @@ default_imp_for_new_connector_integration_file_upload!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -376,6 +383,7 @@ default_imp_for_new_connector_integration_payouts_create!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -404,6 +412,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -432,6 +441,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -460,6 +470,7 @@ default_imp_for_new_connector_integration_payouts_cancel!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -488,6 +499,7 @@ default_imp_for_new_connector_integration_payouts_quote!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -516,6 +528,7 @@ default_imp_for_new_connector_integration_payouts_recipient!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -544,6 +557,7 @@ default_imp_for_new_connector_integration_payouts_sync!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -572,6 +586,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -598,6 +613,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -626,6 +642,7 @@ default_imp_for_new_connector_integration_frm_sale!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -654,6 +671,7 @@ default_imp_for_new_connector_integration_frm_checkout!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -682,6 +700,7 @@ default_imp_for_new_connector_integration_frm_transaction!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -710,6 +729,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -738,6 +758,7 @@ default_imp_for_new_connector_integration_frm_record_return!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); @@ -763,6 +784,7 @@ default_imp_for_new_connector_integration_revoking_mandates!( connectors::Fiserv, connectors::Fiservemea, connectors::Helcim, + connectors::Novalnet, connectors::Stax, connectors::Taxjar ); diff --git a/crates/hyperswitch_interfaces/src/configs.rs b/crates/hyperswitch_interfaces/src/configs.rs index 2a30df3b2cbf..2139a68d2757 100644 --- a/crates/hyperswitch_interfaces/src/configs.rs +++ b/crates/hyperswitch_interfaces/src/configs.rs @@ -54,6 +54,7 @@ pub struct Connectors { pub nexinets: ConnectorParams, pub nmi: ConnectorParams, pub noon: ConnectorParamsWithModeType, + pub novalnet: ConnectorParams, pub nuvei: ConnectorParams, pub opayo: ConnectorParams, pub opennode: ConnectorParams, diff --git a/crates/router/src/connector.rs b/crates/router/src/connector.rs index eb83e2c4ba66..5da8f3a8578d 100644 --- a/crates/router/src/connector.rs +++ b/crates/router/src/connector.rs @@ -69,7 +69,8 @@ pub mod zsl; pub use hyperswitch_connectors::connectors::{ bambora, bambora::Bambora, bitpay, bitpay::Bitpay, fiserv, fiserv::Fiserv, fiservemea, - fiservemea::Fiservemea, helcim, helcim::Helcim, stax, stax::Stax, taxjar, taxjar::Taxjar, + fiservemea::Fiservemea, helcim, helcim::Helcim, novalnet, novalnet::Novalnet, stax, stax::Stax, + taxjar, taxjar::Taxjar, }; #[cfg(feature = "dummy_connector")] 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 3ccd5f2577a6..bed63c10a8aa 100644 --- a/crates/router/src/core/payments/connector_integration_v2_impls.rs +++ b/crates/router/src/core/payments/connector_integration_v2_impls.rs @@ -1251,6 +1251,7 @@ default_imp_for_new_connector_integration_payouts!( connector::Nexinets, connector::Nmi, connector::Noon, + connector::Novalnet, connector::Nuvei, connector::Opayo, connector::Opennode, @@ -2096,6 +2097,7 @@ default_imp_for_new_connector_integration_frm!( connector::Nexinets, connector::Nmi, connector::Noon, + connector::Novalnet, connector::Nuvei, connector::Opayo, connector::Opennode, @@ -2720,6 +2722,7 @@ default_imp_for_new_connector_integration_connector_authentication!( connector::Nexinets, connector::Nmi, connector::Noon, + connector::Novalnet, connector::Nuvei, connector::Opayo, connector::Opennode, diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs index 228c7e208cc1..fb9f9907c5ad 100644 --- a/crates/router/src/core/payments/flows.rs +++ b/crates/router/src/core/payments/flows.rs @@ -556,6 +556,7 @@ default_imp_for_connector_request_id!( connector::Netcetera, connector::Nmi, connector::Noon, + connector::Novalnet, connector::Nuvei, connector::Opayo, connector::Opennode, @@ -1214,6 +1215,7 @@ default_imp_for_payouts!( connector::Nexinets, connector::Nmi, connector::Noon, + connector::Novalnet, connector::Nuvei, connector::Opayo, connector::Opennode, @@ -2233,6 +2235,7 @@ default_imp_for_fraud_check!( connector::Nexinets, connector::Nmi, connector::Noon, + connector::Novalnet, connector::Nuvei, connector::Opayo, connector::Opennode, @@ -3047,6 +3050,7 @@ default_imp_for_connector_authentication!( connector::Nexinets, connector::Nmi, connector::Noon, + connector::Novalnet, connector::Nuvei, connector::Opayo, connector::Opennode, diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs index 513e4fa1ee29..0637b98163d3 100644 --- a/crates/router/src/types/api.rs +++ b/crates/router/src/types/api.rs @@ -416,6 +416,7 @@ impl ConnectorData { enums::Connector::Mollie => Ok(ConnectorEnum::Old(Box::new(&connector::Mollie))), enums::Connector::Nmi => Ok(ConnectorEnum::Old(Box::new(connector::Nmi::new()))), enums::Connector::Noon => Ok(ConnectorEnum::Old(Box::new(connector::Noon::new()))), + // enums::Connector::Novalnet => Ok(ConnectorEnum::Old(Box::new(connector::Novalnet))), enums::Connector::Nuvei => Ok(ConnectorEnum::Old(Box::new(&connector::Nuvei))), enums::Connector::Opennode => { Ok(ConnectorEnum::Old(Box::new(&connector::Opennode))) diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index 67af63b154e0..be9c17bc8aaa 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -269,6 +269,7 @@ impl ForeignTryFrom for common_enums::RoutableConnectors { api_enums::Connector::Nexinets => Self::Nexinets, api_enums::Connector::Nmi => Self::Nmi, api_enums::Connector::Noon => Self::Noon, + // api_enums::Connector::Novalnet => Self::Novalnet, api_enums::Connector::Nuvei => Self::Nuvei, api_enums::Connector::Opennode => Self::Opennode, api_enums::Connector::Paybox => Self::Paybox, diff --git a/crates/router/tests/connectors/main.rs b/crates/router/tests/connectors/main.rs index e0fa3964b27d..2a400b947dc7 100644 --- a/crates/router/tests/connectors/main.rs +++ b/crates/router/tests/connectors/main.rs @@ -47,6 +47,7 @@ mod netcetera; mod nexinets; mod nmi; mod noon; +mod novalnet; mod nuvei; #[cfg(feature = "dummy_connector")] mod opayo; diff --git a/crates/router/tests/connectors/novalnet.rs b/crates/router/tests/connectors/novalnet.rs new file mode 100644 index 000000000000..2337cae383ce --- /dev/null +++ b/crates/router/tests/connectors/novalnet.rs @@ -0,0 +1,420 @@ +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 NovalnetTest; +impl ConnectorActions for NovalnetTest {} +impl utils::Connector for NovalnetTest { + fn get_data(&self) -> api::ConnectorData { + use router::connector::Novalnet; + utils::construct_connector_data_old( + Box::new(Novalnet::new()), + types::Connector::Plaid, + api::GetToken::Connector, + None, + ) + } + fn get_auth_token(&self) -> types::ConnectorAuthType { + utils::to_connector_auth_type( + connector_auth::ConnectorAuthentication::new() + .novalnet + .expect("Missing connector authentication configuration") + .into(), + ) + } + + fn get_name(&self) -> String { + "novalnet".to_string() + } +} + +static CONNECTOR: NovalnetTest = NovalnetTest {}; + +fn get_default_payment_info() -> Option { + None +} + +fn payment_method_details() -> Option { + None +} + +// Cards Positive Tests +// Creates a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_only_authorize_payment() { + let response = CONNECTOR + .authorize_payment(payment_method_details(), get_default_payment_info()) + .await + .expect("Authorize payment response"); + assert_eq!(response.status, enums::AttemptStatus::Authorized); +} + +// Captures a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_capture_authorized_payment() { + let response = CONNECTOR + .authorize_and_capture_payment(payment_method_details(), None, get_default_payment_info()) + .await + .expect("Capture payment response"); + assert_eq!(response.status, enums::AttemptStatus::Charged); +} + +// Partially captures a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_partially_capture_authorized_payment() { + let response = CONNECTOR + .authorize_and_capture_payment( + payment_method_details(), + Some(types::PaymentsCaptureData { + amount_to_capture: 50, + ..utils::PaymentCaptureType::default().0 + }), + get_default_payment_info(), + ) + .await + .expect("Capture payment response"); + assert_eq!(response.status, enums::AttemptStatus::Charged); +} + +// Synchronizes a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_sync_authorized_payment() { + let authorize_response = CONNECTOR + .authorize_payment(payment_method_details(), get_default_payment_info()) + .await + .expect("Authorize payment response"); + let txn_id = utils::get_connector_transaction_id(authorize_response.response); + let response = CONNECTOR + .psync_retry_till_status_matches( + enums::AttemptStatus::Authorized, + Some(types::PaymentsSyncData { + connector_transaction_id: types::ResponseId::ConnectorTransactionId( + txn_id.unwrap(), + ), + ..Default::default() + }), + get_default_payment_info(), + ) + .await + .expect("PSync response"); + assert_eq!(response.status, enums::AttemptStatus::Authorized,); +} + +// Voids a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_void_authorized_payment() { + let response = CONNECTOR + .authorize_and_void_payment( + payment_method_details(), + Some(types::PaymentsCancelData { + connector_transaction_id: String::from(""), + cancellation_reason: Some("requested_by_customer".to_string()), + ..Default::default() + }), + get_default_payment_info(), + ) + .await + .expect("Void payment response"); + assert_eq!(response.status, enums::AttemptStatus::Voided); +} + +// Refunds a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_refund_manually_captured_payment() { + let response = CONNECTOR + .capture_payment_and_refund( + payment_method_details(), + None, + None, + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Partially refunds a payment using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_partially_refund_manually_captured_payment() { + let response = CONNECTOR + .capture_payment_and_refund( + payment_method_details(), + None, + Some(types::RefundsData { + refund_amount: 50, + ..utils::PaymentRefundType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Synchronizes a refund using the manual capture flow (Non 3DS). +#[actix_web::test] +async fn should_sync_manually_captured_refund() { + let refund_response = CONNECTOR + .capture_payment_and_refund( + payment_method_details(), + None, + None, + get_default_payment_info(), + ) + .await + .unwrap(); + let response = CONNECTOR + .rsync_retry_till_status_matches( + enums::RefundStatus::Success, + refund_response.response.unwrap().connector_refund_id, + None, + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Creates a payment using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_make_payment() { + let authorize_response = CONNECTOR + .make_payment(payment_method_details(), get_default_payment_info()) + .await + .unwrap(); + assert_eq!(authorize_response.status, enums::AttemptStatus::Charged); +} + +// Synchronizes a payment using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_sync_auto_captured_payment() { + let authorize_response = CONNECTOR + .make_payment(payment_method_details(), get_default_payment_info()) + .await + .unwrap(); + assert_eq!(authorize_response.status, enums::AttemptStatus::Charged); + let txn_id = utils::get_connector_transaction_id(authorize_response.response); + assert_ne!(txn_id, None, "Empty connector transaction id"); + let response = CONNECTOR + .psync_retry_till_status_matches( + enums::AttemptStatus::Charged, + Some(types::PaymentsSyncData { + connector_transaction_id: types::ResponseId::ConnectorTransactionId( + txn_id.unwrap(), + ), + capture_method: Some(enums::CaptureMethod::Automatic), + ..Default::default() + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!(response.status, enums::AttemptStatus::Charged,); +} + +// Refunds a payment using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_refund_auto_captured_payment() { + let response = CONNECTOR + .make_payment_and_refund(payment_method_details(), None, get_default_payment_info()) + .await + .unwrap(); + assert_eq!( + response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Partially refunds a payment using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_partially_refund_succeeded_payment() { + let refund_response = CONNECTOR + .make_payment_and_refund( + payment_method_details(), + Some(types::RefundsData { + refund_amount: 50, + ..utils::PaymentRefundType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + refund_response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Creates multiple refunds against a payment using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_refund_succeeded_payment_multiple_times() { + CONNECTOR + .make_payment_and_multiple_refund( + payment_method_details(), + Some(types::RefundsData { + refund_amount: 50, + ..utils::PaymentRefundType::default().0 + }), + get_default_payment_info(), + ) + .await; +} + +// Synchronizes a refund using the automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_sync_refund() { + let refund_response = CONNECTOR + .make_payment_and_refund(payment_method_details(), None, get_default_payment_info()) + .await + .unwrap(); + let response = CONNECTOR + .rsync_retry_till_status_matches( + enums::RefundStatus::Success, + refund_response.response.unwrap().connector_refund_id, + None, + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap().refund_status, + enums::RefundStatus::Success, + ); +} + +// Cards Negative scenarios +// Creates a payment with incorrect CVC. +#[actix_web::test] +async fn should_fail_payment_for_incorrect_cvc() { + let response = CONNECTOR + .make_payment( + Some(types::PaymentsAuthorizeData { + payment_method_data: PaymentMethodData::Card(Card { + card_cvc: Secret::new("12345".to_string()), + ..utils::CCardType::default().0 + }), + ..utils::PaymentAuthorizeType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap_err().message, + "Your card's security code is invalid.".to_string(), + ); +} + +// Creates a payment with incorrect expiry month. +#[actix_web::test] +async fn should_fail_payment_for_invalid_exp_month() { + let response = CONNECTOR + .make_payment( + Some(types::PaymentsAuthorizeData { + payment_method_data: PaymentMethodData::Card(Card { + card_exp_month: Secret::new("20".to_string()), + ..utils::CCardType::default().0 + }), + ..utils::PaymentAuthorizeType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap_err().message, + "Your card's expiration month is invalid.".to_string(), + ); +} + +// Creates a payment with incorrect expiry year. +#[actix_web::test] +async fn should_fail_payment_for_incorrect_expiry_year() { + let response = CONNECTOR + .make_payment( + Some(types::PaymentsAuthorizeData { + payment_method_data: PaymentMethodData::Card(Card { + card_exp_year: Secret::new("2000".to_string()), + ..utils::CCardType::default().0 + }), + ..utils::PaymentAuthorizeType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap_err().message, + "Your card's expiration year is invalid.".to_string(), + ); +} + +// Voids a payment using automatic capture flow (Non 3DS). +#[actix_web::test] +async fn should_fail_void_payment_for_auto_capture() { + let authorize_response = CONNECTOR + .make_payment(payment_method_details(), get_default_payment_info()) + .await + .unwrap(); + assert_eq!(authorize_response.status, enums::AttemptStatus::Charged); + let txn_id = utils::get_connector_transaction_id(authorize_response.response); + assert_ne!(txn_id, None, "Empty connector transaction id"); + let void_response = CONNECTOR + .void_payment(txn_id.unwrap(), None, get_default_payment_info()) + .await + .unwrap(); + assert_eq!( + void_response.response.unwrap_err().message, + "You cannot cancel this PaymentIntent because it has a status of succeeded." + ); +} + +// Captures a payment using invalid connector payment id. +#[actix_web::test] +async fn should_fail_capture_for_invalid_payment() { + let capture_response = CONNECTOR + .capture_payment("123456789".to_string(), None, get_default_payment_info()) + .await + .unwrap(); + assert_eq!( + capture_response.response.unwrap_err().message, + String::from("No such payment_intent: '123456789'") + ); +} + +// Refunds a payment with refund amount higher than payment amount. +#[actix_web::test] +async fn should_fail_for_refund_amount_higher_than_payment_amount() { + let response = CONNECTOR + .make_payment_and_refund( + payment_method_details(), + Some(types::RefundsData { + refund_amount: 150, + ..utils::PaymentRefundType::default().0 + }), + get_default_payment_info(), + ) + .await + .unwrap(); + assert_eq!( + response.response.unwrap_err().message, + "Refund amount (₹1.50) is greater than charge amount (₹1.00)", + ); +} + +// Connector dependent test cases goes here + +// [#478]: add unit tests for non 3DS, wallets & webhooks in connector tests diff --git a/crates/router/tests/connectors/sample_auth.toml b/crates/router/tests/connectors/sample_auth.toml index 0bf4d96d19f2..6134d1ae0367 100644 --- a/crates/router/tests/connectors/sample_auth.toml +++ b/crates/router/tests/connectors/sample_auth.toml @@ -267,4 +267,7 @@ key1 = "Gateway Entity Id" api_secret = "Consumer Secret" [taxjar] -api_key = "API Key" \ No newline at end of file +api_key = "API Key" + +[novalnet] +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 b13be3075aa9..0848b9a9f572 100644 --- a/crates/test_utils/src/connector_auth.rs +++ b/crates/test_utils/src/connector_auth.rs @@ -51,6 +51,7 @@ pub struct ConnectorAuthentication { pub netcetera: Option, pub nexinets: Option, pub noon: Option, + pub novalnet: Option, pub nmi: Option, pub nuvei: Option, pub opayo: Option, diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml index 9e5c8a3f0ceb..d2025311dc1e 100644 --- a/loadtest/config/development.toml +++ b/loadtest/config/development.toml @@ -117,6 +117,7 @@ netcetera.base_url = "https://{{merchant_endpoint_prefix}}.3ds-server.prev.netce nexinets.base_url = "https://apitest.payengine.de/v1" nmi.base_url = "https://secure.nmi.com/" noon.base_url = "https://api-test.noonpayments.com/" +novalnet.base_url = "https://payport.novalnet.de/v2" noon.key_mode = "Test" nuvei.base_url = "https://ppp-test.nuvei.com/" opayo.base_url = "https://pi-test.sagepay.com/" @@ -201,6 +202,7 @@ cards = [ "nexinets", "nmi", "noon", + "novalnet", "nuvei", "opayo", "opennode", diff --git a/scripts/add_connector.sh b/scripts/add_connector.sh index 3e5fc1c3d9dc..362d0577c698 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 applepay authorizedotnet bambora bamboraapac bankofamerica billwerk bitpay bluesnap boku braintree cashtocode checkout coinbase cryptopay cybersource datatrans dlocal dummyconnector ebanx fiserv fiservemea forte globalpay globepay gocardless gpayments helcim iatapay itaubank klarna mifinity mollie multisafepay netcetera nexinets noon nuvei opayo opennode paybox payeezy payme payone paypal payu placetopay plaid powertranz prophetpay rapyd razorpay shift4 square stax stripe taxjar threedsecureio trustpay tsys volt wellsfargo wellsfargopayout wise worldline worldpay zsl "$1") + connectors=(aci adyen adyenplatform airwallex applepay authorizedotnet bambora bamboraapac bankofamerica billwerk bitpay bluesnap boku braintree cashtocode checkout coinbase cryptopay cybersource datatrans dlocal dummyconnector ebanx fiserv fiservemea forte globalpay globepay gocardless gpayments helcim iatapay itaubank klarna mifinity mollie multisafepay netcetera nexinets noon novalnet nuvei opayo opennode paybox payeezy payme payone paypal payu placetopay plaid powertranz prophetpay rapyd razorpay shift4 square stax stripe taxjar threedsecureio trustpay tsys volt wellsfargo wellsfargopayout wise worldline worldpay zsl "$1") IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFS res=`echo ${sorted[@]}` sed -i'' -e "s/^ connectors=.*/ connectors=($res \"\$1\")/" $self.tmp