From a610f9c9a7d4ee574375442c9d08f1c50dc43273 Mon Sep 17 00:00:00 2001 From: Narayan Bhat Date: Tue, 17 Oct 2023 15:36:44 +0530 Subject: [PATCH 1/7] refactor: accept connector_label in request --- crates/api_models/src/admin.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index 6162ceffcb30..f4201ac8d90e 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -560,10 +560,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, /// Unique ID of the connector #[schema(example = "mca_5apGeP94tMts6rg3U3kR")] From 9793a0acdc1e7323f3f476c4200b276ba5c0b874 Mon Sep 17 00:00:00 2001 From: Narayan Bhat Date: Tue, 17 Oct 2023 19:06:57 +0530 Subject: [PATCH 2/7] refactor: accept connector_label in create request --- crates/router/src/core/admin.rs | 47 ++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 2fecb57323e2..577e04da2417 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -624,12 +624,39 @@ 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.to_string(), + business_profile.profile_name + )); let mut vec = Vec::new(); let payment_methods_enabled = match req.payment_methods_enabled { @@ -682,16 +709,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, @@ -713,7 +730,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, From 45243853bd5c0ef60d95bfd0643e2864f2a185fe Mon Sep 17 00:00:00 2001 From: Narayan Bhat Date: Wed, 18 Oct 2023 12:26:55 +0530 Subject: [PATCH 3/7] refactor: allow updating connector label --- crates/api_models/src/admin.rs | 7 +++++-- crates/diesel_models/src/merchant_connector_account.rs | 1 + crates/router/src/core/admin.rs | 1 + .../router/src/types/domain/merchant_connector_account.rs | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index f4201ac8d90e..b0188155cfe4 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -655,8 +655,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, @@ -749,6 +749,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, + /// 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,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))] pub connector_account_details: Option, diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rs index ce2684c937ab..a4faa45ce4bc 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, pub connector_name: Option, pub connector_account_details: Option, + pub connector_label: Option, pub test_mode: Option, pub disabled: Option, pub merchant_connector_id: Option, diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 577e04da2417..867f2a5a3145 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -892,6 +892,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/types/domain/merchant_connector_account.rs b/crates/router/src/types/domain/merchant_connector_account.rs index a8dce1e6f078..58c2e018316c 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, applepay_verified_domains: Option>, pm_auth_config: Option, + connector_label: Option, }, } @@ -175,6 +176,7 @@ impl From for MerchantConnectorAccountUpdateInte connector_webhook_details, applepay_verified_domains, pm_auth_config, + connector_label, } => Self { merchant_id, connector_type, @@ -191,6 +193,7 @@ impl From for MerchantConnectorAccountUpdateInte connector_webhook_details, applepay_verified_domains, pm_auth_config, + connector_label, }, } } From ca76b0fe7ff0639aa3262a19da93591253825861 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 18 Oct 2023 07:09:40 +0000 Subject: [PATCH 4/7] docs(openapi): re-generate OpenAPI specification --- openapi/openapi_spec.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index 34c71c161000..60b2136a7b2b 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -6494,6 +6494,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", @@ -6706,6 +6712,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", @@ -6845,6 +6857,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.", From a77fd666d3b4f1ccd495f3785ed9133daf4dfdef Mon Sep 17 00:00:00 2001 From: Narayan Bhat Date: Wed, 18 Oct 2023 12:49:30 +0530 Subject: [PATCH 5/7] chore: cargo clippy --- crates/router/src/core/admin.rs | 3 +-- crates/router/src/core/verification/utils.rs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 867f2a5a3145..9cd90699ac17 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -654,8 +654,7 @@ pub async fn create_payment_connector( )) .unwrap_or(format!( "{}_{}", - req.connector_name.to_string(), - business_profile.profile_name + req.connector_name, business_profile.profile_name )); let mut vec = Vec::new(); diff --git a/crates/router/src/core/verification/utils.rs b/crates/router/src/core/verification/utils.rs index 056cc8c2e54f..433430507fb1 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 .store From 49722b728479a4b5d44ebb566fca264d36cf2ecc Mon Sep 17 00:00:00 2001 From: Narayan Bhat Date: Wed, 18 Oct 2023 15:52:45 +0530 Subject: [PATCH 6/7] tests: added test cases --- .../Payment Connector - Create/event.test.js | 9 ++++++++- .../Payment Connector - Create/request.json | 1 + .../Payment Connector - Update/event.test.js | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) 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.js index aa1bc4845b74..a932b1594bf8 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_id if (jsonData?.merchant_connector_id) { @@ -37,3 +37,10 @@ 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 +if (jsonData?.connector_label != "first_stripe_con`") { + console.log( + "ERROR - The connector_label is not updated", + ); +} diff --git a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Create/request.json b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Create/request.json index 6fe1be149f8d..6f89fa181d13 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.js index d7259b6a840b..86564943335b 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_id if (jsonData?.merchant_connector_id) { @@ -37,3 +37,10 @@ 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 +if (jsonData?.connector_label != "updated_stripe_connector`") { + console.log( + "ERROR - The connector_label is not updated", + ); +} \ No newline at end of file From 71fb7de3cbcea067b7e1c706ff5296ea4c9a9159 Mon Sep 17 00:00:00 2001 From: Narayan Bhat Date: Wed, 18 Oct 2023 16:44:05 +0530 Subject: [PATCH 7/7] tests: added test cases --- .../Payment Connector - Create/event.test.js | 11 ++++++----- .../Payment Connector - Update/event.test.js | 11 ++++++----- .../Payment Connector - Update/request.json | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) 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.js index a932b1594bf8..bd543edd2c31 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 @@ -39,8 +39,9 @@ if (jsonData?.merchant_connector_id) { } // Validate if the connector label is the one that is passed in the request -if (jsonData?.connector_label != "first_stripe_con`") { - console.log( - "ERROR - The connector_label is not updated", - ); -} +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 file 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.js index 86564943335b..98f405d8bb85 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 @@ -39,8 +39,9 @@ if (jsonData?.merchant_connector_id) { } // Validate if the connector label is the one that is passed in the request -if (jsonData?.connector_label != "updated_stripe_connector`") { - console.log( - "ERROR - The connector_label is not updated", - ); -} \ No newline at end of file +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 file diff --git a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/request.json b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/request.json index 1d77181f262d..322a86724c35 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": [