Laravel makes a tidy UPI integration easy.
1. Configuration
Store UPI_SECRET_KEY, UPI_SIGNING_SECRET and UPI_BASE_URL in .env and read them from config/services.php.
2. Creating an order
$res = Http::withToken(config('services.upi.key'))
->post(config('services.upi.url').'/api/v1/orders', [
'amount' => $order->total, 'order_id' => $order->number,
'redirect_url' => route('orders.thanks', $order),
])->json('data');
return redirect()->away($res['payment_url']);
3. The webhook route
Add the route to the CSRF exceptions, verify the signature, then dispatch a job. Make the job idempotent: if the order is already paid, return.
4. The thank-you page
Show the status from your database; if it is still pending, poll your own endpoint for a few seconds.
0 comments