PHPackages                             felixmuhoro/laravel-mpesa-livewire - 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. [Payment Processing](/categories/payments)
4. /
5. felixmuhoro/laravel-mpesa-livewire

ActiveLibrary[Payment Processing](/categories/payments)

felixmuhoro/laravel-mpesa-livewire
==================================

Livewire M-Pesa payment components

v1.0.0(1mo ago)00MITPHPPHP ^8.1

Since Jun 4Pushed 1mo agoCompare

[ Source](https://github.com/felixmuhoro/laravel-mpesa-livewire)[ Packagist](https://packagist.org/packages/felixmuhoro/laravel-mpesa-livewire)[ Docs](https://github.com/felixmuhoro/laravel-mpesa-livewire)[ RSS](/packages/felixmuhoro-laravel-mpesa-livewire/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

laravel-mpesa-livewire
======================

[](#laravel-mpesa-livewire)

Livewire v3 components for M-Pesa payment flows. Drop-in checkout button, payment history, real-time status polling, and a compact wallet widget — all styled with Tailwind and wired with proper Livewire 3 patterns.

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10 / 11 / 12 / 13
- Livewire 3.x
- [felixmuhoro/laravel-mpesa](https://github.com/felixmuhoro/laravel-mpesa) ^1.2

Installation
------------

[](#installation)

```
composer require felixmuhoro/laravel-mpesa-livewire
```

The service provider auto-registers via Laravel package discovery.

Publish the config:

```
php artisan vendor:publish --tag=mpesa-livewire-config
```

Optionally publish views to customise them:

```
php artisan vendor:publish --tag=mpesa-livewire-views
```

Components
----------

[](#components)

### ``

[](#livewirempesa-stk-push-button-)

Full STK push checkout flow with state machine: idle → initiating → awaiting\_confirmation → success | failed. Polls the Daraja STK query endpoint every 3 seconds while waiting for the user's PIN.

```
{{-- Fixed amount --}}

{{-- User-entered amount --}}

```

**Props**

PropTypeDefaultDescription`amount`float`0`Amount in KES. If 0, renders an amount input.`phone`string`''`Pre-fill phone. Falls back to authenticated user's phone column.`reference`string`'Payment'`Account reference (max 12 chars).`description`string`'M-Pesa Payment'`Transaction description (max 13 chars).**Events dispatched**

EventPayloadDescription`mpesa-stk-initiated``{checkoutRequestId, phone, amount}`STK push accepted`mpesa-payment-success``{checkoutRequestId, receiptNumber, amount, phone}`Payment confirmed`mpesa-payment-failed``{checkoutRequestId, resultCode}`Payment failed/cancelled**Listening to events in parent components:**

```
#[On('mpesa-payment-success')]
public function onPaymentSuccess(array $event): void
{
    Order::where('reference', $this->reference)
        ->update([
            'status'         => 'paid',
            'mpesa_receipt'  => $event['receiptNumber'],
        ]);
}
```

---

### ``

[](#livewirempesa-payment-history-)

Paginated, filterable, sortable transaction table scoped to the authenticated user.

```

```

Filters: date range, status, amount range, free-text search (phone / receipt / reference).

URL query parameters are synced via `#[Url]` so filters survive page refresh.

---

### ``

[](#livewirempesa-payment-status-)

Real-time status card. Given a `checkout_request_id`, polls every 3 seconds and shows animated feedback.

```

```

States: pending (spinning) → completed (green checkmark) → failed/cancelled (red X).

**Events dispatched**

EventPayload`mpesa-status-confirmed``{checkoutRequestId, receiptNumber}`Also listens to `echo:payments,PaymentConfirmed` for instant broadcast updates if you have Laravel Echo configured.

---

### ``

[](#livewirempesa-widget-)

Compact collapsible widget combining a mini balance display with a quick-pay form. Ideal for sidebars or dashboards.

```

```

Configure how balance is resolved in `config/mpesa-livewire.php`:

```
// Use a column on the users table
'user_balance_column' => 'wallet_balance',

// Or a custom callable
'balance_resolver' => fn ($user) => $user->wallet->availableBalance(),
```

Configuration
-------------

[](#configuration)

`config/mpesa-livewire.php`:

```
return [
    'transactions_table'  => 'mpesa_transactions', // DB table
    'user_phone_column'   => 'phone',              // Column for pre-filling phone
    'user_balance_column' => 'balance',            // Column for wallet balance
    'balance_resolver'    => null,                 // Custom callable (overrides column)
    'scope_to_user'       => true,                 // Scope history to auth user
    'poll_max_attempts'   => 20,                   // Polls before timeout (3s each = 60s)
    'receipt_route'       => 'mpesa.receipt',      // Named route for receipt downloads
];
```

Styling
-------

[](#styling)

All components use Tailwind CSS utility classes. No additional CSS is required if you have Tailwind in your project. To customise, publish the views and edit them directly.

M-Pesa brand green: `#00A651` / `#007A3D`.

Events &amp; Broadcasting
-------------------------

[](#events--broadcasting)

To enable instant confirmation (instead of polling), fire a `PaymentConfirmed` broadcast event on your server after receiving the M-Pesa callback:

```
broadcast(new PaymentConfirmed($checkoutRequestId, $receiptNumber))
    ->toOthers();
```

The `PaymentStatus` component listens on `echo:payments,PaymentConfirmed` and will stop polling immediately on receipt.

Testing
-------

[](#testing)

```
composer test
```

Tests use Livewire's `Livewire::test()` helper and mock the `mpesa` service binding.

License
-------

[](#license)

MIT — [Felix Muhoro](https://felixmuhoro.dev)

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

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

50d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4e43995a8ec026a33d25263c30f437674d6d8481092cb3acd64e96e4ba3f4e4?d=identicon)[felixmuhoro](/maintainers/felixmuhoro)

---

Tags

laravelmpesakenyasafaricom

### Embed Badge

![Health badge](/badges/felixmuhoro-laravel-mpesa-livewire/health.svg)

```
[![Health](https://phpackages.com/badges/felixmuhoro-laravel-mpesa-livewire/health.svg)](https://phpackages.com/packages/felixmuhoro-laravel-mpesa-livewire)
```

PHPackages © 2026

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