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.
1. Install the package
The package currently tracks themain branch on GitHub:
prepare build in package.json:
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:
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.
3. Add the status proxy
Createfunctions/api/unifi/[[path]].ts in a Cloudflare Pages project:
/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
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
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.