Add Subscription Billing to Next.js

Install the SDK, create one API route, and embed a pricing widget. Ship recurring payments in under 5 minutes with the App Router.

Start Free

Full Integration in 3 Files

# Install

npm install paylio @paylio/react

// app/api/subscription/route.ts

import Paylio from "paylio";

const paylio = new Paylio(process.env.PAYLIO_SECRET_KEY!);

export async function GET(req: Request) {
  const { searchParams } = new URL(req.url);
  const userId = searchParams.get("userId");
  const sub = await paylio.getSubscription(userId!);
  return Response.json(sub);
}

// app/pricing/page.tsx

"use client";
import { PaylioPricingGrid } from "@paylio/react";

export default function PricingPage() {
  return (
    <PaylioPricingGrid
      publishableKey="pk_live_xxx"
      userId="user_123"
    />
  );
}

Integration Steps

1

Install the SDK

Add the Paylio Node.js SDK and React component library to your Next.js project with a single install command.

2

Create an API Route

Add a route handler in your App Router that calls Paylio to check a user&apos;s subscription status server-side.

3

Embed the Pricing Widget

Drop the PaylioPricingGrid component into any page. It renders plans, handles checkout, and manages the full billing flow.

4

Check Entitlements

Use the subscription response to gate features. Check plan status and entitlements before granting access to premium functionality.

FAQ

How do I add subscription billing to a Next.js app?

Install the paylio npm package, create an API route that calls paylio.getSubscription(userId) to check status, and embed the @paylio/react PricingGrid component on your pricing page. The entire integration takes under 5 minutes.

Does Paylio work with the Next.js App Router?

Yes. Paylio works with both the App Router and Pages Router. API routes use the standard route.ts convention, and the React component works in client components with the 'use client' directive.

Can I use Paylio with Next.js Server Components?

The subscription check API works in Server Components since it is a standard fetch call. The PricingGrid widget requires a client component wrapper because it manages interactive checkout state.

How do I handle Paylio webhooks in Next.js?

Create a POST route handler at app/api/webhooks/paylio/route.ts. Paylio sends subscription lifecycle events like created, renewed, and canceled. Verify the signature using the SDK helper and update your database accordingly.

Ship Subscriptions in Your Next.js App Today

Free up to 100 subscribers. No credit card required.

Get Started Free