# PromptSwing — connecting a store you built elsewhere

*Generated 2026-10-09T14:26:54.895Z from `static/signals.js` (sha256 ef39919d7937). Do not edit; edit the library or `scripts/gen-signal-spec.mjs`.*

This page is for the assistant or builder that wrote the store — Claude, Claude Code, Lovable, v0, Bolt, Replit — and for a developer doing it by hand. Follow it and the store is hosted, takes payment to the merchant's own processor, recovers abandoned carts, requests reviews, and reports to the merchant's dashboard. Skip any part of it and that part of PromptSwing stays dark for this store.

## What PromptSwing does for you at deploy — do NOT do these yourself

1. Loads the signal library into the page: `<script src="https://api.promptswing.com/signals.js">`
2. Calls `PromptSwingSignals.init({ token })` with this merchant's own token.
3. Sets `window.__PS_MERCHANT_ID__` to this merchant's numeric id.

Never add the script tag, never call `init`, never hardcode a token or a merchant id. Read `window.__PS_MERCHANT_ID__` **at call time** (inside the function that needs it), not at module load — the page's own scripts may run first.

## Products: read them from PromptSwing, never write them into the page

`GET /api/hosting/storefront/products/{merchantId}` — same-origin on the store's own domain. Returns the merchant's catalogue as the merchant maintains it in their dashboard. **A page that prints its own product list or its own prices is out of contract:** the merchant edits their catalogue in PromptSwing, and a hardcoded page will not follow.

### Product photographs: one square, contained, on white

How PromptSwing's own stores show a product picture, and what `assess_site` looks for on yours. **The photo is shown WHOLE — a 1:1 box, `object-fit: contain`, on flat white `#FFFFFF`** — never `cover`. A merchant photographs a bag of food in portrait on a shop counter; cropping it to fill a wide box takes off the top, which is the half carrying the brand and the weight. Contain letterboxes instead, and white is the ground that shows a product the way every marketplace does. **Every card in a catalogue is then the same size**, which needs the grid's rows equalised and the product name clamped, not only the photo squared. A product with no photo gets the same square, marked as pending — never a picture it does not have.

This is a report, never a refusal: your page is yours. `assess_site` says so when it cannot find a contained square, because a cropped catalogue is the most common reason a merchant's own photographs look wrong on their own shop.

### Categories: the store's own structure, two levels deep

`GET /api/hosting/storefront/categories/{merchantId}` — the categories the merchant has typed on their products, alphabetical, each with its sub-categories: `{ ok, categories: [{ key, name, count, children: [{ key, name, count, children: [] }] }] }`. **There is no category list to configure** — a category exists because a product carries it, and it stops existing when the last one does. A parent's `count` is every product in that category, sub-categorised or not, so **children do not sum to their parent** — the category page still shows them all.

Read this rather than inventing a menu: a category the merchant types today should appear without the store being rebuilt. Narrow the product feed with `?category=` and, one level down, `?category=&subcategory=` — a sub-category without its category is refused. Depth is **two and only two**.

### The front page: read its sections, never pick products in the page

`GET /api/hosting/storefront/sections/{merchantId}` — the store's front-page sections, switched on by the merchant, in their order: `{ ok, sections: [{ key, title, kind, products: [...] }] }`. Every store has **Best sellers** (`best-sellers`, counted from real sales), **On sale** (`on-sale`), **Promotion** (`promotion`) and **Recommended** (`recommended`, the merchant's picks), and may add its own. Render each section in the order given, under its `title`. A section that is switched off or empty is not in the answer — render nothing for it. **An empty `sections` list is a valid front page.** Optional `?limit=` (1–100) caps products per section.

**Changing the sections from the repository — `promptswing.json`.** A store released from GitHub has no connector, so its sections can be set by a `promptswing.json` file at the repository root, read on every successful release:

```json
{ "sections": [
  { "key": "recommended", "title": "Staff picks", "enabled": true, "position": 1, "products": [541, 542] },
  { "key": "new-season", "title": "New season", "products": [543] },
  { "key": "old-promo", "delete": true }
] }
```

Each entry sets values for one section key: `title` (1–80 characters), `enabled`, `position` (lowest first), and `products` — product ids from the store's product feed, which REPLACE that section's products in that order (up to 500). A key the store does not have is created and needs a `title`. `delete: true` removes a section the merchant added; **Best sellers, On sale, Promotion and Recommended cannot be deleted — set `enabled: false`.** Nothing can be placed on `best-sellers`. **A section the file does not list is left alone**, and deleting the file changes nothing. The file is applied whole or not at all, and **only when it changed since the last file applied**, so a push that does not touch it never undoes a change the merchant made on the dashboard. What became of it is on the commit's GitHub Deployment: *Sections applied.* or *promptswing.json refused: <reason>.* A bad file never blocks the release.

The product feed also takes `?section=`, `?category=`, `?subcategory=`, `?limit=` and `?sort=best-selling`. **A front page that prints the whole catalogue, or hand-picks products in its own code, will not follow the merchant's switches** — PromptSwing reports it on every release.

`GET /api/hosting/storefront/reviews/{merchantId}` — the store's reviews and average, already filtered to what a shopper may see.

## Payment

`POST https://api.promptswing.com/api/payments/public/create-intent` — **absolute URL, cross-origin** (this endpoint lives on the API host, not on the store's domain; it allows any origin). Body: `{ merchantId, amount, currency, items, customerEmail }`.

- **`amount` is in MAJOR units — dollars, not cents.** Send `42` for $42.00; the server converts. Sending cents charges one hundred times too much.
- `merchantId` is `window.__PS_MERCHANT_ID__`. `currency` is a three-letter code (`'usd'`). `items` is the array below.
- Returns `{ ok, clientSecret, connectedAccountId, publishableKey, paymentIntentId }`. Initialise the processor's browser SDK with `publishableKey` **and** `connectedAccountId` (the charge settles to the merchant's own account), then confirm with `clientSecret`.
- **For the merchant's Profit reading — optional, never needed to take a payment.** Give each `items` entry `id` (the catalogue product id) and `quantity` beside `name` and `price`, and send `shippingCharged`: what the shopper pays for shipping in major units, `0` when nothing ships, `null` when no carrier rate was quoted. After the payment is confirmed, send the returned `paymentIntentId` with the order as `orderPlaced`'s last argument, `{ payment_reference: paymentIntentId }`. A payment sent without them still goes through; its profit is reported as not matched, never estimated.
- PromptSwing never holds card data and is never the merchant of record.

## The five signal calls — exact signatures, positional

The library takes **positional arguments in this order**. It does not accept an options object. Pass `null` for a value you do not have; never pass an object as the first argument.

### `PromptSwingSignals.cartUpdated(items, totalAmount, customerEmail, currency, meta)`

- **Sends to:** `/api/events/cart`
- **Feeds:** abandoned cart recovery
- **When:** Every time the cart changes — an item added, removed, or its quantity changed. Pass the customer email as soon as you have it (a checkout form field, a login); a cart with no email can never be recovered.

### `PromptSwingSignals.cartAbandoned(customerEmail, totalAmount, currency, meta)`

- **Sends to:** `/api/events/cart`
- **Feeds:** abandoned cart recovery
- **When:** Optional. PromptSwing ages carts on the server and decides abandonment itself, so most sites never call this. Call it only if you have a stronger signal than time — an explicit "leave checkout" action.

### `PromptSwingSignals.checkoutStarted(checkoutId, items, totalAmount, customerEmail, currency, meta)`

- **Sends to:** `/api/events/checkout`
- **Feeds:** checkout intelligence, and it marks the cart as converted
- **When:** The moment the shopper begins paying — the checkout page opens, or the pay button is first pressed. Use one checkoutId per attempt and pass the same id to checkoutResult.

### `PromptSwingSignals.checkoutResult(checkoutId, succeeded, gateway, declineReason, totalAmount, currency, customerEmail)`

- **Sends to:** `/api/events/checkout`
- **Feeds:** checkout intelligence (failed payments, declines)
- **When:** When the payment attempt finishes, whether it succeeded or failed. succeeded MUST be a boolean — an omitted value is recorded as a failure.

### `PromptSwingSignals.orderPlaced(orderId, status, totalAmount, currency, customerEmail, lineItems, meta)`

- **Sends to:** `/api/events/order`
- **Feeds:** customer reviews (the review request is sent from this), the Intelligence Suite, and the Intelligence Agent
- **When:** Once, after the payment has succeeded and you have an order id. This is the single most important call: without it no review is ever requested and no revenue is ever seen.


### The minimum that makes every tool work

```js
// when the cart changes
window.PromptSwingSignals?.cartUpdated(items, totalAmount, customerEmail, 'USD', null)
// when paying begins
window.PromptSwingSignals?.checkoutStarted(checkoutId, items, totalAmount, customerEmail, 'USD', null)
// when the payment attempt ends
window.PromptSwingSignals?.checkoutResult(checkoutId, succeeded, 'stripe', declineReason, totalAmount, 'USD', customerEmail)
// after payment succeeds
window.PromptSwingSignals?.orderPlaced(orderId, 'paid', totalAmount, 'USD', customerEmail, lineItems, null)
```

`items` / `lineItems` is an **array** of `{ id, name, price, quantity }`. `totalAmount` is a **number**. `customerEmail` is a **string or null**. `succeeded` is a **boolean**.

## How you know it worked

The merchant's hosting dashboard shows one of three states for this store: *never heard*, *heard, and when*, or *heard but malformed*. The third means the calls arrived with the wrong shape — an object where an array was expected, a missing email, a total of zero — and nothing downstream will run until it is fixed.
