Contents
On this page

Validate Coupon - Plugixa Car Parking

POST /plugixa-car-parking/v1/coupon/validate

Check whether a coupon code can be used for a selection, and how much it takes off a given subtotal.

Anyone may call it, signed in or not, with the public nonce the plugin’s pages print (see Public routes). It counts against the coupon_validate rate limit: 10 every 10 minutes per visitor address.

Note. An unusable code is not an error: the answer is still 200, with valid: false and a reason. This route also does not look at the site’s coupon setting or at the booking form: a code can come back valid here and still be left out of the price when coupons are switched off or the form hides the coupon field. Price a Stay gives the price that will really be charged.

Request

POST https://your-site.example/wp-json/plugixa-car-parking/v1/coupon/validate

Request body

Content type: application/json. Send the nonce as security here or in the X-Plugixa-Carparking-Nonce header.

Field Type Required Description
code string Yes The coupon code.
subtotal number No The amount to discount. Checked against the coupon’s minimum amount, and used to work out discount. Defaults to 0.
location_id integer No Needed when the coupon is limited to some locations.
space_type_id integer No Needed when the coupon is limited to some space types.
security string Yes The public nonce, unless sent in the header.

The per-customer usage limit is checked only for a signed-in caller.

{
  "code": "WELCOME10",
  "subtotal": 48,
  "location_id": 2,
  "space_type_id": 1
}

Responses

200 OK. The code is valid.

{
  "success": true,
  "message": "",
  "data": {
    "valid": true,
    "code": "WELCOME10",
    "discount": 4.8
  }
}

200 OK. The code cannot be used.

{
  "success": true,
  "message": "",
  "data": {
    "valid": false,
    "reason": "expired",
    "discount": 0
  }
}
Field Type Meaning
data.valid boolean Whether the code can be used
data.code string The coupon’s code as stored. Only when valid
data.discount number What it takes off subtotal: a percentage, or a fixed amount never larger than subtotal. 0 when not valid
data.reason string Only when not valid. One of the reasons below
Reason Meaning
empty No code was sent
not_found No active coupon has that code
not_started The coupon’s start date has not come yet
expired The coupon’s end date has passed
usage_limit The coupon has been used as many times as allowed
usage_limit_per_user The signed-in customer has used it as many times as allowed
min_amount subtotal is below the coupon’s minimum amount
location The coupon does not apply at location_id
space_type The coupon does not apply to space_type_id

Errors

Status Code When
403 rest_error The nonce is missing or not valid: “Your session expired. Please refresh and try again.”

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixa-car-parking/v1/coupon/validate" \
  -H "Content-Type: application/json" \
  -H "X-Plugixa-Carparking-Nonce: $PCP_NONCE" \
  -d '{"code":"WELCOME10","subtotal":48,"location_id":2,"space_type_id":1}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-car-parking/v1/coupon/validate');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => [
        'Content-Type: application/json',
        'X-Plugixa-Carparking-Nonce: ' . getenv('PCP_NONCE'),
    ],
    CURLOPT_POSTFIELDS     => json_encode([
        'code'          => 'WELCOME10',
        'subtotal'      => 48,
        'location_id'   => 2,
        'space_type_id' => 1,
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-car-parking/v1/coupon/validate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Plugixa-Carparking-Nonce': PCP_NONCE,
  },
  body: JSON.stringify({ code: 'WELCOME10', subtotal: 48, location_id: 2, space_type_id: 1 }),
});
const { data } = await response.json();

Quick Links

Share