Adding Stripe to your app: Checkout, webhooks and access
You know the Stripe objects and statuses. Now you wire them into your app: a pricing page that sends the owner to Stripe Checkout, a webhook endpoint that keeps your database in sync, access rules that follow the subscription status, and a link to the customer portal. You do it in Stripe test mode.
The architecture in one picture
Owner clicks "Subscribe" in Bookwise
-> app server creates a Checkout Session (secret key, server side)
-> owner pays on Stripe Checkout
-> Stripe redirects owner back to /billing/success (UX only)
-> Stripe sends webhook events to /webhooks/stripe (the truth)
-> app verifies signature, stores status on subscriptions
-> every request: app checks subscription status -> access or notTwo principles:
- The success page is for the user, the webhook is for the database. A user can close the browser before the redirect, or open the success URL by hand. Never grant access because someone reached the success page.
- Stripe is the source of truth, your database is a cached copy. You store the status so you do not call Stripe on every request, and webhooks keep it current.
Step 1: prepare in Stripe (test mode)
In the Stripe dashboard, in test mode:
- Create the product and prices (from the previous lesson). Note each price id (
price_...). - Configure the customer portal: allow updating payment methods, viewing invoices, switching between your prices and cancelling (at period end).
- Note your test publishable key and test secret key.
You add the webhook endpoint in step 4, once your app has the route.
Step 2: put the keys in the right place
Your app needs at least:
STRIPE_SECRET_KEY(server only)STRIPE_WEBHOOK_SECRET(server only, from step 4)STRIPE_PRICE_MONTHLY,STRIPE_PRICE_YEARLY(not secret, but configuration)- optionally
STRIPE_PUBLISHABLE_KEY(may be used in the browser)
You set environment variables and secrets for an app on my-app.engineer under Apps → App hub → the app's card → Integrations. It finds the variable names your app reads (such as STRIPE_SECRET_KEY), validates and connects the value, stores it in Vault, injects it and restarts the app. Do not paste the secret key into the builder chat, into a Claude conversation or into a file in your repo. If a key ever leaks, roll it immediately in the Stripe dashboard.
Step 3: ask the builder for the billing feature
Send one precise request to the manager chat:
Add Stripe subscription billing for salons (Stripe test mode).
- Read keys and price ids only from environment variables:
STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, STRIPE_PRICE_MONTHLY,
STRIPE_PRICE_YEARLY. Never hard-code keys.
- New salons start a 14-day trial without card (status trialing,
stored on the subscriptions table).
- Billing page (owners only): shows plan, status, trial days left,
next renewal date; buttons "Subscribe monthly", "Subscribe yearly"
(create a Stripe Checkout Session in subscription mode, with the
salon's Stripe customer; create the customer if missing; set
client_reference_id to the salon id) and "Manage billing"
(create a customer portal session and redirect).
- POST /webhooks/stripe: verify the Stripe-Signature header with
STRIPE_WEBHOOK_SECRET using the raw request body; reject invalid
signatures with 400. Store processed event ids and ignore
duplicates. Handle checkout.session.completed,
customer.subscription.created/updated/deleted, invoice.paid,
invoice.payment_failed, customer.subscription.trial_will_end.
Update status, price id and current_period_end on subscriptions.
- Access: trialing and active = full access. past_due = full access
plus a red banner for 7 days after the first failure, then
read-only. canceled, unpaid, incomplete_expired, paused = read-only
dashboard, public booking page shows "Online booking is paused".
- Never grant access from the success redirect alone.After the build, check health and logs (module 2), then open the billing page.
Step 4: register the webhook endpoint
In the Stripe dashboard (test mode), add a webhook endpoint:
- URL:
https://<app>.<your-username>.my-app.engineer/webhooks/stripe(later your own domain); - events: the list from step 3.
Stripe shows a signing secret (whsec_...) for this endpoint. That is your STRIPE_WEBHOOK_SECRET: put it in the app's settings, not in code.
Stripe also offers the Stripe CLI, which can forward events to an app and trigger test events (stripe trigger invoice.payment_failed). It is handy, but you can test everything in this module with Stripe's dashboard and test cards as well.
Step 5: why signature checks and idempotency matter
- Signature check: your webhook URL is public. Without verifying the
Stripe-Signatureheader, anyone could post a fake "subscription active" event and get free access. The check needs the raw request body; frameworks that parse JSON first break it. If signature checks fail for real Stripe events, that is the first thing to look at. - Idempotency: Stripe may send the same event more than once, and events can arrive out of order. Store each processed event id and skip duplicates. When you get a subscription event, it is safest to fetch the current subscription from Stripe and store that, instead of trusting the order of events.
- Respond fast: return a 2xx quickly and do heavy work afterwards; Stripe retries events that time out.
Step 6: review the code with Claude
Use my my-app.engineer workspace. Do not change anything. Review the Stripe integration of [app name]: 1. Is any Stripe secret key or webhook secret hard-coded anywhere in the code or config files? List file and line. 2. Does the webhook endpoint verify the Stripe signature using the raw body? 3. Are duplicate events ignored (stored event ids)? 4. Is access ever granted from the Checkout success redirect instead of the stored status? 5. Does every billing action check that the user is the owner of that salon? Then call get_app_logs for [app name] and tell me if there are webhook errors. Answer as a short checklist with pass/fail.
Step 7: test every path in test mode
| Test | How | Expected |
|---|---|---|
| New subscription | Subscribe with card 4242 4242 4242 4242 | Status active, banner gone |
| Authentication required | Use one of Stripe's 3-D Secure test cards | Checkout asks for authentication, then active |
| Declined card | Use a Stripe decline test card | Stays in trial or incomplete, clear message |
| Failed renewal | In Stripe, use a test clock or a card that fails on renewal, per Stripe's testing docs | past_due, red banner, email |
| Plan switch | Customer portal: monthly to yearly | New price stored |
| Cancel | Customer portal: cancel | Access until period end, then read-only |
| Fake webhook | Send a POST to /webhooks/stripe without signature | 400, nothing changes |
Stripe's testing documentation lists the current test cards and test clocks for simulating time.
Strong customer authentication (SCA, part of the EU's PSD2 rules) applies to most card payments in the European Economic Area and the UK, and Checkout handles it for you. Outside Europe other rules can apply. Check the payment regulations for your country and Stripe's guidance for your region.
Bookwise
The first billing build granted access on the success page. Claude's review (question 4) caught it. One more message to the manager ("Remove access changes from the success route; only webhooks change subscription status") fixed it. The fake-webhook test returned 400 on the first try. Total: three builds and one evening.
Set up your product, prices and portal in test mode, ask the builder for billing in one precise request, register the webhook, run the Claude review and all seven tests. Log the results.
This course is general information, not personal legal, tax or financial advice. Rules, amounts and dates change: check the official source for your country before you act.