Skip to content

Subscription implementation history 1

This is the historical implementation checklist, not a statement of current feature availability. For registered events and capabilities use the generated reference.

  • Writeup concepts of a plan
  • Remove old license and subscription code
    • brezel/api
    • brezel/spa
  • Enable Capabilities to take options
    • Enable Capabilities to require even existing fields (rules required, not just that the field exists at all)
  • Implement Capabilities
    • Billable
      • Required fields
    • Buyable
      • Required fields
        • active_features
        • active_plans
      • Pass an entity and set all active plans and features
  • Integrate Laravel Cashier
    • Handle webhooks
    • Handle product / price creation via bakery planner from the capability
      • create products and prices fresh
      • handle existing products / prices
        • products are looked up by metadata key and updated if changed
        • prices are looked up by lookup_key and if changed, old one is archived and new one is created only when changed
        • if prices are removed (i.e. present on the product but NOT defined by us), archive them. But only if they came from us in the first place (i.e. metadata key managed_by_brezel is set`)
    • build subscription route
    • build subscription manager (customer portal) route
    • handle taxes
    • sync customer data to stripe on Billable user update
    • Make the title (brezel_name) of the bought entity viewable in the billing dashboard to identify what subscription is for which entity (i.e. description of the subscription)
    • ensure stripe has a customer portal set up because we lean heavily on it for subscription management
    • Build an endpoint to get subscription date and remaining time for a plan of an entity
      • Store relation to module and entity in the Subscription table
      • Store date of next payment in the Subscription table
      • Build relation between Subscription and Entity, to get all Subscriptions for an Entity
      • Build route to get all Subscriptions for an Entity
        • /modules/<module_identifier>/resources/<entity_id>/subscriptions
      • Build route to get all Subscriptions for a Module
        • /modules/<module_identifier>/subscriptions
    • Add additional metadata key module_id alongside the module_identifier metadata
      • Refactor all the matching logic to use the module_id instead of the module_identifier metadata key. Just for robustness reasons, works with the identifier as well, but this would be more robust to e.g. survive module renames.
    • Allow for plan changes in subscription.update event handler
      • That way, if the billing portal is configured in a way to change plans instead of just cancelling, the system will handle that correctly.
  • Create endpoint to list all available plans with prices for a module
  • Automatically create stripe webhook for the current system if needed
  • Configure stripe automatic emails
  • Throw and build workflow events
    • event/subscriptionActivated: Fires when a plan was activated for an entity of the specified module.
      • Triggered whenever a plan was activated for an entity.
        • Triggered directly by stripe subscription.created webhook
        • Triggered when a plan was manually activated on an entity
    • event/subscriptionDeactivated: Fires when a plan was deactivated (e.g. when a subscription runs out) for an entity of the specified module.
      • Triggered directly by stripe subscription.deleted webhook
      • Triggered when a plan was manually deactivated on an entity
    • event/subscriptionPaymentFailed: Fires when a payment for a plan failed for an entity of the specified module.
      • Triggered directly by stripe invoice.payment_failed webhook
        • You probably should not really react to this, as a properly configured stripe will send an email to the user and the user can react to it. This might just be helpful for internal statistics or marking the entity as “payment failed” in the system.
    • event/subscriptionFeaturesChanged: Fires when the active_features field on an entity of the specified module was updated.
      • Triggered if something changed in the active_features field of an entity.
        • On subscription activated / deactivated
        • On manual active_plans change
        • When configured features of a plan change
    • event/subscriptionInvoicePaid: Fires when a subscription invoice was paid.
      • Triggered directly by stripe invoice.payment_succeeded webhook
        • Contains the Entity and the Plan and Price details the invoice was paid with (i.e. price config)
  • Extend event/webhook with feature flag filtering
    • i.e. only allow the event if the entity it was triggered for has the required feature flag active.

Subscription plans.