mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
feat(connector): [Itau Bank] Template for payment flows (#5304)
This commit is contained in:
@ -213,6 +213,7 @@ gocardless.base_url = "https://api-sandbox.gocardless.com"
|
||||
gpayments.base_url = "https://{{merchant_endpoint_prefix}}-test.api.as1.gpayments.net"
|
||||
helcim.base_url = "https://api.helcim.com/"
|
||||
iatapay.base_url = "https://sandbox.iata-pay.iata.org/api/v1"
|
||||
itaubank.base_url = "https://sandbox.devportal.itau.com.br/itau-ep9-gtw-pix-recebimentos-ext-v2/v2"
|
||||
klarna.base_url = "https://api{{klarna_region}}.playground.klarna.com/"
|
||||
mifinity.base_url = "https://demo.mifinity.com/"
|
||||
mollie.base_url = "https://api.mollie.com/v2/"
|
||||
|
||||
@ -53,6 +53,7 @@ gocardless.base_url = "https://api-sandbox.gocardless.com"
|
||||
gpayments.base_url = "https://{{merchant_endpoint_prefix}}-test.api.as1.gpayments.net"
|
||||
helcim.base_url = "https://api.helcim.com/"
|
||||
iatapay.base_url = "https://sandbox.iata-pay.iata.org/api/v1"
|
||||
itaubank.base_url = "https://sandbox.devportal.itau.com.br/itau-ep9-gtw-pix-recebimentos-ext-v2/v2"
|
||||
klarna.base_url = "https://api{{klarna_region}}.playground.klarna.com/"
|
||||
mifinity.base_url = "https://demo.mifinity.com/"
|
||||
mollie.base_url = "https://api.mollie.com/v2/"
|
||||
|
||||
@ -57,6 +57,7 @@ gocardless.base_url = "https://api.gocardless.com"
|
||||
gpayments.base_url = "https://{{merchant_endpoint_prefix}}-test.api.as1.gpayments.net"
|
||||
helcim.base_url = "https://api.helcim.com/"
|
||||
iatapay.base_url = "https://iata-pay.iata.org/api/v1"
|
||||
itaubank.base_url = "https://sandbox.devportal.itau.com.br/itau-ep9-gtw-pix-recebimentos-ext-v2/v2"
|
||||
klarna.base_url = "https://api{{klarna_region}}.klarna.com/"
|
||||
mifinity.base_url = "https://secure.mifinity.com/"
|
||||
mollie.base_url = "https://api.mollie.com/v2/"
|
||||
|
||||
@ -57,6 +57,7 @@ gocardless.base_url = "https://api-sandbox.gocardless.com"
|
||||
gpayments.base_url = "https://{{merchant_endpoint_prefix}}-test.api.as1.gpayments.net"
|
||||
helcim.base_url = "https://api.helcim.com/"
|
||||
iatapay.base_url = "https://sandbox.iata-pay.iata.org/api/v1"
|
||||
itaubank.base_url = "https://sandbox.devportal.itau.com.br/itau-ep9-gtw-pix-recebimentos-ext-v2/v2"
|
||||
klarna.base_url = "https://api{{klarna_region}}.playground.klarna.com/"
|
||||
mifinity.base_url = "https://demo.mifinity.com/"
|
||||
mollie.base_url = "https://api.mollie.com/v2/"
|
||||
|
||||
@ -125,6 +125,7 @@ cards = [
|
||||
"gpayments",
|
||||
"helcim",
|
||||
"iatapay",
|
||||
"itaubank",
|
||||
"mollie",
|
||||
"multisafepay",
|
||||
"netcetera",
|
||||
@ -206,6 +207,7 @@ gocardless.base_url = "https://api-sandbox.gocardless.com"
|
||||
gpayments.base_url = "https://{{merchant_endpoint_prefix}}-test.api.as1.gpayments.net"
|
||||
helcim.base_url = "https://api.helcim.com/"
|
||||
iatapay.base_url = "https://sandbox.iata-pay.iata.org/api/v1"
|
||||
itaubank.base_url = "https://sandbox.devportal.itau.com.br/itau-ep9-gtw-pix-recebimentos-ext-v2/v2"
|
||||
klarna.base_url = "https://api{{klarna_region}}.playground.klarna.com/"
|
||||
mifinity.base_url = "https://demo.mifinity.com/"
|
||||
mollie.base_url = "https://api.mollie.com/v2/"
|
||||
|
||||
@ -142,6 +142,7 @@ gocardless.base_url = "https://api-sandbox.gocardless.com"
|
||||
gpayments.base_url = "https://{{merchant_endpoint_prefix}}-test.api.as1.gpayments.net"
|
||||
helcim.base_url = "https://api.helcim.com/"
|
||||
iatapay.base_url = "https://sandbox.iata-pay.iata.org/api/v1"
|
||||
itaubank.base_url = "https://sandbox.devportal.itau.com.br/itau-ep9-gtw-pix-recebimentos-ext-v2/v2"
|
||||
klarna.base_url = "https://api{{klarna_region}}.playground.klarna.com/"
|
||||
mifinity.base_url = "https://demo.mifinity.com/"
|
||||
mollie.base_url = "https://api.mollie.com/v2/"
|
||||
@ -222,6 +223,7 @@ cards = [
|
||||
"gpayments",
|
||||
"helcim",
|
||||
"iatapay",
|
||||
"itaubank",
|
||||
"mollie",
|
||||
"multisafepay",
|
||||
"netcetera",
|
||||
|
||||
@ -101,6 +101,7 @@ pub enum Connector {
|
||||
Gpayments,
|
||||
Helcim,
|
||||
Iatapay,
|
||||
// Itaubank, template code for future usage
|
||||
Klarna,
|
||||
Mifinity,
|
||||
Mollie,
|
||||
|
||||
@ -216,6 +216,7 @@ pub enum RoutableConnectors {
|
||||
Gocardless,
|
||||
Helcim,
|
||||
Iatapay,
|
||||
// Itaubank, template code for future usage
|
||||
Klarna,
|
||||
Mifinity,
|
||||
Mollie,
|
||||
|
||||
@ -44,6 +44,7 @@ pub struct Connectors {
|
||||
pub gpayments: ConnectorParams,
|
||||
pub helcim: ConnectorParams,
|
||||
pub iatapay: ConnectorParams,
|
||||
pub itaubank: ConnectorParams,
|
||||
pub klarna: ConnectorParams,
|
||||
pub mifinity: ConnectorParams,
|
||||
pub mollie: ConnectorParams,
|
||||
|
||||
@ -29,6 +29,7 @@ pub mod gocardless;
|
||||
pub mod gpayments;
|
||||
pub mod helcim;
|
||||
pub mod iatapay;
|
||||
pub mod itaubank;
|
||||
pub mod klarna;
|
||||
pub mod mifinity;
|
||||
pub mod mollie;
|
||||
@ -77,7 +78,7 @@ pub use self::{
|
||||
coinbase::Coinbase, cryptopay::Cryptopay, cybersource::Cybersource, datatrans::Datatrans,
|
||||
dlocal::Dlocal, ebanx::Ebanx, fiserv::Fiserv, forte::Forte, globalpay::Globalpay,
|
||||
globepay::Globepay, gocardless::Gocardless, gpayments::Gpayments, helcim::Helcim,
|
||||
iatapay::Iatapay, klarna::Klarna, mifinity::Mifinity, mollie::Mollie,
|
||||
iatapay::Iatapay, itaubank::Itaubank, klarna::Klarna, mifinity::Mifinity, mollie::Mollie,
|
||||
multisafepay::Multisafepay, netcetera::Netcetera, nexinets::Nexinets, nmi::Nmi, noon::Noon,
|
||||
nuvei::Nuvei, opayo::Opayo, opennode::Opennode, payeezy::Payeezy, payme::Payme, payone::Payone,
|
||||
paypal::Paypal, payu::Payu, placetopay::Placetopay, powertranz::Powertranz,
|
||||
|
||||
569
crates/router/src/connector/itaubank.rs
Normal file
569
crates/router/src/connector/itaubank.rs
Normal file
@ -0,0 +1,569 @@
|
||||
pub mod transformers;
|
||||
|
||||
use common_utils::types::{AmountConvertor, StringMinorUnit, StringMinorUnitForConnector};
|
||||
use error_stack::{report, ResultExt};
|
||||
use masking::ExposeInterface;
|
||||
use transformers as itaubank;
|
||||
|
||||
use super::utils::{self as connector_utils};
|
||||
use crate::{
|
||||
configs::settings,
|
||||
core::errors::{self, CustomResult},
|
||||
events::connector_api_logs::ConnectorEvent,
|
||||
headers,
|
||||
services::{
|
||||
self,
|
||||
request::{self, Mask},
|
||||
ConnectorIntegration, ConnectorValidation,
|
||||
},
|
||||
types::{
|
||||
self,
|
||||
api::{self, ConnectorCommon, ConnectorCommonExt},
|
||||
ErrorResponse, RequestContent, Response,
|
||||
},
|
||||
utils::BytesExt,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Itaubank {
|
||||
amount_converter: &'static (dyn AmountConvertor<Output = StringMinorUnit> + Sync),
|
||||
}
|
||||
|
||||
impl Itaubank {
|
||||
pub fn new() -> &'static Self {
|
||||
&Self {
|
||||
amount_converter: &StringMinorUnitForConnector,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl api::Payment for Itaubank {}
|
||||
impl api::PaymentSession for Itaubank {}
|
||||
impl api::ConnectorAccessToken for Itaubank {}
|
||||
impl api::MandateSetup for Itaubank {}
|
||||
impl api::PaymentAuthorize for Itaubank {}
|
||||
impl api::PaymentSync for Itaubank {}
|
||||
impl api::PaymentCapture for Itaubank {}
|
||||
impl api::PaymentVoid for Itaubank {}
|
||||
impl api::Refund for Itaubank {}
|
||||
impl api::RefundExecute for Itaubank {}
|
||||
impl api::RefundSync for Itaubank {}
|
||||
impl api::PaymentToken for Itaubank {}
|
||||
|
||||
impl
|
||||
ConnectorIntegration<
|
||||
api::PaymentMethodToken,
|
||||
types::PaymentMethodTokenizationData,
|
||||
types::PaymentsResponseData,
|
||||
> for Itaubank
|
||||
{
|
||||
}
|
||||
|
||||
impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for Itaubank
|
||||
where
|
||||
Self: ConnectorIntegration<Flow, Request, Response>,
|
||||
{
|
||||
fn build_headers(
|
||||
&self,
|
||||
req: &types::RouterData<Flow, Request, Response>,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<Vec<(String, request::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 Itaubank {
|
||||
fn id(&self) -> &'static str {
|
||||
"itaubank"
|
||||
}
|
||||
|
||||
fn get_currency_unit(&self) -> api::CurrencyUnit {
|
||||
api::CurrencyUnit::Minor
|
||||
}
|
||||
|
||||
fn common_get_content_type(&self) -> &'static str {
|
||||
"application/json"
|
||||
}
|
||||
|
||||
fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
|
||||
connectors.itaubank.base_url.as_ref()
|
||||
}
|
||||
|
||||
fn get_auth_header(
|
||||
&self,
|
||||
auth_type: &types::ConnectorAuthType,
|
||||
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
|
||||
let auth = itaubank::ItaubankAuthType::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: itaubank::ItaubankErrorResponse = res
|
||||
.response
|
||||
.parse_struct("ItaubankErrorResponse")
|
||||
.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 Itaubank {}
|
||||
|
||||
impl ConnectorIntegration<api::Session, types::PaymentsSessionData, types::PaymentsResponseData>
|
||||
for Itaubank
|
||||
{
|
||||
}
|
||||
|
||||
impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, types::AccessToken>
|
||||
for Itaubank
|
||||
{
|
||||
}
|
||||
|
||||
impl
|
||||
ConnectorIntegration<
|
||||
api::SetupMandate,
|
||||
types::SetupMandateRequestData,
|
||||
types::PaymentsResponseData,
|
||||
> for Itaubank
|
||||
{
|
||||
}
|
||||
|
||||
impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::PaymentsResponseData>
|
||||
for Itaubank
|
||||
{
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &types::PaymentsAuthorizeRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Vec<(String, request::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: &types::PaymentsAuthorizeRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<String, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
|
||||
}
|
||||
|
||||
fn get_request_body(
|
||||
&self,
|
||||
req: &types::PaymentsAuthorizeRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let amount = connector_utils::convert_amount(
|
||||
self.amount_converter,
|
||||
req.request.minor_amount,
|
||||
req.request.currency,
|
||||
)?;
|
||||
|
||||
let connector_router_data = itaubank::ItaubankRouterData::from((amount, req));
|
||||
let connector_req = itaubank::ItaubankPaymentsRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(connector_req)))
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &types::PaymentsAuthorizeRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
|
||||
Ok(Some(
|
||||
services::RequestBuilder::new()
|
||||
.method(services::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: &types::PaymentsAuthorizeRouterData,
|
||||
event_builder: Option<&mut ConnectorEvent>,
|
||||
res: Response,
|
||||
) -> CustomResult<types::PaymentsAuthorizeRouterData, errors::ConnectorError> {
|
||||
let response: itaubank::ItaubankPaymentsResponse = res
|
||||
.response
|
||||
.parse_struct("Itaubank PaymentsAuthorizeResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
event_builder.map(|i| i.set_response_body(&response));
|
||||
router_env::logger::info!(connector_response=?response);
|
||||
types::RouterData::try_from(types::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<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData>
|
||||
for Itaubank
|
||||
{
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &types::PaymentsSyncRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Vec<(String, request::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: &types::PaymentsSyncRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<String, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &types::PaymentsSyncRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
|
||||
Ok(Some(
|
||||
services::RequestBuilder::new()
|
||||
.method(services::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: &types::PaymentsSyncRouterData,
|
||||
event_builder: Option<&mut ConnectorEvent>,
|
||||
res: Response,
|
||||
) -> CustomResult<types::PaymentsSyncRouterData, errors::ConnectorError> {
|
||||
let response: itaubank::ItaubankPaymentsResponse = res
|
||||
.response
|
||||
.parse_struct("itaubank PaymentsSyncResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
event_builder.map(|i| i.set_response_body(&response));
|
||||
router_env::logger::info!(connector_response=?response);
|
||||
types::RouterData::try_from(types::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<api::Capture, types::PaymentsCaptureData, types::PaymentsResponseData>
|
||||
for Itaubank
|
||||
{
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &types::PaymentsCaptureRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Vec<(String, request::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: &types::PaymentsCaptureRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<String, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
|
||||
}
|
||||
|
||||
fn get_request_body(
|
||||
&self,
|
||||
_req: &types::PaymentsCaptureRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into())
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &types::PaymentsCaptureRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
|
||||
Ok(Some(
|
||||
services::RequestBuilder::new()
|
||||
.method(services::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: &types::PaymentsCaptureRouterData,
|
||||
event_builder: Option<&mut ConnectorEvent>,
|
||||
res: Response,
|
||||
) -> CustomResult<types::PaymentsCaptureRouterData, errors::ConnectorError> {
|
||||
let response: itaubank::ItaubankPaymentsResponse = res
|
||||
.response
|
||||
.parse_struct("Itaubank PaymentsCaptureResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
event_builder.map(|i| i.set_response_body(&response));
|
||||
router_env::logger::info!(connector_response=?response);
|
||||
types::RouterData::try_from(types::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<api::Void, types::PaymentsCancelData, types::PaymentsResponseData>
|
||||
for Itaubank
|
||||
{
|
||||
}
|
||||
|
||||
impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsResponseData>
|
||||
for Itaubank
|
||||
{
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &types::RefundsRouterData<api::Execute>,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Vec<(String, request::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: &types::RefundsRouterData<api::Execute>,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<String, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
|
||||
}
|
||||
|
||||
fn get_request_body(
|
||||
&self,
|
||||
req: &types::RefundsRouterData<api::Execute>,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let refund_amount = connector_utils::convert_amount(
|
||||
self.amount_converter,
|
||||
req.request.minor_refund_amount,
|
||||
req.request.currency,
|
||||
)?;
|
||||
|
||||
let connector_router_data = itaubank::ItaubankRouterData::from((refund_amount, req));
|
||||
let connector_req = itaubank::ItaubankRefundRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(connector_req)))
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &types::RefundsRouterData<api::Execute>,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
|
||||
let request = services::RequestBuilder::new()
|
||||
.method(services::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: &types::RefundsRouterData<api::Execute>,
|
||||
event_builder: Option<&mut ConnectorEvent>,
|
||||
res: Response,
|
||||
) -> CustomResult<types::RefundsRouterData<api::Execute>, errors::ConnectorError> {
|
||||
let response: itaubank::RefundResponse = res
|
||||
.response
|
||||
.parse_struct("itaubank RefundResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
event_builder.map(|i| i.set_response_body(&response));
|
||||
router_env::logger::info!(connector_response=?response);
|
||||
types::RouterData::try_from(types::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<api::RSync, types::RefundsData, types::RefundsResponseData> for Itaubank {
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &types::RefundSyncRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Vec<(String, request::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: &types::RefundSyncRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<String, errors::ConnectorError> {
|
||||
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &types::RefundSyncRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
|
||||
Ok(Some(
|
||||
services::RequestBuilder::new()
|
||||
.method(services::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: &types::RefundSyncRouterData,
|
||||
event_builder: Option<&mut ConnectorEvent>,
|
||||
res: Response,
|
||||
) -> CustomResult<types::RefundSyncRouterData, errors::ConnectorError> {
|
||||
let response: itaubank::RefundResponse = res
|
||||
.response
|
||||
.parse_struct("itaubank RefundSyncResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
event_builder.map(|i| i.set_response_body(&response));
|
||||
router_env::logger::info!(connector_response=?response);
|
||||
types::RouterData::try_from(types::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 api::IncomingWebhook for Itaubank {
|
||||
fn get_webhook_object_reference_id(
|
||||
&self,
|
||||
_request: &api::IncomingWebhookRequestDetails<'_>,
|
||||
) -> CustomResult<api::webhooks::ObjectReferenceId, errors::ConnectorError> {
|
||||
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
|
||||
}
|
||||
|
||||
fn get_webhook_event_type(
|
||||
&self,
|
||||
_request: &api::IncomingWebhookRequestDetails<'_>,
|
||||
) -> CustomResult<api::IncomingWebhookEvent, errors::ConnectorError> {
|
||||
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
|
||||
}
|
||||
|
||||
fn get_webhook_resource_object(
|
||||
&self,
|
||||
_request: &api::IncomingWebhookRequestDetails<'_>,
|
||||
) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
|
||||
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
|
||||
}
|
||||
}
|
||||
216
crates/router/src/connector/itaubank/transformers.rs
Normal file
216
crates/router/src/connector/itaubank/transformers.rs
Normal file
@ -0,0 +1,216 @@
|
||||
use common_utils::types::StringMinorUnit;
|
||||
use masking::Secret;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
connector::utils::PaymentsAuthorizeRequestData,
|
||||
core::errors,
|
||||
types::{self, api, domain, storage::enums},
|
||||
};
|
||||
|
||||
pub struct ItaubankRouterData<T> {
|
||||
pub amount: StringMinorUnit,
|
||||
pub router_data: T,
|
||||
}
|
||||
|
||||
impl<T> From<(StringMinorUnit, T)> for ItaubankRouterData<T> {
|
||||
fn from((amount, item): (StringMinorUnit, T)) -> Self {
|
||||
Self {
|
||||
amount,
|
||||
router_data: item,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Serialize, PartialEq)]
|
||||
pub struct ItaubankPaymentsRequest {
|
||||
amount: StringMinorUnit,
|
||||
card: ItaubankCard,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
|
||||
pub struct ItaubankCard {
|
||||
number: cards::CardNumber,
|
||||
expiry_month: Secret<String>,
|
||||
expiry_year: Secret<String>,
|
||||
cvc: Secret<String>,
|
||||
complete: bool,
|
||||
}
|
||||
|
||||
impl TryFrom<&ItaubankRouterData<&types::PaymentsAuthorizeRouterData>> for ItaubankPaymentsRequest {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: &ItaubankRouterData<&types::PaymentsAuthorizeRouterData>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
match item.router_data.request.payment_method_data.clone() {
|
||||
domain::PaymentMethodData::Card(req_card) => {
|
||||
let card = ItaubankCard {
|
||||
number: req_card.card_number,
|
||||
expiry_month: req_card.card_exp_month,
|
||||
expiry_year: req_card.card_exp_year,
|
||||
cvc: req_card.card_cvc,
|
||||
complete: item.router_data.request.is_auto_capture()?,
|
||||
};
|
||||
Ok(Self {
|
||||
amount: item.amount.clone(),
|
||||
card,
|
||||
})
|
||||
}
|
||||
_ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ItaubankAuthType {
|
||||
pub(super) api_key: Secret<String>,
|
||||
}
|
||||
|
||||
impl TryFrom<&types::ConnectorAuthType> for ItaubankAuthType {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(auth_type: &types::ConnectorAuthType) -> Result<Self, Self::Error> {
|
||||
match auth_type {
|
||||
types::ConnectorAuthType::HeaderKey { api_key } => Ok(Self {
|
||||
api_key: api_key.to_owned(),
|
||||
}),
|
||||
_ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ItaubankPaymentStatus {
|
||||
Succeeded,
|
||||
Failed,
|
||||
#[default]
|
||||
Processing,
|
||||
}
|
||||
|
||||
impl From<ItaubankPaymentStatus> for enums::AttemptStatus {
|
||||
fn from(item: ItaubankPaymentStatus) -> Self {
|
||||
match item {
|
||||
ItaubankPaymentStatus::Succeeded => Self::Charged,
|
||||
ItaubankPaymentStatus::Failed => Self::Failure,
|
||||
ItaubankPaymentStatus::Processing => Self::Authorizing,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct ItaubankPaymentsResponse {
|
||||
status: ItaubankPaymentStatus,
|
||||
id: String,
|
||||
}
|
||||
|
||||
impl<F, T>
|
||||
TryFrom<types::ResponseRouterData<F, ItaubankPaymentsResponse, T, types::PaymentsResponseData>>
|
||||
for types::RouterData<F, T, types::PaymentsResponseData>
|
||||
{
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: types::ResponseRouterData<
|
||||
F,
|
||||
ItaubankPaymentsResponse,
|
||||
T,
|
||||
types::PaymentsResponseData,
|
||||
>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
status: enums::AttemptStatus::from(item.response.status),
|
||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
||||
resource_id: types::ResponseId::ConnectorTransactionId(item.response.id),
|
||||
redirection_data: None,
|
||||
mandate_reference: None,
|
||||
connector_metadata: None,
|
||||
network_txn_id: None,
|
||||
connector_response_reference_id: None,
|
||||
incremental_authorization_allowed: None,
|
||||
charge_id: None,
|
||||
}),
|
||||
..item.data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Serialize)]
|
||||
pub struct ItaubankRefundRequest {
|
||||
pub amount: StringMinorUnit,
|
||||
}
|
||||
|
||||
impl<F> TryFrom<&ItaubankRouterData<&types::RefundsRouterData<F>>> for ItaubankRefundRequest {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: &ItaubankRouterData<&types::RefundsRouterData<F>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
amount: item.amount.to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct RefundResponse {
|
||||
id: String,
|
||||
status: RefundStatus,
|
||||
}
|
||||
|
||||
impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>>
|
||||
for types::RefundsRouterData<api::Execute>
|
||||
{
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: types::RefundsResponseRouterData<api::Execute, RefundResponse>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
response: Ok(types::RefundsResponseData {
|
||||
connector_refund_id: item.response.id.to_string(),
|
||||
refund_status: enums::RefundStatus::from(item.response.status),
|
||||
}),
|
||||
..item.data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<types::RefundsResponseRouterData<api::RSync, RefundResponse>>
|
||||
for types::RefundsRouterData<api::RSync>
|
||||
{
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: types::RefundsResponseRouterData<api::RSync, RefundResponse>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
response: Ok(types::RefundsResponseData {
|
||||
connector_refund_id: item.response.id.to_string(),
|
||||
refund_status: enums::RefundStatus::from(item.response.status),
|
||||
}),
|
||||
..item.data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct ItaubankErrorResponse {
|
||||
pub status_code: u16,
|
||||
pub code: String,
|
||||
pub message: String,
|
||||
pub reason: Option<String>,
|
||||
}
|
||||
@ -663,6 +663,7 @@ default_imp_for_new_connector_integration_payment!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -747,6 +748,7 @@ default_imp_for_new_connector_integration_refund!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -826,6 +828,7 @@ default_imp_for_new_connector_integration_connector_access_token!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -927,6 +930,7 @@ default_imp_for_new_connector_integration_accept_dispute!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1010,6 +1014,7 @@ default_imp_for_new_connector_integration_defend_dispute!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1077,6 +1082,7 @@ default_imp_for_new_connector_integration_submit_evidence!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1171,6 +1177,7 @@ default_imp_for_new_connector_integration_file_upload!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1247,6 +1254,7 @@ default_imp_for_new_connector_integration_payouts!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1333,6 +1341,7 @@ default_imp_for_new_connector_integration_payouts_create!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1419,6 +1428,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1505,6 +1515,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1591,6 +1602,7 @@ default_imp_for_new_connector_integration_payouts_cancel!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1677,6 +1689,7 @@ default_imp_for_new_connector_integration_payouts_quote!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1763,6 +1776,7 @@ default_imp_for_new_connector_integration_payouts_recipient!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1849,6 +1863,7 @@ default_imp_for_new_connector_integration_payouts_sync!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1935,6 +1950,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2019,6 +2035,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2095,6 +2112,7 @@ default_imp_for_new_connector_integration_frm!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2181,6 +2199,7 @@ default_imp_for_new_connector_integration_frm_sale!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2267,6 +2286,7 @@ default_imp_for_new_connector_integration_frm_checkout!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2353,6 +2373,7 @@ default_imp_for_new_connector_integration_frm_transaction!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2439,6 +2460,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2525,6 +2547,7 @@ default_imp_for_new_connector_integration_frm_record_return!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2608,6 +2631,7 @@ default_imp_for_new_connector_integration_revoking_mandates!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2719,6 +2743,7 @@ default_imp_for_new_connector_integration_connector_authentication!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
|
||||
@ -208,6 +208,7 @@ default_imp_for_complete_authorize!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Multisafepay,
|
||||
@ -293,6 +294,7 @@ default_imp_for_webhook_source_verification!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -386,6 +388,7 @@ default_imp_for_create_customer!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -474,6 +477,7 @@ default_imp_for_connector_redirect_response!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Multisafepay,
|
||||
@ -544,6 +548,7 @@ default_imp_for_connector_request_id!(
|
||||
connector::Gocardless,
|
||||
connector::Gpayments,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -639,6 +644,7 @@ default_imp_for_accept_dispute!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -755,6 +761,7 @@ default_imp_for_file_upload!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -848,6 +855,7 @@ default_imp_for_submit_evidence!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -941,6 +949,7 @@ default_imp_for_defend_dispute!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1041,6 +1050,7 @@ default_imp_for_pre_processing_steps!(
|
||||
connector::Dlocal,
|
||||
connector::Ebanx,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Fiserv,
|
||||
connector::Forte,
|
||||
connector::Globalpay,
|
||||
@ -1121,6 +1131,7 @@ default_imp_for_post_processing_steps!(
|
||||
connector::Dlocal,
|
||||
connector::Ebanx,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Fiserv,
|
||||
connector::Forte,
|
||||
connector::Globalpay,
|
||||
@ -1195,6 +1206,7 @@ default_imp_for_payouts!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1285,6 +1297,7 @@ default_imp_for_payouts_create!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1378,6 +1391,7 @@ default_imp_for_payouts_retrieve!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1474,6 +1488,7 @@ default_imp_for_payouts_eligibility!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1565,6 +1580,7 @@ default_imp_for_payouts_fulfill!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1655,6 +1671,7 @@ default_imp_for_payouts_cancel!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1748,6 +1765,7 @@ default_imp_for_payouts_quote!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1842,6 +1860,7 @@ default_imp_for_payouts_recipient!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -1939,6 +1958,7 @@ default_imp_for_payouts_recipient_account!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2033,6 +2053,7 @@ default_imp_for_approve!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2128,6 +2149,7 @@ default_imp_for_reject!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2207,6 +2229,7 @@ default_imp_for_fraud_check!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2302,6 +2325,7 @@ default_imp_for_frm_sale!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2397,6 +2421,7 @@ default_imp_for_frm_checkout!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2492,6 +2517,7 @@ default_imp_for_frm_transaction!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2587,6 +2613,7 @@ default_imp_for_frm_fulfillment!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2682,6 +2709,7 @@ default_imp_for_frm_record_return!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2774,6 +2802,7 @@ default_imp_for_incremental_authorization!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -2866,6 +2895,7 @@ default_imp_for_revoking_mandates!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -3018,6 +3048,7 @@ default_imp_for_connector_authentication!(
|
||||
connector::Gocardless,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
@ -3108,6 +3139,7 @@ default_imp_for_authorize_session_token!(
|
||||
connector::Gpayments,
|
||||
connector::Helcim,
|
||||
connector::Iatapay,
|
||||
connector::Itaubank,
|
||||
connector::Klarna,
|
||||
connector::Mifinity,
|
||||
connector::Mollie,
|
||||
|
||||
420
crates/router/tests/connectors/itaubank.rs
Normal file
420
crates/router/tests/connectors/itaubank.rs
Normal file
@ -0,0 +1,420 @@
|
||||
use masking::Secret;
|
||||
use router::types::{self, api, domain, storage::enums};
|
||||
use test_utils::connector_auth;
|
||||
|
||||
use crate::utils::{self, ConnectorActions};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct ItaubankTest;
|
||||
impl ConnectorActions for ItaubankTest {}
|
||||
impl utils::Connector for ItaubankTest {
|
||||
fn get_data(&self) -> api::ConnectorData {
|
||||
use router::connector::Adyen;
|
||||
utils::construct_connector_data_old(
|
||||
Box::new(Adyen::new()),
|
||||
types::Connector::Adyen,
|
||||
api::GetToken::Connector,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
fn get_auth_token(&self) -> types::ConnectorAuthType {
|
||||
utils::to_connector_auth_type(
|
||||
connector_auth::ConnectorAuthentication::new()
|
||||
.itaubank
|
||||
.expect("Missing connector authentication configuration")
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
|
||||
fn get_name(&self) -> String {
|
||||
"itaubank".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
static CONNECTOR: ItaubankTest = ItaubankTest {};
|
||||
|
||||
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: domain::PaymentMethodData::Card(domain::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: domain::PaymentMethodData::Card(domain::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: domain::PaymentMethodData::Card(domain::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
|
||||
@ -38,6 +38,7 @@ mod gocardless;
|
||||
mod gpayments;
|
||||
mod helcim;
|
||||
mod iatapay;
|
||||
mod itaubank;
|
||||
mod mifinity;
|
||||
mod mollie;
|
||||
mod multisafepay;
|
||||
|
||||
@ -211,10 +211,6 @@ api_key="API Key"
|
||||
certificate="Certificate"
|
||||
private_key="Private Key"
|
||||
|
||||
|
||||
[ebanx]
|
||||
api_key="API Key"
|
||||
|
||||
[zsl]
|
||||
api_key= "Key"
|
||||
key1= "Merchant id"
|
||||
@ -246,3 +242,6 @@ api_key="API Key"
|
||||
key1 = "Merchant id"
|
||||
api_secret = "Razorpay Id"
|
||||
key2 = "Razorpay Secret"
|
||||
|
||||
[itaubank]
|
||||
api_key="API Key"
|
||||
@ -43,6 +43,7 @@ pub struct ConnectorAuthentication {
|
||||
pub gpayments: Option<HeaderKey>,
|
||||
pub helcim: Option<HeaderKey>,
|
||||
pub iatapay: Option<SignatureKey>,
|
||||
pub itaubank: Option<HeaderKey>,
|
||||
pub mifinity: Option<HeaderKey>,
|
||||
pub mollie: Option<BodyKey>,
|
||||
pub multisafepay: Option<HeaderKey>,
|
||||
|
||||
@ -107,6 +107,7 @@ gocardless.base_url = "https://api-sandbox.gocardless.com"
|
||||
gpayments.base_url = "https://{{merchant_endpoint_prefix}}-test.api.as1.gpayments.net"
|
||||
helcim.base_url = "https://api.helcim.com/"
|
||||
iatapay.base_url = "https://sandbox.iata-pay.iata.org/api/v1"
|
||||
itaubank.base_url = "https://sandbox.devportal.itau.com.br/itau-ep9-gtw-pix-recebimentos-ext-v2/v2"
|
||||
klarna.base_url = "https://api{{klarna_region}}.playground.klarna.com/"
|
||||
mifinity.base_url = "https://demo.mifinity.com/"
|
||||
mollie.base_url = "https://api.mollie.com/v2/"
|
||||
@ -187,6 +188,7 @@ cards = [
|
||||
"gpayments",
|
||||
"helcim",
|
||||
"iatapay",
|
||||
"itaubank",
|
||||
"mollie",
|
||||
"multisafepay",
|
||||
"netcetera",
|
||||
|
||||
@ -6,7 +6,7 @@ function find_prev_connector() {
|
||||
git checkout $self
|
||||
cp $self $self.tmp
|
||||
# Add new connector to existing list and sort it
|
||||
connectors=(aci adyen adyenplatform airwallex applepay authorizedotnet bambora bamboraapac bankofamerica billwerk bitpay bluesnap boku braintree cashtocode checkout coinbase cryptopay cybersource datatrans dlocal dummyconnector ebanx fiserv forte globalpay globepay gocardless gpayments helcim iatapay klarna mifinity mollie multisafepay netcetera nexinets noon nuvei opayo opennode payeezy payme payone paypal payu placetopay powertranz prophetpay rapyd razorpay shift4 square stax stripe threedsecureio trustpay tsys volt wise worldline worldpay zsl "$1")
|
||||
connectors=(aci adyen adyenplatform airwallex applepay authorizedotnet bambora bamboraapac bankofamerica billwerk bitpay bluesnap boku braintree cashtocode checkout coinbase cryptopay cybersource datatrans dlocal dummyconnector ebanx fiserv forte globalpay globepay gocardless gpayments helcim iatapay itaubank klarna mifinity mollie multisafepay netcetera nexinets noon nuvei opayo opennode payeezy payme payone paypal payu placetopay powertranz prophetpay rapyd razorpay shift4 square stax stripe threedsecureio trustpay tsys volt wise worldline worldpay zsl "$1")
|
||||
IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFS
|
||||
res=`echo ${sorted[@]}`
|
||||
sed -i'' -e "s/^ connectors=.*/ connectors=($res \"\$1\")/" $self.tmp
|
||||
|
||||
Reference in New Issue
Block a user