PHPackages                             atendwa/mpesa-artisan - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. atendwa/mpesa-artisan

ActiveLibrary

atendwa/mpesa-artisan
=====================

A Laravel package designed to seamlessly integrate M-Pesa daraja APIs in your laravel project.

v1.0.0(1y ago)21.1k↓100%MITPHPPHP ^8.2

Since Jun 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/atendwa/mpesa-artisan)[ Packagist](https://packagist.org/packages/atendwa/mpesa-artisan)[ Docs](https://github.com/atendwa/mpesa-artisan)[ GitHub Sponsors](https://github.com/atendwa)[ RSS](/packages/atendwa-mpesa-artisan/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (12)Versions (2)Used By (0)

Integrate M-Pesa Effortlessly with Mpesa Artisan
================================================

[](#integrate-m-pesa-effortlessly-with-mpesa-artisan)

[![Latest Stable Version](https://camo.githubusercontent.com/2aaf39880c247e2010aba6b1211b6ade793bbbc7571a8245a0fab247110c2768/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6174656e6477612f6d706573612d6172746973616e2e737667)](https://packagist.org/packages/atendwa/mpesa-artisan)[![Total Downloads](https://camo.githubusercontent.com/5c09d9593b8f7476047673e711699762f3daf26e744bb4aa925ebc04f5a37aef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6174656e6477612f6d706573612d6172746973616e2e737667)](https://packagist.org/packages/atendwa/mpesa-artisan)[![PHP Version](https://camo.githubusercontent.com/a6d146c7916805cdaf50b10828d670462e76c667f091b6527a5ece454a64ebd7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6174656e6477612f6d706573612d6172746973616e)](https://packagist.org/packages/atendwa/mpesa-artisan)[![License](https://camo.githubusercontent.com/4482821266449919545b9d67d07dd0ad7094972a57aecf66648f1c115e83b644/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6174656e6477612f6d706573612d6172746973616e2e737667)](https://packagist.org/packages/atendwa/mpesa-artisan)[![Quality Score](https://camo.githubusercontent.com/91c76d4fd7fb02a6dba07e1e736dc85f7419f705b309f93dfdbdd79ef48bab4e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6174656e6477612f6d706573612d6172746973616e2f7068702d63732d66697865722e796d6c3f6c6162656c3d436f64652532305175616c697479)](https://github.com/atendwa/mpesa-artisan/actions/workflows/php-cs-fixer.yml)[![Code Style Status](https://camo.githubusercontent.com/b49f61ecf660b7af029fa1ba1104a7362242730b051b331427ae3e5ccf66810c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6174656e6477612f6d706573612d6172746973616e2f7068702d63732d66697865722e796d6c3f6c6162656c3d436f64652532305374796c65)](https://github.com/atendwa/mpesa-artisan/actions/workflows/php-cs-fixer.yml)

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 🥳🤯
------------------------------

[](#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! 🚗💨

    ```
        stk()->driver('web-store')->amount(5); //... chain more methods

        stk()->driver('donation')->amount(80); //... chain more methods
    ```
- 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! 🛠️🌟

    ```
       $sanitise = new SanitisePhoneNumber();
       $number = SanitisePhoneNumber::index('0712345678'); // returns 254712345678

       //or

       $number = sanitise_phone_number('0712345678');
    ```
- 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 handles `IP whitelisting` and `removes CSRF token verification`, making integration a breeze! 🚀✨

    ```
     Route::callback('/some-url', [SomeClass, 'do-something'])->name('name');
    ```

---

Installation via Composer
-------------------------

[](#installation-via-composer)

1. **Run the following command in your terminal to install the package:**

    ```
    composer require atendwa/mpesa-artisan
    ```
2. **Publish the Configuration File**

    After installing the package, publish the configuration file using the following Artisan command:

    ```
    php artisan mpesa-artisan:install
    ```

    **Published Configuration File**

    The configuration file `config/mpesa.php` should look like this:

    ```
     env('MPESA_ENVIRONMENT', 'sandbox'),

        // These are the base URLs for sandbox and live environments
        'urls' => [
            'sandbox' => env('MPESA_SANDBOX_URL', 'https://sandbox.safaricom.co.ke'),
            'live' => env('MPESA_LIVE_URL', 'https://api.safaricom.co.ke'),
        ],

        // These are the various API endpoints used in the application
        'endpoints' => [
            'access_token' => env('MPESA_ACCESS_TOKEN', 'oauth/v1/generate?grant_type=client_credentials'),
            'account_balance' => env('MPESA_ACCOUNT_BALANCE_ENDPOINT', 'mpesa/accountbalance/v1/query'),
            'transaction_status' => env('MPESA_TRANSACTION_STATUS', 'mpesa/transactionstatus/v1/query'),
            'c2b_register_url' => env('MPESA_C2B_REGISTER_URL_ENDPOINT', 'mpesa/c2b/v2/registerurl'),
            'business_buy_goods' => env('MPESA_BUSINESS_BUY_GOODS', 'mpesa/b2b/v1/paymentrequest'),
            'b2b_express_checkout' => env('MPESA_B2B_EXPRESS_ENDPOINT', 'v1/ussdpush/get-msisdn'),
            'business_pay_bill' => env('MPESA_BUSINESS_PAY_BILL', 'mpesa/b2b/v1/paymentrequest'),
            'mpesa_express' => env('MPESA_EXPRESS_ENDPOINT', 'mpesa/stkpush/v1/processrequest'),
            'stk_query' => env('MPESA_EXPRESS_QUERY_ENDPOINT', 'mpesa/stkpushquery/v1/query'),
            'dynamic_qr' => env('MPESA_DYNAMIC_QR_ENDPOINT', 'mpesa/qrcode/v1/generate'),
            'tax_remittance' => env('MPESA_TAX_REMITTANCE', 'mpesa/b2b/v1/remittax'),
            'reversal' => env('MPESA_REVERSAL_ENDPOINT', 'mpesa/reversal/v1/request'),
            'b2c' => env('MPESA_B2C_ENDPOINT', 'mpesa/b2c/v1/paymentrequest'),
        ],

        // Contains settings for different MPESA drivers
        'drivers' => [
            'default' => [
                'initiator_name' => env('MPESA_INITIATOR_NAME', ''),
                'passkey' => env('MPESA_PASSKEY', ''),

                'security_credential' => env('MPESA_SECURITY_CREDENTIAL', ''),

                'shortcodes' => [
                    'business' => env('MPESA_BUSINESS_SHORTCODE', ''),
                    'payment' => env('MPESA_PAYMENT_SHORTCODE', ''),
                ],

                'key_pairs' => [
                    'consumer' => [
                        'key' => env('MPESA_CONSUMER_KEY', ''),
                        'secret' => env('MPESA_CONSUMER_SECRET', ''),
                    ],
                    'payment' => [
                        'key' => env('MPESA_PAYMENT_CONSUMER_KEY', ''),
                        'secret' => env('MPESA_PAYMENT_CONSUMER_SECRET', ''),
                    ],
                ],

                'callbacks' => [
                    'default' => env('MPESA_DEFAULT_CALLBACK', ''),
                    'default_timeout_url' => env('MPESA_DEFAULT_TIMEOUT_URL', ''),
                ],
            ],
        ],

        // Additional configuration settings
        'configuration' => [
            'default_driver' => env('MPESA_DRIVER', 'default'),
            'sanitise_phone_number' => env('SANITISE_PHONE_NUMBER', true),
            'use_whitelist' => env('USE_IP_WHITELIST', true),
        ],

        // Cache settings for MPESA responses
        'cache' => [
            'enabled' => env('MPESA_CACHE_ENABLED', true),
            'prefix' => env('MPESA_CACHE_PREFIX', 'mpesa_artisan_cache'),
        ],

        // List of IPs allowed to access the application
        'whitelisted_ips' => [
            '196.201.214.200',
            '196.201.214.206',
            '196.201.213.114',
            '196.201.214.207',
            '196.201.214.208',
            '196. 201.213.44',
            '196.201.212.127',
            '196.201.212.138',
            '196.201.212.129',
            '196.201.212.136',
            '196.201.212.74',
            '196.201.212.69',
        ],
    ];
    ```
3. **Configure your .env File**

    Update your `.env` file with the necessary M-Pesa credentials:

    ```
    MPESA_ENVIRONMENT="live"
    MPESA_INITIATOR_NAME=""
    MPESA_PASSKEY=""
    MPESA_SECURITY_CREDENTIAL=""
    MPESA_BUSINESS_SHORTCODE=""
    MPESA_PAYMENT_SHORTCODE=""
    MPESA_CONSUMER_KEY=""
    MPESA_CONSUMER_SECRET=""
    MPESA_PAYMENT_CONSUMER_KEY=""
    MPESA_PAYMENT_CONSUMER_SECRET=""
    MPESA_DEFAULT_CALLBACK=""
    MPESA_DEFAULT_TIMEOUT_URL=""
    ```

---

Usage
-----

[](#usage)

Before diving into the array of available API endpoints, let's cover how you can easily call any of the service classes.:

```
// instantiate the class
$stk = new STK();
$response = $stk->amount(34)->post();

// use the global helper
stk()->amount(34)->post();

// use the Daraja Facade
\Atendwa\MpesaArtisan\Facades\Daraja::stk()->amount(56)->post();

// use the daraja global helper
daraja()->stk()->buyGoods()->amount(78)->post();
```

---

### Here are a few pointers to keep in mind:

[](#here-are-a-few-pointers-to-keep-in-mind)

- All API services provide a `driver('default')` method to change the `driver` dynamically. However, your custom driver must match the default driver's configuration keys. Exceptions will be thrown if the driver is misconfigured (e.g., the `initiator_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. Pass `false` 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 to `responseCode`.
- The `amount()` method accepts only `integers`, while other methods accept `strings`.
- **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.

    ```
        $response = stk_query()->checkoutRequestID($id)->post();
    ```
- 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 the `endpoint 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 the `Atendwa\MpesaArtisan\Support\SanitisePhoneNumber` class or its global helper function to help sanitize and transform phone numbers to the correct format.

    ```
        $number = sanitise_phone_number('0712345678'); // returns 25471234578
        $number = sanitise_phone_number('+254712345678'); // returns 25471234578
        $number = sanitise_phone_number('254712345678'); // returns 25471234578
    ```

---

### 1. Dynamic QR

[](#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.

```
$response = dynamic_qr()
                ->driver('default') // Optional: Specify a custom driver
                ->useConsumerKeyPair(true) // Optional: Toggle key pairs, defaults to true for consumer key and secret
                ->amount(100) // Required: sets the 'Amount' attribute
                ->buyGoods() // Optional: defaults the TrxCode attribute to 'BG'
                // ->paybill() sets TrxCode to 'PB'
                // ->sendMoney() sets TrxCode to 'SM'
                // ->sendToBusiness() sets TrxCode to 'SB'
                // ->withdrawFromAgent() sets TrxCode to 'WA'
                ->size(400) // Optional: default is 300
                ->merchantName('atendwa') // Required: sets the 'MerchantName' attribute
                ->reference('buy me a coffee') // Required: sets the 'RefNo' attribute
                ->creditPartyIdentifier('123456') // Required: sets the 'CreditPartyIdentifier (CPI)' attribute
                ->post();
```

---

### 2. M-Pesa Express Simulate (STK Push)

[](#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.

```
$response = stk()
        ->driver('default') // Optional: Specify a custom driver
        ->useConsumerKeyPair(true) // Optional: Toggle key pairs, defaults to true for consumer key and secret
        ->partyB('1234567') // Optional: Specify a shortcode, defaults to the business shortcode
        ->buyGoods() // Optional: Choose between 'buyGoods' or 'payBill', defaults to 'buyGoods'
        // ->payBill() // Optional: Choose between 'buyGoods' or 'payBill', defaults to 'buyGoods'
        ->callbackUrl('https://tendwa.dev') // Required: Specify the callback URL
        ->phoneNumber('254712345678') // Required: Specify the customer's phone number
        ->amount(1) // Required: Specify the amount to be transacted
        ->reference('test') // Required: Specify an account reference
        ->description('test') // Required: Specify a transaction description
        ->post();
```

---

### 3. M-Pesa Express Query (STK Query)

[](#3-m-pesa-express-query-stk-query)

Use this API to check the status of a Lipa Na M-Pesa Online Payment.

```
$response = stk_query()
        ->driver('default')  // Optional: defaults to 'default'
        ->useConsumerKeyPair(true) // Optional: defaults to true
        ->shortCode('1234567') // Optional: the package will attempt to use the business shortcode if not set
        ->checkoutRequestID($someID) // Required: The CheckoutRequestID from the STK push response
        ->post();
```

---

### 4. Customer To Business Register URL

[](#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.

```
$response = register_c2b_urls()
                ->driver('default') // Optional: Specify a custom driver
                ->useConsumerKeyPair(true) // Optional: Toggle key pairs, defaults to true for consumer key and secret
                ->shortCode('123456') // Required: Specify the short code
                ->completed() // Optional: the ResponseType is 'Completed' by default
                // ->cancelled() // Optional: sets the ResponseType attribute to 'Cancelled'
                ->confirmationUrl('https://tendwa.dev/package-sale/confirm') // Required: Specify the confirmation URL
                ->validationUrl('https://tendwa.dev/package-sale/validate') // Required: Specify the validation URL
                ->post();
```

---

### 5. Business To Customer (B2C)

[](#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.

```
$response = b2c()
                ->driver('default') // Optional: Specify a custom driver
                ->useConsumerKeyPair(false) // Optional: Toggle key pairs, defaults to true for consumer key and secret
                ->callbackUrl('https://tendwa.dev') // Required: Specify the callback URL
                ->timeoutUrl('https://tendwa.dev') // Required: Specify the timeout URL
                ->partyA('123456')
                ->partyB('254712345678')
                ->initiator('123456') // Optional: defaults to the initiator name in the config file
                ->amount(100) // Required: Specify the amount. Must be > 50 for safaricom to process the request
                ->remarks('test') // Required: Specify the transaction remarks
                ->occasion('test') // Required: Specify the transaction occasion
                ->post()
```

---

### 6. Transaction Status

[](#6-transaction-status)

Check the status of a transaction.

```
$response = transaction_status()
                ->driver('default') // Optional: Specify a custom driver
                ->useConsumerKeyPair(false) // Optional: Toggle key pairs, defaults to true for consumer key and secret
                ->initiator('initiator') // Optional: defaults to the initiator name in the config file
                ->partyA('1234567')
                ->transactionID('NEF61H8J60') // Optional: use this if you have a transaction ID
                // ->originatorConversationID('AG_20190826_0000777ab7d848b9e721') // Optional: use this if you don't have a transaction ID
                ->timeoutUrl('https://tendwa.dev') // Required: Specify the timeout URL
                ->callbackUrl('https://tendwa.dev') // Required: Specify the callback URL
                ->remarks('Transaction status request.') // Optional: defaults to 'Transaction status request.'
                ->occasion('Transaction status request.') // Optional: defaults to 'Transaction status request.'
                ->post();
```

---

### 7. Account Balance

[](#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.

```
$response = account_balance()
                ->driver('default') // Optional: Specify a custom driver
                ->useConsumerKeyPair(true) // Optional: Toggle key pairs, defaults to true for consumer key and secret
                ->partyA('123456')
                ->remarks('Get account balance.') // Optional: defaults to 'Get account balance.'
                ->timeoutUrl('https://tendwa.dev') // Required: Specify the timeout URL
                ->callbackUrl('https://tendwa.dev') // Required: Specify the callback URL
                ->post();
```

---

### 8. Reversals

[](#8-reversals)

```
$response = reversal()
                ->driver('default') // Optional: Specify a custom driver
                ->useConsumerKeyPair(true) // Optional: Toggle key pairs, defaults to true for consumer key and secret
                ->occasion('Transaction reversal request.') // Required: Specify the occasion transaction or defaults to 'Transaction reversal request.'.
                ->remarks('Transaction reversal request.') // Required: Specify the occasion transaction or defaults to 'Transaction reversal request.'.
                ->timeoutUrl('https://tendwa.dev') // Required: Specify the timeout URL
                ->callbackUrl('https://tendwa.dev') // Required: Specify the callback URL
                ->initiator('initiator') // Optional: defaults to the initiator name in the config file
                ->receiverParty('1234567')
                ->amount(100) // Required: Specify the amount
                ->transactionID('NEF61H8J60') // Optional: use this if you have a transaction ID
                ->post();
```

---

### 9. Tax Remittance

[](#9-tax-remittance)

```
$response = tax_remittance()
                ->driver('default') // Optional: Specify a custom driver
                ->useConsumerKeyPair(true) // Optional: Toggle key pairs, defaults to true for consumer key and secret
                ->initiator('initiator') // Optional: defaults to the initiator name in the config file
                ->callbackUrl('https://tendwa.dev') // Required: Specify the callback URL
                ->timeoutUrl('https://tendwa.dev') // Required: Specify the timeout URL
                ->partyA('1234567') // Required: Specify the shortcode
                ->partyB('572572') // Required: Specify the shortcode
                ->amount(100) // Required: Specify the amount
                ->remarks('Tax Remittance') // Optional: defaults to 'Tax Remittance'
                ->reference('Tax Remittance') // Optional: defaults to 'Tax Remittance'
                ->post();
```

---

### 10. Business Pay Bill

[](#10-business-pay-bill)

```
$response = business_pay_bill()
                ->driver('default') // Optional: Specify a custom driver
                ->useConsumerKeyPair(true) // Optional: Toggle key pairs, defaults to true for consumer key and secret
                ->initiator('initiator') // Optional: defaults to the initiator name in the config file
                ->callbackUrl('https://tendwa.dev') // Required: Specify the callback URL
                ->timeoutUrl('https://tendwa.dev') // Required: Specify the timeout URL
                ->partyA('1234567') // Required: Specify the shortcode
                ->partyB('572572') // Required: Specify the shortcode
                ->amount(100) // Required: Specify the amount
                ->remarks('Business Payment') // Optional: defaults to 'Business Payment'
                ->reference('Business Payment') // Optional: defaults to 'Business Payment'
                ->post();
```

---

### 11. Business Buy Goods

[](#11-business-buy-goods)

```
$response = business_buy_goods()
                ->driver('default') // Optional: Specify a custom driver
                ->useConsumerKeyPair(true) // Optional: Toggle key pairs, defaults to true for consumer key and secret
                ->initiator('initiator') // Optional: defaults to the initiator name in the config file
                ->callbackUrl('https://tendwa.dev') // Required: Specify the callback URL
                ->timeoutUrl('https://tendwa.dev') // Required: Specify the timeout URL
                ->partyA('1234567') // Required: Specify the shortcode
                ->partyB('572572') // Required: Specify the shortcode
                ->amount(100) // Required: Specify the amount
                ->remarks('Business Payment') // Optional: defaults to 'Business Payment'
                ->reference('Business Payment') // Optional: defaults to 'Business Payment'
                ->post();
```

---

### 12. B2B Express CheckOut

[](#12-b2b-express-checkout)

```
$response = b2b_express_checkout()
                ->driver('default') // Optional: Specify a custom driver
                ->useConsumerKeyPair(true) // Optional: Toggle key pairs, defaults to true for consumer key and secret
                ->primaryShortCode('1234567') // Required: Specify the primary short code
                ->receiverShortCode('572572') // Required: Specify the receiver short code
                ->amount(100) // Required: Specify the amount
                ->reference('Business Payment') // Required: Specify the reference
                ->callbackUrl('https://tendwa.dev') // Required: Specify the callback URL
                ->requestRefID($someUniqueID) // Required
                ->partnerName($yourStoreName) // Required
                ->post();
```

---

Helpers
-------

[](#helpers)

Check out some of the handy helper classes included in the package:

### **Mpesa Callback Request (MpesaCallbackRequest::class)**

[](#mpesa-callback-request-mpesacallbackrequestclass)

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).

```
use Atendwa\MpesaArtisan\Http\Requests\MpesaCallbackRequest;

public function handleStkCallback(MpesaCallbackRequest $request)
{
    $response = $request->fetchResponse(); // returns the response body as a collection
    $response->get('resultCode'); // returns the result code from the response body

    // for stk push
    $response->get('merchantRequestID');

    // for b2c
    $response->get('TransactionID'); // returns the result code from the response body

    $request->log(); // logs the response to your logging system with the info level

    $success = $request->successful(); // returns a boolean indicating if the transaction was successful by checking the result code
}
```

---

### **Sanitise Phone Number (SanitisePhoneNumber::class)**

[](#sanitise-phone-number-sanitisephonenumberclass)

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.

```
$number = sanitise_phone_number('0712345678'); // returns 254712345678
```

---

### **Parse Response (ParseResponse::class)**

[](#parse-response-parseresponseclass)

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.

```
$response = parse_response(stk()->post());

$response->get('successfulResponse');  // returns true if the response was successful

$response->get('responseCode');
```

###  Health Score

31

—

LowBetter than 71% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

656d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8f3391990d67fe49d89c238c9defd734b6f07f863c7f12c7674e9cfcde409f98?d=identicon)[atendwa](/maintainers/atendwa)

---

Top Contributors

[![atendwa](https://avatars.githubusercontent.com/u/125092307?v=4)](https://github.com/atendwa "atendwa (2 commits)")

---

Tags

darajalaravelmpesasafaricomlaravelb2bmpesaB2Csafaricommpesa-apidarajac2bdaraja-apistk-pushAtendwampesa-integrationmpesa-artisanmpesa laravelmpesa darajastk querympesa onlinempesa online payment

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/atendwa-mpesa-artisan/health.svg)

```
[![Health](https://phpackages.com/badges/atendwa-mpesa-artisan/health.svg)](https://phpackages.com/packages/atendwa-mpesa-artisan)
```

###  Alternatives

[aimeos/aimeos-laravel

Cloud native, API first Laravel eCommerce package with integrated AI for ultra-fast online shops, marketplaces and complex B2B projects

8.6k212.7k2](/packages/aimeos-aimeos-laravel)[smodav/mpesa

M-Pesa API implementation

16361.8k1](/packages/smodav-mpesa)[gathuku/laravelmpesa

A simple mpesa package for laravel framework

5217.6k](/packages/gathuku-laravelmpesa)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
