Skip to main content
The payment widget checks status through a same-origin merchant route. The server proxy validates the request, adds UNIFI_API_KEY, calls the UniFi API, and returns the upstream status response. The proxy is intentionally narrow. It accepts only GET and OPTIONS, and only these paths:
  • /payment/merchant/session/:sessionId below the configured proxy prefix, with a valid 64-character hexadecimal session ID; and
  • /payment/onchain/receipt/:receiptId below the configured proxy prefix, with a valid UniFi receipt ID.
It is not an arbitrary API passthrough.

Cloudflare Pages

Create functions/api/unifi/[[path]].ts:
Add UNIFI_API_KEY as an encrypted Cloudflare Pages secret. Do not add it as a public build-time variable.

Any Fetch API-compatible server

Pass the original request so the proxy can validate its URL, method, and origin.

Configuration

Most production merchants should use the defaults for apiPrefix and UNIFI_API_BASE_URL. The proxy forwards these allowlisted requests to the corresponding /v1/... UniFi API routes.

Cross-origin frontend

Same-origin requests need no extra CORS configuration. If the frontend and proxy deliberately use different origins, allow each literal browser origin:
Do not use bind addresses such as 0.0.0.0 as browser origins, and do not use a wildcard for a secret-bearing proxy.

Response behavior

  • Valid status responses pass through with Cache-Control: no-store.
  • The proxy removes Set-Cookie from the upstream response.
  • Missing server configuration returns 500 without revealing a key.
  • Disallowed routes return 404; unsupported methods return 405.
  • An unreachable UniFi API returns 502.
  • CORS headers are emitted only for the request origin or an explicitly allowed origin.

Security checklist

  • Keep UNIFI_API_KEY in the runtime’s encrypted secret store.
  • Search generated JavaScript, HTML, source maps, logs, and browser requests for accidental key exposure before launch.
  • Keep the allowlist limited to the session lookup and single-receipt status routes.
  • Add merchant-side monitoring and rate limits appropriate for checkout traffic.
  • Reject status checks that are not associated with a known merchant order when your server owns that association.
  • Log order IDs and session IDs as operational identifiers, but never log API keys or wallet signing material.
The proxy confirms that UniFi has a receipt for the session. Your order system must still verify that the receipt belongs to the expected amount, asset, network, and recipient before fulfilment.