{"id":26378438,"url":"https://github.com/muindi6602/mpesa-php","last_synced_at":"2026-01-04T03:15:31.171Z","repository":{"id":278629168,"uuid":"936253121","full_name":"Muindi6602/Mpesa-PHP","owner":"Muindi6602","description":"A simple STK Mpesa integration using PHP","archived":false,"fork":false,"pushed_at":"2025-02-20T19:28:29.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-20T20:30:04.658Z","etag":null,"topics":["mpesa-sdk"],"latest_commit_sha":null,"homepage":"https://github.com/Muindi6602/Mpesa-PHP","language":"Hack","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Muindi6602.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-20T19:21:34.000Z","updated_at":"2025-02-20T19:28:32.000Z","dependencies_parsed_at":"2025-02-20T20:31:01.872Z","dependency_job_id":"f25da0ac-eb75-4068-b81d-9e8862125731","html_url":"https://github.com/Muindi6602/Mpesa-PHP","commit_stats":null,"previous_names":["muindi6602/mpesa-php"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muindi6602%2FMpesa-PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muindi6602%2FMpesa-PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muindi6602%2FMpesa-PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muindi6602%2FMpesa-PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Muindi6602","download_url":"https://codeload.github.com/Muindi6602/Mpesa-PHP/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976511,"owners_count":20377691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mpesa-sdk"],"created_at":"2025-03-17T04:51:55.166Z","updated_at":"2026-01-04T03:15:31.132Z","avatar_url":"https://github.com/Muindi6602.png","language":"Hack","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Introduction**\n\nThis package seeks to help php developers implement the various Mpesa APIs without much hustle. It is based on the REST API whose documentation is available on https://developer.safaricom.co.ke.\n \n **Installation using composer**\u003cbr\u003e\n `composer require safaricom/mpesa`\u003cbr\u003e\n \n \n **Configuration**\u003cbr\u003e\n At your project root, create a .env file and in it set the consumer key and consumer secret as follows   \n `MPESA_CONSUMER_KEY= [consumer key]` \u003cbr\u003e\n `MPESA_CONSUMER_SECRET=[consumer secret]`\u003cbr\u003e\n `MPESA_ENV=[live or sandbox]`\u003cbr\u003e\n For Laravel users, open the Config/App.php file and add `\\Safaricom\\Mpesa\\MpesaServiceProvider::class` under providers and ` 'Mpesa'=\u003e \\Safaricom\\Mpesa\\MpesaServiceProvider::class` under aliases.\n  \n  _Remember to edit the consumer_key and consumer_secret values appropriately when switching between sandbox and live_\n\n  \n **Usage**\n \n **Confirmation and validation urls** \n\n**B2C Payment Request**\n \n This creates transaction between an M-Pesa short code to a phone number registered on M-Pesa.\n \n`$mpesa= new \\Safaricom\\Mpesa\\Mpesa();`\n\n`$b2cTransaction=$mpesa-\u003eb2c($InitiatorName, $SecurityCredential, $CommandID, $Amount, $PartyA, $PartyB, $Remarks, $QueueTimeOutURL, $ResultURL, $Occasion);`\n\n\n\n**Account Balance Request**\n \nThis is used to enquire the balance on an M-Pesa BuyGoods (Till Number)\n\n`$mpesa= new \\Safaricom\\Mpesa\\Mpesa();`\n\n`$balanceInquiry=$mpesa-\u003eaccountBalance($CommandID, $Initiator, $SecurityCredential, $PartyA, $IdentifierType, $Remarks, $QueueTimeOutURL, $ResultURL);`\n\n\n\n**Transaction Status Request**\nThis is used to check the status of transaction. \n\n`$mpesa= new \\Safaricom\\Mpesa\\Mpesa();`\n\n`$trasactionStatus=$mpesa-\u003etransactionStatus($Initiator, $SecurityCredential, $CommandID, $TransactionID, $PartyA, $IdentifierType, $ResultURL, $QueueTimeOutURL, $Remarks, $Occasion);`\n\n\n\n**B2B Payment Request**\n\nThis is used to transfer funds between two companies.\n\n`$mpesa= new \\Safaricom\\Mpesa\\Mpesa();`\n\n`$b2bTransaction=$mpesa-\u003eb2b($ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );`\n\n\n\n**C2B Payment Request**\n\nThis is used to Simulate transfer of funds between a customer and business.\n\n\n`$mpesa= new \\Safaricom\\Mpesa\\Mpesa();`\n\n`$b2bTransaction=$mpesa-\u003ec2b($ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );`\n\n_Also important to note is that you should have registered validation and confirmation urls where the callback responses will be sent._\n\n\n\n**STK Push Simulation**\n\nThis is used to initiate online payment on behalf of a customer.\n\n`$mpesa= new \\Safaricom\\Mpesa\\Mpesa();`\n\n`$stkPushSimulation=$mpesa-\u003eSTKPushSimulation($BusinessShortCode, $LipaNaMpesaPasskey, $TransactionType, $Amount, $PartyA, $PartyB, $PhoneNumber, $CallBackURL, $AccountReference, $TransactionDesc, $Remarks);`\n\n\n\n**STK Push Status Query**\n\n This is used to check the status of a Lipa Na M-Pesa Online Payment.\n \n`$mpesa= new \\Safaricom\\Mpesa\\Mpesa();`\n\n`$STKPushRequestStatus=$mpesa-\u003eSTKPushQuery($checkoutRequestID,$businessShortCode,$password,$timestamp);`\n\n\n\n\n**Callback Routes**\nM-Pesa APIs are asynchronous. When a valid M-Pesa API request is received by the API Gateway, it is sent to M-Pesa where it is added to a queue. M-Pesa then processes the requests in the queue and sends a response to the API Gateway which then forwards the response to the URL registered in the CallBackURL or ResultURL request parameter. Whenever M-Pesa receives more requests than the queue can handle, M-Pesa responds by rejecting any more requests and the API Gateway sends a queue timeout response to the URL registered in the QueueTimeOutURL request parameter.\n\n**Obtaining post data from callbacks**\n This is used to get post data from callback in json format. The data can be decoded and stored in a database.\n \n `$mpesa= new \\Safaricom\\Mpesa\\Mpesa();`\n \n `$callbackData=$mpesa-\u003egetDataFromCallback();`\n  \n  **Finishing a transaction**\n  After obtaining the Post data from the callbacks, use this at the end of your callback routes to complete the transaction\n  \n  `$mpesa= new \\Safaricom\\Mpesa\\Mpesa();`\n  \n  `$callbackData=$mpesa-\u003efinishTransaction();`\n\n\n  If validation fails, pass `false` to `finishTransaction()`\n\n  `$mpesa= new \\Safaricom\\Mpesa\\Mpesa();`\n  \n  `$callbackData=$mpesa-\u003efinishTransaction(false);`\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuindi6602%2Fmpesa-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuindi6602%2Fmpesa-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuindi6602%2Fmpesa-php/lists"}