Subscription Plans: Basic concept
Basic concept
Section titled “Basic concept”Some things in a brezel system can be bought / unlocked with a subscription based paywall.
For that, there is the concept of “plans” which can be bought/activated via a subscription. These define prices and most importantly, “Features” that can be used to enable or disable things in the system.
Concept Summary
Section titled “Concept Summary”- A
Userentity with the “Billable” Capability can buy a plan for anEntity. - The
Userwill be registered as a customer in stripe (identified by their email) and charged for the selected plan by stripe. - Only entities from
Modulesthat use theBuyableCapability can be bought. In the options of that capability, thesubscription_plans, which contain feature flags and prices, are defined. During bakery apply, configured plans will be created in Stripe as Products with their respective prices. - Any
Entityfrom aBuyableModule will have the fieldsactive_plansandactive_featuresset, which can be used by workflows, policies, recipes etc. to enable or disable features.- You should only use the
active_featuresfield to check for features, as they are unique and derived from theactive_plansfield.-
Tip: You can use
entity.hasActiveFeature(<feature_identifier>)in both API and SPA recipes to check if an entity has a specific feature active.
-
- You should only use the
- To react on payment events, there are several workflow events that can be used to hook into.
Additional features to manage plans
Section titled “Additional features to manage plans”- Ability to build an overview that see all active plans via routes / SPA Api helpers
/modules/<module_identifier>/resources/<entity_id>/subscriptionsviaApi.getSubscriptionsForEntity(entity: Entity)/modules/<module_identifier>/subscriptionsviaApi.getSubscriptionsForModule(module: Module)- These endpoints return a structure like this:
[{"id": 1, // Unique identifier for the subscription"user_id": 1, // The ID of the user that bought the plan"type": "ultra", // The identifier of the plan that was bought"stripe_id": "sub_1RiuvmBFAS1bkUxqN0ae5IzV", // The ID of the subscription in Stripe"stripe_status": "active", // The status of the subscription in Stripe"module_id": 2, // The ID of the module if the entity that the subscription is for"resource_id": 1, // The ID of the entity that the subscription is for"stripe_price": "price_1RiXrVBFAS1bkUxqrYZ4fnXt", // The ID of the price in Stripe that was bought"quantity": 1, // Always 1, as we only support single subscriptions for now"trial_ends_at": null, // The date when the trial ends. Always null since we don't support trials via stripe."ends_at": null, // When the subscription ends. Set to the date when the subscription will be deactivated, once the subscription was canceled"next_billing_at": "2026-07-09 10:08:50", // The date when the next payment will be charged. This is the date when the subscription will be renewed."created_at": "2025-07-09T10:08:56.000000Z", // The date when the subscription was created / first activated"updated_at": "2025-07-09T10:08:56.000000Z", // The date when the subscription was last updated"items": [{}] // An array of the `subscription_items` of that subscription. Should always just contain one item. You can get the stripe id (e.g. `prod_xxxxxxx`) of the Stripe product via `items[0].stripe_product`}]
- Ability to manually activate/remove plans to an entity
active_plansis just a textarea withmode = tags. You can add (or remove) another identifier freely, and upon saving, the system will update theactive_featuresfield accordingly.- You can also activate subscriptions via the Stripe dashboard if you indeed want them to be payed for.
- Prerequisites:
- Have customers created in Stripe
- Have at least one working payment method for that customer
- Have the plans and prices your Brezel expects created in Stripe via bakery apply
- How do do it:
- Navigate to
https://dashboard.stripe.com/test/customers/{customer_id} - Click on “Add subscription”
- Choose the right plan and price as product
- The subscription will start immediately, but if you want to bill the user later (e.g. useful when migrating from the old Stripe integration) set the “Ab abrechnen” field accordingly.
- Set the correct metadata. For a minimum you need these fields:
module_identifier: The identifier of the module that the entity is from (e.g.buyable_thingy)resource_id: The ID of the entity that the subscription is for (e.g.1234)plan_identifier: The identifier of the plan that was bought (e.g.pro_monthly)
- Choose the right payment method
- Add a meaningful name (which will be shown in the billing portal) as a description. E.g.
"Pro Plan - Buyable Thingy 1234" - Click on “Create subscription”
- Now Stripe will send a webhook to your Brezel which will act like a normal Subscription activation.
- Afterward you should have the plan with features active on the desired entity, and the user should be able to open the billing portal.
- Navigate to
- Prerequisites:
- Ability to start a Stripe customer billing portal session for a user to manage their subscriptions
- All subscription cancellations / adjustments are handled via the stripe customer portal. A link to which can be generated for the current user via the endpoint
/subscription-portal
- All subscription cancellations / adjustments are handled via the stripe customer portal. A link to which can be generated for the current user via the endpoint