🔌 مرجع API
API مدفوعات Zyrix
v1.0
REST API لقبول المدفوعات وإدارة المعاملات وأتمتة سير عمل الدفع عبر MENA وتركيا. Base URL: api.zyrix.co/v1
RESTJSONHTTPS onlyIdempotentWebhooks99.9% SLA
المصادقة
جميع طلبات API تتطلب مصادقة باستخدام مفتاحك السري في رأس Authorization. احتفظ بمفتاحك السري خاصاً — لا تكشف عنه أبداً في كود العميل.
# أضف في كل طلب
Authorization: Bearer sk_live_zyrix_xxxxxxxxxxxxxxxxxxxx
Content-Type: application/json
X-Idempotency-Key: your-unique-key-per-request
sk_live_...
مفتاح سري حي
للخادم فقط
pk_live_...
مفتاح عام حي
للعميل (الدفع)
sk_test_...
مفتاح سري اختباري
للاختبار فقط
معالج المدفوعات
Core APIPOST/v1/payments/intentإنشاء نية دفع
يُنشئ نية دفع — كائن جانب الخادم يمثل محاولة دفع. تلتقط النية المبلغ والعملة وطريقة الدفع والبيانات الوصفية قبل أن يدفع العميل.
جسم الطلب
{
// Required
"amount": 25000, // integer, in smallest unit (kuruş/halala/fils)
"currency": "TRY", // "TRY"|"SAR"|"AED"|"KWD"|"QAR"|"EGP"|"IQD"
"payment_method": "card", // "card"|"crypto"|"cod"|"qr"|"tap_to_pay"
// Crypto-specific (required when payment_method = "crypto")
"crypto_asset": "USDT", // "USDT"|"BTC"|"ETH"
"crypto_network": "trc20", // "trc20"|"erc20"|"bep20"|"bitcoin"|"ethereum"
// Optional — metadata
"merchant_id": "mer_xxxxxxxxx",
"customer_id": "cus_xxxxxxxxx", // Zyrix customer ID (from /customers)
"order_id": "ord_123456", // Your internal order reference
"description": "Order #1234 — Blue Sneakers",
"statement_descriptor": "MYSTORE", // max 22 chars, on bank statement
"metadata": { // arbitrary key-value, returned in webhooks
"product_id": "prod_xyz",
"channel": "mobile_app"
},
// COD-specific
"cod_address": {
"line1": "King Fahd Road",
"city": "Riyadh",
"country": "SA",
"postal_code": "12271"
},
// Split Pay (optional)
"split": [
{ "merchant_id": "mer_supplier_01", "amount": 5000, "currency": "TRY" },
{ "merchant_id": "mer_supplier_02", "amount": 3000, "currency": "TRY" }
],
// Locale for receipts & notifications
"locale": "ar", // "ar"|"tr"|"en"
// Idempotency (also pass as header X-Idempotency-Key)
"idempotency_key": "order_1234_attempt_1"
}استجابة 201 تم الإنشاء
{
"id": "pay_xxxxxxxxxxxxxxxxxx",
"object": "payment_intent",
"status": "requires_payment_method",
// Status flow:
// requires_payment_method → requires_confirmation →
// requires_action → processing → succeeded | failed
"amount": 25000,
"currency": "TRY",
"amount_received": 0,
"payment_method": "card",
// For crypto payments
"crypto": {
"asset": "USDT",
"network": "trc20",
"address": "TQn5nZxxxxxxxxxxxxxxxxxxxxxxxxxx",
"amount_crypto": "8.33", // exact amount customer must send
"rate_locked_until": "2026-03-29T14:30:00Z", // 15-min rate lock
"qr_code_url": "https://api.zyrix.co/v1/qr/pay_xxx"
},
// Checkout URL (for hosted payment page)
"checkout_url": "https://pay.zyrix.co/c/pay_xxxxxxxxx",
"client_secret": "pay_xxx_secret_yyy", // for Zyrix.js client SDK
// Fees (transparent — shown upfront)
"fee": {
"amount": 200, // ₺2.00 in kuruş
"currency": "TRY",
"rate": "0.008", // 0.8%
"breakdown": {
"processing": 200,
"currency_conversion": 0,
"network": 0
}
},
// Settlement
"net_amount": 24800, // amount - fees
"settlement_date": "2026-03-30", // next business day
"merchant_id": "mer_xxxxxxxxx",
"order_id": "ord_123456",
"metadata": { "product_id": "prod_xyz", "channel": "mobile_app" },
"created_at": "2026-03-29T13:45:00Z",
"expires_at": "2026-03-29T14:45:00Z", // 1-hour expiry
"livemode": true
}استجابات الخطأ
400·invalid_amount
المبلغ أقل من الحد الأدنى
400·invalid_currency
العملة غير مدعومة في هذا السوق
401·invalid_api_key
المفتاح السري مفقود أو غير صالح
402·insufficient_funds
رصيد التاجر غير كافٍ
409·idempotency_conflict
نفس مفتاح الidemopotency، معاملات مختلفة
429·rate_limit_exceeded
120 طلب/دقيقة لكل مفتاح API
POST/v1/payments/{payment_id}/confirmتأكيد الدفع
// Request
{
"payment_method_id": "pm_xxxxxxxxx", // from /payment-methods
"return_url": "https://yourstore.com/payment/result"
}
// Response 200
{
"id": "pay_xxxxxxxxxxxxxxxxxx",
"status": "processing", // or "succeeded" for instant methods
"next_action": { // if 3DS required
"type": "redirect_to_url",
"redirect_to_url": {
"url": "https://3ds.bank.com/challenge/...",
"return_url": "https://yourstore.com/payment/result"
}
},
"succeeded_at": null, // populated when status = "succeeded"
"receipt_url": null // WhatsApp receipt sent automatically
}GET/v1/payments/{payment_id}استرداد الدفع
GET /v1/payments/pay_xxxxxxxxxxxxxxxxxx Authorization: Bearer sk_live_xxx // Response 200 — complete payment object with current status
GET/v1/paymentsقائمة المدفوعات
GET /v1/payments?
limit=20 // 1-100, default 20
&starting_after=pay_xxx // cursor pagination
&status=succeeded // filter by status
¤cy=TRY // filter by currency
&payment_method=crypto // filter by method
&created[gte]=1711670400 // Unix timestamp
&created[lte]=1711756800
// Response 200
{
"object": "list",
"data": [ /* array of payment objects */ ],
"has_more": true,
"next_cursor": "pay_yyy",
"total_count": 847
}Webhooks
يرسل Zyrix webhooks لنقطة نهايتك عند حدوث أحداث الدفع. تحقق دائماً من التوقيع باستخدام سر webhook الخاص بك قبل المعالجة.
// Webhook payload structure
{
"id": "evt_xxxxxxxxxxxxxxxxxx",
"type": "payment.succeeded",
// Event types:
// payment.created | payment.processing | payment.succeeded
// payment.failed | payment.refunded | payment.disputed
// crypto.detected | crypto.confirmed | crypto.expired
// cod.assigned | cod.delivered | cod.returned
// payout.paid | invoice.sent | subscription.renewed
"created": 1711756800,
"livemode": true,
"data": {
"object": { /* full payment object */ }
},
"merchant_id": "mer_xxxxxxxxx"
}
// Signature verification (Node.js example)
const crypto = require('crypto');
const expectedSig = crypto
.createHmac('sha256', process.env.ZYRIX_WEBHOOK_SECRET)
.update(rawBody)
.digest('hex');
if (request.headers['x-zyrix-signature'] !== expectedSig) {
return res.status(401).json({ error: 'Invalid signature' });
}⚠️ استجب دائماً بـ HTTP 200 خلال 5 ثوانٍ. يعيد Zyrix المحاولة عند الفشل مع backoff متزايد: 5ث → 30ث → 2د → 10د → 1س → 6س → 24س (7 محاولات إجمالاً).
TypeScript الأنواع
// ── Zyrix Payment Types ─────────────────────────────────────────
// Install: npm install @zyrix/types
// Or use these definitions directly in your project
type ZyrixCurrency = "TRY" | "SAR" | "AED" | "KWD" | "QAR" | "EGP" | "IQD";
type ZyrixCryptoAsset = "USDT" | "BTC" | "ETH";
type ZyrixCryptoNetwork = "trc20" | "erc20" | "bep20" | "bitcoin" | "ethereum";
type ZyrixPaymentMethod = "card" | "crypto" | "cod" | "qr" | "tap_to_pay" | "bank_transfer";
type ZyrixLocale = "ar" | "tr" | "en";
type ZyrixPaymentStatus =
| "requires_payment_method"
| "requires_confirmation"
| "requires_action"
| "processing"
| "succeeded"
| "failed"
| "canceled"
| "refunded";
interface ZyrixCreatePaymentIntent {
amount: number; // in smallest unit
currency: ZyrixCurrency;
payment_method: ZyrixPaymentMethod;
crypto_asset?: ZyrixCryptoAsset;
crypto_network?: ZyrixCryptoNetwork;
merchant_id?: string;
customer_id?: string;
order_id?: string;
description?: string;
statement_descriptor?: string; // max 22 chars
metadata?: Record<string, string>;
locale?: ZyrixLocale;
idempotency_key?: string;
cod_address?: {
line1: string;
city: string;
country: string;
postal_code?: string;
};
split?: Array<{
merchant_id: string;
amount: number;
currency: ZyrixCurrency;
}>;
}
interface ZyrixPaymentIntent {
id: string;
object: "payment_intent";
status: ZyrixPaymentStatus;
amount: number;
currency: ZyrixCurrency;
amount_received: number;
payment_method: ZyrixPaymentMethod;
crypto?: {
asset: ZyrixCryptoAsset;
network: ZyrixCryptoNetwork;
address: string;
amount_crypto: string;
rate_locked_until: string;
qr_code_url: string;
};
fee: {
amount: number;
currency: ZyrixCurrency;
rate: string;
breakdown: {
processing: number;
currency_conversion: number;
network: number;
};
};
net_amount: number;
settlement_date: string;
checkout_url: string;
client_secret: string;
merchant_id: string;
order_id?: string;
metadata?: Record<string, string>;
created_at: string;
expires_at: string;
livemode: boolean;
next_action?: {
type: "redirect_to_url";
redirect_to_url: {
url: string;
return_url: string;
};
};
}
interface ZyrixWebhookEvent {
id: string;
type: string;
created: number;
livemode: boolean;
data: { object: ZyrixPaymentIntent | Record<string, unknown> };
merchant_id: string;
}
// ── Usage example ───────────────────────────────────────────────
async function createPayment(orderAmount: number, currency: ZyrixCurrency) {
const intent: ZyrixCreatePaymentIntent = {
amount: orderAmount * 100, // convert to kuruş/halala
currency,
payment_method: "card",
locale: "ar",
metadata: { source: "mobile_app" },
idempotency_key: `order_${Date.now()}`,
};
const response = await fetch("https://api.zyrix.co/v1/payments/intent", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.ZYRIX_SECRET_KEY}`,
"Content-Type": "application/json",
"X-Idempotency-Key": intent.idempotency_key!,
},
body: JSON.stringify(intent),
});
const payment: ZyrixPaymentIntent = await response.json();
return payment;
}حدود المعدل والحدود
حد معدل API
120 req/min
لكل مفتاح API
أدنى مبلغ دفع
₺1 / SAR 0.10
يختلف حسب العملة
أقصى مبلغ دفع
₺500,000
حدود أعلى عبر المؤسسات
مهلة Webhook
5 seconds
ثم يُعلَّم كفاشل
انتهاء صلاحية الدفع
1 hour
الكريبتو: قفل سعر 15 دقيقة
نافذة التسوية
T+1
يوم العمل التالي (معياري)
SDKs
Node.js / TypeScript
متاحnpm install @zyrix/node
Python
متاحpip install zyrix
PHP
متاحcomposer require zyrix/zyrix-php
Go
قريباًgo get github.com/zyrix/zyrix-go
Ruby
قريباًgem install zyrix
Zyrix.js (Browser)
متاح<script src="https://js.zyrix.co/v1/"></script>
مستعد للتكامل؟
احصل على مفاتيح API الاختبارية فوراً. لا يلزم موافقة للـ sandbox.