Skip to content

ดูข้อมูลคำสั่งซื้อ

ดึงข้อมูล order โดยใช้ reference_id ที่ Merchant กำหนดตอนสร้าง order

Endpoint

http
GET /v1/orders/{reference_id}

Authentication

ต้องส่ง X-API-Key header ทุก request — ดู Authentication

Path Parameters

ParameterTypeRequiredDescription
reference_idstringReference ID ที่ Merchant กำหนดตอนสร้าง order

Response

200 — Order Found

json
{
    "order_number": "ord_abc123",
    "reference_id": "ref_abc123",
    "user_id": "user_001",
    "server_id": "server_th01",
    "character_id": "char_123",
    "status": "completed",
    "subtotal_amount": "500.00",
    "discount_amount": "0.00",
    "total_amount": "500.00",
    "source_type": "api",
    "created_by": {
        "id": 0,
        "name": "API"
    },
    "created_at": "2025-01-15T10:30:00.000Z",
    "updated_at": "2025-01-15T10:35:00.000Z",
    "failure_code": null,
    "failure_message": null,
    "items": [
        {
            "sku": "DIAMOND_100",
            "quantity": 5,
            "completed_quantity": 5,
            "failed_quantity": 0,
            "status": "completed",
            "subtotal_amount": "500.00",
            "discount_amount": "0.00",
            "total_amount": "500.00",
            "failure_code": null,
            "failure_message": null
        }
    ]
}

Response Fields

FieldTypeDescription
order_numberstringOrder ID ที่ระบบ GameSO ออกให้
reference_idstringReference ID ที่ Merchant ส่งมา
statusstringสถานะ order ปัจจุบัน
total_amountstringยอดรวมทั้งหมด (THB)
failure_codestring|nullรหัสข้อผิดพลาด (กรณี failed)
failure_messagestring|nullรายละเอียดข้อผิดพลาด (กรณี failed)
itemsarrayรายละเอียดแต่ละ item
items[].completed_quantityintegerจำนวนที่เติมสำเร็จแล้ว
items[].failed_quantityintegerจำนวนที่เติมล้มเหลว

Order Status ที่เป็นไปได้

Statusความหมายขั้นตอนถัดไป
pendingรอการประมวลผลรอ webhook หรือ poll ใหม่
processingกำลังประมวลผลรอ webhook หรือ poll ใหม่
completedเสร็จสมบูรณ์ไม่ต้องทำอะไรเพิ่ม
failedล้มเหลวดู failure_code และ failure_message

Error Responses

401 — Unauthorized

json
{
    "status": 401,
    "code": "UNAUTHORIZED",
    "message": "Invalid or missing API key"
}

404 — Order Not Found

json
{
    "status": 404,
    "code": "NOT_FOUND",
    "message": "Order not found"
}

WARNING

ระบบค้นหา order ด้วย reference_id ที่ Merchant กำหนด ไม่ใช่ order_number ที่ระบบ GameSO ออกให้

ตัวอย่างการใช้งาน

bash
curl -X GET https://api.gameso.io/v1/orders/POS-20250115-001 \
  -H "X-API-Key: your_api_key_here"
javascript
const referenceId = "POS-20250115-001";

const response = await fetch(`https://api.gameso.io/v1/orders/${referenceId}`, {
    headers: {
        "X-API-Key": process.env.GAMESO_API_KEY,
    },
});

if (response.status === 404) {
    console.log("Order not found");
} else {
    const order = await response.json();
    console.log("Status:", order.status);
    console.log("Total:", order.total_amount, "THB");

    order.items.forEach((item) => {
        console.log(
            `${item.sku}: ${item.completed_quantity}/${item.quantity} completed`,
        );
    });
}
python
import requests
import os

reference_id = 'POS-20250115-001'

response = requests.get(
    f'https://api.gameso.io/v1/orders/{reference_id}',
    headers={'X-API-Key': os.environ['GAMESO_API_KEY']}
)

if response.status_code == 404:
    print('Order not found')
elif response.status_code == 200:
    order = response.json()
    print(f"Status: {order['status']}")
    print(f"Total: {order['total_amount']} THB")
    for item in order['items']:
        print(f"{item['sku']}: {item['completed_quantity']}/{item['quantity']} completed")
php
<?php
$referenceId = 'POS-20250115-001';

$ch = curl_init("https://api.gameso.io/v1/orders/{$referenceId}");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => [
        'X-API-Key: ' . getenv('GAMESO_API_KEY'),
    ],
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($httpCode === 404) {
    echo "Order not found";
} elseif ($httpCode === 200) {
    $order = json_decode($response, true);
    echo "Status: " . $order['status'];
    echo "Total: " . $order['total_amount'] . " THB";
}

Polling vs Webhook

สำหรับการติดตามสถานะ order มี 2 วิธี:

วิธีข้อดีข้อเสีย
Polling (GET API)ง่าย ไม่ต้องตั้งค่าเพิ่มต้องเรียก API ซ้ำๆ ใช้ resource มากกว่า
WebhookReal-time ประหยัด resourceต้องมี public endpoint รับ webhook

แนะนำ

ใช้ Webhook สำหรับ production เพื่อประสิทธิภาพที่ดีกว่า — ดู Webhook Overview

GameSO API Documentation