mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 11:24:45 +08:00
feat(connector): [REDSYS] add Connector Template Code (#6659)
This commit is contained in:
committed by
GitHub
parent
ae7d16e236
commit
19cbcdd979
@ -252,6 +252,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/"
|
||||
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/"
|
||||
signifyd.base_url = "https://api.signifyd.com/"
|
||||
|
||||
@ -93,6 +93,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/"
|
||||
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/"
|
||||
riskified.base_url = "https://sandbox.riskified.com/api"
|
||||
|
||||
@ -97,6 +97,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"
|
||||
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/"
|
||||
signifyd.base_url = "https://api.signifyd.com/"
|
||||
|
||||
@ -97,6 +97,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/"
|
||||
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/"
|
||||
signifyd.base_url = "https://api.signifyd.com/"
|
||||
|
||||
@ -155,6 +155,7 @@ cards = [
|
||||
"plaid",
|
||||
"powertranz",
|
||||
"prophetpay",
|
||||
"redsys",
|
||||
"shift4",
|
||||
"square",
|
||||
"stax",
|
||||
@ -268,6 +269,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/"
|
||||
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/"
|
||||
signifyd.base_url = "https://api.signifyd.com/"
|
||||
|
||||
@ -183,6 +183,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/"
|
||||
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/"
|
||||
signifyd.base_url = "https://api.signifyd.com/"
|
||||
@ -276,6 +277,7 @@ cards = [
|
||||
"plaid",
|
||||
"powertranz",
|
||||
"prophetpay",
|
||||
"redsys",
|
||||
"shift4",
|
||||
"square",
|
||||
"stax",
|
||||
|
||||
@ -113,6 +113,7 @@ pub enum Connector {
|
||||
Prophetpay,
|
||||
Rapyd,
|
||||
Razorpay,
|
||||
// Redsys,
|
||||
Shift4,
|
||||
Square,
|
||||
Stax,
|
||||
@ -251,6 +252,7 @@ impl Connector {
|
||||
| Self::Powertranz
|
||||
| Self::Prophetpay
|
||||
| Self::Rapyd
|
||||
// | Self::Redsys
|
||||
| Self::Shift4
|
||||
| Self::Square
|
||||
| Self::Stax
|
||||
|
||||
@ -108,6 +108,7 @@ pub enum RoutableConnectors {
|
||||
Prophetpay,
|
||||
Rapyd,
|
||||
Razorpay,
|
||||
// Redsys,
|
||||
Riskified,
|
||||
Shift4,
|
||||
Signifyd,
|
||||
|
||||
@ -28,6 +28,7 @@ pub mod payeezy;
|
||||
pub mod payu;
|
||||
pub mod powertranz;
|
||||
pub mod razorpay;
|
||||
pub mod redsys;
|
||||
pub mod shift4;
|
||||
pub mod square;
|
||||
pub mod stax;
|
||||
@ -49,6 +50,7 @@ pub use self::{
|
||||
helcim::Helcim, inespay::Inespay, jpmorgan::Jpmorgan, mollie::Mollie,
|
||||
multisafepay::Multisafepay, nexinets::Nexinets, nexixpay::Nexixpay, nomupay::Nomupay,
|
||||
novalnet::Novalnet, payeezy::Payeezy, payu::Payu, powertranz::Powertranz, razorpay::Razorpay,
|
||||
shift4::Shift4, square::Square, stax::Stax, taxjar::Taxjar, thunes::Thunes, tsys::Tsys,
|
||||
volt::Volt, worldline::Worldline, worldpay::Worldpay, xendit::Xendit, zen::Zen, zsl::Zsl,
|
||||
redsys::Redsys, shift4::Shift4, square::Square, stax::Stax, taxjar::Taxjar, thunes::Thunes,
|
||||
tsys::Tsys, volt::Volt, worldline::Worldline, worldpay::Worldpay, xendit::Xendit, zen::Zen,
|
||||
zsl::Zsl,
|
||||
};
|
||||
|
||||
563
crates/hyperswitch_connectors/src/connectors/redsys.rs
Normal file
563
crates/hyperswitch_connectors/src/connectors/redsys.rs
Normal file
@ -0,0 +1,563 @@
|
||||
pub mod transformers;
|
||||
|
||||
use common_utils::{
|
||||
errors::CustomResult,
|
||||
ext_traits::BytesExt,
|
||||
request::{Method, Request, RequestBuilder, RequestContent},
|
||||
types::{AmountConvertor, StringMinorUnit, StringMinorUnitForConnector},
|
||||
};
|
||||
use error_stack::{report, ResultExt};
|
||||
use hyperswitch_domain_models::{
|
||||
router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
|
||||
router_flow_types::{
|
||||
access_token_auth::AccessTokenAuth,
|
||||
payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void},
|
||||
refunds::{Execute, RSync},
|
||||
},
|
||||
router_request_types::{
|
||||
AccessTokenRequestData, PaymentMethodTokenizationData, PaymentsAuthorizeData,
|
||||
PaymentsCancelData, PaymentsCaptureData, PaymentsSessionData, PaymentsSyncData,
|
||||
RefundsData, SetupMandateRequestData,
|
||||
},
|
||||
router_response_types::{PaymentsResponseData, RefundsResponseData},
|
||||
types::{
|
||||
PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData,
|
||||
RefundSyncRouterData, RefundsRouterData,
|
||||
},
|
||||
};
|
||||
use hyperswitch_interfaces::{
|
||||
api::{self, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, ConnectorValidation},
|
||||
configs::Connectors,
|
||||
errors,
|
||||
events::connector_api_logs::ConnectorEvent,
|
||||
types::{self, Response},
|
||||
webhooks,
|
||||
};
|
||||
use masking::{ExposeInterface, Mask};
|
||||
use transformers as redsys;
|
||||
|
||||
use crate::{constants::headers, types::ResponseRouterData, utils};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Redsys {
|
||||
amount_converter: &'static (dyn AmountConvertor<Output = StringMinorUnit> + Sync),
|
||||
}
|
||||
|
||||
impl Redsys {
|
||||
pub fn new() -> &'static Self {
|
||||
&Self {
|
||||
amount_converter: &StringMinorUnitForConnector,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl api::Payment for Redsys {}
|
||||
impl api::PaymentSession for Redsys {}
|
||||
impl api::ConnectorAccessToken for Redsys {}
|
||||
impl api::MandateSetup for Redsys {}
|
||||
impl api::PaymentAuthorize for Redsys {}
|
||||
impl api::PaymentSync for Redsys {}
|
||||
impl api::PaymentCapture for Redsys {}
|
||||
impl api::PaymentVoid for Redsys {}
|
||||
impl api::Refund for Redsys {}
|
||||
impl api::RefundExecute for Redsys {}
|
||||
impl api::RefundSync for Redsys {}
|
||||
impl api::PaymentToken for Redsys {}
|
||||
|
||||
impl ConnectorIntegration<PaymentMethodToken, PaymentMethodTokenizationData, PaymentsResponseData>
|
||||
for Redsys
|
||||
{
|
||||
// Not Implemented (R)
|
||||
}
|
||||
|
||||
impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for Redsys
|
||||
where
|
||||
Self: ConnectorIntegration<Flow, Request, Response>,
|
||||
{
|
||||
fn build_headers(
|
||||
&self,
|
||||
req: &RouterData<Flow, Request, Response>,
|
||||
_connectors: &Connectors,
|
||||
) -> CustomResult<Vec<(String, masking::Maskable<String>)>, 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 Redsys {
|
||||
fn id(&self) -> &'static str {
|
||||
"redsys"
|
||||
}
|
||||
|
||||
fn get_currency_unit(&self) -> api::CurrencyUnit {
|
||||
api::CurrencyUnit::Base
|
||||
// TODO! Check connector documentation, on which unit they are processing the currency.
|
||||
// If the connector accepts amount in lower unit ( i.e cents for USD) then return api::CurrencyUnit::Minor,
|
||||
// if connector accepts amount in base unit (i.e dollars for USD) then return api::CurrencyUnit::Base
|
||||
}
|
||||
|
||||
fn common_get_content_type(&self) -> &'static str {
|
||||
"application/json"
|
||||
}
|
||||
|
||||
fn base_url<'a>(&self, connectors: &'a Connectors) -> &'a str {
|
||||
connectors.redsys.base_url.as_ref()
|
||||
}
|
||||
|
||||
fn get_auth_header(
|
||||
&self,
|
||||
auth_type: &ConnectorAuthType,
|
||||
) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
|
||||
let auth = redsys::RedsysAuthType::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<ErrorResponse, errors::ConnectorError> {
|
||||
let response: redsys::RedsysErrorResponse = res
|
||||
.response
|
||||
.parse_struct("RedsysErrorResponse")
|
||||
.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 Redsys {
|
||||
//TODO: implement functions when support enabled
|
||||
}
|
||||
|
||||
impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> for Redsys {
|
||||
//TODO: implement sessions flow
|
||||
}
|
||||
|
||||
impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken> for Redsys {}
|
||||
|
||||
impl ConnectorIntegration<SetupMandate, SetupMandateRequestData, PaymentsResponseData> for Redsys {}
|
||||
|
||||
impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData> for Redsys {
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &PaymentsAuthorizeRouterData,
|
||||
connectors: &Connectors,
|
||||
) -> CustomResult<Vec<(String, masking::Maskable<String>)>, 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<String, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
|
||||
}
|
||||
|
||||
fn get_request_body(
|
||||
&self,
|
||||
req: &PaymentsAuthorizeRouterData,
|
||||
_connectors: &Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let amount = utils::convert_amount(
|
||||
self.amount_converter,
|
||||
req.request.minor_amount,
|
||||
req.request.currency,
|
||||
)?;
|
||||
|
||||
let connector_router_data = redsys::RedsysRouterData::from((amount, req));
|
||||
let connector_req = redsys::RedsysPaymentsRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(connector_req)))
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &PaymentsAuthorizeRouterData,
|
||||
connectors: &Connectors,
|
||||
) -> CustomResult<Option<Request>, 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<PaymentsAuthorizeRouterData, errors::ConnectorError> {
|
||||
let response: redsys::RedsysPaymentsResponse = res
|
||||
.response
|
||||
.parse_struct("Redsys 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<ErrorResponse, errors::ConnectorError> {
|
||||
self.build_error_response(res, event_builder)
|
||||
}
|
||||
}
|
||||
|
||||
impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Redsys {
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &PaymentsSyncRouterData,
|
||||
connectors: &Connectors,
|
||||
) -> CustomResult<Vec<(String, masking::Maskable<String>)>, 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<String, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &PaymentsSyncRouterData,
|
||||
connectors: &Connectors,
|
||||
) -> CustomResult<Option<Request>, 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<PaymentsSyncRouterData, errors::ConnectorError> {
|
||||
let response: redsys::RedsysPaymentsResponse = res
|
||||
.response
|
||||
.parse_struct("redsys 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<ErrorResponse, errors::ConnectorError> {
|
||||
self.build_error_response(res, event_builder)
|
||||
}
|
||||
}
|
||||
|
||||
impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> for Redsys {
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &PaymentsCaptureRouterData,
|
||||
connectors: &Connectors,
|
||||
) -> CustomResult<Vec<(String, masking::Maskable<String>)>, 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<String, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
|
||||
}
|
||||
|
||||
fn get_request_body(
|
||||
&self,
|
||||
_req: &PaymentsCaptureRouterData,
|
||||
_connectors: &Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into())
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &PaymentsCaptureRouterData,
|
||||
connectors: &Connectors,
|
||||
) -> CustomResult<Option<Request>, 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<PaymentsCaptureRouterData, errors::ConnectorError> {
|
||||
let response: redsys::RedsysPaymentsResponse = res
|
||||
.response
|
||||
.parse_struct("Redsys 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<ErrorResponse, errors::ConnectorError> {
|
||||
self.build_error_response(res, event_builder)
|
||||
}
|
||||
}
|
||||
|
||||
impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Redsys {}
|
||||
|
||||
impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Redsys {
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &RefundsRouterData<Execute>,
|
||||
connectors: &Connectors,
|
||||
) -> CustomResult<Vec<(String, masking::Maskable<String>)>, 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<Execute>,
|
||||
_connectors: &Connectors,
|
||||
) -> CustomResult<String, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
|
||||
}
|
||||
|
||||
fn get_request_body(
|
||||
&self,
|
||||
req: &RefundsRouterData<Execute>,
|
||||
_connectors: &Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let refund_amount = utils::convert_amount(
|
||||
self.amount_converter,
|
||||
req.request.minor_refund_amount,
|
||||
req.request.currency,
|
||||
)?;
|
||||
|
||||
let connector_router_data = redsys::RedsysRouterData::from((refund_amount, req));
|
||||
let connector_req = redsys::RedsysRefundRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(connector_req)))
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &RefundsRouterData<Execute>,
|
||||
connectors: &Connectors,
|
||||
) -> CustomResult<Option<Request>, 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<Execute>,
|
||||
event_builder: Option<&mut ConnectorEvent>,
|
||||
res: Response,
|
||||
) -> CustomResult<RefundsRouterData<Execute>, errors::ConnectorError> {
|
||||
let response: redsys::RefundResponse =
|
||||
res.response
|
||||
.parse_struct("redsys 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<ErrorResponse, errors::ConnectorError> {
|
||||
self.build_error_response(res, event_builder)
|
||||
}
|
||||
}
|
||||
|
||||
impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Redsys {
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &RefundSyncRouterData,
|
||||
connectors: &Connectors,
|
||||
) -> CustomResult<Vec<(String, masking::Maskable<String>)>, 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<String, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &RefundSyncRouterData,
|
||||
connectors: &Connectors,
|
||||
) -> CustomResult<Option<Request>, 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<RefundSyncRouterData, errors::ConnectorError> {
|
||||
let response: redsys::RefundResponse = res
|
||||
.response
|
||||
.parse_struct("redsys 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<ErrorResponse, errors::ConnectorError> {
|
||||
self.build_error_response(res, event_builder)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl webhooks::IncomingWebhook for Redsys {
|
||||
fn get_webhook_object_reference_id(
|
||||
&self,
|
||||
_request: &webhooks::IncomingWebhookRequestDetails<'_>,
|
||||
) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError> {
|
||||
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
|
||||
}
|
||||
|
||||
fn get_webhook_event_type(
|
||||
&self,
|
||||
_request: &webhooks::IncomingWebhookRequestDetails<'_>,
|
||||
) -> CustomResult<api_models::webhooks::IncomingWebhookEvent, errors::ConnectorError> {
|
||||
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
|
||||
}
|
||||
|
||||
fn get_webhook_resource_object(
|
||||
&self,
|
||||
_request: &webhooks::IncomingWebhookRequestDetails<'_>,
|
||||
) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
|
||||
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
|
||||
}
|
||||
}
|
||||
@ -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 RedsysRouterData<T> {
|
||||
pub amount: StringMinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
|
||||
pub router_data: T,
|
||||
}
|
||||
|
||||
impl<T> From<(StringMinorUnit, T)> for RedsysRouterData<T> {
|
||||
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 RedsysPaymentsRequest {
|
||||
amount: StringMinorUnit,
|
||||
card: RedsysCard,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
|
||||
pub struct RedsysCard {
|
||||
number: cards::CardNumber,
|
||||
expiry_month: Secret<String>,
|
||||
expiry_year: Secret<String>,
|
||||
cvc: Secret<String>,
|
||||
complete: bool,
|
||||
}
|
||||
|
||||
impl TryFrom<&RedsysRouterData<&PaymentsAuthorizeRouterData>> for RedsysPaymentsRequest {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: &RedsysRouterData<&PaymentsAuthorizeRouterData>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
match item.router_data.request.payment_method_data.clone() {
|
||||
PaymentMethodData::Card(req_card) => {
|
||||
let card = RedsysCard {
|
||||
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 RedsysAuthType {
|
||||
pub(super) api_key: Secret<String>,
|
||||
}
|
||||
|
||||
impl TryFrom<&ConnectorAuthType> for RedsysAuthType {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(auth_type: &ConnectorAuthType) -> Result<Self, Self::Error> {
|
||||
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 RedsysPaymentStatus {
|
||||
Succeeded,
|
||||
Failed,
|
||||
#[default]
|
||||
Processing,
|
||||
}
|
||||
|
||||
impl From<RedsysPaymentStatus> for common_enums::AttemptStatus {
|
||||
fn from(item: RedsysPaymentStatus) -> Self {
|
||||
match item {
|
||||
RedsysPaymentStatus::Succeeded => Self::Charged,
|
||||
RedsysPaymentStatus::Failed => Self::Failure,
|
||||
RedsysPaymentStatus::Processing => Self::Authorizing,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Fill the struct with respective fields
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct RedsysPaymentsResponse {
|
||||
status: RedsysPaymentStatus,
|
||||
id: String,
|
||||
}
|
||||
|
||||
impl<F, T> TryFrom<ResponseRouterData<F, RedsysPaymentsResponse, T, PaymentsResponseData>>
|
||||
for RouterData<F, T, PaymentsResponseData>
|
||||
{
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: ResponseRouterData<F, RedsysPaymentsResponse, T, PaymentsResponseData>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
status: common_enums::AttemptStatus::from(item.response.status),
|
||||
response: Ok(PaymentsResponseData::TransactionResponse {
|
||||
resource_id: ResponseId::ConnectorTransactionId(item.response.id),
|
||||
redirection_data: Box::new(None),
|
||||
mandate_reference: Box::new(None),
|
||||
connector_metadata: None,
|
||||
network_txn_id: None,
|
||||
connector_response_reference_id: None,
|
||||
incremental_authorization_allowed: None,
|
||||
charge_id: None,
|
||||
}),
|
||||
..item.data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Fill the struct with respective fields
|
||||
// REFUND :
|
||||
// Type definition for RefundRequest
|
||||
#[derive(Default, Debug, Serialize)]
|
||||
pub struct RedsysRefundRequest {
|
||||
pub amount: StringMinorUnit,
|
||||
}
|
||||
|
||||
impl<F> TryFrom<&RedsysRouterData<&RefundsRouterData<F>>> for RedsysRefundRequest {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(item: &RedsysRouterData<&RefundsRouterData<F>>) -> Result<Self, Self::Error> {
|
||||
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<RefundStatus> 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<RefundsResponseRouterData<Execute, RefundResponse>> for RefundsRouterData<Execute> {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: RefundsResponseRouterData<Execute, RefundResponse>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
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<RefundsResponseRouterData<RSync, RefundResponse>> for RefundsRouterData<RSync> {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: RefundsResponseRouterData<RSync, RefundResponse>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
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 RedsysErrorResponse {
|
||||
pub status_code: u16,
|
||||
pub code: String,
|
||||
pub message: String,
|
||||
pub reason: Option<String>,
|
||||
}
|
||||
@ -119,6 +119,7 @@ default_imp_for_authorize_session_token!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Taxjar,
|
||||
@ -177,6 +178,7 @@ default_imp_for_calculate_tax!(
|
||||
connectors::Payu,
|
||||
connectors::Powertranz,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -223,6 +225,7 @@ default_imp_for_session_update!(
|
||||
connectors::Inespay,
|
||||
connectors::Jpmorgan,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -283,6 +286,7 @@ default_imp_for_post_session_tokens!(
|
||||
connectors::Inespay,
|
||||
connectors::Jpmorgan,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Taxjar,
|
||||
@ -348,6 +352,7 @@ default_imp_for_complete_authorize!(
|
||||
connectors::Payeezy,
|
||||
connectors::Payu,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
connectors::Taxjar,
|
||||
@ -406,6 +411,7 @@ default_imp_for_incremental_authorization!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -466,6 +472,7 @@ default_imp_for_create_customer!(
|
||||
connectors::Payu,
|
||||
connectors::Powertranz,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Square,
|
||||
connectors::Taxjar,
|
||||
@ -522,6 +529,7 @@ default_imp_for_connector_redirect_response!(
|
||||
connectors::Payu,
|
||||
connectors::Powertranz,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -578,6 +586,7 @@ default_imp_for_pre_processing_steps!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
connectors::Taxjar,
|
||||
@ -637,6 +646,7 @@ default_imp_for_post_processing_steps!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -697,6 +707,7 @@ default_imp_for_approve!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -757,6 +768,7 @@ default_imp_for_reject!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -817,6 +829,7 @@ default_imp_for_webhook_source_verification!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -878,6 +891,7 @@ default_imp_for_accept_dispute!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -938,6 +952,7 @@ default_imp_for_submit_evidence!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -998,6 +1013,7 @@ default_imp_for_defend_dispute!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1067,6 +1083,7 @@ default_imp_for_file_upload!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1120,6 +1137,7 @@ default_imp_for_payouts!(
|
||||
connectors::Payu,
|
||||
connectors::Powertranz,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Square,
|
||||
connectors::Stax,
|
||||
@ -1181,6 +1199,7 @@ default_imp_for_payouts_create!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1243,6 +1262,7 @@ default_imp_for_payouts_retrieve!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1305,6 +1325,7 @@ default_imp_for_payouts_eligibility!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1367,6 +1388,7 @@ default_imp_for_payouts_fulfill!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1429,6 +1451,7 @@ default_imp_for_payouts_cancel!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1491,6 +1514,7 @@ default_imp_for_payouts_quote!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1553,6 +1577,7 @@ default_imp_for_payouts_recipient!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1615,6 +1640,7 @@ default_imp_for_payouts_recipient_account!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1677,6 +1703,7 @@ default_imp_for_frm_sale!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1739,6 +1766,7 @@ default_imp_for_frm_checkout!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1801,6 +1829,7 @@ default_imp_for_frm_transaction!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1863,6 +1892,7 @@ default_imp_for_frm_fulfillment!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1925,6 +1955,7 @@ default_imp_for_frm_record_return!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1984,6 +2015,7 @@ default_imp_for_revoking_mandates!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
|
||||
@ -235,6 +235,7 @@ default_imp_for_new_connector_integration_payment!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -296,6 +297,7 @@ default_imp_for_new_connector_integration_refund!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -352,6 +354,7 @@ default_imp_for_new_connector_integration_connector_access_token!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -414,6 +417,7 @@ default_imp_for_new_connector_integration_accept_dispute!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -475,6 +479,7 @@ default_imp_for_new_connector_integration_submit_evidence!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -536,6 +541,7 @@ default_imp_for_new_connector_integration_defend_dispute!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -607,6 +613,7 @@ default_imp_for_new_connector_integration_file_upload!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -670,6 +677,7 @@ default_imp_for_new_connector_integration_payouts_create!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -733,6 +741,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -796,6 +805,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -859,6 +869,7 @@ default_imp_for_new_connector_integration_payouts_cancel!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -922,6 +933,7 @@ default_imp_for_new_connector_integration_payouts_quote!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -985,6 +997,7 @@ default_imp_for_new_connector_integration_payouts_recipient!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1048,6 +1061,7 @@ default_imp_for_new_connector_integration_payouts_sync!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1111,6 +1125,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1172,6 +1187,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1235,6 +1251,7 @@ default_imp_for_new_connector_integration_frm_sale!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1298,6 +1315,7 @@ default_imp_for_new_connector_integration_frm_checkout!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1361,6 +1379,7 @@ default_imp_for_new_connector_integration_frm_transaction!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1424,6 +1443,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1487,6 +1507,7 @@ default_imp_for_new_connector_integration_frm_record_return!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
@ -1547,6 +1568,7 @@ default_imp_for_new_connector_integration_revoking_mandates!(
|
||||
connectors::Mollie,
|
||||
connectors::Multisafepay,
|
||||
connectors::Razorpay,
|
||||
connectors::Redsys,
|
||||
connectors::Shift4,
|
||||
connectors::Stax,
|
||||
connectors::Square,
|
||||
|
||||
@ -76,6 +76,7 @@ pub struct Connectors {
|
||||
pub prophetpay: ConnectorParams,
|
||||
pub rapyd: ConnectorParams,
|
||||
pub razorpay: ConnectorParamsWithKeys,
|
||||
pub redsys: ConnectorParams,
|
||||
pub riskified: ConnectorParams,
|
||||
pub shift4: ConnectorParams,
|
||||
pub signifyd: ConnectorParams,
|
||||
|
||||
@ -54,10 +54,11 @@ pub use hyperswitch_connectors::connectors::{
|
||||
inespay::Inespay, jpmorgan, jpmorgan::Jpmorgan, mollie, mollie::Mollie, multisafepay,
|
||||
multisafepay::Multisafepay, nexinets, nexinets::Nexinets, nexixpay, nexixpay::Nexixpay,
|
||||
nomupay, nomupay::Nomupay, novalnet, novalnet::Novalnet, payeezy, payeezy::Payeezy, payu,
|
||||
payu::Payu, powertranz, powertranz::Powertranz, razorpay, razorpay::Razorpay, shift4,
|
||||
shift4::Shift4, square, square::Square, stax, stax::Stax, taxjar, taxjar::Taxjar, thunes,
|
||||
thunes::Thunes, tsys, tsys::Tsys, volt, volt::Volt, worldline, worldline::Worldline, worldpay,
|
||||
worldpay::Worldpay, xendit, xendit::Xendit, zen, zen::Zen, zsl, zsl::Zsl,
|
||||
payu::Payu, powertranz, powertranz::Powertranz, razorpay, razorpay::Razorpay, redsys,
|
||||
redsys::Redsys, shift4, shift4::Shift4, square, square::Square, stax, stax::Stax, taxjar,
|
||||
taxjar::Taxjar, thunes, thunes::Thunes, tsys, tsys::Tsys, volt, volt::Volt, worldline,
|
||||
worldline::Worldline, worldpay, worldpay::Worldpay, xendit, xendit::Xendit, zen, zen::Zen, zsl,
|
||||
zsl::Zsl,
|
||||
};
|
||||
|
||||
#[cfg(feature = "dummy_connector")]
|
||||
|
||||
@ -1170,6 +1170,7 @@ default_imp_for_new_connector_integration_payouts!(
|
||||
connector::Prophetpay,
|
||||
connector::Rapyd,
|
||||
connector::Razorpay,
|
||||
connector::Redsys,
|
||||
connector::Riskified,
|
||||
connector::Signifyd,
|
||||
connector::Square,
|
||||
@ -1818,6 +1819,7 @@ default_imp_for_new_connector_integration_frm!(
|
||||
connector::Prophetpay,
|
||||
connector::Rapyd,
|
||||
connector::Razorpay,
|
||||
connector::Redsys,
|
||||
connector::Riskified,
|
||||
connector::Signifyd,
|
||||
connector::Square,
|
||||
@ -2314,6 +2316,7 @@ default_imp_for_new_connector_integration_connector_authentication!(
|
||||
connector::Prophetpay,
|
||||
connector::Rapyd,
|
||||
connector::Razorpay,
|
||||
connector::Redsys,
|
||||
connector::Riskified,
|
||||
connector::Signifyd,
|
||||
connector::Square,
|
||||
|
||||
@ -511,6 +511,7 @@ default_imp_for_connector_request_id!(
|
||||
connector::Prophetpay,
|
||||
connector::Rapyd,
|
||||
connector::Razorpay,
|
||||
connector::Redsys,
|
||||
connector::Riskified,
|
||||
connector::Shift4,
|
||||
connector::Signifyd,
|
||||
@ -1799,6 +1800,7 @@ default_imp_for_fraud_check!(
|
||||
connector::Prophetpay,
|
||||
connector::Rapyd,
|
||||
connector::Razorpay,
|
||||
connector::Redsys,
|
||||
connector::Shift4,
|
||||
connector::Square,
|
||||
connector::Stax,
|
||||
@ -2462,6 +2464,7 @@ default_imp_for_connector_authentication!(
|
||||
connector::Prophetpay,
|
||||
connector::Rapyd,
|
||||
connector::Razorpay,
|
||||
connector::Redsys,
|
||||
connector::Riskified,
|
||||
connector::Shift4,
|
||||
connector::Signifyd,
|
||||
|
||||
@ -486,6 +486,7 @@ impl ConnectorData {
|
||||
enums::Connector::Rapyd => {
|
||||
Ok(ConnectorEnum::Old(Box::new(connector::Rapyd::new())))
|
||||
}
|
||||
// enums::Connector::Redsys => Ok(ConnectorEnum::Old(Box::new(connector::Redsys))),
|
||||
enums::Connector::Shift4 => {
|
||||
Ok(ConnectorEnum::Old(Box::new(connector::Shift4::new())))
|
||||
}
|
||||
|
||||
@ -280,6 +280,7 @@ impl ForeignTryFrom<api_enums::Connector> 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::Redsys => Self::Redsys,
|
||||
api_enums::Connector::Shift4 => Self::Shift4,
|
||||
api_enums::Connector::Signifyd => {
|
||||
Err(common_utils::errors::ValidationError::InvalidValue {
|
||||
|
||||
@ -74,6 +74,7 @@ mod powertranz;
|
||||
mod prophetpay;
|
||||
mod rapyd;
|
||||
mod razorpay;
|
||||
mod redsys;
|
||||
mod shift4;
|
||||
mod square;
|
||||
mod stax;
|
||||
|
||||
421
crates/router/tests/connectors/redsys.rs
Normal file
421
crates/router/tests/connectors/redsys.rs
Normal file
@ -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 RedsysTest;
|
||||
impl ConnectorActions for RedsysTest {}
|
||||
impl utils::Connector for RedsysTest {
|
||||
fn get_data(&self) -> api::ConnectorData {
|
||||
use router::connector::Redsys;
|
||||
utils::construct_connector_data_old(
|
||||
Box::new(Redsys::new()),
|
||||
types::Connector::Plaid,
|
||||
api::GetToken::Connector,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
fn get_auth_token(&self) -> types::ConnectorAuthType {
|
||||
utils::to_connector_auth_type(
|
||||
connector_auth::ConnectorAuthentication::new()
|
||||
.redsys
|
||||
.expect("Missing connector authentication configuration")
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
|
||||
fn get_name(&self) -> String {
|
||||
"redsys".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
static CONNECTOR: RedsysTest = RedsysTest {};
|
||||
|
||||
fn get_default_payment_info() -> Option<utils::PaymentInfo> {
|
||||
None
|
||||
}
|
||||
|
||||
fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
|
||||
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
|
||||
@ -268,6 +268,9 @@ api_key="API Key"
|
||||
[nexixpay]
|
||||
api_key="API Key"
|
||||
|
||||
[redsys]
|
||||
api_key="API Key"
|
||||
|
||||
[wellsfargopayout]
|
||||
api_key = "Consumer Key"
|
||||
key1 = "Gateway Entity Id"
|
||||
|
||||
@ -77,6 +77,7 @@ pub struct ConnectorAuthentication {
|
||||
pub prophetpay: Option<HeaderKey>,
|
||||
pub rapyd: Option<BodyKey>,
|
||||
pub razorpay: Option<BodyKey>,
|
||||
pub redsys: Option<HeaderKey>,
|
||||
pub shift4: Option<HeaderKey>,
|
||||
pub square: Option<BodyKey>,
|
||||
pub stax: Option<HeaderKey>,
|
||||
|
||||
@ -149,6 +149,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/"
|
||||
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/"
|
||||
signifyd.base_url = "https://api.signifyd.com/"
|
||||
|
||||
@ -6,7 +6,7 @@ function find_prev_connector() {
|
||||
git checkout $self
|
||||
cp $self $self.tmp
|
||||
# Add new connector to existing list and sort it
|
||||
connectors=(aci adyen adyenplatform airwallex amazonpay applepay authorizedotnet bambora bamboraapac bankofamerica billwerk bitpay bluesnap boku braintree cashtocode checkout coinbase cryptopay cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector ebanx elavon fiserv fiservemea fiuu forte globalpay globepay gocardless gpayments helcim iatapay inespay itaubank jpmorgan klarna mifinity mollie multisafepay netcetera nexinets nexixpay nomupay noon novalnet nuvei opayo opennode paybox payeezy payme payone paypal payu placetopay plaid powertranz prophetpay rapyd razorpay shift4 square stax stripe taxjar threedsecureio thunes trustpay tsys 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 checkout coinbase cryptopay cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector ebanx elavon fiserv fiservemea fiuu forte globalpay globepay gocardless gpayments helcim iatapay inespay itaubank jpmorgan klarna mifinity mollie multisafepay netcetera nexinets nexixpay nomupay noon novalnet nuvei opayo opennode paybox payeezy payme payone paypal payu placetopay plaid powertranz prophetpay rapyd razorpay redsys shift4 square stax stripe taxjar threedsecureio thunes trustpay tsys 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
|
||||
|
||||
Reference in New Issue
Block a user