Download the PHP package lepresk/momo-api without Composer
On this page you can find all versions of the php package lepresk/momo-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lepresk/momo-api
More information about lepresk/momo-api
Files in lepresk/momo-api
Package momo-api
Short Description PHP library for MTN Mobile Money (MoMo) API. Receive payments (Collection), send money (Disbursement), and manage mobile transactions in Africa.
License MIT
Homepage https://github.com/lepresk/momo-api
Informations about the package momo-api
Librairie Momo API
A powerful and professional PHP wrapper for integrating MTN Mobile Money and Airtel Money APIs. Supports Collection (receive payments) and Disbursement (send money) operations.
Features
| Provider | Product | Supported Operations |
|---|---|---|
| MTN MoMo | Collection | Request payments, Check payment status, Check account holder, Get balance |
| MTN MoMo | Disbursement | Transfer money, Deposit funds, Process refunds, Check account holder, Get balance |
| MTN MoMo | Sandbox | Create API users, Generate API keys, Test environment support |
| Airtel Money | Collection | Request payments, Check payment status, Get balance |
| Airtel Money | Disbursement | Transfer money, Check transfer status, Get balance |
Requirements
- PHP 8.2 or higher
- MTN MoMo Developer Account (Sign up) and/or Airtel Money API credentials
Installation
Quick Start
Collection API (Receive Payments)
Disbursement API (Send Money)
Sandbox Setup
The sandbox accepts EUR only. Against the sandbox, requestToPay(), quickPay(),
deposit(), transfer() and refund() send EUR whatever currency the request
was built with (MomoApi::SANDBOX_CURRENCY), so the same XAF code runs in both
environments. Outside the sandbox the request currency is sent as is.
Advanced Usage
Collection API - Full Example
Disbursement API - Full Example
Airtel Money
Airtel Collection API (Receive Payments)
Airtel Disbursement API (Send Money)
Airtel Disbursement PIN
The transfer endpoint takes an RSA-encrypted PIN, never the PIN itself:
The key is accepted as PEM, base64-encoded PEM, or the bare base64 body (MIIBIj...).
Airtel Phone Numbers
Airtel expects a national MSISDN. Numbers are normalised for you — passing
242068511358 or 068511358 sends 068511358 either way. Phone::clean() is
public if you need the same normalisation elsewhere.
Airtel Failures
Airtel reports business failures with HTTP 200 and status.success: false, so
requestToPay() and transfer() throw a MomoException in that case rather
than returning an externalId for a refused request.
Status codes: TS successful, TF failed, TIP and TI both pending.
Airtel Environments
| Mode | URL | Use Case |
|---|---|---|
staging |
https://openapiuat.airtel.cg |
Testing |
production |
https://openapi.airtel.cg |
Production - Congo |
Retrying Without Paying Twice
Each write returns the id you poll its status with. By default it is a random UUID, so if the request times out or fails with a 5xx you never learn it: you cannot ask whether the payment went through, and retrying sends a new id that MTN or Airtel treats as a new payment.
Pass your own UUID as the last argument instead, and store it before sending. After an ambiguous failure, query the status with it; retry with the same id only once the status says the first attempt does not exist.
The id must be a UUID (any version): anything else throws an
InvalidArgumentException before a request is sent. Without it, every method
keeps generating a random UUID.
Handling Callbacks
Callbacks are not signed. Neither MTN nor Airtel signs the request sent to your callback URL, and that URL is no secret: it travels in the
X-Callback-Urlheader of every request. Anyone can call it with"status": "SUCCESSFUL". Never fulfil an order from the callback body. Treat the callback as a signal that something changed, then ask MTN or Airtel for the real status.
MTN MoMo
MTN sends the callback as a JSON body (PUT). Use it only to find the order, then
re-query the payment with the reference id requestToPay() returned, which you
stored with the order:
Airtel Money
Airtel's callback carries transaction.id, the externalId you passed to
requestToPay(). Re-query it the same way:
Transaction::parse() turns an array into a Transaction; it does not verify
anything. Use it on data you fetched yourself, not on a callback you intend to act on.
Error Handling
Available Environments
| Constant | Value | Use Case |
|---|---|---|
ENVIRONMENT_SANDBOX |
sandbox | Testing |
ENVIRONMENT_MTN_CONGO |
mtncongo | Production - Congo |
ENVIRONMENT_MTN_UGANDA |
mtnuganda | Production - Uganda |
ENVIRONMENT_MTN_GHANA |
mtnghana | Production - Ghana |
ENVIRONMENT_IVORY_COAST |
mtnivorycoast | Production - Ivory Coast |
ENVIRONMENT_ZAMBIA |
mtnzambia | Production - Zambia |
ENVIRONMENT_CAMEROON |
mtncameroon | Production - Cameroon |
ENVIRONMENT_BENIN |
mtnbenin | Production - Benin |
ENVIRONMENT_SWAZILAND |
mtnswaziland | Production - Swaziland |
ENVIRONMENT_GUINEACONAKRY |
mtnguineaconakry | Production - Guinea Conakry |
ENVIRONMENT_SOUTHAFRICA |
mtnsouthafrica | Production - South Africa |
ENVIRONMENT_LIBERIA |
mtnliberia | Production - Liberia |
API Reference
Collection API
| Method | Description |
|---|---|
requestToPay(PaymentRequest $request, ?string $referenceId = null) |
Request payment from customer |
quickPay(string $amount, string $phone, string $ref, string $currency = 'XAF', ?string $referenceId = null) |
Quick payment helper |
getPaymentStatus(string $paymentId) |
Check payment status |
checkAccountHolder(string $phone) |
Check if MSISDN is active |
getBalance() |
Get account balance |
getAccessToken() |
Get OAuth token (auto-managed) |
Disbursement API
| Method | Description |
|---|---|
transfer(TransferRequest $request, ?string $referenceId = null) |
Transfer money to beneficiary |
getTransferStatus(string $transferId) |
Check transfer status |
deposit(PaymentRequest $request, ?string $referenceId = null) |
Deposit funds |
getDepositStatus(string $depositId) |
Check deposit status |
refund(RefundRequest $request, ?string $referenceId = null) |
Refund a transaction |
getRefundStatus(string $refundId) |
Check refund status |
checkAccountHolder(string $phone) |
Check if MSISDN is active |
getBalance() |
Get account balance |
getAccessToken() |
Get OAuth token (auto-managed) |
Airtel Collection API
| Method | Description |
|---|---|
requestToPay(string $amount, string $phone, string $reference, ?string $transactionId = null) |
Request payment from customer |
getPaymentStatus(string $externalId) |
Check payment status (returns AirtelTransaction) |
getBalance() |
Get account balance |
getAccessToken() |
Get OAuth token (cached automatically) |
Airtel Disbursement API
| Method | Description |
|---|---|
transfer(string $amount, string $phone, string $reference, ?string $transactionId = null) |
Transfer money (requires encryptedPin) |
getTransferStatus(string $externalId) |
Check transfer status (returns AirtelTransaction) |
getBalance() |
Get account balance |
getAccessToken() |
Get OAuth token (cached automatically) |
Sandbox API
| Method | Description |
|---|---|
createApiUser(string $uuid, string $callback) |
Create sandbox API user |
getApiUser(string $uuid) |
Get API user details |
createApiKey(string $uuid) |
Generate API key |
Testing
The package includes two types of tests:
Unit Tests - Fast tests with mocked HTTP responses:
Fixture Tests - Validate parsing of real MTN API responses:
Run PHPStan analysis:
Production Notes
- Never hardcode credentials - Use environment variables
- Validate callbacks - Check transaction status via API, not just callback data
- Handle webhooks asynchronously - Process in background queue
- Log all transactions - Keep audit trail
- Test thoroughly in sandbox before going live
Ecosystem
The same client is available for multiple languages:
| Language | Package | Install |
|---|---|---|
| PHP | lepresk/momo-api |
composer require lepresk/momo-api |
| Node.js / TypeScript | @lepresk/momo-api |
npm install @lepresk/momo-api |
| Python | mtn-momo-client |
pip install mtn-momo-client |
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
Changelog
See CHANGELOG.md for the full history of changes.
License
MIT License - see LICENSE file for details.
Support
- Documentation: MTN MoMo Developer Portal
- Issues: GitHub Issues