1. Go to this page and download the library: Download shiftechafrica/pam-php-sdk 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/ */
shiftechafrica / pam-php-sdk example snippets
use PAM\API\B2C;
use PAM\API\PayLoad;
use PAM\API\RegC2bUrl;
use PAM\API\ShortCode;
use PAM\API\App;
use PAM\API\STKPush;
use PAM\API\Balance;
/**
* Fetch all your shortcodes
*/
(new ShortCode())->index();
/**
* Get details of one shortcode
* by passing the id
*/
(new ShortCode())->show('id');
/**
* Fetch all your apps
*/
(new App())->index();
/**
* Get details of one app
* by passing the id
*/
(new App())->show('id');
/**
* Fetch max <= 1000 latest transactions
*/
(new PayLoad())->index();
/**
* Get details of one payload
* by passing the id
*/
(new PayLoad())->show('id');
/**
* get the validate shortcode
* @return mixed
*/
(new ShortCode())->validate([
"ConsumerKey" => "",
"ConsumerSecret" => "",
"Environment" => "" // sandbox or production
]);
/**
* get the initiate stk
* push
* @return mixed
*/
(new STKPush())->initiateSTK([
"CallingCode" => "", // 254 or 255
"Secret" => "",
"TransactionType" => "", // CustomerPayBillOnline or CustomerBuyGoodsOnline
"PhoneNumber" => "",
"Amount" => "",
"ResultUrl" => "",
"Description" => ""
]);
/**
* register c2b url for lipa_na_mpesa
* @return JsonResponse|mixed
*/
(new RegC2bUrl())->registerC2BURL([
"Secret" => ""
]);
/**
* check paybill/till balance
* @return JsonResponse|mixed
*/
(new Balance())->checkBalance([
"Secret" => ""
]);
/**
* process the b2c transaction
* here
* @return mixed
*/
(new B2C())->initiateB2C([
"CallingCode" => "", // 254 or 255
"Secret" => "",
"TransactionType" => "", // SalaryPayment or BusinessPayment or PromotionPayment
"PhoneNumber" => "",
"Amount" => "",
"ResultUrl" => "",
"Description" => ""
]);
/**
* process the stk payment confirmation
* here
* @return mixed
*/
return (new ConfirmPayment())->stkPayment([
"Secret" => "",// secret for handling stk transactions
"ReferenceNumber" => "", // the transaction number used for initiating the payment.
"ResultUrl" => "", // url to receive the payment status
]);
/**
* process the withdrawal confirmation
* here
* @return mixed
*/
return (new ConfirmPayment())->withdrawPayment([
"Secret" => "", // secret for handling b2c transactions
"ReferenceNumber" => "", // the transaction number used for initiating the payment.
"ResultUrl" => "", // url to receive the payment status
]);
# Sample 200 response
"data": {
"Message": "The m-pesa app keys are valid."
},
"success": true
# Sample 200 response
"data": {
"Message": "Validation and Confirmation URLs are already registered"
},
"success": true