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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(payment_connector): allow connector label to be updated (#2622)
Narayan Bhatc86ac9b1fe53
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex dbac9a4bc4..af6a8aa446 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -587,10 +587,9 @@ pub struct MerchantConnectorCreate {/// Name of the Connector#[schema(value_type = Connector, example = "stripe")]pub connector_name: api_enums::Connector,- // /// Connector label for specific country and Business- #[serde(skip_deserializing)]+ /// Connector label for a connector, this can serve as a field to identify the connector as per business details#[schema(example = "stripe_US_travel")]- pub connector_label: String,+ pub connector_label: Option<String>,/// Unique ID of the connector#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]@@ -683,8 +682,8 @@ pub struct MerchantConnectorResponse {/// Name of the Connector#[schema(example = "stripe")]pub connector_name: String,- // /// Connector label for specific country and Business- #[serde(skip_deserializing)]++ /// Connector label for a connector, this can serve as a field to identify the connector as per business details#[schema(example = "stripe_US_travel")]pub connector_label: Option<String>,@@ -777,6 +776,9 @@ pub struct MerchantConnectorUpdate {#[schema(value_type = ConnectorType, example = "payment_processor")]pub connector_type: api_enums::ConnectorType,+ /// Connector label for a connector, this can serve as a field to identify the connector as per business details+ pub connector_label: Option<String>,+/// Account details of the Connector. You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Useful for storing additional, structured information on an object.#[schema(value_type = Option<Object>,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))]pub connector_account_details: Option<pii::SecretSerdeValue>,diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rsindex ce2684c937..a4faa45ce4 100644--- a/crates/diesel_models/src/merchant_connector_account.rs+++ b/crates/diesel_models/src/merchant_connector_account.rs@@ -79,6 +79,7 @@ pub struct MerchantConnectorAccountUpdateInternal {pub connector_type: Option<storage_enums::ConnectorType>,pub connector_name: Option<String>,pub connector_account_details: Option<Encryption>,+ pub connector_label: Option<String>,pub test_mode: Option<bool>,pub disabled: Option<bool>,pub merchant_connector_id: Option<String>,diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex e6c318285b..c0d6c576dd 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -661,12 +661,38 @@ pub async fn create_payment_connector(&merchant_account,)?;- let connector_label = core_utils::get_connector_label(+ // Business label support will be deprecated soon+ let profile_id = core_utils::get_profile_id_from_business_details(req.business_country,req.business_label.as_ref(),- req.business_sub_label.as_ref(),- &req.connector_name.to_string(),- );+ &merchant_account,+ req.profile_id.as_ref(),+ store,+ true,+ )+ .await?;++ let business_profile = state+ .store+ .find_business_profile_by_profile_id(&profile_id)+ .await+ .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound {+ id: profile_id.to_owned(),+ })?;++ // If connector label is not passed in the request, generate one+ let connector_label = req+ .connector_label+ .or(core_utils::get_connector_label(+ req.business_country,+ req.business_label.as_ref(),+ req.business_sub_label.as_ref(),+ &req.connector_name.to_string(),+ ))+ .unwrap_or(format!(+ "{}_{}",+ req.connector_name, business_profile.profile_name+ ));let mut vec = Vec::new();let payment_methods_enabled = match req.payment_methods_enabled {@@ -718,16 +744,6 @@ pub async fn create_payment_connector(let frm_configs = get_frm_config_as_secret(req.frm_configs);- let profile_id = core_utils::get_profile_id_from_business_details(- req.business_country,- req.business_label.as_ref(),- &merchant_account,- req.profile_id.as_ref(),- &*state.store,- true,- )- .await?;-let merchant_connector_account = domain::MerchantConnectorAccount {merchant_id: merchant_id.to_string(),connector_type: req.connector_type,@@ -749,7 +765,7 @@ pub async fn create_payment_connector(disabled: req.disabled,metadata: req.metadata,frm_configs,- connector_label: connector_label.clone(),+ connector_label: Some(connector_label),business_country: req.business_country,business_label: req.business_label.clone(),business_sub_label: req.business_sub_label,@@ -911,6 +927,7 @@ pub async fn update_payment_connector(connector_type: Some(req.connector_type),connector_name: None,merchant_connector_id: None,+ connector_label: req.connector_label,connector_account_details: req.connector_account_details.async_lift(|inner| {diff --git a/crates/router/src/core/verification/utils.rs b/crates/router/src/core/verification/utils.rsindex 056cc8c2e5..433430507f 100644--- a/crates/router/src/core/verification/utils.rs+++ b/crates/router/src/core/verification/utils.rs@@ -59,6 +59,7 @@ pub async fn check_existence_and_add_domain_to_db(connector_webhook_details: None,applepay_verified_domains: Some(already_verified_domains.clone()),pm_auth_config: None,+ connector_label: None,};state.storediff --git a/crates/router/src/types/domain/merchant_connector_account.rs b/crates/router/src/types/domain/merchant_connector_account.rsindex a8dce1e6f0..58c2e01831 100644--- a/crates/router/src/types/domain/merchant_connector_account.rs+++ b/crates/router/src/types/domain/merchant_connector_account.rs@@ -53,6 +53,7 @@ pub enum MerchantConnectorAccountUpdate {connector_webhook_details: Option<pii::SecretSerdeValue>,applepay_verified_domains: Option<Vec<String>>,pm_auth_config: Option<serde_json::Value>,+ connector_label: Option<String>,},}@@ -175,6 +176,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInteconnector_webhook_details,applepay_verified_domains,pm_auth_config,+ connector_label,} => Self {merchant_id,connector_type,@@ -191,6 +193,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInteconnector_webhook_details,applepay_verified_domains,pm_auth_config,+ connector_label,},}}diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.jsonindex 507c1000b3..a224fac57d 100644--- a/openapi/openapi_spec.json+++ b/openapi/openapi_spec.json@@ -6508,6 +6508,12 @@"connector_name": {"$ref": "#/components/schemas/Connector"},+ "connector_label": {+ "type": "string",+ "description": "Connector label for a connector, this can serve as a field to identify the connector as per business details",+ "example": "stripe_US_travel",+ "nullable": true+ },"merchant_connector_id": {"type": "string","description": "Unique ID of the connector",@@ -6720,6 +6726,12 @@"description": "Name of the Connector","example": "stripe"},+ "connector_label": {+ "type": "string",+ "description": "Connector label for a connector, this can serve as a field to identify the connector as per business details",+ "example": "stripe_US_travel",+ "nullable": true+ },"merchant_connector_id": {"type": "string","description": "Unique ID of the connector",@@ -6859,6 +6871,11 @@"connector_type": {"$ref": "#/components/schemas/ConnectorType"},+ "connector_label": {+ "type": "string",+ "description": "Connector label for a connector, this can serve as a field to identify the connector as per business details",+ "nullable": true+ },"connector_account_details": {"type": "object","description": "Account details of the Connector. You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Useful for storing additional, structured information on an object.",diff --git a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Create/event.test.js b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Create/event.test.jsindex aa1bc4845b..bd543edd2c 100644--- a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Create/event.test.js+++ b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Create/event.test.js@@ -20,7 +20,7 @@ pm.test(let jsonData = {};try {jsonData = pm.response.json();-} catch (e) {}+} catch (e) { }// pm.collectionVariables - Set merchant_connector_id as variable for jsonData.merchant_connector_idif (jsonData?.merchant_connector_id) {@@ -37,3 +37,11 @@ if (jsonData?.merchant_connector_id) {"INFO - Unable to assign variable {{merchant_connector_id}}, as jsonData.merchant_connector_id is undefined.",);}++// Validate if the connector label is the one that is passed in the request+pm.test(+ "[POST]::/accounts/:account_id/connectors - connector_label is not autogenerated",+ function () {+ pm.expect(jsonData.connector_label).to.eql("first_stripe_connector")+ },+);\ No newline at end of filediff --git a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Create/request.json b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Create/request.jsonindex 6fe1be149f..6f89fa181d 100644--- a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Create/request.json+++ b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Create/request.json@@ -42,6 +42,7 @@"connector_name": "stripe","business_country": "US","business_label": "default",+ "connector_label": "first_stripe_connector","connector_account_details": {"auth_type": "HeaderKey","api_key": "{{connector_api_key}}"diff --git a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/event.test.js b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/event.test.jsindex d7259b6a84..98f405d8bb 100644--- a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/event.test.js+++ b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/event.test.js@@ -20,7 +20,7 @@ pm.test(let jsonData = {};try {jsonData = pm.response.json();-} catch (e) {}+} catch (e) { }// pm.collectionVariables - Set merchant_connector_id as variable for jsonData.merchant_connector_idif (jsonData?.merchant_connector_id) {@@ -37,3 +37,11 @@ if (jsonData?.merchant_connector_id) {"INFO - Unable to assign variable {{merchant_connector_id}}, as jsonData.merchant_connector_id is undefined.",);}++// Validate if the connector label is the one that is passed in the request+pm.test(+ "[POST]::/accounts/:account_id/connectors - connector_label is not autogenerated",+ function () {+ pm.expect(jsonData.connector_label).to.eql("updated_stripe_connector")+ },+);\ No newline at end of filediff --git a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/request.json b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/request.jsonindex 1d77181f26..322a86724c 100644--- a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/request.json+++ b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/request.json@@ -43,6 +43,7 @@"auth_type": "HeaderKey","api_key": "{{connector_api_key}}"},+ "connector_label": "updated_stripe_connector","test_mode": false,"disabled": false,"payment_methods_enabled": [