mainmoney / mm-aggr-php-sdk
PHP SDK for the MainMoney aggregator merchant API
Requires
- php: ^8.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
PHP client for the MainMoney aggregator merchant API. Install this package in your PHP application (Laravel, Symfony, WordPress, WooCommerce, or plain PHP).
WordPress and WooCommerce plugins from MainMoney use this SDK on the server. Browser checkout uses the JS/TS frontend SDK and still requires this (or another) backend SDK.
Requirements
- PHP 8.2 or later (8.4 or 8.5 recommended)
- Composer
- A merchant application on MM Aggregator
Install
composer require mainmoney/mm-aggr-php-sdk
Quick start
use MainMoney\Aggregator\Client; $client = new Client( clientId: getenv('MM_CLIENT_ID'), secret: getenv('MM_API_SECRET'), test: true, // https://testaggregator.mainmoney.net — omit for production ); $deposit = $client->deposits->create( [ 'provider_code' => 'VODACOM_MPESA_COD', 'reference' => 'ORDER-123', 'amount' => '100.00', 'currency' => 'USD', 'customer_phone' => '243820000000', ], idempotencyKey: 'ORDER-123', );
Defaults: production https://aggregator.mainmoney.net/api/v1/, test
https://testaggregator.mainmoney.net/api/v1/. Pass baseUri only to override.
Configure credentials from your environment. Merchant API docs:
/api/v1/docs/merchants/ on the aggregator host.
Exchange client_id and secret for a Bearer access token is handled by the
SDK. There is no X-API-KEY header. Resend the same reference and
Idempotency-Key only when retrying the same create (same body). When the body
changes (new phone number, new currency) use a new Idempotency-Key; after a
failed deposit also use a new reference, because a failed one stays reserved.
Derive the key from your checkout session, not from the cart or order. Amounts are
decimal strings; do not mix currencies.
Verify inbound webhooks with $client->webhooks->verify($rawBody, $signature, $secret).
Do not send merchant API keys to the browser.
License
Copyright (c) 2026 MainMoney SARL. Licensed under the MIT License. See LICENSE.
Examples
A runnable Laravel mini-shop lives in examples/laravel. Pair it with a JS/TS frontend example.
Want to contribute? See CONTRIBUTING.md.