malipopay / laravel
Official Laravel package for Malipopay - Service Provider, Facade, Blade directives, Eloquent model, and webhook handling for mobile money, bank, card, and USSD payments in Tanzania
Requires
- php: ^8.1
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- malipopay/malipopay-php: ^1.1
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
README
Official Laravel integration for Malipopay. Service Provider, Facade, Eloquent models, Blade directives, webhook handling, and artisan commands for accepting payments in Tanzania via Mobile Money, Bank Transfer, USSD, and Card.
Wraps the malipopay/malipopay-php SDK with Laravel conveniences.
Installation
composer require malipopay/laravel
Install the config and migrations:
php artisan malipopay:install
Add to .env:
MALIPOPAY_API_KEY=your_api_key_here MALIPOPAY_ENVIRONMENT=uat MALIPOPAY_WEBHOOK_SECRET=your_webhook_secret
Quick Start
Collect a payment
use Malipopay\Laravel\Facades\Malipopay; $payment = Malipopay::collect([ 'description' => 'Order #1234', 'amount' => 10000, 'phoneNumber' => '255712345678', ]); // $payment is an Eloquent MalipopayPayment model — already saved in your DB echo $payment->reference; echo $payment->status; echo $payment->link;
Disburse funds
Malipopay::disburse([ 'description' => 'Salary payment', 'amount' => 50000, 'phoneNumber' => '255712345678', ]);
Verify a payment
$payment = Malipopay::verify('PAY-abc123');
Create a payment link
$link = Malipopay::createPaymentLink([ 'amount' => 25000, 'phoneNumber' => '255712345678', ]); return redirect($link->link);
Access any resource from the underlying SDK
$customers = Malipopay::customers->list(); $invoice = Malipopay::invoices->create([...]); Malipopay::sms->send([...]);
Webhooks
The package registers a POST route at /webhooks/malipopay automatically (configurable). It verifies the signature, stores the event, updates the payment model, and fires Laravel events you can listen to.
Listen to events
// app/Providers/EventServiceProvider.php use Malipopay\Laravel\Events\PaymentCompleted; use Malipopay\Laravel\Events\PaymentFailed; use App\Listeners\FulfillOrder; protected $listen = [ PaymentCompleted::class => [FulfillOrder::class], PaymentFailed::class => [NotifyCustomerPaymentFailed::class], ];
Listener example
use Malipopay\Laravel\Events\PaymentCompleted; class FulfillOrder { public function handle(PaymentCompleted $event): void { $payment = $event->payment; // MalipopayPayment model // update your order, send confirmation email, etc. } }
Available events
| Event | Fired when |
|---|---|
PaymentCompleted |
Collection successfully completed |
PaymentFailed |
Collection failed, reversed, or cancelled |
DisbursementCompleted |
Disbursement successfully completed |
WebhookReceived |
Catch-all, fired for every verified webhook |
Eloquent Model
MalipopayPayment stores every payment made through the package.
use Malipopay\Laravel\Models\MalipopayPayment; $pending = MalipopayPayment::pending()->count(); $completed = MalipopayPayment::completed()->whereDate('created_at', today())->sum('amount'); $payment = MalipopayPayment::where('reference', 'PAY-123')->first(); if ($payment->isCompleted()) { // ... }
Blade Directives
{{-- Insert a checkout button --}} @malipopayCheckout(['amount' => 10000, 'phone' => '255712345678', 'description' => 'Order #1234']) {{-- Format an amount --}} <span>@malipopayAmount(10000)</span> {{-- TZS 10,000 --}} <span>@malipopayAmount(10000, 'USD')</span> {{-- USD 10,000 --}}
Artisan Commands
# Install config and migrations php artisan malipopay:install # Send a test payment (use UAT) php artisan malipopay:test 255712345678 --amount=100 --description="Test"
Configuration
After publishing the config file (config/malipopay.php), you can customize:
- API key and environment
- Timeout and retry behavior
- Webhook path, signature header, and event storage
- Which Eloquent model to use (extend
MalipopayPayment) - Whether to auto-register webhook routes
Requirements
- PHP 8.1+
- Laravel 10, 11, or 12
- Malipopay API key (get one here)
License
MIT
See Also
| SDK | Install |
|---|---|
| Laravel (this package) | composer require malipopay/laravel |
| PHP (raw SDK) | composer require malipopay/malipopay-php |
| Node.js | npm install malipopay |
| Python | pip install malipopay |
| Java | Maven / Gradle |
| .NET | dotnet add package Malipopay |
| Ruby | gem install malipopay |
| Flutter/Dart | flutter pub add malipopay |
| React | npm install @malipopay/react |