Cards & Subscriptions API

This section covers the administrative APIs for managing product cards (activation keys) and viewing active subscriptions.

Note: All endpoints require Admin Authentication (/api/admin/*).


Cards Management

1. List Cards

Retrieve a list of all cards (activation keys) in the system, along with their usage status and associated product names.

  • Endpoint: /api/admin/cards
  • Method: GET
  • Authentication: Required (Admin)

Success Response (200)

[
  {
    "id": 1,
    "productId": 3,
    "productName": "Steam Gift Card $50",
    "cardNumber": "STEAM-XXXX-YYYY-ZZZZ",
    "isUsed": false,
    "orderId": null,
    "createdAt": "2024-03-21T10:00:00.000Z"
  }
]

2. Bulk Import Cards

Import multiple cards for a specific key type product.

  • Endpoint: /api/admin/cards
  • Method: POST
  • Authentication: Required (Admin)

Request Body

{
  "productId": 3,
  "cardNumbers": ["KEY-1234-ABCD", "KEY-5678-EFGH"]
}

Success Response (200)

{
  "code": 0,
  "message": "Successfully added 2 cards"
}

Error Response (400)

{
  "statusCode": 400,
  "message": "Missing required fields"
}

3. Delete Card

Delete an unused card from the system.

  • Endpoint: /api/admin/cards/:id
  • Method: DELETE
  • Authentication: Required (Admin)

Success Response (200)

{
  "code": 0,
  "message": "Card deleted successfully"
}

Error Response (400) - Card Used

{
  "code": 1,
  "message": "Cannot delete a card that has already been used"
}

Subscriptions Management

1. List Active Subscriptions

Retrieve a list of all orders that are categorized as subscriptions (status active or expired).

  • Endpoint: /api/admin/subscriptions
  • Method: GET
  • Authentication: Required (Admin)

Success Response (200)

[
  {
    "id": "ORD123456789",
    "amount": 29.99,
    "contactEmail": "user@example.com",
    "status": "active",
    "createdAt": "2024-03-01T10:00:00.000Z",
    "paidAt": "2024-03-01T10:05:00.000Z",
    "metaData": {
      "subscription_cycle": "1_month",
      "expire_at": 1711965600000
    },
    "productId": 5,
    "productName": "Pro SaaS Plan",
    "userId": 42,
    "userNickname": "John Doe"
  }
]