diff --git a/config/config.example.toml b/config/config.example.toml index 9e54c7e8c8..453e116128 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -255,6 +255,7 @@ powertranz.base_url = "https://staging.ptranz.com/api/" prophetpay.base_url = "https://ccm-thirdparty.cps.golf/" rapyd.base_url = "https://sandboxapi.rapyd.net" razorpay.base_url = "https://sandbox.juspay.in/" +recurly.base_url = "https://{{merchant_subdomain_name}}.recurly.com" redsys.base_url = "https://sis-t.redsys.es:25443/sis/realizarPago" riskified.base_url = "https://sandbox.riskified.com/api" shift4.base_url = "https://api.shift4.com/" diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml index c8eb14c985..a6a7a09e16 100644 --- a/config/deployments/integration_test.toml +++ b/config/deployments/integration_test.toml @@ -100,6 +100,7 @@ powertranz.base_url = "https://staging.ptranz.com/api/" prophetpay.base_url = "https://ccm-thirdparty.cps.golf/" rapyd.base_url = "https://sandboxapi.rapyd.net" razorpay.base_url = "https://sandbox.juspay.in/" +recurly.base_url = "https://{{merchant_subdomain_name}}.recurly.com" redsys.base_url = "https://sis-t.redsys.es:25443/sis/realizarPago" shift4.base_url = "https://api.shift4.com/" signifyd.base_url = "https://api.signifyd.com/" diff --git a/config/deployments/production.toml b/config/deployments/production.toml index 90ca4ae143..e8f2c30c69 100644 --- a/config/deployments/production.toml +++ b/config/deployments/production.toml @@ -104,6 +104,7 @@ powertranz.base_url = "https://staging.ptranz.com/api/" prophetpay.base_url = "https://ccm-thirdparty.cps.golf/" rapyd.base_url = "https://sandboxapi.rapyd.net" razorpay.base_url = "https://api.juspay.in" +recurly.base_url = "https://{{merchant_subdomain_name}}.recurly.com" redsys.base_url = "https://sis.redsys.es:25443/sis/realizarPago" riskified.base_url = "https://wh.riskified.com/api/" shift4.base_url = "https://api.shift4.com/" diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml index 29e6013114..302ff6f3a0 100644 --- a/config/deployments/sandbox.toml +++ b/config/deployments/sandbox.toml @@ -104,6 +104,7 @@ powertranz.base_url = "https://staging.ptranz.com/api/" prophetpay.base_url = "https://ccm-thirdparty.cps.golf/" rapyd.base_url = "https://sandboxapi.rapyd.net" razorpay.base_url = "https://sandbox.juspay.in/" +recurly.base_url = "https://{{merchant_subdomain_name}}.recurly.com" redsys.base_url = "https://sis-t.redsys.es:25443/sis/realizarPago" riskified.base_url = "https://sandbox.riskified.com/api" shift4.base_url = "https://api.shift4.com/" diff --git a/config/development.toml b/config/development.toml index 7619f992aa..b81080740f 100644 --- a/config/development.toml +++ b/config/development.toml @@ -327,6 +327,7 @@ powertranz.base_url = "https://staging.ptranz.com/api/" prophetpay.base_url = "https://ccm-thirdparty.cps.golf/" rapyd.base_url = "https://sandboxapi.rapyd.net" razorpay.base_url = "https://sandbox.juspay.in/" +recurly.base_url = "https://{{merchant_subdomain_name}}.recurly.com" redsys.base_url = "https://sis-t.redsys.es:25443/sis/realizarPago" riskified.base_url = "https://sandbox.riskified.com/api" shift4.base_url = "https://api.shift4.com/" diff --git a/config/docker_compose.toml b/config/docker_compose.toml index 58cf75fb8d..83aa883a16 100644 --- a/config/docker_compose.toml +++ b/config/docker_compose.toml @@ -187,6 +187,7 @@ powertranz.base_url = "https://staging.ptranz.com/api/" prophetpay.base_url = "https://ccm-thirdparty.cps.golf/" rapyd.base_url = "https://sandboxapi.rapyd.net" razorpay.base_url = "https://sandbox.juspay.in/" +recurly.base_url = "https://{{merchant_subdomain_name}}.recurly.com" redsys.base_url = "https://sis-t.redsys.es:25443/sis/realizarPago" riskified.base_url = "https://sandbox.riskified.com/api" shift4.base_url = "https://api.shift4.com/" diff --git a/crates/common_enums/src/connector_enums.rs b/crates/common_enums/src/connector_enums.rs index cadca5fad0..65fa444175 100644 --- a/crates/common_enums/src/connector_enums.rs +++ b/crates/common_enums/src/connector_enums.rs @@ -116,6 +116,7 @@ pub enum RoutableConnectors { Prophetpay, Rapyd, Razorpay, + // Recurly, // Redsys, Riskified, Shift4, @@ -259,6 +260,7 @@ pub enum Connector { Prophetpay, Rapyd, Razorpay, + //Recurly, // Redsys, Shift4, Square, @@ -408,6 +410,7 @@ impl Connector { | Self::Powertranz | Self::Prophetpay | Self::Rapyd + // | Self::Recurly // | Self::Redsys | Self::Shift4 | Self::Square @@ -543,6 +546,7 @@ impl From for Connector { RoutableConnectors::Prophetpay => Self::Prophetpay, RoutableConnectors::Rapyd => Self::Rapyd, RoutableConnectors::Razorpay => Self::Razorpay, + // RoutableConnectors::Recurly => Self::Recurly, RoutableConnectors::Riskified => Self::Riskified, RoutableConnectors::Shift4 => Self::Shift4, RoutableConnectors::Signifyd => Self::Signifyd, diff --git a/crates/hyperswitch_connectors/src/connectors.rs b/crates/hyperswitch_connectors/src/connectors.rs index 6fa0d9e103..495228de0c 100644 --- a/crates/hyperswitch_connectors/src/connectors.rs +++ b/crates/hyperswitch_connectors/src/connectors.rs @@ -59,6 +59,7 @@ pub mod powertranz; pub mod prophetpay; pub mod rapyd; pub mod razorpay; +pub mod recurly; pub mod redsys; pub mod shift4; pub mod square; @@ -92,8 +93,8 @@ pub use self::{ noon::Noon, novalnet::Novalnet, nuvei::Nuvei, opayo::Opayo, opennode::Opennode, paybox::Paybox, payeezy::Payeezy, payme::Payme, paystack::Paystack, payu::Payu, placetopay::Placetopay, powertranz::Powertranz, prophetpay::Prophetpay, rapyd::Rapyd, razorpay::Razorpay, - redsys::Redsys, shift4::Shift4, square::Square, stax::Stax, stripebilling::Stripebilling, - taxjar::Taxjar, thunes::Thunes, trustpay::Trustpay, tsys::Tsys, + recurly::Recurly, redsys::Redsys, shift4::Shift4, square::Square, stax::Stax, + stripebilling::Stripebilling, taxjar::Taxjar, thunes::Thunes, trustpay::Trustpay, tsys::Tsys, unified_authentication_service::UnifiedAuthenticationService, volt::Volt, wellsfargo::Wellsfargo, worldline::Worldline, worldpay::Worldpay, xendit::Xendit, zen::Zen, zsl::Zsl, diff --git a/crates/hyperswitch_connectors/src/connectors/recurly.rs b/crates/hyperswitch_connectors/src/connectors/recurly.rs new file mode 100644 index 0000000000..c16810a6ab --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/recurly.rs @@ -0,0 +1,568 @@ +pub mod transformers; + +use common_utils::{ + errors::CustomResult, + ext_traits::BytesExt, + request::{Method, Request, RequestBuilder, RequestContent}, + types::{AmountConvertor, StringMinorUnit, StringMinorUnitForConnector}, +}; +use error_stack::{report, ResultExt}; +use hyperswitch_domain_models::{ + router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData}, + router_flow_types::{ + access_token_auth::AccessTokenAuth, + payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void}, + refunds::{Execute, RSync}, + }, + router_request_types::{ + AccessTokenRequestData, PaymentMethodTokenizationData, PaymentsAuthorizeData, + PaymentsCancelData, PaymentsCaptureData, PaymentsSessionData, PaymentsSyncData, + RefundsData, SetupMandateRequestData, + }, + router_response_types::{PaymentsResponseData, RefundsResponseData}, + types::{ + PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData, + RefundSyncRouterData, RefundsRouterData, + }, +}; +use hyperswitch_interfaces::{ + api::{ + self, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, ConnectorSpecifications, + ConnectorValidation, + }, + configs::Connectors, + errors, + events::connector_api_logs::ConnectorEvent, + types::{self, Response}, + webhooks, +}; +use masking::{ExposeInterface, Mask}; +use transformers as recurly; + +use crate::{constants::headers, types::ResponseRouterData, utils}; + +#[derive(Clone)] +pub struct Recurly { + amount_converter: &'static (dyn AmountConvertor + Sync), +} + +impl Recurly { + pub fn new() -> &'static Self { + &Self { + amount_converter: &StringMinorUnitForConnector, + } + } +} + +impl api::Payment for Recurly {} +impl api::PaymentSession for Recurly {} +impl api::ConnectorAccessToken for Recurly {} +impl api::MandateSetup for Recurly {} +impl api::PaymentAuthorize for Recurly {} +impl api::PaymentSync for Recurly {} +impl api::PaymentCapture for Recurly {} +impl api::PaymentVoid for Recurly {} +impl api::Refund for Recurly {} +impl api::RefundExecute for Recurly {} +impl api::RefundSync for Recurly {} +impl api::PaymentToken for Recurly {} + +impl ConnectorIntegration + for Recurly +{ + // Not Implemented (R) +} + +impl ConnectorCommonExt for Recurly +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 Recurly { + fn id(&self) -> &'static str { + "recurly" + } + + 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 { + connectors.recurly.base_url.as_ref() + } + + fn get_auth_header( + &self, + auth_type: &ConnectorAuthType, + ) -> CustomResult)>, errors::ConnectorError> { + let auth = recurly::RecurlyAuthType::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: recurly::RecurlyErrorResponse = res + .response + .parse_struct("RecurlyErrorResponse") + .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 Recurly { + //TODO: implement functions when support enabled +} + +impl ConnectorIntegration for Recurly { + //TODO: implement sessions flow +} + +impl ConnectorIntegration for Recurly {} + +impl ConnectorIntegration for Recurly {} + +impl ConnectorIntegration for Recurly { + 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 = recurly::RecurlyRouterData::from((amount, req)); + let connector_req = recurly::RecurlyPaymentsRequest::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: recurly::RecurlyPaymentsResponse = res + .response + .parse_struct("Recurly 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 Recurly { + 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: recurly::RecurlyPaymentsResponse = res + .response + .parse_struct("recurly 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 Recurly { + 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: recurly::RecurlyPaymentsResponse = res + .response + .parse_struct("Recurly 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 Recurly {} + +impl ConnectorIntegration for Recurly { + 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 = recurly::RecurlyRouterData::from((refund_amount, req)); + let connector_req = recurly::RecurlyRefundRequest::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: recurly::RefundResponse = res + .response + .parse_struct("recurly 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 Recurly { + 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: recurly::RefundResponse = res + .response + .parse_struct("recurly 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 Recurly { + 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 Recurly {} diff --git a/crates/hyperswitch_connectors/src/connectors/recurly/transformers.rs b/crates/hyperswitch_connectors/src/connectors/recurly/transformers.rs new file mode 100644 index 0000000000..bc62985edb --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/recurly/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 RecurlyRouterData { + 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 RecurlyRouterData { + 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 RecurlyPaymentsRequest { + amount: StringMinorUnit, + card: RecurlyCard, +} + +#[derive(Default, Debug, Serialize, Eq, PartialEq)] +pub struct RecurlyCard { + number: cards::CardNumber, + expiry_month: Secret, + expiry_year: Secret, + cvc: Secret, + complete: bool, +} + +impl TryFrom<&RecurlyRouterData<&PaymentsAuthorizeRouterData>> for RecurlyPaymentsRequest { + type Error = error_stack::Report; + fn try_from( + item: &RecurlyRouterData<&PaymentsAuthorizeRouterData>, + ) -> Result { + match item.router_data.request.payment_method_data.clone() { + PaymentMethodData::Card(req_card) => { + let card = RecurlyCard { + 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 RecurlyAuthType { + pub(super) api_key: Secret, +} + +impl TryFrom<&ConnectorAuthType> for RecurlyAuthType { + 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 RecurlyPaymentStatus { + Succeeded, + Failed, + #[default] + Processing, +} + +impl From for common_enums::AttemptStatus { + fn from(item: RecurlyPaymentStatus) -> Self { + match item { + RecurlyPaymentStatus::Succeeded => Self::Charged, + RecurlyPaymentStatus::Failed => Self::Failure, + RecurlyPaymentStatus::Processing => Self::Authorizing, + } + } +} + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct RecurlyPaymentsResponse { + status: RecurlyPaymentStatus, + 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 RecurlyRefundRequest { + pub amount: StringMinorUnit, +} + +impl TryFrom<&RecurlyRouterData<&RefundsRouterData>> for RecurlyRefundRequest { + type Error = error_stack::Report; + fn try_from(item: &RecurlyRouterData<&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 RecurlyErrorResponse { + 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 f64f624187..ad9e456c94 100644 --- a/crates/hyperswitch_connectors/src/default_implementations.rs +++ b/crates/hyperswitch_connectors/src/default_implementations.rs @@ -156,6 +156,7 @@ default_imp_for_authorize_session_token!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -250,6 +251,7 @@ default_imp_for_calculate_tax!( connectors::Prophetpay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -319,6 +321,7 @@ default_imp_for_session_update!( connectors::Klarna, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -415,6 +418,7 @@ default_imp_for_post_session_tokens!( connectors::Klarna, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -520,6 +524,7 @@ default_imp_for_complete_authorize!( connectors::Placetopay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Stax, connectors::Square, @@ -613,6 +618,7 @@ default_imp_for_incremental_authorization!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -707,6 +713,7 @@ default_imp_for_create_customer!( connectors::Prophetpay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Square, @@ -789,6 +796,7 @@ default_imp_for_connector_redirect_response!( connectors::Prophetpay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -875,6 +883,7 @@ default_imp_for_pre_processing_steps!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Stax, connectors::Square, @@ -968,6 +977,7 @@ default_imp_for_post_processing_steps!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1064,6 +1074,7 @@ default_imp_for_approve!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1160,6 +1171,7 @@ default_imp_for_reject!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1256,6 +1268,7 @@ default_imp_for_webhook_source_verification!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1352,6 +1365,7 @@ default_imp_for_accept_dispute!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1447,6 +1461,7 @@ default_imp_for_submit_evidence!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1542,6 +1557,7 @@ default_imp_for_defend_dispute!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1646,6 +1662,7 @@ default_imp_for_file_upload!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1733,6 +1750,7 @@ default_imp_for_payouts!( connectors::Prophetpay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Square, @@ -1829,6 +1847,7 @@ default_imp_for_payouts_create!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1926,6 +1945,7 @@ default_imp_for_payouts_retrieve!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2023,6 +2043,7 @@ default_imp_for_payouts_eligibility!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2119,6 +2140,7 @@ default_imp_for_payouts_fulfill!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2216,6 +2238,7 @@ default_imp_for_payouts_cancel!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2313,6 +2336,7 @@ default_imp_for_payouts_quote!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2410,6 +2434,7 @@ default_imp_for_payouts_recipient!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2507,6 +2532,7 @@ default_imp_for_payouts_recipient_account!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2605,6 +2631,7 @@ default_imp_for_frm_sale!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2703,6 +2730,7 @@ default_imp_for_frm_checkout!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2801,6 +2829,7 @@ default_imp_for_frm_transaction!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2899,6 +2928,7 @@ default_imp_for_frm_fulfillment!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2997,6 +3027,7 @@ default_imp_for_frm_record_return!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -3090,6 +3121,7 @@ default_imp_for_revoking_mandates!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -3186,6 +3218,7 @@ default_imp_for_uas_pre_authentication!( connectors::Placetopay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -3280,6 +3313,7 @@ default_imp_for_uas_post_authentication!( connectors::Placetopay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -3374,6 +3408,7 @@ default_imp_for_uas_authentication!( connectors::Placetopay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -3469,6 +3504,7 @@ default_imp_for_uas_authentication_confirmation!( connectors::Placetopay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rs index f333800480..972a26adf3 100644 --- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs +++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs @@ -265,6 +265,7 @@ default_imp_for_new_connector_integration_payment!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -362,6 +363,7 @@ default_imp_for_new_connector_integration_refund!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -454,6 +456,7 @@ default_imp_for_new_connector_integration_connector_access_token!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -551,6 +554,7 @@ default_imp_for_new_connector_integration_accept_dispute!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -647,6 +651,7 @@ default_imp_for_new_connector_integration_submit_evidence!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -744,6 +749,7 @@ default_imp_for_new_connector_integration_defend_dispute!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -851,6 +857,7 @@ default_imp_for_new_connector_integration_file_upload!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -950,6 +957,7 @@ default_imp_for_new_connector_integration_payouts_create!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1049,6 +1057,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1148,6 +1157,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1247,6 +1257,7 @@ default_imp_for_new_connector_integration_payouts_cancel!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1346,6 +1357,7 @@ default_imp_for_new_connector_integration_payouts_quote!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1445,6 +1457,7 @@ default_imp_for_new_connector_integration_payouts_recipient!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1544,6 +1557,7 @@ default_imp_for_new_connector_integration_payouts_sync!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1643,6 +1657,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1740,6 +1755,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1839,6 +1855,7 @@ default_imp_for_new_connector_integration_frm_sale!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -1938,6 +1955,7 @@ default_imp_for_new_connector_integration_frm_checkout!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2037,6 +2055,7 @@ default_imp_for_new_connector_integration_frm_transaction!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2136,6 +2155,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2235,6 +2255,7 @@ default_imp_for_new_connector_integration_frm_record_return!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, @@ -2331,6 +2352,7 @@ default_imp_for_new_connector_integration_revoking_mandates!( connectors::Multisafepay, connectors::Rapyd, connectors::Razorpay, + connectors::Recurly, connectors::Redsys, connectors::Shift4, connectors::Stax, diff --git a/crates/hyperswitch_interfaces/src/configs.rs b/crates/hyperswitch_interfaces/src/configs.rs index 5b46184c36..e317785692 100644 --- a/crates/hyperswitch_interfaces/src/configs.rs +++ b/crates/hyperswitch_interfaces/src/configs.rs @@ -81,6 +81,7 @@ pub struct Connectors { pub prophetpay: ConnectorParams, pub rapyd: ConnectorParams, pub razorpay: ConnectorParamsWithKeys, + pub recurly: ConnectorParams, pub redsys: ConnectorParams, pub riskified: ConnectorParams, pub shift4: ConnectorParams, diff --git a/crates/router/src/connector.rs b/crates/router/src/connector.rs index 9f99b4c61a..a89ae69451 100644 --- a/crates/router/src/connector.rs +++ b/crates/router/src/connector.rs @@ -38,12 +38,12 @@ pub use hyperswitch_connectors::connectors::{ opennode::Opennode, paybox, paybox::Paybox, payeezy, payeezy::Payeezy, payme, payme::Payme, paystack, paystack::Paystack, payu, payu::Payu, placetopay, placetopay::Placetopay, powertranz, powertranz::Powertranz, prophetpay, prophetpay::Prophetpay, rapyd, rapyd::Rapyd, razorpay, - razorpay::Razorpay, redsys, redsys::Redsys, shift4, shift4::Shift4, square, square::Square, - stax, stax::Stax, stripebilling, stripebilling::Stripebilling, taxjar, taxjar::Taxjar, thunes, - thunes::Thunes, trustpay, trustpay::Trustpay, tsys, tsys::Tsys, unified_authentication_service, - unified_authentication_service::UnifiedAuthenticationService, volt, volt::Volt, wellsfargo, - wellsfargo::Wellsfargo, worldline, worldline::Worldline, worldpay, worldpay::Worldpay, xendit, - xendit::Xendit, zen, zen::Zen, zsl, zsl::Zsl, + razorpay::Razorpay, recurly::Recurly, redsys, redsys::Redsys, shift4, shift4::Shift4, square, + square::Square, stax, stax::Stax, stripebilling, stripebilling::Stripebilling, taxjar, + taxjar::Taxjar, thunes, thunes::Thunes, trustpay, trustpay::Trustpay, tsys, tsys::Tsys, + unified_authentication_service, unified_authentication_service::UnifiedAuthenticationService, + volt, volt::Volt, wellsfargo, wellsfargo::Wellsfargo, worldline, worldline::Worldline, + worldpay, worldpay::Worldpay, xendit, xendit::Xendit, zen, zen::Zen, zsl, zsl::Zsl, }; #[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 4f963755b1..8d38b84a00 100644 --- a/crates/router/src/core/payments/connector_integration_v2_impls.rs +++ b/crates/router/src/core/payments/connector_integration_v2_impls.rs @@ -985,6 +985,7 @@ default_imp_for_new_connector_integration_payouts!( connector::Powertranz, connector::Rapyd, connector::Razorpay, + connector::Recurly, connector::Redsys, connector::Riskified, connector::Signifyd, @@ -1390,6 +1391,7 @@ default_imp_for_new_connector_integration_frm!( connector::Powertranz, connector::Rapyd, connector::Razorpay, + connector::Recurly, connector::Redsys, connector::Riskified, connector::Signifyd, @@ -1729,6 +1731,7 @@ default_imp_for_new_connector_integration_connector_authentication!( connector::Prophetpay, connector::Rapyd, connector::Razorpay, + connector::Recurly, connector::Redsys, connector::Riskified, connector::Signifyd, diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs index 02a4fe2386..7e5cdfdaa3 100644 --- a/crates/router/src/core/payments/flows.rs +++ b/crates/router/src/core/payments/flows.rs @@ -439,6 +439,7 @@ default_imp_for_connector_request_id!( connector::Prophetpay, connector::Rapyd, connector::Razorpay, + connector::Recurly, connector::Redsys, connector::Riskified, connector::Shift4, @@ -1289,6 +1290,7 @@ default_imp_for_fraud_check!( connector::Prophetpay, connector::Rapyd, connector::Razorpay, + connector::Recurly, connector::Redsys, connector::Shift4, connector::Square, @@ -1778,6 +1780,7 @@ default_imp_for_connector_authentication!( connector::Prophetpay, connector::Rapyd, connector::Razorpay, + connector::Recurly, connector::Redsys, connector::Riskified, connector::Shift4, diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs index a32e0457df..c4c2371abf 100644 --- a/crates/router/src/types/api.rs +++ b/crates/router/src/types/api.rs @@ -510,6 +510,7 @@ impl ConnectorData { enums::Connector::Rapyd => { Ok(ConnectorEnum::Old(Box::new(connector::Rapyd::new()))) } + // enums::Connector::Recurly => Ok(ConnectorEnum::Old(Box::new(connector::Recurly))), // enums::Connector::Redsys => Ok(ConnectorEnum::Old(Box::new(connector::Redsys))), enums::Connector::Shift4 => { Ok(ConnectorEnum::Old(Box::new(connector::Shift4::new()))) diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index 514ddbbbb5..6ab4111f4b 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -290,6 +290,7 @@ impl ForeignTryFrom for common_enums::RoutableConnectors { api_enums::Connector::Prophetpay => Self::Prophetpay, api_enums::Connector::Rapyd => Self::Rapyd, api_enums::Connector::Razorpay => Self::Razorpay, + // api_enums::Connector::Recurly => Self::Recurly, // api_enums::Connector::Redsys => Self::Redsys, api_enums::Connector::Shift4 => Self::Shift4, api_enums::Connector::Signifyd => { diff --git a/crates/router/tests/connectors/main.rs b/crates/router/tests/connectors/main.rs index 09718d5618..040b2dd631 100644 --- a/crates/router/tests/connectors/main.rs +++ b/crates/router/tests/connectors/main.rs @@ -78,6 +78,7 @@ mod powertranz; mod prophetpay; mod rapyd; mod razorpay; +mod recurly; mod redsys; mod shift4; mod square; diff --git a/crates/router/tests/connectors/recurly.rs b/crates/router/tests/connectors/recurly.rs new file mode 100644 index 0000000000..a38ed49d41 --- /dev/null +++ b/crates/router/tests/connectors/recurly.rs @@ -0,0 +1,421 @@ +use hyperswitch_domain_models::payment_method_data::{Card, PaymentMethodData}; +use masking::Secret; +use router::types::{self, api, storage::enums}; +use test_utils::connector_auth; + +use crate::utils::{self, ConnectorActions}; + +#[derive(Clone, Copy)] +struct RecurlyTest; +impl ConnectorActions for RecurlyTest {} +impl utils::Connector for RecurlyTest { + fn get_data(&self) -> api::ConnectorData { + use router::connector::Recurly; + utils::construct_connector_data_old( + Box::new(Recurly::new()), + types::Connector::Plaid, + api::GetToken::Connector, + None, + ) + } + + fn get_auth_token(&self) -> types::ConnectorAuthType { + utils::to_connector_auth_type( + connector_auth::ConnectorAuthentication::new() + .recurly + .expect("Missing connector authentication configuration") + .into(), + ) + } + + fn get_name(&self) -> String { + "Recurly".to_string() + } +} + +static CONNECTOR: RecurlyTest = RecurlyTest {}; + +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 d30a500888..0650e5e6a4 100644 --- a/crates/router/tests/connectors/sample_auth.toml +++ b/crates/router/tests/connectors/sample_auth.toml @@ -320,4 +320,7 @@ api_key= "API Key" api_key= "API Key" [paystack] -api_key = "API Key" \ No newline at end of file +api_key = "API Key" + +[recurly] +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 bb40cc51ea..f19d5d22e8 100644 --- a/crates/test_utils/src/connector_auth.rs +++ b/crates/test_utils/src/connector_auth.rs @@ -82,6 +82,7 @@ pub struct ConnectorAuthentication { pub prophetpay: Option, pub rapyd: Option, pub razorpay: Option, + pub recurly: Option, pub redsys: Option, pub shift4: Option, pub square: Option, diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml index 526899b7ff..6b1afeab21 100644 --- a/loadtest/config/development.toml +++ b/loadtest/config/development.toml @@ -153,6 +153,7 @@ powertranz.base_url = "https://staging.ptranz.com/api/" prophetpay.base_url = "https://ccm-thirdparty.cps.golf/" rapyd.base_url = "https://sandboxapi.rapyd.net" razorpay.base_url = "https://sandbox.juspay.in/" +recurly.base_url = "https://{{merchant_subdomain_name}}.recurly.com" redsys.base_url = "https://sis-t.redsys.es:25443/sis/realizarPago" riskified.base_url = "https://sandbox.riskified.com/api" shift4.base_url = "https://api.shift4.com/" diff --git a/scripts/add_connector.sh b/scripts/add_connector.sh index 046042bfa7..022e54a943 100755 --- a/scripts/add_connector.sh +++ b/scripts/add_connector.sh @@ -6,7 +6,7 @@ function find_prev_connector() { git checkout $self cp $self $self.tmp # Add new connector to existing list and sort it - connectors=(aci adyen adyenplatform airwallex amazonpay applepay authorizedotnet bambora bamboraapac bankofamerica billwerk bitpay bluesnap boku braintree cashtocode chargebee checkout coinbase cryptopay cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector ebanx elavon fiserv fiservemea fiuu forte getnet globalpay globepay gocardless gpayments helcim iatapay inespay itaubank jpmorgan klarna mifinity mollie moneris multisafepay netcetera nexinets nexixpay nomupay noon novalnet nuvei opayo opennode paybox payeezy payme payone paypal paystack payu placetopay plaid powertranz prophetpay rapyd razorpay redsys shift4 square stax stripe stripebilling taxjar threedsecureio thunes trustpay tsys unified_authentication_service volt wellsfargo wellsfargopayout wise worldline worldpay xendit zsl "$1") + connectors=(aci adyen adyenplatform airwallex amazonpay applepay authorizedotnet bambora bamboraapac bankofamerica billwerk bitpay bluesnap boku braintree cashtocode chargebee checkout coinbase cryptopay cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector ebanx elavon fiserv fiservemea fiuu forte getnet globalpay globepay gocardless gpayments helcim iatapay inespay itaubank jpmorgan klarna mifinity mollie moneris multisafepay netcetera nexinets nexixpay nomupay noon novalnet nuvei opayo opennode paybox payeezy payme payone paypal paystack payu placetopay plaid powertranz prophetpay rapyd razorpay recurly redsys shift4 square stax stripe stripebilling taxjar threedsecureio thunes trustpay tsys unified_authentication_service volt wellsfargo wellsfargopayout wise worldline worldpay xendit zsl "$1") IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFS res="$(echo ${sorted[@]})" sed -i'' -e "s/^ connectors=.*/ connectors=($res \"\$1\")/" $self.tmp