Contents
On this page

Check Balance - Plugixa PDF Vouchers for WooCommerce

POST /plugixa-pdf-vouchers/v1/balance

What the Balance check block and shortcode call. It answers the balance, whether the voucher can be used and its expiry date, never a name or an email.

Public: no sign-in. The route protects itself instead, as described below. Each visitor may check balance_rate_limit codes a minute (10 by default, see Settings). Wrong codes also count towards the checkout’s lock against guessing codes, and a locked visitor gets the same answer as for a wrong code.

Request

POST https://your-store.example/wp-json/plugixa-pdf-vouchers/v1/balance

Request body

Content type: application/json

Field Type Required Description
code string Yes The voucher code.
{
  "code": "PX-M9P2-FU55"
}

Responses

200 OK. This route answers without the usual data wrapper.

{
  "success": true,
  "usable": true,
  "balance": 30,
  "expires": "",
  "message": "Balance: €30.00."
}
Field Type Meaning
success boolean true
usable boolean Whether the voucher can be spent now
balance number What is left, in the voucher’s currency
expires string The expiry date in the site’s date format, empty when it never expires
message string A sentence for the visitor: the balance and, when there is one, the expiry date; or why the voucher cannot be used, for example This voucher has expired.

The example shows a voucher with no expiry date. With one, message adds the date after the balance.

Errors

Status Code When
404 Unknown, voided, or the visitor is locked for guessing: {"success": false, "message": "This voucher code is not valid."}
429 Too many checks: success false and Too many requests. Please wait a little while and try again. A CAPTCHA added through the plugixa_pdfv_public_request_captcha filter also answers 429 when it fails.

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-store.example/wp-json/plugixa-pdf-vouchers/v1/balance" \
  -H "Content-Type: application/json" \
  -d '{"code":"PX-M9P2-FU55"}'
<?php
$ch = curl_init('https://your-store.example/wp-json/plugixa-pdf-vouchers/v1/balance');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS     => json_encode([
        'code' => 'PX-M9P2-FU55',
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-store.example/wp-json/plugixa-pdf-vouchers/v1/balance', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ code: 'PX-M9P2-FU55' }),
});
const { data } = await response.json();

Quick Links

Share