# Products, templates and pricing

> What the public product catalog holds, how to request a template for a product, and how a unit price is computed.

The public product catalog is a Markdown document at `https://products.api.rpiprint.com/catalog/v1/products.md`. It is
unauthenticated and allows every origin. A second endpoint renders a template for a product the catalog lists. It is
described below.

## What the catalog holds

The catalog is one Markdown table listing the products available publicly, one row per product. A row shows the
product's options by their English names, its prices and its page-count bounds.

The header above the table states when the catalog was generated and the currency of its prices. It also states, once,
any option every product shares, rather than repeating that option as a column.

These columns need explaining:

- SKU holds the product's `manufacturingSku`, the identifier the template endpoint takes. The ordering API does not
  take it, because an order names a customer SKU, which a customer's own account defines.
- Product Class says what kind of product the row describes. Full Bleed and No Bleed are both book products, and they
  differ in how they handle bleed.
- Base price and Per-page price are amounts in the currency the header states, written with a `$` sign, such as
  `$12.60`. A product with no price in one of them shows `unpriced` in that column.
- Page counts gives the minimum page count, the maximum page count, and the step a page count has to be a multiple of.
  `20–502, step 2` allows 20, 22, 24 and so on up to 502.

## What a template is

A template is a product specification in a human-friendly format. Templates are available as a PDF, PNG, or IDML file.
Each template expresses the product specification as visual content.

Multiple products can share an exact specification and thus a template. For books, any rows with the same Product
Class, Cover Type, Text Paper Weight, Paper Finish and Trim Size have the same specification, and their templates are
interchangeable.

## Books

A book is a row whose Product Class is Full Bleed or No Bleed. A product of another class has different options.

Books that share a template can still differ in other columns, such as Cover Finish and Text Print Mode. Each of those
rows has its own base price and per-page price.

## Template requests

A template request names one `manufacturingSku`, one artifact and one format. It is a plain URL against an
unauthenticated endpoint, so a browser can fetch it directly.

```
GET https://products.api.rpiprint.com/templates/published/{manufacturingSku}/{artifact}/{format}
```

The artifact is `cover`, `jacket` or `pages`, and the format is `pdf`, `png` or `idml`. The Cover Type decides which
artifacts a product has. A Hardcover, Dust Jacket product has the `jacket` and `pages` artifacts, and every other
product has the `cover` and `pages` artifacts. The endpoint returns 404 for an artifact the product does not have.

A cover or jacket request takes `units`, `pageCount`, `barcode` and `productDescription`. A pages request takes
`units` and `pageCount`, and takes `side` as well when the format is `png`, because that format renders one page of the
spread rather than the whole book block.

`productDescription` is an English description of the product, such as the option names in its row. The renderers
print that string as a footer label on the template, and they omit the footer when it is unset.

The parameters `pageCount`, `barcode`, `units` and `side` do not change which product a request resolves to. They
change what the renderer draws for it.

The endpoint checks `pageCount` against the Page counts column only for cover and jacket requests. A cover or jacket
request whose `pageCount` is outside the Page counts range or off its step returns 404. A pages request renders any
`pageCount` from 1 to the product's maximum, so a pages template that renders does not show that its page count can be
ordered.

A rejected page count and an unrecognised `manufacturingSku` return the same response: 404 with the error
`Template not found`.

## How a price is computed

A product's unit price is its Base price plus its Per-page price for every page above the product's minimum page
count. The minimum is the first number in the Page counts column.

```
extraPages = max(0, pageCount - minimum page count)
unitPrice  = Base price + Per-page price * extraPages
```

The unit price is rounded to two decimal places. A value exactly halfway between two cents rounds to the even one. A
line total is the unit price multiplied by the quantity ordered.
