Примеры интеграции
Готовый код для вашего Telegram-бота или сайта
# 1. Создание счета в Telegram-боте
import aiohttp, hmac, hashlib
async def create_xevopay_invoice(amount, order_id):
url = "https://pay.xevopay.ru/api/v1/invoices"
headers = {"Authorization": f"Bearer {API_KEY}"}
data = {
"amount": amount,
"currency": "USDT",
"orderId": order_id,
"projectId": PROJECT_ID
}
async with aiohttp.ClientSession() as session:
async with session.post(url, json=data, headers=headers) as r:
res = await r.json()
return res['invoice']['checkout_url']
# 2. Проверка вебхука (FastAPI / aiohttp)
def verify_signature(raw_body, signature, secret):
expected = hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, signature)
// 1. Создание счета (Node.js / Telegraf)
const axios = require('axios');
const crypto = require('crypto');
async function createInvoice(amount, orderId) {
const res = await axios.post('https://pay.xevopay.ru/api/v1/invoices', {
amount,
currency: 'USDT',
orderId,
projectId: 'PROJ_ID'
}, {
headers: { 'Authorization': `Bearer ${API_KEY}` }
});
return res.data.invoice.checkout_url;
}
// 2. Проверка Webhook в Express
app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
const sign = req.headers['x-xevopay-signature'];
const expected = crypto.createHmac('sha256', API_SECRET).update(req.body).digest('hex');
if (sign !== expected) return res.status(401).send('Invalid signature');
// Выдать товар / подписку покупателю
res.send('OK');
});
# Создание инвойса через cURL:
curl -X POST https://pay.xevopay.ru/api/v1/invoices \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"amount": 25.50,
"currency": "USDT",
"orderId": "#809244"
}'
# Ответ шлюза (201 Created):
{
"success": true,
"invoice": {
"id": "inv_1790076972845",
"checkout_url": "https://pay.xevopay.ru/?invoice_id=..."
}
}