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 Flutter
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 22, 2026

Build Paystack Subscriptions in Flutter

To subscribe a customer in Flutter, call your backend to initialize a transaction with a Paystack plan code. Open the authorization URL in a WebView. After payment, Paystack creates the subscription automatically. Your backend receives the subscription.create webhook. From Flutter, check subscription status by calling your backend, which queries the Paystack subscription API.

In this article

  1. 1. Subscription Flow in Flutter
  2. 2. Backend: Initialize Subscription
  3. 3. Flutter: Subscribe Screen
  4. 4. Learn More

Subscription Flow in Flutter

The subscription flow mirrors the one-time payment flow. The difference is on your backend:

  1. Flutter calls your backend with the customer email and plan
  2. Backend initializes a transaction with a Paystack plan code
  3. Backend returns the authorization_url
  4. Flutter opens the URL in a WebView
  5. Customer pays — Paystack creates the subscription and stores their card
  6. Paystack fires subscription.create webhook to your backend
  7. Backend marks the customer as subscribed in your database
  8. Flutter calls your backend status endpoint and shows the active plan

Backend: Initialize Subscription

// Node.js backend
app.post('/api/subscribe', async (req, res) => {
  var { email, planCode } = req.body;
  var reference = 'sub_' + Date.now();

  var response = await fetch('https://api.paystack.co/transaction/initialize', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + process.env.PAYSTACK_SECRET_KEY,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      email,
      plan: planCode,
      reference,
      callback_url: 'https://yourapp.com/subscription/callback',
    }),
  });

  var data = await response.json();
  if (!data.status) return res.status(400).json({ error: data.message });

  res.json({
    authorization_url: data.data.authorization_url,
    reference: data.data.reference,
  });
});

Get weekly developer tips

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

No spam. Unsubscribe anytime.

Flutter: Subscribe Screen

// lib/subscription_screen.dart
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'payment_screen.dart';

class SubscriptionScreen extends StatefulWidget {
  final String userEmail;

  const SubscriptionScreen({super.key, required this.userEmail});

  @override
  State<SubscriptionScreen> createState() => _SubscriptionScreenState();
}

class _SubscriptionScreenState extends State<SubscriptionScreen> {
  bool _isLoading = false;

  Future<void> _subscribe(String planCode, String planName) async {
    setState(() => _isLoading = true);

    var response = await http.post(
      Uri.parse('https://your-backend.com/api/subscribe'),
      headers: {'Content-Type': 'application/json'},
      body: jsonEncode({'email': widget.userEmail, 'planCode': planCode}),
    );

    var data = jsonDecode(response.body);
    setState(() => _isLoading = false);

    if (data['authorization_url'] != null) {
      var result = await Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => PaymentScreen(
            authUrl: data['authorization_url'],
            reference: data['reference'],
          ),
        ),
      );

      if (result?['success'] == true) {
        await _checkSubscriptionStatus();
      }
    }
  }

  Future<void> _checkSubscriptionStatus() async {
    var response = await http.get(
      Uri.parse('https://your-backend.com/api/subscription/status?email=' + widget.userEmail),
    );
    var data = jsonDecode(response.body);

    if (data['active'] == true) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('Subscribed to ${data['plan_name']}!')),
      );
      Navigator.of(context).pop(true);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Choose a Plan')),
      body: _isLoading
          ? const Center(child: CircularProgressIndicator())
          : ListView(
              padding: const EdgeInsets.all(16),
              children: [
                _PlanCard(
                  name: 'Pro Monthly',
                  price: 'NGN 5,000/month',
                  planCode: 'PLN_xxxxxxxxxxxx',
                  onSubscribe: _subscribe,
                ),
                const SizedBox(height: 12),
                _PlanCard(
                  name: 'Pro Annual',
                  price: 'NGN 50,000/year',
                  planCode: 'PLN_yyyyyyyyyyyy',
                  onSubscribe: _subscribe,
                ),
              ],
            ),
    );
  }
}

class _PlanCard extends StatelessWidget {
  final String name;
  final String price;
  final String planCode;
  final Function(String, String) onSubscribe;

  const _PlanCard({
    required this.name,
    required this.price,
    required this.planCode,
    required this.onSubscribe,
  });

  @override
  Widget build(BuildContext context) {
    return Card(
      child: ListTile(
        title: Text(name),
        subtitle: Text(price),
        trailing: ElevatedButton(
          onPressed: () => onSubscribe(planCode, name),
          child: const Text('Subscribe'),
        ),
      ),
    );
  }
}

Learn More

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

Sign up for the McTaba newsletter

Key Takeaways

  • ✓The subscription flow in Flutter is the same as one-time checkout — just pass a plan code when initializing.
  • ✓After checkout, Paystack creates the subscription automatically. Your backend receives the webhook.
  • ✓Flutter checks subscription status by calling your backend API, not Paystack directly.
  • ✓Store subscription status in your backend database and expose it via an API the Flutter app polls.
  • ✓Use Provider or Riverpod to manage subscription state across screens in Flutter.
  • ✓Display the next billing date and plan details in your app from data stored in your backend.

Frequently Asked Questions

How does Flutter know when a subscription is active?
Flutter does not know directly. Your backend receives the subscription.create webhook from Paystack and marks the user as subscribed in the database. Flutter polls your backend status endpoint to check. After the checkout WebView closes, call the status endpoint and update the UI.
Can I cancel a Paystack subscription from Flutter?
Yes. Create a cancel endpoint on your backend that calls POST /subscription/disable with the subscription code and email token. Flutter calls that backend endpoint. The backend handles the Paystack API call and returns success or failure to Flutter.
How do I show the next billing date in Flutter?
Paystack provides next_payment_date in the subscription.create webhook and the subscription status API. Store this date in your database and expose it from your backend. Flutter fetches and displays it on the subscription management screen.
What state management should I use for subscription state in Flutter?
Provider or Riverpod work well. Create a SubscriptionProvider that fetches subscription status from your backend. Refresh it after successful checkout. Any screen that needs to show gated content can watch this provider and adjust the UI accordingly.

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

Accept Payments with Paystack in Flutter

Accept Paystack payments in a Flutter app. This guide covers using paystack_flutter or a custom WebView to launch checkout, capturing the callback, and verifying the transaction from your backend.

Read more

Verify Paystack Payments in Flutter

After a Paystack checkout in Flutter, verify the transaction by calling your backend, which calls the Paystack verify API. This guide shows the full verification flow from the WebView callback to showing the result to the user.

Read more

Handle Paystack Webhooks in Flutter

Paystack webhooks arrive at your server, not your Flutter app. This guide covers building the backend webhook handler and three patterns for pushing webhook events to Flutter: polling, push notifications, and WebSockets.

Read more

Handling subscription.create, subscription.disable and invoice Events

A complete walkthrough of every Paystack subscription and invoice webhook event. Covers subscription.create, subscription.not_renew, subscription.disable, invoice.create, invoice.payment_failed, and invoice.update with production-ready Node.js handlers.

Read more

Paystack Subscription Not Charging

Your Paystack subscription exists but recurring charges are not happening. The subscription might be disabled, the authorization code might not be reusable, the card might have expired, the plan amount might have changed, or the subscription might be in arrears. This guide walks through every cause with a systematic debug checklist.

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.