Skip to main content
This guide uses the complete React widget and a Cloudflare Pages Function. The same browser-facing code works with any Fetch API-compatible server route.

Before you begin

You need:
  • Node.js 20 or newer;
  • a UniFi account and API key;
  • the merchant wallet address that will receive payments; and
  • a deployment that can run a server or edge function.
Create an account at payunifi.com, then generate an API key from the API plan and key flow.

1. Install the package

The package currently tracks the main branch on GitHub:
Declare the dependency and permit its Git dependency prepare build in package.json:
Import its stylesheet once near the application entry point:
npm resolves main to a commit and records that SHA in package-lock.json. Review and commit the lockfile so production installs the exact integration you tested.

2. Configure the merchant

These two values are required in production:
Automatic session-status checks are optional:
Use the deployment provider’s encrypted secret store for the API key. Return the wallet address and optional polling interval through a non-secret runtime-config endpoint or inject them as public application configuration. The widget does not read application environment variables directly. Convert the configured seconds to milliseconds and pass the result as statusPollIntervalMs. For example, 30 becomes 30_000. Values such as 60 and 120 work the same way.
Never expose UNIFI_API_KEY through VITE_*, NEXT_PUBLIC_*, generated JavaScript, HTML, source maps, browser logs, or browser network requests.

3. Add the status proxy

Create functions/api/unifi/[[path]].ts in a Cloudflare Pages project:
The browser now checks the session through /api/unifi/payment/merchant/session/:sessionId and the resulting receipt through /api/unifi/payment/onchain/receipt/:receiptId. Most production merchants should leave UNIFI_API_BASE_URL unset and use the package’s built-in production endpoint.

4. Render the widget

Required props are amount and recipient. The widget handles pair selection, session creation, hosted-checkout launch, the 15-minute session countdown, status checking, and the receipt-detected callback. If statusPollIntervalMs is omitted, the customer uses the Check payment status button. A positive interval enables a compact automatic-check countdown with an immediate refresh control and last-check time.

5. Test the complete flow

1

Open the merchant checkout

Confirm the displayed amount and recipient come from a trusted order record.
2

Choose Sepolia

Use Sepolia for a test payment. Confirm the selected asset and network remain unchanged when the pair picker closes.
3

Open UniFi

Keep the merchant page open while the hosted checkout opens in a new tab.
4

Complete and check

Authorize the payment and return to the merchant tab. Use the status action in manual mode, or wait for the configured automatic check. A successful check returns the receipt ID through onPaid. The order is not confirmed yet.
5

Wait for finality

Check the receipt immediately, then every 15 minutes while it is Processing or Confirmed. Offer a manual refresh action and confirm the order only after Finalized.
6

Verify your records

Confirm the order now contains its UniFi session ID and receipt ID. Do not rely on the temporary UniFi lookup as your order history.

6. Deploy the tested dependency

When you deliberately refresh the GitHub dependency, run npm update --save unifi-pay-widget, test the new resolved commit, and commit the resulting lockfile.

See the production checklist

Validate pending, paid, failed, expired, mobile, keyboard, upstream-outage, and finality behavior.