feat(connector): [billwerk] add connector template code (#4123)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
SamraatBansal
2024-03-27 13:37:49 +05:30
committed by GitHub
parent 929848f871
commit 37be05d31d
20 changed files with 1321 additions and 39 deletions

View File

@ -170,6 +170,7 @@ applepay.base_url = "https://apple-pay-gateway.apple.com/"
authorizedotnet.base_url = "https://apitest.authorize.net/xml/v1/request.api"
bambora.base_url = "https://api.na.bambora.com"
bankofamerica.base_url = "https://apitest.merchant-services.bankofamerica.com/"
billwerk.base_url = "https://api.reepay.com/"
bitpay.base_url = "https://test.bitpay.com"
bluesnap.base_url = "https://sandbox.bluesnap.com/"
bluesnap.secondary_base_url = "https://sandpay.bluesnap.com/"

View File

@ -97,6 +97,7 @@ cards = [
"authorizedotnet",
"bambora",
"bankofamerica",
"billwerk",
"bitpay",
"bluesnap",
"boku",
@ -165,6 +166,7 @@ applepay.base_url = "https://apple-pay-gateway.apple.com/"
authorizedotnet.base_url = "https://apitest.authorize.net/xml/v1/request.api"
bambora.base_url = "https://api.na.bambora.com"
bankofamerica.base_url = "https://apitest.merchant-services.bankofamerica.com/"
billwerk.base_url = "https://api.reepay.com/"
bitpay.base_url = "https://test.bitpay.com"
bluesnap.base_url = "https://sandbox.bluesnap.com/"
bluesnap.secondary_base_url = "https://sandpay.bluesnap.com/"

View File

@ -104,6 +104,7 @@ applepay.base_url = "https://apple-pay-gateway.apple.com/"
authorizedotnet.base_url = "https://apitest.authorize.net/xml/v1/request.api"
bambora.base_url = "https://api.na.bambora.com"
bankofamerica.base_url = "https://apitest.merchant-services.bankofamerica.com/"
billwerk.base_url = "https://api.reepay.com/"
bitpay.base_url = "https://test.bitpay.com"
bluesnap.base_url = "https://sandbox.bluesnap.com/"
bluesnap.secondary_base_url = "https://sandpay.bluesnap.com/"
@ -176,6 +177,7 @@ cards = [
"authorizedotnet",
"bambora",
"bankofamerica",
"billwerk",
"bitpay",
"bluesnap",
"boku",

View File

@ -78,6 +78,7 @@ pub enum Connector {
Authorizedotnet,
Bambora,
Bankofamerica,
// Billwerk, Added as template code for future usage
Bitpay,
Bluesnap,
Boku,
@ -165,6 +166,7 @@ impl Connector {
| Self::Authorizedotnet
| Self::Bambora
| Self::Bankofamerica
// | Self::Billwerk Added as template code for future usage
| Self::Bitpay
| Self::Bluesnap
| Self::Boku
@ -221,6 +223,7 @@ impl Connector {
| Self::Authorizedotnet
| Self::Bambora
| Self::Bankofamerica
// | Self::Billwerk Added as template for future usage
| Self::Bitpay
| Self::Bluesnap
| Self::Boku

View File

@ -115,6 +115,7 @@ pub enum RoutableConnectors {
Airwallex,
Authorizedotnet,
Bankofamerica,
// Billwerk, Added as template code for future usage
Bitpay,
Bambora,
Bluesnap,

View File

@ -116,6 +116,7 @@ pub struct ConnectorConfig {
pub airwallex: Option<ConnectorTomlConfig>,
pub authorizedotnet: Option<ConnectorTomlConfig>,
pub bankofamerica: Option<ConnectorTomlConfig>,
pub billwerk: Option<ConnectorTomlConfig>,
pub bitpay: Option<ConnectorTomlConfig>,
pub bluesnap: Option<ConnectorTomlConfig>,
pub boku: Option<ConnectorTomlConfig>,
@ -227,6 +228,7 @@ impl ConnectorConfig {
Connector::Airwallex => Ok(connector_data.airwallex),
Connector::Authorizedotnet => Ok(connector_data.authorizedotnet),
Connector::Bankofamerica => Ok(connector_data.bankofamerica),
// Connector::Billwerk => Ok(connector_data.billwerk), Added as template code for future usage
Connector::Bitpay => Ok(connector_data.bitpay),
Connector::Bluesnap => Ok(connector_data.bluesnap),
Connector::Boku => Ok(connector_data.boku),

View File

@ -480,6 +480,7 @@ pub struct Connectors {
pub authorizedotnet: ConnectorParams,
pub bambora: ConnectorParams,
pub bankofamerica: ConnectorParams,
pub billwerk: ConnectorParams,
pub bitpay: ConnectorParams,
pub bluesnap: ConnectorParamsWithSecondaryBaseUrl,
pub boku: ConnectorParams,

View File

@ -4,6 +4,7 @@ pub mod airwallex;
pub mod authorizedotnet;
pub mod bambora;
pub mod bankofamerica;
pub mod billwerk;
pub mod bitpay;
pub mod bluesnap;
pub mod boku;
@ -60,15 +61,15 @@ pub mod zen;
pub use self::dummyconnector::DummyConnector;
pub use self::{
aci::Aci, adyen::Adyen, airwallex::Airwallex, authorizedotnet::Authorizedotnet,
bambora::Bambora, bankofamerica::Bankofamerica, bitpay::Bitpay, bluesnap::Bluesnap, boku::Boku,
braintree::Braintree, cashtocode::Cashtocode, checkout::Checkout, coinbase::Coinbase,
cryptopay::Cryptopay, cybersource::Cybersource, dlocal::Dlocal, fiserv::Fiserv, forte::Forte,
globalpay::Globalpay, globepay::Globepay, gocardless::Gocardless, helcim::Helcim,
iatapay::Iatapay, klarna::Klarna, mollie::Mollie, multisafepay::Multisafepay,
nexinets::Nexinets, nmi::Nmi, noon::Noon, nuvei::Nuvei, opayo::Opayo, opennode::Opennode,
payeezy::Payeezy, payme::Payme, paypal::Paypal, payu::Payu, placetopay::Placetopay,
powertranz::Powertranz, prophetpay::Prophetpay, rapyd::Rapyd, riskified::Riskified,
shift4::Shift4, signifyd::Signifyd, square::Square, stax::Stax, stripe::Stripe,
threedsecureio::Threedsecureio, trustpay::Trustpay, tsys::Tsys, volt::Volt, wise::Wise,
worldline::Worldline, worldpay::Worldpay, zen::Zen,
bambora::Bambora, bankofamerica::Bankofamerica, billwerk::Billwerk, bitpay::Bitpay,
bluesnap::Bluesnap, boku::Boku, braintree::Braintree, cashtocode::Cashtocode,
checkout::Checkout, coinbase::Coinbase, cryptopay::Cryptopay, cybersource::Cybersource,
dlocal::Dlocal, fiserv::Fiserv, forte::Forte, globalpay::Globalpay, globepay::Globepay,
gocardless::Gocardless, helcim::Helcim, iatapay::Iatapay, klarna::Klarna, mollie::Mollie,
multisafepay::Multisafepay, nexinets::Nexinets, nmi::Nmi, noon::Noon, nuvei::Nuvei,
opayo::Opayo, opennode::Opennode, payeezy::Payeezy, payme::Payme, paypal::Paypal, payu::Payu,
placetopay::Placetopay, powertranz::Powertranz, prophetpay::Prophetpay, rapyd::Rapyd,
riskified::Riskified, shift4::Shift4, signifyd::Signifyd, square::Square, stax::Stax,
stripe::Stripe, threedsecureio::Threedsecureio, trustpay::Trustpay, tsys::Tsys, volt::Volt,
wise::Wise, worldline::Worldline, worldpay::Worldpay, zen::Zen,
};

View File

@ -0,0 +1,561 @@
pub mod transformers;
use std::fmt::Debug;
use error_stack::{IntoReport, ResultExt};
use masking::ExposeInterface;
use transformers as billwerk;
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(Debug, Clone)]
pub struct Billwerk;
impl api::Payment for Billwerk {}
impl api::PaymentSession for Billwerk {}
impl api::ConnectorAccessToken for Billwerk {}
impl api::MandateSetup for Billwerk {}
impl api::PaymentAuthorize for Billwerk {}
impl api::PaymentSync for Billwerk {}
impl api::PaymentCapture for Billwerk {}
impl api::PaymentVoid for Billwerk {}
impl api::Refund for Billwerk {}
impl api::RefundExecute for Billwerk {}
impl api::RefundSync for Billwerk {}
impl api::PaymentToken for Billwerk {}
impl
ConnectorIntegration<
api::PaymentMethodToken,
types::PaymentMethodTokenizationData,
types::PaymentsResponseData,
> for Billwerk
{
// Not Implemented (R)
}
impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for Billwerk
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 Billwerk {
fn id(&self) -> &'static str {
"billwerk"
}
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.billwerk.base_url.as_ref()
}
fn get_auth_header(
&self,
auth_type: &types::ConnectorAuthType,
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
let auth = billwerk::BillwerkAuthType::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: billwerk::BillwerkErrorResponse = res
.response
.parse_struct("BillwerkErrorResponse")
.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 Billwerk {
//TODO: implement functions when support enabled
}
impl ConnectorIntegration<api::Session, types::PaymentsSessionData, types::PaymentsResponseData>
for Billwerk
{
//TODO: implement sessions flow
}
impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, types::AccessToken>
for Billwerk
{
}
impl
ConnectorIntegration<
api::SetupMandate,
types::SetupMandateRequestData,
types::PaymentsResponseData,
> for Billwerk
{
}
impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::PaymentsResponseData>
for Billwerk
{
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 connector_router_data = billwerk::BillwerkRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.amount,
req,
))?;
let connector_req = billwerk::BillwerkPaymentsRequest::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: billwerk::BillwerkPaymentsResponse = res
.response
.parse_struct("Billwerk 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 Billwerk
{
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: billwerk::BillwerkPaymentsResponse = res
.response
.parse_struct("billwerk 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 Billwerk
{
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: billwerk::BillwerkPaymentsResponse = res
.response
.parse_struct("Billwerk 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 Billwerk
{
}
impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsResponseData>
for Billwerk
{
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 connector_router_data = billwerk::BillwerkRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.refund_amount,
req,
))?;
let connector_req = billwerk::BillwerkRefundRequest::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: billwerk::RefundResponse = res
.response
.parse_struct("billwerk 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 Billwerk {
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: billwerk::RefundResponse = res
.response
.parse_struct("billwerk 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 Billwerk {
fn get_webhook_object_reference_id(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api::webhooks::ObjectReferenceId, errors::ConnectorError> {
Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
fn get_webhook_event_type(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api::IncomingWebhookEvent, errors::ConnectorError> {
Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
fn get_webhook_resource_object(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
}
}

View File

@ -0,0 +1,244 @@
use masking::Secret;
use serde::{Deserialize, Serialize};
use crate::{
connector::utils::PaymentsAuthorizeRequestData,
core::errors,
types::{self, api, storage::enums},
};
//TODO: Fill the struct with respective fields
pub struct BillwerkRouterData<T> {
pub amount: i64, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
pub router_data: T,
}
impl<T>
TryFrom<(
&types::api::CurrencyUnit,
types::storage::enums::Currency,
i64,
T,
)> for BillwerkRouterData<T>
{
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
(_currency_unit, _currency, amount, item): (
&types::api::CurrencyUnit,
types::storage::enums::Currency,
i64,
T,
),
) -> Result<Self, Self::Error> {
//Todo : use utils to convert the amount to the type of amount that a connector accepts
Ok(Self {
amount,
router_data: item,
})
}
}
//TODO: Fill the struct with respective fields
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
pub struct BillwerkPaymentsRequest {
amount: i64,
card: BillwerkCard,
}
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
pub struct BillwerkCard {
number: cards::CardNumber,
expiry_month: Secret<String>,
expiry_year: Secret<String>,
cvc: Secret<String>,
complete: bool,
}
impl TryFrom<&BillwerkRouterData<&types::PaymentsAuthorizeRouterData>> for BillwerkPaymentsRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
item: &BillwerkRouterData<&types::PaymentsAuthorizeRouterData>,
) -> Result<Self, Self::Error> {
match item.router_data.request.payment_method_data.clone() {
api::PaymentMethodData::Card(req_card) => {
let card = BillwerkCard {
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.to_owned(),
card,
})
}
_ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()),
}
}
}
//TODO: Fill the struct with respective fields
// Auth Struct
pub struct BillwerkAuthType {
pub(super) api_key: Secret<String>,
}
impl TryFrom<&types::ConnectorAuthType> for BillwerkAuthType {
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()),
}
}
}
// PaymentsResponse
//TODO: Append the remaining status flags
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum BillwerkPaymentStatus {
Succeeded,
Failed,
#[default]
Processing,
}
impl From<BillwerkPaymentStatus> for enums::AttemptStatus {
fn from(item: BillwerkPaymentStatus) -> Self {
match item {
BillwerkPaymentStatus::Succeeded => Self::Charged,
BillwerkPaymentStatus::Failed => Self::Failure,
BillwerkPaymentStatus::Processing => Self::Authorizing,
}
}
}
//TODO: Fill the struct with respective fields
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct BillwerkPaymentsResponse {
status: BillwerkPaymentStatus,
id: String,
}
impl<F, T>
TryFrom<types::ResponseRouterData<F, BillwerkPaymentsResponse, T, types::PaymentsResponseData>>
for types::RouterData<F, T, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
item: types::ResponseRouterData<
F,
BillwerkPaymentsResponse,
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,
}),
..item.data
})
}
}
//TODO: Fill the struct with respective fields
// REFUND :
// Type definition for RefundRequest
#[derive(Default, Debug, Serialize)]
pub struct BillwerkRefundRequest {
pub amount: i64,
}
impl<F> TryFrom<&BillwerkRouterData<&types::RefundsRouterData<F>>> for BillwerkRefundRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
item: &BillwerkRouterData<&types::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<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
})
}
}
//TODO: Fill the struct with respective fields
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
pub struct BillwerkErrorResponse {
pub status_code: u16,
pub code: String,
pub message: String,
pub reason: Option<String>,
}

View File

@ -1739,6 +1739,10 @@ pub(crate) fn validate_auth_and_metadata_type(
bankofamerica::transformers::BankOfAmericaAuthType::try_from(val)?;
Ok(())
}
// api_enums::Connector::Billwerk => {
// billwerk::transformers::BillwerkAuthType::try_from(val)?;
// Ok(())
// } Added as template code for future usage
api_enums::Connector::Bitpay => {
bitpay::transformers::BitpayAuthType::try_from(val)?;
Ok(())

View File

@ -145,9 +145,9 @@ impl<const T: u8>
}
default_imp_for_complete_authorize!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Billwerk,
connector::Bitpay,
connector::Boku,
connector::Cashtocode,
@ -176,6 +176,7 @@ default_imp_for_complete_authorize!(
connector::Square,
connector::Stax,
connector::Stripe,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -211,13 +212,13 @@ impl<const T: u8>
{
}
default_imp_for_webhook_source_verification!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Braintree,
@ -257,6 +258,7 @@ default_imp_for_webhook_source_verification!(
connector::Square,
connector::Stax,
connector::Stripe,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -294,13 +296,13 @@ impl<const T: u8>
}
default_imp_for_create_customer!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -338,6 +340,7 @@ default_imp_for_create_customer!(
connector::Shift4,
connector::Signifyd,
connector::Square,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -377,11 +380,11 @@ impl<const T: u8> services::ConnectorRedirectResponse for connector::DummyConnec
}
default_imp_for_connector_redirect_response!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Bitpay,
connector::Bankofamerica,
connector::Billwerk,
connector::Boku,
connector::Cashtocode,
connector::Coinbase,
@ -410,6 +413,7 @@ default_imp_for_connector_redirect_response!(
connector::Signifyd,
connector::Square,
connector::Stax,
connector::Threedsecureio,
connector::Tsys,
connector::Volt,
connector::Wise,
@ -429,13 +433,13 @@ macro_rules! default_imp_for_connector_request_id {
impl<const T: u8> api::ConnectorTransactionId for connector::DummyConnector<T> {}
default_imp_for_connector_request_id!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -474,6 +478,7 @@ default_imp_for_connector_request_id!(
connector::Square,
connector::Stax,
connector::Stripe,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -514,13 +519,13 @@ impl<const T: u8>
}
default_imp_for_accept_dispute!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -560,6 +565,7 @@ default_imp_for_accept_dispute!(
connector::Square,
connector::Stax,
connector::Stripe,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -619,13 +625,13 @@ impl<const T: u8>
}
default_imp_for_file_upload!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -663,6 +669,7 @@ default_imp_for_file_upload!(
connector::Signifyd,
connector::Square,
connector::Stax,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -701,13 +708,13 @@ impl<const T: u8>
}
default_imp_for_submit_evidence!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -745,6 +752,7 @@ default_imp_for_submit_evidence!(
connector::Signifyd,
connector::Square,
connector::Stax,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -783,13 +791,13 @@ impl<const T: u8>
}
default_imp_for_defend_dispute!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -828,6 +836,7 @@ default_imp_for_defend_dispute!(
connector::Square,
connector::Stax,
connector::Stripe,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -866,11 +875,11 @@ impl<const T: u8>
}
default_imp_for_pre_processing_steps!(
connector::Threedsecureio,
connector::Aci,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -905,6 +914,7 @@ default_imp_for_pre_processing_steps!(
connector::Signifyd,
connector::Square,
connector::Stax,
connector::Threedsecureio,
connector::Tsys,
connector::Volt,
connector::Wise,
@ -925,12 +935,12 @@ macro_rules! default_imp_for_payouts {
impl<const T: u8> api::Payouts for connector::DummyConnector<T> {}
default_imp_for_payouts!(
connector::Threedsecureio,
connector::Aci,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -971,6 +981,7 @@ default_imp_for_payouts!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1008,12 +1019,12 @@ impl<const T: u8>
#[cfg(feature = "payouts")]
default_imp_for_payouts_create!(
connector::Threedsecureio,
connector::Aci,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1054,6 +1065,7 @@ default_imp_for_payouts_create!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1094,12 +1106,12 @@ impl<const T: u8>
#[cfg(feature = "payouts")]
default_imp_for_payouts_eligibility!(
connector::Threedsecureio,
connector::Aci,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1140,6 +1152,7 @@ default_imp_for_payouts_eligibility!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1177,12 +1190,12 @@ impl<const T: u8>
#[cfg(feature = "payouts")]
default_imp_for_payouts_fulfill!(
connector::Threedsecureio,
connector::Aci,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1223,6 +1236,7 @@ default_imp_for_payouts_fulfill!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1260,12 +1274,12 @@ impl<const T: u8>
#[cfg(feature = "payouts")]
default_imp_for_payouts_cancel!(
connector::Threedsecureio,
connector::Aci,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1306,6 +1320,7 @@ default_imp_for_payouts_cancel!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1343,13 +1358,13 @@ impl<const T: u8>
#[cfg(feature = "payouts")]
default_imp_for_payouts_quote!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1390,6 +1405,7 @@ default_imp_for_payouts_quote!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1427,13 +1443,13 @@ impl<const T: u8>
#[cfg(feature = "payouts")]
default_imp_for_payouts_recipient!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1474,6 +1490,7 @@ default_imp_for_payouts_recipient!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1510,13 +1527,13 @@ impl<const T: u8>
}
default_imp_for_approve!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1557,6 +1574,7 @@ default_imp_for_approve!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1594,13 +1612,13 @@ impl<const T: u8>
}
default_imp_for_reject!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1641,6 +1659,7 @@ default_imp_for_reject!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1662,13 +1681,13 @@ macro_rules! default_imp_for_fraud_check {
impl<const T: u8> api::FraudCheck for connector::DummyConnector<T> {}
default_imp_for_fraud_check!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1707,6 +1726,7 @@ default_imp_for_fraud_check!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1746,13 +1766,13 @@ impl<const T: u8>
#[cfg(feature = "frm")]
default_imp_for_frm_sale!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1791,6 +1811,7 @@ default_imp_for_frm_sale!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1830,13 +1851,13 @@ impl<const T: u8>
#[cfg(feature = "frm")]
default_imp_for_frm_checkout!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1875,6 +1896,7 @@ default_imp_for_frm_checkout!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1914,13 +1936,13 @@ impl<const T: u8>
#[cfg(feature = "frm")]
default_imp_for_frm_transaction!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -1959,6 +1981,7 @@ default_imp_for_frm_transaction!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -1998,13 +2021,13 @@ impl<const T: u8>
#[cfg(feature = "frm")]
default_imp_for_frm_fulfillment!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -2043,6 +2066,7 @@ default_imp_for_frm_fulfillment!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -2082,13 +2106,13 @@ impl<const T: u8>
#[cfg(feature = "frm")]
default_imp_for_frm_record_return!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -2127,6 +2151,7 @@ default_imp_for_frm_record_return!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -2164,13 +2189,13 @@ impl<const T: u8>
}
default_imp_for_incremental_authorization!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -2210,6 +2235,7 @@ default_imp_for_incremental_authorization!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -2245,13 +2271,13 @@ impl<const T: u8>
{
}
default_imp_for_revoking_mandates!(
connector::Threedsecureio,
connector::Aci,
connector::Adyen,
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,
@ -2290,6 +2316,7 @@ default_imp_for_revoking_mandates!(
connector::Stax,
connector::Stripe,
connector::Shift4,
connector::Threedsecureio,
connector::Trustpay,
connector::Tsys,
connector::Volt,
@ -2373,6 +2400,7 @@ default_imp_for_connector_authentication!(
connector::Authorizedotnet,
connector::Bambora,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
connector::Bluesnap,
connector::Boku,

View File

@ -328,6 +328,7 @@ impl ConnectorData {
enums::Connector::Authorizedotnet => Ok(Box::new(&connector::Authorizedotnet)),
enums::Connector::Bambora => Ok(Box::new(&connector::Bambora)),
enums::Connector::Bankofamerica => Ok(Box::new(&connector::Bankofamerica)),
// enums::Connector::Billwerk => Ok(Box::new(&connector::Billwerk)), Added as template code for future usage
enums::Connector::Bitpay => Ok(Box::new(&connector::Bitpay)),
enums::Connector::Bluesnap => Ok(Box::new(&connector::Bluesnap)),
enums::Connector::Boku => Ok(Box::new(&connector::Boku)),

View File

@ -188,6 +188,7 @@ impl ForeignTryFrom<api_enums::Connector> for common_enums::RoutableConnectors {
api_enums::Connector::Authorizedotnet => Self::Authorizedotnet,
api_enums::Connector::Bambora => Self::Bambora,
api_enums::Connector::Bankofamerica => Self::Bankofamerica,
// api_enums::Connector::Billwerk => Self::Billwerk, Added as template code for future usage
api_enums::Connector::Bitpay => Self::Bitpay,
api_enums::Connector::Bluesnap => Self::Bluesnap,
api_enums::Connector::Boku => Self::Boku,

View File

@ -0,0 +1,421 @@
use masking::Secret;
use router::types::{self, api, storage::enums};
use test_utils::connector_auth;
use crate::utils::{self, ConnectorActions};
#[derive(Clone, Copy)]
struct BillwerkTest;
impl ConnectorActions for BillwerkTest {}
impl utils::Connector for BillwerkTest {
fn get_data(&self) -> types::api::ConnectorData {
use router::connector::Billwerk;
types::api::ConnectorData {
connector: Box::new(&Billwerk),
// Added as Dummy connector as template code is added for future usage
connector_name: types::Connector::DummyConnector1,
get_token: types::api::GetToken::Connector,
merchant_connector_id: None,
}
}
fn get_auth_token(&self) -> types::ConnectorAuthType {
utils::to_connector_auth_type(
connector_auth::ConnectorAuthentication::new()
.billwerk
.expect("Missing connector authentication configuration")
.into(),
)
}
fn get_name(&self) -> String {
"billwerk".to_string()
}
}
static CONNECTOR: BillwerkTest = BillwerkTest {};
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: router::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: router::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 scenerios
// 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: types::api::PaymentMethodData::Card(api::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: types::api::PaymentMethodData::Card(api::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: types::api::PaymentMethodData::Card(api::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

View File

@ -13,6 +13,8 @@ mod authorizedotnet;
mod bambora;
#[cfg(feature = "dummy_connector")]
mod bankofamerica;
#[cfg(feature = "dummy_connector")]
mod billwerk;
mod bitpay;
mod bluesnap;
mod boku;

View File

@ -198,3 +198,7 @@ key1= "Trankey"
[threedsecureio]
api_key="API Key"
[billwerk]
api_key="API Key"

View File

@ -18,6 +18,7 @@ pub struct ConnectorAuthentication {
pub authorizedotnet: Option<BodyKey>,
pub bambora: Option<BodyKey>,
pub bankofamerica: Option<SignatureKey>,
pub billwerk: Option<HeaderKey>,
pub bitpay: Option<HeaderKey>,
pub bluesnap: Option<BodyKey>,
pub boku: Option<BodyKey>,

View File

@ -71,6 +71,7 @@ applepay.base_url = "https://apple-pay-gateway.apple.com/"
authorizedotnet.base_url = "https://apitest.authorize.net/xml/v1/request.api"
bambora.base_url = "https://api.na.bambora.com"
bankofamerica.base_url = "https://apitest.merchant-services.bankofamerica.com/"
billwerk.base_url = "https://api.reepay.com/"
bitpay.base_url = "https://test.bitpay.com"
bluesnap.base_url = "https://sandbox.bluesnap.com/"
bluesnap.secondary_base_url = "https://sandpay.bluesnap.com/"
@ -142,6 +143,7 @@ cards = [
"authorizedotnet",
"bambora",
"bankofamerica",
"billwerk",
"bitpay",
"bluesnap",
"boku",

View File

@ -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 airwallex applepay authorizedotnet bambora bankofamerica bitpay bluesnap boku braintree cashtocode checkout coinbase cryptopay cybersource dlocal dummyconnector fiserv forte globalpay globepay gocardless helcim iatapay klarna mollie multisafepay nexinets noon nuvei opayo opennode payeezy payme paypal payu placetopay powertranz prophetpay rapyd shift4 square stax stripe threedsecureio trustpay tsys volt wise worldline worldpay "$1")
connectors=(aci adyen airwallex applepay authorizedotnet bambora bankofamerica billwerk bitpay bluesnap boku braintree cashtocode checkout coinbase cryptopay cybersource dlocal dummyconnector fiserv forte globalpay globepay gocardless helcim iatapay klarna mollie multisafepay nexinets noon nuvei opayo opennode payeezy payme paypal payu placetopay powertranz prophetpay rapyd shift4 square stax stripe threedsecureio trustpay tsys volt wise worldline worldpay "$1")
IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFS
res=`echo ${sorted[@]}`
sed -i'' -e "s/^ connectors=.*/ connectors=($res \"\$1\")/" $self.tmp