مستندات توسعهدهندگان
هر آنچه برای دریافت پرداختهای USDT با Kem Business API نیاز دارید: احراز هویت، نقاط پایانی پرداخت و وبهوکهای امضاشده که وضعیت سفارش شما را پیش میبرند.
احراز هویت
کلیدهای API را از داشبورد در بخش «کلیدهای API» بسازید و کلید محرمانه را بهصورت Bearer token در هر درخواست بفرستید. کلیدهای آزمایشی (…sk_test_) پرداخت آزمایشی میسازند؛ کلیدهای اصلی (…sk_live_) پول واقعی جابهجا میکنند.
Authorization: Bearer sk_live_... # or sk_test_...
Base URL: https://api-business.kemapp.ioپرداختها
یک پرداخت بسازید و مشتری را به checkout_url میزبانیشده بفرستید — Kem کیف پولها، شبکهها و تأییدها را مدیریت میکند. وضعیت را با خواندن پرداخت یا بهتر از آن با وبهوکها دنبال کنید.
/v1/paymentscurl -X POST https://api-business.kemapp.io/v1/payments \
-H "Authorization: Bearer sk_test_..." \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-1042" \
-d '{
"amount": "25.000000",
"currency": "USDT",
"merchant_reference": "order-1042",
"customer_email": "[email protected]",
"description": "Pro plan",
"return_url": "https://yourshop.example/thanks",
"metadata": {"order_id": "1042"}
}'{
"id": "pay_01J...",
"status": "pending",
"mode": "test",
"amount": "25.000000",
"amount_minor": 25000000,
"currency": "USDT",
"merchant_reference": "order-1042",
"checkout_url": "https://pay.kemapp.io/pay_01J...",
"checkout_expires_at": "2026-07-13T13:30:00+00:00",
"created_at": "2026-07-13T13:00:00+00:00"
}Idempotency-Key — اختیاری اما توصیهشده — تلاش مجدد با همان کلید، همان پرداخت اولیه را برمیگرداند و نسخه تکراری نمیسازد.
/v1/payments— query: status, limit (1–100, default 20), cursor · returns has_more, next_cursor/v1/payments/{id}amount — decimal string with 6 places ("25.000000"); amount_minor — the same value as an integer in micro-USDT.
چرخه عمر پرداخت
pending → detected → succeeded · failed · expired
pending — در انتظار انتقال · detected — روی زنجیره دیده شد و در حال تأیید · succeeded — وجه در کیف پول شما تأیید شد (سفارش را همینجا تحویل دهید) · failed / expired — نهایی. تغییرات بازپرداخت بهصورت رویداد وبهوک میرسند.
checkout window: 30 minutes, then → expired
خطاها و محدودیتها
همه خطاها یک قالب واحد دارند. کدها ثابتاند — بر اساس error.code تصمیم بگیرید، نه متن پیام.
HTTP 4xx/5xx
{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key reused with a different request"
}
}| 401 unauthorized | missing or invalid API key |
| 404 not_found | unknown payment id (or a live id with a test key) |
| 409 idempotency_conflict | Idempotency-Key reused with a different body — identical retries replay the original response |
| 422 (validation) | malformed body — bad amount, unsupported currency |
| 429 rate_limited | over the per-key budget: 100 writes/min, 1000 reads/min |
محصولات، لینکهای پرداخت، نقاط وبهوک و بازپرداختها از داشبورد مدیریت میشوند — هنوز نقطه REST عمومی ندارند.
وبهوکها
در داشبورد بخش «Webhooks» یک نقطه پایانی اضافه کنید و رویدادهای موردنظر را انتخاب کنید. هر نقطه یک سرّ امضای اختصاصی (…whsec_) میگیرد که فقط هنگام ساخت نمایش داده میشود.
| payment.created | A payment intent was created (API or checkout link). |
| payment.detected | The transfer was seen on-chain / in the KEM ledger; confirming. |
| payment.succeeded | Funds are confirmed in your business wallet. Fulfill on this event. |
| payment.failed | The payment failed. |
| payment.expired | The checkout window closed without payment. |
| payment.refund.created | A refund was initiated from the dashboard. |
| payment.refund.succeeded | The refund settled back to the customer. |
بدنه رویداد
{
"id": "payment_event_01J...",
"type": "payment.succeeded",
"created": "2026-07-13T13:04:12+00:00",
"data": {
"payment": {
"id": "pay_01J...",
"status": "succeeded",
"amount_minor": 25000000,
"currency": "USDT",
"merchant_reference": "order-1042",
"network": "TRON",
"product_id": null,
"payment_link_id": null
}
}
}راستیآزمایی امضاها
هر تحویل یک هدر Kem-Signature دارد. HMAC را روی «<t>.» بهعلاوه بدنه خام درخواست با سرّ نقطه خود بازمحاسبه کنید و با مقایسه زمان-ثابت بسنجید. هر چیز نامنطبق را رد کنید.
Kem-Signature: t=<unix_timestamp>,v1=<hmac_sha256_hex>
signed_input = "<t>." + raw_request_body
v1 = HMAC_SHA256(endpoint_secret, signed_input) # secret: whsec_...
# reject replays: drop the delivery when |now - t| > 300simport crypto from "node:crypto";
export function verifyKemSignature(rawBody, header, secret) {
// header: "t=1720000000,v1=hex"
const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
const expected = crypto
.createHmac("sha256", secret) // secret: whsec_...
.update(`${parts.t}.`)
.update(rawBody) // the RAW request bytes
.digest("hex");
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}import hashlib, hmac
def verify_kem_signature(raw_body: bytes, header: str, secret: str) -> bool:
parts = dict(p.split("=") for p in header.split(","))
expected = hmac.new(
secret.encode(), f"{parts['t']}.".encode() + raw_body, hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, parts["v1"])تحویل و تلاش مجدد
سریع با 2xx پاسخ دهید. تحویلهای ناموفق با فاصلههای افزایشی تکرار و سپس بایگانی میشوند:
1m · 5m · 30m · 2h · 12h · 24h
آزمایش
با کلید آزمایشی میتوانید یک پرداخت را بدون جابهجایی پول در کل چرخه پیش ببرید — انتقالها را شبیهسازی کنید و رسیدن وبهوکها را ببینید:
curl -X POST https://api-business.kemapp.io/v1/payments/{id}/_simulate/succeeded \
-H "Authorization: Bearer sk_test_..."