مرجع الواجهة البرمجية
واجهة Forypay REST
JSON بسيط عبر HTTPS مع مصادقة bearer. نقطتا نهاية تغطّيان دورة حياة الدفعة بالكامل؛ وثالثة تتحقق من معاملة واحدة تملك بصمتها مسبقًا.
البناء بالذكاء الاصطناعي
تستخدم مساعد برمجة بالذكاء الاصطناعي مثل Claude أو ChatGPT أو Cursor أو Copilot؟ انسخ هذا الأمر والصقه فيه داخل مشروعك. يصف الواجهة كاملةً وتوقيع الـ webhook وقواعد الأمان، ويطلب من المساعد بناء صفحة الدفع ومعالج الـ webhook وحقول قاعدة البيانات والاختبارات نيابةً عنك.
- أنشئ مفتاح API من صفحة المشاريع، واضبط رابط الـ webhook وسرّ التوقيع من الإعدادات.
- انسخ الأمر واملأ أسطر «About my project»، أو دع المساعد يسألك عنها.
- الصقه في مساعدك ومشروعك مفتوح، ثم راجع خطته قبل أن يكتب الكود.
You are a senior engineer integrating Forypay USDT payments into my application. Forypay watches the blockchain for a USDT transfer to my wallet address and tells my server when it arrives. Work in my existing codebase and follow its conventions.
## About my project (fill in or ask me)
- Language / framework: <e.g. Next.js, Laravel, Django, Express>
- Where orders live: <e.g. Postgres "orders" table>
- Networks I accept: <bsc, tron, or both>
- My receiving wallet address(es): <0x… for BSC, T… for TRON>
If anything above is missing, inspect the codebase first, then ask me before writing code.
## Forypay API — authoritative facts (do not invent anything beyond these)
Base URL: https://forypay.com
Auth: every request sends `Authorization: Bearer <API key>`. Keys start with `fp_test_` or `fp_live_` and are created in the Forypay dashboard → Projects. An fp_test_ key creates TEST payments: never watched on chain, never billed, and no real transfer can settle them — move them with POST /api/v1/payments/{id}/simulate instead. An fp_live_ key creates live payments, monitored on the real BSC/TRON mainnets. The key is a server-side secret: never ship it to a browser or mobile app.
All requests and responses are JSON. Amounts are always decimal STRINGS such as "25.00" — never floats or numbers.
Stablecoins accepted per network — bsc: USDT · tron: USDT · polygon: USDT, USDC · base: USDC. Pass `token` to choose one; omit it for the network's default (the first listed).
### POST /api/v1/payments — create a payment
Body:
- network (required): "bsc" | "tron" | "polygon" | "base"
- token (optional): "USDT" | "USDC" — must be one the network accepts (see above); default is the network's first
- receiver (required): my wallet address on that network (BSC, Polygon, Base: checksummed 0x address; TRON: base58 address starting with T)
- amount (required): decimal string, e.g. "25.00"
- order_id (optional): my order reference, max 191 chars
- expires_in (optional): integer seconds, minimum 60
- expected_sender (optional): payer's address, same network format
Header `Idempotency-Key: <unique per order>` makes retries safe: repeating it returns the existing payment instead of creating a second one.
Response 200:
{ "id", "order_id", "network", "token": "USDT", "amount", "receiver", "status": "PENDING", "expires_at", "usage": {...} }
IMPORTANT: the returned `amount` can be slightly HIGHER than requested (e.g. "25.0001"). Forypay nudges it so that two open payments to the same address never share an amount — that is how it tells customers apart. Store the returned amount and show the payer exactly that figure, with all its decimals. A transfer of any other amount will not settle the payment.
### GET /api/v1/payments/{id} — fetch one payment
Returns: id, order_id, network, token, expected_amount, detected_amount, status, transaction_hash, sender, receiver, created_at, detected_at, confirmed_at, transfers[]. 404 → PAYMENT_NOT_FOUND.
Every payment response also carries checkout_url: a hosted page (/pay/{id}) showing the payer the exact amount, address, QR code and live status. Redirect the customer there instead of building your own payment screen if you prefer; it shows no order or merchant details. Pass return_url (https, include your order reference) on create and the page sends the payer back to it once the payment settles — but still treat only the webhook / GET status as proof of payment, never the arrival on return_url.
### GET /api/v1/payments?limit=N&cursor=C — list payments, newest first
Returns { "data": [...], "has_more": bool, "next_cursor": string|null }. limit 1–100 (default 20). To page, pass next_cursor back as cursor until has_more is false. An invalid cursor → 400 INVALID_CURSOR.
### POST /api/v1/payments/{id}/simulate — test mode only
Body: { "action": "pay" | "underpay" | "overpay" | "expire" }. Only with an fp_test_ key and only for a payment created with one (live key → 403 FORBIDDEN; live payment → 409 NOT_TEST_PAYMENT; settled/expired → 409 PAYMENT_NOT_OPEN). pay sends exactly what is owed (→ CONFIRMED), underpay sends half (→ DETECTED), overpay sends the remainder + 1 token, expire ends a PENDING payment (→ EXPIRED). The real webhooks fire, so this is how to test the webhook handler end to end. Every payment response and webhook payload carries test_mode (true/false): in production, never fulfil an order whose payment has test_mode true.
### POST /api/v1/verify — verify one transaction hash I already have
Body: { "network", "transaction_hash", "receiver" }. Returns { valid, status, network, transaction_hash, sender, receiver, amount, ... }. Each call is billed, so do not poll it; it is not needed for the normal checkout flow.
### Payment statuses
PENDING → waiting for the transfer
DETECTED → money was seen but the payment is not settled: either underpaid, or the full amount is still waiting for network confirmations. Do NOT fulfil.
CONFIRMED → paid in full. Fulfil the order.
OVERPAID → more than the amount arrived. Fulfil the order and flag it for review.
EXPIRED → expires_in elapsed without payment. Do not fulfil.
Settlement is immediate on detection; there is no confirmation-count wait.
### Webhooks
Configured in the dashboard → Settings (webhook URL + signing secret). The URL must be public HTTPS; redirects are not followed; the request times out after 10 seconds.
Events: payment.detected, payment.confirmed, payment.expired.
Each delivery is a POST with these headers:
- X-Forypay-Event: event name
- X-Forypay-Delivery: delivery id, stable across retries — use it to dedupe
- X-Forypay-Timestamp: unix seconds
- X-Forypay-Signature: sha256=<hex>
Body example: { "event": "payment.confirmed", "data": { "payment_id", "order_id", "network", "token", "amount", "transaction_hash", "status" } }
Signature = "sha256=" + hex(HMAC-SHA256(secret, timestamp + "." + rawBody)), where rawBody is the exact received bytes BEFORE any JSON parsing. Compare in constant time. Reject if |now − timestamp| > 300 seconds.
Any 2xx response acknowledges the delivery. Otherwise Forypay retries after 1m, 5m, 15m, 1h, 6h and 24h, so the handler must be idempotent.
### Errors
Shape: { "error": { "code", "message", "request_id" } }. Branch on `code`, never on `message`. Log `request_id`.
400 INVALID_REQUEST (message names the bad field) · 400 INVALID_AMOUNT · 400 INVALID_TOKEN · 401 INVALID_API_KEY · 402 QUOTA_EXCEEDED / INSUFFICIENT_CREDITS (plan limit reached — show a clear error, do not retry) · 403 ACCOUNT_DISABLED · 404 PAYMENT_NOT_FOUND · 429 RATE_LIMITED · 5xx (retry with backoff).
## What to build
1. Configuration: read FORYPAY_API_KEY, FORYPAY_WEBHOOK_SECRET, FORYPAY_BASE_URL (default https://forypay.com) and the receiving address(es) from environment variables. Add them to the example env file. Never hard-code secrets.
2. A small server-side Forypay client: createPayment, getPayment. Timeouts; retry only on 429/5xx/network errors with exponential backoff, always reusing the same Idempotency-Key.
3. Persistence: add to my order model (with a migration) forypay_payment_id, network, pay_amount (string/decimal — not float), receiver, payment_status, expires_at, paid_at, transaction_hash.
4. Checkout: when the customer picks "Pay with USDT", create the payment with Idempotency-Key = my order id and order_id = my order id, save the response, then show a payment page with: network name, receiver address (with copy button and a QR code of the address), the exact returned amount (with copy button), a countdown to expires_at, and a clear warning to send USDT on the correct network only.
5. Webhook endpoint: read the RAW body, verify the signature and timestamp (reject with 401 otherwise), dedupe on X-Forypay-Delivery, then re-fetch the payment with GET /api/v1/payments/{id} and act on THAT status — not on the webhook body alone. Mark the order paid exactly once (CONFIRMED or OVERPAID), cancel/release it on EXPIRED. Return 2xx quickly; do slow work asynchronously. Make sure no body-parsing middleware alters the raw body for this route, and that CSRF protection excludes it.
6. Fallback: the payment page polls MY backend every ~10 seconds, and my backend reads its stored status (refreshing from GET /api/v1/payments/{id} if the payment is still open), so the order still completes if a webhook is delayed.
7. Tests: signature verification (valid, wrong secret, tampered body, stale timestamp), idempotent webhook handling (same delivery twice), the status → order-state mapping, and that a payment with test_mode true is never fulfilled when running with a live key.
8. Finish with a short README section: env vars, how to set the webhook URL in the Forypay dashboard, and how to test end to end without real money: create a payment with the fp_test_ key, then call POST /api/v1/payments/{id}/simulate with pay, underpay, overpay and expire (or use the buttons on the checkout page) and watch the webhook update the order.
## Rules
- Never use floating-point numbers for money anywhere.
- Never expose the API key or webhook secret to the client.
- Never mark an order paid from a browser redirect or client-side check — only from a verified webhook or a server-side GET.
- Do not invent endpoints, fields or statuses not listed above. If you need something that is not here, ask me.
- Work in small steps and show me the plan before making large changes.لا تلصق مفاتيحك في المحادثة أبدًا
المصادقة
كل المسارات أدناه نسبية إلى هذا الرابط الأساسي. أرسل الطلبات عبر HTTPS بجسم JSON.
https://forypay.com/api/v1كل طلب يحمل مفتاح API للمشروع كرمز bearer. تُنشأ المفاتيح في لوحة التحكم ضمن مفاتيح API، وتُعرض مرة واحدة عند الإنشاء، وتُخزَّن كبصمة فقط — فإن فقدت مفتاحًا، أبطِله وأصدر غيره.
Authorization: Bearer fp_live_9f2c…المفاتيح أسرار
إنشاء دفعة
POST/api/v1/payments
يسجّل الدفعة التي تتوقّع استلامها ويبدأ مراقبة السلسلة. تخبرك الاستجابة بموعد إغلاق النافذة.
تحصل كل دفعة أيضًا على صفحة دفع مستضافة. وجّه عميلك إلى checkout_url في الاستجابة فيرى المبلغ الدقيق والعنوان ورمز QR والحالة المباشرة — دون تفاصيل الطلب أو التاجر — بدل شاشة تبنيها بنفسك.
| الحقل | النوع | الوصف |
|---|---|---|
| مطلوب | السلسلة التي سيرسل عليها الدافع. | |
| اختياري | العملة المستقرة المطلوب استلامها. اختياري — عند حذفه تُستخدم العملة الافتراضية للشبكة (الأولى في القائمة). المقبول لكل شبكة: bsc: USDT · tron: USDT · polygon: USDT, USDC · base: USDC | |
| مطلوب | عنوان الاستلام الخاص بك. 0x… على BSC وPolygon وBase، و T… على TRON. | |
| مطلوب | المبلغ العشري كنص، مثل "25.00". يُرسل كنص لتجنّب تدوير الأعداد العائمة. | |
| اختياري | مرجعك الخاص، حتى 191 حرفًا. يُعاد إرساله مع كل Webhook. | |
| اختياري | الثواني حتى إغلاق نافذة الدفع. الحد الأدنى 60. أهمِله لعدم انتهاء الصلاحية — تبقى الدفعة حينها مفتوحة حتى يصل المبلغ الدقيق. | |
| اختياري | يقيّد المطابقة على التحويلات القادمة من هذا العنوان. | |
| اختياري | عنوان https تُرسل إليه صفحة الدفع المستضافة الدافعَ بعد تسوية الدفعة، بعد عرض اسم المضيف لبضع ثوانٍ. ضمّنه مرجع طلبك. يظهر علنًا في صفحة الدفع. |
أضف ترويسة Idempotency-Key لتجعل إعادة المحاولة آمنة: الطلب المتكرّر بالمفتاح ذاته يُرجع الدفعة الأصلية بدل إنشاء دفعة ثانية.
المبلغ الدقيق، ما دامت الدفعة مفتوحة
curl -X POST https://forypay.com/api/v1/payments \
-H "Authorization: Bearer $FP_API_KEY" \
-H "Idempotency-Key: ORDER-1042" \
-H "Content-Type: application/json" \
-d '{
"order_id": "ORDER-1042",
"network": "bsc",
"receiver": "0x2f1a…9c3e",
"amount": "25.00",
"expires_in": 1800
}'{
"id": "pay_8Fq2mZx1LrKd",
"order_id": "ORDER-1042",
"network": "bsc",
"token": "USDT",
"amount": "25.00",
"receiver": "0x2f1a…9c3e",
"status": "PENDING",
"expires_at": "2026-08-17T14:35:00.000Z"
}جلب دفعة
GET/api/v1/payments/{id}
يُرجع الحالة الراهنة مع كل تحويل مطابق. استخدمه للتسوية، أو كبديل إذا كانت نقطة نهاية Webhook لديك غير متاحة.
جرّبهاcurl https://forypay.com/api/v1/payments/pay_8Fq2mZx1LrKd \
-H "Authorization: Bearer $FP_API_KEY"{
"id": "pay_8Fq2mZx1LrKd",
"order_id": "ORDER-1042",
"network": "bsc",
"token": "USDT",
"expected_amount": "25.00",
"detected_amount": "25.00",
"status": "CONFIRMED",
"transaction_hash": "0x9d4c…7b21",
"sender": null,
"receiver": "0x2f1a…9c3e",
"created_at": "2026-08-17T14:05:00.000Z",
"detected_at": "2026-08-17T14:05:12.000Z",
"confirmed_at": "2026-08-17T14:05:21.000Z",
"transfers": [ /* … */ ]
}سرد المدفوعات
GET/api/v1/payments
يُرجع المدفوعات الحديثة، الأحدث أولًا، مغلَّفة في مصفوفة data. أضف limit لتغيير حجم الصفحة — القيمة الافتراضية 20 والحد الأقصى 100.
عندما تكون قيمة has_more صحيحة، أعِد قيمة next_cursor المُرجَعة في المعامل cursor لجلب الصفحة التالية الأقدم. المؤشرات معتمة؛ والمؤشر غير الصالح يُرجع 400 INVALID_CURSOR.
curl "https://forypay.com/api/v1/payments?limit=50" \
-H "Authorization: Bearer $FP_API_KEY"وضع الاختبار
POST/api/v1/payments/{id}/simulate
الدفعة المُنشأة بمفتاح fp_test_ دفعة تجريبية: لا تُراقَب على السلسلة أبدًا، ولا تُحتسب في الفوترة، ولا يمكن لأي تحويل حقيقي أن يُسوّيها. تصرّف كالدافع عبر هذه النقطة بدلًا من ذلك — تمرّ الدفعة بالحالات وأحداث Webhook نفسها التي يُنتجها تحويل حقيقي تمامًا، فيُختبر معالج الـ webhook لديك من البداية إلى النهاية. وتعرض صفحة الدفع المستضافة ولوحة التحكم الإجراءات نفسها كأزرار.
جرّبها| الحقل | النوع | الوصف |
|---|---|---|
| مطلوب | pay يُرسل المتبقّي بالضبط؛ underpay يُرسل نصفه (تبقى الدفعة DETECTED)؛ overpay يُرسل المتبقّي مع رمز واحد إضافي؛ expire يُنهي دفعة لم يصلها شيء. |
curl -X POST https://forypay.com/api/v1/payments/$PAYMENT_ID/simulate \
-H "Authorization: Bearer $FP_TEST_KEY" \
-H "Content-Type: application/json" \
-d '{ "action": "pay" }'{
"id": "8c1e…",
"status": "CONFIRMED",
"expected_amount": "25.5",
"detected_amount": "25.5",
"transaction_hash": "0x5133…",
"test_mode": true
}للدفعات التجريبية فقط، وبمفتاح اختبار فقط
التحقق من معاملة
POST/api/v1/verify
فحص لمرة واحدة لبصمة تملكها مسبقًا. يقرأ السلسلة مباشرةً ولا يُنشئ سجل دفعة ولا يحدّثه — مفيد للتسوية اليدوية ولترحيل الطلبات التاريخية.
جرّبها| الحقل | النوع | الوصف |
|---|---|---|
| مطلوب | السلسلة المطلوب قراءتها. | |
| اختياري | العملة التي نقلها التحويل. اختياري — عند حذفه تُستخدم العملة الافتراضية للشبكة. المقبول لكل شبكة: bsc: USDT · tron: USDT · polygon: USDT, USDC · base: USDC | |
| مطلوب | بصمة التحويل المطلوب فحصه. | |
| مطلوب | العنوان الذي يجب أن يكون التحويل قد أضاف إليه. |
curl -X POST https://forypay.com/api/v1/verify \
-H "Authorization: Bearer $FP_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"network": "bsc",
"transaction_hash": "0x9d4c…7b21",
"receiver": "0x2f1a…9c3e"
}'{
"valid": true,
"status": "CONFIRMED",
"network": "bsc",
"transaction_hash": "0x9d4c…7b21",
"sender": "0x8f2a…1b4e",
"receiver": "0x2f1a…9c3e",
"amount": "25.00"
}حالات الدفعة
تبدأ الدفعة عند PENDING وتتقدّم إلى الأمام فقط. هذه هي الحالات التي ستراها في Webhooks واستجابات الواجهة ولوحة التحكم.
| الحالة | المعنى |
|---|---|
| قيد الانتظار | أُنشئت وتنتظر تحويلًا مطابقًا على السلسلة. |
| مكتشفة | ظهر تحويل مطابق: إمّا جزء من المبلغ فقط، أو المبلغ كاملًا بانتظار تأكيدات الشبكة. لا تُنفّذ الطلب بعد. |
| مؤكّدة | تمت التسوية: المبلغ كاملًا مؤكَّد على السلسلة. آمن لتنفيذ الطلب. |
| دفع زائد | تمت التسوية، لكن الدافع أرسل أكثر من المبلغ المتوقّع. |
| منتهية الصلاحية | أُغلقت النافذة قبل وصول تحويل مطابق. |
Webhooks
حدّد عنوان Webhook على المشروع، وسنرسل JSON بطلب POST مع تقدّم الدفعة. تُصطفّ الأحداث وتُعاد المحاولة بتراجع أُسّي حتى تُرجع نقطة النهاية لديك رمز 2xx، فتعامل مع المعالجات على أنها آمنة للتكرار — فقد يصل الحدث نفسه مرتين.
payment.detected— ظهر تحويل مطابق على السلسلة (لم يُؤكَّد بعد)payment.confirmed— تأكّد المبلغ كاملًا على السلسلة وتمت تسوية الدفعة (الحالة CONFIRMED أو OVERPAID)payment.expired— أُغلقت النافذة دون دفع
كل تسليم يحمل توقيع HMAC-SHA256 مشتقًّا من سرّ Webhook للمشروع، محسوبًا على ترويسة الوقت وجسم الطلب الخام موصولين بنقطة. قارنه بمقارنة ثابتة الزمن قبل الثقة بالحمولة، وارفض ما مضى عليه أكثر من خمس دقائق، ودوّر السرّ من إعدادات المشروع إن تعرّض للكشف يومًا.
POST /your/webhook
Content-Type: application/json
X-Forypay-Event: payment.confirmed
X-Forypay-Delivery: whk_3Kd9vQ2mTz
X-Forypay-Timestamp: 1755820800
X-Forypay-Signature: sha256=6f1b…a92c
{
"event": "payment.confirmed",
"data": {
"payment_id": "pay_8Fq2mZx1LrKd",
"order_id": "ORDER-1042",
"status": "CONFIRMED",
"transaction_hash": "0x9d4c…7b21",
"test_mode": false
}
}في بيئة الإنتاج، لا تُنفّذ أبدًا طلبًا لدفعة اختبار
// after verifying the signature
const { event, data } = JSON.parse(rawBody);
if (process.env.NODE_ENV === 'production' && data.test_mode) {
return res.status(200).end(); // acknowledge, but never fulfil
}الأخطاء
تستخدم الأخطاء رموز حالة HTTP المعتادة وجسمًا متسقًا. ويستحق request_id التسجيل — اذكره عند طلب المساعدة لنجد الطلب بعينه.
{
"error": {
"code": "INVALID_AMOUNT",
"message": "Invalid amount",
"request_id": "req_7bQ1xKp0Za"
}
}| الرمز | HTTP | السبب |
|---|---|---|
| 400 | فشل الجسم في التحقق من المخطط. الرسالة تسمّي الحقل. | |
| 400 | لم يكن المبلغ نصًّا عشريًّا بسيطًا. | |
| 400 | التوكن غير مُمكَّن على تلك الشبكة. | |
| 401 | رمز bearer مفقود أو مُشوَّه أو مُبطَل أو غير معروف. | |
| 404 | لا توجد دفعة بهذا المعرّف. | |
| 500 | بيانات التوكن الوصفية ناقصة من جانبنا. | |
| 500 | فشلت قراءة السلسلة — أعد المحاولة ثم تواصل معنا. |
جرّبها دون كتابة كود
ترسل ساحة التجربة طلبًا حقيقيًّا إلى أي نقطة نهاية موثّقة بمفتاح تلصقه أنت، وتعرض الاستجابة الخام.
افتح ساحة تجربة الواجهة