Skip to content

Vebxuklar ​

Wasyt hamkor yoki kompaniya tizimiga voqealar haqida o‘zi xabar beradi. Kalit berilganda bitta webhook URL ko‘rsatiladi — barcha voqealar shu manzilga POST qilinadi.

So‘rov ​

http
POST https://partner.uz/wasyt-webhook
Content-Type: application/json
X-Wasyt-Timestamp: 1760870453
X-Wasyt-Signature: 9f2c…e41a

{"method": "CreateSale", "params": { … }}

method — voqea nomi, params — uning ma’lumotlari. Bitta URL ga turli voqealar keladi, ular method bo‘yicha ajratiladi.

methodQachonparams
CreateSaleKassada oddiy sotuv yakunlanganda yoki ICAN kredit shartnomasi bo‘yicha sotuv ochgandaSotuv: id, code, company_id, status, currency, sold_amount, returned_amount, comment, created_at, client (id, full_name, main_phone, bonus_balance), bonus_accrued, bonus_spent, products[] (product_id, service_id, name, price, discount, sold_quantity, returned_quantity), source_type, credit
CreateTransactionICAN kredit shartnomasi bo‘yicha to‘lov yoki qaytarish o‘tkazgandaTo‘lov: id, type, payment_type, amount, currency, comment, company_id, cashbox_id, created_at, sale (id, code, status), credit (id, number, transaction_id), client (full_name, main_phone), refunded_payment_id

bonus_accrued — shu chek uchun mijozga berilgan keshbek, bonus_spent — chekni to‘lashga sarflangan bonus, client.bonus_balance — mijozning hozirgi bonus qoldig‘i. Xuddi shu maydonlarni records/sale ham qaytaradi.

Kredit sotuvlar. CreateSale dagi source_type sotuv turini ko‘rsatadi: wasyt — oddiy kassa sotuvi, credit — ICAN kredit shartnomasi bo‘yicha ochgan sotuv. Kredit sotuvda status = in_progress (u hali to‘lanmoqda), credit esa shartnoma: {"id": 77, "number": "KR-2026-0418"}; oddiy sotuvda credit = null.

Shartnoma bo‘yicha to‘lovlar — CreateTransaction. ICAN to‘lov (type = income) yoki qaytarish (type = outcome) o‘tkazganda keladi:

json
{
  "method": "CreateTransaction",
  "params": {
    "id": 3051,
    "type": "income",
    "payment_type": "cash",
    "amount": 500000,
    "currency": "uzs",
    "comment": null,
    "company_id": 1,
    "cashbox_id": 2,
    "created_at": "2026-11-02 10:15:00",
    "sale": {"id": 125, "code": "#021126001", "status": "in_progress"},
    "credit": {"id": 77, "number": "KR-2026-0418", "transaction_id": 9001},
    "client": {"full_name": "Aliyev Vali", "main_phone": "998901234567"},
    "refunded_payment_id": null
  }
}

sale.status — shu to‘lovdan keyingi sotuv holati. Shartnomaning Wasyt da sotuvi bo‘lmasa (u ombor ulanishidan oldin tuzilgan), sale = null, shartnoma va mijoz to‘lovning o‘zidan olinadi; bunday to‘lov qaytarilganda refunded_payment_id — qaytarilayotgan to‘lov.

Kredit sotuv ochilganda u bilan birga yuborilgan to‘lovlar va sotuv bekor qilinganda qaytarishlar ham keladi — ularda credit.transaction_id = null. CreateSale va CreateTransaction bir-biridan mustaqil yuboriladi, shuning uchun kelish tartibi kafolatlanmaydi. Oddiy kassa sotuvlarining to‘lovlari yuborilmaydi.

Kalit standart holatda faqat CreateSale ni oladi; CreateTransaction va boshqa voqealarni Wasyt jamoasi yoqadi. Har bir voqea bir marta yuboriladi: javob 2xx bo‘lmasa yoki 10 soniyada kelmasa, qayta yuborilmaydi — o‘tkazib yuborilganini records/sale orqali o‘qish mumkin.

Imzoni tekshirish ​

X-Wasyt-Signature — X-Wasyt-Timestamp, nuqta va so‘rov tanasining (o‘zgartirilmagan holda) HMAC-SHA256 si, kalit — webhook secret (whsec_…). Imzo mos kelmasa yoki vaqt 5 daqiqadan eski bo‘lsa, so‘rovni rad eting.

php
$body = file_get_contents('php://input');
$timestamp = $_SERVER['HTTP_X_WASYT_TIMESTAMP'] ?? '';
$expected = hash_hmac('sha256', $timestamp . '.' . $body, $webhookSecret);

if (!hash_equals($expected, $_SERVER['HTTP_X_WASYT_SIGNATURE'] ?? '') || abs(time() - (int) $timestamp) > 300) {
    http_response_code(401);
    exit;
}
js
const crypto = require('crypto')

function isFromWasyt(rawBody, timestamp, signature, secret) {
  const expected = crypto.createHmac('sha256', secret).update(`${timestamp}.${rawBody}`).digest('hex')

  return signature.length === expected.length
    && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature))
    && Math.abs(Date.now() / 1000 - Number(timestamp)) <= 300
}