twenty/packages
Ana Sofia Marin Alexandre 35f2d7a004
Add entitlement table and sso stripe feature (#8608)
**TLDR**


Added Billing Entitlement table, based on stripe
customer.ActiveEntitlements webhook event. In this table it has a key
value pair with each key being the stripe feature lookup key and the
value a boolean. We use this table in order to see if SSO or other
feaures are enabled by workspace.

**In order to test: twenty-server**


Billing:

- Set IS_BILLING_ENABLED to true
- Add your BILLING_STRIPE_SECRET and BILLING_STRIPE_API_KEY
- Add your BILLING_STRIPE_BASE_PLAN_PRODUCT_ID (use the one in testMode
> Base Plan)

Auth:

- Set AUTH_SSO_ENABLED to true
- Set your ACCESS_TOKEN_SECRET, LOGIN_TOKEN_SECRET, REFRESH_TOKEN_SECRET
and FILE_TOKEN_SECRET
- Set IS_SSO_ENABLED feature flag to true

Stripe Webhook: 

- Authenticate with your account in the stripe CLI
- Run the command: stripe listen --forward-to
http://localhost:3000/billing/webhooks

Migration:

- npx nx typeorm -- migration:run -d
src/database/typeorm/core/core.datasource.ts

**In order to test: twenty site**

- Buy a subscription (you can use the card 4242...42 with expiration
date later in the future)
- Go to SSO and create an OICD subscription
- Change the value in the entitlement table in order to put it in false
- An error should occur saying that the current workspace has no
entitlement

**Considerations**

The data from the Entitlement table is updated based on the stripe
webhook responses, and we use the customerActiveEntitlemet response to
update the info on the table, however this event doesnt have the
metadata containing the workspaceId. Because we cannot control at wich
order the webhook send events, we force a server error if the
entitlements are updated before the BillingSubscription. Stripe resends
the event based on a exponential backoff (for more info see
https://docs.stripe.com/webhooks#retries ) because we are in test mode
Stripe retries three times over a few hours. So if the
BillingEntitlement is not updated it is completely normal and it will be
updated when stripe resends the event.

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
2024-11-22 15:32:48 +01:00
..
twenty-chrome-extension Settings Option Card component (#8456) 2024-11-18 09:22:33 +00:00
twenty-docker Fix interactive install script (#8669) 2024-11-22 10:29:36 +01:00
twenty-e2e-testing Begin moving to postgres spilo + adding pgvector (#8309) 2024-11-15 09:38:30 +01:00
twenty-emails Bump 0.34.0-canary (#8675) 2024-11-22 11:53:33 +01:00
twenty-front fix-percentage (#8684) 2024-11-22 14:20:37 +00:00
twenty-server Add entitlement table and sso stripe feature (#8608) 2024-11-22 15:32:48 +01:00
twenty-tinybird refactor webhookAnalytics call and enrich analytics module (#8253) 2024-11-08 10:00:51 +01:00
twenty-ui Bump 0.34.0-canary (#8675) 2024-11-22 11:53:33 +01:00
twenty-utils Fix docs build in CI (#5826) 2024-06-11 19:06:37 +02:00
twenty-website Bump 0.34.0-canary (#8675) 2024-11-22 11:53:33 +01:00
twenty-zapier Update zapier trigger payload (#8464) 2024-11-12 17:58:36 +01:00