Download the PHP package atendwa/mpesa-artisan without Composer
On this page you can find all versions of the php package atendwa/mpesa-artisan. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download atendwa/mpesa-artisan
More information about atendwa/mpesa-artisan
Files in atendwa/mpesa-artisan
Package mpesa-artisan
Short Description A Laravel package designed to seamlessly integrate M-Pesa daraja APIs in your laravel project.
License MIT
Homepage https://github.com/atendwa/mpesa-artisan
Informations about the package mpesa-artisan
Integrate M-Pesa Effortlessly with Mpesa Artisan
This Laravel package seamlessly integrates M-Pesa payment services, allowing you to effortlessly handle M-Pesa transactions within your Laravel applications. It's the perfect solution for businesses and individuals seeking a reliable mobile money integration.
Shipped with a little magic 🥳🤯
This package has a lot to offer, but I think you'll love these features the most:
-
Secure Callbacks with IP Whitelisting: Our
AllowWhitelistedMpesaIps
middleware adds an extra layer of security by verifying that the IP address sending the callback is whitelisted and valid. -
I've implemented
12/13
of M-Pesa's APIs for your convenience. The 13th API is on its way! Stay tuned for even more functionality. 🎉🚀 -
Yes, you guessed it
drivers!
With this package, you can set up multiple drivers to handle different M-Pesa credentials for your app. Just add them to the mpesa.php config file, and you're good to go! 🚗💨 -
Our package includes useful helper classes and functions like a phone number sanitizer, a callback request class and more. Plus, most classes have corresponding global helper functions for added convenience! 🛠️🌟
- And finally, why not try the
Route::callback()
macro? It lets you set up callback routes in a snap, right in your route file. It handlesIP whitelisting
andremoves CSRF token verification
, making integration a breeze! 🚀✨
Installation via Composer
-
Run the following command in your terminal to install the package:
-
Publish the Configuration File
After installing the package, publish the configuration file using the following Artisan command:
Published Configuration File
The configuration file
config/mpesa.php
should look like this: -
Configure your .env File
Update your
.env
file with the necessary M-Pesa credentials:
Usage
Before diving into the array of available API endpoints, let's cover how you can easily call any of the service classes.:
Here are a few pointers to keep in mind:
-
All API services provide a
driver('default')
method to change thedriver
dynamically. However, your custom driver must match the default driver's configuration keys. Exceptions will be thrown if the driver is misconfigured (e.g., theinitiator_name
key must always be present). -
All API services also offer a
useConsumerKeyPair(true)
method to toggle between key pairs. By default,consumer key pairs
are used. Passfalse
to use payment keys, ensuring they match the provided shortcode. Incorrect pairs can lock your security credentials. -
All API services return instances of
Illuminate\Support\Collection
with keys in camel case. For example,ResponseCode
in the response body will be transformed toresponseCode
. -
The
amount()
method accepts onlyintegers
, while other methods acceptstrings
. -
Type safety is enforced in the package. Passing an invalid type to a method will throw an exception or use a fallback value. Empty strings may be used if an invalid string type is encountered.
-
Different API services assume default values for the driver, key pairs, remarks, occasion, shortcode, and more, so you don't need to call every single method.
-
Each API service specifies its required attributes for the payload. If any required attribute is blank, an exception will be thrown.
-
To use a different
API version
, simply override theendpoint URL
for the desired endpoint in your.env
file. - Phone numbers should be in the format
254#########
. While the package doesn't validate the values you pass, you can use theAtendwa\MpesaArtisan\Support\SanitisePhoneNumber
class or its global helper function to help sanitize and transform phone numbers to the correct format.
1. Dynamic QR
Use this API to generate a Dynamic QR code, enabling Safaricom M-PESA customers with the My Safaricom App or M-PESA app to scan the QR code. They can then capture the till number and amount and authorize payment for goods and services at select LIPA NA M-PESA (LNM) merchant outlets.
https://developer.safaricom.co.ke/APIs/DynamicQRCode
2. M-Pesa Express Simulate (STK Push)
The Lipa na M-PESA online API, also known as M-PESA Express (STK Push/NI push), facilitates Merchant/Business-initiated C2B (Customer to Business) payments.
https://developer.safaricom.co.ke/APIs/MpesaExpressSimulate
3. M-Pesa Express Query (STK Query)
Use this API to check the status of a Lipa Na M-Pesa Online Payment.
https://developer.safaricom.co.ke/APIs/MpesaExpressQuery
4. Customer To Business Register URL
The Register URL API complements the Customer to Business (C2B) APIs by enabling the receipt of payment notifications to your paybill. This API allows you to register callback URLs through which you will receive notifications for payments made to your pay bill/till number.
https://developer.safaricom.co.ke/APIs/CustomerToBusinessRegisterURL
5. Business To Customer (B2C)
The B2C API allows businesses to make payments directly to customers, such as salary payments, cashback, promotional payments, winnings, withdrawals, and loan disbursements.
https://developer.safaricom.co.ke/APIs/BusinessToCustomer
6. Transaction Status
Check the status of a transaction.
https://developer.safaricom.co.ke/APIs/TransactionStatus
7. Account Balance
The Account Balance API is used to request the balance of a short code, applicable to B2C, buy goods, and pay bill accounts.
https://developer.safaricom.co.ke/APIs/AccountBalance
8. Reversals
https://developer.safaricom.co.ke/APIs/Reversal
9. Tax Remittance
https://developer.safaricom.co.ke/APIs/TaxRemittance
10. Business Pay Bill
https://developer.safaricom.co.ke/APIs/BusinessPayBill
11. Business Buy Goods
https://developer.safaricom.co.ke/APIs/BusinessBuyGoods
12. B2B Express CheckOut
https://developer.safaricom.co.ke/APIs/B2BExpressCheckout
Helpers
Check out some of the handy helper classes included in the package:
Mpesa Callback Request (MpesaCallbackRequest::class)
This class extends Laravel's Http Request class with additional features for parsing M-Pesa callback results and checking transaction success status.
-
All methods from the
Illuminate\Http\Request
class are available. - The
fetchResponse()
method automatically parses the response body, allowing you to directly access the result code without needing to navigate through nested arrays for different callback types (e.g., STK, B2C).
Sanitise Phone Number (SanitisePhoneNumber::class)
This class sanitizes phone numbers, transforming them to the desired format. It has a single method, index
, which accepts a phone number and returns the sanitized version.
Parse Response (ParseResponse::class)
This class parses API responses from Safaricom. It has a single method, index
, which accepts a response
and returns a parsed version. The parsed response will have camel case keys, successfulResponse
and successfulResult
indicators for success, and a hasErrors
key for errors. This class is used internally to ensure consistent response parsing.
All versions of mpesa-artisan with dependencies
ext-openssl Version *