Logo Lanfrica

moshthepitt/simple-mpesa-php-sdk

Domain:

digital infrastructure

Record type:

software
Creator:
mos
Host:
Really Simple M-PESA API PHP SDK # Really Simple M-PESA API PHP SDK This is a really simple PHP implementation of the Safaricom M-PESA API. The intention is to have the entire thing implemented in just one PHP file (because why not) that is hopefully easy to work with and ultra portable (just copy paste). ## Implemented APIs ### 1. M-PESA Express (aka STK Push) For Lipa Na M-Pesa payments using STK Push. #### M-PESA Express Request First, you need to start a transaction, like this: ```php // instantiate the API object $api = new Mpesa('YOUR CONSUMER KEY', 'YOUR CONSUMER SECRET'); // generate an access token $api->generateToken(); // make the STK push request print_r($api->STKPushSimulation( 000000, // the till number (or shortcode). Get tests ones from developer.safaricom.co.ke 'YOUR PASSKEY', // your passkey 'CustomerPayBillOnline', // either CustomerPayBillOnline or CustomerBuyGoodsOnline 1337, // the amount '254xxxxxxxxx', // The phone number sending money 174379, // the till number '254xxxxxxxxx', // The Mobile Number to receive the STK Pin Prompt. 'example.com', // your callback URL 'account-123', // account reference 'description' // the description )); ``` #### M-PESA Express Query After you have initiated the payment, you can query for a status as follows: ```php // instantiate the API object $api = new Mpesa('YOUR CONSUMER KEY', 'YOUR CONSUMER SECRET'); // generate an access token $api->generateToken(); // make the STK push query request print_r($api->STKPushQuery( 'Safaricom transaction id aka $CheckoutRequestID', // the transaction id that you get from Safaricom from the 'M-PESA Express Request' above 174379, // the till number 'your passkey', // your passkey )); ``` #### Callbacks You will notice that the `STKPushSimulation` request includes a callback url (`CallBackURL`) parameter. Safaricom will use this to send transaction notifications to your web service. There are two included utility methods for deali …

Languages