Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(connector): [Bambora APAC] Add payment flows (#5193)

Sakil Mostakf7abcee625e8
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index c75cabb767..2251bbac24 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -7724,6 +7724,7 @@
"airwallex",
"authorizedotnet",
"bambora",
+ "bamboraapac",
"bankofamerica",
"billwerk",
"bitpay",
@@ -19442,6 +19443,7 @@
"billwerk",
"bitpay",
"bambora",
+ "bamboraapac",
"bluesnap",
"boku",
"braintree",
diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml
index f3acbb4a85..962f885c08 100644
--- a/config/deployments/integration_test.toml
+++ b/config/deployments/integration_test.toml
@@ -26,7 +26,7 @@ airwallex.base_url = "https://api-demo.airwallex.com/"
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"
-bamboraapac.base_url = "https://demo.bambora.co.nz/interface/api/dts.asmx"
+bamboraapac.base_url = "https://demo.ippayments.com.au/interface/api/dts.asmx"
bankofamerica.base_url = "https://apitest.merchant-services.bankofamerica.com/"
billwerk.base_url = "https://api.reepay.com/"
billwerk.secondary_base_url = "https://card.reepay.com/"
diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml
index 09ee7a4d3f..05e3c7e90c 100644
--- a/config/deployments/sandbox.toml
+++ b/config/deployments/sandbox.toml
@@ -30,7 +30,7 @@ airwallex.base_url = "https://api-demo.airwallex.com/"
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"
-bamboraapac.base_url = "https://demo.bambora.co.nz/interface/api/dts.asmx"
+bamboraapac.base_url = "https://demo.ippayments.com.au/interface/api/dts.asmx"
bankofamerica.base_url = "https://apitest.merchant-services.bankofamerica.com/"
billwerk.base_url = "https://api.reepay.com/"
billwerk.secondary_base_url = "https://card.reepay.com/"
diff --git a/config/development.toml b/config/development.toml
index ade64172f2..b3548b35d0 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -176,7 +176,7 @@ airwallex.base_url = "https://api-demo.airwallex.com/"
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"
-bamboraapac.base_url = "https://demo.bambora.co.nz/interface/api/dts.asmx"
+bamboraapac.base_url = "https://demo.ippayments.com.au/interface/api/dts.asmx"
bankofamerica.base_url = "https://apitest.merchant-services.bankofamerica.com/"
billwerk.base_url = "https://api.reepay.com/"
billwerk.secondary_base_url = "https://card.reepay.com/"
diff --git a/crates/api_models/src/enums.rs b/crates/api_models/src/enums.rs
index 82db395677..29d344dfd5 100644
--- a/crates/api_models/src/enums.rs
+++ b/crates/api_models/src/enums.rs
@@ -78,7 +78,7 @@ pub enum Connector {
Airwallex,
Authorizedotnet,
Bambora,
- // Bamboraapac, commented for template
+ Bamboraapac,
Bankofamerica,
Billwerk,
Bitpay,
@@ -206,6 +206,7 @@ impl Connector {
| Self::Airwallex
| Self::Authorizedotnet
| Self::Bambora
+ | Self::Bamboraapac
| Self::Bankofamerica
| Self::Billwerk
| Self::Bitpay
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index e4f671a859..87d4f5e775 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -123,7 +123,7 @@ pub enum RoutableConnectors {
Billwerk,
Bitpay,
Bambora,
- // Bamboraapac, commented for template
+ Bamboraapac,
Bluesnap,
Boku,
Braintree,
diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs
index 9f29693928..baa606f82c 100644
--- a/crates/connector_configs/src/connector.rs
+++ b/crates/connector_configs/src/connector.rs
@@ -139,6 +139,7 @@ pub struct ConnectorConfig {
pub adyenplatform_payout: Option<ConnectorTomlConfig>,
pub airwallex: Option<ConnectorTomlConfig>,
pub authorizedotnet: Option<ConnectorTomlConfig>,
+ pub bamboraapac: Option<ConnectorTomlConfig>,
pub bankofamerica: Option<ConnectorTomlConfig>,
pub billwerk: Option<ConnectorTomlConfig>,
pub bitpay: Option<ConnectorTomlConfig>,
@@ -274,6 +275,7 @@ impl ConnectorConfig {
Connector::Adyenplatform => Err("Use get_payout_connector_config".to_string()),
Connector::Airwallex => Ok(connector_data.airwallex),
Connector::Authorizedotnet => Ok(connector_data.authorizedotnet),
+ Connector::Bamboraapac => Ok(connector_data.bamboraapac),
Connector::Bankofamerica => Ok(connector_data.bankofamerica),
Connector::Billwerk => Ok(connector_data.billwerk),
Connector::Bitpay => Ok(connector_data.bitpay),
diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.toml
index 94b7adfe2d..e62e8d8ea4 100644
--- a/crates/connector_configs/toml/development.toml
+++ b/crates/connector_configs/toml/development.toml
@@ -410,6 +410,49 @@ merchant_secret="Source verification key"
api_key="Passcode"
key1="Merchant Id"
+
+[bamboraapac]
+[[bamboraapac.credit]]
+ payment_method_type = "Mastercard"
+[[bamboraapac.credit]]
+ payment_method_type = "Visa"
+[[bamboraapac.credit]]
+ payment_method_type = "Interac"
+[[bamboraapac.credit]]
+ payment_method_type = "AmericanExpress"
+[[bamboraapac.credit]]
+ payment_method_type = "JCB"
+[[bamboraapac.credit]]
+ payment_method_type = "DinersClub"
+[[bamboraapac.credit]]
+ payment_method_type = "Discover"
+[[bamboraapac.credit]]
+ payment_method_type = "CartesBancaires"
+[[bamboraapac.credit]]
+ payment_method_type = "UnionPay"
+[[bamboraapac.debit]]
+ payment_method_type = "Mastercard"
+[[bamboraapac.debit]]
+ payment_method_type = "Visa"
+[[bamboraapac.debit]]
+ payment_method_type = "Interac"
+[[bamboraapac.debit]]
+ payment_method_type = "AmericanExpress"
+[[bamboraapac.debit]]
+ payment_method_type = "JCB"
+[[bamboraapac.debit]]
+ payment_method_type = "DinersClub"
+[[bamboraapac.debit]]
+ payment_method_type = "Discover"
+[[bamboraapac.debit]]
+ payment_method_type = "CartesBancaires"
+[[bamboraapac.debit]]
+ payment_method_type = "UnionPay"
+[bamboraapac.connector_auth.SignatureKey]
+api_key="Username"
+key1="Account Number"
+api_secret="Password"
+
[bankofamerica]
[[bankofamerica.credit]]
payment_method_type = "Mastercard"
diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.toml
index 7bb867b0cd..c31b75ad3f 100644
--- a/crates/connector_configs/toml/production.toml
+++ b/crates/connector_configs/toml/production.toml
@@ -423,6 +423,48 @@ merchant_config_currency="Currency"
api_key="Passcode"
key1="Merchant Id"
+[bamboraapac]
+[[bamboraapac.credit]]
+ payment_method_type = "Mastercard"
+[[bamboraapac.credit]]
+ payment_method_type = "Visa"
+[[bamboraapac.credit]]
+ payment_method_type = "Interac"
+[[bamboraapac.credit]]
+ payment_method_type = "AmericanExpress"
+[[bamboraapac.credit]]
+ payment_method_type = "JCB"
+[[bamboraapac.credit]]
+ payment_method_type = "DinersClub"
+[[bamboraapac.credit]]
+ payment_method_type = "Discover"
+[[bamboraapac.credit]]
+ payment_method_type = "CartesBancaires"
+[[bamboraapac.credit]]
+ payment_method_type = "UnionPay"
+[[bamboraapac.debit]]
+ payment_method_type = "Mastercard"
+[[bamboraapac.debit]]
+ payment_method_type = "Visa"
+[[bamboraapac.debit]]
+ payment_method_type = "Interac"
+[[bamboraapac.debit]]
+ payment_method_type = "AmericanExpress"
+[[bamboraapac.debit]]
+ payment_method_type = "JCB"
+[[bamboraapac.debit]]
+ payment_method_type = "DinersClub"
+[[bamboraapac.debit]]
+ payment_method_type = "Discover"
+[[bamboraapac.debit]]
+ payment_method_type = "CartesBancaires"
+[[bamboraapac.debit]]
+ payment_method_type = "UnionPay"
+[bamboraapac.connector_auth.SignatureKey]
+api_key="Username"
+key1="Account Number"
+api_secret="Password"
+
[bankofamerica]
[[bankofamerica.credit]]
payment_method_type = "Mastercard"
diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.toml
index a02e3be94b..5b44dc1551 100644
--- a/crates/connector_configs/toml/sandbox.toml
+++ b/crates/connector_configs/toml/sandbox.toml
@@ -410,6 +410,48 @@ merchant_secret="Source verification key"
api_key="Passcode"
key1="Merchant Id"
+[bamboraapac]
+[[bamboraapac.credit]]
+ payment_method_type = "Mastercard"
+[[bamboraapac.credit]]
+ payment_method_type = "Visa"
+[[bamboraapac.credit]]
+ payment_method_type = "Interac"
+[[bamboraapac.credit]]
+ payment_method_type = "AmericanExpress"
+[[bamboraapac.credit]]
+ payment_method_type = "JCB"
+[[bamboraapac.credit]]
+ payment_method_type = "DinersClub"
+[[bamboraapac.credit]]
+ payment_method_type = "Discover"
+[[bamboraapac.credit]]
+ payment_method_type = "CartesBancaires"
+[[bamboraapac.credit]]
+ payment_method_type = "UnionPay"
+[[bamboraapac.debit]]
+ payment_method_type = "Mastercard"
+[[bamboraapac.debit]]
+ payment_method_type = "Visa"
+[[bamboraapac.debit]]
+ payment_method_type = "Interac"
+[[bamboraapac.debit]]
+ payment_method_type = "AmericanExpress"
+[[bamboraapac.debit]]
+ payment_method_type = "JCB"
+[[bamboraapac.debit]]
+ payment_method_type = "DinersClub"
+[[bamboraapac.debit]]
+ payment_method_type = "Discover"
+[[bamboraapac.debit]]
+ payment_method_type = "CartesBancaires"
+[[bamboraapac.debit]]
+ payment_method_type = "UnionPay"
+[bamboraapac.connector_auth.SignatureKey]
+api_key="Username"
+key1="Account Number"
+api_secret="Password"
+
[bankofamerica]
[[bankofamerica.credit]]
payment_method_type = "Mastercard"
diff --git a/crates/router/src/connector/bamboraapac.rs b/crates/router/src/connector/bamboraapac.rs
index f1f5fe4054..335453125e 100644
--- a/crates/router/src/connector/bamboraapac.rs
+++ b/crates/router/src/connector/bamboraapac.rs
@@ -2,29 +2,27 @@ pub mod transformers;
use common_utils::{
self,
+ ext_traits::XmlExt,
types::{AmountConvertor, MinorUnit, MinorUnitForConnector},
};
-use error_stack::{report, ResultExt};
-use masking::ExposeInterface;
+use diesel_models::enums;
+use error_stack::{report, Report, ResultExt};
+use hyperswitch_interfaces::consts;
use transformers as bamboraapac;
-use super::utils as connector_utils;
use crate::{
configs::settings,
+ connector::utils as connector_utils,
core::errors::{self, CustomResult},
events::connector_api_logs::ConnectorEvent,
headers,
- services::{
- self,
- request::{self, Mask},
- ConnectorIntegration, ConnectorValidation,
- },
+ services::{self, request, ConnectorIntegration, ConnectorValidation},
types::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt},
ErrorResponse, RequestContent, Response,
},
- utils::BytesExt,
+ utils::{self, BytesExt},
};
#[derive(Clone)]
@@ -69,19 +67,33 @@ where
{
fn build_headers(
&self,
- req: &types::RouterData<Flow, Request, Response>,
+ _req: &types::RouterData<Flow, Request, Response>,
_connectors: &settings::Connectors,
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
- let mut header = vec![(
+ let 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 ConnectorValidation for Bamboraapac {
+ fn validate_capture_method(
+ &self,
+ capture_method: Option<enums::CaptureMethod>,
+ _pmt: Option<enums::PaymentMethodType>,
+ ) -> CustomResult<(), errors::ConnectorError> {
+ let capture_method = capture_method.unwrap_or_default();
+ match capture_method {
+ enums::CaptureMethod::Automatic | enums::CaptureMethod::Manual => Ok(()),
+ enums::CaptureMethod::ManualMultiple | enums::CaptureMethod::Scheduled => Err(
+ connector_utils::construct_not_implemented_error_report(capture_method, self.id()),
+ ),
+ }
+ }
+}
+
impl ConnectorCommon for Bamboraapac {
fn id(&self) -> &'static str {
"bamboraapac"
@@ -92,53 +104,51 @@ impl ConnectorCommon for Bamboraapac {
}
fn common_get_content_type(&self) -> &'static str {
- "application/json"
+ "text/xml"
}
fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
connectors.bamboraapac.base_url.as_ref()
}
- fn get_auth_header(
- &self,
- auth_type: &types::ConnectorAuthType,
- ) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
- let auth = bamboraapac::BamboraapacAuthType::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: bamboraapac::BamboraapacErrorResponse = res
- .response
- .parse_struct("BamboraapacErrorResponse")
- .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,
- })
+ let response: Result<
+ bamboraapac::BamboraapacErrorResponse,
+ Report<common_utils::errors::ParsingError>,
+ > = res.response.parse_struct("BamboraapacErrorResponse");
+
+ match response {
+ Ok(response_data) => {
+ event_builder.map(|i| i.set_error_response_body(&response_data));
+ router_env::logger::info!(connector_response=?response_data);
+
+ Ok(ErrorResponse {
+ status_code: res.status_code,
+ code: response_data
+ .declined_code
+ .unwrap_or(consts::NO_ERROR_CODE.to_string()),
+ message: response_data
+ .declined_message
+ .clone()
+ .unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
+ reason: response_data.declined_message,
+ attempt_status: None,
+ connector_transaction_id: None,
+ })
+ }
+ Err(error_msg) => {
+ event_builder.map(|event| event.set_error(serde_json::json!({"error": res.response.escape_ascii().to_string(), "status_code": res.status_code})));
+ router_env::logger::error!(deserialization_error =? error_msg);
+ utils::handle_json_response_deserialization_failure(res, "bamboaraapac")
+ }
+ }
}
}
-impl ConnectorValidation for Bamboraapac {
- //TODO: implement functions when support enabled
-}
-
impl ConnectorIntegration<api::Session, types::PaymentsSessionData, types::PaymentsResponseData>
for Bamboraapac
{
@@ -177,9 +187,9 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
fn get_url(
&self,
_req: &types::PaymentsAuthorizeRouterData,
- _connectors: &settings::Connectors,
+ connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ Ok(self.base_url(connectors).to_string())
}
fn get_request_body(
@@ -193,9 +203,10 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
req.request.currency,
)?;
let connector_router_data = bamboraapac::BamboraapacRouterData::try_from((amount, req))?;
- let connector_req =
- bamboraapac::BamboraapacPaymentsRequest::try_from(&connector_router_data)?;
- Ok(RequestContent::Json(Box::new(connector_req)))
+
+ let connector_req = bamboraapac::get_payment_body(&connector_router_data)?;
+
+ Ok(RequestContent::RawBytes(connector_req))
}
fn build_request(
@@ -226,10 +237,15 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<types::PaymentsAuthorizeRouterData, errors::ConnectorError> {
- let response: bamboraapac::BamboraapacPaymentsResponse = res
- .response
- .parse_struct("Bamboraapac PaymentsAuthorizeResponse")
+ let response_data = html_to_xml_string_conversion(
+ String::from_utf8(res.response.to_vec())
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?,
+ );
+
+ let response = response_data
+ .parse_xml::<bamboraapac::BamboraapacPaymentsResponse>()
.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 {
@@ -266,9 +282,19 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
fn get_url(
&self,
_req: &types::PaymentsSyncRouterData,
- _connectors: &settings::Connectors,
+ connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ Ok(self.base_url(connectors).to_string())
+ }
+
+ fn get_request_body(
+ &self,
+ req: &types::PaymentsSyncRouterData,
+ _connectors: &settings::Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_req = bamboraapac::get_payment_sync_body(req)?;
+
+ Ok(RequestContent::RawBytes(connector_req))
}
fn build_request(
@@ -278,10 +304,13 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
Ok(Some(
services::RequestBuilder::new()
- .method(services::Method::Get)
+ .method(services::Method::Post)
.url(&types::PaymentsSyncType::get_url(self, req, connectors)?)
.attach_default_headers()
.headers(types::PaymentsSyncType::get_headers(self, req, connectors)?)
+ .set_body(types::PaymentsSyncType::get_request_body(
+ self, req, connectors,
+ )?)
.build(),
))
}
@@ -292,10 +321,15 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<types::PaymentsSyncRouterData, errors::ConnectorError> {
- let response: bamboraapac::BamboraapacPaymentsResponse = res
- .response
- .parse_struct("bamboraapac PaymentsSyncResponse")
+ let response_data = html_to_xml_string_conversion(
+ String::from_utf8(res.response.to_vec())
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?,
+ );
+
+ let response = response_data
+ .parse_xml::<bamboraapac::BamboraapacSyncResponse>()
.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 {
@@ -332,17 +366,26 @@ impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::Payme
fn get_url(
&self,
_req: &types::PaymentsCaptureRouterData,
- _connectors: &settings::Connectors,
+ connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ Ok(self.base_url(connectors).to_string())
}
fn get_request_body(
&self,
- _req: &types::PaymentsCaptureRouterData,
+ req: &types::PaymentsCaptureRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into())
+ let amount = connector_utils::convert_amount(
+ self.amount_converter,
+ req.request.minor_amount_to_capture,
+ req.request.currency,
+ )?;
+ let connector_router_data = bamboraapac::BamboraapacRouterData::try_from((amount, req))?;
+
+ let connector_req = bamboraapac::get_capture_body(&connector_router_data)?;
+
+ Ok(RequestContent::RawBytes(connector_req))
}
fn build_request(
@@ -371,12 +414,18 @@ impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::Payme
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<types::PaymentsCaptureRouterData, errors::ConnectorError> {
- let response: bamboraapac::BamboraapacPaymentsResponse = res
- .response
- .parse_struct("Bamboraapac PaymentsCaptureResponse")
+ let response_data = html_to_xml_string_conversion(
+ String::from_utf8(res.response.to_vec())
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?,
+ );
+
+ let response = response_data
+ .parse_xml::<bamboraapac::BamboraapacCaptureResponse>()
.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(),
@@ -403,7 +452,7 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
{
fn get_headers(
&self,
- req: &types::RefundsRouterData<api::Execute>,
+ req: &types::RefundExecuteRouterData,
connectors: &settings::Connectors,
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
self.build_headers(req, connectors)
@@ -415,33 +464,32 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
fn get_url(
&self,
- _req: &types::RefundsRouterData<api::Execute>,
- _connectors: &settings::Connectors,
+ _req: &types::RefundExecuteRouterData,
+ connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ Ok(self.base_url(connectors).to_string())
}
fn get_request_body(
&self,
- req: &types::RefundsRouterData<api::Execute>,
+ req: &types::RefundExecuteRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let refund_amount = connector_utils::convert_amount(
+ let amount = connector_utils::convert_amount(
self.amount_converter,
req.request.minor_refund_amount,
req.request.currency,
)?;
+ let connector_router_data = bamboraapac::BamboraapacRouterData::try_from((amount, req))?;
+
+ let connector_req = bamboraapac::get_refund_body(&connector_router_data)?;
- let connector_router_data =
- bamboraapac::BamboraapacRouterData::try_from((refund_amount, req))?;
- let connector_req =
- bamboraapac::BamboraapacRefundRequest::try_from(&connector_router_data)?;
- Ok(RequestContent::Json(Box::new(connector_req)))
+ Ok(RequestContent::RawBytes(connector_req))
}
fn build_request(
&self,
- req: &types::RefundsRouterData<api::Execute>,
+ req: &types::RefundExecuteRouterData,
connectors: &settings::Connectors,
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
let request = services::RequestBuilder::new()
@@ -460,16 +508,22 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
fn handle_response(
&self,
- data: &types::RefundsRouterData<api::Execute>,
+ data: &types::RefundExecuteRouterData,
event_builder: Option<&mut ConnectorEvent>,
res: Response,
- ) -> CustomResult<types::RefundsRouterData<api::Execute>, errors::ConnectorError> {
- let response: bamboraapac::RefundResponse = res
- .response
- .parse_struct("bamboraapac RefundResponse")
+ ) -> CustomResult<types::RefundExecuteRouterData, errors::ConnectorError> {
+ let response_data = html_to_xml_string_conversion(
+ String::from_utf8(res.response.to_vec())
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?,
+ );
+
+ let response = response_data
+ .parse_xml::<bamboraapac::BamboraapacRefundsResponse>()
.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(),
@@ -504,9 +558,19 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
fn get_url(
&self,
_req: &types::RefundSyncRouterData,
- _connectors: &settings::Connectors,
+ connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ Ok(self.base_url(connectors).to_string())
+ }
+
+ fn get_request_body(
+ &self,
+ req: &types::RefundSyncRouterData,
+ _connectors: &settings::Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_req = bamboraapac::get_refund_sync_body(req)?;
+
+ Ok(RequestContent::RawBytes(connector_req))
}
fn build_request(
@@ -516,7 +580,7 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
Ok(Some(
services::RequestBuilder::new()
- .method(services::Method::Get)
+ .method(services::Method::Post)
.url(&types::RefundSyncType::get_url(self, req, connectors)?)
.attach_default_headers()
.headers(types::RefundSyncType::get_headers(self, req, connectors)?)
@@ -533,10 +597,15 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<types::RefundSyncRouterData, errors::ConnectorError> {
- let response: bamboraapac::RefundResponse = res
- .response
- .parse_struct("bamboraapac RefundSyncResponse")
+ let response_data = html_to_xml_string_conversion(
+ String::from_utf8(res.response.to_vec())
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?,
+ );
+
+ let response = response_data
+ .parse_xml::<bamboraapac::BamboraapacSyncResponse>()
.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 {
@@ -578,3 +647,7 @@ impl api::IncomingWebhook for Bamboraapac {
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
}
}
+
+fn html_to_xml_string_conversion(res: String) -> String {
+ res.replace("&lt;", "<").replace("&gt;", ">")
+}
diff --git a/crates/router/src/connector/bamboraapac/transformers.rs b/crates/router/src/connector/bamboraapac/transformers.rs
index 4d0e1a28ff..d660278fba 100644
--- a/crates/router/src/connector/bamboraapac/transformers.rs
+++ b/crates/router/src/connector/bamboraapac/transformers.rs
@@ -1,22 +1,25 @@
-use masking::Secret;
+use common_utils::types::MinorUnit;
+use error_stack::ResultExt;
+use hyperswitch_interfaces::consts;
+use masking::{PeekInterface, Secret};
use serde::{Deserialize, Serialize};
use crate::{
- connector::utils::PaymentsAuthorizeRequestData,
+ connector::utils::{self, CardData, RouterData},
core::errors,
- types::{self, api, domain, storage::enums, MinorUnit},
+ types::{self, domain, storage::enums, transformers::ForeignFrom},
};
-//TODO: Fill the struct with respective fields
+type Error = error_stack::Report<errors::ConnectorError>;
+
pub struct BamboraapacRouterData<T> {
- pub amount: MinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
+ pub amount: MinorUnit,
pub router_data: T,
}
impl<T> TryFrom<(MinorUnit, T)> for BamboraapacRouterData<T> {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from((amount, item): (MinorUnit, 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,
@@ -24,211 +27,816 @@ impl<T> TryFrom<(MinorUnit, T)> for BamboraapacRouterData<T> {
}
}
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Serialize, Eq, PartialEq)]
-pub struct BamboraapacPaymentsRequest {
- amount: MinorUnit,
- card: BamboraapacCard,
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct BamboraapacMeta {
+ pub authorize_id: String,
}
-#[derive(Default, Debug, Serialize, Eq, PartialEq)]
-pub struct BamboraapacCard {
- number: cards::CardNumber,
- expiry_month: Secret<String>,
- expiry_year: Secret<String>,
- cvc: Secret<String>,
- complete: bool,
+// request body in soap format
+pub fn get_payment_body(
+ req: &BamboraapacRouterData<&types::PaymentsAuthorizeRouterData>,
+) -> Result<Vec<u8>, Error> {
+ let transaction_data = get_transaction_body(req)?;
+ let body = format!(
+ r#"
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:dts="http://www.ippayments.com.au/interface/api/dts">
+ <soapenv:Body>
+ <dts:SubmitSinglePayment>
+ <dts:trnXML>
+ <![CDATA[
+ {}
+ ]]>
+ </dts:trnXML>
+ </dts:SubmitSinglePayment>
+ </soapenv:Body>
+ </soapenv:Envelope>
+ "#,
+ transaction_data
+ );
+
+ Ok(body.as_bytes().to_vec())
}
-impl TryFrom<&BamboraapacRouterData<&types::PaymentsAuthorizeRouterData>>
- for BamboraapacPaymentsRequest
-{
- type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(
- item: &BamboraapacRouterData<&types::PaymentsAuthorizeRouterData>,
- ) -> Result<Self, Self::Error> {
- match item.router_data.request.payment_method_data.clone() {
- domain::PaymentMethodData::Card(req_card) => {
- let card = BamboraapacCard {
- 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()),
+fn get_transaction_body(
+ req: &BamboraapacRouterData<&types::PaymentsAuthorizeRouterData>,
+) -> Result<String, Error> {
+ let auth_details = BamboraapacAuthType::try_from(&req.router_data.connector_auth_type)?;
+ let transaction_type = get_transaction_type(req.router_data.request.capture_method)?;
+ let card_info = get_card_data(req.router_data)?;
+ let transaction_data = format!(
+ r#"
+ <Transaction>
+ <CustRef>{}</CustRef>
+ <Amount>{}</Amount>
+ <TrnType>{}</TrnType>
+ <AccountNumber>{}</AccountNumber>
+ {}
+ <Security>
+ <UserName>{}</UserName>
+ <Password>{}</Password>
+ </Security>
+ </Transaction>
+ "#,
+ req.router_data.connector_request_reference_id.to_owned(),
+ req.amount,
+ transaction_type,
+ auth_details.account_number.peek(),
+ card_info,
+ auth_details.username.peek(),
+ auth_details.password.peek(),
+ );
+
+ Ok(transaction_data)
+}
+
+fn get_card_data(req: &types::PaymentsAuthorizeRouterData) -> Result<String, Error> {
+ let card_holder_name = req.get_billing_full_name()?;
+ let card_data = match &req.request.payment_method_data {
+ domain::PaymentMethodData::Card(card) => {
+ format!(
+ r#"
+ <CreditCard Registered="False">
+ <CardNumber>{}</CardNumber>
+ <ExpM>{}</ExpM>
+ <ExpY>{}</ExpY>
+ <CVN>{}</CVN>
+ <CardHolderName>{}</CardHolderName>
+ </CreditCard>
+ "#,
+ card.card_number.get_card_no(),
+ card.card_exp_month.peek(),
+ card.get_expiry_year_4_digit().peek(),
+ card.card_cvc.peek(),
+ card_holder_name.peek(),
+ )
}
+ _ => {
+ return Err(errors::ConnectorError::NotImplemented(
+ utils::get_unimplemented_payment_method_error_message("Bambora APAC"),
+ ))?
+ }
+ };
+ Ok(card_data)
+}
+
+fn get_transaction_type(capture_method: Option<enums::CaptureMethod>) -> Result<u8, Error> {
+ match capture_method {
+ Some(enums::CaptureMethod::Automatic) => Ok(1),
+ Some(enums::CaptureMethod::Manual) => Ok(2),
+ _ => Err(errors::ConnectorError::CaptureMethodNotSupported)?,
}
}
-//TODO: Fill the struct with respective fields
-// Auth Struct
pub struct BamboraapacAuthType {
- pub(super) api_key: Secret<String>,
+ username: Secret<String>,
+ password: Secret<String>,
+ account_number: Secret<String>,
}
impl TryFrom<&types::ConnectorAuthType> for BamboraapacAuthType {
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(),
+ types::ConnectorAuthType::SignatureKey {
+ api_key,
+ key1,
+ api_secret,
+ } => Ok(Self {
+ username: api_key.to_owned(),
+ password: api_secret.to_owned(),
+ account_number: key1.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 BamboraapacPaymentStatus {
- Succeeded,
- Failed,
- #[default]
- Processing,
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename = "Envelope")]
+#[serde(rename_all = "PascalCase")]
+pub struct BamboraapacPaymentsResponse {
+ body: BodyResponse,
}
-impl From<BamboraapacPaymentStatus> for enums::AttemptStatus {
- fn from(item: BamboraapacPaymentStatus) -> Self {
- match item {
- BamboraapacPaymentStatus::Succeeded => Self::Charged,
- BamboraapacPaymentStatus::Failed => Self::Failure,
- BamboraapacPaymentStatus::Processing => Self::Authorizing,
- }
- }
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct BodyResponse {
+ submit_single_payment_response: SubmitSinglePaymentResponse,
}
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
-pub struct BamboraapacPaymentsResponse {
- status: BamboraapacPaymentStatus,
- id: String,
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct SubmitSinglePaymentResponse {
+ submit_single_payment_result: SubmitSinglePaymentResult,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct SubmitSinglePaymentResult {
+ response: PaymentResponse,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct PaymentResponse {
+ response_code: u8,
+ receipt: String,
+ declined_code: Option<String>,
+ declined_message: Option<String>,
+}
+
+fn get_attempt_status(
+ response_code: u8,
+ capture_method: Option<enums::CaptureMethod>,
+) -> enums::AttemptStatus {
+ match response_code {
+ 0 => match capture_method {
+ Some(enums::CaptureMethod::Automatic) => enums::AttemptStatus::Charged,
+ Some(enums::CaptureMethod::Manual) => enums::AttemptStatus::Authorized,
+ _ => enums::AttemptStatus::Pending,
+ },
+ 1 => enums::AttemptStatus::Failure,
+ _ => enums::AttemptStatus::Pending,
+ }
}
-impl<F, T>
+impl<F>
TryFrom<
- types::ResponseRouterData<F, BamboraapacPaymentsResponse, T, types::PaymentsResponseData>,
- > for types::RouterData<F, T, types::PaymentsResponseData>
+ types::ResponseRouterData<
+ F,
+ BamboraapacPaymentsResponse,
+ types::PaymentsAuthorizeData,
+ types::PaymentsResponseData,
+ >,
+ > for types::RouterData<F, types::PaymentsAuthorizeData, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
item: types::ResponseRouterData<
F,
BamboraapacPaymentsResponse,
- T,
+ types::PaymentsAuthorizeData,
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
- })
+ let response_code = item
+ .response
+ .body
+ .submit_single_payment_response
+ .submit_single_payment_result
+ .response
+ .response_code;
+ let connector_transaction_id = item
+ .response
+ .body
+ .submit_single_payment_response
+ .submit_single_payment_result
+ .response
+ .receipt;
+ // transaction approved
+ if response_code == 0 {
+ Ok(Self {
+ status: get_attempt_status(response_code, item.data.request.capture_method),
+ response: Ok(types::PaymentsResponseData::TransactionResponse {
+ resource_id: types::ResponseId::ConnectorTransactionId(
+ connector_transaction_id.to_owned(),
+ ),
+ redirection_data: None,
+ mandate_reference: None,
+ connector_metadata: None,
+ network_txn_id: None,
+ connector_response_reference_id: Some(connector_transaction_id),
+ incremental_authorization_allowed: None,
+ charge_id: None,
+ }),
+ ..item.data
+ })
+ }
+ // transaction failed
+ else {
+ let code = item
+ .response
+ .body
+ .submit_single_payment_response
+ .submit_single_payment_result
+ .response
+ .declined_code
+ .unwrap_or(consts::NO_ERROR_CODE.to_string());
+
+ let declined_message = item
+ .response
+ .body
+ .submit_single_payment_response
+ .submit_single_payment_result
+ .response
+ .declined_message
+ .unwrap_or(consts::NO_ERROR_MESSAGE.to_string());
+ Ok(Self {
+ status: get_attempt_status(response_code, item.data.request.capture_method),
+ response: Err(types::ErrorResponse {
+ status_code: item.http_code,
+ code,
+ message: declined_message.to_owned(),
+ reason: Some(declined_message),
+ attempt_status: None,
+ connector_transaction_id: None,
+ }),
+ ..item.data
+ })
+ }
}
}
-//TODO: Fill the struct with respective fields
-// REFUND :
-// Type definition for RefundRequest
-#[derive(Default, Debug, Serialize)]
-pub struct BamboraapacRefundRequest {
- pub amount: MinorUnit,
+// capture body in soap format
+pub fn get_capture_body(
+ req: &BamboraapacRouterData<&types::PaymentsCaptureRouterData>,
+) -> Result<Vec<u8>, Error> {
+ let receipt = req.router_data.request.connector_transaction_id.to_owned();
+ let auth_details = BamboraapacAuthType::try_from(&req.router_data.connector_auth_type)?;
+ let body = format!(
+ r#"
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:dts="http://www.ippayments.com.au/interface/api/dts">
+ <soapenv:Body>
+ <dts:SubmitSingleCapture>
+ <dts:trnXML>
+ <![CDATA[
+ <Capture>
+ <Receipt>{}</Receipt>
+ <Amount>{}</Amount>
+ <Security>
+ <UserName>{}</UserName>
+ <Password>{}</Password>
+ </Security>
+ </Capture>
+ ]]>
+ </dts:trnXML>
+ </dts:SubmitSingleCapture>
+ </soapenv:Body>
+ </soapenv:Envelope>
+ "#,
+ receipt,
+ req.amount,
+ auth_details.username.peek(),
+ auth_details.password.peek(),
+ );
+
+ Ok(body.as_bytes().to_vec())
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename = "Envelope")]
+#[serde(rename_all = "PascalCase")]
+pub struct BamboraapacCaptureResponse {
+ body: CaptureBodyResponse,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct CaptureBodyResponse {
+ submit_single_capture_response: SubmitSingleCaptureResponse,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct SubmitSingleCaptureResponse {
+ submit_single_capture_result: SubmitSingleCaptureResult,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct SubmitSingleCaptureResult {
+ response: CaptureResponse,
}
-impl<F> TryFrom<&BamboraapacRouterData<&types::RefundsRouterData<F>>> for BamboraapacRefundRequest {
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct CaptureResponse {
+ response_code: u8,
+ receipt: String,
+ declined_code: Option<String>,
+ declined_message: Option<String>,
+}
+
+impl<F>
+ TryFrom<
+ types::ResponseRouterData<
+ F,
+ BamboraapacCaptureResponse,
+ types::PaymentsCaptureData,
+ types::PaymentsResponseData,
+ >,
+ > for types::RouterData<F, types::PaymentsCaptureData, types::PaymentsResponseData>
+{
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
- item: &BamboraapacRouterData<&types::RefundsRouterData<F>>,
+ item: types::ResponseRouterData<
+ F,
+ BamboraapacCaptureResponse,
+ types::PaymentsCaptureData,
+ types::PaymentsResponseData,
+ >,
) -> Result<Self, Self::Error> {
- Ok(Self {
- amount: item.amount.to_owned(),
- })
+ let response_code = item
+ .response
+ .body
+ .submit_single_capture_response
+ .submit_single_capture_result
+ .response
+ .response_code;
+ let connector_transaction_id = item
+ .response
+ .body
+ .submit_single_capture_response
+ .submit_single_capture_result
+ .response
+ .receipt;
+
+ // storing receipt_id of authorize to metadata for future usage
+ let connector_metadata = Some(serde_json::json!(BamboraapacMeta {
+ authorize_id: item.data.request.connector_transaction_id.to_owned()
+ }));
+ // transaction approved
+ if response_code == 0 {
+ Ok(Self {
+ status: enums::AttemptStatus::Charged,
+ response: Ok(types::PaymentsResponseData::TransactionResponse {
+ resource_id: types::ResponseId::ConnectorTransactionId(
+ connector_transaction_id.to_owned(),
+ ),
+ redirection_data: None,
+ mandate_reference: None,
+ connector_metadata,
+ network_txn_id: None,
+ connector_response_reference_id: Some(connector_transaction_id),
+ incremental_authorization_allowed: None,
+ charge_id: None,
+ }),
+ ..item.data
+ })
+ }
+ // transaction failed
+ else {
+ let code = item
+ .response
+ .body
+ .submit_single_capture_response
+ .submit_single_capture_result
+ .response
+ .declined_code
+ .unwrap_or(consts::NO_ERROR_CODE.to_string());
+ let declined_message = item
+ .response
+ .body
+ .submit_single_capture_response
+ .submit_single_capture_result
+ .response
+ .declined_message
+ .unwrap_or(consts::NO_ERROR_MESSAGE.to_string());
+ Ok(Self {
+ status: enums::AttemptStatus::Failure,
+ response: Err(types::ErrorResponse {
+ status_code: item.http_code,
+ code,
+ message: declined_message.to_owned(),
+ reason: Some(declined_message),
+ attempt_status: None,
+ connector_transaction_id: None,
+ }),
+ ..item.data
+ })
+ }
}
}
-// Type definition for Refund Response
+// refund body in soap format
+pub fn get_refund_body(
+ req: &BamboraapacRouterData<&types::RefundExecuteRouterData>,
+) -> Result<Vec<u8>, Error> {
+ let receipt = req.router_data.request.connector_transaction_id.to_owned();
+ let auth_details = BamboraapacAuthType::try_from(&req.router_data.connector_auth_type)?;
+ let body = format!(
+ r#"
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:dts="http://www.ippayments.com.au/interface/api/dts">
+ <soapenv:Header/>
+ <soapenv:Body>
+ <dts:SubmitSingleRefund>
+ <dts:trnXML>
+ <![CDATA[
+ <Refund>
+ <CustRef>{}</CustRef>
+ <Receipt>{}</Receipt>
+ <Amount>{}</Amount>
+ <Security>
+ <UserName>{}</UserName>
+ <Password>{}</Password>
+ </Security>
+ </Refund>
+ ]]>
+ </dts:trnXML>
+ </dts:SubmitSingleRefund>
+ </soapenv:Body>
+ </soapenv:Envelope>
+ "#,
+ req.router_data.request.refund_id.to_owned(),
+ receipt,
+ req.amount,
+ auth_details.username.peek(),
+ auth_details.password.peek(),
+ );
-#[allow(dead_code)]
-#[derive(Debug, Serialize, Default, Deserialize, Clone)]
-pub enum RefundStatus {
- Succeeded,
- Failed,
- #[default]
- Processing,
+ Ok(body.as_bytes().to_vec())
}
-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
- }
- }
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename = "Envelope")]
+#[serde(rename_all = "PascalCase")]
+pub struct BamboraapacRefundsResponse {
+ body: RefundBodyResponse,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct RefundBodyResponse {
+ submit_single_refund_response: SubmitSingleRefundResponse,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct SubmitSingleRefundResponse {
+ submit_single_refund_result: SubmitSingleRefundResult,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct SubmitSingleRefundResult {
+ response: RefundResponse,
}
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Clone, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
pub struct RefundResponse {
- id: String,
- status: RefundStatus,
+ response_code: u8,
+ receipt: String,
+ declined_code: Option<String>,
+ declined_message: Option<String>,
+}
+
+impl ForeignFrom<u8> for enums::RefundStatus {
+ fn foreign_from(item: u8) -> Self {
+ match item {
+ 0 => Self::Success,
+ 1 => Self::Failure,
+ _ => Self::Pending,
+ }
+ }
}
-impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>>
- for types::RefundsRouterData<api::Execute>
+impl<F>
+ TryFrom<
+ types::ResponseRouterData<
+ F,
+ BamboraapacRefundsResponse,
+ types::RefundsData,
+ types::RefundsResponseData,
+ >,
+ > for types::RouterData<F, types::RefundsData, types::RefundsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
- item: types::RefundsResponseRouterData<api::Execute, RefundResponse>,
+ item: types::ResponseRouterData<
+ F,
+ BamboraapacRefundsResponse,
+ types::RefundsData,
+ types::RefundsResponseData,
+ >,
) -> Result<Self, Self::Error> {
+ let response_code = item
+ .response
+ .body
+ .submit_single_refund_response
+ .submit_single_refund_result
+ .response
+ .response_code;
+ let connector_refund_id = item
+ .response
+ .body
+ .submit_single_refund_response
+ .submit_single_refund_result
+ .response
+ .receipt;
+
Ok(Self {
response: Ok(types::RefundsResponseData {
- connector_refund_id: item.response.id.to_string(),
- refund_status: enums::RefundStatus::from(item.response.status),
+ connector_refund_id: connector_refund_id.to_owned(),
+ refund_status: enums::RefundStatus::foreign_from(response_code),
}),
..item.data
})
}
}
-impl TryFrom<types::RefundsResponseRouterData<api::RSync, RefundResponse>>
- for types::RefundsRouterData<api::RSync>
+pub fn get_payment_sync_body(req: &types::PaymentsSyncRouterData) -> Result<Vec<u8>, Error> {
+ let auth_details = BamboraapacAuthType::try_from(&req.connector_auth_type)?;
+ let connector_transaction_id = req
+ .request
+ .connector_transaction_id
+ .get_connector_transaction_id()
+ .change_context(errors::ConnectorError::MissingConnectorTransactionID)?;
+ let body = format!(
+ r#"
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:dts="http://www.ippayments.com.au/interface/api/dts">
+ <soapenv:Header/>
+ <soapenv:Body>
+ <dts:QueryTransaction>
+ <dts:queryXML>
+ <![CDATA[
+ <QueryTransaction>
+ <Criteria>
+ <AccountNumber>{}</AccountNumber>
+ <TrnStartTimestamp>2024-06-23 00:00:00</TrnStartTimestamp>
+ <TrnEndTimestamp>2099-12-31 23:59:59</TrnEndTimestamp>
+ <Receipt>{}</Receipt>
+ </Criteria>
+ <Security>
+ <UserName>{}</UserName>
+ <Password>{}</Password>
+ </Security>
+ </QueryTransaction>
+ ]]>
+ </dts:queryXML>
+ </dts:QueryTransaction>
+ </soapenv:Body>
+ </soapenv:Envelope>
+ "#,
+ auth_details.account_number.peek(),
+ connector_transaction_id,
+ auth_details.username.peek(),
+ auth_details.password.peek(),
+ );
+
+ Ok(body.as_bytes().to_vec())
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename = "Envelope")]
+#[serde(rename_all = "PascalCase")]
+pub struct BamboraapacSyncResponse {
+ body: SyncBodyResponse,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct SyncBodyResponse {
+ query_transaction_response: QueryTransactionResponse,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct QueryTransactionResponse {
+ query_transaction_result: QueryTransactionResult,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct QueryTransactionResult {
+ query_response: QueryResponse,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct QueryResponse {
+ response: SyncResponse,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct SyncResponse {
+ response_code: u8,
+ receipt: String,
+ declined_code: Option<String>,
+ declined_message: Option<String>,
+}
+
+impl<F>
+ TryFrom<
+ types::ResponseRouterData<
+ F,
+ BamboraapacSyncResponse,
+ types::PaymentsSyncData,
+ types::PaymentsResponseData,
+ >,
+ > for types::RouterData<F, types::PaymentsSyncData, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
- item: types::RefundsResponseRouterData<api::RSync, RefundResponse>,
+ item: types::ResponseRouterData<
+ F,
+ BamboraapacSyncResponse,
+ types::PaymentsSyncData,
+ types::PaymentsResponseData,
+ >,
+ ) -> Result<Self, Self::Error> {
+ let response_code = item
+ .response
+ .body
+ .query_transaction_response
+ .query_transaction_result
+ .query_response
+ .response
+ .response_code;
+ let connector_transaction_id = item
+ .response
+ .body
+ .query_transaction_response
+ .query_transaction_result
+ .query_response
+ .response
+ .receipt;
+ // transaction approved
+ if response_code == 0 {
+ Ok(Self {
+ status: get_attempt_status(response_code, item.data.request.capture_method),
+ response: Ok(types::PaymentsResponseData::TransactionResponse {
+ resource_id: types::ResponseId::ConnectorTransactionId(
+ connector_transaction_id.to_owned(),
+ ),
+ redirection_data: None,
+ mandate_reference: None,
+ connector_metadata: None,
+ network_txn_id: None,
+ connector_response_reference_id: Some(connector_transaction_id),
+ incremental_authorization_allowed: None,
+ charge_id: None,
+ }),
+ ..item.data
+ })
+ }
+ // transaction failed
+ else {
+ let code = item
+ .response
+ .body
+ .query_transaction_response
+ .query_transaction_result
+ .query_response
+ .response
+ .declined_code
+ .unwrap_or(consts::NO_ERROR_CODE.to_string());
+ let declined_message = item
+ .response
+ .body
+ .query_transaction_response
+ .query_transaction_result
+ .query_response
+ .response
+ .declined_message
+ .unwrap_or(consts::NO_ERROR_MESSAGE.to_string());
+ Ok(Self {
+ status: get_attempt_status(response_code, item.data.request.capture_method),
+ response: Err(types::ErrorResponse {
+ status_code: item.http_code,
+ code,
+ message: declined_message.to_owned(),
+ reason: Some(declined_message),
+ attempt_status: None,
+ connector_transaction_id: None,
+ }),
+ ..item.data
+ })
+ }
+ }
+}
+
+pub fn get_refund_sync_body(req: &types::RefundSyncRouterData) -> Result<Vec<u8>, Error> {
+ let auth_details = BamboraapacAuthType::try_from(&req.connector_auth_type)?;
+
+ let body = format!(
+ r#"
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:dts="http://www.ippayments.com.au/interface/api/dts">
+ <soapenv:Header/>
+ <soapenv:Body>
+ <dts:QueryTransaction>
+ <dts:queryXML>
+ <![CDATA[
+ <QueryTransaction>
+ <Criteria>
+ <AccountNumber>{}</AccountNumber>
+ <TrnStartTimestamp>2024-06-23 00:00:00</TrnStartTimestamp>
+ <TrnEndTimestamp>2099-12-31 23:59:59</TrnEndTimestamp>
+ <CustRef>{}</CustRef>
+ </Criteria>
+ <Security>
+ <UserName>{}</UserName>
+ <Password>{}</Password>
+ </Security>
+ </QueryTransaction>
+ ]]>
+ </dts:queryXML>
+ </dts:QueryTransaction>
+ </soapenv:Body>
+ </soapenv:Envelope>
+ "#,
+ auth_details.account_number.peek(),
+ req.request.refund_id,
+ auth_details.username.peek(),
+ auth_details.password.peek(),
+ );
+
+ Ok(body.as_bytes().to_vec())
+}
+
+impl<F>
+ TryFrom<
+ types::ResponseRouterData<
+ F,
+ BamboraapacSyncResponse,
+ types::RefundsData,
+ types::RefundsResponseData,
+ >,
+ > for types::RouterData<F, types::RefundsData, types::RefundsResponseData>
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: types::ResponseRouterData<
+ F,
+ BamboraapacSyncResponse,
+ types::RefundsData,
+ types::RefundsResponseData,
+ >,
) -> Result<Self, Self::Error> {
+ let response_code = item
+ .response
+ .body
+ .query_transaction_response
+ .query_transaction_result
+ .query_response
+ .response
+ .response_code;
+ let connector_refund_id = item
+ .response
+ .body
+ .query_transaction_response
+ .query_transaction_result
+ .query_response
+ .response
+ .receipt;
Ok(Self {
response: Ok(types::RefundsResponseData {
- connector_refund_id: item.response.id.to_string(),
- refund_status: enums::RefundStatus::from(item.response.status),
+ connector_refund_id: connector_refund_id.to_owned(),
+ refund_status: enums::RefundStatus::foreign_from(response_code),
}),
..item.data
})
}
}
-//TODO: Fill the struct with respective fields
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
pub struct BamboraapacErrorResponse {
- pub status_code: u16,
- pub code: String,
- pub message: String,
- pub reason: Option<String>,
+ pub declined_code: Option<String>,
+ pub declined_message: Option<String>,
}
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index dcc649279a..dc72ec2ba8 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -2180,10 +2180,10 @@ pub(crate) fn validate_auth_and_metadata_type_with_connector(
bambora::transformers::BamboraAuthType::try_from(val)?;
Ok(())
}
- // api_enums::Connector::Bamboraapac => {
- // bamboraapac::transformers::BamboraapacAuthType::try_from(val)?;
- // Ok(())
- // }
+ api_enums::Connector::Bamboraapac => {
+ bamboraapac::transformers::BamboraapacAuthType::try_from(val)?;
+ Ok(())
+ }
api_enums::Connector::Boku => {
boku::transformers::BokuAuthType::try_from(val)?;
Ok(())
diff --git a/crates/router/src/core/payments/connector_integration_v2_impls.rs b/crates/router/src/core/payments/connector_integration_v2_impls.rs
index f99f5fa5c1..b54838e525 100644
--- a/crates/router/src/core/payments/connector_integration_v2_impls.rs
+++ b/crates/router/src/core/payments/connector_integration_v2_impls.rs
@@ -608,6 +608,7 @@ default_imp_for_new_connector_integration_payment!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -690,6 +691,7 @@ default_imp_for_new_connector_integration_refund!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -767,6 +769,7 @@ default_imp_for_new_connector_integration_connector_access_token!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -866,6 +869,7 @@ default_imp_for_new_connector_integration_accept_dispute!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -947,6 +951,7 @@ default_imp_for_new_connector_integration_defend_dispute!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1012,6 +1017,7 @@ default_imp_for_new_connector_integration_submit_evidence!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1104,6 +1110,7 @@ default_imp_for_new_connector_integration_file_upload!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1178,6 +1185,7 @@ default_imp_for_new_connector_integration_payouts!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1262,6 +1270,7 @@ default_imp_for_new_connector_integration_payouts_create!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1346,6 +1355,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1430,6 +1440,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1514,6 +1525,7 @@ default_imp_for_new_connector_integration_payouts_cancel!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1598,6 +1610,7 @@ default_imp_for_new_connector_integration_payouts_quote!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1682,6 +1695,7 @@ default_imp_for_new_connector_integration_payouts_recipient!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1766,6 +1780,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1848,6 +1863,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -1922,6 +1938,7 @@ default_imp_for_new_connector_integration_frm!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -2006,6 +2023,7 @@ default_imp_for_new_connector_integration_frm_sale!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -2090,6 +2108,7 @@ default_imp_for_new_connector_integration_frm_checkout!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -2174,6 +2193,7 @@ default_imp_for_new_connector_integration_frm_transaction!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -2258,6 +2278,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -2342,6 +2363,7 @@ default_imp_for_new_connector_integration_frm_record_return!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -2423,6 +2445,7 @@ default_imp_for_new_connector_integration_revoking_mandates!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
@@ -2532,6 +2555,7 @@ default_imp_for_new_connector_integration_connector_authentication!(
connector::Airwallex,
connector::Authorizedotnet,
connector::Bambora,
+ connector::Bamboraapac,
connector::Bankofamerica,
connector::Billwerk,
connector::Bitpay,
diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs
index acb8b0ef93..443ca00f24 100644
--- a/crates/router/src/types/api.rs
+++ b/crates/router/src/types/api.rs
@@ -356,6 +356,9 @@ impl ConnectorData {
Ok(ConnectorEnum::Old(Box::new(&connector::Authorizedotnet)))
}
enums::Connector::Bambora => Ok(ConnectorEnum::Old(Box::new(&connector::Bambora))),
+ enums::Connector::Bamboraapac => {
+ Ok(ConnectorEnum::Old(Box::new(connector::Bamboraapac::new())))
+ }
enums::Connector::Bankofamerica => {
Ok(ConnectorEnum::Old(Box::new(&connector::Bankofamerica)))
}
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 8f3ef929b1..43f56b540c 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -217,7 +217,7 @@ impl ForeignTryFrom<api_enums::Connector> for common_enums::RoutableConnectors {
api_enums::Connector::Airwallex => Self::Airwallex,
api_enums::Connector::Authorizedotnet => Self::Authorizedotnet,
api_enums::Connector::Bambora => Self::Bambora,
- // api_enums::Connector::Bamboraapac => Self::Bamboraapac, commented for template
+ api_enums::Connector::Bamboraapac => Self::Bamboraapac,
api_enums::Connector::Bankofamerica => Self::Bankofamerica,
api_enums::Connector::Billwerk => Self::Billwerk,
api_enums::Connector::Bitpay => Self::Bitpay,
diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml
index 49561629c9..2f1aa1dbbd 100644
--- a/loadtest/config/development.toml
+++ b/loadtest/config/development.toml
@@ -77,7 +77,7 @@ airwallex.base_url = "https://api-demo.airwallex.com/"
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"
-bamboraapac.base_url = "https://demo.bambora.co.nz/interface/api/dts.asmx"
+bamboraapac.base_url = "https://demo.ippayments.com.au/interface/api/dts.asmx"
bankofamerica.base_url = "https://apitest.merchant-services.bankofamerica.com/"
billwerk.base_url = "https://api.reepay.com/"
billwerk.secondary_base_url = "https://card.reepay.com/"