add fetch billing products from tables instead of env variables (#9601)

Solves https://github.com/twentyhq/private-issues/issues/237

**TLDR:**

- Fetches billing products and prices from the tables BilllingProducts
and BillingPrices instead of fetching the product from the environment
variables and the prices from the stripe API.
- Adds new feature flag for this feature
- Fixes calls used to fetch stripe products and prices for the command
Billing Sync Plans Data.


**In order to test:**

1. Have the environment variable IS_BILLING_ENABLED set to true and add
the other required environment variables for Billing to work
2. Do a database reset (to ensure that the new feature flag is properly
added and that the billing tables are created)
3. Run the command: `npx nx run twenty-server:command
billing:sync-plans-data` (if you don't do that the products and prices
will not be present in the database)
4. Run the server , the frontend, the worker, and the stripe listen
command (`stripe listen --forward-to
http://localhost:3000/billing/webhooks`)
5. Buy a subscription for the Acme workspace and play with the project

**Doing**

I think there is some room of progress for the function
formatProductPrices, I used a similar version that was done before, I'll
look into that.
This commit is contained in:
Ana Sofia Marin Alexandre
2025-01-21 16:19:29 -03:00
committed by GitHub
parent 3d2bb03c6d
commit 7d30b7577d
59 changed files with 870 additions and 245 deletions

View File

@ -50,6 +50,11 @@ export const seedFeatureFlags = async (
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKey.IsBillingPlansEnabled,
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKey.IsGmailSendEmailScopeEnabled,
workspaceId: workspaceId,

View File

@ -0,0 +1,25 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddNonNullableProductDescription1737127856478
implements MigrationInterface
{
name = 'AddNonNullableProductDescription1737127856478';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."billingProduct" ALTER COLUMN "description" SET DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingProduct" ALTER COLUMN "description" SET NOT NULL`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."billingProduct" ALTER COLUMN "description" DROP DEFAULT`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingProduct" ALTER COLUMN "description" DROP NOT NULL`,
);
}
}