If you are new to payments, think about this system in two parts:
- a checkout link that sends the user to Stripe, LemonSqueezy, or Polar
- a webhook that tells your app “the payment succeeded”
What The Payments System Does
In AnotherWrapper, payments are used for two main things:- selling your product tiers such as Premium, Enterprise, or Agency
- selling credit top-ups such as
credits-smallandcredits-large
- A user clicks a checkout button in your app
- They pay on the provider’s hosted checkout page
- The provider sends a webhook to your app
- Your app verifies the webhook is real
- Your app stores the purchase in the database
- Your app updates the user’s credits or purchase state
Important Basic Terms
Checkout URL
A checkout URL is the payment link your user clicks. Example:Webhook
A webhook is a secure HTTP request sent by your payment provider to your app after something important happens, such as a successful payment. In this repo, all payment providers send webhooks to:- Stripe:
https://yourdomain.com/api/payments/stripe - LemonSqueezy:
https://yourdomain.com/api/payments/lemonsqueezy - Polar:
https://yourdomain.com/api/payments/polar
Purchase Type
A purchase type is the label your app uses internally to know what was bought. The current repo supports:anotherwrapper-premiumanotherwrapper-enterpriseanotherwrapper-agencycredits-smallcredits-large
What You Need Before Starting
Before setting up payments, make sure:- the app already runs locally
- Supabase is set up
- your production domain is known
- you know which provider you want to use first
Shared Env Vars
These env vars are used regardless of provider:What Each Shared Env Var Means
NEXT_PUBLIC_PAYMENT_PROVIDER: which provider the UI should useNEXT_PUBLIC_DEFAULT_MARKETING_PURCHASE_TYPE: which plan the main marketing CTA should representNEXT_PUBLIC_CHECKOUT_URL_TEMPLATE: fallback main checkout URLNEXT_PUBLIC_CHECKOUT_URL_CREDITS_SMALL: checkout link for the small credit packNEXT_PUBLIC_CHECKOUT_URL_CREDITS_LARGE: checkout link for the large credit pack
How The Repo Handles Payments
The main files are:lib/payments/public-config.tsfor shared checkout URLs, labels, prices, and credit-pack metadatacomponents/(ui-components)/payments/checkout-link.tsxfor hosted checkout buttons in the UIapp/api/payments/[provider]/route.tsfor the shared webhook entrypointlib/payments/providers/*for provider-specific verification logiclib/payments/processor.tsfor the shared “payment succeeded” logic
lib/payments/public-config.ts. UI components should not hardcode raw
checkout links.
Metadata vs Product Maps
There are two common ways to tell the app what a payment means.Option A: Metadata
You store a value liketype=anotherwrapper-enterprise in the provider itself.
This is usually the cleanest approach because the purchase explains itself.
Option B: Product Map In Env
You keep a JSON map in env:Credits
If the purchase type iscredits-small or credits-large, the repo can add
credits automatically after the webhook succeeds.
If the purchase is a plan like anotherwrapper-enterprise, the repo stores the
purchase and updates the user’s profile state instead.
Optional Meta Ads Attribution
If you run Meta Ads, the repo can also track:InitiateCheckoutfrom the shared checkout link componentPurchasefrom the shared payment processor after a successful webhook
Suggested Setup Order
For beginners, use this order:- Pick one provider
- Create one simple “Premium” product
- Create one simple “Small credits” product
- Add the checkout URLs to
.env.local - Add the webhook endpoint in the provider dashboard
- Complete a test payment
- Confirm the purchase appears in your database
- Confirm the user gets the right result in the app
Common Mistakes
- using the wrong webhook URL
- forgetting to set the provider-specific secret
- creating checkout links but never connecting the webhook
- not mapping the purchased product to a valid purchase type
- changing
.env.localbut forgetting to restart the app
Provider Guides
Stripe
Best if you want the most common developer payment flow.
LemonSqueezy
Best if you want a simple hosted product + variant workflow.
Polar
Best if you want a clean product-based checkout flow with metadata support.
Meta Ads
See how the repo optionally tracks checkout clicks and purchases for Meta Ads.
Credits And Billing
See how credits are used in the dashboard and across the apps.

