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): [Fiuu] Add Card Flows (#5786)

awasthi21ed0d816248ee
diff --git a/Cargo.lock b/Cargo.lock
index 4897549b19..de688a61f7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3912,6 +3912,7 @@ dependencies = [
"api_models",
"async-trait",
"base64 0.22.1",
+ "bytes 1.7.1",
"cards",
"common_enums",
"common_utils",
@@ -3924,6 +3925,7 @@ dependencies = [
"once_cell",
"rand",
"regex",
+ "reqwest 0.11.27",
"ring 0.17.8",
"router_env",
"serde",
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json
index b1ea332e87..77ddc657fd 100644
--- a/api-reference-v2/openapi_spec.json
+++ b/api-reference-v2/openapi_spec.json
@@ -4475,6 +4475,7 @@
"ebanx",
"fiserv",
"fiservemea",
+ "fiuu",
"forte",
"globalpay",
"globepay",
@@ -16333,6 +16334,7 @@
"ebanx",
"fiserv",
"fiservemea",
+ "fiuu",
"forte",
"globalpay",
"globepay",
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index 2057212ec4..24bb66598e 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -8122,6 +8122,7 @@
"ebanx",
"fiserv",
"fiservemea",
+ "fiuu",
"forte",
"globalpay",
"globepay",
@@ -20776,6 +20777,7 @@
"ebanx",
"fiserv",
"fiservemea",
+ "fiuu",
"forte",
"globalpay",
"globepay",
diff --git a/crates/api_models/src/enums.rs b/crates/api_models/src/enums.rs
index eea76ab4bf..34a0445887 100644
--- a/crates/api_models/src/enums.rs
+++ b/crates/api_models/src/enums.rs
@@ -100,7 +100,7 @@ pub enum Connector {
Ebanx,
Fiserv,
Fiservemea,
- // Fiuu,
+ Fiuu,
Forte,
Globalpay,
Globepay,
@@ -215,7 +215,6 @@ impl Connector {
// Add Separate authentication support for connectors
// | Self::Novalnet
// | Self::Nexixpay
- // | Self::Fiuu
// | Self::Taxjar
| Self::Adyen
| Self::Adyenplatform
@@ -237,6 +236,7 @@ impl Connector {
| Self::Ebanx
| Self::Fiserv
| Self::Fiservemea
+ | Self::Fiuu
| Self::Forte
| Self::Globalpay
| Self::Globepay
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index 507db0301d..2de401934c 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -213,7 +213,7 @@ pub enum RoutableConnectors {
Ebanx,
Fiserv,
Fiservemea,
- // Fiuu,
+ Fiuu,
Forte,
Globalpay,
Globepay,
diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs
index 08dffb93c3..cb13ec9d86 100644
--- a/crates/connector_configs/src/connector.rs
+++ b/crates/connector_configs/src/connector.rs
@@ -174,7 +174,7 @@ pub struct ConnectorConfig {
pub ebanx_payout: Option<ConnectorTomlConfig>,
pub fiserv: Option<ConnectorTomlConfig>,
pub fiservemea: Option<ConnectorTomlConfig>,
- // pub fiuu: Option<ConnectorTomlConfig>,
+ pub fiuu: Option<ConnectorTomlConfig>,
pub forte: Option<ConnectorTomlConfig>,
pub globalpay: Option<ConnectorTomlConfig>,
pub globepay: Option<ConnectorTomlConfig>,
@@ -323,7 +323,7 @@ impl ConnectorConfig {
Connector::Ebanx => Ok(connector_data.ebanx_payout),
Connector::Fiserv => Ok(connector_data.fiserv),
Connector::Fiservemea => Ok(connector_data.fiservemea),
- // Connector::Fiuu => Ok(connector_data.fiuu),
+ Connector::Fiuu => Ok(connector_data.fiuu),
Connector::Forte => Ok(connector_data.forte),
Connector::Globalpay => Ok(connector_data.globalpay),
Connector::Globepay => Ok(connector_data.globepay),
diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.toml
index 6d515e8421..06825a107a 100644
--- a/crates/connector_configs/toml/development.toml
+++ b/crates/connector_configs/toml/development.toml
@@ -3988,4 +3988,46 @@ api_secret="CLE Secret"
[wellsfargo.connector_auth.SignatureKey]
api_key="Key"
key1="Merchant ID"
-api_secret="Shared Secret"
\ No newline at end of file
+api_secret="Shared Secret"
+
+[fiuu]
+[[fiuu.credit]]
+ payment_method_type = "Mastercard"
+[[fiuu.credit]]
+ payment_method_type = "Visa"
+[[fiuu.credit]]
+ payment_method_type = "Interac"
+[[fiuu.credit]]
+ payment_method_type = "AmericanExpress"
+[[fiuu.credit]]
+ payment_method_type = "JCB"
+[[fiuu.credit]]
+ payment_method_type = "DinersClub"
+[[fiuu.credit]]
+ payment_method_type = "Discover"
+[[fiuu.credit]]
+ payment_method_type = "CartesBancaires"
+[[fiuu.credit]]
+ payment_method_type = "UnionPay"
+[[fiuu.debit]]
+ payment_method_type = "Mastercard"
+[[fiuu.debit]]
+ payment_method_type = "Visa"
+[[fiuu.debit]]
+ payment_method_type = "Interac"
+[[fiuu.debit]]
+ payment_method_type = "AmericanExpress"
+[[fiuu.debit]]
+ payment_method_type = "JCB"
+[[fiuu.debit]]
+ payment_method_type = "DinersClub"
+[[fiuu.debit]]
+ payment_method_type = "Discover"
+[[fiuu.debit]]
+ payment_method_type = "CartesBancaires"
+[[fiuu.debit]]
+ payment_method_type = "UnionPay"
+[fiuu.connector_auth.SignatureKey]
+api_key="Verify Key"
+key1="Merchant ID"
+api_secret="Secret Key"
\ No newline at end of file
diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.toml
index 0899b43a93..3fc4f8c9f0 100644
--- a/crates/connector_configs/toml/production.toml
+++ b/crates/connector_configs/toml/production.toml
@@ -2971,4 +2971,47 @@ key1 = "datatrans MerchantId"
[wellsfargo.connector_auth.SignatureKey]
api_key="Key"
key1="Merchant ID"
-api_secret="Shared Secret"
\ No newline at end of file
+api_secret="Shared Secret"
+
+
+[fiuu]
+[[fiuu.credit]]
+ payment_method_type = "Mastercard"
+[[fiuu.credit]]
+ payment_method_type = "Visa"
+[[fiuu.credit]]
+ payment_method_type = "Interac"
+[[fiuu.credit]]
+ payment_method_type = "AmericanExpress"
+[[fiuu.credit]]
+ payment_method_type = "JCB"
+[[fiuu.credit]]
+ payment_method_type = "DinersClub"
+[[fiuu.credit]]
+ payment_method_type = "Discover"
+[[fiuu.credit]]
+ payment_method_type = "CartesBancaires"
+[[fiuu.credit]]
+ payment_method_type = "UnionPay"
+[[fiuu.debit]]
+ payment_method_type = "Mastercard"
+[[fiuu.debit]]
+ payment_method_type = "Visa"
+[[fiuu.debit]]
+ payment_method_type = "Interac"
+[[fiuu.debit]]
+ payment_method_type = "AmericanExpress"
+[[fiuu.debit]]
+ payment_method_type = "JCB"
+[[fiuu.debit]]
+ payment_method_type = "DinersClub"
+[[fiuu.debit]]
+ payment_method_type = "Discover"
+[[fiuu.debit]]
+ payment_method_type = "CartesBancaires"
+[[fiuu.debit]]
+ payment_method_type = "UnionPay"
+[fiuu.connector_auth.SignatureKey]
+api_key="Verify Key"
+key1="Merchant ID"
+api_secret="Secret Key"
\ No newline at end of file
diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.toml
index ebe7048c2b..9de845f0b5 100644
--- a/crates/connector_configs/toml/sandbox.toml
+++ b/crates/connector_configs/toml/sandbox.toml
@@ -3980,4 +3980,47 @@ api_secret="CLE Secret"
[wellsfargo.connector_auth.SignatureKey]
api_key="Key"
key1="Merchant ID"
-api_secret="Shared Secret"
\ No newline at end of file
+api_secret="Shared Secret"
+
+
+[fiuu]
+[[fiuu.credit]]
+ payment_method_type = "Mastercard"
+[[fiuu.credit]]
+ payment_method_type = "Visa"
+[[fiuu.credit]]
+ payment_method_type = "Interac"
+[[fiuu.credit]]
+ payment_method_type = "AmericanExpress"
+[[fiuu.credit]]
+ payment_method_type = "JCB"
+[[fiuu.credit]]
+ payment_method_type = "DinersClub"
+[[fiuu.credit]]
+ payment_method_type = "Discover"
+[[fiuu.credit]]
+ payment_method_type = "CartesBancaires"
+[[fiuu.credit]]
+ payment_method_type = "UnionPay"
+[[fiuu.debit]]
+ payment_method_type = "Mastercard"
+[[fiuu.debit]]
+ payment_method_type = "Visa"
+[[fiuu.debit]]
+ payment_method_type = "Interac"
+[[fiuu.debit]]
+ payment_method_type = "AmericanExpress"
+[[fiuu.debit]]
+ payment_method_type = "JCB"
+[[fiuu.debit]]
+ payment_method_type = "DinersClub"
+[[fiuu.debit]]
+ payment_method_type = "Discover"
+[[fiuu.debit]]
+ payment_method_type = "CartesBancaires"
+[[fiuu.debit]]
+ payment_method_type = "UnionPay"
+[fiuu.connector_auth.SignatureKey]
+api_key="Verify Key"
+key1="Merchant ID"
+api_secret="Secret Key"
\ No newline at end of file
diff --git a/crates/hyperswitch_connectors/Cargo.toml b/crates/hyperswitch_connectors/Cargo.toml
index 8ae48a0122..c0fdc2213a 100644
--- a/crates/hyperswitch_connectors/Cargo.toml
+++ b/crates/hyperswitch_connectors/Cargo.toml
@@ -15,12 +15,14 @@ actix-http = "3.6.0"
actix-web = "4.5.1"
async-trait = "0.1.79"
base64 = "0.22.0"
+bytes = "1.6.0"
error-stack = "0.4.1"
hex = "0.4.3"
http = "0.2.12"
once_cell = "1.19.0"
rand = "0.8.5"
regex = "1.10.4"
+reqwest = { version = "0.11.27" }
ring = "0.17.8"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
diff --git a/crates/hyperswitch_connectors/src/connectors/fiuu.rs b/crates/hyperswitch_connectors/src/connectors/fiuu.rs
index 957f8428c7..97b5092787 100644
--- a/crates/hyperswitch_connectors/src/connectors/fiuu.rs
+++ b/crates/hyperswitch_connectors/src/connectors/fiuu.rs
@@ -1,14 +1,17 @@
pub mod transformers;
+use std::collections::HashMap;
+
+use common_enums::{CaptureMethod, PaymentMethodType};
use common_utils::{
- errors::CustomResult,
+ errors::{self as common_errors, CustomResult},
ext_traits::BytesExt,
request::{Method, Request, RequestBuilder, RequestContent},
- types::{AmountConvertor, StringMinorUnit, StringMinorUnitForConnector},
+ types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector},
};
use error_stack::{report, ResultExt};
use hyperswitch_domain_models::{
- router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
+ router_data::{AccessToken, ErrorResponse, RouterData},
router_flow_types::{
access_token_auth::AccessTokenAuth,
payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void},
@@ -21,8 +24,8 @@ use hyperswitch_domain_models::{
},
router_response_types::{PaymentsResponseData, RefundsResponseData},
types::{
- PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData,
- RefundSyncRouterData, RefundsRouterData,
+ PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
+ PaymentsSyncRouterData, RefundSyncRouterData, RefundsRouterData,
},
};
use hyperswitch_interfaces::{
@@ -33,20 +36,64 @@ use hyperswitch_interfaces::{
types::{self, Response},
webhooks,
};
-use masking::{ExposeInterface, Mask};
+use masking::Secret;
+use reqwest::multipart::Form;
+use serde::{Deserialize, Serialize};
+use serde_json::Value;
use transformers as fiuu;
use crate::{constants::headers, types::ResponseRouterData, utils};
+fn parse_response<T>(data: &[u8]) -> Result<T, errors::ConnectorError>
+where
+ T: for<'de> Deserialize<'de>,
+{
+ let response_str = String::from_utf8(data.to_vec()).map_err(|e| {
+ router_env::logger::error!("Error in Deserializing Response Data: {:?}", e);
+ errors::ConnectorError::ResponseDeserializationFailed
+ })?;
+
+ let mut json = serde_json::Map::new();
+ let mut miscellaneous: HashMap<String, Secret<String>> = HashMap::new();
+
+ for line in response_str.lines() {
+ if let Some((key, value)) = line.split_once('=') {
+ if key.trim().is_empty() {
+ router_env::logger::error!("Null or empty key encountered in response.");
+ continue;
+ }
+
+ if let Some(old_value) = json.insert(key.to_string(), Value::String(value.to_string()))
+ {
+ router_env::logger::warn!("Repeated key encountered: {}", key);
+ miscellaneous.insert(key.to_string(), Secret::new(old_value.to_string()));
+ }
+ }
+ }
+ if !miscellaneous.is_empty() {
+ let misc_value = serde_json::to_value(miscellaneous).map_err(|e| {
+ router_env::logger::error!("Error serializing miscellaneous data: {:?}", e);
+ errors::ConnectorError::ResponseDeserializationFailed
+ })?;
+ json.insert("miscellaneous".to_string(), misc_value);
+ }
+
+ let response: T = serde_json::from_value(Value::Object(json)).map_err(|e| {
+ router_env::logger::error!("Error in Deserializing Response Data: {:?}", e);
+ errors::ConnectorError::ResponseDeserializationFailed
+ })?;
+
+ Ok(response)
+}
#[derive(Clone)]
pub struct Fiuu {
- amount_converter: &'static (dyn AmountConvertor<Output = StringMinorUnit> + Sync),
+ amount_converter: &'static (dyn AmountConvertor<Output = StringMajorUnit> + Sync),
}
impl Fiuu {
pub fn new() -> &'static Self {
&Self {
- amount_converter: &StringMinorUnitForConnector,
+ amount_converter: &StringMajorUnitForConnector,
}
}
}
@@ -76,15 +123,13 @@ where
{
fn build_headers(
&self,
- req: &RouterData<Flow, Request, Response>,
+ _req: &RouterData<Flow, Request, Response>,
_connectors: &Connectors,
) -> CustomResult<Vec<(String, masking::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)
}
}
@@ -96,31 +141,12 @@ impl ConnectorCommon for Fiuu {
fn get_currency_unit(&self) -> api::CurrencyUnit {
api::CurrencyUnit::Base
- // TODO! Check connector documentation, on which unit they are processing the currency.
- // If the connector accepts amount in lower unit ( i.e cents for USD) then return api::CurrencyUnit::Minor,
- // if connector accepts amount in base unit (i.e dollars for USD) then return api::CurrencyUnit::Base
- }
-
- fn common_get_content_type(&self) -> &'static str {
- "application/json"
}
fn base_url<'a>(&self, connectors: &'a Connectors) -> &'a str {
connectors.fiuu.base_url.as_ref()
}
- fn get_auth_header(
- &self,
- auth_type: &ConnectorAuthType,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
- let auth = fiuu::FiuuAuthType::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,
@@ -136,17 +162,53 @@ impl ConnectorCommon for Fiuu {
Ok(ErrorResponse {
status_code: res.status_code,
- code: response.code,
- message: response.message,
- reason: response.reason,
+ code: response.error_code.clone(),
+ message: response.error_desc.clone(),
+ reason: Some(response.error_desc.clone()),
attempt_status: None,
connector_transaction_id: None,
})
}
}
+pub fn build_form_from_struct<T: Serialize>(data: T) -> Result<Form, common_errors::ParsingError> {
+ let mut form = Form::new();
+ let serialized = serde_json::to_value(&data).map_err(|e| {
+ router_env::logger::error!("Error serializing data to JSON value: {:?}", e);
+ common_errors::ParsingError::EncodeError("json-value")
+ })?;
+ let serialized_object = serialized.as_object().ok_or_else(|| {
+ router_env::logger::error!("Error: Expected JSON object but got something else");
+ common_errors::ParsingError::EncodeError("Expected object")
+ })?;
+ for (key, values) in serialized_object {
+ let value = match values {
+ Value::String(s) => s.clone(),
+ Value::Number(n) => n.to_string(),
+ Value::Bool(b) => b.to_string(),
+ Value::Array(_) | Value::Object(_) | Value::Null => {
+ router_env::logger::error!(serialization_error =? "Form Construction Failed.");
+ "".to_string()
+ }
+ };
+ form = form.text(key.clone(), value.clone());
+ }
+ Ok(form)
+}
impl ConnectorValidation for Fiuu {
- //TODO: implement functions when support enabled
+ fn validate_capture_method(
+ &self,
+ capture_method: Option<CaptureMethod>,
+ _pmt: Option<PaymentMethodType>,
+ ) -> CustomResult<(), errors::ConnectorError> {
+ let capture_method = capture_method.unwrap_or_default();
+ match capture_method {
+ CaptureMethod::Automatic | CaptureMethod::Manual => Ok(()),
+ CaptureMethod::ManualMultiple | CaptureMethod::Scheduled => Err(
+ utils::construct_not_implemented_error_report(capture_method, self.id()),
+ ),
+ }
+ }
}
impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> for Fiuu {
@@ -166,16 +228,15 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
self.build_headers(req, connectors)
}
- fn get_content_type(&self) -> &'static str {
- self.common_get_content_type()
- }
-
fn get_url(
&self,
_req: &PaymentsAuthorizeRouterData,
- _connectors: &Connectors,
+ connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ Ok(format!(
+ "{}RMS/API/Direct/1.4.0/index.php",
+ self.base_url(connectors)
+ ))
}
fn get_request_body(
@@ -190,8 +251,10 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
)?;
let connector_router_data = fiuu::FiuuRouterData::from((amount, req));
- let connector_req = fiuu::FiuuPaymentsRequest::try_from(&connector_router_data)?;
- Ok(RequestContent::Json(Box::new(connector_req)))
+ let payment_request = fiuu::FiuuPaymentsRequest::try_from(&connector_router_data)?;
+ let connector_req = build_form_from_struct(payment_request)
+ .change_context(errors::ConnectorError::ParsingFailed)?;
+ Ok(RequestContent::FormData(connector_req))
}
fn build_request(
@@ -206,9 +269,6 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
self, req, connectors,
)?)
.attach_default_headers()
- .headers(types::PaymentsAuthorizeType::get_headers(
- self, req, connectors,
- )?)
.set_body(types::PaymentsAuthorizeType::get_request_body(
self, req, connectors,
)?)
@@ -252,17 +312,27 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Fiu
) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
self.build_headers(req, connectors)
}
-
- fn get_content_type(&self) -> &'static str {
- self.common_get_content_type()
- }
-
fn get_url(
&self,
_req: &PaymentsSyncRouterData,
- _connectors: &Connectors,
+ connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ let base_url = connectors
+ .fiuu
+ .secondary_base_url
+ .as_ref()
+ .ok_or(errors::ConnectorError::FailedToObtainIntegrationUrl)?;
+ Ok(format!("{}RMS/API/gate-query/index.php", base_url))
+ }
+ fn get_request_body(
+ &self,
+ req: &PaymentsSyncRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let sync_request = fiuu::FiuuPaymentSyncRequest::try_from(req)?;
+ let connector_req = build_form_from_struct(sync_request)
+ .change_context(errors::ConnectorError::ParsingFailed)?;
+ Ok(RequestContent::FormData(connector_req))
}
fn build_request(
@@ -272,10 +342,12 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Fiu
) -> CustomResult<Option<Request>, errors::ConnectorError> {
Ok(Some(
RequestBuilder::new()
- .method(Method::Get)
+ .method(Method::Post)
.url(&types::PaymentsSyncType::get_url(self, req, connectors)?)
+ .set_body(types::PaymentsSyncType::get_request_body(
+ self, req, connectors,
+ )?)
.attach_default_headers()
- .headers(types::PaymentsSyncType::get_headers(self, req, connectors)?)
.build(),
))
}
@@ -286,12 +358,10 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Fiu
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<PaymentsSyncRouterData, errors::ConnectorError> {
- let response: fiuu::FiuuPaymentsResponse = res
- .response
- .parse_struct("fiuu PaymentsSyncResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ let response: fiuu::FiuuPaymentSyncResponse = parse_response(&res.response)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
+
RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
@@ -309,32 +379,36 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Fiu
}
impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> for Fiuu {
- fn get_headers(
- &self,
- req: &PaymentsCaptureRouterData,
- connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
- self.build_headers(req, connectors)
- }
-
- fn get_content_type(&self) -> &'static str {
- self.common_get_content_type()
- }
-
fn get_url(
&self,
_req: &PaymentsCaptureRouterData,
- _connectors: &Connectors,
+ connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ let base_url = connectors
+ .fiuu
+ .secondary_base_url
+ .as_ref()
+ .ok_or(errors::ConnectorError::FailedToObtainIntegrationUrl)?;
+ Ok(format!("{}RMS/API/capstxn/index.php", base_url))
}
fn get_request_body(
&self,
- _req: &PaymentsCaptureRouterData,
+ req: &PaymentsCaptureRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into())
+ let amount = utils::convert_amount(
+ self.amount_converter,
+ req.request.minor_amount_to_capture,
+ req.request.currency,
+ )?;
+
+ let connector_router_data = fiuu::FiuuRouterData::from((amount, req));
+ let connector_req = build_form_from_struct(fiuu::PaymentCaptureRequest::try_from(
+ &connector_router_data,
+ )?)
+ .change_context(errors::ConnectorError::ParsingFailed)?;
+ Ok(RequestContent::FormData(connector_req))
}
fn build_request(
@@ -347,9 +421,6 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
.method(Method::Post)
.url(&types::PaymentsCaptureType::get_url(self, req, connectors)?)
.attach_default_headers()
- .headers(types::PaymentsCaptureType::get_headers(
- self, req, connectors,
- )?)
.set_body(types::PaymentsCaptureType::get_request_body(
self, req, connectors,
)?)
@@ -363,7 +434,7 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<PaymentsCaptureRouterData, errors::ConnectorError> {
- let response: fiuu::FiuuPaymentsResponse = res
+ let response: fiuu::PaymentCaptureResponse = res
.response
.parse_struct("Fiuu PaymentsCaptureResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
@@ -385,27 +456,87 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
}
}
-impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Fiuu {}
+impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Fiuu {
+ fn get_url(
+ &self,
+ _req: &PaymentsCancelRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ let base_url = connectors
+ .fiuu
+ .secondary_base_url
+ .as_ref()
+ .ok_or(errors::ConnectorError::FailedToObtainIntegrationUrl)?;
+ Ok(format!("{}RMS/API/refundAPI/refund.php", base_url))
+ }
+
+ fn get_request_body(
+ &self,
+ req: &PaymentsCancelRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_req = build_form_from_struct(fiuu::FiuuPaymentCancelRequest::try_from(req)?)
+ .change_context(errors::ConnectorError::ParsingFailed)?;
+ Ok(RequestContent::FormData(connector_req))
+ }
-impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Fiuu {
- fn get_headers(
+ fn build_request(
&self,
- req: &RefundsRouterData<Execute>,
+ req: &PaymentsCancelRouterData,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
- self.build_headers(req, connectors)
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ let request = Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .url(&types::PaymentsVoidType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .set_body(types::PaymentsVoidType::get_request_body(
+ self, req, connectors,
+ )?)
+ .build(),
+ );
+
+ Ok(request)
}
- fn get_content_type(&self) -> &'static str {
- self.common_get_content_type()
+ fn handle_response(
+ &self,
+ data: &PaymentsCancelRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PaymentsCancelRouterData, errors::ConnectorError> {
+ let response: fiuu::FiuuPaymentCancelResponse = parse_response(&res.response)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ .change_context(errors::ConnectorError::ResponseHandlingFailed)
}
+ 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<Execute, RefundsData, RefundsResponseData> for Fiuu {
fn get_url(
&self,
_req: &RefundsRouterData<Execute>,
- _connectors: &Connectors,
+ connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ let base_url = connectors
+ .fiuu
+ .secondary_base_url
+ .as_ref()
+ .ok_or(errors::ConnectorError::FailedToObtainIntegrationUrl)?;
+ Ok(format!("{}RMS/API/refundAPI/index.php", base_url))
}
fn get_request_body(
@@ -420,8 +551,10 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Fiuu {
)?;
let connector_router_data = fiuu::FiuuRouterData::from((refund_amount, req));
- let connector_req = fiuu::FiuuRefundRequest::try_from(&connector_router_data)?;
- Ok(RequestContent::Json(Box::new(connector_req)))
+ let connector_req =
+ build_form_from_struct(fiuu::FiuuRefundRequest::try_from(&connector_router_data)?)
+ .change_context(errors::ConnectorError::ParsingFailed)?;
+ Ok(RequestContent::FormData(connector_req))
}
fn build_request(
@@ -433,9 +566,6 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Fiuu {
.method(Method::Post)
.url(&types::RefundExecuteType::get_url(self, req, connectors)?)
.attach_default_headers()
- .headers(types::RefundExecuteType::get_headers(
- self, req, connectors,
- )?)
.set_body(types::RefundExecuteType::get_request_body(
self, req, connectors,
)?)
@@ -449,9 +579,9 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Fiuu {
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<RefundsRouterData<Execute>, errors::ConnectorError> {
- let response: fiuu::RefundResponse = res
+ let response: fiuu::FiuuRefundResponse = res
.response
- .parse_struct("fiuu RefundResponse")
+ .parse_struct("fiuu FiuuRefundResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
@@ -472,24 +602,27 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Fiuu {
}
impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Fiuu {
- fn get_headers(
+ fn get_url(
&self,
- req: &RefundSyncRouterData,
+ _req: &RefundSyncRouterData,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
- self.build_headers(req, connectors)
- }
-
- fn get_content_type(&self) -> &'static str {
- self.common_get_content_type()
+ ) -> CustomResult<String, errors::ConnectorError> {
+ let base_url = connectors
+ .fiuu
+ .secondary_base_url
+ .as_ref()
+ .ok_or(errors::ConnectorError::FailedToObtainIntegrationUrl)?;
+ Ok(format!("{}RMS/API/refundAPI/q_by_txn.php", base_url))
}
- fn get_url(
+ fn get_request_body(
&self,
- _req: &RefundSyncRouterData,
+ req: &RefundSyncRouterData,
_connectors: &Connectors,
- ) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_req = build_form_from_struct(fiuu::FiuuRefundSyncRequest::try_from(req)?)
+ .change_context(errors::ConnectorError::ParsingFailed)?;
+ Ok(RequestContent::FormData(connector_req))
}
fn build_request(
@@ -499,10 +632,9 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Fiuu {
) -> CustomResult<Option<Request>, errors::ConnectorError> {
Ok(Some(
RequestBuilder::new()
- .method(Method::Get)
+ .method(Method::Post)
.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,
)?)
@@ -516,10 +648,10 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Fiuu {
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<RefundSyncRouterData, errors::ConnectorError> {
- let response: fiuu::RefundResponse =
- res.response
- .parse_struct("fiuu RefundSyncResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ let response: fiuu::FiuuRefundSyncResponse = res
+ .response
+ .parse_struct("fiuu FiuuRefundSyncResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
diff --git a/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs b/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs
index d4067662a7..a45b31b896 100644
--- a/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs
@@ -1,31 +1,44 @@
-use common_enums::enums;
-use common_utils::types::StringMinorUnit;
+use std::collections::HashMap;
+
+use cards::CardNumber;
+use common_enums::{enums, CaptureMethod, Currency};
+use common_utils::{
+ crypto::GenerateDigest,
+ request::Method,
+ types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector},
+};
+use error_stack::{Report, ResultExt};
use hyperswitch_domain_models::{
payment_method_data::PaymentMethodData,
- router_data::{ConnectorAuthType, RouterData},
+ router_data::{ConnectorAuthType, ErrorResponse, RouterData},
router_flow_types::refunds::{Execute, RSync},
- router_request_types::ResponseId,
- router_response_types::{PaymentsResponseData, RefundsResponseData},
- types::{PaymentsAuthorizeRouterData, RefundsRouterData},
+ router_request_types::{PaymentsAuthorizeData, ResponseId},
+ router_response_types::{PaymentsResponseData, RedirectForm, RefundsResponseData},
+ types::{
+ PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
+ PaymentsSyncRouterData, RefundSyncRouterData, RefundsRouterData,
+ },
};
use hyperswitch_interfaces::errors;
-use masking::Secret;
+use masking::{PeekInterface, Secret};
use serde::{Deserialize, Serialize};
+use strum::Display;
use crate::{
- types::{RefundsResponseRouterData, ResponseRouterData},
- utils::PaymentsAuthorizeRequestData,
+ types::{
+ PaymentsCancelResponseRouterData, PaymentsCaptureResponseRouterData,
+ PaymentsSyncResponseRouterData, RefundsResponseRouterData, ResponseRouterData,
+ },
+ utils::{PaymentsAuthorizeRequestData, RouterData as _},
};
-//TODO: Fill the struct with respective fields
pub struct FiuuRouterData<T> {
- pub amount: StringMinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
+ pub amount: StringMajorUnit,
pub router_data: T,
}
-impl<T> From<(StringMinorUnit, T)> for FiuuRouterData<T> {
- fn from((amount, item): (StringMinorUnit, T)) -> Self {
- //Todo : use utils to convert the amount to the type of amount that a connector accepts
+impl<T> From<(StringMajorUnit, T)> for FiuuRouterData<T> {
+ fn from((amount, item): (StringMajorUnit, T)) -> Self {
Self {
amount,
router_data: item,
@@ -33,194 +46,834 @@ impl<T> From<(StringMinorUnit, T)> for FiuuRouterData<T> {
}
}
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Serialize, PartialEq)]
+pub struct FiuuAuthType {
+ pub(super) merchant_id: Secret<String>,
+ pub(super) verify_key: Secret<String>,
+ pub(super) secret_key: Secret<String>,
+}
+
+impl TryFrom<&ConnectorAuthType> for FiuuAuthType {
+ type Error = Report<errors::ConnectorError>;
+ fn try_from(auth_type: &ConnectorAuthType) -> Result<Self, Self::Error> {
+ match auth_type {
+ ConnectorAuthType::SignatureKey {
+ api_key,
+ key1,
+ api_secret,
+ } => Ok(Self {
+ merchant_id: key1.to_owned(),
+ verify_key: api_key.to_owned(),
+ secret_key: api_secret.to_owned(),
+ }),
+ _ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),
+ }
+ }
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+#[serde(rename_all = "UPPERCASE")]
+enum TxnType {
+ Sals,
+ Auts,
+}
+
+impl TryFrom<Option<CaptureMethod>> for TxnType {
+ type Error = Report<errors::ConnectorError>;
+ fn try_from(capture_method: Option<CaptureMethod>) -> Result<Self, Self::Error> {
+ match capture_method {
+ Some(CaptureMethod::Automatic) => Ok(Self::Sals),
+ Some(CaptureMethod::Manual) => Ok(Self::Auts),
+ _ => Err(errors::ConnectorError::CaptureMethodNotSupported.into()),
+ }
+ }
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+#[serde(rename_all = "UPPERCASE")]
+enum TxnChannel {
+ Creditan,
+}
+
+#[derive(Serialize, Debug, Deserialize)]
+#[serde(rename_all = "PascalCase")]
pub struct FiuuPaymentsRequest {
- amount: StringMinorUnit,
- card: FiuuCard,
+ #[serde(rename = "MerchantID")]
+ merchant_id: Secret<String>,
+ reference_no: String,
+ txn_type: TxnType,
+ txn_channel: TxnChannel,
+ txn_currency: Currency,
+ txn_amount: StringMajorUnit,
+ signature: Secret<String>,
+ #[serde(rename = "CC_PAN")]
+ cc_pan: CardNumber,
+ #[serde(rename = "CC_CVV2")]
+ cc_cvv2: Secret<String>,
+ #[serde(rename = "CC_MONTH")]
+ cc_month: Secret<String>,
+ #[serde(rename = "CC_YEAR")]
+ cc_year: Secret<String>,
+ #[serde(rename = "non_3DS")]
+ non_3ds: i32,
+ #[serde(rename = "ReturnURL")]
+ return_url: Option<String>,
}
-#[derive(Default, Debug, Serialize, Eq, PartialEq)]
-pub struct FiuuCard {
- number: cards::CardNumber,
- expiry_month: Secret<String>,
- expiry_year: Secret<String>,
- cvc: Secret<String>,
- complete: bool,
+pub fn calculate_signature(
+ signature_data: String,
+) -> Result<Secret<String>, Report<errors::ConnectorError>> {
+ let message = signature_data.as_bytes();
+ let encoded_data = hex::encode(
+ common_utils::crypto::Md5
+ .generate_digest(message)
+ .change_context(errors::ConnectorError::RequestEncodingFailed)?,
+ );
+ Ok(Secret::new(encoded_data))
}
impl TryFrom<&FiuuRouterData<&PaymentsAuthorizeRouterData>> for FiuuPaymentsRequest {
- type Error = error_stack::Report<errors::ConnectorError>;
+ type Error = Report<errors::ConnectorError>;
fn try_from(item: &FiuuRouterData<&PaymentsAuthorizeRouterData>) -> Result<Self, Self::Error> {
+ let auth = FiuuAuthType::try_from(&item.router_data.connector_auth_type)?;
+ let merchant_id = auth.merchant_id.peek().to_string();
+ let txn_currency = item.router_data.request.currency;
+ let txn_amount = item.amount.clone();
+ let reference_no = item.router_data.connector_request_reference_id.clone();
+ let verify_key = auth.verify_key.peek().to_string();
+ let signature = calculate_signature(format!(
+ "{}{merchant_id}{reference_no}{verify_key}",
+ txn_amount.get_amount_as_string()
+ ))?;
match item.router_data.request.payment_method_data.clone() {
- PaymentMethodData::Card(req_card) => {
- let card = FiuuCard {
- number: req_card.card_number,
- expiry_month: req_card.card_exp_month,
- expiry_year: req_card.card_exp_year,
- cvc: req_card.card_cvc,
- complete: item.router_data.request.is_auto_capture()?,
- };
- Ok(Self {
- amount: item.amount.clone(),
- card,
- })
- }
+ PaymentMethodData::Card(req_card) => Ok(Self {
+ merchant_id: auth.merchant_id,
+ reference_no,
+ txn_type: match item.router_data.request.is_auto_capture()? {
+ true => TxnType::Sals,
+ false => TxnType::Auts,
+ },
+ txn_channel: TxnChannel::Creditan,
+ txn_currency,
+ txn_amount,
+ signature,
+ cc_pan: req_card.card_number,
+ cc_cvv2: req_card.card_cvc,
+ cc_month: req_card.card_exp_month,
+ cc_year: req_card.card_exp_year,
+ non_3ds: match item.router_data.is_three_ds() {
+ false => 1,
+ true => 0,
+ },
+ return_url: item.router_data.request.router_return_url.clone(),
+ }),
_ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()),
}
}
}
-//TODO: Fill the struct with respective fields
-// Auth Struct
-pub struct FiuuAuthType {
- pub(super) api_key: Secret<String>,
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct FiuuPaymentsSuccessResponse {
+ pub reference_no: String,
+ #[serde(rename = "TxnID")]
+ pub txn_id: String,
+ pub txn_type: String,
+ pub txn_currency: String,
+ pub txn_amount: String,
+ pub txn_channel: String,
+ pub txn_data: TxnData,
}
-impl TryFrom<&ConnectorAuthType> for FiuuAuthType {
- type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(auth_type: &ConnectorAuthType) -> Result<Self, Self::Error> {
- match auth_type {
- ConnectorAuthType::HeaderKey { api_key } => Ok(Self {
- api_key: api_key.to_owned(),
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(untagged)]
+pub enum FiuuPaymentsResponse {
+ Success(Box<FiuuPaymentsSuccessResponse>),
+ Error(FiuuErrorResponse),
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct TxnData {
+ #[serde(rename = "RequestURL")]
+ pub request_url: String,
+ pub request_type: RequestType,
+ pub request_data: RequestData,
+ pub request_method: String,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "UPPERCASE")]
+pub enum RequestType {
+ Redirect,
+ Response,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
+pub struct ThreeDSResponseData {
+ #[serde(rename = "paRes")]
+ pa_res: String,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(untagged)]
+pub enum RequestData {
+ NonThreeDS(NonThreeDSResponseData),
+ ThreeDS(ThreeDSResponseData),
+}
+#[derive(Debug, Serialize, Deserialize)]
+pub struct NonThreeDSResponseData {
+ #[serde(rename = "tranID")]
+ pub tran_id: String,
+ pub status: String,
+ pub error_code: Option<String>,
+ pub error_desc: Option<String>,
+}
+
+impl<F>
+ TryFrom<
+ ResponseRouterData<F, FiuuPaymentsResponse, PaymentsAuthorizeData, PaymentsResponseData>,
+ > for RouterData<F, PaymentsAuthorizeData, PaymentsResponseData>
+{
+ type Error = Report<errors::ConnectorError>;
+ fn try_from(
+ item: ResponseRouterData<
+ F,
+ FiuuPaymentsResponse,
+ PaymentsAuthorizeData,
+ PaymentsResponseData,
+ >,
+ ) -> Result<Self, Self::Error> {
+ match item.response {
+ FiuuPaymentsResponse::Error(error) => Ok(Self {
+ response: Err(ErrorResponse {
+ code: error.error_code.clone(),
+ message: error.error_desc.clone(),
+ reason: Some(error.error_desc),
+ status_code: item.http_code,
+ attempt_status: None,
+ connector_transaction_id: None,
+ }),
+ ..item.data
}),
- _ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),
+ FiuuPaymentsResponse::Success(data) => match data.txn_data.request_data {
+ RequestData::ThreeDS(three_ds_data) => {
+ let form_fields = {
+ let mut map = HashMap::new();
+ map.insert("paRes".to_string(), three_ds_data.pa_res.clone());
+ map
+ };
+ let redirection_data = Some(RedirectForm::Form {
+ endpoint: data.txn_data.request_url.to_string(),
+ method: if data.txn_data.request_method.as_str() == "POST" {
+ Method::Post
+ } else {
+ Method::Get
+ },
+ form_fields,
+ });
+ Ok(Self {
+ status: enums::AttemptStatus::AuthenticationPending,
+ response: Ok(PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::ConnectorTransactionId(data.txn_id),
+ redirection_data,
+ mandate_reference: None,
+ connector_metadata: None,
+ network_txn_id: None,
+ connector_response_reference_id: None,
+ incremental_authorization_allowed: None,
+ charge_id: None,
+ }),
+ ..item.data
+ })
+ }
+
+ RequestData::NonThreeDS(non_threeds_data) => Ok(Self {
+ status: match non_threeds_data.status.as_str() {
+ "00" => {
+ if item.data.request.is_auto_capture()? {
+ Ok(enums::AttemptStatus::Charged)
+ } else {
+ Ok(enums::AttemptStatus::Authorized)
+ }
+ }
+ "11" => Ok(enums::AttemptStatus::Failure),
+ "22" => Ok(enums::AttemptStatus::Pending),
+ other => Err(errors::ConnectorError::UnexpectedResponseError(
+ bytes::Bytes::from(other.to_owned()),
+ )),
+ }?,
+ response: Ok(PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::ConnectorTransactionId(data.txn_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
+ }),
+ },
}
}
}
-// PaymentsResponse
-//TODO: Append the remaining status flags
-#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
-#[serde(rename_all = "lowercase")]
-pub enum FiuuPaymentStatus {
- Succeeded,
- Failed,
- #[default]
- Processing,
-}
-impl From<FiuuPaymentStatus> for common_enums::AttemptStatus {
- fn from(item: FiuuPaymentStatus) -> Self {
- match item {
- FiuuPaymentStatus::Succeeded => Self::Charged,
- FiuuPaymentStatus::Failed => Self::Failure,
- FiuuPaymentStatus::Processing => Self::Authorizing,
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct FiuuRefundRequest {
+ pub refund_type: RefundType,
+ #[serde(rename = "MerchantID")]
+ pub merchant_id: Secret<String>,
+ #[serde(rename = "RefID")]
+ pub ref_id: String,
+ #[serde(rename = "TxnID")]
+ pub txn_id: String,
+ pub amount: StringMajorUnit,
+ pub signature: Secret<String>,
+}
+#[derive(Debug, Serialize, Display)]
+pub enum RefundType {
+ #[serde(rename = "P")]
+ Partial,
+}
+impl RefundType {
+ pub fn as_str(&self) -> &'static str {
+ match self {
+ Self::Partial => "P",
}
}
}
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
-pub struct FiuuPaymentsResponse {
- status: FiuuPaymentStatus,
- id: String,
+impl TryFrom<&FiuuRouterData<&RefundsRouterData<Execute>>> for FiuuRefundRequest {
+ type Error = Report<errors::ConnectorError>;
+ fn try_from(item: &FiuuRouterData<&RefundsRouterData<Execute>>) -> Result<Self, Self::Error> {
+ let auth: FiuuAuthType = FiuuAuthType::try_from(&item.router_data.connector_auth_type)?;
+ let merchant_id = auth.merchant_id.peek().to_string();
+ let txn_amount = item.amount.clone();
+ let reference_no = item.router_data.connector_request_reference_id.clone();
+ let txn_id = item.router_data.request.connector_transaction_id.clone();
+ let secret_key = auth.secret_key.peek().to_string();
+ Ok(Self {
+ refund_type: RefundType::Partial,
+ merchant_id: auth.merchant_id,
+ ref_id: reference_no.clone(),
+ txn_id: txn_id.clone(),
+ amount: txn_amount.clone(),
+ signature: calculate_signature(format!(
+ "{}{merchant_id}{reference_no}{txn_id}{}{secret_key}",
+ RefundType::Partial.as_str(),
+ txn_amount.get_amount_as_string()
+ ))?,
+ })
+ }
}
-impl<F, T> TryFrom<ResponseRouterData<F, FiuuPaymentsResponse, T, PaymentsResponseData>>
- for RouterData<F, T, PaymentsResponseData>
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct FiuuRefundSuccessResponse {
+ #[serde(rename = "RefundID")]
+ refund_id: i64,
+ status: String,
+}
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(untagged)]
+pub enum FiuuRefundResponse {
+ Success(FiuuRefundSuccessResponse),
+ Error(FiuuErrorResponse),
+}
+impl TryFrom<RefundsResponseRouterData<Execute, FiuuRefundResponse>>
+ for RefundsRouterData<Execute>
{
- type Error = error_stack::Report<errors::ConnectorError>;
+ type Error = Report<errors::ConnectorError>;
fn try_from(
- item: ResponseRouterData<F, FiuuPaymentsResponse, T, PaymentsResponseData>,
+ item: RefundsResponseRouterData<Execute, FiuuRefundResponse>,
) -> Result<Self, Self::Error> {
- Ok(Self {
- status: common_enums::AttemptStatus::from(item.response.status),
- response: Ok(PaymentsResponseData::TransactionResponse {
- resource_id: ResponseId::ConnectorTransactionId(item.response.id),
- redirection_data: None,
- mandate_reference: None,
- connector_metadata: None,
- network_txn_id: None,
- connector_response_reference_id: None,
- incremental_authorization_allowed: None,
- charge_id: None,
+ match item.response {
+ FiuuRefundResponse::Error(error) => Ok(Self {
+ response: Err(ErrorResponse {
+ code: error.error_code.clone(),
+ message: error.error_desc.clone(),
+ reason: Some(error.error_desc),
+ status_code: item.http_code,
+ attempt_status: None,
+ connector_transaction_id: None,
+ }),
+ ..item.data
}),
- ..item.data
- })
+ FiuuRefundResponse::Success(refund_data) => Ok(Self {
+ response: Ok(RefundsResponseData {
+ connector_refund_id: refund_data.refund_id.to_string(),
+ refund_status: match refund_data.status.as_str() {
+ "00" => Ok(enums::RefundStatus::Success),
+ "11" => Ok(enums::RefundStatus::Failure),
+ "22" => Ok(enums::RefundStatus::Pending),
+ other => Err(errors::ConnectorError::UnexpectedResponseError(
+ bytes::Bytes::from(other.to_owned()),
+ )),
+ }?,
+ }),
+ ..item.data
+ }),
+ }
}
}
-//TODO: Fill the struct with respective fields
-// REFUND :
-// Type definition for RefundRequest
-#[derive(Default, Debug, Serialize)]
-pub struct FiuuRefundRequest {
- pub amount: StringMinorUnit,
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct FiuuErrorResponse {
+ pub error_code: String,
+ pub error_desc: String,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct FiuuPaymentSyncRequest {
+ amount: StringMajorUnit,
+ #[serde(rename = "txID")]
+ tx_id: String,
+ domain: String,
+ skey: Secret<String>,
+}
+
+#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
+#[serde(rename_all = "PascalCase")]
+pub struct FiuuPaymentSyncResponse {
+ stat_code: String,
+ stat_name: StatName,
+ #[serde(rename = "TranID")]
+ tran_id: String,
+ error_code: String,
+ error_desc: String,
+ #[serde(rename = "miscellaneous")]
+ miscellaneous: Option<HashMap<String, Secret<String>>>,
+}
+
+#[derive(Debug, Serialize, Deserialize, Display, Clone, Copy, PartialEq)]
+#[serde(rename_all = "lowercase")]
+pub enum StatName {
+ Captured,
+ Settled,
+ Authorized,
+ Failed,
+ Cancelled,
+ Chargeback,
+ Release,
+ #[serde(rename = "reject/hold")]
+ RejectHold,
+ Blocked,
+ #[serde(rename = "ReqCancel")]
+ ReqCancel,
+ #[serde(rename = "ReqChargeback")]
+ ReqChargeback,
+ #[serde(rename = "Pending")]
+ Pending,
+ #[serde(rename = "Unknown")]
+ Unknown,
+}
+impl TryFrom<&PaymentsSyncRouterData> for FiuuPaymentSyncRequest {
+ type Error = Report<errors::ConnectorError>;
+ fn try_from(item: &PaymentsSyncRouterData) -> Result<Self, Self::Error> {
+ let auth = FiuuAuthType::try_from(&item.connector_auth_type)?;
+ let txn_id = item
+ .request
+ .connector_transaction_id
+ .get_connector_transaction_id()
+ .change_context(errors::ConnectorError::MissingConnectorTransactionID)?;
+ let merchant_id = auth.merchant_id.peek().to_string();
+ let verify_key = auth.verify_key.peek().to_string();
+ let amount = StringMajorUnitForConnector
+ .convert(item.request.amount, item.request.currency)
+ .change_context(errors::ConnectorError::AmountConversionFailed)?;
+ Ok(Self {
+ amount: amount.clone(),
+ tx_id: txn_id.clone(),
+ domain: merchant_id.clone(),
+ skey: calculate_signature(format!(
+ "{txn_id}{merchant_id}{verify_key}{}",
+ amount.get_amount_as_string()
+ ))?,
+ })
+ }
}
-impl<F> TryFrom<&FiuuRouterData<&RefundsRouterData<F>>> for FiuuRefundRequest {
- type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(item: &FiuuRouterData<&RefundsRouterData<F>>) -> Result<Self, Self::Error> {
+impl TryFrom<PaymentsSyncResponseRouterData<FiuuPaymentSyncResponse>> for PaymentsSyncRouterData {
+ type Error = Report<errors::ConnectorError>;
+ fn try_from(
+ item: PaymentsSyncResponseRouterData<FiuuPaymentSyncResponse>,
+ ) -> Result<Self, Self::Error> {
+ let stat_name = item.response.stat_name;
+ let status = match item.response.stat_code.as_str() {
+ "00" => {
+ if stat_name == StatName::Captured || stat_name == StatName::Settled {
+ Ok(enums::AttemptStatus::Charged)
+ } else {
+ Ok(enums::AttemptStatus::Authorized)
+ }
+ }
+ "22" => Ok(enums::AttemptStatus::Pending),
+ "11" => Ok(enums::AttemptStatus::Failure),
+ other => Err(errors::ConnectorError::UnexpectedResponseError(
+ bytes::Bytes::from(other.to_owned()),
+ )),
+ }?;
+ let error_response = if status == enums::AttemptStatus::Failure {
+ Some(ErrorResponse {
+ status_code: item.http_code,
+ code: item.response.stat_code.as_str().to_owned(),
+ message: item.response.stat_name.clone().to_string(),
+ reason: Some(item.response.stat_name.clone().to_string()),
+ attempt_status: Some(enums::AttemptStatus::Failure),
+ connector_transaction_id: None,
+ })
+ } else {
+ None
+ };
+ let payments_response_data = PaymentsResponseData::TransactionResponse {
+ resource_id: item.data.request.connector_transaction_id.clone(),
+ 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,
+ };
Ok(Self {
- amount: item.amount.to_owned(),
+ status,
+ response: error_response.map_or_else(|| Ok(payments_response_data), Err),
+ ..item.data
})
}
}
-// Type definition for Refund Response
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct PaymentCaptureRequest {
+ domain: String,
+ #[serde(rename = "tranID")]
+ tran_id: String,
+ amount: StringMajorUnit,
+ #[serde(rename = "RefID")]
+ ref_id: String,
+ skey: Secret<String>,
+}
-#[allow(dead_code)]
-#[derive(Debug, Serialize, Default, Deserialize, Clone)]
-pub enum RefundStatus {
- Succeeded,
- Failed,
- #[default]
- Processing,
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "PascalCase")]
+pub struct PaymentCaptureResponse {
+ #[serde(rename = "TranID")]
+ tran_id: String,
+ stat_code: String,
}
-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
- }
+impl TryFrom<&FiuuRouterData<&PaymentsCaptureRouterData>> for PaymentCaptureRequest {
+ type Error = Report<errors::ConnectorError>;
+ fn try_from(item: &FiuuRouterData<&PaymentsCaptureRouterData>) -> Result<Self, Self::Error> {
+ let auth = FiuuAuthType::try_from(&item.router_data.connector_auth_type)?;
+ let merchant_id = auth.merchant_id.peek().to_string();
+ let amount = item.amount.clone();
+ let txn_id = item.router_data.request.connector_transaction_id.clone();
+ let verify_key = auth.verify_key.peek().to_string();
+ let signature = calculate_signature(format!(
+ "{txn_id}{}{merchant_id}{verify_key}",
+ amount.get_amount_as_string()
+ ))?;
+ Ok(Self {
+ domain: merchant_id,
+ tran_id: txn_id,
+ amount,
+ ref_id: item.router_data.connector_request_reference_id.clone(),
+ skey: signature,
+ })
}
}
-
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Clone, Serialize, Deserialize)]
-pub struct RefundResponse {
- id: String,
- status: RefundStatus,
+fn capture_status_codes() -> HashMap<&'static str, &'static str> {
+ [
+ ("00", "Capture successful"),
+ ("11", "Capture failed"),
+ ("12", "Invalid or unmatched security hash string"),
+ ("13", "Not a credit card transaction"),
+ ("15", "Requested day is on settlement day"),
+ ("16", "Forbidden transaction"),
+ ("17", "Transaction not found"),
+ ("18", "Missing required parameter"),
+ ("19", "Domain not found"),
+ ("20", "Temporary out of service"),
+ ("21", "Authorization expired"),
+ ("23", "Partial capture not allowed"),
+ ("24", "Transaction already captured"),
+ ("25", "Requested amount exceeds available capture amount"),
+ ("99", "General error (contact payment gateway support)"),
+ ]
+ .into_iter()
+ .collect()
}
-impl TryFrom<RefundsResponseRouterData<Execute, RefundResponse>> for RefundsRouterData<Execute> {
- type Error = error_stack::Report<errors::ConnectorError>;
+impl TryFrom<PaymentsCaptureResponseRouterData<PaymentCaptureResponse>>
+ for PaymentsCaptureRouterData
+{
+ type Error = Report<errors::ConnectorError>;
fn try_from(
- item: RefundsResponseRouterData<Execute, RefundResponse>,
+ item: PaymentsCaptureResponseRouterData<PaymentCaptureResponse>,
) -> Result<Self, Self::Error> {
+ let status_code = item.response.stat_code;
+
+ let status = match status_code.as_str() {
+ "00" => Ok(enums::AttemptStatus::Charged),
+ "22" => Ok(enums::AttemptStatus::Pending),
+ "11" | "12" | "13" | "15" | "16" | "17" | "18" | "19" | "20" | "21" | "23" | "24"
+ | "25" | "99" => Ok(enums::AttemptStatus::Failure),
+ other => Err(errors::ConnectorError::UnexpectedResponseError(
+ bytes::Bytes::from(other.to_owned()),
+ )),
+ }?;
+ let capture_message_status = capture_status_codes();
+ let error_response = if status == enums::AttemptStatus::Failure {
+ Some(ErrorResponse {
+ status_code: item.http_code,
+ code: status_code.to_owned(),
+ message: capture_message_status
+ .get(status_code.as_str())
+ .unwrap_or(&"NO_ERROR_MESSAGE")
+ .to_string(),
+ reason: Some(
+ capture_message_status
+ .get(status_code.as_str())
+ .unwrap_or(&"NO_ERROR_REASON")
+ .to_string(),
+ ),
+ attempt_status: None,
+ connector_transaction_id: None,
+ })
+ } else {
+ None
+ };
+ let payments_response_data = PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::ConnectorTransactionId(item.response.tran_id.to_string()),
+ 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,
+ };
Ok(Self {
- response: Ok(RefundsResponseData {
- connector_refund_id: item.response.id.to_string(),
- refund_status: enums::RefundStatus::from(item.response.status),
- }),
+ status,
+ response: error_response.map_or_else(|| Ok(payments_response_data), Err),
..item.data
})
}
}
-impl TryFrom<RefundsResponseRouterData<RSync, RefundResponse>> for RefundsRouterData<RSync> {
- type Error = error_stack::Report<errors::ConnectorError>;
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct FiuuPaymentCancelRequest {
+ #[serde(rename = "txnID")]
+ txn_id: String,
+ domain: String,
+ skey: Secret<String>,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "PascalCase")]
+pub struct FiuuPaymentCancelResponse {
+ #[serde(rename = "TranID")]
+ tran_id: String,
+ stat_code: String,
+ #[serde(rename = "miscellaneous")]
+ miscellaneous: Option<HashMap<String, Secret<String>>>,
+}
+
+impl TryFrom<&PaymentsCancelRouterData> for FiuuPaymentCancelRequest {
+ type Error = Report<errors::ConnectorError>;
+
+ fn try_from(item: &PaymentsCancelRouterData) -> Result<Self, Self::Error> {
+ let auth = FiuuAuthType::try_from(&item.connector_auth_type)?;
+ let txn_id = item.request.connector_transaction_id.clone();
+ let merchant_id = auth.merchant_id.peek().to_string();
+ let secret_key = auth.secret_key.peek().to_string();
+ Ok(Self {
+ txn_id: txn_id.clone(),
+ domain: merchant_id.clone(),
+ skey: calculate_signature(format!("{txn_id}{merchant_id}{secret_key}"))?,
+ })
+ }
+}
+
+fn void_status_codes() -> HashMap<&'static str, &'static str> {
+ [
+ ("00", "Success (will proceed the request)"),
+ ("11", "Failure"),
+ ("12", "Invalid or unmatched security hash string"),
+ ("13", "Not a refundable transaction"),
+ ("14", "Transaction date more than 180 days"),
+ ("15", "Requested day is on settlement day"),
+ ("16", "Forbidden transaction"),
+ ("17", "Transaction not found"),
+ ("18", "Duplicate partial refund request"),
+ ("19", "Merchant not found"),
+ ("20", "Missing required parameter"),
+ (
+ "21",
+ "Transaction must be in authorized/captured/settled status",
+ ),
+ ]
+ .into_iter()
+ .collect()
+}
+impl TryFrom<PaymentsCancelResponseRouterData<FiuuPaymentCancelResponse>>
+ for PaymentsCancelRouterData
+{
+ type Error = Report<errors::ConnectorError>;
fn try_from(
- item: RefundsResponseRouterData<RSync, RefundResponse>,
+ item: PaymentsCancelResponseRouterData<FiuuPaymentCancelResponse>,
) -> Result<Self, Self::Error> {
+ let status_code = item.response.stat_code;
+ let status = match status_code.as_str() {
+ "00" => Ok(enums::AttemptStatus::Voided),
+ "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "20" | "21" => {
+ Ok(enums::AttemptStatus::VoidFailed)
+ }
+ other => Err(errors::ConnectorError::UnexpectedResponseError(
+ bytes::Bytes::from(other.to_owned()),
+ )),
+ }?;
+ let void_message_status = void_status_codes();
+ let error_response = if status == enums::AttemptStatus::VoidFailed {
+ Some(ErrorResponse {
+ status_code: item.http_code,
+ code: status_code.to_owned(),
+ message: void_message_status
+ .get(status_code.as_str())
+ .unwrap_or(&"NO_ERROR_MESSAGE")
+ .to_string(),
+ reason: Some(
+ void_message_status
+ .get(status_code.as_str())
+ .unwrap_or(&"NO_ERROR_REASON")
+ .to_string(),
+ ),
+ attempt_status: None,
+ connector_transaction_id: None,
+ })
+ } else {
+ None
+ };
+ let payments_response_data = PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::ConnectorTransactionId(item.response.tran_id.to_string()),
+ 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,
+ };
Ok(Self {
- response: Ok(RefundsResponseData {
- connector_refund_id: item.response.id.to_string(),
- refund_status: enums::RefundStatus::from(item.response.status),
- }),
+ status,
+ response: error_response.map_or_else(|| Ok(payments_response_data), Err),
..item.data
})
}
}
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
-pub struct FiuuErrorResponse {
- pub status_code: u16,
- pub code: String,
- pub message: String,
- pub reason: Option<String>,
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct FiuuRefundSyncRequest {
+ #[serde(rename = "TxnID")]
+ txn_id: String,
+ #[serde(rename = "MerchantID")]
+ merchant_id: Secret<String>,
+ signature: Secret<String>,
+}
+
+impl TryFrom<&RefundSyncRouterData> for FiuuRefundSyncRequest {
+ type Error = Report<errors::ConnectorError>;
+
+ fn try_from(item: &RefundSyncRouterData) -> Result<Self, Self::Error> {
+ let auth = FiuuAuthType::try_from(&item.connector_auth_type)?;
+ let (txn_id, merchant_id, verify_key) = (
+ item.request.connector_transaction_id.clone(),
+ auth.merchant_id.peek().to_string(),
+ auth.verify_key.peek().to_string(),
+ );
+ let signature = calculate_signature(format!("{txn_id}{merchant_id}{verify_key}"))?;
+ Ok(Self {
+ txn_id,
+ merchant_id: auth.merchant_id,
+ signature,
+ })
+ }
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(untagged)]
+pub enum FiuuRefundSyncResponse {
+ Success(Vec<RefundData>),
+ Error(FiuuErrorResponse),
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct RefundData {
+ #[serde(rename = "RefundID")]
+ refund_id: String,
+ status: RefundStatus,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "lowercase")]
+pub enum RefundStatus {
+ Success,
+ Pending,
+ Rejected,
+ Processing,
+}
+
+impl TryFrom<RefundsResponseRouterData<RSync, FiuuRefundSyncResponse>>
+ for RefundsRouterData<RSync>
+{
+ type Error = Report<errors::ConnectorError>;
+
+ fn try_from(
+ item: RefundsResponseRouterData<RSync, FiuuRefundSyncResponse>,
+ ) -> Result<Self, Self::Error> {
+ match item.response {
+ FiuuRefundSyncResponse::Error(error) => Ok(Self {
+ response: Err(ErrorResponse {
+ code: error.error_code.clone(),
+ message: error.error_desc.clone(),
+ reason: Some(error.error_desc),
+ status_code: item.http_code,
+ attempt_status: None,
+ connector_transaction_id: None,
+ }),
+ ..item.data
+ }),
+ FiuuRefundSyncResponse::Success(refund_data) => {
+ let refund = refund_data
+ .iter()
+ .find(|refund| {
+ Some(refund.refund_id.clone()) == item.data.request.connector_refund_id
+ })
+ .ok_or_else(|| errors::ConnectorError::MissingConnectorRefundID)?;
+ Ok(Self {
+ response: Ok(RefundsResponseData {
+ connector_refund_id: refund.refund_id.clone(),
+ refund_status: enums::RefundStatus::from(refund.status.clone()),
+ }),
+ ..item.data
+ })
+ }
+ }
+ }
+}
+
+impl From<RefundStatus> for enums::RefundStatus {
+ fn from(item: RefundStatus) -> Self {
+ match item {
+ RefundStatus::Pending => Self::Pending,
+ RefundStatus::Success => Self::Success,
+ RefundStatus::Rejected => Self::Failure,
+ RefundStatus::Processing => Self::Pending,
+ }
+ }
}
diff --git a/crates/hyperswitch_connectors/src/types.rs b/crates/hyperswitch_connectors/src/types.rs
index 3238bd5e82..1624b03171 100644
--- a/crates/hyperswitch_connectors/src/types.rs
+++ b/crates/hyperswitch_connectors/src/types.rs
@@ -1,11 +1,23 @@
use hyperswitch_domain_models::{
- router_data::RouterData, router_request_types::RefundsData,
- router_response_types::RefundsResponseData,
+ router_data::RouterData,
+ router_flow_types::{Capture, PSync, Void},
+ router_request_types::{
+ PaymentsCancelData, PaymentsCaptureData, PaymentsSyncData, RefundsData,
+ },
+ router_response_types::{PaymentsResponseData, RefundsResponseData},
};
+pub type PaymentsSyncResponseRouterData<R> =
+ ResponseRouterData<PSync, R, PaymentsSyncData, PaymentsResponseData>;
+
+pub type PaymentsCaptureResponseRouterData<R> =
+ ResponseRouterData<Capture, R, PaymentsCaptureData, PaymentsResponseData>;
pub(crate) type RefundsResponseRouterData<F, R> =
ResponseRouterData<F, R, RefundsData, RefundsResponseData>;
+pub type PaymentsCancelResponseRouterData<R> =
+ ResponseRouterData<Void, R, PaymentsCancelData, PaymentsResponseData>;
+
// TODO: Remove `ResponseRouterData` from router crate after all the related type aliases are moved to this crate.
pub struct ResponseRouterData<Flow, R, Request, Response> {
pub response: R,
diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rs
index 4dd33612e5..6898a9e002 100644
--- a/crates/router/src/configs/defaults.rs
+++ b/crates/router/src/configs/defaults.rs
@@ -1521,6 +1521,53 @@ impl Default for super::settings::RequiredFields {
common: HashMap::new(),
}
),
+ (
+ enums::Connector::Fiuu,
+ RequiredFieldFinal {
+ mandate: HashMap::new(),
+ non_mandate: HashMap::from(
+ [
+ (
+ "payment_method_data.card.card_number".to_string(),
+ RequiredFieldInfo {
+ required_field: "payment_method_data.card.card_number".to_string(),
+ display_name: "card_number".to_string(),
+ field_type: enums::FieldType::UserCardNumber,
+ value: None,
+ }
+ ),
+ (
+ "payment_method_data.card.card_exp_month".to_string(),
+ RequiredFieldInfo {
+ required_field: "payment_method_data.card.card_exp_month".to_string(),
+ display_name: "card_exp_month".to_string(),
+ field_type: enums::FieldType::UserCardExpiryMonth,
+ value: None,
+ }
+ ),
+ (
+ "payment_method_data.card.card_exp_year".to_string(),
+ RequiredFieldInfo {
+ required_field: "payment_method_data.card.card_exp_year".to_string(),
+ display_name: "card_exp_year".to_string(),
+ field_type: enums::FieldType::UserCardExpiryYear,
+ value: None,
+ }
+ ),
+ (
+ "payment_method_data.card.card_cvc".to_string(),
+ RequiredFieldInfo {
+ required_field: "payment_method_data.card.card_cvc".to_string(),
+ display_name: "card_cvc".to_string(),
+ field_type: enums::FieldType::UserCardCvc,
+ value: None,
+ }
+ )
+ ]
+ ),
+ common: HashMap::new(),
+ }
+ ),
(
enums::Connector::Forte,
RequiredFieldFinal {
@@ -4337,6 +4384,53 @@ impl Default for super::settings::RequiredFields {
common: HashMap::new(),
}
),
+ (
+ enums::Connector::Fiuu,
+ RequiredFieldFinal {
+ mandate: HashMap::new(),
+ non_mandate: HashMap::from(
+ [
+ (
+ "payment_method_data.card.card_number".to_string(),
+ RequiredFieldInfo {
+ required_field: "payment_method_data.card.card_number".to_string(),
+ display_name: "card_number".to_string(),
+ field_type: enums::FieldType::UserCardNumber,
+ value: None,
+ }
+ ),
+ (
+ "payment_method_data.card.card_exp_month".to_string(),
+ RequiredFieldInfo {
+ required_field: "payment_method_data.card.card_exp_month".to_string(),
+ display_name: "card_exp_month".to_string(),
+ field_type: enums::FieldType::UserCardExpiryMonth,
+ value: None,
+ }
+ ),
+ (
+ "payment_method_data.card.card_exp_year".to_string(),
+ RequiredFieldInfo {
+ required_field: "payment_method_data.card.card_exp_year".to_string(),
+ display_name: "card_exp_year".to_string(),
+ field_type: enums::FieldType::UserCardExpiryYear,
+ value: None,
+ }
+ ),
+ (
+ "payment_method_data.card.card_cvc".to_string(),
+ RequiredFieldInfo {
+ required_field: "payment_method_data.card.card_cvc".to_string(),
+ display_name: "card_cvc".to_string(),
+ field_type: enums::FieldType::UserCardCvc,
+ value: None,
+ }
+ )
+ ]
+ ),
+ common: HashMap::new(),
+ }
+ ),
(
enums::Connector::Forte,
RequiredFieldFinal {
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 85c8d90c8b..8101867df4 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -1317,6 +1317,10 @@ impl<'a> ConnectorAuthTypeAndMetadataValidation<'a> {
fiservemea::transformers::FiservemeaAuthType::try_from(self.auth_type)?;
Ok(())
}
+ api_enums::Connector::Fiuu => {
+ fiuu::transformers::FiuuAuthType::try_from(self.auth_type)?;
+ Ok(())
+ }
api_enums::Connector::Forte => {
forte::transformers::ForteAuthType::try_from(self.auth_type)?;
Ok(())
diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs
index da37e0f854..33ecacc681 100644
--- a/crates/router/src/types/api.rs
+++ b/crates/router/src/types/api.rs
@@ -396,6 +396,7 @@ impl ConnectorData {
enums::Connector::Fiservemea => {
Ok(ConnectorEnum::Old(Box::new(connector::Fiservemea::new())))
}
+ enums::Connector::Fiuu => Ok(ConnectorEnum::Old(Box::new(connector::Fiuu::new()))),
enums::Connector::Forte => {
Ok(ConnectorEnum::Old(Box::new(connector::Forte::new())))
}
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 7b637b76c1..ba2f01e93e 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -279,7 +279,7 @@ impl ForeignTryFrom<api_enums::Connector> for common_enums::RoutableConnectors {
api_enums::Connector::Ebanx => Self::Ebanx,
api_enums::Connector::Fiserv => Self::Fiserv,
api_enums::Connector::Fiservemea => Self::Fiservemea,
- // api_enums::Connector::Fiuu => Self::Fiuu,
+ api_enums::Connector::Fiuu => Self::Fiuu,
api_enums::Connector::Forte => Self::Forte,
api_enums::Connector::Globalpay => Self::Globalpay,
api_enums::Connector::Globepay => Self::Globepay,
diff --git a/cypress-tests/cypress/e2e/PaymentUtils/Commons.js b/cypress-tests/cypress/e2e/PaymentUtils/Commons.js
index f1c9614745..cfb136acd1 100644
--- a/cypress-tests/cypress/e2e/PaymentUtils/Commons.js
+++ b/cypress-tests/cypress/e2e/PaymentUtils/Commons.js
@@ -17,6 +17,7 @@ function normalise(input) {
paybox: "Paybox",
paypal: "Paypal",
wellsfargo: "Wellsfargo",
+ fiuu: "Fiuu"
// Add more known exceptions here
};
diff --git a/cypress-tests/cypress/e2e/PaymentUtils/Fiuu.js b/cypress-tests/cypress/e2e/PaymentUtils/Fiuu.js
new file mode 100644
index 0000000000..86e2314c92
--- /dev/null
+++ b/cypress-tests/cypress/e2e/PaymentUtils/Fiuu.js
@@ -0,0 +1,188 @@
+const successfulNo3DSCardDetails = {
+ card_number: "5105105105105100",
+ card_exp_month: "12",
+ card_exp_year: "2030",
+ card_holder_name: "joseph Doe",
+ card_cvc: "123",
+};
+
+const successfulThreeDSTestCardDetails = {
+ card_number: "5105105105105100",
+ card_exp_month: "12",
+ card_exp_year: "2030",
+ card_holder_name: "joseph Doe",
+ card_cvc: "123",
+};
+export const connectorDetails = {
+ card_pm: {
+ PaymentIntent: {
+ Request: {
+ currency: "USD",
+ customer_acceptance: null,
+ setup_future_usage: "on_session",
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "requires_payment_method",
+ },
+ },
+ },
+ "3DSManualCapture": {
+ Request: {
+ payment_method: "card",
+ payment_method_data: {
+ card: successfulThreeDSTestCardDetails,
+ },
+ currency: "USD",
+ customer_acceptance: null,
+ setup_future_usage: "on_session",
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "requires_capture",
+ },
+ },
+ },
+ "3DSAutoCapture": {
+ Request: {
+ payment_method: "card",
+ payment_method_data: {
+ card: successfulThreeDSTestCardDetails,
+ },
+ currency: "USD",
+ customer_acceptance: null,
+ setup_future_usage: "on_session",
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "requires_customer_action",
+ },
+ },
+ },
+ No3DSManualCapture: {
+ Request: {
+ payment_method: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ },
+ currency: "USD",
+ customer_acceptance: null,
+ setup_future_usage: "on_session",
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "requires_capture",
+ },
+ },
+ },
+ No3DSAutoCapture: {
+ Request: {
+ payment_method: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ },
+ currency: "USD",
+ customer_acceptance: null,
+ setup_future_usage: "on_session",
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "succeeded",
+ },
+ },
+ },
+ Capture: {
+ Request: {
+ payment_method: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ },
+ currency: "USD",
+ customer_acceptance: null,
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "succeeded",
+ amount: 6500,
+ amount_capturable: 0,
+ amount_received: 6500,
+ },
+ },
+ },
+ PartialCapture: {
+ Request: {},
+ Response: {
+ status: 200,
+ body: {
+ status: "partially_captured",
+ amount: 6500,
+ amount_capturable: 0,
+ amount_received: 100,
+ },
+ },
+ },
+ Void: {
+ Request: {},
+ Response: {
+ status: 200,
+ body: {
+ status: "cancelled",
+ },
+ },
+ },
+ Refund: {
+ Request: {
+ payment_method: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ },
+ currency: "USD",
+ customer_acceptance: null,
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "pending",
+ },
+ },
+ },
+ PartialRefund: {
+ Request: {
+ payment_method: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ },
+ currency: "USD",
+ customer_acceptance: null,
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "pending",
+ },
+ },
+ },
+ SyncRefund: {
+ Request: {
+ payment_method: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ },
+ currency: "USD",
+ customer_acceptance: null,
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "pending",
+ },
+ },
+ },
+ },
+};
diff --git a/cypress-tests/cypress/e2e/PaymentUtils/Utils.js b/cypress-tests/cypress/e2e/PaymentUtils/Utils.js
index 8da1c3ea81..8c643f9cd8 100644
--- a/cypress-tests/cypress/e2e/PaymentUtils/Utils.js
+++ b/cypress-tests/cypress/e2e/PaymentUtils/Utils.js
@@ -16,6 +16,7 @@ import { connectorDetails as paypalConnectorDetails } from "./Paypal.js";
import { connectorDetails as stripeConnectorDetails } from "./Stripe.js";
import { connectorDetails as trustpayConnectorDetails } from "./Trustpay.js";
import { connectorDetails as wellsfargoConnectorDetails } from "./WellsFargo.js";
+import { connectorDetails as fiuuConnectorDetails } from "./Fiuu.js";
const connectorDetails = {
adyen: adyenConnectorDetails,
@@ -33,6 +34,7 @@ const connectorDetails = {
trustpay: trustpayConnectorDetails,
datatrans: datatransConnectorDetails,
wellsfargo: wellsfargoConnectorDetails,
+ fiuu: fiuuConnectorDetails,
};
export default function getConnectorDetails(connectorId) {