@openrails/billing-ui 0.0.0-stage → 0.233.2

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.
Files changed (113) hide show
  1. package/CHANGELOG.md +351 -0
  2. package/LICENSE +21 -0
  3. package/README.md +260 -2
  4. package/dist/account/account-billing.d.ts +19 -0
  5. package/dist/account/cancel-dialog.d.ts +18 -0
  6. package/dist/account/change-card-dialog.d.ts +14 -0
  7. package/dist/account/format.d.ts +25 -0
  8. package/dist/account/notice.d.ts +3 -0
  9. package/dist/account/payment-history.d.ts +8 -0
  10. package/dist/account/payment-methods-panel.d.ts +17 -0
  11. package/dist/account/section.d.ts +27 -0
  12. package/dist/account/status-badge.d.ts +8 -0
  13. package/dist/account/subscriptions-panel.d.ts +19 -0
  14. package/dist/appearance.d.ts +23 -0
  15. package/dist/authenticate.d.ts +8 -0
  16. package/dist/checkout-frame.d.ts +17 -0
  17. package/dist/checkout-page.d.ts +21 -0
  18. package/dist/checkout.d.ts +24 -0
  19. package/dist/client/client.d.ts +181 -0
  20. package/dist/client/errors.d.ts +26 -0
  21. package/dist/client/generated/currencies.d.ts +1 -0
  22. package/dist/client/generated/error-codes.d.ts +7 -0
  23. package/dist/client/generated/routes.d.ts +775 -0
  24. package/dist/client/generated/wire.d.ts +682 -0
  25. package/dist/client/index.d.ts +4 -0
  26. package/dist/client/types.d.ts +800 -0
  27. package/dist/client-DXUPzA8C.js +889 -0
  28. package/dist/client-DXUPzA8C.js.map +1 -0
  29. package/dist/client.js +2 -0
  30. package/dist/components/billing-fields.d.ts +39 -0
  31. package/dist/components/card-brands.d.ts +6 -0
  32. package/dist/components/card-fields.d.ts +29 -0
  33. package/dist/components/ccbill-fields.d.ts +8 -0
  34. package/dist/components/methods.d.ts +13 -0
  35. package/dist/components/pay-button.d.ts +6 -0
  36. package/dist/components/qr.d.ts +6 -0
  37. package/dist/components/saved-methods.d.ts +9 -0
  38. package/dist/components/states.d.ts +10 -0
  39. package/dist/components/stripe-card.d.ts +17 -0
  40. package/dist/components/summary.d.ts +12 -0
  41. package/dist/components/ui/alert-dialog.d.ts +18 -0
  42. package/dist/components/ui/badge.d.ts +7 -0
  43. package/dist/components/ui/button.d.ts +8 -0
  44. package/dist/components/ui/card.d.ts +11 -0
  45. package/dist/components/ui/dialog.d.ts +17 -0
  46. package/dist/components/ui/input.d.ts +3 -0
  47. package/dist/components/ui/label.d.ts +3 -0
  48. package/dist/components/ui/radio-group.d.ts +5 -0
  49. package/dist/components/ui/separator.d.ts +3 -0
  50. package/dist/components/ui/skeleton.d.ts +2 -0
  51. package/dist/components/ui/spinner.d.ts +3 -0
  52. package/dist/components/ui/textarea.d.ts +3 -0
  53. package/dist/config-BQELtBh4.js +341 -0
  54. package/dist/config-BQELtBh4.js.map +1 -0
  55. package/dist/dist-CslWupfi.js +3311 -0
  56. package/dist/dist-CslWupfi.js.map +1 -0
  57. package/dist/fixtures.d.ts +9 -0
  58. package/dist/frame.d.ts +47 -0
  59. package/dist/i18n/context.d.ts +4 -0
  60. package/dist/i18n/index.d.ts +2 -0
  61. package/dist/i18n/messages.d.ts +58 -0
  62. package/dist/index.d.ts +29 -0
  63. package/dist/index.js +4090 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/lib/billing.d.ts +39 -0
  66. package/dist/lib/card-brands.d.ts +2 -0
  67. package/dist/lib/card-entry.d.ts +46 -0
  68. package/dist/lib/ccbill.d.ts +8 -0
  69. package/dist/lib/collect.d.ts +51 -0
  70. package/dist/lib/money.d.ts +10 -0
  71. package/dist/lib/period.d.ts +13 -0
  72. package/dist/lib/rail-meta.d.ts +15 -0
  73. package/dist/lib/redirect.d.ts +2 -0
  74. package/dist/lib/stripe-appearance.d.ts +2 -0
  75. package/dist/lib/stripe.d.ts +2 -0
  76. package/dist/locales/de.d.ts +2 -0
  77. package/dist/locales/de.js +207 -0
  78. package/dist/locales/de.js.map +1 -0
  79. package/dist/locales/en.d.ts +204 -0
  80. package/dist/locales/en.js +207 -0
  81. package/dist/locales/en.js.map +1 -0
  82. package/dist/locales/es.d.ts +2 -0
  83. package/dist/locales/es.js +207 -0
  84. package/dist/locales/es.js.map +1 -0
  85. package/dist/locales/ja.d.ts +2 -0
  86. package/dist/locales/ja.js +198 -0
  87. package/dist/locales/ja.js.map +1 -0
  88. package/dist/locales/ko.d.ts +2 -0
  89. package/dist/locales/ko.js +198 -0
  90. package/dist/locales/ko.js.map +1 -0
  91. package/dist/locales/zh.d.ts +2 -0
  92. package/dist/locales/zh.js +198 -0
  93. package/dist/locales/zh.js.map +1 -0
  94. package/dist/modal.d.ts +12 -0
  95. package/dist/provider.d.ts +18 -0
  96. package/dist/psp.d.ts +35 -0
  97. package/dist/react/config.d.ts +34 -0
  98. package/dist/react/context.d.ts +35 -0
  99. package/dist/react/hooks.d.ts +82 -0
  100. package/dist/react/index.d.ts +4 -0
  101. package/dist/react/provider.d.ts +10 -0
  102. package/dist/react/remote.d.ts +10 -0
  103. package/dist/react.js +33 -0
  104. package/dist/react.js.map +1 -0
  105. package/dist/save-payment-method.d.ts +26 -0
  106. package/dist/scope-context.d.ts +17 -0
  107. package/dist/scope.d.ts +6 -0
  108. package/dist/source.d.ts +5 -0
  109. package/dist/styles.css +3 -0
  110. package/dist/tokenized-card-form.d.ts +24 -0
  111. package/dist/types.d.ts +250 -0
  112. package/docs/payment-form-contract.md +136 -0
  113. package/package.json +112 -3
@@ -0,0 +1,82 @@
1
+ import { SendSolanaTransaction } from '../client/client';
2
+ import { BillingError } from '../client/errors';
3
+ import { NewCard, Payment, PaymentMethod, Product, Subscription, TierChange } from '../client/types';
4
+ export type ActionResult = Promise<BillingError | null>;
5
+ /** `signing` and `confirming` are a wallet step's stages. */
6
+ export type SubscriptionAction = "cancel" | "resume" | "payment_method" | "change_tier" | "signing" | "confirming";
7
+ export interface SubscriptionsOptions {
8
+ /** Server filter; default `all`. */
9
+ status?: string;
10
+ limit?: number;
11
+ }
12
+ export interface SubscriptionsState {
13
+ subscriptions: Subscription[] | null;
14
+ /** The next page's cursor; null on the last page. */
15
+ nextCursor: string | null;
16
+ loading: boolean;
17
+ error: BillingError | null;
18
+ refetch: () => void;
19
+ /** In-flight action per subscription id. */
20
+ pending: Readonly<Record<string, SubscriptionAction>>;
21
+ /**
22
+ * Cancels at period end. A Solana subscription is canceled by the wallet:
23
+ * pass `sendTransaction`; without it the cancel resolves to a
24
+ * `wallet_required` error.
25
+ */
26
+ cancel: (subscriptionId: string, reason: string, sendTransaction?: SendSolanaTransaction) => ActionResult;
27
+ resume: (subscriptionId: string) => ActionResult;
28
+ setPaymentMethod: (subscriptionId: string, paymentMethodId: string) => ActionResult;
29
+ /**
30
+ * Resolves to the change, whose `status` may still be `processing` or
31
+ * `requires_action`, or to the error. A Solana change is signed with
32
+ * `sendTransaction` and resolves once the chain confirms it.
33
+ */
34
+ changeTier: (subscriptionId: string, input: {
35
+ priceId: string;
36
+ idempotencyKey: string;
37
+ }, sendTransaction?: SendSolanaTransaction) => Promise<TierChange | BillingError>;
38
+ }
39
+ export declare function useSubscriptions(options?: SubscriptionsOptions): SubscriptionsState;
40
+ export interface ProductsState {
41
+ products: Product[] | null;
42
+ /** The cursor of the next page; null on the last. */
43
+ nextCursor: string | null;
44
+ loading: boolean;
45
+ error: BillingError | null;
46
+ refetch: () => void;
47
+ }
48
+ /** The catalog: active products with their active prices. */
49
+ export declare function useProducts(options?: {
50
+ limit?: number;
51
+ }): ProductsState;
52
+ export type PaymentMethodAction = "remove" | "collection";
53
+ export interface PaymentMethodsState {
54
+ methods: PaymentMethod[] | null;
55
+ loading: boolean;
56
+ error: BillingError | null;
57
+ refetch: () => void;
58
+ pending: Readonly<Record<string, PaymentMethodAction>>;
59
+ adding: boolean;
60
+ add: (card: NewCard) => ActionResult;
61
+ remove: (paymentMethodId: string) => ActionResult;
62
+ /** Makes the card the one that collects one currency's invoices. */
63
+ setCollection: (paymentMethodId: string, currency: string) => ActionResult;
64
+ }
65
+ export declare function usePaymentMethods(): PaymentMethodsState;
66
+ export interface PaymentsOptions {
67
+ pageSize?: number;
68
+ /** Filter by rail. */
69
+ rail?: string;
70
+ }
71
+ export interface PaymentsState {
72
+ payments: Payment[] | null;
73
+ /** Zero-based. */
74
+ page: number;
75
+ hasMore: boolean;
76
+ loading: boolean;
77
+ error: BillingError | null;
78
+ next: () => void;
79
+ previous: () => void;
80
+ refetch: () => void;
81
+ }
82
+ export declare function usePayments(options?: PaymentsOptions): PaymentsState;
@@ -0,0 +1,4 @@
1
+ export { BillingProvider, type BillingProviderProps } from './provider';
2
+ export { useBillingClient, useBillingRefresh, useOptionalBillingContext, type BillingChange, type BillingContextValue, } from './context';
3
+ export { useConfig, useCurrencyScales, type ConfigState, type ConfigStore, } from './config';
4
+ export { usePaymentMethods, usePayments, useProducts, useSubscriptions, type ActionResult, type PaymentMethodAction, type PaymentMethodsState, type PaymentsOptions, type PaymentsState, type ProductsState, type SubscriptionAction, type SubscriptionsOptions, type SubscriptionsState, } from './hooks';
@@ -0,0 +1,10 @@
1
+ import { ReactNode } from 'react';
2
+ import { BillingClient } from '../client/client';
3
+ import { BillingChange } from './context';
4
+ export interface BillingProviderProps {
5
+ client: BillingClient;
6
+ /** Fires after each successful mutation: the host's cache-invalidation hook. */
7
+ onChange?: (change: BillingChange) => void;
8
+ children?: ReactNode;
9
+ }
10
+ export declare function BillingProvider({ client, onChange, children, }: BillingProviderProps): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { BillingError } from '../client/errors';
2
+ export interface RemoteState<T> {
3
+ data: T | null;
4
+ loading: boolean;
5
+ error: BillingError | null;
6
+ refetch: () => void;
7
+ }
8
+ export declare function useRemote<T>(key: string, load: (signal: AbortSignal) => Promise<T>): RemoteState<T> & {
9
+ replace: (update: (data: T) => T) => void;
10
+ };
package/dist/react.js ADDED
@@ -0,0 +1,33 @@
1
+ import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u } from "./config-BQELtBh4.js";
2
+ import { useCallback as d, useEffect as f, useMemo as p, useRef as m, useState as h } from "react";
3
+ import { jsx as g } from "react/jsx-runtime";
4
+ //#region src/react/provider.tsx
5
+ function _({ client: e, onChange: n, children: r }) {
6
+ let [i, a] = h(0), o = m(n);
7
+ f(() => {
8
+ o.current = n;
9
+ });
10
+ let s = d((e) => {
11
+ a((e) => e + 1), o.current?.(e);
12
+ }, []), c = d(() => a((e) => e + 1), []), l = p(() => u(e), [e]), _ = p(() => ({
13
+ client: e,
14
+ version: i,
15
+ notify: s,
16
+ refresh: c,
17
+ config: l
18
+ }), [
19
+ e,
20
+ i,
21
+ s,
22
+ c,
23
+ l
24
+ ]);
25
+ return /* @__PURE__ */ g(t.Provider, {
26
+ value: _,
27
+ children: r
28
+ });
29
+ }
30
+ //#endregion
31
+ export { _ as BillingProvider, a as useBillingClient, n as useBillingRefresh, o as useConfig, c as useCurrencyScales, r as useOptionalBillingContext, i as usePaymentMethods, e as usePayments, s as useProducts, l as useSubscriptions };
32
+
33
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","names":[],"sources":["../src/react/provider.tsx"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from \"react\"\n\nimport type { BillingClient } from \"../client/client\"\nimport { createConfigStore } from \"./config\"\nimport { BillingContext, type BillingChange } from \"./context\"\n\nexport interface BillingProviderProps {\n client: BillingClient\n /** Fires after each successful mutation: the host's cache-invalidation hook. */\n onChange?: (change: BillingChange) => void\n children?: ReactNode\n}\n\nexport function BillingProvider({\n client,\n onChange,\n children,\n}: BillingProviderProps) {\n const [version, setVersion] = useState(0)\n const onChangeRef = useRef(onChange)\n useEffect(() => {\n onChangeRef.current = onChange\n })\n const notify = useCallback((change: BillingChange) => {\n setVersion((v) => v + 1)\n onChangeRef.current?.(change)\n }, [])\n const refresh = useCallback(() => setVersion((v) => v + 1), [])\n const config = useMemo(() => createConfigStore(client), [client])\n const value = useMemo(\n () => ({ client, version, notify, refresh, config }),\n [client, version, notify, refresh, config]\n )\n return (\n <BillingContext.Provider value={value}>{children}</BillingContext.Provider>\n )\n}\n"],"mappings":";;;;AAoBA,SAAgB,EAAgB,EAC9B,WACA,aACA,eACuB;CACvB,IAAM,CAAC,GAAS,KAAc,EAAS,CAAC,GAClC,IAAc,EAAO,CAAQ;CACnC,QAAgB;EACd,EAAY,UAAU;CACxB,CAAC;CACD,IAAM,IAAS,GAAa,MAA0B;EAEpD,AADA,GAAY,MAAM,IAAI,CAAC,GACvB,EAAY,UAAU,CAAM;CAC9B,GAAG,CAAC,CAAC,GACC,IAAU,QAAkB,GAAY,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,GACxD,IAAS,QAAc,EAAkB,CAAM,GAAG,CAAC,CAAM,CAAC,GAC1D,IAAQ,SACL;EAAE;EAAQ;EAAS;EAAQ;EAAS;CAAO,IAClD;EAAC;EAAQ;EAAS;EAAQ;EAAS;CAAM,CAC3C;CACA,OACE,kBAAC,EAAe,UAAhB;EAAgC;EAAQ;CAAkC,CAAA;AAE9E"}
@@ -0,0 +1,26 @@
1
+ import { CheckoutAppearance } from './appearance';
2
+ import { PspConfig } from './psp';
3
+ import * as React from "react";
4
+ export interface SavePaymentMethodProps {
5
+ /** The PSP to save the card with, from OpenRails's payment config. */
6
+ psp: PspConfig;
7
+ onSaved: (paymentMethodId: string) => void;
8
+ /**
9
+ * Where the provider returns after an off-page verification (3-D Secure),
10
+ * given the setup id to confirm with `client.confirmCardSetup`. Default:
11
+ * the current page with `?setup_id=`.
12
+ */
13
+ returnURL?: (setupId: string) => string;
14
+ /** Billing country to preselect; default: the browser locale's region. */
15
+ defaultCountry?: string;
16
+ submitLabel?: string;
17
+ appearance?: CheckoutAppearance;
18
+ className?: string;
19
+ }
20
+ /**
21
+ * Saves a card to the customer's account with any PSP OpenRails serves, in
22
+ * the page. The PSP's configuration picks the flow: card data enters the
23
+ * provider's own frames, or, for a PSP whose card_entry is server, is posted
24
+ * to OpenRails. Requires `BillingProvider`.
25
+ */
26
+ export declare function SavePaymentMethod(props: SavePaymentMethodProps): React.JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { CSSProperties } from 'react';
2
+ import { CheckoutAppearance, CheckoutTheme } from './appearance';
3
+ export type Navigate = (to: string) => void;
4
+ export interface UiSettings {
5
+ appearance?: CheckoutAppearance;
6
+ locale?: string;
7
+ navigate?: Navigate;
8
+ }
9
+ export declare const UiContext: import('react').Context<UiSettings>;
10
+ export declare const useUiSettings: () => UiSettings;
11
+ export interface ScopeProps {
12
+ className: string;
13
+ "data-orck-theme": CheckoutTheme;
14
+ style?: CSSProperties;
15
+ }
16
+ /** Props that make an element a styling root; portals carry them too. */
17
+ export declare function useScopeProps(appearance?: CheckoutAppearance): ScopeProps;
@@ -0,0 +1,6 @@
1
+ import { ComponentProps } from 'react';
2
+ import { CheckoutAppearance } from './appearance';
3
+ /** Styling root for in-page billing surfaces. */
4
+ export declare function BillingUiRoot({ appearance, className, style, ...props }: ComponentProps<"div"> & {
5
+ appearance?: CheckoutAppearance;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { CheckoutSession, PayRequest, PayResult } from './types';
2
+ export interface CheckoutSource {
3
+ getSession(): Promise<CheckoutSession>;
4
+ pay(request: PayRequest): Promise<PayResult>;
5
+ }