osenco / airtel
Intuitive and Comprehensive M-PESA SDK for PHP Applications. Just Plug 'N Play
dev-master
2021-08-02 20:31 UTC
Requires
- php: >=7.4
- guzzlehttp/guzzle: 7.4.x-dev
This package is auto-updated.
Last update: 2024-11-29 06:41:29 UTC
README
Airtel Money API PHP SDK
Installation
composer require osenco/airtel
Collection APIs
Instantiate
use Osen\Airtel\Collection; $collectAPI = new Collection( array( 'env' => 'live', 'client_id' => 'YOUR_CLIENT_ID', 'client_secret' => 'YOUR_CLIENT_SECRET', 'public_key' => 'YOUR_PUBLIC_KEY', 'country' => 'Transaction Country Code e.g KE', 'currency' => 'Transaction Currency Code e.g KES' ) );
STK/USSD Push
$collectAPI->authorize()->ussdPush($phone, $amount);
Note : Do not send country code in phone number.
You can pass a token to the authorize method if you have a caching mechanism instead of creating a new one each time. You can pass a second argument that is a callback function that updates your token
$token = ''; // Get your token from database, redis or whichever cache you use. $collectAPI->authorize($token, function($newToken) { print($newToken); // Save/update $newToken in your database })->ussdPush($phone, $amount);
Disbursement APIs
use Osen\Airtel\Disbursement; $disburseAPI = new Disbursement( array( 'env' => 'live', 'client_id' => 'YOUR_CLIENT_ID', 'client_secret' => 'YOUR_CLIENT_SECRET', 'public_key' => 'YOUR_PUBLIC_KEY', 'country' => 'Transaction Country Code e.g KE', 'currency' => 'Transaction Currency Code e.g KES' ) );
Then send the money
$disburseAPI->authorize()->send($phone, $amount);