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
feat: change admin api key auth to merchant api key auth in few connectors flow (#5572)
Hrithikesh7a23e663c283
diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rsindex a28324ee59..5e3a9c49e8 100644--- a/crates/router/src/routes/admin.rs+++ b/crates/router/src/routes/admin.rs@@ -405,11 +405,16 @@ pub async fn connector_retrieve(state,&req,payload,- |state, _, req, _| {- retrieve_connector(state, req.merchant_id, None, req.merchant_connector_id)+ |state, auth, req, _| {+ retrieve_connector(+ state,+ req.merchant_id,+ auth.profile_id,+ req.merchant_connector_id,+ )},auth::auth_type(- &auth::AdminApiAuth,+ &auth::HeaderAuth(auth::ApiKeyAuth),&auth::JWTAuthMerchantFromRoute {merchant_id,required_permission: Permission::MerchantConnectorAccountRead,@@ -518,9 +523,9 @@ pub async fn payment_connector_list(state,&req,merchant_id.to_owned(),- |state, _, merchant_id, _| list_payment_connectors(state, merchant_id, None),+ |state, _auth, merchant_id, _| list_payment_connectors(state, merchant_id, None),auth::auth_type(- &auth::AdminApiAuth,+ &auth::HeaderAuth(auth::ApiKeyAuth),&auth::JWTAuthMerchantFromRoute {merchant_id,required_permission: Permission::MerchantConnectorAccountRead,@@ -570,9 +575,17 @@ pub async fn connector_update(state,&req,json_payload.into_inner(),- |state, _, req, _| update_connector(state, &merchant_id, None, &merchant_connector_id, req),+ |state, auth, req, _| {+ update_connector(+ state,+ &merchant_id,+ auth.profile_id,+ &merchant_connector_id,+ req,+ )+ },auth::auth_type(- &auth::AdminApiAuth,+ &auth::HeaderAuth(auth::ApiKeyAuth),&auth::JWTAuthMerchantFromRoute {merchant_id: merchant_id.clone(),required_permission: Permission::MerchantConnectorAccountWrite,diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex aadf258123..db2ad63773 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -484,7 +484,7 @@ Cypress.Commands.add("connectorRetrieveCall", (globalState) => {headers: {Accept: "application/json","Content-Type": "application/json",- "api-key": globalState.get("adminApiKey"),+ "api-key": globalState.get("apiKey"),},failOnStatusCode: false,}).then((response) => {@@ -530,7 +530,7 @@ Cypress.Commands.add(headers: {Accept: "application/json","Content-Type": "application/json",- "api-key": globalState.get("adminApiKey"),+ "api-key": globalState.get("apiKey"),},body: updateConnectorBody,failOnStatusCode: false,@@ -554,7 +554,7 @@ Cypress.Commands.add("connectorListByMid", (globalState) => {url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors`,headers: {"Content-Type": "application/json",- "api-key": globalState.get("adminApiKey"),+ "api-key": globalState.get("apiKey"),},failOnStatusCode: false,}).then((response) => {@@ -2060,7 +2060,7 @@ Cypress.Commands.add("ListMCAbyMID", (globalState) => {url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`,headers: {"Content-Type": "application/json",- "api-key": globalState.get("adminApiKey"),+ "api-key": globalState.get("apiKey"),},failOnStatusCode: false,}).then((response) => {diff --git a/postman/collection-dir/stripe/PaymentConnectors/.meta.json b/postman/collection-dir/stripe/PaymentConnectors/.meta.jsonindex 3f8bc360dd..198acc6d53 100644--- a/postman/collection-dir/stripe/PaymentConnectors/.meta.json+++ b/postman/collection-dir/stripe/PaymentConnectors/.meta.json@@ -1,5 +1,6 @@{"childrenOrder": [+ "API Key - Create","Payment Connector - Create","Payment Connector - Retrieve","Payment Connector - Update",diff --git a/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/.event.meta.json b/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/.event.meta.jsonnew file mode 100644index 0000000000..0731450e6b--- /dev/null+++ b/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/.event.meta.json@@ -0,0 +1,3 @@+{+ "eventOrder": ["event.test.js"]+}diff --git a/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/event.test.js b/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/event.test.jsnew file mode 100644index 0000000000..4e27c5a502--- /dev/null+++ b/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/event.test.js@@ -0,0 +1,46 @@+// Validate status 2xx+pm.test("[POST]::/api_keys/:merchant_id - Status code is 2xx", function () {+ pm.response.to.be.success;+});++// Validate if response header has matching content-type+pm.test(+ "[POST]::/api_keys/:merchant_id - Content-Type is application/json",+ function () {+ pm.expect(pm.response.headers.get("Content-Type")).to.include(+ "application/json",+ );+ },+);++// Set response object as internal variable+let jsonData = {};+try {+ jsonData = pm.response.json();+} catch (e) {}++// pm.collectionVariables - Set api_key_id as variable for jsonData.key_id+if (jsonData?.key_id) {+ pm.collectionVariables.set("api_key_id", jsonData.key_id);+ console.log(+ "- use {{api_key_id}} as collection variable for value",+ jsonData.key_id,+ );+} else {+ console.log(+ "INFO - Unable to assign variable {{api_key_id}}, as jsonData.key_id is undefined.",+ );+}++// pm.collectionVariables - Set api_key as variable for jsonData.api_key+if (jsonData?.api_key) {+ pm.collectionVariables.set("api_key", jsonData.api_key);+ console.log(+ "- use {{api_key}} as collection variable for value",+ jsonData.api_key,+ );+} else {+ console.log(+ "INFO - Unable to assign variable {{api_key}}, as jsonData.api_key is undefined.",+ );+}diff --git a/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/request.json b/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/request.jsonnew file mode 100644index 0000000000..6ceefe5d24--- /dev/null+++ b/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/request.json@@ -0,0 +1,47 @@+{+ "auth": {+ "type": "apikey",+ "apikey": [+ {+ "key": "value",+ "value": "{{admin_api_key}}",+ "type": "string"+ },+ {+ "key": "key",+ "value": "api-key",+ "type": "string"+ }+ ]+ },+ "method": "POST",+ "header": [+ {+ "key": "Content-Type",+ "value": "application/json"+ },+ {+ "key": "Accept",+ "value": "application/json"+ }+ ],+ "body": {+ "mode": "raw",+ "raw_json_formatted": {+ "name": "API Key 1",+ "description": null,+ "expiration": "2069-09-23T01:02:03.000Z"+ }+ },+ "url": {+ "raw": "{{baseUrl}}/api_keys/:merchant_id",+ "host": ["{{baseUrl}}"],+ "path": ["api_keys", ":merchant_id"],+ "variable": [+ {+ "key": "merchant_id",+ "value": "{{merchant_id}}"+ }+ ]+ }+}diff --git a/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/response.json b/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/response.jsonnew file mode 100644index 0000000000..fe51488c70--- /dev/null+++ b/postman/collection-dir/stripe/PaymentConnectors/API Key - Create/response.json@@ -0,0 +1 @@+[]diff --git a/postman/collection-dir/stripe/PaymentConnectors/List Connectors by MID/request.json b/postman/collection-dir/stripe/PaymentConnectors/List Connectors by MID/request.jsonindex 81d0ea5ef1..f731ff3a42 100644--- a/postman/collection-dir/stripe/PaymentConnectors/List Connectors by MID/request.json+++ b/postman/collection-dir/stripe/PaymentConnectors/List Connectors by MID/request.json@@ -4,7 +4,7 @@"apikey": [{"key": "value",- "value": "{{admin_api_key}}",+ "value": "{{api_key}}","type": "string"},{diff --git a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Retrieve/request.json b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Retrieve/request.jsonindex 7536380bcf..05f84b5771 100644--- a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Retrieve/request.json+++ b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Retrieve/request.json@@ -4,7 +4,7 @@"apikey": [{"key": "value",- "value": "{{admin_api_key}}",+ "value": "{{api_key}}","type": "string"},{diff --git a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/request.json b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/request.jsonindex 5e87da3d7f..bcc133ce43 100644--- a/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/request.json+++ b/postman/collection-dir/stripe/PaymentConnectors/Payment Connector - Update/request.json@@ -4,7 +4,7 @@"apikey": [{"key": "value",- "value": "{{admin_api_key}}",+ "value": "{{api_key}}","type": "string"},{diff --git a/postman/collection-dir/stripe/QuickStart/Payment Connector - Update/request.json b/postman/collection-dir/stripe/QuickStart/Payment Connector - Update/request.jsonindex 3e225815f9..8b46ad180f 100644--- a/postman/collection-dir/stripe/QuickStart/Payment Connector - Update/request.json+++ b/postman/collection-dir/stripe/QuickStart/Payment Connector - Update/request.json@@ -4,7 +4,7 @@"apikey": [{"key": "value",- "value": "{{admin_api_key}}",+ "value": "{{api_key}}","type": "string"},{diff --git a/postman/collection-json/stripe.postman_collection.json b/postman/collection-json/stripe.postman_collection.jsonindex d881692098..c3e3c6f158 100644--- a/postman/collection-json/stripe.postman_collection.json+++ b/postman/collection-json/stripe.postman_collection.json@@ -1348,6 +1348,115 @@}]},+ {+ "name": "API Key - Create",+ "event": [+ {+ "listen": "test",+ "script": {+ "exec": [+ "// Validate status 2xx",+ "pm.test(\"[POST]::/api_keys/:merchant_id - Status code is 2xx\", function () {",+ " pm.response.to.be.success;",+ "});",+ "",+ "// Validate if response header has matching content-type",+ "pm.test(",+ " \"[POST]::/api_keys/:merchant_id - Content-Type is application/json\",",+ " function () {",+ " pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(",+ " \"application/json\",",+ " );",+ " },",+ ");",+ "",+ "// Set response object as internal variable",+ "let jsonData = {};",+ "try {",+ " jsonData = pm.response.json();",+ "} catch (e) {}",+ "",+ "// pm.collectionVariables - Set api_key_id as variable for jsonData.key_id",+ "if (jsonData?.key_id) {",+ " pm.collectionVariables.set(\"api_key_id\", jsonData.key_id);",+ " console.log(",+ " \"- use {{api_key_id}} as collection variable for value\",",+ " jsonData.key_id,",+ " );",+ "} else {",+ " console.log(",+ " \"INFO - Unable to assign variable {{api_key_id}}, as jsonData.key_id is undefined.\",",+ " );",+ "}",+ "",+ "// pm.collectionVariables - Set api_key as variable for jsonData.api_key",+ "if (jsonData?.api_key) {",+ " pm.collectionVariables.set(\"api_key\", jsonData.api_key);",+ " console.log(",+ " \"- use {{api_key}} as collection variable for value\",",+ " jsonData.api_key,",+ " );",+ "} else {",+ " console.log(",+ " \"INFO - Unable to assign variable {{api_key}}, as jsonData.api_key is undefined.\",",+ " );",+ "}",+ ""+ ],+ "type": "text/javascript"+ }+ }+ ],+ "request": {+ "auth": {+ "type": "apikey",+ "apikey": [+ {+ "key": "value",+ "value": "{{admin_api_key}}",+ "type": "string"+ },+ {+ "key": "key",+ "value": "api-key",+ "type": "string"+ }+ ]+ },+ "method": "POST",+ "header": [+ {+ "key": "Content-Type",+ "value": "application/json"+ },+ {+ "key": "Accept",+ "value": "application/json"+ }+ ],+ "body": {+ "mode": "raw",+ "raw": "{\"name\":\"API Key 1\",\"description\":null,\"expiration\":\"2069-09-23T01:02:03.000Z\"}"+ },+ "url": {+ "raw": "{{baseUrl}}/api_keys/:merchant_id",+ "host": [+ "{{baseUrl}}"+ ],+ "path": [+ "api_keys",+ ":merchant_id"+ ],+ "variable": [+ {+ "key": "merchant_id",+ "value": "{{merchant_id}}"+ }+ ]+ }+ },+ "response": []+ },{"name": "Payment Connector - Create","event": [@@ -1528,7 +1637,7 @@"apikey": [{"key": "value",- "value": "{{admin_api_key}}",+ "value": "{{api_key}}","type": "string"},{@@ -1643,7 +1752,7 @@"apikey": [{"key": "value",- "value": "{{admin_api_key}}",+ "value": "{{api_key}}","type": "string"},{@@ -1740,7 +1849,7 @@"apikey": [{"key": "value",- "value": "{{admin_api_key}}",+ "value": "{{api_key}}","type": "string"},{@@ -2575,7 +2684,7 @@"apikey": [{"key": "value",- "value": "{{admin_api_key}}",+ "value": "{{api_key}}","type": "string"},{