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. Testing Split Payment Logic Safely
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 22, 2026

Testing Split Payment Logic Safely

Test split payment logic at three levels: (1) unit test the commission calculation function in isolation, (2) mock the Paystack API in integration tests to verify the correct percentage_charge or transaction_charge is passed, and (3) end-to-end test using Paystack test mode — create real test subaccounts and verify the settlement breakdown in the Paystack test dashboard.

In this article

  1. 1. Unit Testing Commission Calculation
  2. 2. Integration Test with Mocked Paystack API
  3. 3. Learn More

Unit Testing Commission Calculation

// commission.ts
export function calculateSplit(totalAmount: number, commissionRate: number) {
  const vendorShare = Math.round(totalAmount * (1 - commissionRate) * 100); // kobo
  const platformShare = Math.round(totalAmount * commissionRate * 100); // kobo
  return { vendorShare, platformShare };
}

// commission.test.ts
describe('calculateSplit', () => {
  it('splits 10% commission correctly', () => {
    var result = calculateSplit(10000, 0.10);
    expect(result.vendorShare).toBe(900000); // NGN 9,000 in kobo
    expect(result.platformShare).toBe(100000); // NGN 1,000 in kobo
  });

  it('handles non-round amounts without floating point errors', () => {
    var result = calculateSplit(999.99, 0.10);
    // Should not produce fractional kobo
    expect(result.vendorShare % 1).toBe(0);
    expect(result.platformShare % 1).toBe(0);
  });

  it('returns full amount to vendor at 0% commission', () => {
    var result = calculateSplit(5000, 0);
    expect(result.vendorShare).toBe(500000);
    expect(result.platformShare).toBe(0);
  });
});

Integration Test with Mocked Paystack API

// Mock Paystack API in Jest
jest.mock('../lib/paystack', () => ({
  initializeTransaction: jest.fn().mockResolvedValue({
    status: true,
    data: {
      authorization_url: 'https://checkout.paystack.com/test',
      access_code: 'test_access',
      reference: 'test_ref_001',
    }
  }),
}));

describe('Checkout with vendor split', () => {
  it('passes correct percentage_charge to Paystack', async () => {
    var paystack = require('../lib/paystack');
    var vendor = { subaccount_code: 'SUB_test123', commission_rate: 0.15 };

    await checkoutService.initializeSplitPayment({
      email: 'buyer@test.com',
      amount: 10000,
      vendor,
    });

    expect(paystack.initializeTransaction).toHaveBeenCalledWith(
      expect.objectContaining({
        subaccount: 'SUB_test123',
        percentage_charge: 85, // 1 - 0.15 = 0.85 = 85%
        bearer: 'account',
      })
    );
  });
});

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

This guide is part of the Paystack split payments guide.

Sign up for the McTaba newsletter

Key Takeaways

  • ✓Unit test commission calculation functions independently before testing the API integration.
  • ✓Mock the Paystack API in unit and integration tests — do not hit the real API in CI pipelines.
  • ✓Create dedicated test subaccounts in Paystack test mode for end-to-end testing.
  • ✓Test the full split: initialize transaction, simulate webhook, verify subaccount share is correct in your DB.
  • ✓Test edge cases: 0% commission, 100% to subaccount, rounding on non-round amounts (NGN 999.99).
  • ✓Verify bearer configuration in tests — a wrong bearer setting shifts who absorbs Paystack fees.

Frequently Asked Questions

Can I create test subaccounts with fake bank details in Paystack test mode?
Yes. In test mode, Paystack does not validate bank account numbers. You can use any numeric string as an account number. Create test subaccounts with dummy bank codes and account numbers. They will work for testing the split API without needing real bank details.
How do I verify the actual settlement breakdown in a test transaction?
After completing a test transaction, call GET /transaction/:id to see the transaction details. The subaccount field in the response shows how much was allocated to the subaccount. Compare this against your expected split calculation.
Should I test percentage splits or flat splits?
Test both — they use different Paystack parameters (percentage_charge vs transaction_charge). Percentage splits can have rounding issues at certain amounts. Flat splits can fail if the transaction_charge exceeds the transaction amount. Have dedicated tests for each model.
How do I test the webhook handler for a split payment?
Send a mock charge.success event to your webhook endpoint in tests. Include the metadata you set during transaction initialization (vendor_id, order_id). Verify that your handler correctly updates the order status and records the vendor's earnings. Use the Paystack webhook simulator from the test dashboard for end-to-end testing.

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 Split Payments and Marketplaces: Complete Guide

Everything you need to split payments on Paystack: creating subaccounts, choosing between percentage and flat splits, multi-split transactions, fee configuration, delayed settlement, escrow-style patterns, and building real marketplace products with working Node.js code.

Read more

Percentage vs Flat Split Configuration on Paystack

A detailed comparison of percentage and flat split configurations on Paystack. Covers how each model works, worked margin calculations across different transaction sizes, when to use percentage vs flat, implementing per-transaction overrides, and building hybrid models that combine both approaches.

Read more

Escrow-Style Flows on Paystack and Their Limits

A thorough analysis of what escrow-style flows you can and cannot build on Paystack. Covers the difference between true escrow and delayed settlement, how to use manual settlement for hold-and-release patterns, the limits around hold duration and fund recovery, regulatory considerations in African markets, and when Paystack is not the right tool for escrow.

Read more

Building a Freelance Marketplace on Paystack

A freelance marketplace holds client funds until the work is approved, then releases to the freelancer. This guide covers implementing that hold-and-release pattern using Paystack delayed settlement, collecting platform commission via splits, and handling disputes and refunds.

Read more

Building an Automated Payout System on Paystack

A production payout system is more than a loop calling the transfer API. This guide covers the full architecture: payout queue design, approval workflows, balance pre-checks, batch execution, webhook-driven status updates, reconciliation against Paystack records, and handling the edge cases that show up at scale.

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.