πŸ’¬Order Notifications

To receive order notifications, you can either provide a responseUrl per order or define a merchant-level webhook on the β€œDevelopers” page within the Swapped.com Dashboard. You will receive the notification on the provided URL. In the header of the HTTP request, there’s a signature to make sure the data comes from Swapped.

The callback destination is determined at the time of order creation and cannot be modified afterwards.

The system follows this priority:

  • If an order-level responseURL is provided during order creation, it will be used for all callbacks for that order.

  • If no order-level responseURL exists, the system will use the merchant-level webhook URL configured in the dashboard.

  • If neither exists at the time of order creation, no callbacks will be sent for that order.

Callback Configuration Priority: The system follows a clear priority structure for determining where to send callbacks.

  • If a responseURL is provided in the iframe initialization URL, this will be used as a priority.

  • If a responseURL is not provided, but a callback URL is configured via the Swapped.com dashboard, this will be used.

  • If neither responseURL nor callback URL is set, callbacks will be disabled for this order.

This configuration is locked in when the order is created and cannot be changed, even if you later update your merchant level webhook settings.

Important note on Callbacks: When you receive order notifications, they will always follow a specific sequence. All orders begin with a payment_pending notification. From there, the order will either progress successfully through order_completed to order_broadcasted, or it will end with order_cancelled. Once an order has been cancelled, no further callbacks will be sent for that order.

Order notifications can be resent to account for network errors. As such you must validate that a transaction has not been credited before crediting for it.

For more information on notification resending, see Order Notification Retry Policy.

Order notifications inform you of the status of each order. These notifications will be sent to either your order specific responseUrl or your merchant level webhook URL, depending on your configuration. Below are the types of notifications you can receive. In the event of a missed order notification, you can resend the most recent notification directly from the Swapped.com Dashboard transaction page. This functionality is available to users with the roles of Admin, User, or Developer.

Responses

Payment Pending:

Indicates that the transaction has been created but the customer hasn't completed payment.

{
  "order_status": "payment_pending",
  "external_customer_id": "1234567",
  "order_crypto": "LTC",
  "order_id": "9fcc45a5-4def-4953-9bd8-9ff75d9aaa9c"
}

Order Cancelled:

Indicates that the order is cancelled for any reason, such as payment failure, or user cancellation.

{
  "order_status": "order_cancelled",
  "external_customer_id": "1234567",
  "order_id": "9fcc45a5-4def-4953-9bd8-9ff75d9aaa9c"
}

Order Completed:

Indicates that the order has been processed, and the cryptocurrency purchase was successful.

{
  "order_id": "9fcc45a5-4def-4953-9bd8-9ff75d9aaa9c",
  "order_crypto_amount": 0.347764,
  "order_crypto": "LTC",
  "order_status": "order_completed",
  "order_crypto_address": "ltc1qlec2yfpkdvn4lr0vpf27qggrxtu34zeu5l6g2u",
  "external_customer_id": "1234567",
  "order_amount_usd": "25",
  "order_amount_usd_plus_fees": "25.5",
  "order_amount_eur": "21",
  "order_amount_eur_plus_fees": "22.5",
  "network": "litecoin"
}

Order Broadcasted:

Indicates that the cryptocurrency transaction has been broadcasted to the blockchain.

{
  "order_id": "9fcc45a5-4def-4953-9bd8-9ff75d9aaa9c",
  "order_crypto_amount": 0.347764,
  "order_crypto": "LTC",
  "order_status": "order_broadcasted",
  "transaction_id": "ea458dda0ff8583199bdd4d9b9a69a2813694764a633fd40b27de22a868cebec",
  "order_crypto_address": "ltc1qlec2yfpkdvn4lr0vpf27qggrxtu34zeu5l6g2u",
  "external_customer_id": "1234567",
  "order_amount_usd": "25",
  "order_amount_usd_plus_fees": "25.5",
  "order_amount_eur": "21",
  "order_amount_eur_plus_fees": "22.5",
  "network": "litecoin"
}

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: The order_crypto_amount converted to USD (Mid-market rates without spread). This does not include the platform fee.

  • order_amount_usd_plus_fees: The order_amount_usd plus the platform fee.

  • network: The network used to send transactions via.

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 request header.

Example with NodeJS:

import crypto from 'crypto';

const secretKey = 'sk_test_key'; // Replace with your secret key
const requestBody = '{ "order_id": "9fcc45a5-4def-4953-9bd8-9ff75d9aaa9c"}'

const signature =
  crypto
    .createHmac('sha256', secretKey)
    .update(requestBody)
    .digest('base64'); 

Last updated