1. Go to this page and download the library: Download monapay/laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
monapay / laravel example snippets
use MonaPay\Laravel\Facades\MonaPay;
$qr = MonaPay::createVietQrForOrder(
orderId: $order->getKey(),
amount: $order->total,
);
use Illuminate\Support\Facades\Event;
use MonaPay\Laravel\Events\PaymentReceived;
use MonaPay\Laravel\Support\PaymentMatcher;
Event::listen(PaymentReceived::class, function (PaymentReceived $event): void {
$orderId = PaymentMatcher::extractOrderId((string) $event->payload['description']);
$order = $orderId !== null ? Order::find($orderId) : null;
if (!$order || !$event->matchesOrder($order->getKey(), $order->total)) {
return;
}
// transaction_code needs a unique index so webhook retries are not processed twice.
Payment::firstOrCreate(
['transaction_code' => $event->transactionCode()],
['order_id' => $order->getKey(), 'amount' => $event->amount()],
);
});
bash
php artisan monapay:test-webhook
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.