Purchase-Gated Permission Workflow

How FlowState locks and unlocks SOP / Checklist features based on ownership and purchased industry bundles.

Step 1

User Generates SOP / Checklist

User picks an industry and generates a document via the AI generator.

Step 2

Is It Their Own Content?

The system checks created_by_id — if the user is the owner, all features unlock immediately.

Step 3

Check Purchased Industries

For others' content, the system queries active Purchase records for industries the user has unlocked.

Step 4

Has Access?

If the document's industry matches a purchased industry → full access (print, edit, export, reorder).

Step 5

Locked Banner Shown

If no matching purchase → buttons are replaced with a 'Locked' state and an amber banner appears.

Step 6

User Clicks 'Unlock Access'

Banner links to the pricing section where the user selects a bundle tier (Starter, Pro, Enterprise).

Step 7

Checkout Session Created

create-checkout backend function creates a Wix checkout session and a Purchase record (status: pending) with the bundle's industries.

Step 8

Payment Confirmed (Webhook)

Wix sends an order_approved webhook → wix-payments-webhook flips the Purchase status to 'active'.

Step 9

Access Granted

usePurchasedIndustries hook now sees the active purchase — print, edit, export, and reorder unlock for that industry.

Plain English Walkthrough

  1. 1

    When someone opens an SOP or Checklist, the app first checks whether they created it. If they did, every feature — print, edit, export, reorder — is available right away, no purchase needed.

  2. 2

    If the content belongs to someone else (e.g. a published template), the app looks up the user's active Purchase records to see which industries they've paid to unlock.

  3. 3

    If the document's industry is in their purchased list, all features unlock. If not, the Print, Edit, Export, and Reorder buttons are hidden and replaced with a 'Locked' button, plus an amber banner explaining the content is locked and offering an 'Unlock Access' link.

  4. 4

    Clicking 'Unlock Access' sends them to the pricing section, where they choose a bundle tier (Starter, Pro, or Enterprise). Each tier maps to specific industries.

  5. 5

    The create-checkout backend function calls Wix Payments to create a checkout session and simultaneously creates a Purchase record in the database with status 'pending' and the bundle's industries stored on it.

  6. 6

    After the user pays on the Wix checkout page, Wix fires an order_approved webhook to the wix-payments-webhook backend function, which finds the matching Purchase by checkout session ID and sets its status to 'active'.

  7. 7

    On the next page load, the usePurchasedIndustries hook fetches all active purchases, sees the newly unlocked industries, and all previously locked features become available.

Frontend Hook

usePurchasedIndustries

Fetches active purchases and exposes the unlocked industries list to any page.

Backend: create-checkout

Creates a Wix checkout session + a pending Purchase record with the bundle's industries.

Backend: wix-payments-webhook

Receives the payment confirmation from Wix and activates the Purchase record.

Entity: Purchase

Stores bundle name, tier, price, industries array, status, and checkout session ID.