Skip to main content

Apply Gift Voucher

Apply a gift voucher code to reduce the cart total.

Authentication

Requires user authentication token.

Request Body

voucher_code
string
required
Gift voucher code to apply

Response

Returns the updated cart with gift voucher discount applied.
products
object
Products in cart with updated pricing
meta
object
Cart metadata including gift voucher details
calculations
object
Updated cart totals with voucher discount

Validation Process

  1. Code Sanitization - Voucher code is sanitized
  2. Ownership Check - Verifies voucher belongs to user (by email or phone)
  3. Status Check - Ensures voucher is active (status=1)
  4. Cart Validation - Vouchers cannot be applied to gift-voucher-only carts
  5. Discount Application - Applies available voucher balance to cart
{
  "products": {
    "items": [
      {
        "prod_id": 12345,
        "product": "Classic T-Shirt",
        "price": 799,
        "quantity": 2,
        "sub_total": 1598
      }
    ]
  },
  "meta": {
    "items": [
      {
        "name": "gift_voucher",
        "voucher_code": "GV2024ABC123"
      },
      {
        "name": "calculations",
        "sub_total": 1598,
        "gift_voucher_value": 500,
        "total": 1098
      }
    ]
  }
}

Error Responses

title
string
Error title
description
string
Detailed error message
{
  "title": "Bad Request",
  "description": "Please provide the voucher code"
}
{
  "title": "Bad Request",
  "description": "Invalid voucher code"
}
{
  "title": "Bad Request",
  "description": "Gift Voucher not applicable on current cart"
}

View Gift Vouchers

Retrieve all available gift vouchers for the authenticated user.

Authentication

Requires user authentication token.

Query Parameters

platform
string
Platform identifier (web/app)

Response

Returns an array of gift vouchers owned by the user.
name
string
Name of the person who sent the gift voucher
voucher_code
string
Unique voucher code
voucher_value
number
Current balance/value of the voucher
voucher_initial_value
number
Original value of the voucher when issued
event_id
string
Event tracking ID (only for web platform)
[
  {
    "name": "John Doe",
    "voucher_code": "GV2024ABC123",
    "voucher_value": 500,
    "voucher_initial_value": 1000
  },
  {
    "name": "Jane Smith",
    "voucher_code": "GV2024XYZ456",
    "voucher_value": 750,
    "voucher_initial_value": 750
  },
  {
    "event_id": "pageview_1234567890"
  }
]

Gift Voucher Ownership

Gift vouchers are linked to users through:
  • Email Address - Primary identifier
  • Phone Number - Secondary identifier (if email is empty)
The system checks both email and phone to find vouchers belonging to the user.

Database Query Logic

SELECT voucher_code, voucher_value, voucher_initial_value, sender_name
FROM gift_vouchers gv
INNER JOIN users u ON u.id = gv.from_id
WHERE gv.status = 1 
  AND (
    gv.to_id = :user_email 
    OR (gv.to_id IN ('', NULL) AND gv.to_phone = :user_phone)
  )

Gift Voucher Restrictions

  • Cannot be the only items in cart when applying voucher
  • Must have regular products in cart along with gift vouchers
  • Voucher must be active (status=1)
  • Voucher must belong to the authenticated user
  • Partial usage is supported (remaining balance preserved)

Purchase Gift Vouchers

Gift vouchers can be purchased as products and will be:
  • Generated with unique codes
  • Sent to recipient’s email/phone
  • Tracked in order history
  • Activated upon successful payment

Tracking & Analytics

The endpoint includes Facebook event tracking for:
  • Page views
  • Voucher applications
  • Purchase events
Event data includes:
  • User email and phone
  • Event source URL
  • Action source (web=1, app=2)
  • Client IP address
  • User agent information

Build docs developers (and LLMs) love