---
name: payment-check
description: Checks whether someone could get the paid part of an app without paying. Looks at how upgrades, plans, subscriptions and credits are switched on, where prices come from, whether payment webhooks are verified, and whether users can edit their own paid status in the database. Use when the user asks whether people can get Pro or premium for free, whether their Stripe (or Paddle, Lemon Squeezy, PayPal, Polar, RevenueCat) checkout or payments are set up correctly, whether a success page or webhook can be faked, or wants a payments check before launch. Explains each problem in plain language, with a prompt to paste into an AI builder such as Lovable, Bolt or Replit and the code to paste.
allowed-tools: Read Grep Glob
license: MIT
---

# Payment check

Read the project's code and report every way someone could get the paid part of the app without paying. Change nothing.

## Rules

- **Read only.** Use Read, Grep and Glob. Do not edit or create files and do not run commands. Give each fix as code or SQL the user can paste; do not apply it.
- **Report only what gives paid access away or lets someone pay less.** A leaked secret key, a slow page or untidy code is not this check's job. Put anything outside the scope under "Not checked" in one line.
- **Do not flag what is meant to be public or is already right.** Listing safe things as problems teaches the user to ignore the report. Name them under "Looks right" so the user can see they were checked.
- Write for someone who is not an engineer. Say "anyone who opens the browser's developer tools" or "anyone on the internet", not "the client" or "the anon role" on their own. Explain a term the first time you use it.
- Do not use the words "safe" or "secure" anywhere in the reply, about the app, the payments or any part of them ("this stays safe" included). Say what you checked, what you found and what you did not check.

## Background you need

Anything that runs in the visitor's browser can be changed by the visitor. They can edit the page's code, send their own requests with the app's public key, and visit any address, including the "payment successful" page. So the browser can never be the thing that decides someone has paid.

The only trustworthy proof of payment is a message from the payment provider to the app's **server** (a webhook), whose **signature** the server checks with a signing secret only the provider and the server know. Without that check, anyone who finds the webhook's address can send a fake "payment succeeded" message. A server can also ask the provider directly (for Stripe, `stripe.checkout.sessions.retrieve(id)` and read `payment_status`); that is also fine.

Where things run, in apps built with Lovable, Bolt, Replit or similar:

- **Browser**: `src/`, `app/` or `pages/` components, `public/`, anything in a Vite or plain React project that is not a server function.
- **Server**: `supabase/functions/`, `api/`, `server/`, `functions/`, `netlify/functions/`, Next.js `app/**/route.ts`, `pages/api/`, server actions (`"use server"`), and database functions and policies in SQL.

What is meant to be public and must not be reported:

- **Stripe publishable key** (`pk_live_…`, `pk_test_…`), Paddle client-side token, Lemon Squeezy store ID, PayPal client ID, Supabase URL and anon or publishable key. They are designed for the browser.
- **A success or thank-you page** that only says thank you, or re-reads the user's status from the database or asks a server function to confirm. Only a success page that itself switches access on is a problem.
- **Hiding a paid button or page in the browser**, as long as the server function or database rule behind it also checks. Hiding is a convenience; the server check is the lock. If the server does not check, that is the problem to report, at the server.
- **A webhook function with sign-in checks turned off** (in Supabase, `verify_jwt = false` in `supabase/config.toml`). Payment providers cannot sign in, so this is required. The signature check replaces it.
- **A server function or verified webhook writing with the Supabase service-role key** (or another admin key). This is how paid status should be written. Whether the key itself has leaked is a different check.
- **A database function marked `security definer`** that changes credits or plans, when `execute` on it is revoked from `public`, `anon` and `authenticated` and granted only to `service_role`.
- **A plan list with prices in the browser** used only to show labels, when the server ignores any amount the browser sends.

## Step 1: Find the payment code

Grep the whole project (case-insensitive) for:

- Providers: `stripe`, `paddle`, `lemonsqueezy`, `lemon_squeezy`, `paypal`, `polar`, `revenuecat`, `purchases`, `dodo`, `gumroad`, `checkout`, `webhook`.
- Paid status: `is_pro`, `isPro`, `is_premium`, `premium`, `is_paid`, `paid`, `plan`, `tier`, `subscription`, `subscribed`, `credits`, `balance`, `tokens_remaining`, `entitlement`, `lifetime`.
- Success pages: `success`, `thank`, `session_id`, `payment_intent`, `redirect_status`.

Then Glob for `supabase/migrations/**/*.sql` and other `**/*.sql`, and read `supabase/config.toml` if it exists.

Read every file that creates a checkout, receives a webhook, shows a success page, writes a paid field, or serves a paid feature. Read whole files, not only the matching lines. If the project has no payment code at all, say so in one line and stop.

## Step 2: Check each place

Report as a **problem** each place that matches one of these types (the letters are for this list only; number the problems in your reply 1, 2, 3 in the order you report them):

- **A. The browser switches on paid access.** Browser code writes a paid field (`is_pro`, `plan`, `credits`, `subscription_status` and the like) to the database, for example `supabase.from("profiles").update({ is_pro: true })` on a success page. Also: a paid flag kept in `localStorage`, `sessionStorage` or a cookie the browser sets and the app trusts; access granted because the address contains `?success=true`, `session_id=…` or `redirect_status=succeeded`, without a server asking the provider. Anyone can open that page or run that line themselves.
- **B. The price or amount comes from the browser.** A server function builds the checkout from a number the browser sent: `unit_amount`, `amount`, `price`, `quantity` of credits, `currency`, a discount, or a Stripe `price` ID passed through without checking it against a list on the server. Anyone can send `amount: 1`. The browser should send only a plan or pack name, and the server should look up the price ID or amount itself.
- **C. The webhook does not check the signature.** The webhook handler reads the event with `req.json()`, `JSON.parse(body)` or similar and acts on it without verifying it. Verification looks like `stripe.webhooks.constructEvent` or `constructEventAsync` with the signing secret (`whsec_…`, from the environment), Paddle's `webhooks.unmarshal`, a Lemon Squeezy HMAC-SHA256 check of `X-Signature`, Standard Webhooks headers (`webhook-signature`, used by Polar and Dodo), PayPal's `verify-webhook-signature` call, or a RevenueCat `Authorization` header compared with a secret. Also a problem: the check is there but its failure is caught and ignored, or it runs on a body that has already been parsed and re-serialised (Stripe needs the raw text, `await req.text()`), or the secret has a hard-coded fallback such as `?? "test"`. Check **every** webhook function: an app often has more than one.
- **D. Access is granted before payment is confirmed.** The handler grants access on an event that does not mean "paid", or without checking the paid status inside it. For Stripe:
   - `checkout.session.completed` without checking `payment_status === "paid"`. Bank debits and other delayed methods (for example SEPA Direct Debit, ACH Direct Debit, Bacs Direct Debit and Boleto) finish checkout while `payment_status` is still `"unpaid"`, and the payment can still fail. Paid access for these should come from `checkout.session.async_payment_succeeded`. This is a problem whenever the code does not check, and worse if the checkout lists a delayed method in `payment_method_types`.
   - `payment_intent.created`, `invoice.created`, `invoice.finalized`, `customer.subscription.created` with no status check, or `charge.pending`: none of these mean money arrived.
   - Fine: `checkout.session.completed` with `payment_status` checked, `checkout.session.async_payment_succeeded`, `invoice.paid`, `invoice.payment_succeeded`, `payment_intent.succeeded`, and subscription events whose `status` is checked to be `active` or `trialing` (a trial is free on purpose).
   - Other providers: Paddle `transaction.completed` or `transaction.paid` and `subscription.activated`; Lemon Squeezy `order_created` with `status` `paid`, `subscription_payment_success`; PayPal `PAYMENT.CAPTURE.COMPLETED`, not `CHECKOUT.ORDER.APPROVED` alone (approved is not captured). A PayPal button whose `onApprove` captures the order in the browser and then switches on access from the browser is type A.
- **E. A user can edit their own paid status in the database.** In the SQL, a table that holds a paid field (`is_pro`, `plan`, `credits` and so on) has an `update` (or `all`) policy for signed-in users that compares only the owner, such as `using ((select auth.uid()) = id)`, and nothing stops them changing the paid columns.
   Supabase lets signed-in users update every column by default, so a correct-looking owner policy still lets anyone set `is_pro = true` on their own row from the browser console.
   It is fixed when update on those columns is revoked (`revoke update … from authenticated` then `grant update (<only the harmless columns>)`), when a trigger rejects changes to them, or when paid status lives in a separate table that signed-in users can only read.
   Also a problem: an `insert` policy that lets a user create their own row with any `is_pro` or `credits` value, RLS off on such a table, and a `security definer` function that adds credits or sets a plan and that signed-in users can still call. Read the migrations oldest first; a later one can fix an earlier one.
- **F. A paid feature is locked only in the browser.** A server function or database rule that serves the paid thing (an export, an AI call, a premium table) does not check the user's paid status itself. Report it at the server file.

Put under **"Worth tightening"**, not under Problems (they matter, but they do not give paid access to someone who has not paid):

- The webhook does not ignore an event it has already handled (Stripe can send the same event more than once), so credits could be added twice.
- No handling of refunds, disputes or chargebacks (`charge.refunded`, `charge.dispute.created`), so access stays after the money goes back.
- Cancellation or failed renewal does not remove access (no `customer.subscription.deleted` or `updated` handling). Only mention this if the app sells subscriptions and you looked for it and it is missing.

## Output

Reply with this and nothing before it.

````
Payment check: <N> problem(s) found

## Problems

1. <what is wrong, in one plain sentence>
   Where: `<file>:<line>`
   How someone gets it free: <the steps a visitor would take, in plain words>
   Paste this to your builder: "<one plain-words instruction for Lovable, Bolt or Replit that makes the same fix as the code below>"
   Fix (if you edit the code yourself):
   ```<language>
   <code or SQL to paste>
   ```

## Worth tightening

- <one line each, with file>

## Looks right

- <each safe thing you checked, one line each: the publishable key, a thank-you page that only re-reads status, prices looked up on the server, verified webhooks, service-role writes from a verified webhook, server checks behind hidden buttons>

## Not checked

- <see below>
````

- Order problems by damage: anyone can switch on paid access for free (types A, C, E), then paying less (B), then paying with money that never arrives (D), then the rest.
- One numbered problem per place and fault. If one file has two faults, give two entries.
- Write the headline last: `<N>` is the number of numbered entries under Problems. Count them. When one problem refers to another, use the number it has in this reply.
- Every problem gets a **builder prompt** on the "Paste this to your builder:" line, because most readers change their app by asking an AI builder, not by editing code. It is one sentence or two, in plain words, in quotation marks. It must:
  - describe the same fix as the code below it, not a different or partial one;
  - name the file, function, page or table to change (for example "in the `subscription-webhook` function" or "in a new database migration for the `profiles` table");
  - say what must stay working (for example "users must still be able to change their display name and avatar");
  - never ask the builder to switch anything off, remove a check, turn off row-level security or "make it work" by opening access. Ask for a lock or a check to be added, or for a write to be moved to the server.
- Fixes must be complete enough to paste, written for the project's real file, field and table names. If a snippet replaces a block of code, it must keep the parts of that block that were already right; say exactly which lines it replaces. Otherwise give the whole file.
  - Type A: replace the write with a thank-you page that re-reads status (or polls a few times), and say where the write belongs (the verified webhook).
  - Type B: a server-side map from plan name to price ID (`line_items: [{ price: PRICES[plan], quantity: 1 }]`), rejecting unknown names.
  - Type C: the full verification code for the provider, reading the raw body and the secret from the environment, returning 400 on failure. Remind the user to add the signing secret in the provider dashboard and the server's secrets.
  - Type D: the paid-status check and, for Stripe, an `async_payment_succeeded` branch.
  - Type E: SQL for a new migration, for example `revoke update on public.<table> from anon, authenticated;` then `grant update (<harmless columns>) on public.<table> to authenticated;`. List the harmless columns from the table definition and from what the app's own pages update, so the app keeps working.
  - Type F: the server-side check to add before the paid work starts.
- If there are no problems, write `Payment check: 0 problems found`, write "None." under Problems, and keep the other sections. Do not invent a problem.

## Not checked

Always include these lines, adjusted to the project:

- The live setup. This check read the code only. Database policies changed by hand in the dashboard, webhook endpoints and the events they are subscribed to, and secrets set in the provider and hosting dashboards were not seen.
- Whether the webhook signing secret is actually set on the server, and whether the price IDs in the code match real prices in the provider's dashboard.
- Secret keys left in the code or in git (Stripe secret key, service-role key). Use a secrets check such as `pre-launch-secrets-sweep` for that.
- Who can read or change other tables. Only tables holding paid status were checked; use a database check such as `supabase-rls-review` for the rest.
- Coupons, promotion codes and free trials set up in the provider's dashboard, and any payments taken outside this code (payment links, mobile app stores).

<!--
MIT License

Copyright (c) 2026 PT Maverick Rintis Karya

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
