@schematichq/schematic-components 2.29.1 → 2.31.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.
@@ -1,3 +1,4 @@
1
+ import { BillingActions } from '@schematichq/schematic-react';
1
2
  import { BillingData } from '@schematichq/schematic-react';
2
3
  import { BillingDataProvider } from '@schematichq/schematic-react';
3
4
  import { BillingDataProviderProps } from '@schematichq/schematic-react';
@@ -9,22 +10,30 @@ import { InvoicePage } from '@schematichq/schematic-react';
9
10
  import { InvoiceQuery } from '@schematichq/schematic-react';
10
11
  import type { InvoiceStatus } from '@schematichq/schematic-react';
11
12
  import { JSX } from 'react';
13
+ import { PaymentMethod } from '@schematichq/schematic-react';
14
+ import { PaymentMethodsHandle } from '@schematichq/schematic-react';
12
15
  import { default as React_2 } from 'react';
13
16
  import { ResourceHandle } from '@schematichq/schematic-react';
14
17
  import { ResourceState } from '@schematichq/schematic-react';
15
18
  import { SchematicI18nConfig } from '@schematichq/schematic-react';
16
19
  import { SchematicI18nProvider } from '@schematichq/schematic-react';
17
20
  import { SchematicI18nProviderProps } from '@schematichq/schematic-react';
21
+ import { SetupIntent } from '@schematichq/schematic-react';
22
+ import { SetupIntentHandle } from '@schematichq/schematic-react';
18
23
  import type { Translate } from '@schematichq/schematic-react';
19
24
  import { UpcomingInvoice } from '@schematichq/schematic-react';
20
25
  import { useInvalidateBillingData } from '@schematichq/schematic-react';
21
26
  import { useInvoices } from '@schematichq/schematic-react';
27
+ import { usePaymentMethods } from '@schematichq/schematic-react';
22
28
  import { useSchematicI18n } from '@schematichq/schematic-react';
23
29
  import { useSchematicLocale } from '@schematichq/schematic-react';
24
30
  import { useSchematicStrings } from '@schematichq/schematic-react';
25
31
  import { useSchematicTranslate } from '@schematichq/schematic-react';
32
+ import { useSetupIntent } from '@schematichq/schematic-react';
26
33
  import { useUpcomingInvoice } from '@schematichq/schematic-react';
27
34
 
35
+ export { BillingActions }
36
+
28
37
  export { BillingData }
29
38
 
30
39
  export { BillingDataProvider }
@@ -65,6 +74,18 @@ export declare interface BillLine {
65
74
  */
66
75
  export declare const DEFAULT_STRINGS: ElementStrings & StringCatalog;
67
76
 
77
+ export declare interface DerivedPaymentMethods {
78
+ /** Every method, in the order the server gave. */
79
+ rows: PaymentMethodRow[];
80
+ /** The default — the one the card shows — or null when none is. */
81
+ current: PaymentMethodRow | null;
82
+ /** Every row but the default; all of them when there is no default. */
83
+ others: PaymentMethodRow[];
84
+ /** The default card's months left, for the header's warning. */
85
+ monthsToExpiration: number | null;
86
+ expiryWarning: PaymentMethodExpiryWarning;
87
+ }
88
+
68
89
  export declare function deriveInvoiceList(page: InvoicePage, options: DeriveInvoiceListOptions): InvoiceList;
69
90
 
70
91
  export declare interface DeriveInvoiceListOptions {
@@ -72,6 +93,20 @@ export declare interface DeriveInvoiceListOptions {
72
93
  format?: InvoiceFormatters;
73
94
  }
74
95
 
96
+ /**
97
+ * The default is whichever row the server marked, which already prefers the
98
+ * subscription's method over the customer's. Nothing is promoted: a list
99
+ * with no default has no `current`, and every row is among the `others`.
100
+ */
101
+ export declare function derivePaymentMethods(methods: PaymentMethod[], options: DerivePaymentMethodsOptions): DerivedPaymentMethods;
102
+
103
+ export declare interface DerivePaymentMethodsOptions {
104
+ /** Reserved for a formatted expiry; the short form is locale-free. */
105
+ locale: string;
106
+ /** The moment expiry is judged from. Default: the current time. */
107
+ now?: Date;
108
+ }
109
+
75
110
  export declare function deriveUpcomingInvoice(invoice: UpcomingInvoice, options: DeriveUpcomingInvoiceOptions): UpcomingBillSummary;
76
111
 
77
112
  export declare interface DeriveUpcomingInvoiceOptions {
@@ -151,6 +186,44 @@ export declare type ElementStrings = {
151
186
  upcomingBillDiscount: string;
152
187
  upcomingBillDiscountValue: string;
153
188
  upcomingBillDiscountRepeating: string;
189
+ paymentMethodsLoading: string;
190
+ paymentMethodsHeader: string;
191
+ paymentMethodsError: string;
192
+ paymentMethodsUnavailable: string;
193
+ paymentMethodsEmpty: string;
194
+ paymentMethodsEdit: string;
195
+ paymentMethodsAdd: string;
196
+ paymentMethodsExpiresInMonths: string;
197
+ paymentMethodsExpired: string;
198
+ paymentMethodsCardEndingIn: string;
199
+ paymentMethodsApplePayEndingIn: string;
200
+ paymentMethodsGooglePayEndingIn: string;
201
+ paymentMethodsApplePay: string;
202
+ paymentMethodsGooglePay: string;
203
+ paymentMethodsAmazonPayAccount: string;
204
+ paymentMethodsCashAppAccount: string;
205
+ paymentMethodsPayPalAccount: string;
206
+ paymentMethodsLinkAccount: string;
207
+ paymentMethodsBankAccount: string;
208
+ paymentMethodsGeneric: string;
209
+ paymentMethodsDialogTitle: string;
210
+ paymentMethodsClose: string;
211
+ paymentMethodsChooseDifferent: string;
212
+ paymentMethodsExpires: string;
213
+ paymentMethodsSetDefault: string;
214
+ paymentMethodsRemove: string;
215
+ paymentMethodsAddNew: string;
216
+ paymentMethodsSelectExisting: string;
217
+ paymentMethodsFormLoading: string;
218
+ paymentMethodsFormError: string;
219
+ paymentMethodsEmail: string;
220
+ paymentMethodsEmailPlaceholder: string;
221
+ paymentMethodsSetupError: string;
222
+ paymentMethodsSave: string;
223
+ paymentMethodsSaving: string;
224
+ paymentMethodsSaveError: string;
225
+ paymentMethodsSetDefaultError: string;
226
+ paymentMethodsRemoveError: string;
154
227
  };
155
228
 
156
229
  /**
@@ -189,6 +262,13 @@ export declare interface FormatCurrencyOptions {
189
262
  /** "August 21, 2026", in the viewer's time zone. Empty for an Invalid Date. */
190
263
  export declare function formatDate(date: Date, locale: string, options?: Intl.DateTimeFormatOptions): string;
191
264
 
265
+ /**
266
+ * "08/2027": a card's expiry as the locale writes a month and year. Empty
267
+ * for a month outside 1–12 or a year that is not a whole number, which is
268
+ * what a malformed row carries.
269
+ */
270
+ export declare function formatMonthYear(month: number, year: number, locale: string): string;
271
+
192
272
  export declare function formatNumber(value: number, locale: string, options?: Intl.NumberFormatOptions): string;
193
273
 
194
274
  /**
@@ -219,6 +299,16 @@ export declare type HeadingLevel = 2 | 3 | 4 | 5 | 6;
219
299
  */
220
300
  export declare function httpStatus(error: Error | undefined): number | undefined;
221
301
 
302
+ /**
303
+ * GENERATED by scripts/inline-icons.mjs from @schematichq/schematic-icons@0.8.0.
304
+ * Do not edit; run `pnpm run icons` after bumping the package.
305
+ *
306
+ * The icon font and its glyph rules, appended to the elements stylesheet by
307
+ * `<SchematicStyles />`. Glyphs render on `.schematic-icon
308
+ * .schematic-icon--<name>`.
309
+ */
310
+ export declare const iconsCss: string;
311
+
222
312
  /**
223
313
  * Fills `{{name}}` placeholders, i18next style. A placeholder with no value
224
314
  * is left as written so the omission is visible.
@@ -304,6 +394,139 @@ export declare interface InvoicesProps extends ElementProps {
304
394
  */
305
395
  export declare function lookup(catalog: StringCatalog | undefined, key: string, vars?: StringVars, locale?: string): string | undefined;
306
396
 
397
+ export { PaymentMethod }
398
+
399
+ /**
400
+ * `expired` once a card's month has arrived, so a card in its last month
401
+ * already reads as expired; `soon` when fewer than four months remain; `ok`
402
+ * beyond that; `none` for a method that does not expire.
403
+ */
404
+ export declare type PaymentMethodExpiry = "ok" | "soon" | "expired" | "none";
405
+
406
+ /** The header's warning: the default card's `expiry`, with nothing to warn
407
+ * of folded to `none`. */
408
+ export declare type PaymentMethodExpiryWarning = "none" | "soon" | "expired";
409
+
410
+ /**
411
+ * The glyph beside a row's label, by its name in the schematic-icons font:
412
+ * the card network where the font has its mark, a generic card otherwise,
413
+ * the wallet's own mark, a bank for a US bank account, and
414
+ * `generic-payment` for a type nobody mapped. The element renders it as
415
+ * `schematic-icon schematic-icon--<icon>`.
416
+ */
417
+ export declare type PaymentMethodIcon = "visa" | "mastercard" | "amex" | "credit" | "bank" | "applepay" | "google" | "cashapp" | "paypal" | "link" | "amazonpay" | "generic-payment";
418
+
419
+ /**
420
+ * `derivePaymentMethods`: the company's saved payment methods as rows, with
421
+ * the default singled out — it is the one the card shows — and the rest
422
+ * beside it, plus whether the default card is about to stop working.
423
+ *
424
+ * The provider's vocabulary stays here. A row says "Card ending in" and
425
+ * "8/27"; the element never reads `cardBrand` or does calendar arithmetic.
426
+ */
427
+ export declare type PaymentMethodKind = "card" | "bank" | "wallet" | "other";
428
+
429
+ /**
430
+ * What names a method. A `key` is copy to resolve through the translator
431
+ * ("Card ending in"); `text` is a value the provider supplied — a bank's
432
+ * name, the email behind a Link account.
433
+ */
434
+ export declare type PaymentMethodLabel = {
435
+ key: PaymentMethodLabelKey;
436
+ text?: undefined;
437
+ } | {
438
+ text: string;
439
+ key?: undefined;
440
+ };
441
+
442
+ /** The copy a row's label can ask for; each is a string key the host can
443
+ * translate. */
444
+ export declare type PaymentMethodLabelKey = Extract<StringKey, "paymentMethodsCardEndingIn" | "paymentMethodsApplePayEndingIn" | "paymentMethodsGooglePayEndingIn" | "paymentMethodsApplePay" | "paymentMethodsGooglePay" | "paymentMethodsAmazonPayAccount" | "paymentMethodsCashAppAccount" | "paymentMethodsPayPalAccount" | "paymentMethodsLinkAccount" | "paymentMethodsBankAccount" | "paymentMethodsGeneric">;
445
+
446
+ export declare interface PaymentMethodRow {
447
+ id: string;
448
+ /** The provider's id, which is what "set default" is asked with. */
449
+ externalId: string;
450
+ kind: PaymentMethodKind;
451
+ label: PaymentMethodLabel;
452
+ icon: PaymentMethodIcon;
453
+ /** The card brand, lowercased, else the raw type; for `[data-brand]`. */
454
+ brand: string;
455
+ /** The wire type as sent: `card`, `us_bank_account`, `link`, … */
456
+ type: string;
457
+ /** Digits that follow the label: "Card ending in" 4444. */
458
+ last4: string | null;
459
+ /** "8/27"; null when the method has none. */
460
+ expiresShort: string | null;
461
+ /** Whole months from the current month to the expiry month; null when the
462
+ * method has none. Zero or less is expired. */
463
+ monthsToExpiration: number | null;
464
+ expiry: PaymentMethodExpiry;
465
+ isDefault: boolean;
466
+ /** The server's answer, which already applies the last-method rules. */
467
+ canRemove: boolean;
468
+ }
469
+
470
+ /**
471
+ * The company's payment method on file: a pill naming the default, an expiry
472
+ * warning beside the heading, and an Edit that opens a dialog where the
473
+ * other saved methods can be made the default or removed and a new one
474
+ * added through Stripe.
475
+ *
476
+ * Inside the dialog the pill offers Remove and the other rows a remove
477
+ * control; each shows only where the server's
478
+ * `canRemove` allows it, which it refuses only for the last method on an
479
+ * active paid subscription.
480
+ */
481
+ export declare function PaymentMethods({ allowEdit, checkoutPrefill, checkoutSettings, className, headingLevel, locale: localeProp, showExpiration, showHeader, strings, }: PaymentMethodsProps): React_2.JSX.Element;
482
+
483
+ export declare namespace PaymentMethods {
484
+ var resources: readonly ["paymentMethods"];
485
+ }
486
+
487
+ /** Values the Add form starts with. */
488
+ export declare interface PaymentMethodsCheckoutPrefill {
489
+ billingDetails?: {
490
+ /** Fills the email field until the customer edits it. */
491
+ email?: string;
492
+ /** Fills the address fields' name, and is sent as the billing name
493
+ * whenever those fields are shown. */
494
+ name?: string;
495
+ };
496
+ }
497
+
498
+ /**
499
+ * What the Add form collects beyond Stripe's payment fields. Each defaults
500
+ * to false.
501
+ */
502
+ export declare interface PaymentMethodsCheckoutSettings {
503
+ /** An email field, sent to Stripe as the method's billing email. */
504
+ collectEmail?: boolean;
505
+ /** Stripe's billing address fields. */
506
+ collectAddress?: boolean;
507
+ /** A phone field; brings Stripe's address fields with it, without
508
+ * requiring the address to be complete. */
509
+ collectPhone?: boolean;
510
+ }
511
+
512
+ export { PaymentMethodsHandle }
513
+
514
+ export declare interface PaymentMethodsProps extends ElementProps {
515
+ /** The Edit (or Add) action and the dialog behind it. Default true. */
516
+ allowEdit?: boolean;
517
+ /** The "Payment Details" heading. Default true. */
518
+ showHeader?: boolean;
519
+ /** Heading level, so the card fits the host's outline. Default 2. */
520
+ headingLevel?: HeadingLevel;
521
+ /** The header's warning when the default card has expired or is about
522
+ * to. Default true. */
523
+ showExpiration?: boolean;
524
+ /** What the Add form collects beyond the payment fields. */
525
+ checkoutSettings?: PaymentMethodsCheckoutSettings;
526
+ /** Values the Add form starts with. */
527
+ checkoutPrefill?: PaymentMethodsCheckoutPrefill;
528
+ }
529
+
307
530
  /**
308
531
  * `other` is required because every language has it. Supply whichever other
309
532
  * categories the language uses: Polish needs `one`, `few`, and `many`;
@@ -357,7 +580,10 @@ export declare const SchematicStyles: React_2.FC;
357
580
 
358
581
  /**
359
582
  * The stylesheet `<SchematicStyles />` injects: the rules above with every
360
- * token's default inlined as a `var()` fallback.
583
+ * token's default inlined as a `var()` fallback, then the icon font and its
584
+ * glyph rules (see ./icons.ts). The font is appended after the substitution
585
+ * rather than run through it: nothing in it takes a token, and the base64
586
+ * is not something to search.
361
587
  */
362
588
  export declare const schematicStylesCss: string;
363
589
 
@@ -367,6 +593,10 @@ export declare const schematicStylesCss: string;
367
593
  */
368
594
  export declare const schematicTokensCss: string;
369
595
 
596
+ export { SetupIntent }
597
+
598
+ export { SetupIntentHandle }
599
+
370
600
  /** A flat catalogue, the shape of both a host's `strings` and the defaults. */
371
601
  export declare type StringCatalog = Record<string, string | undefined>;
372
602
 
@@ -462,6 +692,8 @@ export { useInvalidateBillingData }
462
692
 
463
693
  export { useInvoices }
464
694
 
695
+ export { usePaymentMethods }
696
+
465
697
  /**
466
698
  * The element's `locale` prop, else the provider's, else the viewer's.
467
699
  *
@@ -479,6 +711,8 @@ export { useSchematicStrings }
479
711
 
480
712
  export { useSchematicTranslate }
481
713
 
714
+ export { useSetupIntent }
715
+
482
716
  /**
483
717
  * Resolves copy in order: the element's `strings`, the provider's `strings`,
484
718
  * the provider's `translate`, then the English default.