Skip to content

Commit 9e358e4

Browse files
refactor(router): refactor merchant_connector update v2 flow (#5484)
1 parent ec5f9de commit 9e358e4

File tree

6 files changed

+496
-156
lines changed

6 files changed

+496
-156
lines changed

crates/api_models/src/admin.rs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,10 @@ impl MerchantConnectorListResponse {
13651365
}
13661366

13671367
/// Create a new Merchant Connector for the merchant account. The connector could be a payment processor / facilitator / acquirer or specialized services like Fraud / Accounting etc."
1368+
#[cfg(all(
1369+
any(feature = "v1", feature = "v2"),
1370+
not(feature = "merchant_connector_account_v2")
1371+
))]
13681372
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
13691373
#[serde(deny_unknown_fields)]
13701374
pub struct MerchantConnectorUpdate {
@@ -1444,6 +1448,104 @@ pub struct MerchantConnectorUpdate {
14441448
pub status: Option<api_enums::ConnectorStatus>,
14451449
}
14461450

1451+
/// Create a new Merchant Connector for the merchant account. The connector could be a payment processor / facilitator / acquirer or specialized services like Fraud / Accounting etc."
1452+
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
1453+
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
1454+
#[serde(deny_unknown_fields)]
1455+
pub struct MerchantConnectorUpdate {
1456+
/// Type of the Connector for the financial use case. Could range from Payments to Accounting to Banking.
1457+
#[schema(value_type = ConnectorType, example = "payment_processor")]
1458+
pub connector_type: api_enums::ConnectorType,
1459+
1460+
/// This is an unique label you can generate and pass in order to identify this connector account on your Hyperswitch dashboard and reports. Eg: if your profile label is `default`, connector label can be `stripe_default`
1461+
#[schema(example = "stripe_US_travel")]
1462+
pub connector_label: Option<String>,
1463+
1464+
/// An object containing the required details/credentials for a Connector account.
1465+
#[schema(value_type = Option<MerchantConnectorDetails>,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))]
1466+
pub connector_account_details: Option<pii::SecretSerdeValue>,
1467+
1468+
/// An object containing the details about the payment methods that need to be enabled under this merchant connector account
1469+
#[schema(example = json!([
1470+
{
1471+
"payment_method": "wallet",
1472+
"payment_method_types": [
1473+
"upi_collect",
1474+
"upi_intent"
1475+
],
1476+
"payment_method_issuers": [
1477+
"labore magna ipsum",
1478+
"aute"
1479+
],
1480+
"payment_schemes": [
1481+
"Discover",
1482+
"Discover"
1483+
],
1484+
"accepted_currencies": {
1485+
"type": "enable_only",
1486+
"list": ["USD", "EUR"]
1487+
},
1488+
"accepted_countries": {
1489+
"type": "disable_only",
1490+
"list": ["FR", "DE","IN"]
1491+
},
1492+
"minimum_amount": 1,
1493+
"maximum_amount": 68607706,
1494+
"recurring_enabled": true,
1495+
"installment_payment_enabled": true
1496+
}
1497+
]))]
1498+
pub payment_methods_enabled: Option<Vec<PaymentMethodsEnabled>>,
1499+
1500+
/// Webhook details of this merchant connector
1501+
#[schema(example = json!({
1502+
"connector_webhook_details": {
1503+
"merchant_secret": "1234567890987654321"
1504+
}
1505+
}))]
1506+
pub connector_webhook_details: Option<MerchantConnectorWebhookDetails>,
1507+
1508+
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
1509+
#[schema(value_type = Option<Object>,max_length = 255,example = json!({ "city": "NY", "unit": "245" }))]
1510+
pub metadata: Option<pii::SecretSerdeValue>,
1511+
1512+
/// A boolean value to indicate if the connector is disabled. By default, its value is false.
1513+
#[schema(default = false, example = false)]
1514+
pub disabled: Option<bool>,
1515+
1516+
/// Contains the frm configs for the merchant connector
1517+
#[schema(example = json!(consts::FRM_CONFIGS_EG))]
1518+
pub frm_configs: Option<Vec<FrmConfigs>>,
1519+
1520+
/// pm_auth_config will relate MCA records to their respective chosen auth services, based on payment_method and pmt
1521+
#[schema(value_type = Option<Object>)]
1522+
pub pm_auth_config: Option<pii::SecretSerdeValue>,
1523+
1524+
#[schema(value_type = ConnectorStatus, example = "inactive")]
1525+
pub status: Option<api_enums::ConnectorStatus>,
1526+
1527+
/// The identifier for the Merchant Account
1528+
#[schema(value_type = String, max_length = 64, min_length = 1, example = "y3oqhf46pyzuxjbcn2giaqnb44")]
1529+
pub merchant_id: id_type::MerchantId,
1530+
}
1531+
1532+
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
1533+
impl MerchantConnectorUpdate {
1534+
pub fn get_frm_config_as_secret(&self) -> Option<Vec<Secret<serde_json::Value>>> {
1535+
match self.frm_configs.as_ref() {
1536+
Some(frm_value) => {
1537+
let configs_for_frm_value: Vec<Secret<serde_json::Value>> = frm_value
1538+
.iter()
1539+
.map(|config| config.encode_to_value().map(Secret::new))
1540+
.collect::<Result<Vec<_>, _>>()
1541+
.ok()?;
1542+
Some(configs_for_frm_value)
1543+
}
1544+
None => None,
1545+
}
1546+
}
1547+
}
1548+
14471549
///Details of FrmConfigs are mentioned here... it should be passed in payment connector create api call, and stored in merchant_connector_table
14481550
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
14491551
#[serde(deny_unknown_fields)]

crates/hyperswitch_domain_models/src/router_data.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use std::{collections::HashMap, marker::PhantomData};
22

3-
use common_utils::{errors::IntegrityCheckError, ext_traits::OptionExt, id_type, types::MinorUnit};
3+
use common_utils::{
4+
errors::IntegrityCheckError,
5+
ext_traits::{OptionExt, ValueExt},
6+
id_type,
7+
types::MinorUnit,
8+
};
49
use error_stack::ResultExt;
510
use masking::Secret;
611

@@ -119,6 +124,16 @@ impl ConnectorAuthType {
119124
"ConnectorAuthType",
120125
))
121126
}
127+
128+
pub fn from_secret_value(
129+
value: common_utils::pii::SecretSerdeValue,
130+
) -> common_utils::errors::CustomResult<Self, common_utils::errors::ParsingError> {
131+
value
132+
.parse_value::<Self>("ConnectorAuthType")
133+
.change_context(common_utils::errors::ParsingError::StructParseFailure(
134+
"ConnectorAuthType",
135+
))
136+
}
122137
}
123138

124139
#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]

0 commit comments

Comments
 (0)