diff --git a/config/config.example.toml b/config/config.example.toml index 4fb7ea8f8f..3fdb96eb43 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -290,6 +290,7 @@ redsys.base_url = "https://sis-t.redsys.es:25443" riskified.base_url = "https://sandbox.riskified.com/api" santander.base_url = "https://pix.santander.com.br/api/v1/sandbox/" shift4.base_url = "https://api.shift4.com/" +sift.base_url = "https://api.sift.com/v205" silverflow.base_url = "https://api-sbx.silverflow.co/v1" signifyd.base_url = "https://api.signifyd.com/" square.base_url = "https://connect.squareupsandbox.com/" diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml index 34cc63b8f7..4607d92000 100644 --- a/config/deployments/integration_test.toml +++ b/config/deployments/integration_test.toml @@ -126,6 +126,7 @@ recurly.base_url = "https://v3.recurly.com" redsys.base_url = "https://sis-t.redsys.es:25443" santander.base_url = "https://pix.santander.com.br/api/v1/sandbox/" shift4.base_url = "https://api.shift4.com/" +sift.base_url = "https://api.sift.com/v205" silverflow.base_url = "https://api-sbx.silverflow.co/v1" signifyd.base_url = "https://api.signifyd.com/" riskified.base_url = "https://sandbox.riskified.com/api" diff --git a/config/deployments/production.toml b/config/deployments/production.toml index a2031c3b55..7a1521001c 100644 --- a/config/deployments/production.toml +++ b/config/deployments/production.toml @@ -131,6 +131,7 @@ redsys.base_url = "https://sis.redsys.es" riskified.base_url = "https://wh.riskified.com/api/" santander.base_url = "https://trust-pix.santander.com.br/" shift4.base_url = "https://api.shift4.com/" +sift.base_url = "https://api.sift.com/v205" silverflow.base_url = "https://api.silverflow.co/v1" signifyd.base_url = "https://api.signifyd.com/" square.base_url = "https://connect.squareup.com/" diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml index c9f671d813..88e7d4115e 100644 --- a/config/deployments/sandbox.toml +++ b/config/deployments/sandbox.toml @@ -131,6 +131,7 @@ redsys.base_url = "https://sis-t.redsys.es:25443" riskified.base_url = "https://sandbox.riskified.com/api" santander.base_url = "https://pix.santander.com.br/api/v1/sandbox/" shift4.base_url = "https://api.shift4.com/" +sift.base_url = "https://api.sift.com/v205" silverflow.base_url = "https://api-sbx.silverflow.co/v1" signifyd.base_url = "https://api.signifyd.com/" square.base_url = "https://connect.squareupsandbox.com/" diff --git a/config/development.toml b/config/development.toml index 8c3402c4ce..9020c89ef8 100644 --- a/config/development.toml +++ b/config/development.toml @@ -329,6 +329,7 @@ redsys.base_url = "https://sis-t.redsys.es:25443" riskified.base_url = "https://sandbox.riskified.com/api" santander.base_url = "https://pix.santander.com.br/api/v1/sandbox/" shift4.base_url = "https://api.shift4.com/" +sift.base_url = "https://api.sift.com/v205" silverflow.base_url = "https://api-sbx.silverflow.co/v1" signifyd.base_url = "https://api.signifyd.com/" square.base_url = "https://connect.squareupsandbox.com/" diff --git a/config/docker_compose.toml b/config/docker_compose.toml index 728dab571e..c518574435 100644 --- a/config/docker_compose.toml +++ b/config/docker_compose.toml @@ -216,6 +216,7 @@ redsys.base_url = "https://sis-t.redsys.es:25443" riskified.base_url = "https://sandbox.riskified.com/api" santander.base_url = "https://pix.santander.com.br/api/v1/sandbox/" shift4.base_url = "https://api.shift4.com/" +sift.base_url = "https://api.sift.com/v205" silverflow.base_url = "https://api-sbx.silverflow.co/v1" signifyd.base_url = "https://api.signifyd.com/" square.base_url = "https://connect.squareupsandbox.com/" diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs index 3ee75b85a9..7289e6d4a9 100644 --- a/crates/connector_configs/src/connector.rs +++ b/crates/connector_configs/src/connector.rs @@ -285,6 +285,7 @@ pub struct ConnectorConfig { pub redsys: Option, pub santander: Option, pub shift4: Option, + pub sift: Option, pub silverflow: Option, pub stripe: Option, #[cfg(feature = "payouts")] diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.toml index 7fb4a3759e..5f38b42d4a 100644 --- a/crates/connector_configs/toml/development.toml +++ b/crates/connector_configs/toml/development.toml @@ -6591,6 +6591,10 @@ merchant_secret="Source verification key" [katapult.connector_auth.HeaderKey] api_key = "API Key" +[sift] +[sift.connector_auth.HeaderKey] +api_key = "API Key" + [flexiti] [flexiti.connector_auth.BodyKey] api_key = "Client id" diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.toml index 70ef2d2a3e..4bb725ed12 100644 --- a/crates/connector_configs/toml/production.toml +++ b/crates/connector_configs/toml/production.toml @@ -5212,3 +5212,7 @@ merchant_secret="Source verification key" [katapult] [katapult.connector_auth.HeaderKey] api_key = "API Key" + +[sift] +[sift.connector_auth.HeaderKey] +api_key = "API Key" diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.toml index 4920a4f7bd..3b17bfca44 100644 --- a/crates/connector_configs/toml/sandbox.toml +++ b/crates/connector_configs/toml/sandbox.toml @@ -6570,6 +6570,10 @@ merchant_secret="Source verification key" [katapult.connector_auth.HeaderKey] api_key = "API Key" +[sift] +[sift.connector_auth.HeaderKey] +api_key = "API Key" + [flexiti] [flexiti.connector_auth.BodyKey] api_key = "Client id" diff --git a/crates/hyperswitch_connectors/src/connectors.rs b/crates/hyperswitch_connectors/src/connectors.rs index e2b648e75e..b0b440b5b5 100644 --- a/crates/hyperswitch_connectors/src/connectors.rs +++ b/crates/hyperswitch_connectors/src/connectors.rs @@ -97,6 +97,7 @@ pub mod redsys; pub mod riskified; pub mod santander; pub mod shift4; +pub mod sift; pub mod signifyd; pub mod silverflow; pub mod square; @@ -148,7 +149,7 @@ pub use self::{ payme::Payme, payone::Payone, paypal::Paypal, paystack::Paystack, paytm::Paytm, payu::Payu, phonepe::Phonepe, placetopay::Placetopay, plaid::Plaid, powertranz::Powertranz, prophetpay::Prophetpay, rapyd::Rapyd, razorpay::Razorpay, recurly::Recurly, redsys::Redsys, - riskified::Riskified, santander::Santander, shift4::Shift4, signifyd::Signifyd, + riskified::Riskified, santander::Santander, shift4::Shift4, sift::Sift, signifyd::Signifyd, silverflow::Silverflow, square::Square, stax::Stax, stripe::Stripe, stripebilling::Stripebilling, taxjar::Taxjar, threedsecureio::Threedsecureio, thunes::Thunes, tokenio::Tokenio, trustpay::Trustpay, trustpayments::Trustpayments, tsys::Tsys, diff --git a/crates/hyperswitch_connectors/src/connectors/sift.rs b/crates/hyperswitch_connectors/src/connectors/sift.rs new file mode 100644 index 0000000000..101cda9e03 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/sift.rs @@ -0,0 +1,622 @@ +pub mod transformers; + +use std::sync::LazyLock; + +use common_enums::enums; +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::{ + payment_method_data::PaymentMethodData, + 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::{ + ConnectorInfo, PaymentsResponseData, RefundsResponseData, SupportedPaymentMethods, + }, + 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 sift; + +use crate::{constants::headers, types::ResponseRouterData, utils}; + +#[derive(Clone)] +pub struct Sift { + amount_converter: &'static (dyn AmountConvertor + Sync), +} + +impl Sift { + pub fn new() -> &'static Self { + &Self { + amount_converter: &StringMinorUnitForConnector, + } + } +} + +impl api::Payment for Sift {} +impl api::PaymentSession for Sift {} +impl api::ConnectorAccessToken for Sift {} +impl api::MandateSetup for Sift {} +impl api::PaymentAuthorize for Sift {} +impl api::PaymentSync for Sift {} +impl api::PaymentCapture for Sift {} +impl api::PaymentVoid for Sift {} +impl api::Refund for Sift {} +impl api::RefundExecute for Sift {} +impl api::RefundSync for Sift {} +impl api::PaymentToken for Sift {} + +impl ConnectorIntegration + for Sift +{ + // Not Implemented (R) +} + +impl ConnectorCommonExt for Sift +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 Sift { + fn id(&self) -> &'static str { + "sift" + } + + 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.sift.base_url.as_ref() + } + + fn get_auth_header( + &self, + auth_type: &ConnectorAuthType, + ) -> CustomResult)>, errors::ConnectorError> { + let auth = sift::SiftAuthType::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: sift::SiftErrorResponse = res + .response + .parse_struct("SiftErrorResponse") + .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + + event_builder.map(|i| i.set_response_body(&response)); + router_env::logger::info!(connector_response=?response); + + Ok(ErrorResponse { + status_code: res.status_code, + code: response.code, + message: response.message, + reason: response.reason, + attempt_status: None, + connector_transaction_id: None, + network_advice_code: None, + network_decline_code: None, + network_error_message: None, + }) + } +} + +impl ConnectorValidation for Sift { + fn validate_mandate_payment( + &self, + _pm_type: Option, + pm_data: PaymentMethodData, + ) -> CustomResult<(), errors::ConnectorError> { + match pm_data { + PaymentMethodData::Card(_) => Err(errors::ConnectorError::NotImplemented( + "validate_mandate_payment does not support cards".to_string(), + ) + .into()), + _ => Ok(()), + } + } + + fn validate_psync_reference_id( + &self, + _data: &PaymentsSyncData, + _is_three_ds: bool, + _status: enums::AttemptStatus, + _connector_meta_data: Option, + ) -> CustomResult<(), errors::ConnectorError> { + Ok(()) + } +} + +impl ConnectorIntegration for Sift { + //TODO: implement sessions flow +} + +impl ConnectorIntegration for Sift {} + +impl ConnectorIntegration for Sift {} + +impl ConnectorIntegration for Sift { + 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 = sift::SiftRouterData::from((amount, req)); + let connector_req = sift::SiftPaymentsRequest::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: sift::SiftPaymentsResponse = res + .response + .parse_struct("Sift 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 Sift { + 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: sift::SiftPaymentsResponse = res + .response + .parse_struct("sift 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 Sift { + 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: sift::SiftPaymentsResponse = res + .response + .parse_struct("Sift 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 Sift {} + +impl ConnectorIntegration for Sift { + 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 = sift::SiftRouterData::from((refund_amount, req)); + let connector_req = sift::SiftRefundRequest::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: sift::RefundResponse = res + .response + .parse_struct("sift 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 Sift { + 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: sift::RefundResponse = + res.response + .parse_struct("sift 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 Sift { + 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)) + } +} + +static SIFT_SUPPORTED_PAYMENT_METHODS: LazyLock = + LazyLock::new(SupportedPaymentMethods::new); + +static SIFT_CONNECTOR_INFO: ConnectorInfo = ConnectorInfo { + display_name: "Sift", + description: "Sift connector", + connector_type: enums::PaymentConnectorCategory::PaymentGateway, +}; + +static SIFT_SUPPORTED_WEBHOOK_FLOWS: [enums::EventClass; 0] = []; + +impl ConnectorSpecifications for Sift { + fn get_connector_about(&self) -> Option<&'static ConnectorInfo> { + Some(&SIFT_CONNECTOR_INFO) + } + + fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> { + Some(&*SIFT_SUPPORTED_PAYMENT_METHODS) + } + + fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> { + Some(&SIFT_SUPPORTED_WEBHOOK_FLOWS) + } +} diff --git a/crates/hyperswitch_connectors/src/connectors/sift/transformers.rs b/crates/hyperswitch_connectors/src/connectors/sift/transformers.rs new file mode 100644 index 0000000000..e0f9b6ba74 --- /dev/null +++ b/crates/hyperswitch_connectors/src/connectors/sift/transformers.rs @@ -0,0 +1,217 @@ +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}; + +//TODO: Fill the struct with respective fields +pub struct SiftRouterData { + 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 SiftRouterData { + 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 SiftPaymentsRequest { + amount: StringMinorUnit, + card: SiftCard, +} + +#[derive(Default, Debug, Serialize, Eq, PartialEq)] +pub struct SiftCard { + number: cards::CardNumber, + expiry_month: Secret, + expiry_year: Secret, + cvc: Secret, + complete: bool, +} + +impl TryFrom<&SiftRouterData<&PaymentsAuthorizeRouterData>> for SiftPaymentsRequest { + type Error = error_stack::Report; + fn try_from(item: &SiftRouterData<&PaymentsAuthorizeRouterData>) -> Result { + match item.router_data.request.payment_method_data.clone() { + PaymentMethodData::Card(_) => Err(errors::ConnectorError::NotImplemented( + "Card payment method not implemented".to_string(), + ) + .into()), + _ => Err(errors::ConnectorError::NotImplemented("Payment method".to_string()).into()), + } + } +} + +//TODO: Fill the struct with respective fields +// Auth Struct +pub struct SiftAuthType { + pub(super) api_key: Secret, +} + +impl TryFrom<&ConnectorAuthType> for SiftAuthType { + 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, Copy, Default, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum SiftPaymentStatus { + Succeeded, + Failed, + #[default] + Processing, +} + +impl From for common_enums::AttemptStatus { + fn from(item: SiftPaymentStatus) -> Self { + match item { + SiftPaymentStatus::Succeeded => Self::Charged, + SiftPaymentStatus::Failed => Self::Failure, + SiftPaymentStatus::Processing => Self::Authorizing, + } + } +} + +//TODO: Fill the struct with respective fields +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct SiftPaymentsResponse { + status: SiftPaymentStatus, + 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 SiftRefundRequest { + pub amount: StringMinorUnit, +} + +impl TryFrom<&SiftRouterData<&RefundsRouterData>> for SiftRefundRequest { + type Error = error_stack::Report; + fn try_from(item: &SiftRouterData<&RefundsRouterData>) -> Result { + Ok(Self { + amount: item.amount.to_owned(), + }) + } +} + +// Type definition for Refund Response + +#[allow(dead_code)] +#[derive(Debug, Copy, 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 SiftErrorResponse { + pub status_code: u16, + pub code: String, + pub message: String, + pub reason: Option, + pub network_advice_code: Option, + pub network_decline_code: Option, + pub network_error_message: Option, +} diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs index 22c87d0832..7df691d95a 100644 --- a/crates/hyperswitch_connectors/src/default_implementations.rs +++ b/crates/hyperswitch_connectors/src/default_implementations.rs @@ -242,6 +242,7 @@ default_imp_for_authorize_session_token!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -381,6 +382,7 @@ default_imp_for_calculate_tax!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -482,6 +484,7 @@ default_imp_for_session_update!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stripe, @@ -621,6 +624,7 @@ default_imp_for_post_session_tokens!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Square, @@ -758,6 +762,7 @@ default_imp_for_create_order!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Square, @@ -898,6 +903,7 @@ default_imp_for_update_metadata!( connectors::Redsys, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Square, @@ -1037,6 +1043,7 @@ default_imp_for_cancel_post_capture!( connectors::Redsys, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Square, @@ -1197,6 +1204,7 @@ default_imp_for_complete_authorize!( connectors::Recurly, connectors::Riskified, connectors::Santander, + connectors::Sift, connectors::Signifyd, connectors::Stax, connectors::Square, @@ -1333,6 +1341,7 @@ default_imp_for_incremental_authorization!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -1469,6 +1478,7 @@ default_imp_for_create_customer!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Square, @@ -1593,6 +1603,7 @@ default_imp_for_connector_redirect_response!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -1719,6 +1730,7 @@ default_imp_for_pre_processing_steps!( connectors::Recurly, connectors::Riskified, connectors::Santander, + connectors::Sift, connectors::Signifyd, connectors::Stax, connectors::Square, @@ -1855,6 +1867,7 @@ default_imp_for_post_processing_steps!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -1996,6 +2009,7 @@ default_imp_for_approve!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2137,6 +2151,7 @@ default_imp_for_reject!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2277,6 +2292,7 @@ default_imp_for_webhook_source_verification!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2417,6 +2433,7 @@ default_imp_for_accept_dispute!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2555,6 +2572,7 @@ default_imp_for_submit_evidence!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2692,6 +2710,7 @@ default_imp_for_defend_dispute!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2833,6 +2852,7 @@ default_imp_for_fetch_disputes!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2973,6 +2993,7 @@ default_imp_for_dispute_sync!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3120,6 +3141,7 @@ default_imp_for_file_upload!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3245,6 +3267,7 @@ default_imp_for_payouts!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Square, @@ -3381,6 +3404,7 @@ default_imp_for_payouts_create!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3520,6 +3544,7 @@ default_imp_for_payouts_retrieve!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3660,6 +3685,7 @@ default_imp_for_payouts_eligibility!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3795,6 +3821,7 @@ default_imp_for_payouts_fulfill!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3933,6 +3960,7 @@ default_imp_for_payouts_cancel!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -4072,6 +4100,7 @@ default_imp_for_payouts_quote!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -4212,6 +4241,7 @@ default_imp_for_payouts_recipient!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -4352,6 +4382,7 @@ default_imp_for_payouts_recipient_account!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -4493,6 +4524,7 @@ default_imp_for_frm_sale!( connectors::Redsys, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Square, @@ -4634,6 +4666,7 @@ default_imp_for_frm_checkout!( connectors::Redsys, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Square, @@ -4775,6 +4808,7 @@ default_imp_for_frm_transaction!( connectors::Redsys, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Square, @@ -4916,6 +4950,7 @@ default_imp_for_frm_fulfillment!( connectors::Redsys, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Square, @@ -5057,6 +5092,7 @@ default_imp_for_frm_record_return!( connectors::Redsys, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stripe, connectors::Stax, @@ -5193,6 +5229,7 @@ default_imp_for_revoking_mandates!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -5332,6 +5369,7 @@ default_imp_for_uas_pre_authentication!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stripe, @@ -5470,6 +5508,7 @@ default_imp_for_uas_post_authentication!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stripe, @@ -5609,6 +5648,7 @@ default_imp_for_uas_authentication_confirmation!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -5739,6 +5779,7 @@ default_imp_for_connector_request_id!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -5873,6 +5914,7 @@ default_imp_for_fraud_check!( connectors::Redsys, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Square, @@ -6035,6 +6077,7 @@ default_imp_for_connector_authentication!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -6172,6 +6215,7 @@ default_imp_for_uas_authentication!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -6304,6 +6348,7 @@ default_imp_for_revenue_recovery!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -6446,6 +6491,7 @@ default_imp_for_billing_connector_payment_sync!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stripe, @@ -6586,6 +6632,7 @@ default_imp_for_revenue_recovery_record_back!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stripe, @@ -6727,6 +6774,7 @@ default_imp_for_billing_connector_invoice_sync!( connectors::Santander, connectors::Signifyd, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Square, @@ -6861,6 +6909,7 @@ default_imp_for_external_vault!( connectors::Santander, connectors::Signifyd, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Stripe, @@ -7001,6 +7050,7 @@ default_imp_for_external_vault_insert!( connectors::Santander, connectors::Signifyd, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Stripe, @@ -7141,6 +7191,7 @@ default_imp_for_external_vault_retrieve!( connectors::Santander, connectors::Signifyd, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Stripe, @@ -7281,6 +7332,7 @@ default_imp_for_external_vault_delete!( connectors::Santander, connectors::Signifyd, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Stripe, @@ -7420,6 +7472,7 @@ default_imp_for_external_vault_create!( connectors::Santander, connectors::Signifyd, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Stax, connectors::Stripe, diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rs index c40ac1d346..69166f3e01 100644 --- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs +++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs @@ -354,6 +354,7 @@ default_imp_for_new_connector_integration_payment!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -495,6 +496,7 @@ default_imp_for_new_connector_integration_refund!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -631,6 +633,7 @@ default_imp_for_new_connector_integration_connector_access_token!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -772,6 +775,7 @@ default_imp_for_new_connector_integration_accept_dispute!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -913,6 +917,7 @@ default_imp_for_new_connector_integration_fetch_disputes!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Signifyd, connectors::Silverflow, connectors::Square, @@ -1055,6 +1060,7 @@ default_imp_for_new_connector_integration_dispute_sync!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Signifyd, connectors::Silverflow, connectors::Square, @@ -1197,6 +1203,7 @@ default_imp_for_new_connector_integration_defend_dispute!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -1337,6 +1344,7 @@ default_imp_for_new_connector_integration_submit_evidence!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -1488,6 +1496,7 @@ default_imp_for_new_connector_integration_file_upload!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -1631,6 +1640,7 @@ default_imp_for_new_connector_integration_payouts_create!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -1774,6 +1784,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -1917,6 +1928,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2060,6 +2072,7 @@ default_imp_for_new_connector_integration_payouts_cancel!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2203,6 +2216,7 @@ default_imp_for_new_connector_integration_payouts_quote!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2346,6 +2360,7 @@ default_imp_for_new_connector_integration_payouts_recipient!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2489,6 +2504,7 @@ default_imp_for_new_connector_integration_payouts_sync!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2632,6 +2648,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2773,6 +2790,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -2916,6 +2934,7 @@ default_imp_for_new_connector_integration_frm_sale!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3059,6 +3078,7 @@ default_imp_for_new_connector_integration_frm_checkout!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3202,6 +3222,7 @@ default_imp_for_new_connector_integration_frm_transaction!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3345,6 +3366,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3488,6 +3510,7 @@ default_imp_for_new_connector_integration_frm_record_return!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3627,6 +3650,7 @@ default_imp_for_new_connector_integration_revoking_mandates!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3739,6 +3763,7 @@ default_imp_for_new_connector_integration_frm!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -3877,6 +3902,7 @@ default_imp_for_new_connector_integration_connector_authentication!( connectors::Recurly, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -4007,6 +4033,7 @@ default_imp_for_new_connector_integration_revenue_recovery!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, @@ -4170,6 +4197,7 @@ default_imp_for_new_connector_integration_external_vault!( connectors::Riskified, connectors::Santander, connectors::Shift4, + connectors::Sift, connectors::Silverflow, connectors::Signifyd, connectors::Stax, diff --git a/crates/hyperswitch_domain_models/src/connector_endpoints.rs b/crates/hyperswitch_domain_models/src/connector_endpoints.rs index d9691d8382..ab6b031ee5 100644 --- a/crates/hyperswitch_domain_models/src/connector_endpoints.rs +++ b/crates/hyperswitch_domain_models/src/connector_endpoints.rs @@ -112,6 +112,7 @@ pub struct Connectors { pub riskified: ConnectorParams, pub santander: ConnectorParams, pub shift4: ConnectorParams, + pub sift: ConnectorParams, pub silverflow: ConnectorParams, pub signifyd: ConnectorParams, pub square: ConnectorParams, diff --git a/crates/router/src/connector.rs b/crates/router/src/connector.rs index a54c1e4840..def4e3cff0 100644 --- a/crates/router/src/connector.rs +++ b/crates/router/src/connector.rs @@ -36,14 +36,15 @@ pub use hyperswitch_connectors::connectors::{ placetopay::Placetopay, plaid, plaid::Plaid, powertranz, powertranz::Powertranz, prophetpay, prophetpay::Prophetpay, rapyd, rapyd::Rapyd, razorpay, razorpay::Razorpay, recurly, recurly::Recurly, redsys, redsys::Redsys, riskified, riskified::Riskified, santander, - santander::Santander, shift4, shift4::Shift4, signifyd, signifyd::Signifyd, silverflow, - silverflow::Silverflow, square, square::Square, stax, stax::Stax, stripe, stripe::Stripe, - stripebilling, stripebilling::Stripebilling, taxjar, taxjar::Taxjar, threedsecureio, - threedsecureio::Threedsecureio, thunes, thunes::Thunes, tokenio, tokenio::Tokenio, trustpay, - trustpay::Trustpay, trustpayments, trustpayments::Trustpayments, tsys, tsys::Tsys, - unified_authentication_service, unified_authentication_service::UnifiedAuthenticationService, - vgs, vgs::Vgs, volt, volt::Volt, wellsfargo, wellsfargo::Wellsfargo, wellsfargopayout, - wellsfargopayout::Wellsfargopayout, wise, wise::Wise, worldline, worldline::Worldline, - worldpay, worldpay::Worldpay, worldpayvantiv, worldpayvantiv::Worldpayvantiv, worldpayxml, - worldpayxml::Worldpayxml, xendit, xendit::Xendit, zen, zen::Zen, zsl, zsl::Zsl, + santander::Santander, shift4, shift4::Shift4, sift, sift::Sift, signifyd, signifyd::Signifyd, + silverflow, silverflow::Silverflow, square, square::Square, stax, stax::Stax, stripe, + stripe::Stripe, stripebilling, stripebilling::Stripebilling, taxjar, taxjar::Taxjar, + threedsecureio, threedsecureio::Threedsecureio, thunes, thunes::Thunes, tokenio, + tokenio::Tokenio, trustpay, trustpay::Trustpay, trustpayments, trustpayments::Trustpayments, + tsys, tsys::Tsys, unified_authentication_service, + unified_authentication_service::UnifiedAuthenticationService, vgs, vgs::Vgs, volt, volt::Volt, + wellsfargo, wellsfargo::Wellsfargo, wellsfargopayout, wellsfargopayout::Wellsfargopayout, wise, + wise::Wise, worldline, worldline::Worldline, worldpay, worldpay::Worldpay, worldpayvantiv, + worldpayvantiv::Worldpayvantiv, worldpayxml, worldpayxml::Worldpayxml, xendit, xendit::Xendit, + zen, zen::Zen, zsl, zsl::Zsl, }; diff --git a/crates/router/tests/connectors/main.rs b/crates/router/tests/connectors/main.rs index 5189e4cc01..7f3c170104 100644 --- a/crates/router/tests/connectors/main.rs +++ b/crates/router/tests/connectors/main.rs @@ -100,6 +100,7 @@ mod razorpay; mod redsys; mod santander; mod shift4; +mod sift; mod silverflow; mod square; mod stax; diff --git a/crates/router/tests/connectors/sift.rs b/crates/router/tests/connectors/sift.rs new file mode 100644 index 0000000000..815ce9cdb2 --- /dev/null +++ b/crates/router/tests/connectors/sift.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 SiftTest; +impl ConnectorActions for SiftTest {} +impl utils::Connector for SiftTest { + fn get_data(&self) -> api::ConnectorData { + use router::connector::Sift; + utils::construct_connector_data_old( + Box::new(Sift::new()), + types::Connector::Plaid, + api::GetToken::Connector, + None, + ) + } + + fn get_auth_token(&self) -> types::ConnectorAuthType { + utils::to_connector_auth_type( + connector_auth::ConnectorAuthentication::new() + .sift + .expect("Missing connector authentication configuration") + .into(), + ) + } + + fn get_name(&self) -> String { + "sift".to_string() + } +} + +static CONNECTOR: SiftTest = SiftTest {}; + +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/test_utils/src/connector_auth.rs b/crates/test_utils/src/connector_auth.rs index b14a190bd6..3829fc17eb 100644 --- a/crates/test_utils/src/connector_auth.rs +++ b/crates/test_utils/src/connector_auth.rs @@ -107,6 +107,7 @@ pub struct ConnectorAuthentication { pub redsys: Option, pub santander: Option, pub shift4: Option, + pub sift: Option, pub silverflow: Option, pub square: Option, pub stax: Option, diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml index 90552d1a76..adb2d4a249 100644 --- a/loadtest/config/development.toml +++ b/loadtest/config/development.toml @@ -183,6 +183,7 @@ redsys.base_url = "https://sis-t.redsys.es:25443" riskified.base_url = "https://sandbox.riskified.com/api" santander.base_url = "https://pix.santander.com.br/api/v1/sandbox/" shift4.base_url = "https://api.shift4.com/" +sift.base_url = "https://api.sift.com/v205" silverflow.base_url = "https://api-sbx.silverflow.co/v1" signifyd.base_url = "https://api.signifyd.com/" square.base_url = "https://connect.squareupsandbox.com/" diff --git a/scripts/add_connector.sh b/scripts/add_connector.sh index 2f56916090..e909c144d1 100755 --- a/scripts/add_connector.sh +++ b/scripts/add_connector.sh @@ -6,7 +6,7 @@ function find_prev_connector() { git checkout $self cp $self $self.tmp # Add new connector to existing list and sort it - connectors=(aci adyen adyenplatform affirm airwallex amazonpay applepay archipel authipay authorizedotnet bambora bamboraapac bankofamerica barclaycard billwerk bitpay blackhawknetwork bluecode bluesnap boku braintree breadpay cashtocode celero chargebee checkbook checkout coinbase cryptopay ctp_visa custombilling cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector dwolla ebanx elavon facilitapay fiserv fiservemea fiuu flexiti forte getnet globalpay globepay gocardless gpayments helcim hipay hyperswitch_vault iatapay inespay itaubank jpmorgan juspaythreedsserver katapult klarna mifinity mollie moneris mpgs multisafepay netcetera nexinets nexixpay nomupay noon nordea novalnet nuvei opayo opennode paybox payeezy payload payme payone paypal paystack paytm payu phonepe placetopay plaid powertranz prophetpay rapyd razorpay recurly redsys santander shift4 silverflow square stax stripe stripebilling taxjar threedsecureio thunes tokenio trustpay trustpayments tsys unified_authentication_service vgs volt wellsfargo wellsfargopayout wise worldline worldpay worldpayvantiv worldpayxml xendit zsl "$1") + connectors=(aci adyen adyenplatform affirm airwallex amazonpay applepay archipel authipay authorizedotnet bambora bamboraapac bankofamerica barclaycard billwerk bitpay blackhawknetwork bluecode bluesnap boku braintree breadpay cashtocode celero chargebee checkbook checkout coinbase cryptopay ctp_visa custombilling cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector dwolla ebanx elavon facilitapay fiserv fiservemea fiuu flexiti forte getnet globalpay globepay gocardless gpayments helcim hipay hyperswitch_vault iatapay inespay itaubank jpmorgan juspaythreedsserver katapult klarna mifinity mollie moneris mpgs multisafepay netcetera nexinets nexixpay nomupay noon nordea novalnet nuvei opayo opennode paybox payeezy payload payme payone paypal paystack paytm payu phonepe placetopay plaid powertranz prophetpay rapyd razorpay recurly redsys santander shift4 sift silverflow square stax stripe stripebilling taxjar threedsecureio thunes tokenio trustpay trustpayments tsys unified_authentication_service vgs volt wellsfargo wellsfargopayout wise worldline worldpay worldpayvantiv worldpayxml xendit zsl "$1") IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFS