Send 100 USDT on TRON to:
TWkKZkmuB8DpVeiMoHiKf99ZoFHzk73CqR
Expires:
```
***
## Step 3: Handle the Webhook Notification
Configure your callback URL in the gateway. When payment is detected and confirmed, the gateway sends a signed `POST` request:
```javascript theme={null}
// Express.js webhook handler
import express from "express";
import crypto from "crypto";
const app = express();
app.use(express.json());
const WEBHOOK_SECRET = process.env.XPAYLABS_WEBHOOK_SECRET;
app.post("/webhooks/xpaylabs", (req, res) => {
const payload = req.body;
// Verify signature
const dataJson = JSON.stringify(payload.data);
const expectedSign = crypto
.createHmac("sha256", WEBHOOK_SECRET)
.update(dataJson, "utf8")
.digest("hex");
if (expectedSign !== payload.sign) {
return res.status(400).send("Invalid signature");
}
// Route by event type
switch (payload.notifyType) {
case "ORDER_PENDING":
console.log("Order created, awaiting payment");
break;
case "ORDER_PENDING_CONFIRMATION":
console.log("Payment detected, awaiting confirmations");
// Update order status in your database
break;
case "ORDER_SUCCESS":
console.log(`Payment confirmed for order ${payload.data.orderId}`);
// Fulfill the order — release goods, update database
break;
case "ORDER_EXPIRED":
console.log(`Order ${payload.data.orderId} expired`);
// Mark as expired in your system
break;
}
res.status(200).send("ok");
});
app.listen(3000);
```
***
## Step 4: Poll Order Status (Alternative to Webhooks)
If you cannot receive webhooks, poll the status endpoint:
```javascript theme={null}
async function getOrderStatus(orderId, token) {
const sign = crypto
.createHmac("sha256", token)
.update(orderId, "utf8")
.digest("hex");
const response = await fetch(
`http://your-gateway:180/v1/order/getOrderStatus?orderId=${orderId}&sign=${sign}`
);
const result = await response.json();
return result.data.status;
}
// Poll every 3 seconds until confirmed or expired
async function waitForPayment(orderId, token) {
return new Promise((resolve) => {
const interval = setInterval(async () => {
const status = await getOrderStatus(orderId, token);
if (status === "SUCCESS") {
clearInterval(interval);
resolve(true);
} else if (status === "EXPIRED" || status === "FAILED") {
clearInterval(interval);
resolve(false);
}
}, 3000);
});
}
```
***
## Supported Chains
When creating a collection, specify the `chain` parameter:
| Chain | Value | Tokens |
| --------- | -------------- | ------------------------ |
| TRON | `TRON` | USDT (TRC20), USDC |
| Ethereum | `ETH` | USDT (ERC20), USDC, DAI |
| BNB Chain | `BSC` | USDT (BEP20), USDC, BUSD |
| Polygon | `POLYGON` | USDT, USDC, DAI |
| Avalanche | `AVAX_C_CHAIN` | USDT, USDC |
| SUI | `SUI` | USDC |