@openrails/billing-ui 0.0.0-stage → 0.230.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.
- package/CHANGELOG.md +257 -0
- package/LICENSE +21 -0
- package/README.md +211 -2
- package/dist/account/account-billing.d.ts +19 -0
- package/dist/account/cancel-dialog.d.ts +18 -0
- package/dist/account/change-card-dialog.d.ts +14 -0
- package/dist/account/format.d.ts +25 -0
- package/dist/account/notice.d.ts +3 -0
- package/dist/account/payment-history.d.ts +8 -0
- package/dist/account/payment-methods-panel.d.ts +19 -0
- package/dist/account/section.d.ts +25 -0
- package/dist/account/status-badge.d.ts +8 -0
- package/dist/account/subscriptions-panel.d.ts +19 -0
- package/dist/appearance.d.ts +23 -0
- package/dist/authenticate.d.ts +8 -0
- package/dist/checkout-frame.d.ts +17 -0
- package/dist/checkout-page.d.ts +16 -0
- package/dist/checkout.d.ts +24 -0
- package/dist/client/client.d.ts +167 -0
- package/dist/client/errors.d.ts +26 -0
- package/dist/client/generated/openrails-routes.d.ts +2 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/types.d.ts +754 -0
- package/dist/client-DhG2jv34.js +771 -0
- package/dist/client-DhG2jv34.js.map +1 -0
- package/dist/client.js +3 -0
- package/dist/components/billing-fields.d.ts +39 -0
- package/dist/components/card-brands.d.ts +6 -0
- package/dist/components/card-fields.d.ts +29 -0
- package/dist/components/ccbill-fields.d.ts +8 -0
- package/dist/components/methods.d.ts +13 -0
- package/dist/components/pay-button.d.ts +6 -0
- package/dist/components/qr.d.ts +6 -0
- package/dist/components/saved-methods.d.ts +9 -0
- package/dist/components/states.d.ts +10 -0
- package/dist/components/stripe-card.d.ts +17 -0
- package/dist/components/summary.d.ts +12 -0
- package/dist/components/ui/alert-dialog.d.ts +18 -0
- package/dist/components/ui/badge.d.ts +7 -0
- package/dist/components/ui/button.d.ts +8 -0
- package/dist/components/ui/card.d.ts +11 -0
- package/dist/components/ui/dialog.d.ts +17 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/label.d.ts +3 -0
- package/dist/components/ui/radio-group.d.ts +5 -0
- package/dist/components/ui/separator.d.ts +3 -0
- package/dist/components/ui/skeleton.d.ts +2 -0
- package/dist/components/ui/spinner.d.ts +3 -0
- package/dist/components/ui/textarea.d.ts +3 -0
- package/dist/dist-CslWupfi.js +3311 -0
- package/dist/dist-CslWupfi.js.map +1 -0
- package/dist/errors-T-PRm3vV.js +54 -0
- package/dist/errors-T-PRm3vV.js.map +1 -0
- package/dist/fixtures.d.ts +9 -0
- package/dist/frame.d.ts +47 -0
- package/dist/hooks-DLFF-zx5.js +285 -0
- package/dist/hooks-DLFF-zx5.js.map +1 -0
- package/dist/i18n/context.d.ts +4 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/messages.d.ts +58 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +4182 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/billing.d.ts +25 -0
- package/dist/lib/card-brands.d.ts +2 -0
- package/dist/lib/card-entry.d.ts +46 -0
- package/dist/lib/ccbill.d.ts +8 -0
- package/dist/lib/collect.d.ts +51 -0
- package/dist/lib/money.d.ts +9 -0
- package/dist/lib/period.d.ts +15 -0
- package/dist/lib/rail-meta.d.ts +15 -0
- package/dist/lib/redirect.d.ts +2 -0
- package/dist/lib/stripe-appearance.d.ts +2 -0
- package/dist/lib/stripe.d.ts +2 -0
- package/dist/locales/de.d.ts +2 -0
- package/dist/locales/de.js +204 -0
- package/dist/locales/de.js.map +1 -0
- package/dist/locales/en.d.ts +201 -0
- package/dist/locales/en.js +204 -0
- package/dist/locales/en.js.map +1 -0
- package/dist/locales/es.d.ts +2 -0
- package/dist/locales/es.js +204 -0
- package/dist/locales/es.js.map +1 -0
- package/dist/locales/ja.d.ts +2 -0
- package/dist/locales/ja.js +195 -0
- package/dist/locales/ja.js.map +1 -0
- package/dist/locales/ko.d.ts +2 -0
- package/dist/locales/ko.js +195 -0
- package/dist/locales/ko.js.map +1 -0
- package/dist/locales/zh.d.ts +2 -0
- package/dist/locales/zh.js +195 -0
- package/dist/locales/zh.js.map +1 -0
- package/dist/modal.d.ts +12 -0
- package/dist/provider.d.ts +18 -0
- package/dist/psp.d.ts +46 -0
- package/dist/react/context.d.ts +38 -0
- package/dist/react/hooks.d.ts +76 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/provider.d.ts +18 -0
- package/dist/react/remote.d.ts +11 -0
- package/dist/react.js +37 -0
- package/dist/react.js.map +1 -0
- package/dist/save-payment-method.d.ts +26 -0
- package/dist/scope-context.d.ts +17 -0
- package/dist/scope.d.ts +6 -0
- package/dist/source.d.ts +14 -0
- package/dist/styles.css +3 -0
- package/dist/tokenized-card-form.d.ts +24 -0
- package/dist/types.d.ts +191 -0
- package/docs/1055-nmi-host-integration.md +28 -0
- package/docs/payment-form-contract.md +153 -0
- package/package.json +112 -3
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SendSolanaTransaction, SolanaCancelStage } 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
|
+
export type SubscriptionAction = "cancel" | "resume" | "payment_method" | "change_tier" | SolanaCancelStage;
|
|
6
|
+
export interface SubscriptionsOptions {
|
|
7
|
+
/** Server filter; default `all`. */
|
|
8
|
+
status?: string;
|
|
9
|
+
limit?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SubscriptionsState {
|
|
12
|
+
subscriptions: Subscription[] | null;
|
|
13
|
+
total: number | null;
|
|
14
|
+
loading: boolean;
|
|
15
|
+
error: BillingError | null;
|
|
16
|
+
refetch: () => void;
|
|
17
|
+
/** In-flight action per subscription id. */
|
|
18
|
+
pending: Readonly<Record<string, SubscriptionAction>>;
|
|
19
|
+
cancel: (subscriptionId: string, feedback: string) => ActionResult;
|
|
20
|
+
/** Solana rail: the wallet signs the server-prepared cancel transaction. */
|
|
21
|
+
cancelOnChain: (subscriptionId: string, sendTransaction: SendSolanaTransaction) => ActionResult;
|
|
22
|
+
resume: (subscriptionId: string) => ActionResult;
|
|
23
|
+
setPaymentMethod: (subscriptionId: string, paymentMethodId: string) => ActionResult;
|
|
24
|
+
/**
|
|
25
|
+
* Card rails: `client.changeTier`. Resolves to the change, whose `status`
|
|
26
|
+
* may still be `processing` or `requires_action`, or to the error.
|
|
27
|
+
*/
|
|
28
|
+
changeTier: (subscriptionId: string, input: {
|
|
29
|
+
priceId: string;
|
|
30
|
+
idempotencyKey: string;
|
|
31
|
+
}) => Promise<TierChange | BillingError>;
|
|
32
|
+
}
|
|
33
|
+
export declare function useSubscriptions(options?: SubscriptionsOptions): SubscriptionsState;
|
|
34
|
+
export interface ProductsState {
|
|
35
|
+
products: Product[] | null;
|
|
36
|
+
total: number | null;
|
|
37
|
+
loading: boolean;
|
|
38
|
+
error: BillingError | null;
|
|
39
|
+
refetch: () => void;
|
|
40
|
+
}
|
|
41
|
+
/** The catalog: active products with their active prices. */
|
|
42
|
+
export declare function useProducts(options?: {
|
|
43
|
+
limit?: number;
|
|
44
|
+
}): ProductsState;
|
|
45
|
+
export type PaymentMethodAction = "remove" | "default";
|
|
46
|
+
export interface PaymentMethodsState {
|
|
47
|
+
methods: PaymentMethod[] | null;
|
|
48
|
+
loading: boolean;
|
|
49
|
+
error: BillingError | null;
|
|
50
|
+
refetch: () => void;
|
|
51
|
+
pending: Readonly<Record<string, PaymentMethodAction>>;
|
|
52
|
+
adding: boolean;
|
|
53
|
+
add: (card: NewCard) => ActionResult;
|
|
54
|
+
remove: (paymentMethodId: string) => ActionResult;
|
|
55
|
+
/** Default collector for one currency's invoices. */
|
|
56
|
+
setDefault: (paymentMethodId: string, currency: string) => ActionResult;
|
|
57
|
+
}
|
|
58
|
+
export declare function usePaymentMethods(): PaymentMethodsState;
|
|
59
|
+
export interface PaymentsOptions {
|
|
60
|
+
pageSize?: number;
|
|
61
|
+
/** Filter by rail. */
|
|
62
|
+
rail?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface PaymentsState {
|
|
65
|
+
payments: Payment[] | null;
|
|
66
|
+
/** Zero-based. */
|
|
67
|
+
page: number;
|
|
68
|
+
hasMore: boolean;
|
|
69
|
+
total: number | null;
|
|
70
|
+
loading: boolean;
|
|
71
|
+
error: BillingError | null;
|
|
72
|
+
next: () => void;
|
|
73
|
+
previous: () => void;
|
|
74
|
+
refetch: () => void;
|
|
75
|
+
}
|
|
76
|
+
export declare function usePayments(options?: PaymentsOptions): PaymentsState;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { BillingProvider, type BillingProviderProps } from './provider';
|
|
2
|
+
export { useBillingClient, useBillingRefresh, useOptionalBillingContext, type BillingChange, type BillingContextValue, } from './context';
|
|
3
|
+
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,18 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Cancel and resume are queued server-side (202); hooks re-read the
|
|
10
|
+
* subscription until the change shows. Default 1000 ms x 10.
|
|
11
|
+
*/
|
|
12
|
+
settle?: {
|
|
13
|
+
intervalMs?: number;
|
|
14
|
+
attempts?: number;
|
|
15
|
+
};
|
|
16
|
+
children?: ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export declare function BillingProvider({ client, onChange, settle, children, }: BillingProviderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
};
|
|
11
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, t as s } from "./hooks-DLFF-zx5.js";
|
|
2
|
+
import { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
|
|
3
|
+
import { jsx as p } from "react/jsx-runtime";
|
|
4
|
+
//#region src/react/provider.tsx
|
|
5
|
+
function m({ client: t, onChange: n, settle: r, children: i }) {
|
|
6
|
+
let [a, o] = f(0), s = d(n);
|
|
7
|
+
l(() => {
|
|
8
|
+
s.current = n;
|
|
9
|
+
});
|
|
10
|
+
let m = c((e) => {
|
|
11
|
+
o((e) => e + 1), s.current?.(e);
|
|
12
|
+
}, []), h = c(() => o((e) => e + 1), []), g = r?.intervalMs ?? 1e3, _ = r?.attempts ?? 10, v = u(() => ({
|
|
13
|
+
client: t,
|
|
14
|
+
version: a,
|
|
15
|
+
notify: m,
|
|
16
|
+
refresh: h,
|
|
17
|
+
settle: {
|
|
18
|
+
intervalMs: g,
|
|
19
|
+
attempts: _
|
|
20
|
+
}
|
|
21
|
+
}), [
|
|
22
|
+
t,
|
|
23
|
+
a,
|
|
24
|
+
m,
|
|
25
|
+
h,
|
|
26
|
+
g,
|
|
27
|
+
_
|
|
28
|
+
]);
|
|
29
|
+
return /* @__PURE__ */ p(e.Provider, {
|
|
30
|
+
value: v,
|
|
31
|
+
children: i
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { m as BillingProvider, a as useBillingClient, t as useBillingRefresh, r as useOptionalBillingContext, s as usePaymentMethods, i as usePayments, o as useProducts, n as useSubscriptions };
|
|
36
|
+
|
|
37
|
+
//# 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 { 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 /**\n * Cancel and resume are queued server-side (202); hooks re-read the\n * subscription until the change shows. Default 1000 ms x 10.\n */\n settle?: { intervalMs?: number; attempts?: number }\n children?: ReactNode\n}\n\nexport function BillingProvider({\n client,\n onChange,\n settle,\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 intervalMs = settle?.intervalMs ?? 1000\n const attempts = settle?.attempts ?? 10\n const value = useMemo(\n () => ({\n client,\n version,\n notify,\n refresh,\n settle: { intervalMs, attempts },\n }),\n [client, version, notify, refresh, intervalMs, attempts]\n )\n return (\n <BillingContext.Provider value={value}>{children}</BillingContext.Provider>\n )\n}\n"],"mappings":";;;;AAwBA,SAAgB,EAAgB,EAC9B,WACA,aACA,WACA,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,IAAa,GAAQ,cAAc,KACnC,IAAW,GAAQ,YAAY,IAC/B,IAAQ,SACL;EACL;EACA;EACA;EACA;EACA,QAAQ;GAAE;GAAY;EAAS;CACjC,IACA;EAAC;EAAQ;EAAS;EAAQ;EAAS;EAAY;CAAQ,CACzD;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 checkout 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;
|
package/dist/scope.d.ts
ADDED
|
@@ -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;
|
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CheckoutSession, PayRequest, PayResult } from './types';
|
|
2
|
+
export interface CheckoutSource {
|
|
3
|
+
getSession(): Promise<CheckoutSession>;
|
|
4
|
+
pay(request: PayRequest): Promise<PayResult>;
|
|
5
|
+
}
|
|
6
|
+
export declare class CheckoutSourceError extends Error {
|
|
7
|
+
readonly status?: number;
|
|
8
|
+
constructor(message: string, status?: number);
|
|
9
|
+
}
|
|
10
|
+
export declare function createHttpSource(options: {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
sessionId: string;
|
|
13
|
+
fetch?: typeof fetch;
|
|
14
|
+
}): CheckoutSource;
|