# Test Stripe Lifetime Billing (/en/docs/billing/stripe/lifetime/test)

Run this test after changing lifetime pricing, Checkout, billing webhooks, the
billing portal, onboarding email, password setup, or paid-access behavior.

**Give your agent this prompt:**

```text
Test Stripe lifetime billing in the test environment.
Follow https://coremvp.com/en/docs/billing/stripe/lifetime/test.md. Complete https://coremvp.com/en/docs/billing/stripe/lifetime/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:lifetime passes and both buyer cases open Stripe test Checkout and show a saved Stripe purchase.
Report what changed, the check result, and anything you could not run.
```

## Test locally

Complete [lifetime configuration](/en/docs/billing/stripe/lifetime/configure),
including the default customer portal, and keep the app and matching Stripe
listener running. Add guest email capture to ignored `.env.local` and restart the
app:

```dotenv title=".env.local" interactive=true
PAYMENT_PROVIDER=stripe
NEXT_PUBLIC_STRIPE_MODE=test
EMAIL_DELIVERY_MODE=test_capture
TEST_EMAIL_CAPTURE_TOKEN=<private-capture-token>
```

The app and the local runner need the same token. Keep it server and local only:
never print it or put it in browser code or URLs. Capture mode supplies the
guest's setup link without sending Resend email.

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

From your cloned app root, run:

```bash
./coremvp e2e billing:lifetime
```

A passing run exits with code `0` and finishes both buyer cases. The signed-in
case creates its buyer through local signup before payment. The guest case
starts without a session, pays first and completes password setup from its
captured link.

The test checks that:

* the configured lifetime offer opens Stripe-hosted test Checkout;
* both payments return to the app and their signed callbacks store access;
* the fresh guest sets a password and reaches the authenticated app;
* the account readers report the approved lifetime Price and purchase date;
* Billing and its owned Stripe portal reflect the buyer's purchase;
* protected HTML and Markdown allow the buyer, then deny access after signout.

| Symptom                                     | Check                                                                                                                         |
| ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| The test stops before Checkout              | Recheck Stripe test mode, the approved Price mapping and any supplied Product mapping.                                        |
| Payment succeeds but access does not change | Inspect the forwarded `checkout.session.completed` response.                                                                  |
| Guest setup cannot retrieve its link        | Check that the app and runner share the capture mode and token, then restart the app. Do not substitute another buyer's link. |

## Test in production

Production tests still use **Stripe test mode**; no live charge is made. Target
the exact deployment. First put the deployed app's test Price ID in your
ignored `.env` as `NEXT_PUBLIC_STRIPE_INDIVIDUAL_PRICE_ID`, with the other
values in [Prepare the local runner](/en/docs/deployment/deploy-app#prepare-the-local-runner). The test compares the purchase with that value from your shell. The deployed app must use the same Stripe test catalog and webhook destination you are testing. Set up hosted email capture through [Production Email](/en/docs/deployment/email), with the same `TEST_EMAIL_CAPTURE_TOKEN` in the deployed environment and your ignored local `.env`.

Load `.env` first, then run:

```bash interactive=true
set -a; source .env; set +a
export TEST_BASE_URL=https://<app-domain>
./coremvp prod e2e billing:lifetime
```

Expect `result production E2E passed` and your target URL.

_Video: The lifetime billing check in a browser, sped up: it buys with Stripe's test card, sets a password, opens the dashboard and then the paid content (/docs/deployment/test-billing.mp4)._

One passing `./coremvp prod e2e billing:lifetime` run against the Next.js
template on Vercel, shown at 2.5× speed. The guest pays with Stripe's test
card, sets a password, opens the dashboard and then the paid content. The test
account's email and name are hidden.

For the target, required state and coverage, see
[Deploy and Test Your App](/en/docs/deployment/deploy-app#test-production).

## What the test does not cover

* A live-mode Stripe charge.
* Real Resend inbox delivery. Check it after configuring
  `EMAIL_DELIVERY_MODE=real`.
* Production DNS or domain configuration.
* Subscription billing.

## What's next

- [Stripe Guest Checkout and Access](/en/docs/billing/stripe/lifetime/guest-checkout): See how a guest purchase leads to account setup and lifetime access.

- [Configure Stripe Webhooks](/en/docs/billing/stripe/webhooks): Check webhook delivery, saved billing state and retry behavior.

- [Email](/en/docs/email): Verify the onboarding messages triggered by lifetime checkout.
