💳إنشاء واجهة برمجة تطبيقات الفاتورة
This endpoint creates an invoice scoped to the API key's merchant and returns a customer-ready payment URL.
تأكد من اجتياز صالحةmerchant_id, reference_id، وكميةعند تقديم الطلب. إذا لم يتم العثور على التاجر أو المرجع، أو كان المبلغ غير صالح، سيتم إرجاع خطأ.
📝 معلمات الإدخال
| المعلمة | يكتب | مطلوب | وصف |
|---|---|---|---|
| merchant_id | string | ✔️ | المعرف الفريد للتاجر. هذا مطلوب لإنشاء فاتورة. |
| reference_id | string | ✔️ | Your unique order ID (1–36 characters). Reuse the same value only when retrying the identical request. |
| currency_id | string | ✔️ | UUID of an operational currency on a network with an active wallet. |
| كمية | string | ✔️ | Decimal string, at least 1, up to 28 total digits and 12 decimal places; for example "10.50". |
| وصف | string | ❌ | Optional, up to 500 characters; must remain unchanged on retries. |
- 🔹 تتطلب واجهة برمجة التطبيقاتمفتاح واجهة برمجة التطبيقاتللمصادقة.
- 🔹 الmerchant_idيجب أن يتم تمريرها في نص الطلب.
- 🔹 الكميةيجب أن يكون تمثيل سلسلة صالحًا لرقم وأكبر من 1.
Request body format
Send this request body as JSON. In Postman, select Body → raw → JSON. multipart/form-data is not supported by this endpoint.
The Idempotency-Key header is required and must exactly match the reference_id in the request body.
Backend integration examples
Choose your backend language. Every example reads secret credentials only from environment variables.
const response = await fetch("https://api.dinakel.com/api/gateway/v1/invoices", {
method: "POST"
headers: {
Authorization: `Bearer ${process.env.DINAKEL_API_KEY}`,
Accept: "application/json",
"Content-Type": "application/json",
"Idempotency-Key": process.env.DINAKEL_REFERENCE_ID
}
body: JSON.stringify({
merchant_id: process.env.DINAKEL_MERCHANT_ID,
reference_id: process.env.DINAKEL_REFERENCE_ID,
currency_id: process.env.DINAKEL_CURRENCY_ID,
amount: "10.50",
description: "Order payment"
})
});
const result = await response.json();
if (!response.ok) throw new Error(result.message || "Dinakel request failed");
console.log(result);💡 طلب مثال
POST https://api.dinakel.com/api/gateway/v1/invoices
Headers:
Authorization: Bearer <your_api_key>
Idempotency-Key: <reference_id>
Content-Type: application/json
Accept: application/json
Body (raw JSON; not form-data):
{
"merchant_id": "<merchant_id>",
"reference_id": "<reference_id>",
"currency_id": "<currency_id>",
"amount": "<amount>",
"description": "<description>"
}
🔍 الرد المثالى
{
"status": true,
"statusCode": 201,
"invoice_id": "<invoice_id>",
"data": {
"invoice_id": "<invoice_id>",
"invoice_status": "draft",
"payment_url": "https://dinakel.com/gateway-payment?invoice_id=<invoice_id>",
"idempotency_replayed": false
}
}
For retries, resend the same reference_id and unchanged invoice data. A replay returns HTTP 200 with the original invoice ID; a new invoice returns HTTP 201.
⚠️ معالجة الأخطاء
توفر واجهة برمجة التطبيقات استجابات الخطأ التالية:
{
"status": false,
"statusCode": 400,
"message": "Amount must be a valid decimal number."
}
400 Bad Request:معلمة المبلغ غير صالحة. تأكد من أن المبلغ رقم عشري صالح وأكبر من 1.
{
"status": false,
"statusCode": 409,
"message": "reference_id is already used with different invoice data",
"message_key": "api.invoice.idempotency_conflict"
}
409 Conflict: The reference was already used with different invoice data.
{
"status": false,
"statusCode": 403,
"message": "API key is not authorized for this merchant"
}
403 Forbidden: The key belongs to another merchant.
{
"status": false,
"statusCode": 409,
"message": "Financial commands are unavailable for this currency",
"operational_status": "maintenance"
}
409 Conflict: The network or currency is temporarily unavailable.
429 Too Many Requests: Up to 20 create requests per minute per key; use Retry-After.
{
"status": false,
"statusCode": 500,
"message": "Internal server error"
}
500 Internal Server Error:حدث خطأ غير متوقع على الخادم. حاول مرة أخرى لاحقًا أو اتصل بالدعم.