I want to sell products on my website#
Use checkout to accept payment for products. This guide walks through a 10 USDC order.
Prerequisites#
Have your API key, secret key, passphrase, and merchant recipient address ready. The example creates a 10 USDC order on X Layer. Replace the sample address and order ID with your own values.
1. Create a Payment Order#
Send the request from your server. USDC has 6 decimals, so 10 USDC is tokenAmount = "10000000". fiatAmount and fiatCurrency provide reference fiat information.
curl --request POST 'https://web3.okx.com/api/v6/pay/onchainos-payment/create' \
--header "OK-ACCESS-KEY: ${OK_ACCESS_KEY}" \
--header "OK-ACCESS-SIGN: ${OK_ACCESS_SIGN}" \
--header "OK-ACCESS-PASSPHRASE: ${OK_ACCESS_PASSPHRASE}" \
--header "OK-ACCESS-TIMESTAMP: ${OK_ACCESS_TIMESTAMP}" \
--header 'Content-Type: application/json' \
--data-raw '{
"merchantPaymentId": "order_20261106_0001",
"to": "0x1111111111111111111111111111111111111111",
"fiatAmount": "10.00",
"fiatCurrency": "USD",
"quotes": [
{
"paymentToken": {
"chainId": "196",
"tokenAddress": "0xb6ceceab302e2e4948951ee7843fc24e92933061",
"tokenAmount": "10000000"
}
}
],
"merchantDisplayName": "Example Store",
"productDesc": "Example product",
"returnUrl": "https://merchant.example.com/payment/result",
"expireSeconds": 1800
}'
2. Save the Order and Checkout URL#
Confirm that the response code is 0. Save paymentIntentId, merchantPaymentId, and checkoutUrl so you can match the payment to your business order and look it up later.
{
"code": 0,
"msg": "",
"data": {
"merchantPaymentId": "order_20261106_0001",
"paymentIntentId": "2026110600000123456789012345678901",
"status": "pending",
"to": "0x1111111111111111111111111111111111111111",
"quotes": [
{
"paymentToken": {
"chainId": "196",
"tokenSymbol": "USDC",
"tokenAddress": "0xb6ceceab302e2e4948951ee7843fc24e92933061",
"tokenDecimal": 6,
"tokenAmount": "10000000"
},
"exchangeRate": "1"
}
],
"checkoutUrl": "https://checkout.example.com/pay?paymentIntentId=2026110600000123456789012345678901",
"expiresAt": "2026-11-06T04:30:00Z"
}
}
3. Open Checkout#
Return checkoutUrl to your frontend and open it there. At checkout, the buyer connects a wallet, confirms the order, and signs the payment authorization.
// Use the checkout URL returned by your server. Create the order on the server.
window.location.assign(checkoutUrl);
4. Check the Payment Result#
Query the order from your server using the same API key that created it. Pass either paymentIntentId or merchantPaymentId.
curl --request POST 'https://web3.okx.com/api/v6/pay/onchainos-payment/query' \
--header "OK-ACCESS-KEY: ${OK_ACCESS_KEY}" \
--header "OK-ACCESS-SIGN: ${OK_ACCESS_SIGN}" \
--header "OK-ACCESS-PASSPHRASE: ${OK_ACCESS_PASSPHRASE}" \
--header "OK-ACCESS-TIMESTAMP: ${OK_ACCESS_TIMESTAMP}" \
--header 'Content-Type: application/json' \
--data-raw '{"paymentIntentId":"2026110600000123456789012345678901"}'
This example shows a settled payment.
{
"code": 0,
"msg": "",
"data": {
"merchantPaymentId": "order_20261106_0001",
"paymentIntentId": "2026110600000123456789012345678901",
"status": "settled",
"to": "0x1111111111111111111111111111111111111111",
"txHash": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"fiatAmount": "10.00",
"fiatCurrency": "USD",
"paymentToken": {
"chainId": "196",
"tokenSymbol": "USDC",
"tokenAddress": "0xb6ceceab302e2e4948951ee7843fc24e92933061",
"tokenDecimal": 6,
"tokenAmount": "10000000"
},
"expiresAt": "2026-11-06T04:30:00Z",
"merchantDisplayName": null,
"qrContent": null
}
}
5. Confirm the Business Order#
When the response status is settled, verify the recipient address, network, token contract, and amount paid. Mark your business order as paid and make fulfillment idempotent so repeated checks cannot ship a product or grant access twice.
| Status | Action |
|---|---|
pending / paid | Keep polling and leave the business order unconfirmed. |
settled | Verify the payment details and fulfill the order. |
failed / expired | Stop polling. Create a new order if the buyer needs to pay again. |
