Contents
On this page

Preview Invoice Layout - Plugixa POS for WooCommerce

POST /plugixa-pos/v1/invoice-layout/preview

Render a design without saving it, on the latest completed register sale.

Needs a user with the plugixa_pos_manage_settings capability (signed in with an Application Password, or the login cookie with an X-WP-Nonce header). Administrators hold it; other roles only when you grant it.

Request

POST https://your-site.example/wp-json/plugixa-pos/v1/invoice-layout/preview

Request body

Content type: application/json

Field Type Required Description
layout object Yes version and schemas: up to 150 elements of type text, image, rectangle, ellipse or line, positioned in mm. One element must be named lines (at least 90 by 40 mm): the lines, VAT and totals go there.
{
  "layout": {
    "version": 1,
    "schemas": [
      {
        "name": "seller_company",
        "type": "text",
        "content": "{seller_company}",
        "position": {
          "x": 13,
          "y": 14
        },
        "width": 110,
        "height": 8,
        "rotate": 0,
        "opacity": 1,
        "readOnly": true,
        "fontName": "dejavusans-bold",
        "fontSize": 14,
        "fontColor": "#1f2937",
        "alignment": "left",
        "verticalAlignment": "top",
        "lineHeight": 1.3,
        "characterSpacing": 0,
        "backgroundColor": ""
      },
      {
        "name": "lines",
        "type": "rectangle",
        "position": {
          "x": 13,
          "y": 100
        },
        "width": 184,
        "height": 120
      }
    ]
  }
}

Responses

200 OK. data.pdf is the PDF, base64-encoded.

{
  "success": true,
  "data": {
    "pdf": "JVBERi0xLjcKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAv..."
  }
}

Errors

Status Code When
422 plugixa_pos_layout_lines The lines element is missing or too small.
409 plugixa_pos_preview_no_sale No completed register sale yet.

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixa-pos/v1/invoice-layout/preview" \
  -u "$WP_USER:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"layout":{"version":1,"schemas":[{"name":"seller_company","type":"text","content":"{seller_company}","position":{"x":13,"y":14},"width":110,"height":8,"rotate":0,"opacity":1,"readOnly":true,"fontName":"dejavusans-bold","fontSize":14,"fontColor":"#1f2937","alignment":"left","verticalAlignment":"top","lineHeight":1.3,"characterSpacing":0,"backgroundColor":""},{"name":"lines","type":"rectangle","position":{"x":13,"y":100},"width":184,"height":120}]}}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-pos/v1/invoice-layout/preview');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD        => getenv('WP_USER') . ':' . getenv('WP_APP_PASSWORD'),
    CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS     => json_encode([
        'layout' => [
            'version' => 1,
            'schemas' => [
                [
                    'name'              => 'seller_company',
                    'type'              => 'text',
                    'content'           => '{seller_company}',
                    'position'          => [
                        'x' => 13,
                        'y' => 14,
                    ],
                    'width'             => 110,
                    'height'            => 8,
                    'rotate'            => 0,
                    'opacity'           => 1,
                    'readOnly'          => true,
                    'fontName'          => 'dejavusans-bold',
                    'fontSize'          => 14,
                    'fontColor'         => '#1f2937',
                    'alignment'         => 'left',
                    'verticalAlignment' => 'top',
                    'lineHeight'        => 1.3,
                    'characterSpacing'  => 0,
                    'backgroundColor'   => '',
                ],
                [
                    'name'     => 'lines',
                    'type'     => 'rectangle',
                    'position' => [
                        'x' => 13,
                        'y' => 100,
                    ],
                    'width'    => 184,
                    'height'   => 120,
                ],
            ],
        ],
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-pos/v1/invoice-layout/preview', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${btoa(`${process.env.WP_USER}:${process.env.WP_APP_PASSWORD}`)}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ layout: { version: 1, schemas: [{ name: 'seller_company', type: 'text', content: '{seller_company}', position: { x: 13, y: 14 }, width: 110, height: 8, rotate: 0, opacity: 1, readOnly: true, fontName: 'dejavusans-bold', fontSize: 14, fontColor: '#1f2937', alignment: 'left', verticalAlignment: 'top', lineHeight: 1.3, characterSpacing: 0, backgroundColor: '' }, { name: 'lines', type: 'rectangle', position: { x: 13, y: 100 }, width: 184, height: 120 }] } }),
});
const { data } = await response.json();

Quick Links

Share