Swipelux
Server-side integration

Create an order

To create a new order programmatically, you need to send a POST request to our REST API endpoint.

Implementation

This guide will feature implementations in JavaScript, Python, and PHP, but these snippets can be translated to almost any other language by following the Reference section.

Make sure you have a secret API key

If you don't have one, you can create it in the Merchant Panel. Read here for more information.

Install dependencies if needed

If you don't have a preferred language, we recommend using JavaScript. Most modern browsers and runtimes have Fetch API built-in, which is a modern way to make HTTP requests.

If you need to use a different language, you can use a package manager like pip to install the requests library for Python or curl for PHP. Refer to your language's documentation for more information.

Define a function that makes the request

async function createPreparedOrder(
  secretKey,
  {
    amount,
    fromCurrency = "USD",
    toCurrency = "USDC",
    targetAddress,
    userEmail,
    userPhone,
  },
) {
  const response = await fetch(
    "https://api.swipelux.com/api/orders/createPrepared",
    {
      method: "POST",
      headers: {
        Authorization: secretKey,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        amounts: {
          from: {
            amount,
            currency: fromCurrency
          },
          to: {
            currency: toCurrency
          },
        },
        user: {
          email: userEmail,
          phone: userPhone
        },
        targetAddress,
      }),
    },
  );
 
  if (!response.ok) {
    const error = await response.json();
    throw new Error(error.message);
  }
 
  return await response.json();
}

Make the request

try {
  const response = await createPreparedOrder("YOUR_SECRET_KEY_HERE", {
    amount: 100,
    fromCurrency: "USD",
    toCurrency: "USDC",
    targetAddress: "0x1234...",
    userEmail: "user@example.com",
    userPhone: "+1234567890",
  });
  console.log("Order created:", response.orderId);
} catch (error) {
  console.error("Error:", error.message);
}

Handle the response

The JSON response contains important information about the created order.

Here's what you'll receive:

{
  "orderId": "your-order-id",
  "orderToken": "your-order-token",
  "acsUrl": "https://track.swipelux.com?specificSettings={...}"
}

You can use the acsUrl to redirect your customers to the widget directly, or use orderToken alongside other widget settings for embedded widget integrations.

Reference

URL

POST https://api.swipelux.com/api/orders/createPrepared

Request headers

HeaderValueRequired
AuthorizationYour secret API keyYes

Request body

Root object

PropTypeDefault
externalId?
string
-
targetAddress
string
-
user
object
-
amounts
object
-

amounts object

PropTypeDefault
to.currency
string
-
from.amount
number
-
from.currency
string
-

user object

PropTypeDefault
email?
string
-
phone
string
-

On this page