McTaba Labs logo
Software EngineeringThe WhiteboardProjectsEventsMasterclassesWebinarsLearn
Book Call

500+ developers already in the community

Get answers, find accountability partners, and stay ahead

Join Discord →
McTaba Labs logo

Educating 1 million students in tech by 2030.

Programs

  • HighSchool Graduates Launchpad
  • AI & Business Automation
  • Corporate Training
  • McTaba Story & Mission
  • Full-Stack Curriculum
  • Course Pricing & Plans
  • Frequently Asked Questions

Resources

  • Join Discord Community
  • Tech Events in Nairobi
  • Masterclasses
  • Free Resources
  • Learn
  • Campus
  • Africa Tech Talent Report
  • Partner With Us
  • Start a Project
  • Our Work

Contact Us

  • 124 Manyani East Road, Lavington, Nairobi
  • +254727795603
  • Book a Discovery Call

Office Hours:

Mon-Fri: 9am - 2pm EAT

Sat: 10am - 12pm EAT

© 2027 McTaba Labs - A product of Edtech Industries. All rights reserved.

Privacy PolicyTerms of ServiceRefund Policy
  1. Learn
  2. Paystack for African Developers
  3. Build Paystack Subscriptions in Nuxt
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 22, 2026

Build Paystack Subscriptions in Nuxt

To build Paystack subscriptions in Nuxt, create plans via a server route using the Plans API. Initialize transactions with the plan code so Paystack handles recurring billing. Listen for subscription webhooks (subscription.create, invoice.payment_failed, subscription.disable) in a server route. Display subscription status in your Vue pages by fetching from your own API.

In this article

  1. 1. How Paystack Subscriptions Work with Nuxt
  2. 2. Create Plans via Server Route
  3. 3. Subscription Checkout Page
  4. 4. Subscribe Server Route
  5. 5. Handle Subscription Webhooks
  6. 6. Display and Manage Subscriptions
  7. 7. Ship Payments Faster

How Paystack Subscriptions Work with Nuxt

Paystack subscriptions are built on plans. A plan defines the amount, billing interval, and currency. When a customer completes a transaction that includes a plan code, Paystack creates a subscription and charges the customer automatically on the next billing date.

In Nuxt, the full flow runs in a single project:

  1. Server route: Creates plans (one-time setup) and stores plan codes in your database.
  2. Server route: Returns available plans to the frontend.
  3. Page component: Displays plans and opens the Paystack checkout popup with the selected plan.
  4. Server route: Initializes the transaction with the plan code.
  5. Paystack: Processes the first charge and creates the subscription.
  6. Server route: Receives subscription webhooks and updates the database.
  7. Page component: Displays the subscription status from your database.

Create Plans via Server Route

// server/api/plans/create.post.ts
export default defineEventHandler(async (event) => {
  var config = useRuntimeConfig();
  var body = await readBody(event);

  var response = await fetch('https://api.paystack.co/plan', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + config.paystackSecretKey,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      name: body.name,
      amount: body.amount,
      interval: body.interval,
      currency: body.currency || 'NGN',
    }),
  });

  var data = await response.json();

  if (!data.status) {
    throw createError({ statusCode: 400, message: data.message });
  }

  // Save to database
  // await db.plans.insertOne({
  //   plan_code: data.data.plan_code,
  //   name: data.data.name,
  //   amount: data.data.amount,
  //   interval: data.data.interval,
  // });

  return {
    plan_code: data.data.plan_code,
    name: data.data.name,
    amount: data.data.amount,
    interval: data.data.interval,
  };
});

You typically create plans once during setup. After that, your pages fetch the list of available plans from your database through a GET server route.

// server/api/plans/index.get.ts
export default defineEventHandler(async (event) => {
  // Fetch plans from your database
  // var plans = await db.plans.find({ active: true }).toArray();
  var plans = [
    { plan_code: 'PLN_basic123', name: 'Basic', amount: 500000, interval: 'monthly' },
    { plan_code: 'PLN_pro456', name: 'Pro', amount: 1500000, interval: 'monthly' },
  ];

  return { plans: plans };
});

Get weekly developer tips

Join 25,000+ developers. Practical guides, job tips, and new content — straight to your inbox.

No spam. Unsubscribe anytime.

Subscription Checkout Page

<!-- pages/pricing.vue -->
<script setup>
useHead({
  script: [{ src: 'https://js.paystack.co/v2/inline.js', defer: true }],
});

var { data: plansData } = await useFetch('/api/plans');
var email = ref('');
var loading = ref(false);

async function subscribe(planCode) {
  if (!email.value) return;
  loading.value = true;

  try {
    var data = await $fetch('/api/subscribe', {
      method: 'POST',
      body: { email: email.value, plan_code: planCode },
    });

    var popup = new window.PaystackPop();
    popup.checkout({
      accessCode: data.access_code,
      onSuccess: async function(transaction) {
        await $fetch('/api/verify', {
          params: { reference: transaction.reference },
        });
        navigateTo('/dashboard');
        loading.value = false;
      },
      onCancel: function() {
        loading.value = false;
      },
    });
  } catch (err) {
    alert('Failed to start checkout');
    loading.value = false;
  }
}
</script>

<template>
  <div>
    <h1>Choose a Plan</h1>
    <input v-model="email" type="email" placeholder="Email" />
    <div v-for="plan in plansData?.plans" :key="plan.plan_code">
      <h3>{{ plan.name }}</h3>
      <p>NGN {{ (plan.amount / 100).toLocaleString() }} / {{ plan.interval }}</p>
      <button @click="subscribe(plan.plan_code)" :disabled="loading || !email">
        Subscribe
      </button>
    </div>
  </div>
</template>

Subscribe Server Route

// server/api/subscribe.post.ts
export default defineEventHandler(async (event) => {
  var config = useRuntimeConfig();
  var body = await readBody(event);

  var response = await fetch('https://api.paystack.co/transaction/initialize', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + config.paystackSecretKey,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      email: body.email,
      plan: body.plan_code,
      // amount is pulled from the plan automatically
    }),
  });

  var data = await response.json();

  if (!data.status) {
    throw createError({ statusCode: 400, message: data.message });
  }

  return {
    access_code: data.data.access_code,
    reference: data.data.reference,
  };
});

When you pass a plan parameter, you omit the amount. Paystack pulls the amount from the plan definition. After the first successful charge, Paystack creates the subscription automatically.

Handle Subscription Webhooks

// server/api/webhooks/paystack.post.ts
import crypto from 'crypto';

export default defineEventHandler(async (event) => {
  var config = useRuntimeConfig();
  var rawBody = await readRawBody(event);

  if (!rawBody) {
    throw createError({ statusCode: 400, message: 'Empty body' });
  }

  var signature = getHeader(event, 'x-paystack-signature');
  var hash = crypto
    .createHmac('sha512', config.paystackSecretKey)
    .update(rawBody)
    .digest('hex');

  if (hash !== signature) {
    throw createError({ statusCode: 400, message: 'Invalid signature' });
  }

  var payload = JSON.parse(rawBody);

  if (payload.event === 'subscription.create') {
    var sub = payload.data;
    // Save subscription: sub.subscription_code, sub.customer.email,
    // sub.plan.plan_code, sub.next_payment_date, sub.email_token
    console.log('Subscription created:', sub.subscription_code);
  }

  if (payload.event === 'charge.success') {
    // Could be initial or recurring charge
    console.log('Charge successful:', payload.data.reference);
  }

  if (payload.event === 'invoice.payment_failed') {
    // Recurring charge failed
    // Update subscription status to past_due, notify customer
    console.log('Invoice payment failed:', payload.data.subscription.subscription_code);
  }

  if (payload.event === 'subscription.not_renew') {
    // Customer cancelled, will not renew at end of period
    console.log('Subscription will not renew:', payload.data.subscription_code);
  }

  if (payload.event === 'subscription.disable') {
    // Subscription fully deactivated
    // Revoke access
    console.log('Subscription disabled:', payload.data.subscription_code);
  }

  return { received: true };
});

Store the email_token from the subscription.create event. You need it later to cancel the subscription programmatically.

Display and Manage Subscriptions

<!-- pages/dashboard.vue -->
<script setup>
var { data: subData } = await useFetch('/api/subscription');
var cancelling = ref(false);

async function cancelSubscription() {
  if (!confirm('Cancel your subscription?')) return;
  cancelling.value = true;

  try {
    await $fetch('/api/subscription/cancel', { method: 'POST' });
    subData.value.subscription.status = 'cancelled';
  } catch (err) {
    alert('Failed to cancel. Please try again.');
  } finally {
    cancelling.value = false;
  }
}
</script>

<template>
  <div v-if="subData?.subscription">
    <h2>Your Subscription</h2>
    <p>Plan: {{ subData.subscription.planName }}</p>
    <p>Status: {{ subData.subscription.status }}</p>
    <p>Next billing: {{ subData.subscription.nextPaymentDate }}</p>
    <button v-if="subData.subscription.status === 'active'" @click="cancelSubscription" :disabled="cancelling">
      Cancel Subscription
    </button>
  </div>
  <div v-else>
    <p>No active subscription.</p>
    <NuxtLink to="/pricing">View Plans</NuxtLink>
  </div>
</template>

The cancel endpoint calls Paystack's Disable Subscription API:

// server/api/subscription/cancel.post.ts
export default defineEventHandler(async (event) => {
  var config = useRuntimeConfig();

  // Get the user's subscription from your database
  // var sub = await db.subscriptions.findOne({ userId: event.context.auth.userId });

  var response = await fetch('https://api.paystack.co/subscription/disable', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + config.paystackSecretKey,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      code: 'SUB_xxxx', // sub.subscription_code
      token: 'xxxx',    // sub.email_token
    }),
  });

  var data = await response.json();

  if (!data.status) {
    throw createError({ statusCode: 400, message: data.message });
  }

  // Update database
  // await db.subscriptions.updateOne({ userId: event.context.auth.userId }, { status: 'cancelled' });

  return { cancelled: true };
});

Ship Payments Faster

This guide is part of the Paystack integration guides by language and framework series.

Sign up for the McTaba newsletter

Key Takeaways

  • ✓Nuxt handles everything in one project: plan management in server routes, checkout in pages, and webhook handling in server routes.
  • ✓Create plans using the Paystack Plans API from a server route. Store plan codes in your database.
  • ✓Initialize a subscription by passing the plan code to the transaction initialization endpoint. Paystack handles recurring billing after the first charge.
  • ✓Handle subscription webhooks in a dedicated server route: subscription.create, invoice.payment_failed, subscription.not_renew, and subscription.disable.
  • ✓Show subscription status by fetching from your own server route. Do not call the Paystack API from the client.
  • ✓Let customers cancel via the Paystack manage link or through your own UI backed by the Disable Subscription API.

Frequently Asked Questions

Can I manage Paystack subscriptions entirely in Nuxt?
Yes. Nuxt server routes handle plan creation, subscription initialization, webhook processing, and cancellation. You do not need a separate backend.
What is the email_token and why do I need it?
The email_token is returned in the subscription.create webhook event. You need it along with the subscription_code to cancel a subscription programmatically via the Disable Subscription API. Store it when you receive the webhook.
How does Paystack handle failed recurring charges?
Paystack retries failed charges over several days. It sends invoice.payment_failed and invoice.update webhook events. If all retries fail, it disables the subscription and sends a subscription.disable event.
Can I change a subscription plan in Paystack?
Paystack does not support direct plan changes on an existing subscription. To switch plans, cancel the current subscription and create a new one on the new plan. The customer will need to go through checkout again.
What happens to access when a customer cancels?
The customer keeps access until the end of the current billing period. Paystack sends subscription.not_renew immediately when cancelled and subscription.disable when the period ends. Use these events to manage access in your database.

Learn Paystack Integration

KES 2,999

The definitive guide to building payment systems with Paystack — from your first transaction to production-grade payment infrastructure across Africa. 9 modules, 47 lessons. Free preview available.

Start Paystack Course

Not ready? Create Free Account

Keep reading

Paystack Integration Guides by Language and Framework

A complete directory of Paystack integration guides organized by programming language and framework. Each guide covers accepting payments, verifying transactions, handling webhooks, and building subscriptions in your specific stack.

Read more

Verify Paystack Payments in Svelte and SvelteKit

Verify Paystack transactions in SvelteKit using server endpoints for popup verification and load functions for redirect callback verification. Covers amount validation, idempotent fulfillment, and SSR verification for instant results.

Read more

Handle Paystack Webhooks in Flask

Receive and verify Paystack webhooks in your Flask application. This guide covers accessing request.data for raw bytes, HMAC SHA-512 signature verification, processing charge.success events, and making handlers idempotent.

Read more

Build Paystack Subscriptions in ASP.NET Core

Implement Paystack recurring billing in ASP.NET Core. This guide covers creating plans, subscribing customers through transaction initialization, handling renewal webhooks with C#, and cancelling subscriptions.

Read more

Paystack Settlement Timelines and What Engineers Should Assume

Settlement is when the money actually lands in your bank account. It does not happen at the same time as the charge. This guide explains the settlement cycle for each Paystack-supported country, how to query settlement data, and how to build your application so that settlement timing never causes bugs or confusion.

Read more

Paystack Status Page and Incident Response for Your Team

status.paystack.com tells you when Paystack is having problems, but it will not tell you what to do about it. This guide covers how to subscribe to alerts, build an internal incident response runbook for payment outages, communicate with customers during downtime, and reconcile transactions after recovery.

Read more

Explore related topics

M-Pesa & African Stack

M-Pesa Daraja API tutorials, USSD development, and WhatsApp Business API guides. The African Stack that global bootcamps do not teach.

Learn to Code in Kenya

Everything a Kenyan needs to know before writing their first line of code. Career paths, real costs, hardware requirements, and honest answers about what it takes.

Learning to Code

Roadmaps, language guides, and practical advice for learning to code and launching a programming career.

Breaking Into Tech

Practical, no-nonsense guides for anyone looking to start or change their career in tech. From choosing your first language to acing interviews.

The African Stack: Skills for This Market

The skills that make Kenyan developers hard to replace: M-Pesa, USSD, WhatsApp, fintech, and building for the African market.

Bonaventure Ogeto

Bonaventure Ogeto

Founder, McTaba Labs

Bonaventure is the founder of McTaba Labs, a coding bootcamp in Nairobi, Kenya. He has spent years building products for the African market and mentoring the next generation of developers across the continent.