@pontive/pontkit-core 1.42.0 → 1.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,158 @@
1
+ import { PaymentKeys, PaymentStart } from '../provider/account-billing';
2
+ import { StripeFactory, StripeInstance, StripeIntentResult } from './stripe';
3
+ /**
4
+ * # The payment form both billing elements use (billing-svc docs/m17-design.md, Part 3, The payment form, shared)
5
+ *
6
+ * Copied, not imported, from billing-web's hosted invoice script (`api/assets/hosted-invoice.js`):
7
+ * Stripe.js with the platform's publishable key and the connected account; the Payment Element in
8
+ * deferred mode with the amount and currency; `elements.submit()`, then the server call, then
9
+ * `confirmPayment` with the client secret; `handleNextAction` for `requires_action`; and after a
10
+ * payment, the resource is read again until billing-svc has recorded it, since only Stripe's
11
+ * webhook records a payment (`watchUntilSettled`, billing-web commit `968681f`).
12
+ *
13
+ * Three differences from the hosted page, as the design has them:
14
+ *
15
+ * - `confirmSetup` for a SetupIntent (a trial with nothing due, or adding a method);
16
+ * - `setupFutureUsage: "off_session"` in checkout, so the renewals can collect (R4);
17
+ * - `redirect: "if_required"`, so a card payment never leaves the client's page. A method that must
18
+ * redirect comes back with Stripe's query, which `readStripeReturn` reads and removes.
19
+ *
20
+ * The Payment Element mounts in the light DOM, in a node the element renders outside any keyed or
21
+ * bound template part, and never inside a kit dialog (R10): a dialog makes the rest of the page
22
+ * inert, and Stripe puts its 3D Secure and Link overlays on `<body>`.
23
+ */
24
+ /** What to do after the server's answer to confirm or pay. */
25
+ export type PaymentStep = {
26
+ kind: "confirm";
27
+ intent: "payment" | "setup";
28
+ clientSecret: string;
29
+ } | {
30
+ kind: "action";
31
+ clientSecret: string;
32
+ } | {
33
+ kind: "confirming";
34
+ } | {
35
+ kind: "failed";
36
+ message?: string;
37
+ } | {
38
+ kind: "error";
39
+ };
40
+ /**
41
+ * The server's outcome as the next step (pontive-spec 35, Checkout, 3): confirm in the form,
42
+ * finish an authentication, wait for the webhook, or say the decline.
43
+ */
44
+ export declare function stepFor(start: PaymentStart): PaymentStep;
45
+ /** What Stripe.js's answer means: wait for the webhook, say why it failed, or let the customer try again. */
46
+ export type StripeOutcome = {
47
+ kind: "confirming";
48
+ } | {
49
+ kind: "failed";
50
+ message?: string;
51
+ } | {
52
+ kind: "retry";
53
+ };
54
+ /** Stripe's answer to a confirm or a next action. */
55
+ export declare function outcomeOf(result: StripeIntentResult | undefined): StripeOutcome;
56
+ /** billing-web's timings (`hosted-invoice.js`, `CONFIRM_*`). */
57
+ export declare const CONFIRM_FAST_MS = 2000;
58
+ export declare const CONFIRM_FAST_FOR_MS = 30000;
59
+ export declare const CONFIRM_SLOW_MS = 10000;
60
+ export declare const CONFIRM_SLOW_FOR_MS = 600000;
61
+ export interface WatchOptions<T> {
62
+ /** Reads the resource again. */
63
+ read: () => Promise<T>;
64
+ /** Whether it shows the payment's result. */
65
+ settled: (value: T) => boolean;
66
+ onSettled: (value: T) => void;
67
+ /** After `CONFIRM_FAST_FOR_MS`: say the page updates when it is confirmed. */
68
+ onSlow?: () => void;
69
+ /** After `CONFIRM_SLOW_FOR_MS` more: stop checking, leave the message. */
70
+ onGiveUp?: () => void;
71
+ /** A read failed with a status that will not change (404): stop. */
72
+ onGone?: (error: unknown) => void;
73
+ /** For tests. */
74
+ now?: () => number;
75
+ setTimer?: (fn: () => void, ms: number) => unknown;
76
+ clearTimer?: (timer: unknown) => void;
77
+ }
78
+ /**
79
+ * Reads until the resource reflects the payment: every 2 seconds for 30 seconds, then every 10
80
+ * seconds for 10 minutes, then stops (billing-web `confirmPayment`). The first read is at once.
81
+ * Returns the stop.
82
+ */
83
+ export declare function watchUntilSettled<T>(options: WatchOptions<T>): () => void;
84
+ export interface StripeReturn {
85
+ /** `confirm` for a payment or setup that succeeded or is processing, `failed` otherwise. */
86
+ result: "confirm" | "failed";
87
+ /** The element's own marker it put on the return URL (a checkout session, an invoice). */
88
+ marker: string | null;
89
+ }
90
+ /**
91
+ * Reads Stripe's return to the page from `url` and the element's `markerParam`, and answers the
92
+ * URL without them (so a refresh or a shared link does not carry the client secret), or `null`
93
+ * when this is not a return. Other query parameters of the page are kept.
94
+ */
95
+ export declare function readStripeReturn(url: URL, markerParam: string): {
96
+ ret: StripeReturn;
97
+ clean: string;
98
+ } | null;
99
+ /** `url` with the element's marker added, for `confirmParams.return_url`. */
100
+ export declare function returnUrlWith(url: string, markerParam: string, marker: string): string;
101
+ /** Drops Stripe's query and the marker from the address bar. */
102
+ export declare function cleanAddressBar(clean: string): void;
103
+ /** How the Payment Element is created: deferred (amount known, no intent yet), or for an existing intent. */
104
+ export type PaymentFormMode = {
105
+ mode: "payment";
106
+ amount: number;
107
+ currency: string;
108
+ setupFutureUsage?: "off_session";
109
+ } | {
110
+ mode: "setup";
111
+ currency?: string;
112
+ } | {
113
+ clientSecret: string;
114
+ };
115
+ export interface PaymentFormOptions {
116
+ /** For tests and stories: Stripe.js without loading it. */
117
+ loadStripe?: () => Promise<StripeFactory>;
118
+ }
119
+ /**
120
+ * One Payment Element: created on `prepare`, mounted on `attach` (again when the node changed),
121
+ * confirmed on `confirm`. Holds the Stripe instance for `handleNextAction`.
122
+ */
123
+ export declare class PaymentForm {
124
+ private readonly options;
125
+ private stripe;
126
+ private elements;
127
+ private element;
128
+ private node;
129
+ private themeObserver;
130
+ private host;
131
+ private seq;
132
+ /** How the current elements were created; a confirm of the other intent type updates them first. */
133
+ private current;
134
+ constructor(options?: PaymentFormOptions);
135
+ /** Whether a form is ready to mount or mounted. */
136
+ get ready(): boolean;
137
+ /** The Stripe instance for `keys`, loading Stripe.js on first need. */
138
+ stripeFor(keys: PaymentKeys): Promise<StripeInstance>;
139
+ /** Loads Stripe.js and creates the Payment Element, styled from `host`'s tokens. */
140
+ prepare(keys: PaymentKeys, mode: PaymentFormMode, host: Element): Promise<void>;
141
+ /** Mounts into `node` (the element's light-DOM mount node), or remounts when it changed. */
142
+ attach(node: HTMLElement | null): void;
143
+ private mountInto;
144
+ /** Validates the fields (deferred mode needs it before the server call). Resolves with Stripe's message, or null. */
145
+ submit(): Promise<string | null>;
146
+ /**
147
+ * Confirms with the server's client secret. `returnUrl` is where a redirecting method comes back.
148
+ * A confirm of the other intent type than the form was made for (a trial's SetupIntent where the
149
+ * preview owed money) updates the form first.
150
+ */
151
+ confirm(intent: "payment" | "setup", clientSecret: string, returnUrl: string): Promise<StripeOutcome>;
152
+ /** Finishes an authentication (3D Secure) the issuer asked for, with the server's client secret. */
153
+ nextAction(keys: PaymentKeys | null | undefined, clientSecret: string): Promise<StripeOutcome>;
154
+ /** A theme change after mount: the colours again (R11). The fields keep what was typed. */
155
+ private watchTheme;
156
+ /** Unmounts and forgets the form. */
157
+ destroy(): void;
158
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * # Stripe.js for the billing elements (billing-svc docs/m17-design.md, Part 3; docs/questions.md, P68)
3
+ *
4
+ * Card details are entered only in Stripe's Payment Element, on the client's connected account;
5
+ * they never reach the kit or Pontive (pontive-spec 32-billing-overview.md, Regulatory boundaries).
6
+ *
7
+ * **The one runtime third-party script** (P68, recorded in CLAUDE.md): the kit's bundle is one
8
+ * self-contained file so that SRI covers everything it runs, and Stripe forbids bundling or
9
+ * self-hosting Stripe.js. So, only when a billing element needs the payment form, the kit injects
10
+ * `https://js.stripe.com/v3/` once per page, **without SRI** (Stripe publishes no hashes). A page
11
+ * that already has `window.Stripe` (it loaded Stripe.js itself) is used as it is.
12
+ *
13
+ * Nothing else in the kit loads a script at runtime. The types below are the few Stripe.js calls
14
+ * the elements make, so tests and stories can pass a fake.
15
+ */
16
+ /** Where Stripe.js comes from. Stripe serves it only from this origin. */
17
+ export declare const STRIPE_JS_URL = "https://js.stripe.com/v3/";
18
+ export interface StripeError {
19
+ type?: string;
20
+ code?: string;
21
+ message?: string;
22
+ }
23
+ export interface StripeIntentResult {
24
+ error?: StripeError;
25
+ paymentIntent?: {
26
+ status?: string;
27
+ };
28
+ setupIntent?: {
29
+ status?: string;
30
+ };
31
+ }
32
+ export interface StripePaymentElement {
33
+ mount(node: HTMLElement): void;
34
+ unmount(): void;
35
+ destroy?(): void;
36
+ }
37
+ export interface StripeElements {
38
+ create(type: "payment", options?: Record<string, unknown>): StripePaymentElement;
39
+ submit(): Promise<{
40
+ error?: StripeError;
41
+ }>;
42
+ update(options: Record<string, unknown>): void;
43
+ }
44
+ /** What the elements call on a Stripe instance. */
45
+ export interface StripeInstance {
46
+ elements(options: Record<string, unknown>): StripeElements;
47
+ confirmPayment(options: Record<string, unknown>): Promise<StripeIntentResult>;
48
+ confirmSetup(options: Record<string, unknown>): Promise<StripeIntentResult>;
49
+ handleNextAction(options: {
50
+ clientSecret: string;
51
+ }): Promise<StripeIntentResult>;
52
+ }
53
+ /** `window.Stripe`. */
54
+ export type StripeFactory = (publishableKey: string, options?: {
55
+ stripeAccount?: string;
56
+ locale?: string;
57
+ }) => StripeInstance;
58
+ /** What the loader touches, so a test can give its own. */
59
+ export interface StripeLoaderEnv {
60
+ window: {
61
+ Stripe?: unknown;
62
+ };
63
+ document: Pick<Document, "createElement" | "querySelector" | "head">;
64
+ }
65
+ /** Forgets a load in progress or done. For tests and stories. */
66
+ export declare function resetStripeLoader(): void;
67
+ /**
68
+ * `window.Stripe`, loading Stripe.js from js.stripe.com first when the page has not. One load per
69
+ * page: later calls share it. A failed load is forgotten, so the next call tries again.
70
+ */
71
+ export declare function loadStripe(env?: StripeLoaderEnv): Promise<StripeFactory>;
72
+ /** One Stripe instance per key, account and language on the page. */
73
+ export declare function stripeFor(factory: StripeFactory, keys: {
74
+ publishable_key: string;
75
+ provider_account: string;
76
+ }, locale?: string): StripeInstance;
77
+ /** Forgets the Stripe instances. For tests and stories. */
78
+ export declare function resetStripeInstances(): void;
79
+ /** The kit tokens the Payment Element's colours come from, by Stripe Appearance variable. */
80
+ export declare const APPEARANCE_TOKENS: {
81
+ readonly colorPrimary: "--pont-sem-color-primary";
82
+ readonly colorBackground: "--pont-sem-color-bg";
83
+ readonly colorText: "--pont-sem-color-fg";
84
+ readonly colorTextSecondary: "--pont-sem-color-muted-fg";
85
+ readonly colorDanger: "--pont-sem-color-destructive";
86
+ };
87
+ /**
88
+ * A CSS colour (the kit's are `oklch`) as `rgb(r, g, b)`, which Stripe's Appearance API takes.
89
+ * Painted on a 1 by 1 canvas and read back, so any colour the browser knows converts. Undefined
90
+ * when it cannot be read.
91
+ */
92
+ export declare function toRgb(color: string): string | undefined;
93
+ /**
94
+ * Stripe's Appearance for the Payment Element, read at mount from the kit's tokens as they apply
95
+ * to `host`: colours from `--pont-sem-*`, resolved to `rgb`; the body font; the input radius. A
96
+ * dark background picks Stripe's `night` theme.
97
+ */
98
+ export declare function stripeAppearance(host: Element): Record<string, unknown>;
@@ -38,3 +38,5 @@ export * from './account-menu/account-menu';
38
38
  export * from './organization-switcher/organization-switcher';
39
39
  export * from './account-settings/account-settings';
40
40
  export * from './member-management/member-management';
41
+ export * from './checkout/checkout';
42
+ export * from './billing-portal/billing-portal';
@@ -0,0 +1,384 @@
1
+ import { Page } from './account-client';
2
+ /**
3
+ * # The account client's billing part (billing-svc docs/m17-design.md, Part 2 and Part 3)
4
+ *
5
+ * `<pont-checkout>` and `<pont-billing-portal>` talk to management-api's end-customer billing
6
+ * routes, `/mgmt/v1/me/billing/*`, through this part of the account client. Every call uses a
7
+ * **management-API token** (the billing scopes live only on it, pontive-spec
8
+ * 41-embedded-organization-management.md §5.1), drawn before each request, like member management.
9
+ *
10
+ * **This file is the only place the HTTP shapes live**: the paths, the query and body each call
11
+ * sends, and how each answer is read. The routes were designed before they were built (billing-svc
12
+ * `docs/m17-design.md`), so where the design leaves a shape open this file picks one and says so
13
+ * with `ASSUMED`. If the built routes differ, change this file and its test; the elements read only
14
+ * the types below.
15
+ *
16
+ * Wire conventions, as management-api's billing routes already answer (`core/billing/protorest`):
17
+ * one object is sent bare with its `object`; a list is `{ object: "list", data, pagination }`;
18
+ * amounts are `{ amount: "12.50", currency: "usd" }` with a decimal string; times are RFC 3339.
19
+ * Create and mutate calls send `X-Idempotency-Key`, which management-api passes to billing-svc.
20
+ */
21
+ /** An amount: a decimal string with its ISO 4217 currency (pontive-spec 32, Money). Never a float. */
22
+ export interface BillingMoney {
23
+ amount: string;
24
+ currency: string;
25
+ }
26
+ /** A Customer's subject: who it bills (pontive-spec 32, Customers). */
27
+ export interface BillingSubject {
28
+ type: "user" | "organization";
29
+ id: string;
30
+ }
31
+ /** What Stripe.js loads with: the platform's publishable key and the client's connected account. */
32
+ export interface PaymentKeys {
33
+ publishable_key: string;
34
+ provider_account: string;
35
+ }
36
+ /**
37
+ * One Customer the caller may see (`GET /me/billing/customers`, pontive-spec 32, End-customer
38
+ * surface): its own `user` Customer, those of organizations where it holds `sys:billing:read`, and
39
+ * the suspended organizations it may recover (P79).
40
+ */
41
+ export interface BillingAccount {
42
+ id: string;
43
+ subject: BillingSubject;
44
+ name?: string;
45
+ email?: string;
46
+ currency?: string;
47
+ status?: string;
48
+ default_payment_method?: BillingPaymentMethodSummary | null;
49
+ /**
50
+ * What the caller may do here (R9). ASSUMED: `permissions: { read, pay }`, after the keys
51
+ * `sys:billing:read` and `sys:billing:pay`. Missing: both true, and billing-svc still decides.
52
+ */
53
+ permissions: {
54
+ read: boolean;
55
+ pay: boolean;
56
+ };
57
+ /** A suspended organization the caller (its owner) may recover: only the recovery actions (P79). */
58
+ recovery: boolean;
59
+ /** ASSUMED: the keys for Stripe.js, `null` when the instance has no payment connection. */
60
+ keys: PaymentKeys | null;
61
+ }
62
+ export interface BillingPaymentMethodSummary {
63
+ id: string;
64
+ type: string;
65
+ brand?: string;
66
+ last4?: string;
67
+ exp_month?: number;
68
+ exp_year?: number;
69
+ }
70
+ /** A package the end customer may choose: in a checkout session, or as a change in the portal. */
71
+ export interface BillingPackageOption {
72
+ package_id: string;
73
+ key?: string;
74
+ name?: string;
75
+ description?: string;
76
+ display?: {
77
+ tagline?: string;
78
+ highlights?: string[];
79
+ badge?: string;
80
+ cta_label?: string;
81
+ };
82
+ trial?: {
83
+ days?: number;
84
+ kind?: string;
85
+ payment_method_required?: boolean;
86
+ } | null;
87
+ /** The frequencies offered (`monthly`, `quarterly`, `annual`). */
88
+ billing_frequencies: string[];
89
+ /** ASSUMED: the price of one period at each frequency, `{ billing_frequency, amount }` (P65). */
90
+ prices: {
91
+ billing_frequency: string;
92
+ amount: BillingMoney;
93
+ }[];
94
+ }
95
+ /** A checkout session (pontive-spec 35, Checkout session; P65's read). */
96
+ export interface CheckoutSession {
97
+ id: string;
98
+ status: "open" | "completed" | "expired" | string;
99
+ expires_at?: string;
100
+ contract_id?: string | null;
101
+ collect?: {
102
+ billing_address?: "auto" | "required" | string;
103
+ tax_id?: boolean;
104
+ };
105
+ success_url?: string;
106
+ cancel_url?: string;
107
+ packages: BillingPackageOption[];
108
+ /** ASSUMED: the keys for Stripe.js, so the payment form shows before confirm (deferred intent). */
109
+ keys: PaymentKeys | null;
110
+ }
111
+ /** What the end customer chose, sent to preview and confirm (pontive-spec 35, API Surface). */
112
+ export interface CheckoutChoice {
113
+ package_id: string;
114
+ billing_frequency: string;
115
+ billing_address?: BillingAddress;
116
+ /** ASSUMED: `{ value }`, with the type left to billing-svc. */
117
+ tax_id?: {
118
+ type?: string;
119
+ value: string;
120
+ };
121
+ }
122
+ export interface BillingAddress {
123
+ line1?: string;
124
+ line2?: string;
125
+ city?: string;
126
+ state?: string;
127
+ postal_code?: string;
128
+ country?: string;
129
+ }
130
+ /** The first invoice as it would be (P65), read from `POST .../checkout-sessions/{id}/preview`. */
131
+ export interface CheckoutPreview {
132
+ invoice: BillingInvoice;
133
+ }
134
+ /**
135
+ * How an on-session payment starts: checkout's confirm, paying an invoice. The hosted invoice
136
+ * page's outcomes (pontive-spec 35, Checkout, 3; 38, Paying on the hosted page).
137
+ */
138
+ export interface PaymentStart {
139
+ outcome: "requires_confirmation" | "requires_action" | "processing" | "succeeded" | "failed" | string;
140
+ contract_id?: string;
141
+ invoice_id?: string;
142
+ payment_id?: string;
143
+ /** Never logged, never stored: it goes to Stripe.js only. */
144
+ client_secret?: string;
145
+ intent_type?: "payment" | "setup";
146
+ decline_message?: string;
147
+ /** ASSUMED for confirm (the hosted page's pay answer has them): the keys, when the answer needs Stripe.js. */
148
+ keys?: PaymentKeys | null;
149
+ }
150
+ export interface BillingInvoiceLine {
151
+ id?: string;
152
+ kind?: string;
153
+ description?: string;
154
+ quantity?: string;
155
+ amount: BillingMoney;
156
+ }
157
+ export interface BillingInvoice {
158
+ id: string | null;
159
+ number?: string;
160
+ status: string;
161
+ currency: string;
162
+ contract_id?: string;
163
+ period_start?: string;
164
+ period_end?: string;
165
+ finalized_at?: string;
166
+ due_date?: string;
167
+ created_at?: string;
168
+ lines: BillingInvoiceLine[];
169
+ subtotal?: BillingMoney;
170
+ tax_total?: BillingMoney;
171
+ total?: BillingMoney;
172
+ amount_due?: BillingMoney;
173
+ amount_remaining?: BillingMoney;
174
+ /** ASSUMED, as on the hosted invoice: `amount_remaining` in the provider's integer units. */
175
+ amount_provider_units?: number;
176
+ hosted_url?: string;
177
+ }
178
+ export interface BillingCreditNote {
179
+ id: string;
180
+ number?: string;
181
+ invoice_id?: string;
182
+ status?: string;
183
+ total?: BillingMoney;
184
+ created_at?: string;
185
+ }
186
+ export interface BillingSubscription {
187
+ id: string;
188
+ product_id?: string;
189
+ billing_frequency?: string;
190
+ /** `mode` is `quantity_only` (the contract sets it) or `members` (the organization's member count), pontive-spec 35. */
191
+ quantity?: {
192
+ mode?: string;
193
+ current?: string;
194
+ min?: string;
195
+ max?: string;
196
+ };
197
+ }
198
+ /** A contract (pontive-spec 35, Contract). */
199
+ export interface BillingContract {
200
+ id: string;
201
+ status: string;
202
+ currency?: string;
203
+ /** ASSUMED: `name` beside the reference, for the portal to show. */
204
+ package?: {
205
+ id?: string;
206
+ key?: string;
207
+ version?: number;
208
+ name?: string;
209
+ };
210
+ starting_at?: string;
211
+ ending_before?: string;
212
+ billing?: {
213
+ current_period_start?: string;
214
+ current_period_end?: string;
215
+ };
216
+ term?: {
217
+ current_term_end?: string;
218
+ };
219
+ trial?: {
220
+ ending_before?: string;
221
+ } | null;
222
+ cancellation?: {
223
+ takes_effect_at?: string;
224
+ } | null;
225
+ pending_change?: {
226
+ package?: string;
227
+ billing_frequency?: string;
228
+ takes_effect_at?: string;
229
+ } | null;
230
+ subscriptions: BillingSubscription[];
231
+ access?: string;
232
+ /**
233
+ * ASSUMED: the packages and frequencies the end customer may change to (public, self-service
234
+ * `change`, allowed for `initiated_by: customer`), shaped as a checkout session's packages.
235
+ * `GET /v1/packages/public` is not in M17, so the portal has no other way to list them.
236
+ */
237
+ change_options: BillingPackageOption[];
238
+ /** ASSUMED: the package's self-service flags; missing means "offer it and let billing-svc decide". */
239
+ self_service?: {
240
+ change?: boolean;
241
+ cancel?: boolean;
242
+ set_seats?: boolean;
243
+ };
244
+ }
245
+ /** A contract change: a package or frequency, or a quantity (pontive-spec 35, API Surface). */
246
+ export type ContractChange = {
247
+ package: string;
248
+ billing_frequency?: string;
249
+ } | {
250
+ quantity: string;
251
+ subscription_id?: string;
252
+ };
253
+ /** `POST .../contracts/{id}/preview-change`: the change's effect and the hash `change` must send back (R3). */
254
+ export interface ContractChangePreview {
255
+ contract: BillingContract;
256
+ invoices: BillingInvoice[];
257
+ upcoming_invoice: BillingInvoice | null;
258
+ preview_hash: string;
259
+ }
260
+ /** A saved payment method (pontive-spec 38, Payment method (summary)). */
261
+ export interface BillingPaymentMethod {
262
+ id: string;
263
+ type: string;
264
+ display: {
265
+ brand?: string;
266
+ last4?: string;
267
+ exp_month?: number;
268
+ exp_year?: number;
269
+ bank_name?: string;
270
+ country?: string;
271
+ };
272
+ reusable: boolean;
273
+ is_default: boolean;
274
+ status: string;
275
+ }
276
+ /** What the Payment Element collects a method with (`POST .../payment-method-session`, embedded). */
277
+ export interface PaymentMethodSession {
278
+ id?: string;
279
+ client_secret: string;
280
+ keys: PaymentKeys;
281
+ }
282
+ /** `DELETE .../payment-methods/{pm}`: a warning when it was the last reusable method (pontive-spec 38, Removal). */
283
+ export interface PaymentMethodRemoval {
284
+ warnings: string[];
285
+ }
286
+ export interface BillingListParams {
287
+ page?: number;
288
+ limit?: number;
289
+ }
290
+ /** A request to create a session through `/me` (pontive-spec 35, API Surface). */
291
+ export interface CreateCheckoutSessionRequest {
292
+ subject?: BillingSubject;
293
+ packages: {
294
+ package_id: string;
295
+ billing_frequencies?: string[];
296
+ }[];
297
+ success_url: string;
298
+ cancel_url: string;
299
+ }
300
+ /** Every call can name the Customer's subject (the element's `subject` attribute; P37, P79). */
301
+ export interface BillingCallOptions {
302
+ subject?: BillingSubject;
303
+ }
304
+ /**
305
+ * The billing part of the account client: one method per `/me/billing` route of the design's
306
+ * Part 2. Optional on `AccountClient`, like the members part.
307
+ */
308
+ export interface AccountBillingApi {
309
+ /** Draws (or reuses) a management token and resolves with its scopes (shared with the members part). */
310
+ getManagementScopes(): Promise<string[]>;
311
+ /** The scopes the app asks for at sign-in (the provider's `scope`), to explain a refused token. */
312
+ requestedScopes?(): string[];
313
+ listBillingAccounts(): Promise<BillingAccount[]>;
314
+ listMyContracts(options?: BillingCallOptions): Promise<BillingContract[]>;
315
+ previewMyContractChange(contractId: string, change: ContractChange, options?: BillingCallOptions): Promise<ContractChangePreview>;
316
+ changeMyContract(contractId: string, change: ContractChange, previewHash: string, options?: BillingCallOptions): Promise<BillingContract>;
317
+ cancelMyContract(contractId: string, options?: BillingCallOptions): Promise<BillingContract>;
318
+ revokeMyContractCancellation(contractId: string, options?: BillingCallOptions): Promise<BillingContract>;
319
+ createMyCheckoutSession(request: CreateCheckoutSessionRequest): Promise<CheckoutSession>;
320
+ getMyCheckoutSession(sessionId: string, options?: BillingCallOptions): Promise<CheckoutSession>;
321
+ previewMyCheckout(sessionId: string, choice: CheckoutChoice, options?: BillingCallOptions): Promise<CheckoutPreview>;
322
+ confirmMyCheckout(sessionId: string, choice: CheckoutChoice, options?: BillingCallOptions): Promise<PaymentStart>;
323
+ listMyInvoices(options?: BillingCallOptions & BillingListParams): Promise<Page<BillingInvoice>>;
324
+ getMyInvoice(invoiceId: string, options?: BillingCallOptions): Promise<BillingInvoice>;
325
+ getMyInvoicePdf(invoiceId: string, options?: BillingCallOptions): Promise<Blob>;
326
+ getMyUpcomingInvoice(options?: BillingCallOptions): Promise<BillingInvoice | null>;
327
+ listMyCreditNotes(options?: BillingCallOptions & BillingListParams): Promise<Page<BillingCreditNote>>;
328
+ payMyInvoice(invoiceId: string, method: "saved" | "new", options?: BillingCallOptions): Promise<PaymentStart>;
329
+ listMyPaymentMethods(options?: BillingCallOptions): Promise<BillingPaymentMethod[]>;
330
+ createMyPaymentMethodSession(options?: BillingCallOptions & {
331
+ return_url?: string;
332
+ }): Promise<PaymentMethodSession>;
333
+ setMyDefaultPaymentMethod(paymentMethodId: string, options?: BillingCallOptions): Promise<void>;
334
+ removeMyPaymentMethod(paymentMethodId: string, options?: BillingCallOptions): Promise<PaymentMethodRemoval>;
335
+ listMyPayments(options?: BillingCallOptions & BillingListParams): Promise<Page<Record<string, unknown>>>;
336
+ listMyBalances(options?: BillingCallOptions): Promise<Record<string, unknown>[]>;
337
+ listMyLedgerEntries(options?: BillingCallOptions & BillingListParams): Promise<Page<Record<string, unknown>>>;
338
+ getMyUsage(options?: BillingCallOptions & Record<string, string | number | undefined>): Promise<Record<string, unknown>>;
339
+ listMyEntitlements(options?: BillingCallOptions): Promise<Record<string, unknown>>;
340
+ checkMyEntitlement(request: Record<string, unknown>, options?: BillingCallOptions): Promise<Record<string, unknown>>;
341
+ }
342
+ /** Every method of the billing part; a client lacking one of these has no billing part. */
343
+ export declare const BILLING_METHODS: readonly ["getManagementScopes", "listBillingAccounts", "listMyContracts", "previewMyContractChange", "changeMyContract", "cancelMyContract", "revokeMyContractCancellation", "createMyCheckoutSession", "getMyCheckoutSession", "previewMyCheckout", "confirmMyCheckout", "listMyInvoices", "getMyInvoice", "getMyInvoicePdf", "getMyUpcomingInvoice", "listMyCreditNotes", "payMyInvoice", "listMyPaymentMethods", "createMyPaymentMethodSession", "setMyDefaultPaymentMethod", "removeMyPaymentMethod", "listMyPayments", "listMyBalances", "listMyLedgerEntries", "getMyUsage", "listMyEntitlements", "checkMyEntitlement"];
344
+ /** The methods `<pont-checkout>` needs. */
345
+ export declare const CHECKOUT_METHODS: readonly ["getManagementScopes", "createMyCheckoutSession", "getMyCheckoutSession", "previewMyCheckout", "confirmMyCheckout"];
346
+ /** The methods `<pont-billing-portal>` needs. */
347
+ export declare const PORTAL_METHODS: readonly ["getManagementScopes", "listBillingAccounts", "listMyContracts", "previewMyContractChange", "changeMyContract", "cancelMyContract", "revokeMyContractCancellation", "listMyInvoices", "getMyInvoice", "getMyInvoicePdf", "getMyUpcomingInvoice", "listMyCreditNotes", "payMyInvoice", "listMyPaymentMethods", "createMyPaymentMethodSession", "setMyDefaultPaymentMethod", "removeMyPaymentMethod"];
348
+ /** Whether `client` has every method in `methods` (an app's own client may have none). */
349
+ export declare function hasBillingMethods<M extends keyof AccountBillingApi>(client: unknown, methods: readonly M[]): client is Pick<AccountBillingApi, M>;
350
+ /** Billing's OAuth scopes (pontive-spec 41 §5.1): `read` to view, `pay` to act. */
351
+ export declare const BILLING_SCOPES: {
352
+ readonly read: "pontive:billing:read";
353
+ readonly pay: "pontive:billing:pay";
354
+ };
355
+ /**
356
+ * The subject an element's `subject` attribute names: `usr_…` is a user, `org_…` an organization
357
+ * (Pontive's id prefixes). `null` for anything else.
358
+ */
359
+ export declare function parseSubject(value: string | null | undefined): BillingSubject | null;
360
+ /** One request to management-api, relative to `/mgmt/v1`. */
361
+ export interface BillingRequest {
362
+ method: "GET" | "POST" | "DELETE";
363
+ /** The path and its query, e.g. `/me/billing/invoices?page=1`. */
364
+ path: string;
365
+ body?: unknown;
366
+ /** Create and mutate calls: sent as `X-Idempotency-Key`. */
367
+ idempotent?: boolean;
368
+ /** The answer is a file (the invoice PDF), read as a Blob. */
369
+ binary?: boolean;
370
+ }
371
+ /** Sends one request with a management token and answers the parsed JSON (or a Blob, or null for 204). */
372
+ export type BillingTransport = (request: BillingRequest) => Promise<unknown>;
373
+ export declare function readAccount(v: unknown): BillingAccount;
374
+ export declare function readPackageOption(v: unknown): BillingPackageOption;
375
+ export declare function readCheckoutSession(v: unknown): CheckoutSession;
376
+ export declare function readInvoice(v: unknown): BillingInvoice;
377
+ export declare function readContract(v: unknown): BillingContract;
378
+ export declare function readPaymentMethod(v: unknown): BillingPaymentMethod;
379
+ export declare function readPaymentStart(v: unknown): PaymentStart;
380
+ /**
381
+ * The billing part over a transport: each method is one route. `getManagementScopes` and
382
+ * `requestedScopes` are the account client's own, not routes, so the client adds them.
383
+ */
384
+ export declare function createBillingApi(send: BillingTransport): Omit<AccountBillingApi, "getManagementScopes" | "requestedScopes">;