> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oneclickdz.com/llms.txt
> Use this file to discover all available pages before exploring further.

# التحقق من مفتاح API

> تأكّد من أن مفتاح دفع الفواتير يعمل ومن البيئة التي ينتمي إليها

<div dir="ltr">
  ## نظرة عامة

  يتحقق من مفتاح API الخاص بدفع الفواتير ويعيد إليك من أنت والبيئة التي يرتبط بها المفتاح. وهو أول استدعاء يجب إجراؤه في أي تكامل جديد، وأأمن وسيلة لإثبات أنك موجَّه إلى sandbox لا إلى الإنتاج، قبل أن تحرّك أي أموال.

  <Note>
    كل مفتاح مرتبط ببيئة واحدة فقط لا غير — `SANDBOX` أو `PRODUCTION`. البيئة خاصية للمفتاح الذي نُصدره لك. **لا تستنتجها أبدًا من نص المفتاح أو من بادئته**؛ اقرأ `key.type` من هذا endpoint.
  </Note>

  يوجد دفع الفواتير على `https://billapi.oneclickdz.com`، لا على عنوان URL الأساسي الذي تستخدمه بقية المنصة. أما الترويسة فهي نفسها التي تستخدمها بالفعل: `X-Access-Token`.

  ## الاستجابة

  <ResponseField name="success" type="boolean" required>
    `true` عند التحقق من المفتاح بنجاح.
  </ResponseField>

  <ResponseField name="data" type="object" required>
    <Expandable title="properties">
      <ResponseField name="account" type="object" required>
        <Expandable title="properties">
          <ResponseField name="id" type="string" required>
            معرّف حساب الشريك الخاص بك.
          </ResponseField>

          <ResponseField name="status" type="string" required>
            `ACTIVE` لمفتاح اجتاز التحقق.
          </ResponseField>

          <ResponseField name="currency" type="string" required>
            دائمًا `DZD`.
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="key" type="object" required>
        <Expandable title="properties">
          <ResponseField name="type" type="string" required>
            `SANDBOX` أو `PRODUCTION`. البيان الموثوق الوحيد للبيئة التي يعمل فيها هذا المفتاح.
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="meta" type="object" required>
    <Expandable title="properties">
      <ResponseField name="timestamp" type="string" required>
        وقت الاستجابة، بتنسيق ISO 8601 UTC.
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="requestId" type="string" required>
    معرّف الربط، يُرسَل أيضًا في ترويسة الاستجابة `X-Request-Id`.
  </ResponseField>

  ## الأمثلة

  <CodeGroup>
    ```bash cURL theme={null}
    curl https://billapi.oneclickdz.com/v3/validate \
      -H "X-Access-Token: YOUR_API_KEY"
    ```

    ```javascript Node.js theme={null}
    const response = await fetch("https://billapi.oneclickdz.com/v3/validate", {
      headers: { "X-Access-Token": process.env.ONECLICKDZ_API_KEY },
    });

    const body = await response.json();

    if (!body.success) {
      throw new Error(`${body.error.code}: ${body.error.message}`);
    }

    console.log(`Account ${body.data.account.id} — ${body.data.key.type}`);
    ```

    ```python Python theme={null}
    import os
    import requests

    response = requests.get(
        'https://billapi.oneclickdz.com/v3/validate',
        headers={'X-Access-Token': os.getenv('ONECLICKDZ_API_KEY')}
    )

    body = response.json()

    if not body['success']:
        raise RuntimeError(f"{body['error']['code']}: {body['error']['message']}")

    print(f"Account {body['data']['account']['id']} — {body['data']['key']['type']}")
    ```

    ```php PHP theme={null}
    <?php
    $ch = curl_init('https://billapi.oneclickdz.com/v3/validate');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'X-Access-Token: ' . getenv('ONECLICKDZ_API_KEY')
    ]);

    $body = json_decode(curl_exec($ch), true);
    curl_close($ch);

    if (!$body['success']) {
        throw new Exception($body['error']['code'] . ': ' . $body['error']['message']);
    }

    echo "Account {$body['data']['account']['id']} — {$body['data']['key']['type']}";
    ?>
    ```
  </CodeGroup>

  ### استجابة النجاح

  ```json theme={null}
  {
    "success": true,
    "data": {
      "account": {
        "id": "partner_7f21",
        "status": "ACTIVE",
        "currency": "DZD"
      },
      "key": {
        "type": "SANDBOX"
      }
    },
    "meta": {
      "timestamp": "2026-08-31T10:15:32.194Z"
    },
    "requestId": "req_9f3a1c72e0b84d51aB3xZq07"
  }
  ```

  ## استجابات الخطأ

  <AccordionGroup>
    <Accordion title="401 — رمز وصول مفقود">
      **لم تُرسَل ترويسة `X-Access-Token`.**

      ```json theme={null}
      {
        "success": false,
        "error": {
          "code": "MISSING_ACCESS_TOKEN",
          "message": "X-Access-Token header is required."
        },
        "requestId": "req_9f3a1c72e0b84d51aB3xZq07"
      }
      ```

      **ما العمل:** أضف الترويسة. لا يقبل دفع الفواتير المفتاح إلا في تلك الترويسة — لا في سلسلة استعلام ولا في متن الطلب.
    </Accordion>

    <Accordion title="401 — رمز وصول غير صالح">
      **رُفض المفتاح.**

      ```json theme={null}
      {
        "success": false,
        "error": {
          "code": "INVALID_ACCESS_TOKEN",
          "message": "The provided access token is invalid."
        },
        "requestId": "req_9f3a1c72e0b84d51aB3xZq07"
      }
      ```

      **ما العمل:** تحقّق من وجود خطأ في النسخ واللصق، ثم تواصل مع الدعم. إعادة المحاولة بالمفتاح نفسه لن تغيّر الإجابة.
    </Accordion>

    <Accordion title="503 — المصادقة غير متاحة">
      **لم نتمكن من التحقق من مفتاحك في الوقت المناسب. مفتاحك ليس هو المشكلة.**

      ```json theme={null}
      {
        "success": false,
        "error": {
          "code": "AUTH_UNAVAILABLE",
          "message": "Authentication is temporarily unavailable. Please retry shortly."
        },
        "requestId": "req_9f3a1c72e0b84d51aB3xZq07"
      }
      ```

      **ما العمل:** انتظر المدة المحددة في ترويسة `Retry-After` (5 ثوانٍ) ثم أعد المحاولة. لا تُظهر هذا لعميلك أبدًا على أنه خطأ في بيانات الاعتماد، ولا تعطّل المفتاح بسببه.
    </Accordion>

    <Accordion title="503 — الخدمة غير متاحة">
      **واجهة دفع الفواتير في صيانة مُخطّط لها.**

      ```json theme={null}
      {
        "success": false,
        "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "The service is temporarily unavailable. Please retry shortly."
        },
        "requestId": "req_9f3a1c72e0b84d51aB3xZq07"
      }
      ```

      **ما العمل:** التزم بـ `Retry-After` وأعد المحاولة.
    </Accordion>
  </AccordionGroup>

  ## تأكيد بيئتك قبل الإطلاق

  نفّذ هذا الفحص عند بدء التشغيل، ثم مرة أخرى في خط النشر لديك. سطر واحد من المخرجات يخبرك ما إذا كان المفتاح الموجود في إعدادات تلك البيئة هو المفتاح الذي قصدت إطلاقه.

  ```javascript theme={null}
  async function assertEnvironment(expected) {
    const response = await fetch("https://billapi.oneclickdz.com/v3/validate", {
      headers: { "X-Access-Token": process.env.ONECLICKDZ_API_KEY },
    });

    const body = await response.json();

    if (!body.success) {
      throw new Error(`Key check failed: ${body.error.code}`);
    }

    if (body.data.key.type !== expected) {
      throw new Error(
        `Wrong key: expected ${expected}, got ${body.data.key.type}`,
      );
    }

    return body.data.account.id;
  }

  // In your sandbox deployment
  await assertEnvironment("SANDBOX");
  ```

  <Warning>
    مفتاح sandbox ومفتاح الإنتاج متبادلان في الشكل لا في الأثر. مفتاح الإنتاج يحرّك أموالًا حقيقية عند أول عملية دفع ناجحة. تحقّق من `key.type` قبل تفعيل مسار الدفع.
  </Warning>

  ## ما لا يُرجعه هذا endpoint

  مفاتيح دفع الفواتير ليس لها نطاقات صلاحية، ولا حقل انتهاء صلاحية، ولا رصيد لكل مفتاح، لذلك لا يظهر أي منها هنا. `account` و`key.type` و`meta` و`requestId` هي الاستجابة كاملةً.

  ## أفضل الممارسات

  <CardGroup cols={2}>
    <Card title="استدعِه عند بدء التشغيل" icon="power-off">
      استدعاء واحد عند الإقلاع يثبت أن المفتاح يعمل ويحدّد اسم البيئة، قبل أن تصل أي حركة عملاء إلى مسار الدفع.
    </Card>

    <Card title="لا تسجّل المفتاح أبدًا" icon="key">
      سجّل `account.id` و`key.type` بدلًا منه. مكان المفتاح نفسه هو مخزن أسرار، لا سجلات التطبيق.
    </Card>

    <Card title="افصل بين المفتاحين" icon="code-compare">
      احتفظ بمفتاح sandbox ومفتاح الإنتاج في مخازن إعدادات مختلفة كي لا يمكن الوصول إلى أيٍّ منهما من البيئة الأخرى.
    </Card>

    <Card title="تعامل مع 503 على أنه عارض" icon="clock-rotate-left">
      يعني `AUTH_UNAVAILABLE` أننا لم نتمكن من الإجابة في الوقت المناسب. أعد المحاولة بعد `Retry-After`؛ ولا تُدوّر المفتاح.
    </Card>
  </CardGroup>

  ## Endpoints ذات الصلة

  <CardGroup cols={2}>
    <Card title="قائمة الشركاء" icon="building-columns" href="/ar/api-reference/bill-payment/list-partners">
      تحقّق من الشركاء المتاحين
    </Card>

    <Card title="استكشاف الفواتير" icon="magnifying-glass-dollar" href="/ar/api-reference/bill-payment/discover-bills">
      ابدأ استكشاف فاتورة
    </Card>

    <Card title="نظرة عامة على دفع الفواتير" icon="file-invoice-dollar" href="/ar/bill-payment-guides/overview">
      كيف يتكامل التدفق بأكمله
    </Card>

    <Card title="اختبار Sandbox" icon="flask" href="/ar/bill-payment-guides/6-sandbox-testing">
      اختبر كل نتيجة ممكنة قبل الإطلاق
    </Card>
  </CardGroup>
</div>
