Building a plugin¶
A checklist for anyone who writes a plugin or module for a CMS or a shop platform that connects a shop to Ziex Try-On. Work through it in order. A plugin that passes every item behaves the way the WooCommerce plugin and the 1C-Bitrix module do. The same checks make a good acceptance test for your own plugin.
Not an automated test
This is a checklist for you to run by hand. We do not yet publish a script that runs it for you.
The shape of a plugin¶
A plugin has two halves:
- The server half runs on the shop's server. It holds the secret key (
tryon_…) and talks to the API. - The page half is printed into the product page. It holds only the publishable key (
pk_…) and starts the widget.
The secret key never leaves the server. If it appears in a page, a stranger can read it, and it also opens the shop's client portal with the shoppers' photos. See Keys.
1. Connect the site¶
- [ ] Ask the API about the site. From the server, call
GET /api/v1/tryon/integration?site_url=<the shop's address>with the secret key inX-API-Key. Call it when the shop owner saves the key and when the settings page opens, not on every page view: it counts against the general request limit (see Limits) and the answer changes rarely. - [ ] Read
site.allowed. Print the widget only when it istrue. When it isfalse,site.reasontells why:key_not_bound(the key has no bound domain),domain_mismatch(the key belongs to another site) ordev_host(a live key on a development host). Show the shop owner a message that matches; fordev_hostsay "use a test key on a local site". The reasons map onto error codes in Errors. -
[ ] Use the rest of the answer. The fields a plugin needs:
Field What it is site.allowed,site.reason,site.hostWhether this site may use the key, why not, and the site's host as the API reads it. key.publishable_keyThe pk_…key to print on the page.key.modeliveortest. Fortest, tell the shop owner that no money is charged and the result is simulated.key.domain,client.nameThe bound domain and the account name, for the settings page. planThe plan name, its limit, the generations used and remaining, and when they reset. widget.script_url,widget.api_urlThe widget script and the API address, from our host. capabilitiesThe categories the service supports (below). integrationsFor each known plugin or module: latest_version,download_url(ornullwhen we hand the archive over ourselves) anddocs_url. Use it to tell the owner that a newer version of your plugin exists. -
[ ] Identify the plugin on every server call. Send
X-Ziex-Integration: <name>/<version>and your ownUser-Agent(see Identification and Quickstart B).
2. Print the widget safely¶
- [ ] No
tryon_…key in the page. Check the page the plugin produces: the HTML, the inline script, the JavaScript files, the cookies and the data it passes to the front end. A string that starts withtryon_must not appear anywhere. Onlypk_…does. - [ ] Take the script address and the key only from our answer. Use
widget.script_urlandwidget.api_urlfrom theintegrationanswer, andkey.publishable_key. Do not take them from a setting the shop owner can type and do not build them yourself. The script is always loaded fromhttps://api.ziex-tryon.com/embed/; never copytryon-embed.jsto the shop's server, because the widget takes the API address from where its script came from. -
[ ] Initialise the widget with these options (all described in the Widget reference):
Option Value apiKeyThe publishable key, pk_….productImageThe product's main image, an https://URL.productTitleThe product's name. productUrlThe product's page address. categoryA category idfromGET /api/v1/tryon/capabilities(or thecapabilitiesblock of theintegrationanswer):tops,outerwear,bottoms,one-pieces, orautowhen the product cannot be mapped (unlessauto.availableisfalse). Do not hard-code the list: it grows.launcherfalse. The plugin draws its own button and callsTryOn.open().lockCategorytrue. The shop has chosen the category, the shopper is not asked.integration"<name>/<version>", for example"acme-cms/1.0.0". -
[ ] Pick up a try-on after a page change. Load the widget lazily, but load it at once on a page where the tab holds a try-on in progress, otherwise the shopper never sees the result. Use the loader's
ZiexTryOn.hasPending(pk)andZiexTryOn.load(); do not copy the slot rule. See Lazy loading and pickup. - [ ] Allow the widget in the page's Content-Security-Policy, if the shop sets one. See CSP. A plugin that adds inline script needs the platform's own nonce mechanism.
3. Check it with a test key¶
Do this on a development stand with a test key, which costs nothing. See Test keys and Local development.
- [ ] Verify the test key.
GET /api/v1/tryon/integrationwith a test secret key answerskey.mode: "test". On a local or staging hostsite.allowedistruewhen the host is allowed for the key. - [ ] Send one try-on from the server with an
Idempotency-Key, then pollGET /api/v1/tryon/status/{job_id}until it iscompleted. The photo must be an upload (a data URI). A repeat of the same request with the same key must answer200with the same job and create no second one. See Quickstart B. - [ ] Run the widget once on a page of the stand, with the test key's
pk_test_…: open the window, send a photo, reach the result. The window shows a "TEST" badge. - [ ] Verify the webhook signature on a delivery you captured. Register a
testendpoint, send a test try-on and checkX-TryOn-Signature-V2over the raw bytes of the body, with a stale-timestamp refusal. See Webhooks.
4. Tell the shopper¶
- [ ] Give the shop a privacy-policy paragraph. The shopper's photo is sent to the service, so the shop must say so. Show the owner the ready text from Privacy text for shops and tell them to add it to their policy.
- [ ] Handle errors by code, not by text. Show the shopper a plain message for each code and keep the raw text for your log. See Errors.
Examples to read¶
Two plugins are ready examples of this checklist:
- The WooCommerce plugin. The archive is
https://app.ziex-tryon.com/downloads/ziex-tryon-woocommerce.zip. - The 1C-Bitrix module. We hand the archive over directly; ask us.
When your plugin is ready, write to us (see Contact) with its name and the version label it sends.