M-Pesa payment invoices for Laravel
# laravel-mpesa-invoices
Auto-generates professional PDF invoices for M-Pesa payments and stores/emails them.
## Requirements
- PHP 8.1+
- Laravel 10 / 11 / 12 / 13
- `felixmuhoro/laravel-mpesa: ^1.2`
- `barryvdh/laravel-dompdf: ^2.0`
## Installation
```bash
composer require felixmuhoro/laravel-mpesa-invoices
```
Publish the config file:
```bash
php artisan vendor:publish --tag=mpesa-invoices-config
```
Run migrations:
```bash
php artisan migrate
```
## Configuration
Set the following in your `.env`:
```dotenv
INVOICE_BUSINESS_NAME="Acme Kenya Ltd"
INVOICE_BUSINESS_ADDRESS="P.O. Box 12345-00100, Nairobi, Kenya"
INVOICE_BUSINESS_PHONE="+254 700 123 456"
INVOICE_BUSINESS_EMAIL="billing@acme.co.ke"
INVOICE_BUSINESS_WEBSITE="
acme.co.ke"
INVOICE_KRA_PIN="P051234567X"
INVOICE_VAT_NUMBER="V000123456Z" # optional
INVOICE_TAX_RATE=16 # VAT percentage (Kenyan standard)
INVOICE_TAX_ENABLED=true
INVOICE_CURRENCY=KES
INVOICE_AUTO_EMAIL=false # auto-email on PaymentSuccessful event
INVOICE_STORAGE_DISK=local
INVOICE_STORAGE_PATH=invoices
```
## Usage
### Basic — from a payment array
```php
use FelixMuhoro\MpesaInvoices\Invoice;
$invoice = Invoice::fromPayment([
'mpesa_receipt' => 'QHX1234567',
'amount' => 1500.00,
'phone' => '0712345678',
'customer_name' => 'Jane Doe',
'customer_email' => 'jane@example.com',
'description' => 'Premium Subscription',
]);
// Download as PDF response
return $invoice->download();
// Get HTML string
$html = $invoice->toHtml();
// Store PDF to disk + create DB record
$record = $invoice->store();
// Send email (with PDF attachment)
$invoice->send('jane@example.com');
```
### Via Facade
```php
use FelixMuhoro\MpesaInvoices\Facades\MpesaInvoice;
$invoice = MpesaInvoice::createFromPayment($paymentArray, store: true);
$record = MpesaInvoice::findByReceipt('QHX1234567');
$record = MpesaInvoice::findByNumber('INV-202401-0001');
```
### With multiple line items
```php
$invoice …