=== Prodaxis Print Quote ===
Contributors: prodaxis
Tags: 3d-printing, catalog, materials, shortcode
Requires at least: 5.8
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.5.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

An STL upload-and-quote tool that fetches a company's 3D-print options from the Atom API gateway and returns an estimated price.

== Description ==

This plugin authenticates against the Atom API gateway with a per-company API key
and exposes the `[prodaxis_print_quote]` shortcode, which lets a visitor upload an
STL model, choose a material, color and template, and get an estimated print
price, time and filament length.

Because the gateway derives the company from the API key, one WordPress site
quotes against exactly one company's print options: whichever key you configure
under Settings -> Print Quote.

= How it works =

1. Every request to the gateway is sent server-side with an `X-API-Key` header
   carrying the configured key. The gateway resolves the key to its company and
   scopes the response accordingly.
2. It calls GET /print/options to read the company's materials, colors and
   templates.
3. The result is cached (configurable lifetime) and used to populate the quote
   tool's material, color and template controls.

The API key never reaches the browser — all requests happen on the WordPress
server.

== External service ==

This plugin is an interface to the Prodaxis (Atom) API gateway, a third-party
service that holds your company's 3D-print materials and performs the price
calculations. The plugin has no use without access to that service, and no data
is sent anywhere until you configure the gateway URL and an API key under
Settings -> Print Quote.

Once configured, when a visitor requests a quote the plugin sends the following
to the gateway URL you configured, server-side (never from the visitor's
browser):

* the uploaded STL model,
* the selected material, color and template,
* your company API key, as the `X-API-Key` request header.

The gateway returns the estimated price, print time and filament length. The
uploaded model and selections are transmitted to your configured gateway solely
to produce the quote.

* Service provider: Prodaxis — https://prodaxis.io/
* Terms of Service: https://www.prodaxis.io/legal/terms
* Privacy Policy: https://www.prodaxis.io/legal/privacy

== Installation ==

1. Copy the `prodaxis-print-quote` folder into `wp-content/plugins/`.
2. Activate "Prodaxis Print Quote" in Plugins.
3. Go to Settings -> Print Quote and set:
   - API Gateway base URL (e.g. http://host.docker.internal:8086 when WordPress
     runs in Docker; the gateway is on the host, not inside the container)
   - API key (generate it in your company dashboard under Settings -> API; it is
     shown in full only once, so copy it then)
   - Cache lifetime in seconds (default 300)
   - SSL verification (disable only for local self-signed certificates)
4. Add `[prodaxis_print_quote]` to any page or post.

== Shortcode ==

`[prodaxis_print_quote]`

Renders an interactive quote tool. A visitor:

1. Uploads an STL model.
2. Picks a material, then a color and template available for that material
   (the dropdowns are built from the same /print/options catalog).
3. Clicks "Calculate price" to get an estimated price, print time and filament
   length.

The browser never talks to the gateway directly. The file and selections are
sent to WordPress (admin-ajax), which proxies them server-side using the same
cached service-account token:

* POST /slicer/upload         - uploads the STL and returns its print reference.
* POST /print/calculate/async - starts the calculation and returns immediately
  with a calculationId (status IN_PROGRESS); slicing runs in the background.
* GET  /calculation/{id}      - polled until the status becomes COMPLETED (with
  the price, print time and filament length) or FAILED.

Because slicing is asynchronous, the widget shows a "calculating" state and
polls every couple of seconds, giving up after about three minutes.

Changing the material and recalculating reuses the already-uploaded file;
choosing a different file re-uploads. Requests are protected with a WordPress
nonce.

Optional attributes:

* `accent`         - hex accent color for the widget (default `#1976d2`)
* `template_style` - `cards` (default) or `compact` template selector
* `powered_by`     - brand shown in the footer line; omitted hides it

Example: `[prodaxis_print_quote accent="#0f9d6b" template_style="compact"]`

== Notes ==

* The WordPress server must be able to reach the API gateway URL. `localhost`
  works only when WordPress runs on the same machine as the gateway; inside a
  Docker container use `http://host.docker.internal:8086` instead, since
  `localhost` there points at the container, not the host.
* The API key is stored in the WordPress options table and sent as the
  `X-API-Key` header. It is scoped to one company and limited to the print
  read/quote operations the widget needs; if it leaks, regenerate it in the
  company dashboard (which immediately invalidates the old one).
* STL upload size is bounded by two limits: PHP's `upload_max_filesize` /
  `post_max_size` on the WordPress server (raise these for large models) and the
  gateway's authoritative per-company limit, which is enforced server-side.

== Third-party libraries ==

The print-quote widget's 3D preview is powered by Three.js (r185 / 0.185.0),
bundled locally under `assets/js/vendor/` so the widget needs no external
requests:

* three.module.min.js, STLLoader.js, OrbitControls.js — Three.js r185, MIT
  license, Copyright Three.js Authors.
  Source: https://github.com/mrdoob/three.js/tree/r185

These are loaded as ES modules: the viewer script imports the bundled build and
its STLLoader / OrbitControls addons directly. The MIT license is
GPL-compatible. No other external scripts or services are loaded in the browser.

== Changelog ==

= 1.5.1 =
* Rename all PHP functions, classes, constants, the stored option, transients,
  the nonce and AJAX actions, and script handles to use the unique `prodprqu_`
  prefix, avoiding collisions with other plugins. Re-enter the API key under
  Settings -> Print Quote after updating.
* Update the bundled Three.js library from r128 to r185 and load the 3D preview
  as an ES module (the modern build is ESM-only).
* Document the external Prodaxis (Atom) API gateway service, the data sent to
  it, and links to its Terms of Service and Privacy Policy.

= 1.5.0 =
* Authenticate with a per-company API key (sent as the `X-API-Key` header)
  instead of a service-account e-mail and password. Removes the server-side
  login step and token caching. Configure the key under Settings -> Print
  Quote; generate it in your company dashboard (Settings -> API).

= 1.4.0 =
* Remove the `[company_print_catalog]` catalog shortcode and its assets. The
  plugin now focuses solely on the `[prodaxis_print_quote]` tool. The print
  options are still fetched from /print/options to populate the quote controls.

= 1.3.0 =
* Add an interactive 3D preview of the uploaded STL above the upload step
  (Three.js, bundled locally): the model auto-rotates, can be orbited and
  zoomed, and is tinted live by the selected color. Degrades to a small
  "3D preview unavailable" notice where WebGL or Three.js is missing.

= 1.2.0 =
* Redesign the `[prodaxis_print_quote]` widget: a single card with a drag-and-drop
  upload zone, a custom material picker, color swatches, quality-template cards
  and an animated price result. New optional shortcode attributes `accent`,
  `template_style` and `powered_by`.

= 1.1.1 =
* Fix: the quote widget now embeds its configuration inline in the shortcode
  markup, so the material list populates reliably regardless of how the theme or
  page builder prints scripts.

= 1.1.0 =
* Add the `[prodaxis_print_quote]` shortcode: upload an STL, pick a material,
  color and template, and get an asynchronous price calculation. Files and
  selections are proxied server-side (POST /slicer/upload, POST
  /print/calculate/async) and the result is polled (GET /calculation/{id}) until
  it completes or fails. Requests are protected with a WordPress nonce.

= 1.0.0 =
* Initial release: shortcode, admin settings, server-side auth with token and
  catalog caching, material/color/template cards with expandable details.
