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

refactor(connector): [jpmorgan] move hardcoded values to `merchant_account_metadata` (#10717)

Pa1NarKc843ed912d6c
diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs
index ec58779170..3fee2231dc 100644
--- a/crates/connector_configs/src/connector.rs
+++ b/crates/connector_configs/src/connector.rs
@@ -190,6 +190,8 @@ pub struct ConfigMetadata {
pub organizational_unit_id: Option<InputData>,
pub issuer_id: Option<InputData>,
pub jwt_mac_key: Option<InputData>,
+ pub company_name: Option<InputData>,
+ pub product_name: Option<InputData>,
}
#[serde_with::skip_serializing_none]
diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.toml
index d20ca4f4c4..b2c097d1f1 100644
--- a/crates/connector_configs/toml/development.toml
+++ b/crates/connector_configs/toml/development.toml
@@ -2801,6 +2801,18 @@ key2="Certificate Key"
[jpmorgan.connector_auth.BodyKey]
api_key="Client ID"
key1="Client Secret"
+[jpmorgan.metadata.company_name]
+name = "company_name"
+label = "Company Name"
+placeholder = "Enter the company name. Example: JPMC, Hyperswitch"
+required = true
+type = "Text"
+[jpmorgan.metadata.product_name]
+name = "product_name"
+label = "Product Name"
+placeholder = "Enter the product name (used for marketing purposes from a customer perspective)"
+required = true
+type = "Text"
[klarna]
[[klarna.pay_later]]
diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.toml
index 3d0800a56d..0b4cf998b0 100644
--- a/crates/connector_configs/toml/production.toml
+++ b/crates/connector_configs/toml/production.toml
@@ -2422,6 +2422,18 @@ payment_method_type = "Visa"
[jpmorgan.connector_auth.BodyKey]
api_key = "Access Token"
key1 = "Client Secret"
+[jpmorgan.metadata.company_name]
+name = "company_name"
+label = "Company Name"
+placeholder = "Enter the company name. Example: JPMC, Hyperswitch"
+required = true
+type = "Text"
+[jpmorgan.metadata.product_name]
+name = "product_name"
+label = "Product Name"
+placeholder = "Enter the product name (used for marketing purposes from a customer perspective)"
+required = true
+type = "Text"
[klarna]
[[klarna.pay_later]]
@@ -6763,7 +6775,6 @@ api_key = "API Key"
key1="Client Secret"
api_secret="Vault Id"
-
[payjustnowinstore]
[payjustnowinstore.connector_auth.HeaderKey]
api_key = "Merchant Terminal Id"
diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.toml
index 4862c2a94b..9389f02637 100644
--- a/crates/connector_configs/toml/sandbox.toml
+++ b/crates/connector_configs/toml/sandbox.toml
@@ -2778,6 +2778,18 @@ payment_method_type = "Visa"
[jpmorgan.connector_auth.BodyKey]
api_key = "Access Token"
key1 = "Client Secret"
+[jpmorgan.metadata.company_name]
+name = "company_name"
+label = "Company Name"
+placeholder = "Enter the company name. Example: JPMC, Hyperswitch"
+required = true
+type = "Text"
+[jpmorgan.metadata.product_name]
+name = "product_name"
+label = "Product Name"
+placeholder = "Enter the product name (used for marketing purposes from a customer perspective)"
+required = true
+type = "Text"
[klarna]
[[klarna.pay_later]]
@@ -7854,7 +7866,6 @@ api_key = "API Key"
key1="Client Secret"
api_secret="Vault Id"
-
[payjustnowinstore]
[payjustnowinstore.connector_auth.HeaderKey]
api_key = "Merchant Terminal Id"
diff --git a/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs b/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs
index 40ccb29ff0..3fff8fcef4 100644
--- a/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs
@@ -1,5 +1,5 @@
use common_enums::enums::CaptureMethod;
-use common_utils::types::MinorUnit;
+use common_utils::{pii::SecretSerdeValue, types::MinorUnit};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
payment_method_data::PaymentMethodData,
@@ -19,7 +19,8 @@ use serde::{Deserialize, Serialize};
use crate::{
types::{PaymentsCancelResponseRouterData, RefundsResponseRouterData, ResponseRouterData},
utils::{
- get_unimplemented_payment_method_error_message, CardData, RouterData as OtherRouterData,
+ self, get_unimplemented_payment_method_error_message, CardData,
+ RouterData as OtherRouterData,
},
};
pub struct JpmorganRouterData<T> {
@@ -50,6 +51,24 @@ pub struct JpmorganAuthUpdateResponse {
pub expires_in: i64,
}
+/// JPMorgan connector metadata containing merchant software information
+#[derive(Debug, Default, Serialize, Deserialize)]
+pub struct JpmorganConnectorMetadataObject {
+ pub company_name: Secret<String>,
+ pub product_name: Secret<String>,
+}
+
+impl TryFrom<&Option<SecretSerdeValue>> for JpmorganConnectorMetadataObject {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(meta_data: &Option<SecretSerdeValue>) -> Result<Self, Self::Error> {
+ let metadata: Self = utils::to_connector_meta_from_secret::<Self>(meta_data.clone())
+ .change_context(errors::ConnectorError::InvalidConnectorConfig {
+ config: "merchant_connector_account.metadata",
+ })?;
+ Ok(metadata)
+ }
+}
+
impl TryFrom<&RefreshTokenRouterData> for JpmorganAuthUpdateRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(_item: &RefreshTokenRouterData) -> Result<Self, Self::Error> {
@@ -152,12 +171,16 @@ impl TryFrom<&JpmorganRouterData<&PaymentsAuthorizeRouterData>> for JpmorganPaym
let capture_method =
map_capture_method(item.router_data.request.capture_method.unwrap_or_default());
- let merchant_software = JpmorganMerchantSoftware {
- company_name: String::from("JPMC").into(),
- product_name: String::from("Hyperswitch").into(),
- };
+ let connector_metadata = JpmorganConnectorMetadataObject::try_from(
+ &item.router_data.connector_meta_data.clone(),
+ )?;
- let merchant = JpmorganMerchant { merchant_software };
+ let merchant = JpmorganMerchant {
+ merchant_software: JpmorganMerchantSoftware {
+ company_name: connector_metadata.company_name,
+ product_name: connector_metadata.product_name,
+ },
+ };
let expiry: Expiry = Expiry {
month: Secret::new(
@@ -526,11 +549,17 @@ pub struct MerchantRefundReq {
impl<F> TryFrom<&JpmorganRouterData<&RefundsRouterData<F>>> for JpmorganRefundRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &JpmorganRouterData<&RefundsRouterData<F>>) -> Result<Self, Self::Error> {
- let merchant_software = JpmorganMerchantSoftware {
- company_name: String::from("JPMC").into(),
- product_name: String::from("Hyperswitch").into(),
+ let connector_metadata = JpmorganConnectorMetadataObject::try_from(
+ &item.router_data.connector_meta_data.clone(),
+ )?;
+
+ let merchant = MerchantRefundReq {
+ merchant_software: JpmorganMerchantSoftware {
+ company_name: connector_metadata.company_name,
+ product_name: connector_metadata.product_name,
+ },
};
- let merchant = MerchantRefundReq { merchant_software };
+
let amount = item.amount;
let currency = item.router_data.request.currency;
diff --git a/crates/router/src/core/connector_validation.rs b/crates/router/src/core/connector_validation.rs
index e027c100ce..092f3b702c 100644
--- a/crates/router/src/core/connector_validation.rs
+++ b/crates/router/src/core/connector_validation.rs
@@ -320,6 +320,9 @@ impl ConnectorAuthTypeAndMetadataValidation<'_> {
}
api_enums::Connector::Jpmorgan => {
jpmorgan::transformers::JpmorganAuthType::try_from(self.auth_type)?;
+ jpmorgan::transformers::JpmorganConnectorMetadataObject::try_from(
+ self.connector_meta_data,
+ )?;
Ok(())
}
api_enums::Connector::Juspaythreedsserver => Ok(()),
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rs
index 740c5a38e9..9d2822443f 100644
--- a/crates/router/src/core/unified_connector_service/transformers.rs
+++ b/crates/router/src/core/unified_connector_service/transformers.rs
@@ -162,12 +162,8 @@ impl
let merchant_account_metadata = router_data
.connector_meta_data
.as_ref()
- .and_then(|val| val.peek().as_object())
- .map(|map| {
- map.iter()
- .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))
- .collect::<HashMap<String, String>>()
- })
+ .map(|secret| convert_value_map_to_hashmap(secret.peek()))
+ .transpose()?
.unwrap_or_default();
let currency = payments_grpc::Currency::foreign_try_from(router_data.request.currency)?;
@@ -259,23 +255,15 @@ impl
let merchant_account_metadata = router_data
.connector_meta_data
.as_ref()
- .and_then(|val| val.peek().as_object())
- .map(|map| {
- map.iter()
- .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))
- .collect::<HashMap<String, String>>()
- })
+ .map(|secret| convert_value_map_to_hashmap(secret.peek()))
+ .transpose()?
.unwrap_or_default();
let metadata = router_data
.request
.metadata
.as_ref()
- .and_then(|val| val.as_object())
- .map(|map| {
- map.iter()
- .map(|(k, v)| (k.clone(), v.to_string()))
- .collect::<HashMap<String, String>>()
- })
+ .map(convert_value_map_to_hashmap)
+ .transpose()?
.unwrap_or_default();
let setup_future_usage = router_data
.request
@@ -464,12 +452,8 @@ impl
let merchant_account_metadata = router_data
.connector_meta_data
.as_ref()
- .and_then(|val| val.peek().as_object())
- .map(|map| {
- map.iter()
- .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))
- .collect::<HashMap<String, String>>()
- })
+ .map(|secret| convert_value_map_to_hashmap(secret.peek()))
+ .transpose()?
.unwrap_or_default();
let metadata = router_data
.request
@@ -4453,12 +4437,8 @@ impl transformers::ForeignTryFrom<&RouterData<Execute, RefundsData, RefundsRespo
let merchant_account_metadata = router_data
.connector_meta_data
.as_ref()
- .and_then(|val| val.peek().as_object())
- .map(|map| {
- map.iter()
- .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))
- .collect::<HashMap<String, String>>()
- })
+ .map(|secret| convert_value_map_to_hashmap(secret.peek()))
+ .transpose()?
.unwrap_or_default();
let payment_method_type = router_data
@@ -4545,12 +4525,8 @@ impl transformers::ForeignTryFrom<&RouterData<RSync, RefundsData, RefundsRespons
let merchant_account_metadata = router_data
.connector_meta_data
.as_ref()
- .and_then(|val| val.peek().as_object())
- .map(|map| {
- map.iter()
- .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))
- .collect::<HashMap<String, String>>()
- })
+ .map(|secret| convert_value_map_to_hashmap(secret.peek()))
+ .transpose()?
.unwrap_or_default();
let payment_method_type = router_data