Shop hooks: bundles, codes (passes) and orders paid with codes
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
This commit is contained in:
parent
650de78bac
commit
e30e1d3beb
5 changed files with 747 additions and 69 deletions
|
|
@ -41,7 +41,28 @@ routerAdd('POST', '/api/shop/stripe-webhook', (e) => {
|
|||
|
||||
routerAdd('GET', '/api/shop/order', (e) => {
|
||||
const shop = require(`${__hooks}/shop/lib.js`);
|
||||
return e.json(200, shop.orderStatus($app, e.request.url.query().get('payment_intent')));
|
||||
const query = e.request.url.query();
|
||||
return e.json(200, shop.orderStatus($app, query.get('payment_intent'), { orderId: query.get('order'), basketId: query.get('basket') }));
|
||||
});
|
||||
|
||||
// Bundle/voucher codes, for the signed-in admin (Vouchers & codes page).
|
||||
// Customers only use codes through their basket (`apply_code`).
|
||||
routerAdd('GET', '/api/shop/passes', (e) => {
|
||||
if (!e.auth) throw new UnauthorizedError('Sign in to see codes');
|
||||
const shop = require(`${__hooks}/shop/lib.js`);
|
||||
return e.json(200, { passes: shop.listPasses($app, e.request.url.query().get('q')) });
|
||||
});
|
||||
|
||||
routerAdd('POST', '/api/shop/passes/update', (e) => {
|
||||
if (!e.auth) throw new UnauthorizedError('Sign in to change codes');
|
||||
const shop = require(`${__hooks}/shop/lib.js`);
|
||||
return e.json(200, { pass: shop.updatePass($app, e.requestInfo().body) });
|
||||
});
|
||||
|
||||
routerAdd('POST', '/api/shop/passes/issue', (e) => {
|
||||
if (!e.auth) throw new UnauthorizedError('Sign in to issue codes');
|
||||
const shop = require(`${__hooks}/shop/lib.js`);
|
||||
return e.json(200, { pass: shop.issuePass($app, e.requestInfo().body) });
|
||||
});
|
||||
|
||||
routerAdd('POST', '/api/shop/order-email-status', (e) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue