رويــــــالوحة المطور

RUYA / توثيق المطورين

إشعارات Webhook

أمثلة هذه الصفحة تستخدم Sandbox ولا تنقل أموالاً. واجهة Live منفصلة وتتطلب اعتماد الحساب وطريقة الاستلام واشتراكاً سارياً.

دليل التكامل

يجب أن تكون الوجهة HTTPS عامة على 443؛ تُحظر العناوين الداخلية وإعادة التوجيه. يظهر السر مرة واحدة. يثبت معرف الحدث عبر المحاولات ويتجدد الوقت. تعيد قائمة الانتظار الإرسال حتى ثماني مرات بتأخير متزايد حتى ساعة. راجع التسليم وأعد FAILED من اللوحة. ارفض التوقيع الأقدم من خمس دقائق واحفظ معرف الحدث الفريد مع تحديث الطلب.

Node.js · signature verification
import { createHmac, timingSafeEqual } from 'node:crypto';
// Run BEFORE JSON parsing. req.body must be a raw Buffer.
export function verifyRuya(rawBody, headers, secret) {
  const timestamp = headers['x-ruya-timestamp'];
  const signature = headers['x-ruya-signature'];
  if (typeof timestamp !== 'string' || !/^\d+$/.test(timestamp) ||
      Math.abs(Date.now() - Number(timestamp)) > 300000 ||
      typeof signature !== 'string' || !/^[a-f0-9]{64}$/i.test(signature)) {
    throw new Error('Invalid or stale signature');
  }
  const expected = createHmac('sha256', secret)
    .update(timestamp + '.').update(rawBody).digest();
  if (!timingSafeEqual(expected, Buffer.from(signature, 'hex'))) {
    throw new Error('Invalid signature');
  }
  const event = JSON.parse(rawBody.toString('utf8'));
  if (event.id !== headers['x-ruya-id']) throw new Error('Event ID mismatch');
  return event;
}
// In one database transaction: insert event.id into a UNIQUE receipt table;
// match stored order reference, amount, currency and environment;
// update the order. A duplicate receipt returns 2xx without another update.
// Sandbox: data.mode === 'SANDBOX', event === 'payment.succeeded'.
// Live: data.environment === 'LIVE', event === 'payment.paid',
// data.verification === 'MANUAL_ACCOUNT_REVIEW'. Never mix these stores.

المسارات المنفّذة

POST /api/v1/webhooks/endpoints

المصادقة / الصلاحيات: webhooks:write · HTTP 201

Example request / مثال الطلب
{
  "url": "https://your-merchant.example/webhooks/ruya",
  "events": [
    "payment.succeeded",
    "payment.failed"
  ]
}
cURL
curl -X POST 'https://ruya.site/api/v1/webhooks/endpoints'
  -H 'Authorization: Bearer YOUR_SERVER_SIDE_TEST_KEY'
  -H 'Content-Type: application/json'
  --data '{"url":"https://your-merchant.example/webhooks/ruya","events":["payment.succeeded","payment.failed"]}'
Node.js backend
const response = await fetch("https://ruya.site/api/v1/webhooks/endpoints", {
  method: 'POST',
  headers: { Authorization: 'Bearer ' + process.env.RUYA_TEST_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
  "url": "https://your-merchant.example/webhooks/ruya",
  "events": [
    "payment.succeeded",
    "payment.failed"
  ]
})
});
if (!response.ok) throw new Error('RUYA HTTP ' + response.status);
const result = await response.json();
مخططات الطلب والرد الناجح
Generated contract / العقد المولّد
{
  "request": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "url": {
        "type": "string",
        "maxLength": 2000,
        "format": "starts_with",
        "pattern": "^https:\\/\\/.*"
      },
      "events": {
        "minItems": 1,
        "type": "array",
        "items": {
          "type": "string",
          "enum": [
            "payment.created",
            "payment.succeeded",
            "payment.failed",
            "payment.cancelled",
            "payment.refunded",
            "payment.expired"
          ]
        }
      }
    },
    "required": [
      "url",
      "events"
    ]
  },
  "response": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "url": {
        "type": "string"
      },
      "secret": {
        "type": "string"
      },
      "events": {
        "type": "array",
        "items": {
          "type": "string"
        }
      }
    },
    "required": [
      "id",
      "url",
      "secret",
      "events"
    ]
  }
}

استبدل معاملات المسار بمعرف سجلك. اتبع قسم الأخطاء للردود الفاشلة. لا تحتوي الأمثلة على مفاتيح حقيقية أو نتائج دفع فعلية.

جرّب في Sandbox

GET /api/v1/webhooks

المصادقة / الصلاحيات: Authenticated merchant; API access varies by operation · HTTP 200

cURL
curl -X GET 'https://ruya.site/api/v1/webhooks'
  -H 'Cookie: ruya_session=YOUR_SERVER_SESSION'
Node.js backend
const response = await fetch("https://ruya.site/api/v1/webhooks", {
  method: 'GET',
  headers: { Cookie: 'ruya_session=' + process.env.RUYA_SESSION, }
});
if (!response.ok) throw new Error('RUYA HTTP ' + response.status);
const result = await response.json();
مخططات الطلب والرد الناجح
Generated contract / العقد المولّد
{
  "request": null,
  "response": {
    "type": "array",
    "items": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "events": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "deliveries": {
          "type": "array",
          "items": {
            "$ref": "#/schemas/Delivery"
          }
        }
      },
      "required": [
        "id",
        "url",
        "events",
        "deliveries"
      ]
    }
  }
}

استبدل معاملات المسار بمعرف سجلك. اتبع قسم الأخطاء للردود الفاشلة. لا تحتوي الأمثلة على مفاتيح حقيقية أو نتائج دفع فعلية.

جرّب في Sandbox

POST /api/v1/webhooks/:id/retry

المصادقة / الصلاحيات: Authenticated merchant; API access varies by operation · HTTP 201

Parameters / المعاملات
[
  {
    "name": "id",
    "in": "path",
    "required": true,
    "schema": {
      "type": "string"
    }
  }
]
cURL
curl -X POST 'https://ruya.site/api/v1/webhooks/:id/retry'
  -H 'Cookie: ruya_session=YOUR_SERVER_SESSION'
Node.js backend
const response = await fetch("https://ruya.site/api/v1/webhooks/:id/retry", {
  method: 'POST',
  headers: { Cookie: 'ruya_session=' + process.env.RUYA_SESSION, }
});
if (!response.ok) throw new Error('RUYA HTTP ' + response.status);
const result = await response.json();
مخططات الطلب والرد الناجح
Generated contract / العقد المولّد
{
  "request": null,
  "response": {
    "type": "object",
    "properties": {
      "ok": {
        "const": true
      }
    },
    "required": [
      "ok"
    ]
  }
}

استبدل معاملات المسار بمعرف سجلك. اتبع قسم الأخطاء للردود الفاشلة. لا تحتوي الأمثلة على مفاتيح حقيقية أو نتائج دفع فعلية.

جرّب في Sandbox

آخر تحديث: ٥ ديسمبر ٢٠٢٦. مرجع المسارات مولّد من المتحكمات ومخططات التحقق الحالية.