Skip to content

Orders & checkout ​

Create a deposit order, show checkout (QR / links), poll or listen for status, and close when supported.

When to use ​

After the user picks a currency and amount. Session must be active.

Methods ​

MethodPurpose
createOrder(request)Create deposit order; returns ExchangePayOrder
getActiveOrder()In-memory active order, or null
getOrder()Fetch status for the active order (ExchangePayOrderStatus)
openCheckout(order?)Open checkout.mobileUrl ?? checkout.url (defaults to the active order)
closeOrder()Close / abandon the active order (see canClose)
reset()Clear local active order (also happens on session refresh)

Request ​

ts
type CreateExchangePayOrderRequest = {
  provider: ExchangePayProvider
  amount: string // fiat USD amount, e.g. '25.00'
  token: TokenSymbol
  blockchain: Network
}

Creating a new order closes a previous closable active order first, or clears local state if the previous order could not be closed.

Example - create ​

ts
import { IntegrationProvider, Network, TokenSymbol } from '@swapped/connect-sdk'

const order = await client.exchangePay.createOrder({
  provider: IntegrationProvider.Binance,
  amount: '25.00',
  token: TokenSymbol.USDC,
  blockchain: Network.Solana,
})

console.log(order.id, order.expiresAt, order.canClose)

Checkout UI fields ​

FieldUse for
order.checkout.qrQR — { type: 'url', value } to encode, or { type: 'image', value } to render as <img>
order.checkout.urlDesktop checkout link (may be null, e.g. OKX is QR-focused)
order.checkout.mobileUrlMobile / deep link (may be null)
order.expiresAtExpiry timestamp (ms since epoch) - see Expiry
order.canCloseWhether closeOrder() hits the provider API
order.amountTotal crypto to send (includes provider + merchant fees)
order.providerFeeExchange fee in order.currency
order.merchantFeeSwapped fee in order.currency (null when none)
order.fiatAmountNet fiat amount (excluding fees)

Fees & formatted order ​

Fees come from the create-order response. Prefer getFormattedOrder() for UI — the client fetches a live quote and fills fiat values when it lands:

ts
const formatted = client.exchangePay.getFormattedOrder()

client.exchangePay.onFormattedOrderUpdated(({ formattedOrder }) => {
  console.log(
    formattedOrder?.total.formatted.fiatValue,
    formattedOrder?.providerFee.exchangeRateLoading,
  )
})

formattedOrder includes every field from the raw order. Amounts are { amount, token, fiatCurrency, fiatValue, exchangeRate, exchangeRateLoading, formatted } — amount is always crypto. fiatValue is null and exchangeRateLoading is true until the quote loads.

Low-level helpers if you already have a rate:

ts
import {
  getExchangePayOrderBreakdownFiat,
  getExchangePayYouReceive,
  toExchangePayFormattedOrder,
} from '@swapped/connect-sdk'

const breakdown = getExchangePayOrderBreakdownFiat(order, exchangeRateFiat)
const receive = getExchangePayYouReceive(order)
const formatted = toExchangePayFormattedOrder(order, exchangeRateFiat)
ts
const { qr, url, mobileUrl } = order.checkout

if (qr?.type === 'image') {
  // <img src={qr.value} alt="QR" />
} else if (qr?.type === 'url') {
  // render a QR from qr.value (e.g. qrcode library)
}

if (url) {
  // <a href={url}>Open checkout</a>
}

if (mobileUrl && mobileUrl !== url) {
  // <a href={mobileUrl}>Open in app</a>
}

Most providers use { type: 'url', value }. Bitget Pay encodes checkoutUrl as url. Handle image when a provider returns a ready-made PNG data URL.

Opening checkout (openCheckout) ​

openCheckout(order?) opens the exchange-app deep link (checkout.mobileUrl) when present, otherwise checkout.url. If the deep link cannot be opened (for example, the exchange app is not installed), it falls back to checkout.url. It uses the active order when called without an argument. On web it opens a new tab; on React Native it opens the exchange app.

ts
await client.exchangePay.openCheckout()

On web, rendering your own links (above) is still fine. Call openCheckout from a click handler so the browser does not block the new tab. It rejects with CHECKOUT_URL_MISSING when the order has neither URL - show the QR instead.

Closing orders (canClose) ​

canCloseBehavior
trueCall closeOrder() when the user leaves checkout (back, abandon). Uses provider close API.
falseBybit / OKX / Bitget Pay — skip cancel UI. closeOrder() only clears local state. Create a new order when needed.

Starting a new order also clears the previous active order automatically.

ts
if (order.canClose) {
  await client.exchangePay.closeOrder()
}

Status ​

ts
const status = await client.exchangePay.getOrder()
console.log(status.status)
// 'PENDING' | 'PAY_SUCCESS' | 'AWAITING_PROVIDER_FUNDS'

Prefer events for live updates; use getOrder() to refresh on demand.

Completion is treated as success when status is PAY_SUCCESS or a transactionHash is present.

Errors ​

CodeWhenWhat to do
SESSION_REQUIREDNo loaded sessionloadSession()
SESSION_NOT_ACTIVESession cannot start a new paymentrestartSession() first
NO_ACTIVE_ORDERgetOrder / closeOrder / openCheckout with nothing activeCall createOrder first
CHECKOUT_URL_MISSINGopenCheckout on an order without url / mobileUrlShow the QR code
CLOSE_ACTIVE_ORDER_FAILEDProvider close API failedRetry or create a new order
API_ERRORCreate / status / close network failureRetry; keep user on a safe step

See Errors.