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)
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.USDT,
  blockchain: Network.Ethereum,
});

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

Checkout UI fields

FieldUse for
order.checkout.qrQR — { type: 'image', value } or { type: 'url', value }
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
ts
const { qr, url, mobileUrl } = order.checkout;

if (qr?.type === 'image') {
  // <img src={qr.value} alt="Pay 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>
}

QR types

qr.typeMeaningTypical providers
'image'Ready-made image (data URI / URL)Bybit
'url'String to encode as a QRBinance, KuCoin, Gate, KrakPay, OKX

Closing orders (canClose)

canCloseBehavior
trueCall closeOrder() when the user leaves checkout (back, abandon). Uses provider close API.
falseBybit / OKX — 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 with nothing activeCall createOrder first
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.