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

fix(connector): [noon] add connector_auth params and update description (#2429)

SamraatBansal0aa6b30d2c90
diff --git a/config/config.example.toml b/config/config.example.toml
index 0841b26a37..d4b44a062a 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -187,6 +187,7 @@ multisafepay.base_url = "https://testapi.multisafepay.com/"
nexinets.base_url = "https://apitest.payengine.de/v1"
nmi.base_url = "https://secure.nmi.com/"
noon.base_url = "https://api-test.noonpayments.com/"
+noon.key_mode = "Test"
nuvei.base_url = "https://ppp-test.nuvei.com/"
opayo.base_url = "https://pi-test.sagepay.com/"
opennode.base_url = "https://dev-api.opennode.com"
diff --git a/config/development.toml b/config/development.toml
index 0f95dcb657..26a7251dc9 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -161,6 +161,7 @@ multisafepay.base_url = "https://testapi.multisafepay.com/"
nexinets.base_url = "https://apitest.payengine.de/v1"
nmi.base_url = "https://secure.nmi.com/"
noon.base_url = "https://api-test.noonpayments.com/"
+noon.key_mode = "Test"
nuvei.base_url = "https://ppp-test.nuvei.com/"
opayo.base_url = "https://pi-test.sagepay.com/"
opennode.base_url = "https://dev-api.opennode.com"
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index 2ff1c6ab33..ca6b9eeda5 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -105,6 +105,7 @@ multisafepay.base_url = "https://testapi.multisafepay.com/"
nexinets.base_url = "https://apitest.payengine.de/v1"
nmi.base_url = "https://secure.nmi.com/"
noon.base_url = "https://api-test.noonpayments.com/"
+noon.key_mode = "Test"
nuvei.base_url = "https://ppp-test.nuvei.com/"
opayo.base_url = "https://pi-test.sagepay.com/"
opennode.base_url = "https://dev-api.opennode.com"
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index b5e522cf84..fd4a398fd5 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -523,7 +523,7 @@ pub struct Connectors {
pub multisafepay: ConnectorParams,
pub nexinets: ConnectorParams,
pub nmi: ConnectorParams,
- pub noon: ConnectorParams,
+ pub noon: ConnectorParamsWithModeType,
pub nuvei: ConnectorParams,
pub opayo: ConnectorParams,
pub opennode: ConnectorParams,
@@ -552,6 +552,15 @@ pub struct ConnectorParams {
pub secondary_base_url: Option<String>,
}
+#[derive(Debug, Deserialize, Clone, Default, router_derive::ConfigValidate)]
+#[serde(default)]
+pub struct ConnectorParamsWithModeType {
+ pub base_url: String,
+ pub secondary_base_url: Option<String>,
+ /// Can take values like Test or Live for Noon
+ pub key_mode: String,
+}
+
#[derive(Debug, Deserialize, Clone, Default, router_derive::ConfigValidate)]
#[serde(default)]
pub struct ConnectorParamsWithMoreUrls {
diff --git a/crates/router/src/connector/noon.rs b/crates/router/src/connector/noon.rs
index deda24bfbd..8b7c984083 100644
--- a/crates/router/src/connector/noon.rs
+++ b/crates/router/src/connector/noon.rs
@@ -65,7 +65,7 @@ where
fn build_headers(
&self,
req: &types::RouterData<Flow, Request, Response>,
- _connectors: &settings::Connectors,
+ connectors: &settings::Connectors,
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
let mut header = vec![(
headers::CONTENT_TYPE.to_string(),
@@ -73,12 +73,43 @@ where
.to_string()
.into(),
)];
- let mut api_key = self.get_auth_header(&req.connector_auth_type)?;
+ let mut api_key = get_auth_header(&req.connector_auth_type, connectors, req.test_mode)?;
header.append(&mut api_key);
Ok(header)
}
}
+fn get_auth_header(
+ auth_type: &types::ConnectorAuthType,
+ connectors: &settings::Connectors,
+ test_mode: Option<bool>,
+) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
+ let auth = noon::NoonAuthType::try_from(auth_type)?;
+
+ let encoded_api_key = auth
+ .business_identifier
+ .zip(auth.application_identifier)
+ .zip(auth.api_key)
+ .map(|((business_identifier, application_identifier), api_key)| {
+ consts::BASE64_ENGINE.encode(format!(
+ "{}.{}:{}",
+ business_identifier, application_identifier, api_key
+ ))
+ });
+ let key_mode = test_mode.map_or(connectors.noon.key_mode.clone(), |is_test_mode| {
+ if is_test_mode {
+ "Test".to_string()
+ } else {
+ "Live".to_string()
+ }
+ });
+
+ Ok(vec![(
+ headers::AUTHORIZATION.to_string(),
+ format!("Key_{} {}", key_mode, encoded_api_key.peek()).into_masked(),
+ )])
+}
+
impl ConnectorCommon for Noon {
fn id(&self) -> &'static str {
"noon"
@@ -92,28 +123,6 @@ impl ConnectorCommon for Noon {
connectors.noon.base_url.as_ref()
}
- fn get_auth_header(
- &self,
- auth_type: &types::ConnectorAuthType,
- ) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
- let auth = noon::NoonAuthType::try_from(auth_type)?;
-
- let encoded_api_key = auth
- .business_identifier
- .zip(auth.application_identifier)
- .zip(auth.api_key)
- .map(|((business_identifier, application_identifier), api_key)| {
- consts::BASE64_ENGINE.encode(format!(
- "{}.{}:{}",
- business_identifier, application_identifier, api_key
- ))
- });
- Ok(vec![(
- headers::AUTHORIZATION.to_string(),
- format!("Key_Test {}", encoded_api_key.peek()).into_masked(),
- )])
- }
-
fn build_error_response(
&self,
res: Response,
diff --git a/crates/router/src/connector/noon/transformers.rs b/crates/router/src/connector/noon/transformers.rs
index eff6261891..d7dc832b44 100644
--- a/crates/router/src/connector/noon/transformers.rs
+++ b/crates/router/src/connector/noon/transformers.rs
@@ -238,7 +238,16 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest {
item.request.order_category.clone(),
),
};
- let name = item.get_description()?;
+
+ // The description should not have leading or trailing whitespaces, also it should not have double whitespaces and a max 50 chars according to Noon's Docs
+ let name: String = item
+ .get_description()?
+ .trim()
+ .replace(" ", " ")
+ .chars()
+ .take(50)
+ .collect();
+
let (subscription, tokenize_c_c) =
match item.request.setup_future_usage.is_some().then_some((
NoonSubscriptionData {
diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml
index ebab00cac1..1b413b1cdf 100644
--- a/loadtest/config/development.toml
+++ b/loadtest/config/development.toml
@@ -91,6 +91,7 @@ multisafepay.base_url = "https://testapi.multisafepay.com/"
nexinets.base_url = "https://apitest.payengine.de/v1"
nmi.base_url = "https://secure.nmi.com/"
noon.base_url = "https://api-test.noonpayments.com/"
+noon.key_mode = "Test"
nuvei.base_url = "https://ppp-test.nuvei.com/"
opayo.base_url = "https://pi-test.sagepay.com/"
opennode.base_url = "https://dev-api.opennode.com"