API Documentation

Tài liệu API để tích hợp MMO Agency vào hệ thống của bạn. Tất cả các endpoint đều yêu cầu authentication (trừ đăng ký/đăng nhập).

🔐 Authentication

POST /api/register

Đăng ký tài khoản mới

Request Body:

{
  "username": "string (required, unique)",
  "email": "string (required, unique, valid email)",
  "password": "string (required, min 6 characters)"
}

Response (201):

{
  "message": "Registration successful",
  "user_id": 1
}

Error (400):

{
  "error": "Username or email already exists"
}
POST /api/login

Đăng nhập vào hệ thống

Request Body:

{
  "username": "string (username or email)",
  "password": "string"
}

Response (200):

{
  "message": "Login successful",
  "user": {
    "id": 1,
    "username": "user123",
    "balance": 100.00
  }
}

Error (401):

{
  "error": "Invalid credentials"
}
POST /api/logout

Đăng xuất khỏi hệ thống

Response (200):

{
  "message": "Logout successful"
}
GET /api/user

Lấy thông tin người dùng hiện tại (yêu cầu đăng nhập)

Response (200):

{
  "id": 1,
  "username": "user123",
  "email": "user@example.com",
  "balance": 100.00
}

📦 Products

GET /api/products

Lấy danh sách sản phẩm (có phân trang)

Query Parameters:

  • category (optional): Lọc theo danh mục (Gmail, X-Account, Short-term Mail, Trusted Mail, hoặc 'all')
  • page (optional, default: 1): Số trang
  • per_page (optional, default: 15): Số sản phẩm mỗi trang

Example:

GET /api/products?category=Gmail&page=1&per_page=15

Response (200):

{
  "products": [
    {
      "id": 1,
      "category": "Gmail",
      "name": "Gmail Account",
      "live_time": "3-6 months",
      "stock": 100,
      "price": 5.00,
      "description": "Gmail account with full access"
    }
  ],
  "pagination": {
    "page": 1,
    "per_page": 15,
    "total": 100,
    "total_pages": 7,
    "has_next": true,
    "has_prev": false
  }
}
GET /api/products/{product_id}

Lấy thông tin chi tiết một sản phẩm

Response (200):

{
  "id": 1,
  "category": "Gmail",
  "name": "Gmail Account",
  "live_time": "3-6 months",
  "stock": 100,
  "price": 5.00,
  "description": "Gmail account with full access"
}

💰 Transactions

POST /api/deposit

Nạp tiền vào tài khoản (yêu cầu đăng nhập)

Request Body:

{
  "amount": 100.00
}

Response (200):

{
  "message": "Deposit successful",
  "new_balance": 200.00
}
POST /api/purchase

Mua sản phẩm (yêu cầu đăng nhập)

Request Body:

{
  "product_id": 1,
  "quantity": 2
}

Response (200):

{
  "message": "Purchase successful",
  "new_balance": 90.00,
  "product": { ... },
  "quantity": 2,
  "total": 10.00
}

Error (400):

{
  "error": "Insufficient balance" // hoặc "Insufficient stock"
}
GET /api/transactions

Lấy lịch sử giao dịch (yêu cầu đăng nhập)

Response (200):

[
  {
    "id": 1,
    "user_id": 1,
    "product_id": 1,
    "transaction_type": "purchase",
    "amount": 10.00,
    "description": "Purchased 2x Gmail Account",
    "created_at": "2024-01-01 12:00:00",
    "product_name": "Gmail Account"
  },
  {
    "id": 2,
    "user_id": 1,
    "product_id": null,
    "transaction_type": "deposit",
    "amount": 100.00,
    "description": "Deposit $100.00",
    "created_at": "2024-01-01 11:00:00",
    "product_name": null
  }
]

📝 Lưu ý về Authentication

Để sử dụng các endpoint yêu cầu đăng nhập, bạn cần:

  1. Gửi request đăng nhập để nhận session cookie
  2. Gửi kèm cookie trong các request tiếp theo (credentials: 'include' trong fetch)
  3. Session sẽ được duy trì cho đến khi đăng xuất hoặc hết hạn

Example với JavaScript fetch:

// Login
fetch('/api/login', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  credentials: 'include',
  body: JSON.stringify({ username: 'user', password: 'pass' })
});

// Authenticated request
fetch('/api/user', {
  credentials: 'include'
});