E-commerce Integration
Connect your online store to VoucherTrack for seamless voucher validation and redemption
VoucherTrack provides simple webhook endpoints to integrate with any e-commerce platform. Validate vouchers at checkout, apply discounts, and track online redemptions alongside in-store visits.
Getting Your API Key
Before integrating, you'll need your unique API key from VoucherTrack:
- Log in to your VoucherTrack admin dashboard
- Go to Settings → API Keys (or ask your account manager)
- Copy your API key — keep it secure, don't commit to public repos
Your API key grants access to validate and redeem vouchers for your campaigns. Store it as an environment variable — never hardcode it in your website's source code.
How It Works
-
1
Customer enters code at checkout — Your site collects the voucher code
-
2
Your system calls our validation API — We confirm validity and return discount details
-
3
You apply the discount — Use the discount value we return
-
4
After order completes, notify us — We mark the voucher as redeemed and log the transaction
Step 1: Validate Voucher at Checkout
When a customer enters a voucher code, call our validation endpoint to check if it's valid:
GET /api/webhook/validate/{code}
GET /api/webhook/validate/SUMMER20-X7K3M2 Headers: X-API-Key: your_api_key
Success Response (valid voucher):
{
"valid": true,
"code": "SUMMER20-X7K3M2",
"discount_type": "percentage",
"discount_value": 20,
"discount_description": "20% off your order",
"minimum_spend": 25.00,
"valid_until": "2026-03-31T23:59:59Z",
"remaining_uses": 1,
"campaign_name": "Summer Sale",
"client_name": "Demo Restaurant"
}
Error Response (invalid voucher):
{
"valid": false,
"code": "EXPIRED123",
"error": "Voucher has expired"
}
- • "Voucher not found"
- • "Voucher has expired"
- • "Voucher has already been redeemed"
- • "Maximum uses reached"
- • "Voucher not yet active"
Step 2: Apply the Discount
Based on the validation response, apply the discount to the customer's cart:
| Discount Type | How to Apply |
|---|---|
| percentage | Calculate: cart_total × (discount_value / 100) |
| fixed | Subtract: min(discount_value, cart_total) |
| free_item | Show custom message from discount_description |
If minimum_spend is returned, only apply the discount if the cart total meets this threshold.
Show an appropriate message if not met (e.g., "Add £5 more to qualify for this discount").
Step 3: Record the Redemption
After the order is successfully placed, notify VoucherTrack so we can mark the voucher as redeemed and record the transaction details:
POST /api/webhook/redemption
POST /api/webhook/redemption
Headers:
X-API-Key: your_api_key
Content-Type: application/json
{
"code": "SUMMER20-X7K3M2",
"transaction_amount": 45.99,
"order_reference": "ORD-12345",
"redeemed_at": "2026-02-03T14:30:00Z"
}
Success Response:
{
"success": true,
"voucher_code": "SUMMER20-X7K3M2",
"discount_applied": 9.20,
"message": "Redemption recorded successfully"
}
Example: WooCommerce Integration
We have a complete, production-ready WooCommerce integration guide with full code. View the full WooCommerce guide →
Here's a simplified example of how you might integrate with WooCommerce using a custom plugin:
// Validate voucher when coupon is applied
add_filter('woocommerce_coupon_is_valid', function($valid, $coupon) {
$code = $coupon->get_code();
// Call VoucherTrack validation
$response = wp_remote_get(
"https://www.vouchertrack.io/api/webhook/validate/{$code}",
['headers' => ['X-API-Key' => 'your_api_key']]
);
$data = json_decode(wp_remote_retrieve_body($response));
if (!$data->valid) {
throw new Exception($data->error);
}
return true;
}, 10, 2);
// Record redemption after order completes
add_action('woocommerce_order_status_completed', function($order_id) {
$order = wc_get_order($order_id);
$coupons = $order->get_coupon_codes();
foreach ($coupons as $code) {
wp_remote_post('https://www.vouchertrack.io/api/webhook/redemption', [
'headers' => [
'X-API-Key' => 'your_api_key',
'Content-Type' => 'application/json'
],
'body' => json_encode([
'code' => $code,
'transaction_amount' => $order->get_total(),
'order_reference' => $order->get_order_number()
])
]);
}
});
Example: Shopify Integration
For Shopify, you can use a custom app or Shopify Functions:
// Shopify Function (JavaScript)
export function run(input) {
const code = input.cart.discountCodes[0]?.code;
// Call your backend which validates with VoucherTrack
const validation = await fetch(
`https://your-api.com/validate-voucher?code=${code}`
).then(r => r.json());
if (!validation.valid) {
return { discounts: [], discountApplicationStrategy: "FIRST" };
}
return {
discounts: [{
value: {
percentage: { value: validation.discount_value }
},
targets: [{ cartLine: { id: "gid://shopify/CartLine/0" } }]
}],
discountApplicationStrategy: "FIRST"
};
}
Benefits for E-commerce
See online and in-store redemptions in one dashboard. Track which campaigns drive sales.
Each code can only be used once. Real-time validation prevents abuse.
Know exactly which direct mail piece, flyer, or campaign drove each online order.
Transaction amounts are logged, so you can calculate true campaign ROI.
Need Help?
We can provide integration support for your specific e-commerce platform. Contact us at hello@vouchertrack.io.