Skip to content

Developer guide

Checkout with Razorpay in your own page

Checkout turns a signed-in buyer's cart into an order. Call POST /checkout with the cart, the delivery address and an Idempotency-Key; the answer carries a Razorpay order to open in your page. After the buyer pays, send Razorpay's three ids to POST /checkout/{number}/confirm. The order is paid when RapBooster has verified the payment, and the store.order.paid webhook follows.

Guide

Step by step

Place the order

Add the address first (POST /me/addresses), then check out with its id. metadata (up to 20 string keys) is stored on the order and echoed in every order webhook, which is how a site ties an order to its own records.

JavaScript (@rapbooster/sdk)

const { data, error } = await rb.store.checkout.create(
  {
    cart_id: cartId,
    address_id: addressId,
    channel: "web",
    payment_method: "razorpay",
    consent: { terms: true },
    metadata: { source: "my-site" },
  },
  { idempotencyKey: crypto.randomUUID() } // reuse it when you retry
);
if (error) {
  // CART_CHANGED, OUT_OF_STOCK, PINCODE_NOT_SERVICEABLE, MOQ_NOT_MET, CREDIT_LIMIT
  throw new Error(error.code);
}
const { order_number, razorpay } = data!.data;

Pay and confirm

Open Razorpay Checkout with razorpay.key_id and razorpay.order_id. In its success handler send the payment back; a bad signature answers PAYMENT_VERIFY_FAILED. If the buyer closes the page after paying, RapBooster's own Razorpay webhook still marks the order paid.

JavaScript

new Razorpay({
  key: razorpay.key_id,
  order_id: razorpay.order_id,
  handler: async (r) => {
    await rb.store.checkout.confirm(order_number, {
      razorpay_order_id: r.razorpay_order_id,
      razorpay_payment_id: r.razorpay_payment_id,
      razorpay_signature: r.razorpay_signature,
    });
  },
}).open();

After the order

The buyer sees it at GET /me/orders/{number} with its shipments, claims and invoice (GET /me/orders/{number}/invoice answers a 10-minute link to the GST invoice PDF). Approved trade buyers can pay on credit with payment_method: "credit".