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

# Create Order API

> Panduan membuat order user lewat User API secara aman.

# Create Order API

Endpoint ini digunakan untuk membuat order baru milik akun pemilik User API Token.

<Warning>
  Gunakan endpoint ini dengan hati-hati. Order yang valid akan membuat invoice/order baru di LeuwongRR. Untuk testing aman, gunakan Sandbox API Key dan `payment_method: invoice`.
</Warning>

## Endpoint

```http theme={null}
POST /api/v1/me/orders
```

## Headers

```http theme={null}
Authorization: Bearer USER_API_TOKEN
Accept: application/json
Content-Type: application/json
Idempotency-Key: order-unique-001
X-Discord-User-ID: DISCORD_USER_ID_TERLINK
```

## Request Body

```json theme={null}
{
  "order_type": "gamepass",
  "roblox_username": "LeuwongUser",
  "place_id": 123456789,
  "roblox_pass_id": 987654321,
  "payment_method": "invoice",
  "client_reference": "bot-order-001"
}
```

## Field yang diterima

| Field              | Tipe    |    Wajib | Keterangan                                                                                                                                |
| ------------------ | ------- | -------: | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `order_type`       | string  | Opsional | `gamepass` atau `vip_server`. Default: `gamepass`.                                                                                        |
| `roblox_username`  | string  |       Ya | Username Roblox tujuan.                                                                                                                   |
| `place_id`         | integer |       Ya | Place ID Roblox.                                                                                                                          |
| `roblox_pass_id`   | integer |       Ya | Gamepass ID. Alias `gamepass_id` juga didukung.                                                                                           |
| `payment_method`   | string  | Opsional | Default `invoice`. Gunakan `balance` hanya untuk Discord bot yang akun Discord-nya sudah link ke akun web. Sandbox hanya boleh `invoice`. |
| `client_reference` | string  | Opsional | Referensi dari bot/website kamu.                                                                                                          |

## Contoh Request

```bash theme={null}
curl -X POST "https://leuwongrr.online/api/v1/me/orders" \
  -H "Authorization: Bearer USER_API_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-test-001" \
  -H "X-Discord-User-ID: DISCORD_USER_ID_TERLINK" \
  --data '{
    "order_type": "gamepass",
    "roblox_username": "LeuwongUser",
    "place_id": 123456789,
    "roblox_pass_id": 987654321,
    "payment_method": "invoice",
    "client_reference": "bot-order-001"
  }'
```

## Contoh Response

```json theme={null}
{
  "success": true,
  "message": "Order berhasil dibuat.",
  "data": {
    "invoice": {
      "invoice_code": "INV202605010001",
      "type": "order",
      "payment_status": "pending",
      "amount": 348,
      "formatted_amount": "Rp348",
      "currency": "IDR",
      "payment_method": "invoice",
      "invoice_url": "https://leuwongrr.online/user/invoice/INV202605010001"
    },
    "environment": "sandbox",
    "idempotent": false
  }
}
```

## Keamanan

User API tidak menerima field sensitif seperti `user_id`, `email`, `price`, `amount`, `total_amount`, `status`, `payment_status`, `paid_at`, `role`, `balance`, `order_id`, `invoice_id`, atau payload provider. Semua data penting dihitung oleh server LeuwongRR.

## Validasi

Order tetap melewati validasi server LeuwongRR, termasuk validasi Roblox, gamepass/place, harga, diskon, payment method, invoice, dan ownership token user.

## Idempotency-Key

Gunakan header `Idempotency-Key` untuk mengurangi risiko double order saat bot melakukan retry.

```http theme={null}
Idempotency-Key: user-bot-order-20260501-001
```

Jika key yang sama sudah pernah dipakai oleh akun yang sama, API dapat mengembalikan invoice lama dengan `idempotent: true`.

## Testing dari Bot

Bot cukup mengirim input user ke endpoint ini. Bot tidak perlu menghitung harga dan tidak boleh menentukan status order.

## Pembayaran Saldo via Discord

Untuk memakai saldo dari Discord bot, request harus memakai token API member dan Discord ID yang sudah terhubung ke akun web yang sama.

```http theme={null}
Authorization: Bearer USER_API_TOKEN
X-Discord-User-ID: DISCORD_USER_ID_TERLINK
Idempotency-Key: discord-balance-order-001
Content-Type: application/json
Accept: application/json
```

Body wajib mengirim:

```json theme={null}
{
  "payment_method": "balance"
}
```

Jika Discord belum terhubung ke akun web, API akan menolak dengan kode `DISCORD_LINK_REQUIRED`. Jika saldo tidak cukup, API akan menolak dengan kode `INSUFFICIENT_BALANCE`.
