FoxReload Order Polling और अपना Notification Layer
संक्षिप्त उत्तर
FoxReload में webhooks नहीं हैं। Order का status और codes पाने का एकमात्र तरीका है GET /api/orders/{order_id} poll करना। जब status completed हो, items[].externalData में codes मिलते हैं। Customer को notify करने के लिए अपना notification layer build करें — polling loop complete होने पर email/Telegram/queue trigger करें। यह guide FoxReload-specific polling pattern और अपना notification layer build करने की architecture explain करती है।
महत्वपूर्ण: FoxReload में कोई webhook endpoint register करने का option नहीं है, कोई HMAC signature नहीं, कोई
order.fulfilledevents नहीं। Codes के लिएGET /api/orders/{order_id}poll करें। यह design choice है — reliable polling से ही order status मिलता है।
मुख्य निष्कर्ष: FoxReload polling-based है। Order create होने के बाद उसे poll करें जब तक
completed,failed, याcancelledstatus न मिले। Completed orders केitems[].externalDataमें codes होते हैं। Double-buying से बचने के लिए retry से पहले हमेशाGET /api/orders/से existing order check करें।
यह Guide किसके लिए है
- Developers जो FoxReload API integrate कर रहे हैं और order fulfillment automate करना चाहते हैं
- Store operators जो pending orders को reliably handle करना चाहते हैं
- High-volume digital goods pipeline build करने वाले
FoxReload Order Flow
POST /api/orders/ ← order create करें
{ items: [{ itemId, quantity }] }
→ { id: "ord_...", status: "active" }
GET /api/orders/{order_id} ← status poll करें
→ { status: "processing" } ← फिर poll करें
GET /api/orders/{order_id} ← poll करते रहें
→ { status: "completed",
items: [{ externalData: ["XXXXX-YYYYY-ZZZZZ"] }] }
Polling loop (Python example):
import time, requests
BASE = "https://public-api.foxreload.com"
HEADERS = {"X-API-Key": "YOUR_API_KEY"}
def poll_order(order_id, max_attempts=30, interval=3):
for _ in range(max_attempts):
resp = requests.get(f"{BASE}/api/orders/{order_id}", headers=HEADERS)
order = resp.json()
status = order["status"]
if status == "completed":
codes = [item["externalData"] for item in order["items"]]
return {"status": "completed", "codes": codes}
elif status in ("failed", "cancelled"):
return {"status": status, "error": order.get("items")}
time.sleep(interval)
raise TimeoutError(f"Order {order_id} still pending after {max_attempts} attempts")
isMock — Test Orders
FoxReload में sandbox environment नहीं है। Test orders के लिए isMock: true use करें:
POST /api/orders/
{
"items": [{"itemId": "product_01k...", "quantity": 1}],
"isMock": true
}
isMock orders real balance deduct नहीं करते और test codes return करते हैं।
Balance और BalanceNotEnough Error
FoxReload prepaid model पर चलता है। Balance कम होने पर order creation BalanceNotEnough error return करती है। Balance top up करने के लिए:
POST /api/topups/crypto/
{ "chain": "...", "asset": "USDT", "balanceCurrency": "USD", "quoteAmount": 100 }
Production में balance monitor करें — BalanceNotEnough पर orders तुरंत fail होती हैं।
Codes कहाँ मिलते हैं
Completed order में:
{
"status": "completed",
"items": [
{
"itemId": "product_01k...",
"externalData": ["XXXXX-YYYYY-ZZZZZ"],
"error": null
}
]
}
externalData: array of codes/pinserror: per-item error अगर कोई हो
अपना Notification Layer
FoxReload के पास customer notifications नहीं हैं — यह आपकी responsibility है। Polling complete होने पर:
| Delivery Channel | Implementation |
|---|---|
| Transactional email (SendGrid, Postmark) से code भेजें | |
| Telegram bot | bot.sendMessage() से code deliver करें |
| In-app | Order history में code store और display करें |
| SMS | Twilio या local SMS gateway से भेजें |
Architecture:
[Payment confirmed]
↓
[POST /api/orders/ → order_id मिला]
↓
[Background job: poll until completed/failed]
↓
[completed → codes extract → customer को deliver]
[failed → ops alert → refund flow]
Double-Buy से बचाव
FoxReload में idempotency keys नहीं हैं। Retry करने से पहले:
# order create करने से पहले pending orders check करें
existing = requests.get(
f"{BASE}/api/orders/?statuses=active,paid,processing",
headers=HEADERS
).json()
# same item का pending order exist करता है? तो नया मत बनाएं
Network error पर blindly retry करने से double-buying हो सकता है।
Error Handling
| Scenario | Action |
|---|---|
BalanceNotEnough |
Balance top up करें; customer को "temporarily unavailable" दिखाएं |
| Network error / timeout | Exponential backoff के साथ retry; पहले existing orders check करें |
failed status |
Ops को alert करें; customer को charge न करें |
| 429 rate limit | Exponential backoff apply करें |
| Order 30+ min pending | Manual review के लिए flag करें |
Implementation Checklist
-
POST /api/orders/से order create करें (X-API-Key header) - Polling loop implement करें (हर 3-5s, max 30 attempts)
- Completed order के
items[].externalDataसे codes extract करें - Customer delivery: email/Telegram/in-app
- Failed/cancelled orders के लिए ops alerting
- Balance monitoring और low-balance alert
- Retry से पहले existing orders check (double-buy prevention)
-
isMock: trueसे test करें - 429 errors के लिए exponential backoff
