CoreMVP

Test Stripe Subscription Billing

View as Markdown

Run this test after changing recurring products, Checkout, webhooks, the customer portal or subscription access.

Give your agent this prompt
Test Stripe subscription billing in the test environment.
Follow https://coremvp.com/en/docs/billing/stripe/subscription/test.md. Complete https://coremvp.com/en/docs/billing/stripe/subscription/configure.md first. Ask me before changing provider settings or secrets; do not use live payments or print secrets.
Remove any conflicting BILLING_DEMO_PROVIDER override from the runner. Finish when ./coremvp e2e billing:subscription passes and both monthly and yearly cases complete in Stripe test Checkout with Stripe subscription state saved.
Report what changed, the check result, and anything you could not run.

What the test does

The local test runs monthly and yearly cases; the hosted test runs monthly only. Each case:

  1. signs up a new buyer;
  2. subscribes through Stripe-hosted Checkout with Stripe's test card;
  3. waits for the signed webhook and checks the stored Price through /api/user/status and /api/user/subscription, then checks the Active label and Manage Billing button on /dashboard/billing;
  4. opens a real Stripe test-mode customer portal session;
  5. opens paid content, then checks access is gone after signing out.

Run it locally

Complete Connect Stripe, including the customer portal step. Keep the app and the filtered listener running, with the listener's signing secret in ignored , and map both Pro Prices from the same test account:

.env.local
PAYMENT_PROVIDER=stripe
NEXT_PUBLIC_STRIPE_MODE=test
NEXT_PUBLIC_STRIPE_PRO_PRICE_ID_MONTHLY=price_replace_me
NEXT_PUBLIC_STRIPE_PRO_PRICE_ID_YEARLY=price_replace_me

Remove any conflicting BILLING_DEMO_PROVIDER from the runner environment. It takes precedence over PAYMENT_PROVIDER in the checkout tests.

From the repository root, run:

./coremvp e2e billing:subscription

A passing run exits with code 0 after both Stripe monthly and yearly cases. Check that both used Stripe test Checkout and saved a Stripe subscription. To sell only one billing period, leave the other Price unmapped; that offer stays unavailable. Local signup skips the confirmation email; see Auth testing for that.

Run it against your deployment

The deployed app stays in Stripe test mode; no real charge is made.

  1. Activate the customer portal in test mode.

  2. In your ignored , add the deployment's NEXT_PUBLIC_SUPABASE_URL, its matching SUPABASE_SECRET_KEY and its monthly test Price as the following variable. Never print them, and stop if they belong to another Supabase project.

    NEXT_PUBLIC_STRIPE_PRO_PRICE_ID_MONTHLY

    Prepare the local runner lists every value.

  3. Load and run the test against the exact deployed URL:

set -a; source .env; set +a
export TEST_BASE_URL=https://<app-domain>
export PROD_E2E_AUTH_MODE=signup
./coremvp prod e2e billing:subscription

The clip is one passing hosted run on Vercel, at 2.5× speed, with the test account's email hidden.

A passing run prints result production E2E passed and your target URL. For the required deployment state, see Deploy and Test Your App.

If the test fails

SymptomCheck
Checkout cannot startConfirm NEXT_PUBLIC_STRIPE_MODE=test and the recurring Price inputs, then restart the app.
Checkout asks for sign-inSign in first; recurring Checkout is not a guest checkout path.
Webhook requests return 400Copy the active listener signing secret into ignored , then restart bun run dev.
Local catalog is emptyConfirm the filtered listener was running before the fixture created products and prices.
Portal cannot openConfirm authentication and an owned Stripe management target in account status.
Success page appears but access is missingCheck webhook delivery for the actual purchase first.

For Stripe products or catalog sync, return to Configure Stripe Subscription Billing.

Check later subscription states

The test covers the first active subscription. Check renewals, failed payments and cancellations by hand in Stripe test mode, with the app and listener running. Find the test buyer's customer and subscription first:

stripe customers list --email <buyer-email> --limit 1
stripe subscriptions list --customer <customer-id> --limit 1

Run the commands for one state, then reload /dashboard/billing.

StateExpect on /dashboard/billing
Renewal succeedsThe period moves forward and access stays.
Payment enters retriesCheck the status after the webhook arrives; access follows the stored status.
Customer schedules cancellationThe period end shows, and access stays until then.
Subscription endsThe status is final and access is removed if the buyer has no other eligible subscription or lifetime purchase.
Plan changesThe new Price and period show after the webhook arrives.

Renewal succeeds:

stripe subscriptions update <subscription-id> -d billing_cycle_anchor=now -d proration_behavior=none

Payment enters retries: attach Stripe's failing test card, set the returned payment method on the subscription, then run the renewal command again.

stripe payment_methods attach pm_card_chargeCustomerFail --customer <customer-id>
stripe subscriptions update <subscription-id> -d default_payment_method=<payment-method-id>

Customer schedules cancellation: choose Cancel in the customer portal, or run:

stripe subscriptions update <subscription-id> -d cancel_at_period_end=true

Subscription ends:

stripe subscriptions cancel <subscription-id>

Plan changes: switch plans in the customer portal, if you turned on plan switching.

For how invoice.paid and invoice.payment_failed affect access, see Stripe Subscription Lifecycle and Access.

What's next

Was this page helpful?

On this page