Bundles and gift vouchers: codes booked later, confirm without paying #7

Merged
reudy merged 5 commits from bundles-vouchers into main 2026-10-26 09:30:41 +01:00
Member

Why

The studio wants to sell bundles (e.g. 3 massages + a bottle of oil for one price) and gift vouchers that are paid now and booked later. A voucher for one service is just a bundle with one part. There are no customer accounts, so the buyer gets a code: whoever has it books the included sessions without paying again, until it expires.

How it works

  • Bundle = new item type with a price, parts (a service at a set length × count, or a product × count) and validity in months. It's edited under Services & products.
  • Buying works like a product. Stock for products inside the bundle is checked and taken with the order. A bundle in the basket can be marked as a gift (for + message). After payment each bundle becomes a pass with an 8-character code (ABCD-2345, no 0/O/1/I), shown on the result page and in the confirmation email.
  • Redeeming: the customer types the code in the basket. It covers bookings of the same service and length while places are left. Covered lines cost 0. If nothing is left to pay, the button becomes Confirm booking and no Stripe step happens. The order is created directly, and its result page is only shown to that basket's cookie.
  • Counting: a code's used places are its order lines (not refunded) plus live basket holds, the same idea as slot availability. No counter is stored, so a refund gives the place back, and two people can't use the last place at once.
  • Price split: each part's share of the bundle price (in proportion to what the parts cost on their own) is snapshotted on the pass, for partial refunds.
  • Admin, Vouchers & codes: search; used / in a basket / left per part; void or reactivate; change or remove the expiry; issue a code without a purchase. Orders show the codes bought and the bookings paid with a code.
  • GDPR: passes hold the buyer's email and possibly a recipient's name and message. Export, correction and erasure cover them (erasure keeps the code working). Retention anonymises a pass with the orders once it's expired or used up. The privacy policy draft has a line for vouchers.

Also fixed (was broken on main)

PocketBase 0.23 can't store an empty number; it reads back as 0. So:

  • Products saved with "unlimited" stock were sold out. New items.trackStock flag. The migration turns it on for existing products, so nothing that sells today changes. To make a product unlimited, clear its stock field in the admin.
  • orders.total, orders.stripePaymentIntentId and order_lines.price were required, and PocketBase treats 0 / '' as blank. They are now optional: a code-paid booking costs 0 and has no payment.

Tested

  • Migration from merged main (with existing orders and products) and fresh install (pb_schema.json import, which has a passes ↔ orders ↔ baskets relation loop) both work.
  • 38 API checks against PocketBase 0.23.12 + stripe-mock, all passing:
    • buying (price split, gift, stock incl. products inside bundles, webhook → pass, expiry);
    • redeeming (case/dash-insensitive code, partial cover, wrong length not covered, mixed basket pays the rest, free checkout, result-page access);
    • running out across baskets; void and expiry (incl. voided after it was applied → bookings uncovered at checkout);
    • admin list, auth and issue; refund returning a place; GDPR export and erasure; unlimited products.
  • The 46 time-window scenarios from #6 still pass.
  • Browser (Playwright, built images):
    • admin creates a bundle; shop card; add as gift (kept after reload);
    • purchase through the public app's real webhook route, with the email (logged) showing the code, recipient, message, parts and validity;
    • a second visitor books a massage, applies the code (€80 → €0, "2 left"), presses Confirm booking, and the result page and email show "Paid with code";
    • admin codes page, issue, void, and orders showing codes.
  • svelte-check: 0 errors in both apps. The 18 + 3 warnings were already there before this change.

Not tested: a real Stripe payment in the browser (stripe-mock can't run the Payment Element), real email sending, mobile layouts.

Deploying

The migration runs on the next PocketBase start. Back up pb_data first. Then set up bundles under Services & products. Check which products should be unlimited: they keep enforcing their stock number until it's cleared.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW

## Why The studio wants to sell **bundles** (e.g. 3 massages + a bottle of oil for one price) and **gift vouchers** that are paid now and booked later. A voucher for one service is just a bundle with one part. There are no customer accounts, so the buyer gets a **code**: whoever has it books the included sessions without paying again, until it expires. ## How it works - **Bundle** = new item type with a price, parts (a service at a set length × count, or a product × count) and validity in months. It's edited under *Services & products*. - **Buying** works like a product. Stock for products inside the bundle is checked and taken with the order. A bundle in the basket can be marked as a gift (*for* + message). After payment each bundle becomes a **pass** with an 8-character code (`ABCD-2345`, no 0/O/1/I), shown on the result page and in the confirmation email. - **Redeeming**: the customer types the code in the basket. It covers bookings of the same service **and** length while places are left. Covered lines cost 0. If nothing is left to pay, the button becomes **Confirm booking** and no Stripe step happens. The order is created directly, and its result page is only shown to that basket's cookie. - **Counting**: a code's used places are its order lines (not refunded) plus live basket holds, the same idea as slot availability. No counter is stored, so a refund gives the place back, and two people can't use the last place at once. - **Price split**: each part's share of the bundle price (in proportion to what the parts cost on their own) is snapshotted on the pass, for partial refunds. - **Admin, *Vouchers & codes***: search; used / in a basket / left per part; void or reactivate; change or remove the expiry; issue a code without a purchase. Orders show the codes bought and the bookings paid with a code. - **GDPR**: passes hold the buyer's email and possibly a recipient's name and message. Export, correction and erasure cover them (erasure keeps the code working). Retention anonymises a pass with the orders once it's expired or used up. The privacy policy draft has a line for vouchers. ## Also fixed (was broken on `main`) PocketBase 0.23 can't store an empty number; it reads back as 0. So: - **Products saved with "unlimited" stock were sold out.** New `items.trackStock` flag. The migration turns it **on** for existing products, so nothing that sells today changes. To make a product unlimited, clear its stock field in the admin. - `orders.total`, `orders.stripePaymentIntentId` and `order_lines.price` were required, and PocketBase treats 0 / '' as blank. They are now optional: a code-paid booking costs 0 and has no payment. ## Tested - Migration from merged `main` (with existing orders and products) and fresh install (`pb_schema.json` import, which has a passes ↔ orders ↔ baskets relation loop) both work. - 38 API checks against PocketBase 0.23.12 + stripe-mock, all passing: - buying (price split, gift, stock incl. products inside bundles, webhook → pass, expiry); - redeeming (case/dash-insensitive code, partial cover, wrong length not covered, mixed basket pays the rest, free checkout, result-page access); - running out across baskets; void and expiry (incl. voided after it was applied → bookings uncovered at checkout); - admin list, auth and issue; refund returning a place; GDPR export and erasure; unlimited products. - The 46 time-window scenarios from #6 still pass. - Browser (Playwright, built images): - admin creates a bundle; shop card; add as gift (kept after reload); - purchase through the public app's real webhook route, with the email (logged) showing the code, recipient, message, parts and validity; - a second visitor books a massage, applies the code (€80 → €0, "2 left"), presses **Confirm booking**, and the result page and email show "Paid with code"; - admin codes page, issue, void, and orders showing codes. - `svelte-check`: 0 errors in both apps. The 18 + 3 warnings were already there before this change. **Not tested:** a real Stripe payment in the browser (stripe-mock can't run the Payment Element), real email sending, mobile layouts. ## Deploying The migration runs on the next PocketBase start. Back up `pb_data` first. Then set up bundles under *Services & products*. Check which products should be unlimited: they keep enforcing their stock number until it's cleared. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
agent added 5 commits 2026-10-25 22:40:13 +01:00
A bundle (items.type `bundle`) has its own price, parts (a service at a
length × count, or a product × count) and a validity in months. Buying one
creates a pass with an 8-character code; its parts are snapshotted with
their share of the price. Applying a code to a basket covers matching
bookings (same service and length) while places are left — counted from
order lines and live holds, never stored. A fully covered basket is
confirmed without Stripe.

Admin routes list, void/extend and issue codes; GDPR export, correction,
erasure and retention cover passes (erasure keeps the code working).

orders.total, orders.stripePaymentIntentId and order_lines.price are no
longer required: PocketBase treats 0 / '' as blank, and a code-paid order
has neither a payment nor a price.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
PocketBase 0.23 can't store an empty number (it reads back as 0), so a
product saved with "Unlimited when empty" stock was sold out — on main
too. trackStock says whether stock counts; existing products get it on,
so nothing that sells today changes. The shop maps untracked stock to
null (unlimited), as the UI always assumed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
Bundle cards list what they contain and how long the code is valid. In
the basket a bundle can be marked as a gift (for / message). Checkout
takes a code: covered bookings show "Paid with your code" and cost 0,
with what the code has left; when nothing is left to pay the button is
Confirm booking and no Stripe step happens. The result page and the
confirmation email show bought codes and code-paid bookings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
Bundles are edited with their parts (service at a length, or product,
× count), price and validity. /passes lists codes with used/held/left and
each part's share of the price; codes can be voided, reactivated, given a
new expiry, or issued without a purchase. Orders show codes bought and
bookings paid with a code; the customer page lists codes and erasure
covers them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
reudy merged commit dc2b9e4e43 into main 2026-10-26 09:30:41 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: reudy-net/domaino#7
No description provided.