1. Go to this page and download the library: Download rielpays/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/ */
rielpays / laravel example snippets
use RielPay\Laravel\Facades\RielPay;
public function checkout(Order $order)
{
$payment = RielPay::createPayment([
'amount' => $order->total, // e.g. 4.50 (USD) or 18000 (KHR)
'currency' => 'USD',
'description' => "Order #{$order->id}",
'metadata' => ['order_id' => (string) $order->id],
'redirect_url' => route('orders.show', $order), // optional
], idempotencyKey: "order-{$order->id}"); // same key = same payment, never charged twice
$order->update(['rielpay_payment_id' => $payment->id]);
return redirect($payment->checkout_url); // RielPay's hosted KHQR page
}
use RielPay\Laravel\Events\PaymentSucceeded;
// app/Providers/AppServiceProvider.php → boot()
Event::listen(PaymentSucceeded::class, function (PaymentSucceeded $event) {
$order = Order::find($event->payment->metadata('order_id'));
$order?->markAsPaid($event->payment->id);
});
use RielPay\Laravel\Webhooks\Signature;
Signature::verify($request->getContent(), $request->header('X-Webhook-Signature'), config('rielpay.webhook_secret'));
$payment = RielPay::getPayment('pay_...'); // latest status
$page = RielPay::listPayments(['limit' => 20, 'status' => 'paid']);
foreach (RielPay::allPayments(['status' => 'paid']) as $payment) { /* every page, lazily */ }
bash
php artisan rielpay:install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.