1. Go to this page and download the library: Download paymentsds/mpesa library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
paymentsds / mpesa example snippets
use Paymentsds\MPesa\Client;
use Paymentsds\MPesa\Environment;
$client = new Client([
'apiKey' => '<REPLACE>', // API Key
'publicKey' => '<REPLACE>', // Public Key
'serviceProviderCode' => '<REPLACE>' // Service Provider Code
'environment' => Environment::SANDBOX // Environment. Use Environment::PRODUCTION for production
]);
$paymentData = [
'from' => '841234567', // Customer MSISDN
'reference' => '11114', // Third Party Reference
'transaction' => 'T12344CC', // Transaction Reference
'amount' => '10' // Amount
];
$result = $client->receive($paymentData);
if ($result->success) {
// Handle success
} else {
// Handle failure
}
use Paymentsds\MPesa\Client;
$client = new Client([
'apiKey' => '<REPLACE>', // API Key
'publicKey' => '<REPLACE>', // Public Key
'serviceProviderCode' => '<REPLACE>' // Service Provider Code
]);
$paymentData = [
'to' => '841234567', // Customer MSISDN
'reference' => '11114', // Third Party Reference
'transaction' => 'T12344CC', // Transaction Reference
'amount' => '10' // Amount
];
$result = $client->send($paymentData);
if ($result->success) {
// Handle success scenario
} else {
// Handle failure scenario
}
$client = new Client([
'apiKey' => '<REPLACE>', // API Key
'publicKey' => '<REPLACE>', // Public Key
'serviceProviderCode' => '<REPLACE>' // Service Provider Code
]);
$paymentData = [
'from' => '979797', // Receiver Party Code
'reference' => '11114', // Third Party Reference
'transaction' => 'T12344CC', // Transaction Reference
'amount' => '10' // Amount
];
$result = $client->send($paymentData)
if ($result->success) {
// Handle success scenario
} else {
// Handle failure scenario
}
use Paymentsds\MPesa\Client;
$client = new Client([
'apiKey' => '<REPLACE>', // API Key
'publicKey' => '<REPLACE>', // Public Key
'serviceProviderCode' => '<REPLACE>', // Service Provider Code
'initiatorIdentifier' => '<REPLACE>', // Initiator Identifier
'securityIdentifier' => '<REPLACE>' // Security Credential
]);
$paymentData = [
'reference' => '11114', // Third Party Reference
'transaction' => 'T12344CC', // Transaction Reference
'amount' => '10' // Amount
];
$result = $client->revert($paymentData);
if ($result->success) {
// Handle success scenario
} else {
// Handle failure scenario
}
use Paymentsds\MPesa\Client;
$client = new Client([
'apiKey' => '<REPLACE>', // API Key
'publicKey' => '<REPLACE>', // Public Key
'serviceProviderCode' => '<REPLACE>' // Service Provider Code
]);
$paymentData = [
'subject' => '11114', // Query Reference
'transaction' => 'T12344CC', // Transaction Reference
];
$result = $client->query($paymentData);
if ($result->success) {
// Handle success scenario
} else {
// Handle failure scenario
}
bash
git clone https://github.com/paymentsds/mpesa-php-sdk mpesa-php-sdk
cd mpesa-php-sdk
composer install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.