Validate Coupon
Introduction
This endpoint validates a coupon code for a specific event and ticket, ensuring that it’s applicable, available, and authorized for the current user.
Endpoint
POST https://api.paydexp.com/v1/coupon/validate
Authorization
Users need to include basic authentication credentials in the request headers.
Below are code examples in different programming languages demonstrating how to validate a ticket sales.
- Curl
- Go
- Node.js
- Python
- PHP
curl --location --request POST 'https://api.paydexp.com/v1/coupon/validate' \
--header 'Authorization: Basic {base64_encoded_username_password}' \
--header 'Content-Type: application/json' \
--data '{
"event_id": 123,
"ticket_id": 1759,
"slots": 2,
"coupon_code": "DISCOUNT20"
}'
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.paydexp.com/v1/coupon/validate"
method := "POST"
payload := strings.NewReader(`{
"event_id": 123,
"ticket_id": 1759,
"slots": 2,
"coupon_code": "DISCOUNT20"
}`)
client := &http.Client{}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Basic {base64_encoded_username_password}")
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}
const axios = require('axios');
let data = JSON.stringify({
"event_id": 123,
"ticket_id": 1759,
"slots": 2,
"coupon_code": "DISCOUNT20"
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.paydexp.com/v1/coupon/validate',
headers: {
'Authorization': 'Basic {base64_encoded_username_password}',
'Content-Type': 'application/json'
},
data: data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data, null, 2));
})
.catch((error) => {
console.log(error);
});
import requests
import json
from requests.auth import HTTPBasicAuth
url = "https://api.paydexp.com/v1/coupon/validate"
payload = {
"event_id": 123,
"ticket_id": 1759,
"slots": 2,
"coupon_code": "DISCOUNT20"
}
headers = {
"Content-Type": "application/json"
}
response = requests.post(
url,
headers=headers,
data=json.dumps(payload),
auth=HTTPBasicAuth("username", "password") # replace with your credentials
)
print(response.status_code)
print(response.json())
<?php
$url = 'https://api.paydexp.com/v1/coupon/validate';
$payload = array(
"event_id" => 123,
"ticket_id" => 1759,
"slots" => 2,
"coupon_code" => "DISCOUNT20"
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic {base64_encoded_username_password}',
'Content-Type: application/json'
));
$response = curl_exec($ch);
if(curl_errno($ch)){
echo 'Request Error:' . curl_error($ch);
}
curl_close($ch);
echo $response;
?>
Example Success Response
{
"success": true,
"data": {
"id": 1,
"code": "DISCOUNT20",
"discount_type": "percentage",
"discount_value": 20,
"valid_for_ticket": true,
"is_available": true,
"available_until": "2025-12-14",
"original_amount": 300,
"discounted_amount": 240,
"discount_amount": 60,
"discount_percentage": 20,
"sale_period": "Nov 1, 2025 - Dec 14, 2025"
},
"message": "Coupon is valid and applicable."
}
Error Response
{
"success": false,
"message": "Coupon not found"
}
NB
This endpoint includes additional validations to ensure that:
- The event belongs to the authenticated API user
- The ticket belongs to the specified event
- The coupon code is valid and available
- The coupon can be applied to the specified ticket
Conclusion
The endpoint provides a secure and efficient way to verify whether a coupon is valid and applicable to a specific event and ticket.