Subscription Billing With Stripe, From Where Users Sign In

·4 min read

billingstripesubscriptionsentitlements

Most apps that charge for plans end up writing the same code: create products in Stripe, handle Stripe's webhooks, store each customer's subscription, and then check that subscription before every paid feature.

AuthAction now does that part for you. You define plans with prices, features and limits. Your users pay through Stripe Checkout. Your app asks AuthAction what the signed-in user, or their organization, may use.

How it works

  1. Connect Stripe. Paste a Stripe restricted key under Billing in the dashboard. Payments go straight to your own Stripe account, and AuthAction never holds the money.
  2. Price your plans. Give each plan a key (pro), its features (export_pdf), its limits (projects: 50) and its prices. AuthAction creates the products and prices in Stripe.
  3. Send users to checkout. From your app, with the web SDK or one API call. Or link to the hosted pricing page if you have none of your own.
  4. Read entitlements. Your app calls GET /billing/entitlements with the user's access token and gets the plan, features and limits in force now.

Connect your Stripe account

In Stripe, create a restricted key with the permissions listed in the connect Stripe guide. Start with a test mode key (rk_test_...) and switch to the live key when you're ready to take payments.

Paste it under Billing > Stripe and choose Connect Stripe. AuthAction creates a product and prices in Stripe for every priced plan and sets up the Customer Portal, so subscriptions stay in sync without any code on your side.

Price your plans

Plans live under Monetization > Plans. Each one has a key your app compares against, features, whole-number limits, and prices, with an optional free trial:

curl -X POST https://<tenant-domain>/api/v1/plans \
  -H "Authorization: Bearer $MANAGEMENT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Pro",
    "description": "For growing teams",
    "key": "pro",
    "isPublic": true,
    "features": [{ "key": "export_pdf", "name": "Export to PDF" }],
    "limits": { "projects": 50 },
    "prices": [
      { "interval": "month", "amount": 1900, "currency": "usd" },
      { "interval": "year", "amount": 19000, "currency": "usd" }
    ],
    "trialDays": 14
  }'

A plan without prices is free and needs nothing in Stripe. A typical setup is a free plan marked Default and one or more paid plans marked public. When you change a price, existing subscribers keep paying the old one until they change plan, and new checkouts use the new one.

Send users to checkout

With the web SDK, one call creates a Stripe Checkout session and redirects:

await client.redirectToCheckout({ planKey: "pro", interval: "year" });

Subscribers manage their plan in the Stripe Customer Portal, where they can switch between your public plans, update their card, download invoices and cancel at the end of the period. If your app has no pricing page of its own, client.redirectToPricingPage() sends users to a hosted one in your tenant's branding and language.

Check what a user may use

In the browser, the React hook reads the signed-in user's entitlements:

import { useEntitlements } from '@authaction/web-sdk/react';

function Export() {
  const { hasFeature, entitlements, isLoading } = useEntitlements();
  if (isLoading) return null;
  if (!hasFeature('export_pdf')) return <UpgradeButton />;
  return <ExportButton limit={entitlements?.limits.exports} />;
}

Showing or hiding a button is not enforcement, so check again on your server before doing paid work. The Node SDK has middleware for that:

app.post(
  "/api/export",
  requireAuth(verifier),
  requireFeature(entitlements, "export_pdf"),
  exportHandler
);

In other languages, send the same GET /billing/entitlements request with the user's access token. The answer includes the plan, its features and limits, and the subscription behind them, so you can show a renewal date or "ends on" when a subscription is set to cancel. Upgrades and cancellations show up without a new sign-in.

Where a plan comes from

Each user and organization has one plan in force. A paid subscription comes first, then a plan an admin assigned, then the plan marked Default. When a subscription ends, the user falls back to their assigned or default plan.

Billing organizations

For B2B apps, an organization can subscribe instead of a user, and every member gets the organization's plan. Under Billing > Organizations, choose the roles, such as billing-admin, whose holders may buy or manage an organization's subscription. An access token from an organization login reads that organization's entitlements without any extra parameter.

When your server needs to act

You don't need events to use subscriptions, because entitlements are always current. For work your server does when something changes, such as provisioning a workspace or sending a welcome email, set a URL under Billing > Webhooks. AuthAction sends a signed subscription.updated event with the subscriber's new entitlements whenever a subscription starts, renews, changes plan, is set to cancel, or ends.

Trying it with AuthAction

Subscriptions and entitlements are included on AuthAction's free plan, like every other feature. Payments go to your own Stripe account. Connect a test mode key, create a free default plan and a paid one, and try a checkout.

The subscriptions docs walk through each step, from connecting Stripe to entitlements and subscription events. Plans has an overview.


Subscriptions and entitlements, free and unlimited

Plans with features, limits and prices, Stripe Checkout and Customer Portal, a hosted pricing page, and an entitlements endpoint for your app and your API.

Free, unlimited users. No credit card required.