What you build

Three pieces in your Next.js app (App Router): a route handler that creates a Gateway payment intent with your API key, a page that shows a Solana Pay QR code and follows the payment status, and a route handler that receives the signed callback from Gateway.

Register your business first to get the API key and webhook secret. Keep both in server-only environment variables.

Environment variables
# .env.local of your Next.js app. Server-only: no NEXT_PUBLIC_ prefix.
GATE_URL=https://gate.solknife.xyz
GATE_API_KEY=sk_live_...
GATE_WEBHOOK_SECRET=...

1. Create the payment on the server

The route handler calls POST /api/payments with the x-gateway-key header and returns only the fields the browser needs. The API key stays on the server.

The response holds two ways to pay. checkoutUrl is the Gateway hosted checkout. solanaPayTransactionUrl is a Solana Pay transaction request URL (solana:https://...) that a wallet app opens to get the payment transaction.

Create the payment in a route handler
// app/orders/[orderId]/pay/route.ts
import { NextResponse } from "next/server";

const GATE_URL = process.env.GATE_URL;

type Context = { params: Promise<{ orderId: string }> };

// Creates the Gateway payment for an order.
export async function POST(_request: Request, context: Context) {
  const { orderId } = await context.params;
  const order = await loadOrder(orderId); // your own data

  const response = await fetch(`${GATE_URL}/api/payments`, {
    method: "POST",
    headers: {
      "content-type": "application/json",
      "x-gateway-key": process.env.GATE_API_KEY ?? "",
    },
    body: JSON.stringify({
      checkoutReference: order.id,
      customerTelegramChatId: order.customerTelegramChatId,
      merchantAmountRaw: order.amountRaw,
    }),
  });
  const result = await response.json();
  if (!result.ok) {
    return NextResponse.json(result, { status: response.status });
  }

  const { id, reference, checkoutUrl, solanaPayTransactionUrl, expiresAt } = result.data;
  await savePayment(orderId, id, reference); // your own data
  // Never send the API key to the browser. These fields are safe to share.
  return NextResponse.json({ checkoutUrl, solanaPayTransactionUrl, expiresAt });
}

// Returns the payment status for the order page to poll.
export async function GET(_request: Request, context: Context) {
  const { orderId } = await context.params;
  const { paymentId, reference } = await loadPayment(orderId); // your own data

  // Public checkout status: no API key, the reference is the access key.
  const response = await fetch(
    `${GATE_URL}/api/checkout/${paymentId}?reference=${encodeURIComponent(reference)}`,
    { cache: "no-store" },
  );
  const result = await response.json();
  return NextResponse.json({ status: result.ok ? result.data.status : "UNKNOWN" });
}

2a. Simplest option: redirect to the hosted checkout

Redirect the customer to checkoutUrl. The hosted page already shows the Solana Pay QR code on a desktop, opens the wallet on a phone, and refreshes when the payment is confirmed. Then skip to step 3.

2b. Show the Solana Pay QR code in your own page

Render solanaPayTransactionUrl as a QR code, for example with qrcode.react. The customer scans it with a Solana wallet app. The wallet asks Gateway for the transaction, which holds your payment, the 0.0012 SOL gateway fee, and the payment reference. The wallet signs and sends it.

To show the result, poll a route of your own. It calls the public checkout status, GET /api/checkout/{paymentId}?reference=..., from your server. That endpoint needs no API key; the reference is the access key. status moves from PENDING to CONFIRMED once Gateway finds and verifies the transaction, usually within 30 seconds after the customer sends it. A payment that is not paid within 15 minutes expires.

Solana Pay QR code with status polling
// app/orders/[orderId]/solana-pay-qr.tsx
"use client";

import { QRCodeSVG } from "qrcode.react";
import { useEffect, useState } from "react";

type Props = {
  orderId: string;
  solanaPayTransactionUrl: string;
};

export function SolanaPayQr({ orderId, solanaPayTransactionUrl }: Props) {
  const [status, setStatus] = useState("PENDING");

  useEffect(() => {
    if (status !== "PENDING") return;
    const timer = setInterval(async () => {
      const response = await fetch(`/orders/${orderId}/pay`);
      const result = await response.json();
      setStatus(result.status);
    }, 5000);
    return () => clearInterval(timer);
  }, [orderId, status]);

  if (status === "CONFIRMED") return <p>Payment confirmed.</p>;
  if (status === "EXPIRED") return <p>This payment expired. Start a new one.</p>;
  return <QRCodeSVG value={solanaPayTransactionUrl} size={256} />;
}

3. Handle the signed callback

Set your callbackUrl to this route, for example https://app.example/solknife/callback. Read the body with request.text() and verify the signature over those exact bytes before you parse it.

Update the order from the callback, not from the browser status. The status polling only updates the page; the signed payment.confirmed callback is what your backend acts on.

Verify the callback in a route handler
// app/solknife/callback/route.ts
import { createHmac, timingSafeEqual } from "node:crypto";

const TOLERANCE_SECONDS = 300;

const isValidSignature = (rawBody: string, timestamp: string, signature: string): boolean => {
  if (!/^\d+$/.test(timestamp)) return false;
  const nowSeconds = Math.floor(Date.now() / 1000);
  if (Math.abs(nowSeconds - Number(timestamp)) > TOLERANCE_SECONDS) return false;
  const expected = Buffer.from(
    createHmac("sha256", process.env.GATE_WEBHOOK_SECRET ?? "")
      .update(`${timestamp}.${rawBody}`)
      .digest("hex"),
    "hex",
  );
  const received = Buffer.from(signature, "hex");
  return received.length === expected.length && timingSafeEqual(received, expected);
};

export async function POST(request: Request) {
  // Verify the raw body. Parsing and re-serializing the JSON changes the bytes.
  const rawBody = await request.text();
  const timestamp = request.headers.get("x-solknife-timestamp") ?? "";
  const signature = request.headers.get("x-solknife-signature") ?? "";
  if (!isValidSignature(rawBody, timestamp, signature)) {
    return new Response("invalid signature", { status: 401 });
  }

  const deliveryId = request.headers.get("x-solknife-delivery-id") ?? "";
  if (await alreadyProcessed(deliveryId)) {
    return new Response("ok");
  }

  const event = JSON.parse(rawBody);
  if (event.eventType === "payment.confirmed") {
    // Idempotent: the same payment can arrive again through a manual retry.
    await markOrderPaid(event.checkoutReference, event.paymentId, event.signature);
  }
  await rememberDelivery(deliveryId);
  return new Response("ok");
}

Start accepting payments

Register your business to get a Gateway API key and a webhook secret. Payments go straight to your wallet; Gateway takes a fixed 0.0012 SOL fee per payment.