Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Finish removing Stripe from codebase

Tuan Dang28943f3b6ff2
diff --git a/.env.example b/.env.example
index 59c9c59300..1926bcef63 100644
--- a/.env.example
+++ b/.env.example
@@ -61,13 +61,6 @@ SENTRY_DSN=
# Ignore - Not applicable for self-hosted version
POSTHOG_HOST=
POSTHOG_PROJECT_API_KEY=
-STRIPE_SECRET_KEY=
-STRIPE_PUBLISHABLE_KEY=
-STRIPE_WEBHOOK_SECRET=
-STRIPE_PRODUCT_STARTER=
-STRIPE_PRODUCT_TEAM=
-STRIPE_PRODUCT_PRO=
-NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=
CLIENT_ID_GOOGLE=
CLIENT_SECRET_GOOGLE=
diff --git a/.gitignore b/.gitignore
index b8341e81b8..db04f4ec22 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
node_modules
.env
.env.dev
+.env.gamma
.env.prod
.env.infisical
diff --git a/backend/environment.d.ts b/backend/environment.d.ts
index 9bbff7a240..25f56dcc69 100644
--- a/backend/environment.d.ts
+++ b/backend/environment.d.ts
@@ -39,12 +39,6 @@ declare global {
SMTP_PASSWORD: string;
SMTP_FROM_ADDRESS: string;
SMTP_FROM_NAME: string;
- STRIPE_PRODUCT_STARTER: string;
- STRIPE_PRODUCT_TEAM: string;
- STRIPE_PRODUCT_PRO: string;
- STRIPE_PUBLISHABLE_KEY: string;
- STRIPE_SECRET_KEY: string;
- STRIPE_WEBHOOK_SECRET: string;
TELEMETRY_ENABLED: string;
LICENSE_KEY: string;
}
diff --git a/backend/package-lock.json b/backend/package-lock.json
index 735f033b8e..dd4e7dc6c7 100644
--- a/backend/package-lock.json
+++ b/backend/package-lock.json
@@ -50,7 +50,6 @@
"query-string": "^7.1.3",
"rate-limit-mongo": "^2.3.2",
"rimraf": "^3.0.2",
- "stripe": "^10.7.0",
"swagger-autogen": "^2.22.0",
"swagger-ui-express": "^4.6.2",
"tweetnacl": "^1.0.3",
@@ -11588,18 +11587,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
- "node_modules/stripe": {
- "version": "10.17.0",
- "resolved": "https://registry.npmjs.org/stripe/-/stripe-10.17.0.tgz",
- "integrity": "sha512-JHV2KoL+nMQRXu3m9ervCZZvi4DDCJfzHUE6CmtJxR9TmizyYfrVuhGvnsZLLnheby9Qrnf4Hq6iOEcejGwnGQ==",
- "dependencies": {
- "@types/node": ">=8.1.0",
- "qs": "^6.11.0"
- },
- "engines": {
- "node": "^8.1 || >=10.*"
- }
- },
"node_modules/strnum": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz",
@@ -21096,15 +21083,6 @@
"integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==",
"dev": true
},
- "stripe": {
- "version": "10.17.0",
- "resolved": "https://registry.npmjs.org/stripe/-/stripe-10.17.0.tgz",
- "integrity": "sha512-JHV2KoL+nMQRXu3m9ervCZZvi4DDCJfzHUE6CmtJxR9TmizyYfrVuhGvnsZLLnheby9Qrnf4Hq6iOEcejGwnGQ==",
- "requires": {
- "@types/node": ">=8.1.0",
- "qs": "^6.11.0"
- }
- },
"strnum": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz",
diff --git a/backend/package.json b/backend/package.json
index b65fe13aa2..84750e6b95 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -41,7 +41,6 @@
"query-string": "^7.1.3",
"rate-limit-mongo": "^2.3.2",
"rimraf": "^3.0.2",
- "stripe": "^10.7.0",
"swagger-autogen": "^2.22.0",
"swagger-ui-express": "^4.6.2",
"tweetnacl": "^1.0.3",
diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts
index 62638859ac..0f626b8042 100644
--- a/backend/src/config/index.ts
+++ b/backend/src/config/index.ts
@@ -67,14 +67,6 @@ export const getLicenseServerKey = async () => {
}
export const getLicenseServerUrl = async () => (await client.getSecret("LICENSE_SERVER_URL")).secretValue || "https://portal.infisical.com";
-// TODO: deprecate from here
-export const getStripeProductStarter = async () => (await client.getSecret("STRIPE_PRODUCT_STARTER")).secretValue;
-export const getStripeProductPro = async () => (await client.getSecret("STRIPE_PRODUCT_PRO")).secretValue;
-export const getStripeProductTeam = async () => (await client.getSecret("STRIPE_PRODUCT_TEAM")).secretValue;
-export const getStripePublishableKey = async () => (await client.getSecret("STRIPE_PUBLISHABLE_KEY")).secretValue;
-export const getStripeSecretKey = async () => (await client.getSecret("STRIPE_SECRET_KEY")).secretValue;
-export const getStripeWebhookSecret = async () => (await client.getSecret("STRIPE_WEBHOOK_SECRET")).secretValue;
-
export const getTelemetryEnabled = async () => (await client.getSecret("TELEMETRY_ENABLED")).secretValue !== "false" && true;
export const getLoopsApiKey = async () => (await client.getSecret("LOOPS_API_KEY")).secretValue;
export const getSmtpConfigured = async () => (await client.getSecret("SMTP_HOST")).secretValue == "" || (await client.getSecret("SMTP_HOST")).secretValue == undefined ? false : true
diff --git a/backend/src/controllers/v1/index.ts b/backend/src/controllers/v1/index.ts
index 5f25238951..9e4a45c8b3 100644
--- a/backend/src/controllers/v1/index.ts
+++ b/backend/src/controllers/v1/index.ts
@@ -10,7 +10,6 @@ import * as passwordController from "./passwordController";
import * as secretController from "./secretController";
import * as serviceTokenController from "./serviceTokenController";
import * as signupController from "./signupController";
-import * as stripeController from "./stripeController";
import * as userActionController from "./userActionController";
import * as userController from "./userController";
import * as workspaceController from "./workspaceController";
@@ -28,7 +27,6 @@ export {
secretController,
serviceTokenController,
signupController,
- stripeController,
userActionController,
userController,
workspaceController,
diff --git a/backend/src/controllers/v1/organizationController.ts b/backend/src/controllers/v1/organizationController.ts
index 304df8b432..8cbc5232f1 100644
--- a/backend/src/controllers/v1/organizationController.ts
+++ b/backend/src/controllers/v1/organizationController.ts
@@ -1,5 +1,4 @@
import { Request, Response } from "express";
-import Stripe from "stripe";
import {
IncidentContactOrg,
Membership,
@@ -10,7 +9,8 @@ import {
import { createOrganization as create } from "../../helpers/organization";
import { addMembershipsOrg } from "../../helpers/membershipOrg";
import { ACCEPTED, OWNER } from "../../variables";
-import { getSiteURL, getStripeSecretKey } from "../../config";
+import { getSiteURL, getLicenseServerUrl } from "../../config";
+import { licenseServerKeyRequest } from "../../config/request";
export const getOrganizations = async (req: Request, res: Response) => {
const organizations = (
@@ -222,7 +222,7 @@ export const deleteOrganizationIncidentContact = async (
};
/**
- * Redirect user to (stripe) billing portal or add card page depending on
+ * Redirect user to billing portal or add card page depending on
* if there is a card on file
* @param req
* @param res
@@ -232,34 +232,32 @@ export const createOrganizationPortalSession = async (
req: Request,
res: Response
) => {
- let session;
- const stripe = new Stripe(await getStripeSecretKey(), {
- apiVersion: "2022-08-01",
- });
-
- // check if there is a payment method on file
- const paymentMethods = await stripe.paymentMethods.list({
- customer: req.organization.customerId,
- type: "card",
- });
+ const { data: { pmtMethods } } = await licenseServerKeyRequest.get(
+ `${await getLicenseServerUrl()}/api/license-server/v1/customers/${req.organization.customerId}/billing-details/payment-methods`,
+ );
- if (paymentMethods.data.length < 1) {
- // case: no payment method on file
- session = await stripe.checkout.sessions.create({
- customer: req.organization.customerId,
- mode: "setup",
- payment_method_types: ["card"],
- success_url: (await getSiteURL()) + "/dashboard",
- cancel_url: (await getSiteURL()) + "/dashboard",
- });
+ if (pmtMethods.length < 1) {
+ // case: organization has no payment method on file
+ // -> redirect to add payment method portal
+ const { data: { url } } = await licenseServerKeyRequest.post(
+ `${await getLicenseServerUrl()}/api/license-server/v1/customers/${req.organization.customerId}/billing-details/payment-methods`,
+ {
+ success_url: (await getSiteURL()) + "/dashboard",
+ cancel_url: (await getSiteURL()) + "/dashboard"
+ }
+ );
+ return res.status(200).send({ url });
} else {
- session = await stripe.billingPortal.sessions.create({
- customer: req.organization.customerId,
- return_url: (await getSiteURL()) + "/dashboard",
- });
+ // case: organization has payment method on file
+ // -> redirect to billing portal
+ const { data: { url } } = await licenseServerKeyRequest.post(
+ `${await getLicenseServerUrl()}/api/license-server/v1/customers/${req.organization.customerId}/billing-details/billing-portal`,
+ {
+ return_url: (await getSiteURL()) + "/dashboard"
+ }
+ );
+ return res.status(200).send({ url });
}
-
- return res.status(200).send({ url: session.url });
};
/**
@@ -272,16 +270,8 @@ export const getOrganizationSubscriptions = async (
req: Request,
res: Response
) => {
- const stripe = new Stripe(await getStripeSecretKey(), {
- apiVersion: "2022-08-01",
- });
-
- const subscriptions = await stripe.subscriptions.list({
- customer: req.organization.customerId,
- });
-
return res.status(200).send({
- subscriptions,
+ subscriptions: []
});
};
diff --git a/backend/src/controllers/v1/stripeController.ts b/backend/src/controllers/v1/stripeController.ts
deleted file mode 100644
index 2acb52abda..0000000000
--- a/backend/src/controllers/v1/stripeController.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import { Request, Response } from "express";
-import Stripe from "stripe";
-import { getStripeSecretKey, getStripeWebhookSecret } from "../../config";
-
-/**
- * Handle service provisioning/un-provisioning via Stripe
- * @param req
- * @param res
- * @returns
- */
-export const handleWebhook = async (req: Request, res: Response) => {
- // check request for valid stripe signature
- const stripe = new Stripe(await getStripeSecretKey(), {
- apiVersion: "2022-08-01",
- });
-
- const sig = req.headers["stripe-signature"] as string;
- const event = stripe.webhooks.constructEvent(
- req.body,
- sig,
- await getStripeWebhookSecret()
- );
-
- switch (event.type) {
- case "":
- break;
- default:
- }
-
- return res.json({ received: true });
-};
diff --git a/backend/src/ee/controllers/v1/index.ts b/backend/src/ee/controllers/v1/index.ts
index c8b9f48a20..75b30ff95a 100644
--- a/backend/src/ee/controllers/v1/index.ts
+++ b/backend/src/ee/controllers/v1/index.ts
@@ -1,4 +1,3 @@
-import * as stripeController from "./stripeController";
import * as secretController from "./secretController";
import * as secretSnapshotController from "./secretSnapshotController";
import * as organizationsController from "./organizationsController";
@@ -8,7 +7,6 @@ import * as membershipController from "./membershipController";
import * as cloudProductsController from "./cloudProductsController";
export {
- stripeController,
secretController,
secretSnapshotController,
organizationsController,
diff --git a/backend/src/ee/controllers/v1/organizationsController.ts b/backend/src/ee/controllers/v1/organizationsController.ts
index 54c154c7a6..7ab2c5d32a 100644
--- a/backend/src/ee/controllers/v1/organizationsController.ts
+++ b/backend/src/ee/controllers/v1/organizationsController.ts
@@ -52,7 +52,7 @@ export const getOrganizationPmtMethods = async (req: Request, res: Response) =>
}
/**
- * Return a Stripe session URL to add payment method for organization
+ * Return URL to add payment method for organization
*/
export const addOrganizationPmtMethod = async (req: Request, res: Response) => {
const {
diff --git a/backend/src/ee/controllers/v1/stripeController.ts b/backend/src/ee/controllers/v1/stripeController.ts
deleted file mode 100644
index bd3ed7704d..0000000000
--- a/backend/src/ee/controllers/v1/stripeController.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import { Request, Response } from "express";
-import Stripe from "stripe";
-import { getStripeSecretKey, getStripeWebhookSecret } from "../../../config";
-
-/**
- * Handle service provisioning/un-provisioning via Stripe
- * @param req
- * @param res
- * @returns
- */
-export const handleWebhook = async (req: Request, res: Response) => {
- const stripe = new Stripe(await getStripeSecretKey(), {
- apiVersion: "2022-08-01",
- });
-
- // check request for valid stripe signature
- const sig = req.headers["stripe-signature"] as string;
- const event = stripe.webhooks.constructEvent(
- req.body,
- sig,
- await getStripeWebhookSecret()
- );
-
- switch (event.type) {
- case "":
- break;
- default:
- }
-
- return res.json({ received: true });
-};
diff --git a/backend/src/ee/routes/v1/stripe.ts b/backend/src/ee/routes/v1/stripe.ts
deleted file mode 100644
index 101f44f24d..0000000000
--- a/backend/src/ee/routes/v1/stripe.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import express from "express";
-const router = express.Router();
-import { stripeController } from "../../controllers/v1";
-
-router.post("/webhook", stripeController.handleWebhook);
-
-export default router;
\ No newline at end of file
diff --git a/backend/src/ee/services/EELicenseService.ts b/backend/src/ee/services/EELicenseService.ts
index 6417eeb1c5..d6fce3c7f7 100644
--- a/backend/src/ee/services/EELicenseService.ts
+++ b/backend/src/ee/services/EELicenseService.ts
@@ -83,7 +83,7 @@ class EELicenseService {
if (!organization) throw OrganizationNotFoundError();
let url = `${await getLicenseServerUrl()}/api/license-server/v1/customers/${organization.customerId}/cloud-plan`;
-
+
if (workspaceId) {
url += `?workspaceId=${workspaceId}`;
}
diff --git a/backend/src/helpers/organization.ts b/backend/src/helpers/organization.ts
index 642a1233bb..2e9189e113 100644
--- a/backend/src/helpers/organization.ts
+++ b/backend/src/helpers/organization.ts
@@ -1,19 +1,13 @@
-import Stripe from "stripe";
import { Types } from "mongoose";
import { MembershipOrg, Organization } from "../models";
import {
ACCEPTED,
} from "../variables";
-import {
- getStripeProductPro,
- getStripeProductStarter,
- getStripeProductTeam,
- getStripeSecretKey,
-} from "../config";
import {
EELicenseService,
} from "../ee/services";
import {
+ getLicenseServerKey,
getLicenseServerUrl,
} from "../config";
import {
@@ -35,21 +29,21 @@ export const createOrganization = async ({
name: string;
email: string;
}) => {
+ const licenseServerKey = await getLicenseServerKey();
let organization;
- // register stripe account
- const stripe = new Stripe(await getStripeSecretKey(), {
- apiVersion: "2022-08-01",
- });
-
- if (await getStripeSecretKey()) {
- const customer = await stripe.customers.create({
- email,
- description: name,
- });
-
+
+ if (licenseServerKey) {
+ const { data: { customerId } } = await licenseServerKeyRequest.post(
+ `${await getLicenseServerUrl()}/api/license-server/v1/customers`,
+ {
+ email,
+ name
+ }
+ );
+
organization = await new Organization({
name,
- customerId: customer.id,
+ customerId
}).save();
} else {
organization = await new Organization({
@@ -57,68 +51,9 @@ export const createOrganization = async ({
}).save();
}
- await initSubscriptionOrg({ organizationId: organization._id });
-
return organization;
};
-/**
- * Initialize free-tier subscription for new organization
- * @param {Object} obj
- * @param {String} obj.organizationId - id of associated organization for subscription
- * @return {Object} obj
- * @return {Object} obj.stripeSubscription - new stripe subscription
- * @return {Subscription} obj.subscription - new subscription
- */
-export const initSubscriptionOrg = async ({
- organizationId,
-}: {
- organizationId: Types.ObjectId;
-}) => {
- let stripeSubscription;
- let subscription;
-
- // find organization
- const organization = await Organization.findOne({
- _id: organizationId,
- });
-
- if (organization) {
- if (organization.customerId) {
- // initialize starter subscription with quantity of 0
- const stripe = new Stripe(await getStripeSecretKey(), {
- apiVersion: "2022-08-01",
- });
-
- const productToPriceMap = {
- starter: await getStripeProductStarter(),
- team: await getStripeProductTeam(),
- pro: await getStripeProductPro(),
- };
-
- stripeSubscription = await stripe.subscriptions.create({
- customer: organization.customerId,
- items: [
- {
- price: productToPriceMap["starter"],
- quantity: 1,
- },
- ],
- payment_behavior: "default_incomplete",
- proration_behavior: "none",
- expand: ["latest_invoice.payment_intent"],
- });
- }
- } else {
- throw new Error("Failed to initialize free organization subscription");
- }
-
- return {
- stripeSubscription,
- subscription,
- };
-};
-
/**
* Update organization subscription quantity to reflect number of members in
* the organization.
@@ -130,7 +65,6 @@ export const updateSubscriptionOrgQuantity = async ({
}: {
organizationId: string;
}) => {
- let stripeSubscription;
// find organization
const organization = await Organization.findOne({
_id: organizationId,
@@ -171,6 +105,4 @@ export const updateSubscriptionOrgQuantity = async ({
}
await EELicenseService.refreshPlan(organizationId);
-
- return stripeSubscription;
};
\ No newline at end of file
diff --git a/backend/src/index.ts b/backend/src/index.ts
index d0cd67ae52..826d5ca9cc 100644
--- a/backend/src/index.ts
+++ b/backend/src/index.ts
@@ -37,7 +37,6 @@ import {
secretsFolder as v1SecretsFolder,
serviceToken as v1ServiceTokenRouter,
signup as v1SignupRouter,
- stripe as v1StripeRouter,
userAction as v1UserActionRouter,
user as v1UserRouter,
workspace as v1WorkspaceRouter,
@@ -123,7 +122,6 @@ const main = async () => {
app.use("/api/v1/secret", v1SecretRouter); // deprecate
app.use("/api/v1/service-token", v1ServiceTokenRouter); // deprecate
app.use("/api/v1/password", v1PasswordRouter);
- app.use("/api/v1/stripe", v1StripeRouter);
app.use("/api/v1/integration", v1IntegrationRouter);
app.use("/api/v1/integration-auth", v1IntegrationAuthRouter);
app.use("/api/v1/folders", v1SecretsFolder);
diff --git a/backend/src/routes/v1/index.ts b/backend/src/routes/v1/index.ts
index 7efc36a953..43c0f672c2 100644
--- a/backend/src/routes/v1/index.ts
+++ b/backend/src/routes/v1/index.ts
@@ -12,7 +12,6 @@ import inviteOrg from "./inviteOrg";
import secret from "./secret";
import serviceToken from "./serviceToken";
import password from "./password";
-import stripe from "./stripe";
import integration from "./integration";
import integrationAuth from "./integrationAuth";
import secretsFolder from "./secretsFolder";
@@ -32,7 +31,6 @@ export {
secret,
serviceToken,
password,
- stripe,
integration,
integrationAuth,
secretsFolder,
diff --git a/backend/src/routes/v1/stripe.ts b/backend/src/routes/v1/stripe.ts
deleted file mode 100644
index d4ba1255d9..0000000000
--- a/backend/src/routes/v1/stripe.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import express from "express";
-const router = express.Router();
-import { stripeController } from "../../controllers/v1";
-
-router.post("/webhook", stripeController.handleWebhook);
-
-export default router;
diff --git a/backend/src/variables/index.ts b/backend/src/variables/index.ts
index 24e86b8fea..5a625d49d3 100644
--- a/backend/src/variables/index.ts
+++ b/backend/src/variables/index.ts
@@ -8,6 +8,5 @@ export * from "./organization";
export * from "./permission";
export * from "./secret";
export * from "./smtp";
-export * from "./stripe";
export * from "./token";
export * from "./user";
diff --git a/backend/src/variables/stripe.ts b/backend/src/variables/stripe.ts
deleted file mode 100644
index fa0fdae071..0000000000
--- a/backend/src/variables/stripe.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export const PLAN_STARTER = "starter";
-export const PLAN_PRO = "pro";
\ No newline at end of file
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index ad5a3ce02b..8ffa7c3e97 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -55,9 +55,6 @@ services:
environment:
- NEXT_PUBLIC_ENV=development
- INFISICAL_TELEMETRY_ENABLED=${TELEMETRY_ENABLED}
- - NEXT_PUBLIC_STRIPE_PRODUCT_PRO=${STRIPE_PRODUCT_PRO}
- - NEXT_PUBLIC_STRIPE_PRODUCT_TEAM=${STRIPE_PRODUCT_TEAM}
- - NEXT_PUBLIC_STRIPE_PRODUCT_STARTER=${STRIPE_PRODUCT_STARTER}
networks:
- infisical-dev
diff --git a/docker-compose.yml b/docker-compose.yml
index f1b8f7d05a..16f0bd1282 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -38,9 +38,6 @@ services:
environment:
# - NEXT_PUBLIC_POSTHOG_API_KEY=${POSTHOG_PROJECT_API_KEY}
- INFISICAL_TELEMETRY_ENABLED=${TELEMETRY_ENABLED}
- - NEXT_PUBLIC_STRIPE_PRODUCT_PRO=${STRIPE_PRODUCT_PRO}
- - NEXT_PUBLIC_STRIPE_PRODUCT_TEAM=${STRIPE_PRODUCT_TEAM}
- - NEXT_PUBLIC_STRIPE_PRODUCT_STARTER=${STRIPE_PRODUCT_STARTER}
networks:
- infisical
diff --git a/frontend/src/components/utilities/config/index.ts b/frontend/src/components/utilities/config/index.ts
index acdbb4674e..6ced4cac9c 100644
--- a/frontend/src/components/utilities/config/index.ts
+++ b/frontend/src/components/utilities/config/index.ts
@@ -2,14 +2,11 @@ const ENV = process.env.NEXT_PUBLIC_ENV! || "development"; // investigate
const POSTHOG_API_KEY = process.env.NEXT_PUBLIC_POSTHOG_API_KEY!;
const POSTHOG_HOST =
process.env.NEXT_PUBLIC_POSTHOG_HOST! || "https://app.posthog.com";
-const STRIPE_PRODUCT_PRO = process.env.NEXT_PUBLIC_STRIPE_PRODUCT_PRO!;
-const STRIPE_PRODUCT_STARTER = process.env.NEXT_PUBLIC_STRIPE_PRODUCT_STARTER!;
const INTERCOM_ID = process.env.NEXT_PUBLIC_INTERCOM_ID!;
export {
ENV,
INTERCOM_ID,
POSTHOG_API_KEY,
- POSTHOG_HOST,
- STRIPE_PRODUCT_PRO,
- STRIPE_PRODUCT_STARTER};
\ No newline at end of file
+ POSTHOG_HOST
+};
\ No newline at end of file
diff --git a/frontend/src/pages/settings/billing/[id].tsx b/frontend/src/pages/settings/billing/[id].tsx
index 7f0bf7eac6..4d99bd0311 100644
--- a/frontend/src/pages/settings/billing/[id].tsx
+++ b/frontend/src/pages/settings/billing/[id].tsx
@@ -1,16 +1,12 @@
-import { useEffect, useState } from "react";
+import { useState } from "react";
import { useTranslation } from "react-i18next";
import Head from "next/head";
-
import Plan from "@app/components/billing/Plan";
import NavHeader from "@app/components/navigation/NavHeader";
-import { plans as plansConstant } from "@app/const";
-
-import getOrganizationSubscriptions from "../../api/organization/GetOrgSubscription";
-import getOrganizationUsers from "../../api/organization/GetOrgUsers";
+import { useSubscription } from "@app/context";
export default function SettingsBilling() {
- const [currentPlan, setCurrentPlan] = useState("");
+ const { subscription } = useSubscription();
const [numUsers, setNumUsers] = useState(0);
const { t } = useTranslation();
@@ -25,7 +21,7 @@ export default function SettingsBilling() {
subtext: t("billing.starter.subtext")!,
buttonTextMain: t("billing.downgrade")!,
buttonTextSecondary: t("billing.learn-more")!,
- current: currentPlan === plansConstant.starter
+ current: subscription?.slug === "starter" // subscription.slug?
},
{
key: 2,
@@ -35,7 +31,7 @@ export default function SettingsBilling() {
text: "Unlimited members, up to 10 projects. Additional developer experience features.",
buttonTextMain: t("billing.upgrade")!,
buttonTextSecondary: t("billing.learn-more")!,
- current: currentPlan === plansConstant.team
+ current: subscription?.slug === "team" || subscription?.slug === "team-annual"
},
{
key: 3,
@@ -46,7 +42,7 @@ export default function SettingsBilling() {
subtext: t("billing.professional.subtext")!,
buttonTextMain: t("billing.upgrade")!,
buttonTextSecondary: t("billing.learn-more")!,
- current: currentPlan === plansConstant.professional
+ current: subscription?.slug === "pro" || subscription?.slug === "pro-annual"
},
{
key: 4,
@@ -55,26 +51,10 @@ export default function SettingsBilling() {
text: "Boost the security and efficiency of your engineering teams.",
buttonTextMain: t("billing.schedule-demo")!,
buttonTextSecondary: t("billing.learn-more")!,
- current: false
+ current: subscription?.slug === "enterprise"
}
];
- useEffect(() => {
- (async () => {
- const orgId = localStorage.getItem("orgData.id") as string;
- const subscriptions = await getOrganizationSubscriptions({
- orgId
- });
- if (subscriptions) {
- setCurrentPlan(subscriptions.data[0].plan.product);
- }
- const orgUsers = await getOrganizationUsers({
- orgId
- });
- setNumUsers(orgUsers.length);
- })();
- }, []);
-
return (
<div className="flex flex-col justify-between bg-bunker-800 pb-4 text-white">
<Head>
diff --git a/frontend/src/views/Settings/OrgSettingsPage/OrgSettingsPage.tsx b/frontend/src/views/Settings/OrgSettingsPage/OrgSettingsPage.tsx
index 17f49e47f9..b9a409e0de 100644
--- a/frontend/src/views/Settings/OrgSettingsPage/OrgSettingsPage.tsx
+++ b/frontend/src/views/Settings/OrgSettingsPage/OrgSettingsPage.tsx
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { useState } from "react";
import { useTranslation } from "react-i18next";
-import { plans } from "public/data/frequentConstants";
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
import NavHeader from "@app/components/navigation/NavHeader";