Skip to content

Coupons API

Create and manage discount coupons for your store.

List Coupons

http
GET /api/external/v1/coupons

Query Parameters

ParameterTypeDescription
pageintegerPage number (default: 1)
per_pageintegerItems per page (default: 15, max: 100)
statusstringFilter: active, inactive, expired, scheduled
typestringFilter: percentage, fixed_amount, free_shipping
searchstringSearch in code and name

Example Request

bash
curl -X GET "https://yourstore.pixlpay.net/api/external/v1/coupons?status=active&type=percentage" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json"

Response

json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "code": "SUMMER25",
      "name": "Summer Sale 25% Off",
      "description": "25% off all products during summer sale",
      "type": "percentage",
      "value": "25.00",
      "minimum_order_amount": "10.00",
      "maximum_discount": "50.00",
      "usage_limit": 100,
      "usage_limit_per_customer": 1,
      "times_used": 42,
      "is_active": true,
      "first_order_only": false,
      "starts_at": "2025-06-01T00:00:00Z",
      "expires_at": "2025-08-31T23:59:59Z",
      "created_at": "2025-05-15T10:30:00Z",
      "updated_at": "2025-05-15T10:30:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "last_page": 2,
    "per_page": 15,
    "total": 18
  }
}

Get Single Coupon

http
GET /api/external/v1/coupons/{id}

Example Request

bash
curl -X GET "https://yourstore.pixlpay.net/api/external/v1/coupons/1" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json"

Response

json
{
  "success": true,
  "data": {
    "id": 1,
    "code": "SUMMER25",
    "name": "Summer Sale 25% Off",
    "description": "25% off all products during summer sale",
    "type": "percentage",
    "value": "25.00",
    "minimum_order_amount": "10.00",
    "maximum_discount": "50.00",
    "usage_limit": 100,
    "usage_limit_per_customer": 1,
    "times_used": 42,
    "applicable_products": null,
    "applicable_categories": null,
    "excluded_products": null,
    "is_active": true,
    "first_order_only": false,
    "starts_at": "2025-06-01T00:00:00Z",
    "expires_at": "2025-08-31T23:59:59Z",
    "created_at": "2025-05-15T10:30:00Z",
    "updated_at": "2025-05-15T10:30:00Z"
  }
}

Create Coupon

http
POST /api/external/v1/coupons

Request Body

ParameterTypeRequiredDescription
codestringNoUnique coupon code (auto-generated if not provided)
namestringYesDisplay name for the coupon
descriptionstringNoDescription of the coupon
typestringYesDiscount type: percentage, fixed_amount, free_shipping
valuenumberYesDiscount value (percentage or fixed amount)
minimum_order_amountnumberNoMinimum order amount required
maximum_discountnumberNoMaximum discount cap (for percentage discounts)
usage_limitintegerNoTotal usage limit across all customers
usage_limit_per_customerintegerNoUsage limit per individual customer
applicable_productsarrayNoArray of product IDs coupon applies to
applicable_categoriesarrayNoArray of category IDs coupon applies to
excluded_productsarrayNoArray of product IDs to exclude
is_activebooleanNoWhether coupon is active (default: true)
first_order_onlybooleanNoOnly valid for first-time customers
starts_atstringNoStart date (ISO 8601)
expires_atstringNoExpiration date (ISO 8601)

Example Request

bash
curl -X POST "https://yourstore.pixlpay.net/api/external/v1/coupons" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "WELCOME10",
    "name": "Welcome Discount",
    "description": "10% off for new customers",
    "type": "percentage",
    "value": 10,
    "minimum_order_amount": 5.00,
    "maximum_discount": 25.00,
    "usage_limit_per_customer": 1,
    "first_order_only": true,
    "is_active": true
  }'

Response

json
{
  "success": true,
  "data": {
    "id": 2,
    "code": "WELCOME10",
    "name": "Welcome Discount",
    "description": "10% off for new customers",
    "type": "percentage",
    "value": "10.00",
    "minimum_order_amount": "5.00",
    "maximum_discount": "25.00",
    "usage_limit": null,
    "usage_limit_per_customer": 1,
    "times_used": 0,
    "applicable_products": null,
    "applicable_categories": null,
    "excluded_products": null,
    "is_active": true,
    "first_order_only": true,
    "starts_at": null,
    "expires_at": null,
    "created_at": "2025-01-20T14:30:00Z",
    "updated_at": "2025-01-20T14:30:00Z"
  },
  "message": "Coupon created successfully"
}

Update Coupon

http
PUT /api/external/v1/coupons/{id}

Request Body

All fields from the create endpoint are accepted. Only include fields you want to update.

Example Request

bash
curl -X PUT "https://yourstore.pixlpay.net/api/external/v1/coupons/2" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "value": 15,
    "maximum_discount": 30.00,
    "expires_at": "2025-12-31T23:59:59Z"
  }'

Response

json
{
  "success": true,
  "data": {
    "id": 2,
    "code": "WELCOME10",
    "name": "Welcome Discount",
    "description": "10% off for new customers",
    "type": "percentage",
    "value": "15.00",
    "minimum_order_amount": "5.00",
    "maximum_discount": "30.00",
    "usage_limit": null,
    "usage_limit_per_customer": 1,
    "times_used": 0,
    "is_active": true,
    "first_order_only": true,
    "starts_at": null,
    "expires_at": "2025-12-31T23:59:59Z",
    "created_at": "2025-01-20T14:30:00Z",
    "updated_at": "2025-01-20T15:00:00Z"
  },
  "message": "Coupon updated successfully"
}

Delete Coupon

http
DELETE /api/external/v1/coupons/{id}

Coupons with usage history are soft-deleted (archived). Coupons that have never been used are permanently deleted.

Example Request

bash
curl -X DELETE "https://yourstore.pixlpay.net/api/external/v1/coupons/2" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json"

Response

json
{
  "success": true,
  "message": "Coupon deleted successfully"
}

Validate Coupon Code

Validate a coupon code for checkout. This endpoint checks if the coupon is valid, applicable to the customer, and calculates the discount amount.

http
POST /api/external/v1/coupons/validate

Request Body

ParameterTypeRequiredDescription
codestringYesCoupon code to validate
subtotalnumberYesOrder subtotal amount
customer_emailstringYesCustomer's email address
cart_itemsarrayNoCart items for product-specific validation

Cart Item Object

FieldTypeDescription
product_idintegerProduct ID
category_idintegerCategory ID
pricenumberItem price
quantityintegerItem quantity
totalnumberItem total (price * quantity)

Example Request

bash
curl -X POST "https://yourstore.pixlpay.net/api/external/v1/coupons/validate" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "SUMMER25",
    "subtotal": 49.99,
    "customer_email": "player@example.com",
    "cart_items": [
      {
        "product_id": 1,
        "category_id": 2,
        "price": 24.99,
        "quantity": 2,
        "total": 49.98
      }
    ]
  }'

Response (Valid Coupon)

json
{
  "success": true,
  "data": {
    "valid": true,
    "coupon": {
      "id": 1,
      "code": "SUMMER25",
      "name": "Summer Sale 25% Off",
      "type": "percentage",
      "type_label": "Percentage Off",
      "value": "25.00",
      "formatted_value": "25%",
      "discount_amount": 12.50,
      "minimum_order_amount": "10.00",
      "maximum_discount": "50.00"
    }
  }
}

Response (Invalid Coupon)

json
{
  "success": false,
  "data": {
    "valid": false,
    "message": "This coupon has expired"
  }
}

Toggle Coupon Status

Enable or disable a coupon.

http
POST /api/external/v1/coupons/{id}/toggle

Example Request

bash
curl -X POST "https://yourstore.pixlpay.net/api/external/v1/coupons/1/toggle" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json"

Response

json
{
  "success": true,
  "data": {
    "id": 1,
    "code": "SUMMER25",
    "is_active": false
  },
  "message": "Coupon deactivated"
}

Get Coupon Statistics

Retrieve overall coupon statistics for your store.

http
GET /api/external/v1/coupons/statistics

Example Request

bash
curl -X GET "https://yourstore.pixlpay.net/api/external/v1/coupons/statistics" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json"

Response

json
{
  "success": true,
  "data": {
    "statistics": {
      "total_coupons": 18,
      "active_coupons": 12,
      "expired_coupons": 4,
      "total_usages": 342,
      "total_discount_given": "4,523.50",
      "top_coupons": [
        {
          "id": 1,
          "code": "SUMMER25",
          "name": "Summer Sale 25% Off",
          "type": "percentage",
          "value": "25.00",
          "times_used": 89
        },
        {
          "id": 3,
          "code": "FLAT10",
          "name": "$10 Off",
          "type": "fixed_amount",
          "value": "10.00",
          "times_used": 67
        }
      ]
    }
  }
}

Get Coupon Usage History

Retrieve usage history for a specific coupon.

http
GET /api/external/v1/coupons/{id}/usages

Query Parameters

ParameterTypeDescription
pageintegerPage number (default: 1)
per_pageintegerItems per page (default: 15, max: 100)

Example Request

bash
curl -X GET "https://yourstore.pixlpay.net/api/external/v1/coupons/1/usages?per_page=10" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json"

Response

json
{
  "success": true,
  "data": {
    "coupon": {
      "id": 1,
      "code": "SUMMER25",
      "name": "Summer Sale 25% Off",
      "times_used": 89
    },
    "usages": [
      {
        "id": 1,
        "discount_amount": "12.50",
        "created_at": "2025-07-15T14:30:00Z",
        "order": {
          "id": 156,
          "order_number": "ORD-2025-156",
          "total": "37.49",
          "payment_status": "paid",
          "customer_email": "player@example.com",
          "created_at": "2025-07-15T14:30:00Z"
        }
      }
    ]
  },
  "meta": {
    "current_page": 1,
    "last_page": 9,
    "per_page": 10,
    "total": 89
  }
}

Duplicate Coupon

Create a copy of an existing coupon with a new unique code.

http
POST /api/external/v1/coupons/{id}/duplicate

Example Request

bash
curl -X POST "https://yourstore.pixlpay.net/api/external/v1/coupons/1/duplicate" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json"

Response

json
{
  "success": true,
  "data": {
    "id": 19,
    "code": "A8K2M9PX",
    "name": "Summer Sale 25% Off (Copy)",
    "description": "25% off all products during summer sale",
    "type": "percentage",
    "value": "25.00",
    "times_used": 0,
    "is_active": true,
    "created_at": "2025-01-20T16:00:00Z",
    "updated_at": "2025-01-20T16:00:00Z"
  },
  "message": "Coupon duplicated successfully"
}

Coupon Object

FieldTypeDescription
idintegerUnique identifier
codestringCoupon code (uppercase)
namestringDisplay name
descriptionstringDescription
typestringpercentage, fixed_amount, free_shipping
valuestringDiscount value
minimum_order_amountstringMinimum order amount required
maximum_discountstringMaximum discount cap
currencystringCurrency code
usage_limitintegerTotal usage limit (null = unlimited)
usage_limit_per_customerintegerPer-customer limit (null = unlimited)
times_usedintegerNumber of times used
applicable_productsarrayProduct IDs coupon applies to
applicable_categoriesarrayCategory IDs coupon applies to
excluded_productsarrayProduct IDs excluded from coupon
is_activebooleanWhether coupon is active
first_order_onlybooleanOnly for first-time customers
starts_atstringStart date (ISO 8601)
expires_atstringExpiration date (ISO 8601)
created_atstringISO 8601 timestamp
updated_atstringISO 8601 timestamp

Coupon Types

TypeDescription
percentagePercentage discount off order subtotal
fixed_amountFixed monetary discount
free_shippingFree shipping on the order

Validation Errors

When validating a coupon, these are possible error messages:

Error MessageDescription
Coupon not foundThe code doesn't exist
This coupon is no longer activeCoupon is disabled
This coupon has expiredPast expiration date
This coupon is not yet activeBefore start date
This coupon has reached its usage limitGlobal limit reached
This coupon is only valid for first-time customersNot a first order
You have already used this coupon the maximum number of timesPer-customer limit reached
Minimum order amount of $X.XX requiredSubtotal too low
No applicable products in cart for this couponProduct restrictions not met

API Errors

StatusErrorDescription
400Bad RequestInvalid coupon or validation failed
401UnauthorizedInvalid or missing token
403ForbiddenToken lacks coupons:read or coupons:write scope
404Not FoundCoupon doesn't exist
422UnprocessableValidation error (e.g., percentage > 100%)

Built for game developers, by game developers.