# Recipe 6: sell ebooks direct

For an agent helping an author sell their ebooks and audiobooks from their own site on Beautiful
(beautiful.site), so readers pay the author instead of a retailer. It builds on the site from
recipe 1 (https://beautiful.site/recipes/authors/website.md). Read https://beautiful.site/llms.txt
first.

Beautiful never takes payments. A store service does (Payhip, Shopify, Gumroad), and delivers the
book. The site puts "Buy direct" first on every book, has a shop page, and opens the checkout on
the site itself where the store allows it.

## 1. What the author gets

- "Buy the ebook direct · $4.99" as the first button on each book they sell, before the
  retailers.
- A shop page (`/shop/`): every book they sell direct, the bundles, and a line on why buying
  direct helps (in their words).
- Checkout and delivery handled by their store: the reader pays, gets the book on any device, and
  the author keeps 90% or more of the price instead of 35 to 70%.
- Tax worked out by the store as far as it can (section 4 says which does what).
- Bundles (the whole series for one price) and discount codes for the newsletter.

## 2. Before you start

- **Recipe 1 is done**: the book schema already has `direct.ebook` and `direct.ebookPrice`, and
  the buy buttons put them first.
- **The author needs a store account.** You can't make it for them: it holds their bank details.
  Section 4 says which, and walks them through it.
- **The ebook files** (EPUB, and PDF if they like; MP3s or M4B for audiobooks) go into the
  store, not the site. Never put a book file in `public/`: anyone could download it.
- **Works on any plan**, trials included: there's no server code. The store does the selling.
- **Time**: about an hour of the author's time for the store, most of it uploading books and
  setting prices; ten minutes of yours after.

## 3. Talk to the author

Ask in one message:

> Let's set up selling direct. A few questions:
>
> 1. Which books do you want to sell direct: all of them, or some? Ebooks only, or audiobooks too?
> 2. The price for each. (Most authors match or go just under their retailer price.)
> 3. Do you already have a store: Payhip, Shopify, Gumroad, a WooCommerce site, or anything
>    else? Do you use BookFunnel?
> 4. Any bundles: a whole series as a box set, at one price?
> 5. Why should a reader buy from you rather than Amazon? In your words: "you get it a week
>    early", "more of the money reaches me", a bonus scene. One or two sentences, or skip it.
> 6. Do you sell signed paperbacks too, or want to? (That's recipe 7; it shares the store.)

| Question | Why | Default |
| --- | --- | --- |
| Which books | The buttons and the shop page | All of their ebooks |
| Price | `direct.ebookPrice`, the shop page | Ask: never guess a price |
| A store already | Section 4 | Payhip |
| Bundles | The shop page | None |
| Why direct | The shop page's first line | No line: never write their pitch |
| Signed paperbacks | Pick a store that does both | Payhip (it does physical products too) |

Don't advise on tax or the law. When they ask, say what the store does (section 4) and suggest
their accountant for the rest.

## 4. Pick the service

| The author | Pick | Why |
| --- | --- | --- |
| Has nothing yet, or isn't sure | **Payhip** | Free to start (Payhip takes 5% on the free plan, less on paid ones, plus the card fee). Charges the right EU and UK VAT on ebooks. Delivers the file itself, or through BookFunnel. Its checkout opens over the author's own page |
| Already has Shopify | **Shopify** with BookFunnel's Shopify integration | Keep one store. Tax is set up in Shopify, and is the author's to file |
| Already sells on Gumroad | **Gumroad** | Gumroad is the seller of record: it charges and pays the sales tax and VAT itself |
| Has WooCommerce on an old site | Move to Payhip | Their old site is going away (recipe 14). WooCommerce needs a WordPress host |
| Asks about Stripe | Payhip or Gumroad | A bare Stripe Payment Link has no delivery and leaves all tax to them. Use it only if they already run Stripe with a delivery they trust |

Check prices and fees on the store's own page before quoting them: they change.

**Delivery: BookFunnel or the store's own.** Payhip and Gumroad email a download link themselves.
BookFunnel is better when the author has it (it puts the book on any reader's device, and
answers "how do I get this onto my Kindle?" so the author doesn't have to). It plugs into Payhip
and Shopify: in BookFunnel, Integrations, add the store, then link each product to its book.

### Payhip, step by step for the author

Send these as they are:

1. Sign up at https://payhip.com, then Settings, Payouts: add Stripe or PayPal (or both) so you
   get paid.
2. Settings, Taxes: turn on EU VAT and UK VAT for digital products.
3. Products, Add product, Digital product, for each book: the title, the price, the cover, a
   short description (the blurb), and upload the EPUB (and PDF). For BookFunnel delivery, upload
   nothing and link it in BookFunnel instead.
4. Each product has a link like `https://payhip.com/b/AbC12`. Send me every book's link.
5. Bundles: Products, Add product, Bundle, pick the books, set the price. Send me its link.

### Shopify

1. Products, Add product for each book (no shipping: "This is a physical product" off), price,
   and the cover.
2. In BookFunnel: Integrations, Shopify, connect, then link each product to its book.
3. Send me each product's link (`https://<store>.myshopify.com/products/<handle>`, or its own
   domain).

### Gumroad

1. Sign up, then New product, E-book, for each book: price, cover, the file.
2. Send me each product's link (`https://<name>.gumroad.com/l/<id>`).

## 5. How it works

```
src/content/books/<id>.md         direct.ebook: the product link; direct.ebookPrice: "$4.99"
src/data/shop.json                the store, the overlay on or off, the author's "why direct", the bundles
src/pages/shop.astro              /shop/: why direct, every book sold direct, then the bundles
src/components/Checkout.astro     in the layout: turns Payhip links into its on-page checkout
```

The buttons are plain links to the store. With Payhip, `Checkout.astro` marks every Payhip link on
the page and loads Payhip's own script, which opens the checkout over the page instead of
leaving the site. If Payhip's script doesn't load (an ad blocker, a slow phone), the link still
goes to the Payhip page and the reader buys there. So the button never stops working.

## 6. Build it

1. Copy the files below. In `src/data/shop.json`, set `store`, the author's `why` exactly as they
   wrote it (or `""`), and the bundles.
2. For each book sold direct, add to its front matter (each book is an entry: `edit_post` with `track_changes: false` and `save: true`, then `publish_post`):

   ```yaml
   direct:
     ebook: https://payhip.com/b/AbC12
     ebookPrice: $4.99
   ```

   Keep `direct.signed` if recipe 7 set it.
3. `src/layouts/Base.astro`: add `import Checkout from "../components/Checkout.astro";` to its
   imports, and `<Checkout />` on the line before `</body>`.
4. Add `{ "label": "Shop", "href": "/shop/" }` to `nav` in `src/data/site.json`.
5. Bundle covers go in `public/covers/` like the books'.
6. Publish, and test (section 7).

### src/data/shop.json

```json
{
  "store": "payhip",
  "overlay": true,
  "why": "Buying here means more of the money reaches me, and you get each new book a week before the stores.",
  "bundles": [
    {
      "title": "The Saltwater Bay Collection",
      "books": ["the-tide-house", "salt-and-honey"],
      "price": "$9.99",
      "url": "https://payhip.com/b/Bndl1",
      "cover": "/covers/the-tide-house.jpg"
    }
  ]
}
```

- `store`: `payhip`, `shopify`, `gumroad` or `other`. Only `payhip` changes anything (the
  overlay).
- `overlay`: `false` sends readers to the Payhip page instead of opening the checkout on the site.
- `bundles[].books`: book ids, in reading order; the shop page lists their titles.

### src/components/Checkout.astro

```astro
---
// Payhip's on-page checkout (recipe 6): every link to a Payhip product opens the checkout over
// the page. Without Payhip's script the links still go to Payhip, so nothing breaks.
import shop from "../data/shop.json";
const on = shop.store === "payhip" && shop.overlay;
---
{on && (
  <script is:inline>
    (() => {
      const links = document.querySelectorAll('a[href^="https://payhip.com/b/"]');
      if (!links.length) return;
      for (const a of links) {
        a.classList.add("payhip-buy-button");
        a.dataset.product = a.getAttribute("href").split("/b/")[1].split(/[?#/]/)[0];
        a.dataset.theme = "none";
      }
      const s = document.createElement("script");
      s.src = "https://payhip.com/payhip.js";
      s.async = true;
      document.body.append(s);
    })();
  </script>
)}
```

### src/pages/shop.astro

```astro
---
// The author's own shop (recipe 6): every book sold direct, then the bundles. The store does
// the selling; these are links to it.
import Base from "../layouts/Base.astro";
import site from "../data/site.json";
import shop from "../data/shop.json";
import { allBooks } from "../utils/books";
const all = await allBooks();
const books = all.filter((b) => b.data.direct.ebook && b.data.status !== "announced");
const title = (id: string) => all.find((b) => b.id === id)?.data.title ?? id;
---
<Base title="Shop" description={`Buy ${site.name}'s books direct.`}>
  <section class="section">
    <h1>Buy direct</h1>
    {shop.why && <p class="lead">{shop.why}</p>}
    <ul class="shop">
      {books.map((b) => (
        <li>
          <a href={`/books/${b.id}/`}><img src={b.data.cover} alt={b.data.coverAlt ?? `The cover of ${b.data.title}`} width="160" height="240" loading="lazy" /></a>
          <h2><a href={`/books/${b.id}/`}>{b.data.title}</a></h2>
          <p><a class="button primary" href={b.data.direct.ebook}>{b.data.status === "preorder" ? "Preorder" : "Buy"} the ebook{b.data.direct.ebookPrice && ` · ${b.data.direct.ebookPrice}`}</a></p>
        </li>
      ))}
    </ul>
  </section>
  {shop.bundles.length > 0 && (
    <section class="section">
      <h2>Bundles</h2>
      <ul class="shop">
        {shop.bundles.map((x) => (
          <li>
            {x.cover && <img src={x.cover} alt={`The cover of ${x.title}`} width="160" height="240" loading="lazy" />}
            <h2>{x.title}</h2>
            <p class="muted">{x.books.map(title).join(", ")}</p>
            <p><a class="button primary" href={x.url}>Buy the bundle · {x.price}</a></p>
          </li>
        ))}
      </ul>
    </section>
  )}
  <p class="muted">Ebooks are delivered by email the moment you buy, and work on Kindle, Kobo, Apple Books, Nook and any phone. Questions about an order? Write to {site.contact}.</p>
</Base>
<style>
  .shop { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 32px; }
  .shop img { border-radius: 4px; box-shadow: 0 8px 20px rgb(0 0 0 / 0.16); height: auto; max-width: 100%; }
  .shop h2 { font-size: 1.1rem; margin: 12px 0 4px; }
</style>
```

Rewrite the shop's markup for the site's design direction like the other pages, keeping the
links and prices.

## 7. Test it

1. `/shop/` and two book pages at desktop and phone width (`screenshot`): "Buy the ebook direct ·
   $4.99" is the first button on each book sold direct, the retailers follow, the shop lists
   every book you set `direct.ebook` on, the bundles have their titles and prices, and the
   author's `why` is word for word.
2. Every product link: open it (curl `-sI`, or `screenshot`) and check it's that book, at that
   price. A wrong link sells the wrong book.
3. Payhip with `overlay: true`: `screenshot` a book page, then in a browser click "Buy direct":
   Payhip's checkout opens over the page. If you can't click in a browser, ask the author to try
   it once.
4. Ask the author to make one real purchase themselves (Payhip lets them refund it after, or set
   a 100% coupon): the book arrives by email or BookFunnel, and opens on their phone.

## 8. Hand it over

> Your books are on sale direct from your site: "Buy direct" is the first button on [n] books,
> and your shop is at [url]/shop/. Readers pay through [store], which delivers the book [itself /
> through BookFunnel] and [handles EU and UK VAT / is the seller of record and handles the tax].
> You keep about [x]% of each sale.
>
> Your sales and payouts are in [store]'s dashboard. When you add a book, change a price, or make
> a coupon for your newsletter, send me the link or the code and I'll update the site.

## 9. Keep it running

- **A new book.** The author makes the product and sends the link; add `direct` to its front
  matter. On preorder, Payhip can sell it before the file exists only if the author uploads a
  placeholder; better to add `direct` on release day (with recipe 8's launch release).
- **A price change.** The store's price is the one readers pay. Change `ebookPrice` in the same
  minute, or readers see two prices. Sales on the site go with recipe 8's `sale`.
- **A coupon for the newsletter.** The author makes it in the store (Payhip: Coupons). A link that
  applies it: Payhip `https://payhip.com/b/AbC12?coupon=CODE`. Give them that link for their email;
  the site doesn't change.
- **"How many did I sell?"** The store's dashboard; the site doesn't see sales. Authors who sell
  in many places use ScribeCount, which reads Payhip and BookFunnel.
- **Stopping direct sales for a book.** Remove `direct` from its front matter; the retailers'
  buttons stay.

## 10. When it goes wrong

| What you see | Why | Fix |
| --- | --- | --- |
| "Buy direct" opens the Payhip page, not the checkout over the page | Payhip's script blocked (ad blocker) or `overlay: false` | Nothing to fix: the page works. Check `overlay` in `shop.json` |
| The overlay opens with the wrong book | The link's product code is another book's | Fix `direct.ebook` in that book's front matter |
| A reader paid and got no book | Delivery not linked (BookFunnel) or no file uploaded | Author: in the store, the product's file; in BookFunnel, Integrations, the product's book |
| The book isn't on the shop page | `direct.ebook` missing, or the book is `announced` | Add the link; announced books show once they're on preorder |
| Two prices for one book | The store's price changed and `ebookPrice` didn't | Set `ebookPrice` to the store's |
| `template_error` in `shop.astro` | `shop.json` is missing `bundles` or `why` | Every key above is needed (`[]` and `""` are fine) |
