> ## Documentation Index
> Fetch the complete documentation index at: https://docs.payunifi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Payment gateway

> Add UniFi stablecoin payments to an existing merchant checkout.

The UniFi payment gateway adds a stablecoin payment method to the checkout you already own. Your
application supplies the amount, receiving wallet, asset, and network; UniFi opens the hosted
payment flow and returns a receipt that your server can reconcile with the order.

![FliQ Market checkout with UniFi selected beside card and UPI payment methods](https://mintcdn.com/test-ccbd1339/a7-7soYiK1kc9L9N/images/payment-gateway/merchant-checkout.webp?fit=max\&auto=format\&n=a7-7soYiK1kc9L9N\&q=85\&s=2de5e8ada6a8eeca25f44fffba9b06a1)

UniFi embedded beside the payment methods and order summary in FliQ Market.

> [card] [Quickstart](https://docs.payunifi.com/payment-gateway/quickstart.md)
>
> Install the package, add the server proxy, and open your first payment.

> [card] [React components](https://docs.payunifi.com/payment-gateway/react.md)
>
> Use a complete widget or compose UniFi into an existing payment-method UI.

> [card] [Headless TypeScript](https://docs.payunifi.com/payment-gateway/headless.md)
>
> Build sessions, hosted checkout links, status checks, and receipt links without React.

> [card] [FliQ Market example](https://docs.payunifi.com/payment-gateway/fliq-market.md)
>
> Follow a working merchant integration from product selection to payment reconciliation.

## Choose an integration path

| Path | Best for | Package entry point |
| - | - | - |
| Complete React widget | A new checkout or the shortest path to a working UI | `unifi-pay-widget/react` |
| Composable React components | An existing checkout that owns its Pay button and success state | `unifi-pay-widget/react` |
| Headless TypeScript | A custom framework, mobile web shell, or backend-driven UI | `unifi-pay-widget` |
| Server proxy | Every browser integration that checks payment status | `unifi-pay-widget/server` |

The core package and React components never read the API key. The server entry point is the only
layer allowed to access `UNIFI_API_KEY`.

## How the pieces fit

```mermaid theme={null}
flowchart LR
    Browser[Merchant checkout] -->|Create session and open URL| Checkout[UniFi hosted checkout]
    Browser -->|Manual or configured session check| Proxy[Merchant server proxy]
    Secret[(UNIFI_API_KEY)] -. server only .-> Proxy
    Proxy -->|Authenticated status request| API[UniFi API]
    API -->|Pending or receipt ID| Proxy
    Proxy -->|Receipt detected| Browser
    Browser -->|Immediate, every 15 min, or manual receipt check| Proxy
    API -->|Processing, Confirmed, Finalized, Failed, or Reorged| Proxy
    Proxy -->|Latest receipt status| Browser
```

> [!NOTE]
>
> `MERCHANT_WALLET_ADDRESS` is public merchant configuration passed to the widget as `recipient`.
> `PAYMENT_STATUS_POLL_INTERVAL` is optional public application configuration for automatic session
> checks. `UNIFI_API_KEY` is a secret and must stay behind the server proxy.

## Checkout lifecycle

**1. Create the merchant order**

Store your order ID and the expected amount, asset, network, recipient, and expiry in your own
database. Do not trust pricing supplied only by the browser.

**2. Create a UniFi payment session**

`createUniFiPayment` generates a random 64-character hexadecimal session ID and the hosted
checkout URL. Record that session ID against the order.

**3. Send the payer to UniFi**

Open the hosted checkout with the exact order details. The payer connects a wallet, completes
Permit2 approval if required, and signs the short-lived payment authorization.

**4. Check through your proxy**

The merchant browser requests `/api/unifi/payment/merchant/session/:sessionId`. The same-origin
server proxy validates the route and adds the API key server-side. Checks are manual by default;
a merchant can opt into a fixed automatic cadence with `statusPollIntervalMs`.

**5. Track finality and fulfil**

Store the detected receipt ID with the order, check its receipt status immediately, and refresh
non-terminal states every 15 minutes or when the customer requests a manual check. Keep
`Processing` and `Confirmed` in progress; confirm and fulfil the order only after `Finalized`.

## Supported payment pairs

* Assets: **USDT**, **USDC**, and **DAI**
* Networks: **Ethereum**, **Polygon**, and **Sepolia**

The package does not silently replace an invalid selection. The hosted checkout remains the final
authority on whether a pair is currently available.

> [!WARNING]
>
> UniFi's `session_id → receipt_id` lookup is temporary and retained for two hours. It supports
> checkout status checks; it is not a durable merchant order database.

> [card] [Secure the server boundary](https://docs.payunifi.com/payment-gateway/server-proxy.md)
>
> Configure secrets, proxy routing, same-origin requests, and explicit CORS exceptions.

> [card] [Operate the lifecycle](https://docs.payunifi.com/payment-gateway/lifecycle.md)
>
> Handle pending, paid, failed, expiry, receipts, persistence, and chain finality.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.