Files
kits/packages/paykit/dist/react/PlanReview.js
CatoandClaude Opus 5.5 ca723c327a paykit 0.6.0: subscriptions, intro offer, portal, PlanPicker and PlanReview (#29)
* feat(paykit 0.6.0): Stripe subscriptions, intro coupon, portal, plan screens

Owner, 2026-12-03: a monthly subscription that renews until cancelled, a
yearly plan at a discount, and a discount on the first months.

- stripe: stripeBilling — mode=subscription Checkout Sessions with an
  inline recurring price, an intro price as a duration=repeating coupon
  under a deterministic id (read, created on resource_missing, a racing
  resource_already_exists is the same coupon), Billing Portal sessions,
  the subscription read back, and the signed webhook reduced to five
  events. Reads the current and pre-2025-03-31 API shapes. No payment
  method named: Stripe documents TWINT as supporting recurring payments.
  The one-time provider ignores subscription checkouts, so one endpoint
  carries both. StripeError gains `code`.
- checkout: SubscriptionPlan/Event/Record, applySubscriptionEvent (pure,
  safe with repeated and out-of-order events), subscriptionAccessUntil,
  subscriptionStanding.
- plans: subscriptionPricing (year per month, saving rounded down).
- react + styles.css: PlanPicker and PlanReview, styled through --pk-*
  variables with --sk-* and system light/dark fallbacks. react is an
  optional peer dependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtfseicWGK2CMC2U5r

* fix(paykit 0.6.0): cancelSubscription, unpaid periods grant nothing, unbroken tab names

- stripeBilling.cancelSubscription(id): DELETE /v1/subscriptions/{id}, for an
  app's own reasons such as a deleted account; a missing one is null.
- applySubscriptionEvent / recordFromSnapshot: a past_due or unpaid
  subscription already names the next period's end, which nobody paid for;
  only a subscription in good standing or a paid invoice moves access.
- styles.css: no hyphens:auto on the tier switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtfseicWGK2CMC2U5r

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-03 09:27:29 +01:00

45 lines
5.8 KiB
JavaScript

"use client";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
/**
* The last step before the payment page: what is being bought, what to know
* about it, which account it goes on, and the terms the buyer agrees to.
*
* WHY A STEP AT ALL. A subscription charges again by itself. Saying so on the
* button's own screen, and asking for a tick that the buyer read it, is what
* a buyer is owed before a renewing charge (and what the subscription pages
* people trust already do). The button stays off until every required term
* is ticked, and says why above it.
*
* NO SECOND PLAN BY MISTAKE. When the app says the person already holds a
* plan that overlaps (`overlap`), the button to buy is replaced by the way to
* manage the one they have.
*
* The app passes words, links and callbacks; it decides which terms exist
* (never invented here) and what an opt-in switches on.
*/
import { useId, useState } from "react";
export function PlanReview({ step, title, summary, notes = [], account, terms = [], requiredHint, confirm, back, overlap, error, className, }) {
const id = useId();
const [accepted, setAccepted] = useState(() => Object.fromEntries(terms.map((t) => [t.id, t.defaultChecked === true])));
const [busy, setBusy] = useState(false);
const missing = terms.filter((t) => t.required && !accepted[t.id]).length;
const ready = missing === 0 && !busy;
async function run(fn) {
if (busy)
return;
setBusy(true);
try {
await fn();
}
finally {
setBusy(false);
}
}
return (_jsxs("div", { className: ["pk-review", className].filter(Boolean).join(" "), "data-pk": "review", children: [_jsxs("header", { className: "pk-review-head", children: [step && _jsx("p", { className: "pk-step", children: step }), _jsx("h2", { className: "pk-review-title", children: title })] }), _jsxs("div", { className: "pk-summary", "data-pk": "summary", children: [_jsx("p", { className: "pk-summary-name", children: summary.name }), _jsxs("p", { className: "pk-summary-price", children: [_jsx("span", { className: "pk-amount", children: summary.price }), " ", _jsx("span", { className: "pk-per", children: summary.per })] }), summary.detail && _jsx("p", { className: "pk-summary-detail", children: summary.detail }), summary.tax && _jsx("p", { className: "pk-summary-tax", children: summary.tax })] }), notes.length > 0 && (_jsx("ul", { className: "pk-notes", children: notes.map((note) => {
const body = (_jsxs(_Fragment, { children: [_jsx("span", { className: "pk-note-icon", "aria-hidden": "true", children: note.icon ?? note.title.slice(0, 1) }), _jsxs("span", { className: "pk-note-text", children: [_jsx("span", { className: "pk-note-title", children: note.title }), _jsx("span", { className: "pk-note-line", children: note.line })] })] }));
return (_jsx("li", { "data-note": note.id, children: note.more ? (_jsxs("details", { className: "pk-note", children: [_jsxs("summary", { className: "pk-note-row", children: [body, _jsx("svg", { className: "pk-note-chevron", viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M4 6l4 4 4-4", fill: "none", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), _jsx("div", { className: "pk-note-more", children: note.more })] })) : (_jsx("div", { className: "pk-note pk-note-row", children: body })) }, note.id));
}) })), account && (_jsxs("div", { className: "pk-account", "data-pk": "account", children: [_jsx("p", { className: "pk-account-label", children: account.label }), _jsx("p", { className: "pk-account-value", children: account.value }), account.hint && _jsx("p", { className: "pk-account-hint", children: account.hint })] })), overlap ? (_jsxs("div", { className: "pk-overlap", role: "alert", "data-pk": "overlap", children: [_jsx("p", { className: "pk-overlap-title", children: overlap.title }), _jsx("p", { className: "pk-overlap-body", children: overlap.body }), overlap.manage &&
(overlap.manage.href ? (_jsx("a", { className: "pk-button", href: overlap.manage.href, "data-pk": "manage", children: overlap.manage.label })) : (_jsx("button", { type: "button", className: "pk-button", "data-pk": "manage", disabled: busy, "aria-busy": busy || undefined, onClick: () => overlap.manage?.onSelect && run(overlap.manage.onSelect), children: busy && overlap.manage.busyLabel ? overlap.manage.busyLabel : overlap.manage.label })))] })) : (_jsxs(_Fragment, { children: [terms.length > 0 && (_jsx("fieldset", { className: "pk-terms", children: terms.map((term) => (_jsxs("label", { className: "pk-term", "data-term": term.id, "data-required": term.required || undefined, children: [_jsx("input", { className: "pk-checkbox", type: "checkbox", checked: accepted[term.id] === true, "aria-describedby": term.required && missing > 0 ? `${id}-hint` : undefined, onChange: (event) => setAccepted((all) => ({ ...all, [term.id]: event.target.checked })) }), _jsx("span", { className: "pk-term-label", children: term.label })] }, term.id))) })), missing > 0 && requiredHint && (_jsx("p", { id: `${id}-hint`, className: "pk-hint", "data-pk": "hint", children: requiredHint.replace("{n}", String(missing)) })), error && (_jsx("p", { className: "pk-error", role: "alert", children: error })), _jsx("button", { type: "button", className: "pk-button", "data-pk": "confirm", disabled: !ready, "aria-busy": busy || undefined, onClick: () => run(() => confirm.onConfirm(accepted)), children: busy && confirm.busyLabel ? confirm.busyLabel : confirm.label })] })), back &&
(back.href ? (_jsx("a", { className: "pk-quiet", href: back.href, "data-pk": "back", children: back.label })) : (_jsx("button", { type: "button", className: "pk-quiet", "data-pk": "back", onClick: back.onSelect, children: back.label })))] }));
}