# Wix → Slant 3D integration

Customers buy on your Wix site; every paid order is automatically sent to Slant 3D
for printing and shipping. Two backend files, no server, no database:

```
Wix checkout → wixEcom_onOrderApproved (backend/events.js)
            → sendOrder (backend/slant3d.js): draft + process on Slant 3D API v2
            → Slant 3D prints & ships to the customer
```

API reference: https://slant3dapi.com/documentation (machine spec: https://slant3dapi.com/v2/api/openapi.json)

## One-time setup — Slant 3D side (slant3dapi.com dashboard)

1. Get an **API key** (starts with `sl-`).
2. Add a **payment method** to your account — processing an order charges you the print + shipping cost.
3. Create a **Platform** (your store's identity in their system) and copy its `platformId`.
4. Upload each product's STL (dashboard → Files, or `POST /files/direct-upload`) and copy each
   file's `publicFileServiceId`. Files uploaded through your Portals storefront may not appear
   under your API platform — re-upload them here if they don't.
5. Pick a `filamentId` per product from dashboard → Filaments (or call `getFilaments()`).

## One-time setup — Wix side

1. Wix Dashboard → **Developer Tools → Secrets Manager** → add secret `SLANT3D_API_KEY` = your `sl-...` key.
2. In the Wix Editor, enable **Dev Mode** (Velo). Under **Backend**, create `slant3d.js` and
   `events.js` and paste in the files from `backend/` here.
3. In `slant3d.js`, fill in `PLATFORM_ID` and the `PRODUCTS` map
   (Wix product **SKU** → `publicFileServiceId` + `filamentId`).
4. On each Wix Stores product, set the **SKU** to match its `PRODUCTS` key. Products without a
   mapped SKU (stickers, merch, …) are simply ignored by the integration.
5. Price check: run `estimateFilePrice(publicFileServiceId, { filamentId })` from a backend test —
   it returns your print cost so you can set Wix prices with margin (shipping is added per order).
6. **Publish** the site — backend events do not fire in Preview.

## Verify

1. Auth check (spends nothing): call `getFilaments()` from the Velo backend console — a filament
   list back means the key and secret wiring work.
2. End-to-end: place a small real order on the live site (use a 100% coupon to zero your own
   checkout; Slant still charges you the print cost — cheapest honest test). Then confirm:
   - Dashboard → Monitoring → Logs shows `Slant3D order SLANT_... processed for Wix order #...`
   - The order appears in your Slant 3D dashboard with the right file, filament, quantity, address.

If the forward fails, the error is in the same logs and the Wix order stays **Unfulfilled**, so
nothing is silently lost — fix and re-send via `sendOrder` or the Slant dashboard.

## Later (deliberately not built yet)

- **Tracking sync**: Slant platforms support webhooks (order status updates) — an
  `http-functions.js` receiver could mark the Wix order fulfilled with the tracking number so Wix
  emails the customer automatically. Add once v1 has processed real orders.
- CMS collection instead of the hardcoded `PRODUCTS` map — only if the catalog outgrows a screenful.
