# คำสั่งซื้อ

> API ของ LocalSERP Proxy: แพ็กเกจและราคา การซื้อแพ็กเกจด้วยยอดเงินคงเหลือ และประวัติคำสั่งซื้อ พร้อมพารามิเตอร์ ตัวอย่างการตอบกลับ และโค้ด curl, Python และ Node.js

- URL: https://localserpproxy.com/th/docs/api/orders/
- อัปเดตล่าสุด: 2026-10-15
- Publisher: LocalSERP Proxy (https://localserpproxy.com)

ดูรายการแพ็กเกจและราคา ซื้อแพ็กเกจด้วยยอดเงินคงเหลือ (บริการใหม่ เพิ่มปริมาณทราฟฟิก หรือต่ออายุพอร์ต) และดูคำสั่งซื้อที่ผ่านมา

**จุดเชื่อมต่อในหน้านี้**

- `GET /v1/catalog/products`: สินค้า แพ็กเกจ และราคา
- `POST /v1/orders`: ซื้อแพ็กเกจด้วยยอดเงินคงเหลือ (บริการใหม่ เพิ่มปริมาณการใช้งาน หรือขยายระยะเวลาพอร์ต)
- `GET /v1/orders`: แสดงรายการคำสั่งซื้อ
- `GET /v1/orders/{orderId}`: ดูคำสั่งซื้อ

URL พื้นฐาน `https://localserpproxy.com/api/v1` การยืนยันตัวตน ข้อผิดพลาด และขีดจำกัด: ดู [ภาพรวม API](https://localserpproxy.com/th/docs/api/)

## สินค้า แพ็กเกจ และราคา

`GET /v1/catalog/products`

สินค้าทุกรายการพร้อมแพ็กเกจและราคา ตามยอดที่เรียกเก็บจริงเมื่อสั่งซื้อ

สาธารณะ: ไม่ต้องใช้คีย์ API

**การตอบกลับ** `200 OK`

```json
{
  "data": [
    {
      "id": "residential",
      "name": "Residential proxies",
      "description": "Residential traffic for manual local search, advertising, price and application checks in US cities. State, city and ZIP selection, subject to available exits; no promise of GPS position or rankings.",
      "unit": "GB",
      "plans": [
        {
          "id": "res-10",
          "productId": "residential",
          "name": "Local team",
          "quantity": 10,
          "unit": "GB",
          "durationDays": null,
          "price": "7.50",
          "pricePerUnit": "0.75",
          "popular": false,
          "features": [
            "US city selection, subject to availability",
            "Traffic stays until used",
            "Rotating or sticky sessions"
          ],
          "available": true,
          "countries": null
        }
      ]
    }
  ]
}
```

*curl*

```bash
curl -s "https://localserpproxy.com/api/v1/catalog/products"
```

*Python*

```python
import os
import requests

API = "https://localserpproxy.com/api/v1"

r = requests.get(f"{API}/catalog/products", timeout=30)
r.raise_for_status()
print(r.json())
```

*Node.js*

```javascript
// Node.js 18+ (built-in fetch), ES module
const API = 'https://localserpproxy.com/api/v1';

const res = await fetch(`${API}/catalog/products`);
if (!res.ok) throw new Error((await res.json()).error?.message ?? `HTTP ${res.status}`);
console.log(await res.json());
```

## ซื้อแพ็กเกจด้วยยอดเงินคงเหลือ (บริการใหม่ เพิ่มทราฟฟิก หรือต่ออายุพอร์ต)

`POST /v1/orders`

ชำระจากยอดเงินเติมล่วงหน้าเสมอ: API คำนวณราคา (ราคาตามแค็ตตาล็อก × `quantity`) จากนั้นหักยอดเงิน สร้างหรือต่ออายุบริการ และส่งคำสั่งซื้อกลับมาในสถานะ `completed` พร้อม `fulfillment` ข้อมูลพร็อกซีพร้อมใช้งานทันที

- **ทราฟฟิกพร็อกซีเรซิเดนเชียลใหม่**: `{ "planId": "res-10" }`.
- **ทราฟฟิกพร็อกซี 4G/5G แบบหมุนเวียนใหม่ (ต่อ GB)**: `{ "planId": "mgb-10" }` (แพ็กเกจทราฟฟิกที่มี `productId: "mobile-gb"` จัดส่งใน `fulfillment.residentialSubscriptionId`).
- **เพิ่มทราฟฟิกให้แพ็กเกจที่มีอยู่**: `{ "planId": "res-10", "options": { "subscriptionId": "res_9x2m4k" } }`: แพ็กเกจต้องเป็นของผลิตภัณฑ์เดียวกับแพ็กเกจที่สมัครไว้
- **พอร์ตพร็อกซีมือถือใหม่**: `{ "planId": "mob-us-30d", "quantity": 1, "options": { "country": "US" } }` เลือกเพิ่ม `carrier` ได้ (ดูผู้ให้บริการเครือข่ายของแต่ละประเทศได้ที่ [พอร์ตมือถือ](https://localserpproxy.com/th/docs/api/mobile/)) แพ็กเกจโซนครอบคลุมเฉพาะประเทศในโซนนั้น (`422` บน `options.country` ในกรณีอื่น)
- **ต่ออายุพอร์ตพร็อกซีมือถือ**: `{ "planId": "mob-us-7d", "options": { "portId": "mob_2v8k1q" } }` เพิ่มระยะเวลาของแพ็กเกจให้กับ `expiresAt`

**ยอดเงินคงเหลือไม่พอ → `402 insufficient_balance`** โดยระบุยอดที่ขาดและยอดเติมเงินที่แนะนำใน `error.details` (`missing`, `suggestedTopUp`) จะไม่มีการหักเงินเมื่อเกิดข้อผิดพลาด หากต้องการชำระส่วนต่าง ให้เริ่มเติมเงินโดยแนบคำขอเดิมใน `purchase` (`POST /v1/topups`): ระบบจะซื้อแพ็กเกจทันทีเมื่อยอดเติมเงินเข้าบัญชี

การยืนยันตัวตน: ใช้คีย์ API ในส่วนหัว `Authorization: Bearer API_KEY`

**พารามิเตอร์**

| ชื่อ | ใน | ประเภท | จำเป็น | คำอธิบาย |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | ไม่ | คีย์ที่ไม่ซ้ำกัน (เช่น UUID) สำหรับลองส่ง POST ซ้ำอย่างปลอดภัย เก็บไว้ 24 h — สูงสุด 128 ตัวอักษร |

**เนื้อหาคำขอ**

| ฟิลด์ | ประเภท | จำเป็น | คำอธิบาย |
| --- | --- | --- | --- |
| `planId` | string | ใช่ | — |
| `quantity` | integer | ไม่ | 1–100, ค่าเริ่มต้น `1` |
| `options` | object | ไม่ | — |

*ตัวอย่าง: พร็อกซีเรซิเดนเชียล*

```json
{
  "planId": "res-10"
}
```

*ตัวอย่าง: พอร์ตมือถือ*

```json
{
  "planId": "mob-us-30d",
  "quantity": 1,
  "options": {
    "country": "US",
    "carrier": "verizon",
    "autoRenew": true
  }
}
```

*ตัวอย่าง: ต่ออายุพอร์ต*

```json
{
  "planId": "mob-us-7d",
  "options": {
    "portId": "mob_2v8k1q"
  }
}
```

*ตัวอย่าง: ทราฟฟิกมือถือ*

```json
{
  "planId": "mgb-10"
}
```

*ตัวอย่าง: พอร์ตโซน*

```json
{
  "planId": "mob-us-30d",
  "options": {
    "country": "US",
    "carrier": "verizon"
  }
}
```

**การตอบกลับ** `201 Created`

```json
{
  "id": "ord_4f8k2m9q",
  "status": "completed",
  "productId": "residential",
  "planId": "res-10",
  "planName": "Local team",
  "quantity": 1,
  "unitPrice": "7.50",
  "subtotal": "7.50",
  "discount": "0.00",
  "total": "7.50",
  "promoCode": null,
  "currency": "USD",
  "topUpId": null,
  "options": {},
  "fulfillment": {
    "residentialSubscriptionId": "res_9x2m4k",
    "mobilePortIds": []
  },
  "createdAt": "2026-10-05T14:03:11Z",
  "paidAt": "2026-10-05T14:03:11Z"
}
```

*curl*

```bash
curl -s -X POST "https://localserpproxy.com/api/v1/orders" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"planId":"res-10"}'
```

*Python*

```python
import os, uuid
import requests

API = "https://localserpproxy.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['API_KEY']}", "Idempotency-Key": str(uuid.uuid4())}

r = requests.post(f"{API}/orders", headers=HEADERS, json={"planId": "res-10"}, timeout=30)
r.raise_for_status()
print(r.json())
```

*Node.js*

```javascript
// Node.js 18+ (built-in fetch), ES module
import { randomUUID } from 'node:crypto';

const API = 'https://localserpproxy.com/api/v1';

const res = await fetch(`${API}/orders`, {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.API_KEY}`, 'Idempotency-Key': randomUUID(), 'Content-Type': 'application/json' },
  body: JSON.stringify({ planId: 'res-10' }),
});
if (!res.ok) throw new Error((await res.json()).error?.message ?? `HTTP ${res.status}`);
console.log(await res.json());
```

## รายการคำสั่งซื้อ

`GET /v1/orders`

การยืนยันตัวตน: ใช้คีย์ API ในส่วนหัว `Authorization: Bearer API_KEY`

**พารามิเตอร์**

| ชื่อ | ใน | ประเภท | จำเป็น | คำอธิบาย |
| --- | --- | --- | --- | --- |
| `page` | query | integer | ไม่ | ≥ 1 ค่าเริ่มต้น `1` |
| `perPage` | query | integer | ไม่ | 1–100 ค่าเริ่มต้น `20` |
| `status` | query | `completed` · `cancelled` | ไม่ | สร้างคำสั่งซื้อเป็นสถานะชำระเงินแล้ว (หักจากยอดเงินคงเหลือ) `completed` — ชำระแล้วและพร้อมใช้งาน (ข้อมูลพร็อกซีพร้อมใช้งานทันที) |
| `productId` | query | string | ไม่ | รหัสผลิตภัณฑ์จากแค็ตตาล็อก ค่าของ LocalSERP Proxy: `residential` (GB), `mobile` (พอร์ต 4G/5G แบบเฉพาะ) และ `mobile-gb` (ทราฟฟิก 4G/5G แบบหมุนเวียนต่อ GB) ลูกค้าต้องรองรับค่าที่ไม่รู้จัก |

**การตอบกลับ** `200 OK`

```json
{
  "data": [
    {
      "id": "ord_4f8k2m9q",
      "status": "completed",
      "productId": "residential",
      "planId": "res-10",
      "planName": "Local team",
      "quantity": 1,
      "unitPrice": "7.50",
      "subtotal": "7.50",
      "discount": "0.00",
      "total": "7.50",
      "promoCode": null,
      "currency": "USD",
      "topUpId": null,
      "options": {},
      "fulfillment": {
        "residentialSubscriptionId": "res_9x2m4k",
        "mobilePortIds": []
      },
      "createdAt": "2026-10-05T14:03:11Z",
      "paidAt": "2026-10-05T14:03:11Z"
    }
  ],
  "pagination": {
    "page": 1,
    "perPage": 20,
    "total": 1,
    "totalPages": 1
  }
}
```

*curl*

```bash
curl -s "https://localserpproxy.com/api/v1/orders" \
  -H "Authorization: Bearer $API_KEY"
```

*Python*

```python
import os
import requests

API = "https://localserpproxy.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['API_KEY']}"}

r = requests.get(f"{API}/orders", headers=HEADERS, timeout=30)
r.raise_for_status()
print(r.json())
```

*Node.js*

```javascript
// Node.js 18+ (built-in fetch), ES module
const API = 'https://localserpproxy.com/api/v1';

const res = await fetch(`${API}/orders`, {
  headers: { Authorization: `Bearer ${process.env.API_KEY}` },
});
if (!res.ok) throw new Error((await res.json()).error?.message ?? `HTTP ${res.status}`);
console.log(await res.json());
```

## ดูคำสั่งซื้อ

`GET /v1/orders/{orderId}`

การยืนยันตัวตน: ใช้คีย์ API ในส่วนหัว `Authorization: Bearer API_KEY`

**พารามิเตอร์**

| ชื่อ | ใน | ประเภท | จำเป็น | คำอธิบาย |
| --- | --- | --- | --- | --- |
| `orderId` | path | string | ใช่ | — |

**การตอบกลับ** `200 OK`

```json
{
  "id": "ord_4f8k2m9q",
  "status": "completed",
  "productId": "residential",
  "planId": "res-10",
  "planName": "Local team",
  "quantity": 1,
  "unitPrice": "7.50",
  "subtotal": "7.50",
  "discount": "0.00",
  "total": "7.50",
  "promoCode": null,
  "currency": "USD",
  "topUpId": null,
  "options": {},
  "fulfillment": {
    "residentialSubscriptionId": "res_9x2m4k",
    "mobilePortIds": []
  },
  "createdAt": "2026-10-05T14:03:11Z",
  "paidAt": "2026-10-05T14:03:11Z"
}
```

*curl*

```bash
curl -s "https://localserpproxy.com/api/v1/orders/ord_4f8k2m9q" \
  -H "Authorization: Bearer $API_KEY"
```

*Python*

```python
import os
import requests

API = "https://localserpproxy.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['API_KEY']}"}

r = requests.get(f"{API}/orders/ord_4f8k2m9q", headers=HEADERS, timeout=30)
r.raise_for_status()
print(r.json())
```

*Node.js*

```javascript
// Node.js 18+ (built-in fetch), ES module
const API = 'https://localserpproxy.com/api/v1';

const res = await fetch(`${API}/orders/ord_4f8k2m9q`, {
  headers: { Authorization: `Bearer ${process.env.API_KEY}` },
});
if (!res.ok) throw new Error((await res.json()).error?.message ?? `HTTP ${res.status}`);
console.log(await res.json());
```

---

LocalSERP Proxy: LocalSERP Proxy เป็นบริการพร็อกซีเรซิเดนเชียลในสหรัฐฯ สำหรับตรวจสอบผลการค้นหาในพื้นที่ โฆษณา และราคาเป็นรายเมือง ชำระเงินด้วยคริปโตโดยไม่ต้องอัปโหลดเอกสารยืนยันตัวตน.
