Skip to content

Hosted checkout in 20 minutes

Create a checkout session on your server, send the buyer to the hosted checkout with the React button, and handle the return to your site.

With the hosted checkout, your site decides the amount per order. Your server creates a checkout session with its secret key, the buyer pays on the Arbiro checkout page, and returns to your success_url.

1. Create the session on your server

Never use the secret key in the browser. Expose a small endpoint on your server that creates the session for the current order.

// app/api/checkout/route.ts (Next.js) or any Node server
import { Arbiro } from "@arbiro/sdk";

const arbiro = new Arbiro({ apiKey: process.env.ARBIRO_API_KEY! });

export async function POST() {
  const session = await arbiro.checkoutSessions.create(
    {
      amount: 25_000_000n, // 25.00 USDC
      token: "USDC",
      category: "digital",
      merchant_reference: "order_1042",
      success_url: "https://shop.example/thanks",
      cancel_url: "https://shop.example/cart",
    },
    { idempotencyKey: "order_1042" }, // retrying never creates a second session
  );
  return Response.json({ hosted_url: session.hosted_url });
}
# FastAPI
import os
import httpx
from fastapi import FastAPI

app = FastAPI()

@app.post("/api/checkout")
async def checkout() -> dict[str, str]:
    async with httpx.AsyncClient() as client:
        response = await client.post(
            "https://arbiro.com/v1/checkout-sessions",
            headers={
                "Authorization": f"Bearer {os.environ['ARBIRO_API_KEY']}",
                "Idempotency-Key": "order_1042",
            },
            json={
                "amount": "25000000",
                "token": "USDC",
                "category": "digital",
                "merchant_reference": "order_1042",
                "success_url": "https://shop.example/thanks",
                "cancel_url": "https://shop.example/cart",
            },
        )
    response.raise_for_status()
    return {"hosted_url": response.json()["hosted_url"]}
curl https://arbiro.com/v1/checkout-sessions \
  -H "Authorization: Bearer $ARBIRO_API_KEY" \
  -H "Idempotency-Key: order_1042" \
  -H "Content-Type: application/json" \
  -d '{"amount":"25000000","token":"USDC","category":"digital","merchant_reference":"order_1042","success_url":"https://shop.example/thanks"}'

The hosted_url carries the session's client secret in the URL fragment (/pay/cs_...#secret). Browsers never send the fragment to any server.

2. Add the button

@arbiro/sdk/react exports a button that calls your endpoint and sends the buyer to the checkout. It only follows URLs on the Arbiro checkout, so a tampered response cannot redirect your buyers anywhere else.

import { ArbiroCheckoutButton } from "@arbiro/sdk/react";

export function PayButton() {
  return (
    <ArbiroCheckoutButton
      createSession={async () => (await fetch("/api/checkout", { method: "POST" })).json()}
      onError={(error) => alert(error.message)}
      className="pay-button"
    >
      Pay 25.00 USDC with buyer protection
    </ArbiroCheckoutButton>
  );
}
<button id="pay">Pay 25.00 USDC with buyer protection</button>
<script>
  document.getElementById("pay").addEventListener("click", async () => {
    const { hosted_url } = await (await fetch("/api/checkout", { method: "POST" })).json();
    const url = new URL(hosted_url);
    if (url.origin === "https://arbiro.com" && url.pathname.startsWith("/pay/")) window.location.assign(url);
  });
</script>

3. Handle the return

After the payment, the checkout sends the buyer to your success_url with two query parameters:

Parameter Meaning
arbiro_payment_id The on-chain payment id (0x and 64 hex characters).
arbiro_delivery_token A single-use token (dt_...) your backend redeems before delivering a digital product.

Do not trust the redirect alone: confirm the payment with the payment.locked webhook or GET /v1/payments/{id}. For digital goods, redeem the token as described in Delivery tokens; it becomes your proof of delivery if the buyer disputes.

Sessions expire

A session stays open until the buyer pays or it expires (expires_at). The signed terms the buyer receives are valid for 30 minutes, so the buyer always pays exactly what was quoted.

Updated