Confirm a payment

onSuccess runs in the payer’s browser, so it can be faked. Before you ship goods or grant access, have your server check the payment with Uniport.

How it works

When a payment completes, onSuccess gives your page the payment’s depositAddress. Send it to your server. Your server asks Uniport about that address and checks that the answer matches the order.

Checkout.tsx
1<UniportButton2appId="app_..."3recipient="0x..."4destinationToken="arbitrumUSDC"5amount="25"6onSuccess={(result) =>7  fetch("/api/orders/confirm", {8    method: "POST",9    body: JSON.stringify({10      orderId,11      depositAddress: result.depositAddress,12      depositMemo: result.depositMemo,13    }),14  })15}16/>

Check the payment

Call GET https://api.uniport.dev/v1/payments/{depositAddress} from your server. No key is needed. On chains that use a memo, add ?memo= with the depositMemo from onSuccess.

confirm.ts
1const url = new URL(2`https://api.uniport.dev/v1/payments/${encodeURIComponent(depositAddress)}`3);4if (depositMemo) url.searchParams.set("memo", depositMemo);56const res = await fetch(url);7if (!res.ok) return "try-again";8const payment = await res.json();910// Uniport couldn't read its record just now. Ask again shortly.11if (payment.record === "unavailable") return "try-again";12if (payment.status !== "SUCCESS" || payment.amountOut === null) return "not-paid";1314// Use the address and memo from the response, not the ones the browser sent.15const paymentKey = `${payment.depositAddress}:${payment.depositMemo ?? ""}`;1617const paid =18payment.appId === process.env.UNIPORT_APP_ID &&19// EVM (0x) addresses only. On other chains, such as Solana, compare exactly.20payment.recipient.toLowerCase() === MY_WALLET.toLowerCase() &&21payment.destinationAsset === EXPECTED_ASSET &&22BigInt(payment.amountOut) >= EXPECTED_AMOUNT &&23// Must be atomic: for example an insert into a column with a unique constraint.24(await claim(paymentKey, orderId));

Check all of these:

FieldCheck that
statusIt is SUCCESS. Other values mean the payment is still in progress, was refunded, or failed.
appIdIt is your App ID, so the payment was made through your app and not someone else’s.
recipientIt is your address.
destinationAssetIt is the token you expected, on the chain you expected.
amountOutIt is at least the order amount. It is in the token’s smallest units: 25 USDC is 25000000.
depositAddressYou have not already accepted it for another order. Record each one you accept, with its depositMemo, in a way that cannot succeed twice: for example a unique constraint, written in the same transaction that marks the order paid. A check followed by a separate write lets two requests at once both pass. Take both from the response: the same address can be written in more than one way, and the response always gives it in one form.

A few details:

  • destinationAsset is the token’s NEAR Intents asset ID, not the name you pass to the button. Make one test payment and copy the value from the response.
  • If you replace your App ID, payments already under way still carry the old one. Accept both for a day or so.
  • record: "missing" means Uniport has no record of the payment, so it wasn’t made through your app.

The response

FieldWhat it is
statusPENDING_DEPOSIT, KNOWN_DEPOSIT_TX, PROCESSING, SUCCESS, INCOMPLETE_DEPOSIT, REFUNDED or FAILED.
isCompleteTrue once the payment has succeeded, been refunded or failed.
appIdThe App ID the payment was made with, or null.
recordfound, missing (Uniport has no record of this payment, so appId is null) or unavailable (the record couldn’t be read just now; ask again).
recipientThe address the payment is delivered to.
originAssetThe token the payer paid with.
destinationAssetThe token delivered to the recipient.
amountOutThe amount delivered, in the destination token’s smallest units. null until the payment completes.
quotedAmountOutThe amount the payer was quoted.
destinationTxHashesThe delivery transactions on the destination chain.
createdAtWhen the payer was given the deposit address.
signedQuoteThe quote as signed by NEAR Intents, if you want to verify the signature yourself.

What this does not do

It does not tie a payment to one particular order. The check proves that a payment of the right amount reached your address through your app, and that you have not used it before. If two customers place orders for the same amount at the same time, the only thing telling their payments apart is which deposit address each browser reports. If that matters for what you sell, give each order its own amount or its own recipient address.

Check on every order. A page can call your confirm endpoint with any deposit address it likes. Never mark an order paid without running the checks above on your server.