Dynamic QR
Generates a QR code M-Pesa app users scan to capture your till number and the amount, then authorise payment. Unlike most of Daraja, this one is synchronous — the code comes back in the response.
POST mpesa/qrcode/v1/generate
use Starnerz\LaravelDaraja\Enums\QrTransactionType;
$qr = Daraja::qr()->generate( merchantName: 'Test Supermarket', reference: 'INV-9', amount: 1200, type: QrTransactionType::BuyGoods, size: 300,);Using the image
Section titled “Using the image”The API returns base64 PNG data. Two helpers save you decoding it:
// Embed straight into a Blade view<img src="{{ $qr->dataUri() }}" alt="Scan to pay">
// Or store the raw bytesStorage::put("qr/{$invoice->id}.png", $qr->png());Transaction types
Section titled “Transaction types”| Enum | Code | Meaning |
|---|---|---|
QrTransactionType::BuyGoods |
BG |
Pay merchant (buy goods) |
QrTransactionType::WithdrawAtAgent |
WA |
Withdraw cash at an agent till |
QrTransactionType::PayBill |
PB |
Pay bill or business number |
QrTransactionType::SendMoney |
SM |
Send money to a mobile number |
QrTransactionType::SendToBusiness |
SB |
Send to business, CPI in MSISDN format |
The credit party defaults to your configured short code. Override it when the QR should point somewhere else:
Daraja::qr()->generate('Shop', 'REF', 500, QrTransactionType::PayBill, creditPartyIdentifier: '174379',);Payment notification
Section titled “Payment notification”Scanning produces an ordinary C2B payment, so the money arrives through your C2B confirmation URL. This API only makes the image.