Type to search. Use the arrow keys, then Enter.

Pesapal payments for PHP

A tested PHP client and method for taking M-Pesa, Airtel Money and card payments through Pesapal API 3.0, with the verify-then-fulfil pattern and the traps the real sandbox showed.

  • Free
  • Skill
  • v1.0.0
  • MIT licence

Overview

What it is

Everything needed to add Pesapal payments (M-Pesa, Airtel Money, Visa, MasterCard) to a PHP site or system in Kenya and East Africa, and to get it right. The integration is small, but mistakes with money are expensive, and the documentation and the sandbox disagree in a few places that matter.

You can use it two ways: as a skill that an AI coding assistant follows, or by taking the PHP client and examples and wiring them in yourself.

What is inside

  • scripts/PesapalClient.php: one framework-free class. Token caching, registering the notification address, submitting an order, checking a transaction, refunds and cancellations, with typed errors.
  • scripts/: a payments table, working examples of the notification and return pages, a reconciliation job, a self test, and a smoke test against the real sandbox.
  • references/: the API distilled from Pesapal's documentation, notifications and callbacks, refunds, recurring payments, the point-of-sale API, testing, and a list of errors and traps.
  • SKILL.md: the method, written for an AI coding assistant.

How to use it

  1. Unzip the download. You get one folder, pesapal-payments-php.
  2. As a skill for Claude Code: put the folder in .claude/skills/ in your project. Then ask, for example: "Add Pesapal checkout to this shop."
  3. Or by hand: copy scripts/PesapalClient.php and scripts/schema.sql into your project and follow scripts/example_bootstrap.php.
  4. Use your own sandbox keys first. Run scripts/smoke_sandbox.php to prove the connection before any real money moves.

The one rule that matters

Never mark an order paid because the customer came back to your site. Mark it paid only after your server has asked Pesapal for the transaction status and the answer says completed, for the right amount. The examples do it this way.

Good to know

  • Your keys are yours: nothing in the kit sends them anywhere except to Pesapal.
  • This is not an official Pesapal product. Check their current documentation before you go live.
  • Going live needs your own merchant account and Pesapal's approval of your site.

Version history

  • 1.0.0 (14 November 2026): first public release.

Files in the download

  • LICENSE.txt
  • SKILL.md
  • references/api-3.md
  • references/errors-and-traps.md
  • references/ipn-and-callbacks.md
  • references/pos-api.md
  • references/recurring.md
  • references/refunds-cancellations.md
  • references/testing.md
  • scripts/PesapalClient.php
  • scripts/callback_example.php
  • scripts/example_bootstrap.php
  • scripts/ipn_endpoint_example.php
  • scripts/reconcile_example.php
  • scripts/schema.sql
  • scripts/selftest.php
  • scripts/smoke_sandbox.php

Shared under the MIT licence, as it is, without warranty. Read it before you run it, and test on a copy of your data first.

Want this fitted to your system?

Tell me what you run. I will say honestly whether the kit is enough or you need a hand.