Logo Lanfrica

tishmalo/mpesa

Domaine:

digital infrastructure

Type de record:

software
Créateur:
tis
Hôte:
Mpesa package in laravel # Laravel M-Pesa Package A Laravel package for integrating M-Pesa Lipa Na M-Pesa STK Push payments. ## Installation 1. **Install the package via Composer:** ```bash composer require tish/laravel-mpesa ``` 2. **Publish the config file and migrations:** ```bash php artisan vendor:publish --provider="Tish\LaravelMpesa\MpesaServiceProvider" php artisan migrate ``` 3. **Add your M-Pesa credentials to your `.env` file:** ```env MPESA_CONSUMER_KEY=your_consumer_key MPESA_CONSUMER_SECRET=your_consumer_secret MPESA_PASSKEY=your_passkey MPESA_BUSINESS_SHORT_CODE=your_shortcode MPESA_CALLBACK_URL=yourdomain.com MPESA_SANDBOX=true ``` 4. **Create listeners to handle payment events:** ```bash php artisan make:listener HandleSuccessfulPayment php artisan make:listener HandleFailedPayment ``` 5. **Register the event listeners in your `app/Providers/EventServiceProvider.php`:** ```php [ \App\Listeners\HandleSuccessfulPayment::class, ], PaymentFailed::class => [ \App\Listeners\HandleFailedPayment::class, ], ]; public function boot() { // } } ``` 6. **Implement your listeners:** **`app/Listeners/HandleSuccessfulPayment.php`:** ```php transaction; Log::info('Payment completed', [ 'account_reference' => $transaction->account_reference, 'receipt_number' => $transaction->mpesa_receipt_number, 'amount' => $transaction->amount, 'phone' => $transaction->phone_number, ]); // Update your database here // Example: Find order by account_reference and mark as paid /* $order = Order::where('order_number', $transaction->account_reference)->first(); if ($order) { $order->update([ 'status' => 'paid', 'mpesa_receipt' => $transaction->mpesa_receipt_number, 'payment_date' => $transaction->transaction_date, ]); } */ } } ``` **`app/Listeners/HandleFailedPayment.php`:** ```php transaction; Log::warning('Payment failed', [ 'account_reference' => $transaction->account_reference, 'result_desc' => $transaction->result_desc, 'amount' => $transaction->amount, 'phone' => $tra …

Languages