Skip to main content
This example covers the whole path in a Next.js App Router app: the route behind your checkout link, the payment webhook, and a feature check. It works with any payment provider. The three functions marked as yours (createProviderCheckout, verifyProviderWebhook and the db calls) are where your provider’s SDK and your database go. Set the checkout link in Integration > Payment to https://yourapp.com/api/checkout.

Cuprice helpers

Create lib/cuprice.ts. Both helpers ask Cuprice for the price and features on the server, so nothing from the query string is trusted.

Checkout route

Create app/api/checkout/route.ts. This is the address Cuprice sends buyers to.
Free plans arrive with is_free=true and an amount of 0. Most apps skip the provider for them and create the account straight away.

Payment webhook

Create app/api/payments/webhook/route.ts. Your provider calls it when a payment succeeds.
The features were saved when the buyer started checkout, so a plan you edit or hide in Cuprice afterwards does not change what this customer gets.

Feature check

Create lib/entitlements.ts and use it in server components and API routes:

Report the subscription to Cuprice (optional)

To see the customer in your Cuprice dashboard, add this to the webhook after the customer update. It needs an API key with read_write permission and works for regular plans only:
See Report Subscription Event for the other event types.