Files
CatoandClaude 9e63512686 feat(plans): PlansScreen, own-key sheet, test-only Stripe guard (0.5.0) (#20)
* feat(plans): PlansScreen, three-screen checkout, own-key sheet, Stripe test-only guard (0.5.0)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(plans): one 'Pay X to Y' checkout screen with a method list and a Bitcoin scan view

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-03 01:56:38 +01:00

156 lines
5.2 KiB
TypeScript

import type { ReactNode } from "react";
import type { PayMethod } from "./checkout.js";
import type { BillingPeriod, PlanId, PlansConfig } from "./config.js";
/**
* The plans screen: up to three cards (Free, a paid plan, Organisations), a
* yearly toggle that starts ON, one button per card, and three trust lines.
* On a phone the paid card comes first.
*
* Words are `labels` so an app can translate them. Colours are CSS variables
* with neutral fallbacks; Bitcoin orange is not used here.
*/
export type PlansLabels = {
monthly: string;
yearly: string;
save: (percent: number, chf: string) => string;
perMonth: string;
perMonthBilledYearly: (yearly: string) => string;
free: string;
custom: string;
models: string;
startFree: string;
getPlan: (name: string) => string;
comingSoon: string;
contactUs: string;
notifyPlaceholder: string;
notifySubmit: string;
notifyThanks: string;
notifyInvalid: string;
recommended: string;
currentPlan: string;
ownKeyLink: string;
trustPrices: string;
trustHosting: string;
trustNoRenew: string;
};
export declare const DEFAULT_PLANS_LABELS: PlansLabels;
export type PlansScreenProps = {
config: PlansConfig;
/** The person picked a card's button. Not called for "Coming soon" or "Contact us". */
onChoose: (choice: {
plan: "free" | "paid";
period: BillingPeriod;
}) => void;
/** Collect an email while `salesEnabled` is false. Throw to show the error state. */
onNotify?: (email: string) => Promise<void>;
/** Show "Use your own API key" under the cards; called when it is tapped. */
onOpenOwnKey?: () => void;
/** The person's current plan. A free plan hides the own-key link: own keys are for paid plans. */
currentPlan?: PlanId;
locale?: string;
labels?: Partial<PlansLabels>;
};
export declare function PlansScreen(props: PlansScreenProps): import("react").JSX.Element;
export type CheckoutLabels = {
/** Heading: "Pay CHF 90 to Heidi". */
title: (amount: string, recipient: string) => string;
chooseMethod: string;
bitcoin: string;
card: string;
twint: string;
bitcoinNote: string;
cardNote: string;
twintNote: string;
/** The primary button on the picker screen: "Pay CHF 90". */
pay: (amount: string) => string;
/** "About 123,456 sats". */
sats: (formatted: string) => string;
scanQr: string;
scanTitle: string;
scanHint: string;
copy: string;
copied: string;
back: string;
testMode: string;
working: string;
failed: string;
};
export declare const DEFAULT_CHECKOUT_LABELS: CheckoutLabels;
/** An extra way to pay, switched on by the app's own config. */
export type ExtraMethod = {
id: string;
label: string;
note?: string;
};
export type CheckoutSheetProps = {
/** Who is paid: the app or recipient name, shown in the heading. */
recipient: string;
/** What is charged, in CHF. */
amountChf: number;
/** The same price in sats, shown while Bitcoin is picked. The app's own rate. */
sats?: number;
/** Optional line under the heading, e.g. "Plus, yearly". */
summary?: string;
methods: PayMethod[];
/** More methods, by config. They go through `onPay` with their own id. */
extraMethods?: ExtraMethod[];
/** Start the checkout on the server; answer with the page to pay on. */
onPay: (method: string) => Promise<string>;
/**
* Turns on "Scan QR code" for Bitcoin: start the Bitcoin checkout and
* answer with what the QR encodes (`checkout.invoice`).
*/
onShowQr?: () => Promise<string>;
/**
* Draws the QR for a string. Paykit ships no QR library: pass your own, e.g.
* `(v) => <QRCodeSVG value={v} size={216} marginSize={4} />` (qrcode.react).
* Without it the scan screen still shows the code to copy.
*/
renderQr?: (value: string) => ReactNode;
/** Go to the pay page. Default: `window.location.assign`. */
navigate?: (url: string) => void;
onClose?: () => void;
/** Card and TWINT run on Stripe test keys: say so. */
testMode?: boolean;
locale?: string;
labels?: Partial<CheckoutLabels>;
};
export declare function CheckoutSheet(props: CheckoutSheetProps): import("react").JSX.Element;
export type OwnKeyVendor = {
id: string;
label: string;
keyUrl?: string;
};
export type OwnKeyLabels = {
title: string;
provider: string;
keyField: string;
save: string;
remove: string;
close: string;
saved: (last4: string) => string;
privacy: string;
skipsAllowance: string;
failed: string;
};
export declare const DEFAULT_OWNKEY_LABELS: OwnKeyLabels;
export type OwnKeySheetProps = {
vendors: OwnKeyVendor[];
/** What is already saved: only the last four characters ever come back. */
saved?: {
vendor: string;
last4: string;
} | null;
/** Server call: seal and store. Answer `{ last4 }`, or throw. The key is not kept here afterwards. */
onSave: (input: {
vendor: string;
key: string;
}) => Promise<{
last4: string;
}>;
onRemove?: () => Promise<void>;
onClose: () => void;
labels?: Partial<OwnKeyLabels>;
};
export declare function OwnKeySheet(props: OwnKeySheetProps): import("react").JSX.Element;