How to create an order (gift cards & codes)

When a customer completes checkout, call POST /orders to create the order. For products that deliver redeemable codes (game_card, gift_card, app_store, etc.), success usually includes codes in the same response.

For direct top-up products (product_type = direct_top_up), use the dedicated guide: create a direct top-up order (requires fields and uses the delivery object).

When to use this

Call this after the customer has paid (or your system has authorized payment). You should have already checked availability for the same item and quantity. Use the item_code from the catalog.

Step 1: Send the order request

Endpoint: POST https://api.cardpluspay.com/v1/orders

Body (JSON):

  • item_code (required) — Product item code (e.g. GOOGLE-5USD-KOXx). You can also use item_id as an alias.
  • quantity (optional) — Number of units; default 1, max 100.
  • email (optional) — Recipient email for delivery or records.

Optional header: Idempotency-Key (or X-Idempotency-Key) — A unique, stable string per purchase attempt (a UUID is recommended). Retries with the same key and body return the original result instead of creating a duplicate order.

Example request

curl -X POST "https://api.cardpluspay.com/v1/orders" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{"item_code": "GOOGLE-5USD-KOXx", "quantity": 1}'

Quantity must be between the SKU’s min_quantity and max_quantity (from GET /catalog or POST /orders/check) and within platform bounds (1–100). Stock is re-validated at purchase time.

One SKU per request

Each POST /orders purchases one catalog product. quantity is units of that item_code only (for example two of the same Google Play SKU is "quantity": 2 on a single request).

If the customer’s checkout mixes products (for example iTunes and PUBG), send one request per line — each with its own item_code, quantity, and Idempotency-Key. You get a separate order_id and a separate wallet debit for each line.

Do not send an items array or a mixed cart in one body. That is not supported. Idempotency is per purchase attempt (that SKU and quantity), not per storefront cart.

Use data.order_id for status, codes, and support. It identifies this purchase in CardPlusPay.

Step 2: Handle the response

Completed immediately

On success with status: completed, data includes identifiers, amounts, and gift card codes:

{
  "success": true,
  "message": "Gift card purchased successfully",
  "data": {
    "type": "bulk",
    "brand": "GOOGLE-5USD-KOXx",
    "codes": [
      {
        "code": "XXXX-XXXX-XXXX-XXXX",
        "currency": "USD",
        "item_code": "GOOGLE-5USD-KOXx",
        "denomination": "5.00",
        "charged_amount": "4.90",
        "denomination_unit": "USD"
      }
    ],
    "state": "completed",
    "amount": "4.90",
    "status": "completed",
    "order_id": 123,
    "order_no": "ORD-2026-001",
    "created_at": "2026-03-07T21:42:27+02:00",
    "denomination_unit": "USD",
    "total_denomination": 5
  }
}
  • order_id — Use this to check order status later.
  • order_no — Human-readable order reference for your records and support.
  • amount — Total amount charged for this order.
  • codes — Deliver to the customer when present and status is completed.

Still processing (pending)

Some orders return HTTP 200 with status: pending and an empty or missing codes array:

{
  "success": true,
  "message": "Order is being processed",
  "data": {
    "order_id": 124,
    "order_no": "ORD-2026-002",
    "status": "pending",
    "state": "pending",
    "amount": "4.90",
    "codes": []
  }
}

This is not a failure. CardPlusPay is still fulfilling the order. Your API wallet has been debited. Do not create a duplicate order or refund your customer based on time alone. Poll GET /orders/{order_id} until status becomes completed (then read codes) or failed. See order status & polling.

Store order_id and order_no in your database for support and reconciliation.

Production integration

  • HTTP client timeout — Configure at least 90 seconds for POST /orders (180 seconds recommended for some SKUs). A timeout before you receive a response does not mean the order failed.
  • Idempotency on retry — If the connection ends before you receive a response, retry POST /orders with the same Idempotency-Key and body. A same-key replay of an in-flight order is HTTP 200 with status: pending (same success wrapper as the first pending create), not 409.
  • After retry — A successful replay returns HTTP 200 with the same order_id and current status (pending, completed, or a 400 if that key already failed). Poll GET /orders/{id} using data.order_id from that success body.

Error handling

Common responses:

  • 400 — Purchase blocked. Check message and data.state:
    • invalid_quantity — quantity is outside this SKU’s min/max.
    • out_of_stock — Not enough inventory at purchase time (wallet is not debited).
    • Terminal failure with order_id — If order_id is present, call GET /orders/{id} before treating as final; status may still be pending.
    • Failed idempotency replay — A previous purchase with the same key already failed. Start a new purchase with a new key.
  • 402 — Insufficient API wallet balance. Top up your account before retrying.
  • 401 — Invalid or missing API key.
  • 409 — idempotency_conflict — Same key with a different request body (item_code, quantity, or top-up fields). Start a new purchase with a new key. Same key and same body while the order is pending is HTTP 200 (see above), not 409.
  • 422 — Validation error (e.g. missing item_code or invalid format).

← Check availability · Integration Guide · Order status →