π¬Order Notifications
To receive order notifications, you can provide a webhookUrl
per session as a query parameter. You will receive the notification via the provided URL. In the header of the HTTP request, thereβs a signature to validate that the data comes from Swapped.com.
The callback destination is locked at order creation and cannot be changed.
Callback Config Priority
The system follows a clear priority structure for determining where to send callbacks.
If a webhookUrl is provided in the iframe initialization URL, this will be used as a priority.
If a webhookUrl is not set in the iframe initialization, callbacks will be disabled for this order.
This configuration is locked in when the order is created and cannot be changed.
Best Practices
Order notifications can be resent to account for network errors. As such, you must validate that a transaction has not been credited before crediting it.
For more information on notification resending, see the Order Notification Retry Policy.
Callback examples:
Payment Pending:
Indicates that the transaction has been created, but the customer hasn't completed payment.
{
"order_id": "eaf0fcb1-7543-4cad-a712-92caeb25db63",
"order_crypto_amount": "0.0001",
"order_crypto": "BTC",
"order_crypto_address": "2uA6F27wYY6iwtVESsYUhG4VUAxx7mFD4EwMbwxNFmSm",
"order_status": "payment_pending",
"order_amount_usd": "5.000252367857236",
"network": "bitcoin",
"order_crypto_tag": null,
"transaction_id": null,
"external_customer_id": "User-fe1b9"
}
Order Completed:
Indicates that the order has been processed, and the sale of cryptocurrency was successful.
{
"order_id": "eaf0fcb1-7543-4cad-a712-92caeb25db63",
"order_crypto_amount": "0.0001",
"order_crypto": "BTC",
"order_crypto_address": "2uA6F27wYY6iwtVESsYUhG4VUAxx7mFD4EwMbwxNFmSm",
"order_status": "order_completed",
"order_amount_usd": "5.000252367857236",
"network": "bitcoin",
"order_crypto_tag": null,
"transaction_id": "9f488e8af23e68d091d171627766dd7224f4f67f84ca2c924dfd11a4a73c3d8c",
"external_customer_id": "User-fe1b9"
}
Response Definition:
order_id
: The order ID on Swapped.com.order_crypto_amount
: The exact cryptocurrency amount you will receive.order_crypto
: The cryptocurrency you receive.order_status
: The current status of the order.order_crypto_address
: The cryptocurrency address where you receive the cryptocurrency.external_customer_id
: Your customer's ID (If provided in the URL).order_amount_usd
: Theorder_crypto_amount
converted to USD.order_crypto_tag
: The destination tag/memo of the order (used with XRP)network
: The network used to send transactions.transaction_id
: The crypto transaction hash.
Order State Flows
Currently, an order can follow only one flow that is applied when an order gets completed successfully and the user receives crypto:
payment_pending
β order_completed
The signature:
Compute an HMAC with a SHA-256 hash function. Use your secret API key as the key and use the request body as the message. Compare this to the signature sent in the x-signature
request header.
Example with NodeJS:
import crypto from 'crypto';
const secretKey = 'sk_test_key'; // Replace with your secret key
const requestBody = `{"order_id":"eaf0fcb1-7543-4cad-a712-92caeb25db63","order_crypto_amount":"0.0001","order_crypto":"BTC","order_crypto_address":"2uA6F27wYY6iwtVESsYUhG4VUAxx7mFD4EwMbwxNFmSm","order_status":"completed","order_amount_usd":"5.000252367857236","network":"bitcoin","transaction_id":"9f488e8af23e68d091d171627766dd7224f4f67f84ca2c924dfd11a4a73c3d8c","external_customer_id":"User-fe1b9"}`;
const signature =
crypto
.createHmac('sha256', secretKey)
.update(requestBody)
.digest('base64');
Last updated