API reference

Integration examples

Copy-paste starting points.

Next.js (App Router)
// app/api/checkout/route.ts  (server only: the secret key never reaches the browser)
export async function POST(req: Request) {
  const { orderId } = await req.json();
  const order = await db.order.findUniqueOrThrow({ where: { id: orderId } });

  const res = await fetch("https://api.brightsecuretech.com/v1/checkout/sessions", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.BST_SECRET_KEY}`,
      "Idempotency-Key": `order-${order.id}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      amount_minor: order.totalPesewas,          // integer pesewas, from YOUR database
      currency: "GHS",
      description: order.summary,
      merchant_reference: order.id,
      customer_email: order.email,
      success_url: `https://yourshop.com/orders/${order.id}/thanks`,
      cancel_url: "https://yourshop.com/cart",
    }),
  });
  if (!res.ok) return Response.json({ error: "Could not start payment" }, { status: 502 });
  const { checkout_url } = await res.json();
  return Response.json({ checkout_url });   // redirect the customer here
}
Laravel
// routes/web.php
Route::post('/checkout/{order}', function (Order $order) {
    $res = Http::withToken(config('services.bst.secret'))
        ->withHeaders(['Idempotency-Key' => 'order-'.$order->id])
        ->post('https://api.brightsecuretech.com/v1/checkout/sessions', [
            'amount_minor'       => $order->total_pesewas,
            'currency'           => 'GHS',
            'description'        => $order->summary,
            'merchant_reference' => (string) $order->id,
            'customer_email'     => $order->email,
            'success_url'        => route('orders.thanks', $order),
            'cancel_url'         => route('cart'),
        ])->throw();

    return redirect()->away($res->json('checkout_url'));
});

Then

Handle the payment.success webhook (see Webhooks) and mark the order paid only after the signature and amount check.