# New Order API (Bot -> Backend)

When a user completes **شراء البطاقات - بنكي**, the bot sends a `POST` request to the URL configured as `api_new_order` in `whatsapp-bot/bot.config.json`.

## Endpoint config

```json
{
  "api_new_order": "https://example.com/api/new-order"
}
```

## Request

- Method: `POST`
- Headers: `Content-Type: application/json`
- Body (JSON):

```json
{
  "order_no": "ORD-20260301-AB12CD",
  "chat_id": "9705xxxxxxx",
  "customer_mobile": "+97059xxxxxxx",
  "network_id": "jawwal",
  "network_name": "جوال",
  "voucher_id": "jawwal_20",
  "voucher_name": "بطاقة جوال 20",
  "voucher_price": 20,
  "voucher_count": 2,
  "receipt": {
    "message_id": "MSG123",
    "media_url": "https://...",
    "media_base64": "...optional..."
  },
  "note": "ملاحظة العميل",
  "created_at": "2026-03-01T12:34:56+00:00"
}
```

## Expected response (recommended)

```json
{
  "status": "success",
  "order_id": "12345",
  "message": "Order accepted"
}
```

### Failure response (recommended)

```json
{
  "status": "error",
  "message": "Validation failed"
}
```

## Bot behavior

- If `api_new_order` is not configured, bot stores the order locally and marks API result as `skipped`.
- Bot always stores the order in local storage (`bot_state.json`) and logs API result in `whatsapp_bot.events.jsonl`.
