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 an Insurance Premium Collection Portal
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 22, 2026

Build an Insurance Premium Collection Portal

Build an insurance premium portal by creating a Paystack Plan per insurance product (health, motor, microinsurance), subscribing policyholders via the transaction initialize endpoint, setting policy status to "active" on subscription.create, applying a 14-day grace period on invoice.payment_failed before suspending coverage, and disabling the subscription on subscription.disable to mark the policy as "lapsed".

In this article

  1. 1. Policy Enrollment and Premium Setup
  2. 2. Premium Renewal, Grace Period, and Policy Lapse
  3. 3. Learn More

Policy Enrollment and Premium Setup

Tables: insurance_products (name, type, coverage_amount, premium_monthly, paystack_plan_code, terms_url), policies (holder_id, product_id, policy_number, paystack_subscription_code, status, start_date, grace_until, expires_at), claims (policy_id, type, amount, status, submitted_at).

function generatePolicyNumber() {
  return 'POL-' + new Date().getFullYear() + '-' + Math.random().toString(36).toUpperCase().slice(2, 8);
}

async function enrollPolicyholder(holderEmail, holderId, productId) {
  var product = await db.insuranceProducts.findById(productId);

  var policy = await db.policies.create({
    holder_id: holderId,
    product_id: productId,
    policy_number: generatePolicyNumber(),
    status: 'pending_first_payment',
    start_date: new Date(),
  });

  var res = 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: holderEmail,
      amount: product.premium_monthly,
      plan: product.paystack_plan_code,
      metadata: { holder_id: holderId, policy_id: policy.id, product_id: productId },
    }),
  });
  return { policy, authorizationUrl: (await res.json()).data.authorization_url };
}

// Webhook: activate policy on first premium
if (event.event === 'subscription.create') {
  var meta = event.data.metadata;
  var nextPayment = new Date(event.data.next_payment_date);

  await db.policies.update(meta.policy_id, {
    paystack_subscription_code: event.data.subscription_code,
    status: 'active',
    expires_at: nextPayment,
  });
  await issuePolicyCertificate(meta.policy_id, meta.holder_id);
}

Premium Renewal, Grace Period, and Policy Lapse

// Renewal confirmed
if (event.event === 'invoice.create' && event.data.status === 'success') {
  var code = event.data.subscription.subscription_code;
  await db.policies.update({ code }, {
    status: 'active',
    grace_until: null,
    expires_at: new Date(event.data.next_payment_date),
  });
}

// Failed payment: enter grace period
if (event.event === 'invoice.payment_failed') {
  var code = event.data.subscription.subscription_code;
  var graceUntil = new Date();
  graceUntil.setDate(graceUntil.getDate() + 14); // 14-day grace period

  await db.policies.update({ code }, { status: 'grace_period', grace_until: graceUntil });
  await sendPremiumFailedEmail(code,
    'Your premium payment failed. Coverage continues until ' + graceUntil.toDateString() +
    '. Please update your payment method to avoid policy lapse.'
  );
}

// Policy cancelled or subscription disabled — lapse
if (event.event === 'subscription.disable') {
  var code = event.data.subscription_code;
  await db.policies.update({ code }, { status: 'lapsed' });
  await notifyPolicyLapsed(code);
}

// Cron: suspend coverage after grace period expires
async function suspendLapsedPolicies() {
  var now = new Date();
  var overdue = await db.policies.findAll({ status: 'grace_period', grace_until_lt: now });
  for (var policy of overdue) {
    await db.policies.update(policy.id, { status: 'suspended' });
    await sendCoverageSuspendedEmail(policy.holder_id);
  }
}

// Claim eligibility check
async function isEligibleForClaim(policyId) {
  var policy = await db.policies.findById(policyId);
  return policy.status === 'active' || policy.status === 'grace_period';
}

Get weekly developer tips

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

No spam. Unsubscribe anytime.

Learn More

See build a gym membership app for the same grace period and subscription lifecycle pattern applied to a simpler membership product.

Sign up for the McTaba newsletter

Key Takeaways

  • ✓Create one Paystack Plan per insurance product — link each policy to the correct plan code.
  • ✓Map subscription lifecycle events to policy status: active, grace_period, suspended, lapsed.
  • ✓Apply a 14-day grace period on invoice.payment_failed before suspending coverage.
  • ✓Generate a digital policy certificate on the first premium payment confirmation.
  • ✓For microinsurance, consider weekly or daily Paystack Plans to match informal worker income patterns.

Frequently Asked Questions

Do I need an insurance licence to collect premiums via Paystack?
Yes. In Nigeria, collecting insurance premiums requires NAICOM licensing. In Kenya, you need IRA approval. Building a premium collection portal for a licensed insurer (as a technology partner, not the insurer itself) is the typical developer role. Your platform collects payments on behalf of the licensed insurer, which holds the risk and regulatory obligations.
How should I handle a claim submission?
Claims are separate from payments. Build a claims portal where policyholders upload supporting documents (hospital bills, police reports, photos), and a claims assessor reviews and approves or rejects. Payment of approved claims goes via Paystack Transfers to the policyholder's bank account. Track claim processing time as a key service metric.
Can I offer microinsurance with weekly premiums instead of monthly?
Yes. Paystack Plans support weekly billing intervals. Create a weekly_premium plan with a lower amount (e.g., NGN 250/week = NGN 1,000/month equivalent). Weekly billing matches the income patterns of informal workers who are paid daily or weekly. The subscription lifecycle webhooks work identically — only the invoice frequency changes.

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

Things You Can Build with Paystack: Project Guides

A complete map of real-world projects you can build using the Paystack API. From online store checkouts and subscription platforms to savings apps and solar pay-as-you-go systems, each category links to step-by-step build guides with working code.

Read more

Build a Parking Payment App

A build guide for a parking payment app where drivers scan a QR code on entry, pay for their session via Paystack (card or M-Pesa), and the system validates payment before the barrier lifts for exit. Covers time-based pricing, session management, and overstay handling.

Read more

Build a Referral Payout System

A build guide for a referral payout system where users share referral links, earn commissions when referrals convert, and withdraw their balance via Paystack Transfers to their bank account or M-Pesa wallet.

Read more

Build a Veterinary Clinic Booking and Payment System

A build guide for a veterinary clinic booking and payment system where pet owners book appointments online, pay a deposit via Paystack to confirm the slot, and pay the balance at the clinic after the consultation. Includes pet health records, vaccination schedules, and automated reminders.

Read more

Accepting M-Pesa Payments Through Paystack Checkout

A step-by-step implementation guide for accepting M-Pesa payments through Paystack Checkout. Covers Initialize Transaction with the mobile_money channel, what the customer sees, webhook handling, timeout management, testing in Paystack test mode, and a complete Express.js code example from initialization to verification.

Read more

Split Payment Reconciliation and Subaccount Reporting

Split payment reconciliation means verifying that every vendor received the right amount from every transaction. This guide covers querying Paystack transaction and settlement data, building per-vendor earnings reports from your database, and finding discrepancies between expected and actual settlement.

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.