@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.
- package/CHANGELOG.md +351 -0
- package/LICENSE +21 -0
- package/README.md +260 -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 +17 -0
- package/dist/account/section.d.ts +27 -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 +21 -0
- package/dist/checkout.d.ts +24 -0
- package/dist/client/client.d.ts +181 -0
- package/dist/client/errors.d.ts +26 -0
- package/dist/client/generated/currencies.d.ts +1 -0
- package/dist/client/generated/error-codes.d.ts +7 -0
- package/dist/client/generated/routes.d.ts +775 -0
- package/dist/client/generated/wire.d.ts +682 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/types.d.ts +800 -0
- package/dist/client-DXUPzA8C.js +889 -0
- package/dist/client-DXUPzA8C.js.map +1 -0
- package/dist/client.js +2 -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/config-BQELtBh4.js +341 -0
- package/dist/config-BQELtBh4.js.map +1 -0
- package/dist/dist-CslWupfi.js +3311 -0
- package/dist/dist-CslWupfi.js.map +1 -0
- package/dist/fixtures.d.ts +9 -0
- package/dist/frame.d.ts +47 -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 +4090 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/billing.d.ts +39 -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 +10 -0
- package/dist/lib/period.d.ts +13 -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 +207 -0
- package/dist/locales/de.js.map +1 -0
- package/dist/locales/en.d.ts +204 -0
- package/dist/locales/en.js +207 -0
- package/dist/locales/en.js.map +1 -0
- package/dist/locales/es.d.ts +2 -0
- package/dist/locales/es.js +207 -0
- package/dist/locales/es.js.map +1 -0
- package/dist/locales/ja.d.ts +2 -0
- package/dist/locales/ja.js +198 -0
- package/dist/locales/ja.js.map +1 -0
- package/dist/locales/ko.d.ts +2 -0
- package/dist/locales/ko.js +198 -0
- package/dist/locales/ko.js.map +1 -0
- package/dist/locales/zh.d.ts +2 -0
- package/dist/locales/zh.js +198 -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 +35 -0
- package/dist/react/config.d.ts +34 -0
- package/dist/react/context.d.ts +35 -0
- package/dist/react/hooks.d.ts +82 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/provider.d.ts +10 -0
- package/dist/react/remote.d.ts +10 -0
- package/dist/react.js +33 -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 +5 -0
- package/dist/styles.css +3 -0
- package/dist/tokenized-card-form.d.ts +24 -0
- package/dist/types.d.ts +250 -0
- package/docs/payment-form-contract.md +136 -0
- package/package.json +112 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CheckoutAppearance } from '../appearance';
|
|
2
|
+
import { BillingError } from '../client/errors';
|
|
3
|
+
import { SubscriptionAction } from '../react/hooks';
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
export interface CancelSubscriptionDialogProps {
|
|
6
|
+
open: boolean;
|
|
7
|
+
onOpenChange: (open: boolean) => void;
|
|
8
|
+
/** Subscription display name. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** On-chain (Solana) cancel: the wallet signs after the reason. */
|
|
11
|
+
onChain?: boolean;
|
|
12
|
+
/** In-flight stage, when cancelling. */
|
|
13
|
+
pending?: SubscriptionAction;
|
|
14
|
+
/** Resolves null on success; the dialog then closes. */
|
|
15
|
+
onConfirm: (reason: string) => Promise<BillingError | null>;
|
|
16
|
+
appearance?: CheckoutAppearance;
|
|
17
|
+
}
|
|
18
|
+
export declare function CancelSubscriptionDialog({ open, onOpenChange, name, onChain, pending, onConfirm, appearance, }: CancelSubscriptionDialogProps): React.JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CheckoutAppearance } from '../appearance';
|
|
2
|
+
import { BillingError } from '../client/errors';
|
|
3
|
+
import { Subscription } from '../client/types';
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
export interface ChangeCardDialogProps {
|
|
6
|
+
subscription: Subscription | null;
|
|
7
|
+
name: string;
|
|
8
|
+
onOpenChange: (open: boolean) => void;
|
|
9
|
+
pending: boolean;
|
|
10
|
+
/** Resolves null on success; the dialog then closes. */
|
|
11
|
+
onConfirm: (paymentMethodId: string) => Promise<BillingError | null>;
|
|
12
|
+
appearance?: CheckoutAppearance;
|
|
13
|
+
}
|
|
14
|
+
export declare function ChangeCardDialog({ subscription, name, onOpenChange, pending, onConfirm, appearance, }: ChangeCardDialogProps): React.JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CardSummary, CurrencyScales, Payment, Price, Subscription } from '../client/types';
|
|
2
|
+
import { Translator } from '../i18n/messages';
|
|
3
|
+
export declare function formatDate(value: string | null | undefined, locale?: string): string | null;
|
|
4
|
+
/** Exact money, or null while the currency's scale is unknown. */
|
|
5
|
+
export declare function formatMoney(amount: string | null | undefined, currency: string, scales: CurrencyScales, locale?: string): string | null;
|
|
6
|
+
/** "every 30 days", "30 days of access" or "one-time". */
|
|
7
|
+
export declare function intervalLabel(price: Pick<Price, "access_duration_hours" | "billing_interval_hours"> | null | undefined, m: Translator): string | null;
|
|
8
|
+
export declare function subscriptionName(s: Subscription, { t }: Translator): string;
|
|
9
|
+
/** What a payment bought: the product's name, else its kind, plus its cadence. */
|
|
10
|
+
export declare function paymentItem(p: Payment, m: Translator): {
|
|
11
|
+
name: string;
|
|
12
|
+
detail: string | null;
|
|
13
|
+
};
|
|
14
|
+
export declare function brandName(brand: string | null | undefined, fallback: string): string;
|
|
15
|
+
/** "Visa •••• 4242 · 12/30"; the brand alone when no digits are known. */
|
|
16
|
+
export declare function cardText(card: CardSummary | null | undefined, m: Translator): string;
|
|
17
|
+
export declare function expiry(card: CardSummary | null | undefined): string | null;
|
|
18
|
+
export declare const LIVE_STATUSES: Set<string>;
|
|
19
|
+
/** A current subscription, or a canceled subscription retaining paid access. */
|
|
20
|
+
export declare const isLive: (s: Subscription) => boolean;
|
|
21
|
+
/** Future billing has stopped or cancellation is scheduled. */
|
|
22
|
+
export declare const isEnding: (s: Subscription) => boolean;
|
|
23
|
+
export type StatusTone = "success" | "warning" | "destructive" | "neutral";
|
|
24
|
+
export declare const statusTone: (status: string) => StatusTone;
|
|
25
|
+
export declare const RESET = "[&_h2]:m-0 [&_p]:m-0 [&_ul]:m-0 [&_ul]:list-none [&_ul]:p-0 [&_table]:border-spacing-0";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CheckoutAppearance } from '../appearance';
|
|
2
|
+
import { PaymentsOptions } from '../react/hooks';
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export interface PaymentHistoryProps extends PaymentsOptions {
|
|
5
|
+
appearance?: CheckoutAppearance;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function PaymentHistory({ appearance, className, ...options }: PaymentHistoryProps): React.JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CheckoutAppearance } from '../appearance';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface PaymentMethodsPanelProps {
|
|
4
|
+
/** Return target after off-page card verification; see `SavePaymentMethod`. */
|
|
5
|
+
cardSetupReturnURL?: (setupId: string) => string;
|
|
6
|
+
/** Offers to make a card the one that collects this currency's invoices. */
|
|
7
|
+
collectionCurrency?: string;
|
|
8
|
+
/** Billing country to preselect when adding a card. */
|
|
9
|
+
defaultCountry?: string;
|
|
10
|
+
appearance?: CheckoutAppearance;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The customer's saved cards. "Add card" offers each PSP of the merchant's
|
|
15
|
+
* payment setup (`GET /config`) that saves a card in the page.
|
|
16
|
+
*/
|
|
17
|
+
export declare function PaymentMethodsPanel({ cardSetupReturnURL, collectionCurrency, defaultCountry, appearance, className, }: PaymentMethodsPanelProps): React.JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CheckoutAppearance } from '../appearance';
|
|
2
|
+
import { BillingError } from '../client/errors';
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export interface SectionProps {
|
|
5
|
+
title: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
action?: React.ReactNode;
|
|
8
|
+
appearance?: CheckoutAppearance;
|
|
9
|
+
className?: string;
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
"data-testid"?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function Section({ title, description, action, appearance, className, children, ...rest }: SectionProps): React.JSX.Element;
|
|
14
|
+
export declare function ListSkeleton({ rows }: {
|
|
15
|
+
rows?: number;
|
|
16
|
+
}): React.JSX.Element;
|
|
17
|
+
export declare function EmptyState({ title, description, action, }: {
|
|
18
|
+
title: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
action?: React.ReactNode;
|
|
21
|
+
}): React.JSX.Element;
|
|
22
|
+
export declare function ErrorState({ error, message, onRetry, }: {
|
|
23
|
+
error: BillingError;
|
|
24
|
+
/** Replaces the error's own message. */
|
|
25
|
+
message?: string;
|
|
26
|
+
onRetry: () => void;
|
|
27
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface BillingStatusBadgeProps {
|
|
2
|
+
/** Subscription, payment or card-health status. */
|
|
3
|
+
status: string;
|
|
4
|
+
/** Overrides the translated label. */
|
|
5
|
+
label?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function BillingStatusBadge({ status, label, className, }: BillingStatusBadgeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CheckoutAppearance } from '../appearance';
|
|
2
|
+
import { SendSolanaTransaction } from '../client/client';
|
|
3
|
+
import { Subscription } from '../client/types';
|
|
4
|
+
import { SubscriptionsOptions } from '../react/hooks';
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
export interface SubscriptionsPanelProps extends SubscriptionsOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Wallet for Solana-rail subscriptions. Without it their cancel action is
|
|
9
|
+
* hidden.
|
|
10
|
+
*/
|
|
11
|
+
sendSolanaTransaction?: SendSolanaTransaction;
|
|
12
|
+
/** Empty-state link to the host's plans page (uses `navigate` if set). */
|
|
13
|
+
plansHref?: string;
|
|
14
|
+
/** Host content under a row, e.g. a plan-change control. */
|
|
15
|
+
renderSubscriptionFooter?: (subscription: Subscription) => React.ReactNode;
|
|
16
|
+
appearance?: CheckoutAppearance;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function SubscriptionsPanel({ sendSolanaTransaction, plansHref, renderSubscriptionFooter, appearance, className, ...options }: SubscriptionsPanelProps): React.JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
export type CheckoutTheme = "light" | "dark" | "auto" | "inherit";
|
|
3
|
+
export interface CheckoutVariables {
|
|
4
|
+
background?: string;
|
|
5
|
+
foreground?: string;
|
|
6
|
+
card?: string;
|
|
7
|
+
mutedForeground?: string;
|
|
8
|
+
faintForeground?: string;
|
|
9
|
+
border?: string;
|
|
10
|
+
input?: string;
|
|
11
|
+
primary?: string;
|
|
12
|
+
primaryForeground?: string;
|
|
13
|
+
destructive?: string;
|
|
14
|
+
ring?: string;
|
|
15
|
+
radius?: string;
|
|
16
|
+
fontFamily?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CheckoutAppearance {
|
|
19
|
+
theme?: CheckoutTheme;
|
|
20
|
+
variables?: CheckoutVariables;
|
|
21
|
+
}
|
|
22
|
+
export declare function appearanceStyle(appearance: CheckoutAppearance | undefined): CSSProperties | undefined;
|
|
23
|
+
export declare function appearanceTheme(appearance: CheckoutAppearance | undefined): CheckoutTheme;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BillingClient } from './client/client';
|
|
2
|
+
import { PspConfig } from './psp';
|
|
3
|
+
/**
|
|
4
|
+
* Completes the provider challenge (3-D Secure) a pending payment operation
|
|
5
|
+
* waits on. "not_required" when the provider has none outstanding; the
|
|
6
|
+
* operation's own status remains the result.
|
|
7
|
+
*/
|
|
8
|
+
export declare function authenticatePayment(client: BillingClient, operationId: string, psp: PspConfig): Promise<"authenticated" | "not_required">;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CheckoutFrameTheme } from './frame';
|
|
2
|
+
import { CheckoutSessionStatus } from './types';
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export interface CheckoutFrameProps {
|
|
5
|
+
/** The minted session's `url` (createCheckoutSession). */
|
|
6
|
+
url: string;
|
|
7
|
+
onComplete?: (status: CheckoutSessionStatus) => void;
|
|
8
|
+
/** Default "auto": the buyer's system preference. */
|
|
9
|
+
theme?: CheckoutFrameTheme;
|
|
10
|
+
/** Accessible name of the frame. */
|
|
11
|
+
title?: string;
|
|
12
|
+
/** Height before the page reports its own, in pixels. Default 480. */
|
|
13
|
+
minHeight?: number;
|
|
14
|
+
className?: string;
|
|
15
|
+
style?: React.CSSProperties;
|
|
16
|
+
}
|
|
17
|
+
export declare function CheckoutFrame({ url, onComplete, theme, title, minHeight, className, style, }: CheckoutFrameProps): React.JSX.Element | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CheckoutAppearance } from './appearance';
|
|
2
|
+
import { CheckoutLayout } from './checkout';
|
|
3
|
+
import { BillingClient } from './client/client';
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
export interface CheckoutPageProps {
|
|
6
|
+
/** OpenRails mount on this host. Default "/billing/v1". */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** Replaces the client built from `baseUrl`. */
|
|
9
|
+
client?: BillingClient;
|
|
10
|
+
/**
|
|
11
|
+
* Pay as the signed-in customer on this customer surface (its `/me`
|
|
12
|
+
* prefix) instead of with the session id alone; see `checkoutSource`.
|
|
13
|
+
*/
|
|
14
|
+
customerBase?: string;
|
|
15
|
+
/** This host's branding; the framing app chooses the theme. */
|
|
16
|
+
appearance?: CheckoutAppearance;
|
|
17
|
+
layout?: CheckoutLayout;
|
|
18
|
+
defaultCountry?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function CheckoutPage({ baseUrl, client, customerBase, appearance, layout, defaultCountry, className, }: CheckoutPageProps): React.JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CheckoutAppearance } from './appearance';
|
|
2
|
+
import { CheckoutSource } from './source';
|
|
3
|
+
import { CheckoutPhase, PayResult } from './types';
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
export type CheckoutLayout = "auto" | "wide" | "compact";
|
|
6
|
+
export interface CheckoutProps {
|
|
7
|
+
source: CheckoutSource;
|
|
8
|
+
appearance?: CheckoutAppearance;
|
|
9
|
+
layout?: CheckoutLayout;
|
|
10
|
+
/** Billing country to preselect; default: the browser locale's region. */
|
|
11
|
+
defaultCountry?: string;
|
|
12
|
+
/** Return target after an off-page card verification (Stripe setup). */
|
|
13
|
+
cardSetupReturnURL?: (setupId: string) => string;
|
|
14
|
+
onComplete?: (result: PayResult) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Leaves for a redirect rail's page. Default: navigate the top window,
|
|
17
|
+
* which a nested frame may not do; <CheckoutPage> asks its app instead.
|
|
18
|
+
*/
|
|
19
|
+
onRedirect?: (url: string) => void;
|
|
20
|
+
onPhaseChange?: (phase: CheckoutPhase) => void;
|
|
21
|
+
completionMode?: "embedded" | "redirect";
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function Checkout({ source, appearance, layout, defaultCountry, cardSetupReturnURL, onComplete, onRedirect, onPhaseChange, completionMode, className, }: CheckoutProps): React.JSX.Element;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { CheckoutSource } from '../source';
|
|
2
|
+
import { CardSetup, CheckoutSessionLink, PublicConfig, PaymentAuthentication, CurrencyScales, Invoice, ListPage, NewCard, NextAction, Page, Payment, PaymentMethod, Product, SolanaToken, Subscription, TierChange, TierChangePreview } from './types';
|
|
3
|
+
export interface BillingClientOptions {
|
|
4
|
+
/** OpenRails embedded mount. Default "/billing/v1". */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Transport. Pass an authenticating fetch (auth-ui's `client.authFetch`)
|
|
8
|
+
* or combine the default with `getToken`.
|
|
9
|
+
*/
|
|
10
|
+
fetch?: (input: string, init: RequestInit) => Promise<Response>;
|
|
11
|
+
/** Bearer for each request; omit when `fetch` authenticates. */
|
|
12
|
+
getToken?: () => string | null | undefined | Promise<string | null | undefined>;
|
|
13
|
+
/** Sent as Accept-Language. */
|
|
14
|
+
language?: () => string | null | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Extra or overriding currency scales (code -> native-unit decimals). The
|
|
17
|
+
* pinned OpenRails registry is built in; `/me` amounts carry no scale.
|
|
18
|
+
*/
|
|
19
|
+
currencies?: CurrencyScales;
|
|
20
|
+
}
|
|
21
|
+
export interface CheckoutSourceOptions {
|
|
22
|
+
/**
|
|
23
|
+
* A customer surface's base: its `/me` prefix, such as `/billing/v1/me` or
|
|
24
|
+
* a host's own `/api/v1/merchants/acme/billing/me`. The session is read and
|
|
25
|
+
* paid there with this client's credential, which proves the session's
|
|
26
|
+
* customer, so its saved cards pay. Default: the session id alone, at
|
|
27
|
+
* `{baseUrl}/checkout-sessions`.
|
|
28
|
+
*/
|
|
29
|
+
customerBase?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ListOptions {
|
|
32
|
+
limit?: number;
|
|
33
|
+
offset?: number;
|
|
34
|
+
/** A cursor list's next page: the previous page's `next_cursor`. */
|
|
35
|
+
cursor?: string;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}
|
|
38
|
+
/** A cursor list read: pass the previous page's `next_cursor` for the next. */
|
|
39
|
+
export interface CursorOptions {
|
|
40
|
+
limit?: number;
|
|
41
|
+
cursor?: string | null;
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Signs and submits a base64 transaction with the customer's wallet and
|
|
46
|
+
* returns its signature. Throw `WalletRejectedError` when the user declines.
|
|
47
|
+
*/
|
|
48
|
+
export type SendSolanaTransaction = (transactionBase64: string) => Promise<string>;
|
|
49
|
+
export declare class WalletRejectedError extends Error {
|
|
50
|
+
constructor(message?: string);
|
|
51
|
+
}
|
|
52
|
+
export declare const CANCEL_REASON_MIN = 4;
|
|
53
|
+
export declare const CANCEL_REASON_MAX = 500;
|
|
54
|
+
/** A next action the customer's wallet completes. */
|
|
55
|
+
export declare const isWalletAction: (next: NextAction | null | undefined) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Signs and sends a `solana_sign_transactions` next action's transactions in
|
|
58
|
+
* order and returns the last signature, the value the action is repeated
|
|
59
|
+
* with. A declined prompt is a local `wallet_rejected` error.
|
|
60
|
+
*/
|
|
61
|
+
export declare function signWalletAction(next: NextAction, sendTransaction: SendSolanaTransaction): Promise<string>;
|
|
62
|
+
/** Total wait a GET may spend on its one retry. */
|
|
63
|
+
export declare const RETRY_BUDGET_MS = 2000;
|
|
64
|
+
export declare function createBillingClient(options?: BillingClientOptions): {
|
|
65
|
+
baseUrl: string;
|
|
66
|
+
/** One page of the customer's subscriptions, newest first. */
|
|
67
|
+
listSubscriptions(opts?: CursorOptions & {
|
|
68
|
+
status?: string;
|
|
69
|
+
}): Promise<ListPage<Subscription>>;
|
|
70
|
+
/** Includes `recovery` (list rows do not). */
|
|
71
|
+
getSubscription(subscriptionId: string, signal?: AbortSignal): Promise<Subscription>;
|
|
72
|
+
/**
|
|
73
|
+
* Cancels at period end and answers the subscription. When the rail needs
|
|
74
|
+
* the customer's step (`next_action`, a Solana wallet signature), the
|
|
75
|
+
* subscription is unchanged: complete it with `signWalletAction` and
|
|
76
|
+
* repeat with `signature`.
|
|
77
|
+
*/
|
|
78
|
+
cancelSubscription(subscriptionId: string, input: {
|
|
79
|
+
reason: string;
|
|
80
|
+
signature?: string;
|
|
81
|
+
}): Promise<Subscription>;
|
|
82
|
+
/** Undoes a scheduled cancel before the period ends. */
|
|
83
|
+
resumeSubscription(subscriptionId: string): Promise<Subscription>;
|
|
84
|
+
setSubscriptionPaymentMethod(subscriptionId: string, paymentMethodId: string): Promise<Subscription>;
|
|
85
|
+
/** What `changeTier` would charge now and at the next renewal. */
|
|
86
|
+
previewTierChange(subscriptionId: string, priceId: string, signal?: AbortSignal): Promise<TierChangePreview>;
|
|
87
|
+
/**
|
|
88
|
+
* Moves the subscription to another price of its tier group: an upgrade
|
|
89
|
+
* charges the saved card now, a downgrade applies at period end.
|
|
90
|
+
* `idempotencyKey` identifies this attempt; reuse it until the change
|
|
91
|
+
* resolves (`processing`, a `tier_change_in_flight` refusal or a lost
|
|
92
|
+
* response) so the stored result replays instead of charging twice. A
|
|
93
|
+
* wallet next action (Solana) is completed with `signWalletAction` and
|
|
94
|
+
* the change repeated with `signature`.
|
|
95
|
+
*/
|
|
96
|
+
changeTier(subscriptionId: string, input: {
|
|
97
|
+
priceId: string;
|
|
98
|
+
idempotencyKey: string;
|
|
99
|
+
signature?: string;
|
|
100
|
+
}): Promise<TierChange>;
|
|
101
|
+
listPaymentMethods(opts?: CursorOptions): Promise<ListPage<PaymentMethod>>;
|
|
102
|
+
/**
|
|
103
|
+
* Stores a card entered in the page with the PSP `psp_id`: a Collect.js
|
|
104
|
+
* token (`cardSetupDriver` "collect_js") or the card itself ("card").
|
|
105
|
+
*/
|
|
106
|
+
addPaymentMethod(card: NewCard): Promise<PaymentMethod>;
|
|
107
|
+
/**
|
|
108
|
+
* Starts an in-page card setup with a PSP whose browser SDK collects the
|
|
109
|
+
* card (see `cardSetupDriver`). `idempotencyKey` identifies this attempt.
|
|
110
|
+
*/
|
|
111
|
+
createCardSetup(input: {
|
|
112
|
+
pspId: string;
|
|
113
|
+
idempotencyKey: string;
|
|
114
|
+
}): Promise<CardSetup>;
|
|
115
|
+
getCardSetup(setupId: string, signal?: AbortSignal): Promise<CardSetup>;
|
|
116
|
+
/** Verifies the setup with the provider; `payment_method_id` once saved. */
|
|
117
|
+
confirmCardSetup(setupId: string): Promise<CardSetup>;
|
|
118
|
+
/** The provider challenge a pending payment operation is waiting on. */
|
|
119
|
+
getPaymentAuthentication(operationId: string): Promise<PaymentAuthentication>;
|
|
120
|
+
confirmPaymentAuthentication(operationId: string): Promise<void>;
|
|
121
|
+
/** `pending` when the provider is still converging (202). */
|
|
122
|
+
removePaymentMethod(paymentMethodId: string): Promise<"removed" | "pending">;
|
|
123
|
+
/** Makes the card the one that collects one currency's invoices. */
|
|
124
|
+
setCollectionPaymentMethod(input: {
|
|
125
|
+
currency: string;
|
|
126
|
+
paymentMethodId: string;
|
|
127
|
+
}): Promise<void>;
|
|
128
|
+
/** Charges and refunds, newest first. `rail` filters by rail. */
|
|
129
|
+
listPayments(opts?: CursorOptions & {
|
|
130
|
+
rail?: string;
|
|
131
|
+
}): Promise<ListPage<Payment>>;
|
|
132
|
+
listInvoices(opts?: CursorOptions): Promise<ListPage<Invoice>>;
|
|
133
|
+
getInvoice(invoiceId: string, signal?: AbortSignal): Promise<Invoice>;
|
|
134
|
+
/** Products on sale, each with its current prices. */
|
|
135
|
+
listProducts(opts?: ListOptions): Promise<Page<Product>>;
|
|
136
|
+
/**
|
|
137
|
+
* Mints a hosted checkout session for the signed-in customer and one
|
|
138
|
+
* price. Render it with `<CheckoutFrame url>` when the session has a
|
|
139
|
+
* `url`, else with `<Checkout source={client.checkoutSource(id)}>`.
|
|
140
|
+
* Select a price by `priceId`, or by both `productKey` and `priceKey`.
|
|
141
|
+
* `successUrl` brings the buyer back from a redirect rail; it must be on
|
|
142
|
+
* one of this app's return origins.
|
|
143
|
+
*/
|
|
144
|
+
createCheckoutSession(input: {
|
|
145
|
+
priceKey?: string;
|
|
146
|
+
productKey?: string;
|
|
147
|
+
priceId?: string;
|
|
148
|
+
/** Customer-selected deposit in the price currency’s native units. */
|
|
149
|
+
amount?: string;
|
|
150
|
+
/** Defaults to true for recurring prices; false buys the initial term only. */
|
|
151
|
+
autoRenew?: boolean;
|
|
152
|
+
successUrl?: string;
|
|
153
|
+
}): Promise<CheckoutSessionLink>;
|
|
154
|
+
/**
|
|
155
|
+
* Reads and pays one hosted checkout session. By default the id is the
|
|
156
|
+
* only credential: no bearer is sent. With `customerBase` the session's
|
|
157
|
+
* customer reads and pays it on that customer surface, signed in. A
|
|
158
|
+
* refusal the buyer can answer (an invalid card form, too many attempts)
|
|
159
|
+
* resolves as `failed`; an expired or unknown session as `expired`.
|
|
160
|
+
*/
|
|
161
|
+
checkoutSource(sessionId: string, opts?: CheckoutSourceOptions): CheckoutSource;
|
|
162
|
+
/**
|
|
163
|
+
* The deployment's public configuration: what the mount serves, the
|
|
164
|
+
* currency registry and the merchant's payment setup. React components
|
|
165
|
+
* share one copy through `useConfig()`.
|
|
166
|
+
*/
|
|
167
|
+
getConfig(signal?: AbortSignal): Promise<PublicConfig>;
|
|
168
|
+
/**
|
|
169
|
+
* Accepted tokens with live prices. `priceId` adds each token's `quote`;
|
|
170
|
+
* `wallet` adds its `balance`.
|
|
171
|
+
*/
|
|
172
|
+
listSolanaTokens(opts?: {
|
|
173
|
+
priceId?: string;
|
|
174
|
+
wallet?: string;
|
|
175
|
+
signal?: AbortSignal;
|
|
176
|
+
}): Promise<SolanaToken[]>;
|
|
177
|
+
/** Currency code (upper case) to native-unit decimals. */
|
|
178
|
+
currencies: Readonly<Record<string, number>>;
|
|
179
|
+
};
|
|
180
|
+
export type BillingClient = ReturnType<typeof createBillingClient>;
|
|
181
|
+
export declare const isWalletRejection: (error: unknown) => boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface BillingErrorBody {
|
|
2
|
+
type: string;
|
|
3
|
+
code: string;
|
|
4
|
+
message: string;
|
|
5
|
+
request_id?: string;
|
|
6
|
+
param?: string;
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export declare class BillingError extends Error {
|
|
10
|
+
readonly status: number;
|
|
11
|
+
readonly type: string;
|
|
12
|
+
readonly code: string;
|
|
13
|
+
readonly param?: string;
|
|
14
|
+
readonly requestId?: string;
|
|
15
|
+
readonly metadata: Record<string, unknown>;
|
|
16
|
+
constructor(status: number, body: BillingErrorBody);
|
|
17
|
+
}
|
|
18
|
+
export declare const isBillingError: (value: unknown) => value is BillingError;
|
|
19
|
+
/**
|
|
20
|
+
* A server failure (HTTP 5xx) from any client or host source that carries a
|
|
21
|
+
* numeric `status`. It is surfaced at once, never retried behind the caller.
|
|
22
|
+
*/
|
|
23
|
+
export declare const isServerError: (value: unknown) => boolean;
|
|
24
|
+
export declare function localError(code: string, message: string): BillingError;
|
|
25
|
+
export declare function readBillingError(res: Response): Promise<BillingError>;
|
|
26
|
+
export declare function toBillingError(error: unknown): BillingError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const OPENRAILS_CURRENCY_SCALES: Readonly<Record<string, number>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type OpenRailsErrorCode = "access_token_invalid" | "access_token_issuer_unknown" | "access_token_merchant_not_bound" | "admission_captured" | "admission_not_found" | "allowance_meter_not_found" | "allowance_source_in_use" | "allowance_source_invalid" | "api_host_claim_missing" | "api_host_reserved" | "api_host_taken" | "api_host_unproven" | "as_of_required" | "authentication_required" | "authentication_unavailable" | "authorization_unavailable" | "billing_archive_integrity" | "billing_archive_invalid_artifact" | "billing_archive_merchant_mismatch" | "billing_archive_not_empty" | "billing_archive_unavailable" | "billing_archive_unsupported_state" | "billing_policy_not_found" | "cancel_unsupported_on_rail" | "captcha_invalid" | "captcha_required" | "card_attempts_blocked" | "card_declined" | "card_not_saved" | "card_requires_https" | "catalog_benefit_overlap" | "catalog_revision_conflict" | "catalog_updates_disabled" | "checkout_attempt_closed" | "checkout_attempt_expired" | "checkout_offer_unavailable" | "checkout_payment_in_progress" | "checkout_request_invalid" | "checkout_session_expired" | "checkout_session_not_found" | "checkout_session_unavailable" | "collection_payment_method_invalid" | "collection_payment_method_required" | "creation_refused" | "credential_custody_transition_required" | "credential_expired" | "credential_identity_mismatch" | "credential_operation_conflict" | "credential_revoked" | "credential_source_read_only" | "credential_store_read_only" | "credentials_manage_required" | "credit_grant_held" | "credit_grant_not_found" | "credit_grant_unavailable" | "csrf_origin_denied" | "currency_unsupported" | "custodian_capture_unavailable" | "customer_action_required" | "customer_blocked" | "customer_email_required" | "customer_not_found" | "customer_payment_unsupported" | "customer_proof_required" | "customer_session_required" | "dashboard_invalid" | "database_busy" | "default_rate_card_not_found" | "default_rate_card_required" | "delegated_principal_invalid" | "email_unverified" | "finding_action_failed" | "finding_not_actionable" | "hold_not_found" | "host_event_not_found" | "host_merchant_mismatch" | "host_principal_invalid" | "idempotency_key_required" | "idempotency_key_reused" | "insufficient_credits" | "insufficient_funds" | "insufficient_scope" | "internal_error" | "invalid_api_host" | "invalid_cursor" | "invalid_customer_id" | "invalid_email" | "invalid_host_event_request" | "invalid_name" | "invalid_param" | "invalid_payment_method" | "invalid_psp_reference" | "invalid_query" | "invalid_request_body" | "invalid_settlement_status_request" | "invalid_user" | "invites_disabled" | "invoice_action_not_allowed" | "invoice_not_retryable" | "invoice_payment_exceeds_due" | "invoice_payment_invalid" | "invoice_payment_reference_used" | "invoice_retry_idempotency_conflict" | "invoice_retry_in_progress" | "invoice_retry_outcome_unknown" | "invoker_scoped_principal" | "last_owner" | "members_manage_required" | "merchant_binding_mismatch" | "merchant_configuration_application_conflict" | "merchant_configuration_revision_conflict" | "merchant_context_mismatch" | "merchant_creation_payment_method_required" | "merchant_directory_unavailable" | "merchant_not_found" | "merchant_selector_invalid" | "merchant_unresolved" | "meter_in_use" | "meter_rate_card_conflict" | "method_not_allowed" | "metrics_query_invalid" | "model_unavailable" | "name_reserved" | "name_taken" | "operation_authorization_conflict" | "operation_authorization_has_billing_evidence" | "operation_authorization_not_found" | "operation_authorization_not_open" | "payment_duplicate_refused" | "payment_failed" | "payment_idempotency_conflict" | "payment_in_progress" | "payment_method_delete_failed" | "payment_method_delete_unsupported" | "payment_method_not_psp_vaulted" | "payment_method_not_usable" | "payment_method_psp_mismatch" | "payment_method_required" | "payment_method_same_vault" | "payment_method_stale" | "payment_method_update_failed" | "payment_method_update_retry_required" | "payment_method_update_unsupported" | "payment_not_found" | "payment_not_refundable" | "payment_not_retryable" | "payment_provider_rejected" | "permission_required" | "price_key_cadence_conflict" | "price_key_not_found" | "price_not_found" | "price_not_sellable" | "product_not_found" | "product_tier_group_conflict" | "product_tier_group_in_use" | "provider_billing_observation_conflict" | "provider_billing_qualification_not_found" | "provider_billing_qualification_not_refused" | "provider_billing_qualification_refused" | "provider_billing_refusal_conflict" | "provider_billing_resolution_conflict" | "provider_cancel_held" | "provider_outcome_unknown" | "psp_claim_requires_proof" | "psp_credentials_rejected" | "psp_exists" | "psp_key_taken" | "psp_last_active" | "psp_not_found" | "purchase_review_resolved" | "rate_card_currency_mismatch" | "rate_card_has_overrides" | "rate_card_product_not_found" | "rate_limit_exceeded" | "rebill_terms_committed" | "refund_failed" | "refund_rail_unavailable" | "refund_unsupported" | "rename_too_soon" | "renames_disabled" | "reprice_already_scheduled" | "reprice_cross_currency" | "reprice_cross_product" | "reprice_inactive_price" | "reprice_not_found" | "reprice_not_scheduled" | "reprice_notice_window_violation" | "reprice_price_key_not_found" | "reprice_target_price_not_found" | "request_body_too_large" | "resource_access_denied" | "resource_conflict" | "resource_not_found" | "role_escalation" | "route_not_found" | "sender_proof_required" | "service_credential_customer_scope_denied" | "service_credential_invalid" | "service_credential_merchant_unresolved" | "service_credential_resource_scope_denied" | "service_unavailable" | "solana_rpc_unavailable" | "solana_transaction_refused" | "spend_delegation_not_found" | "step_up_required" | "step_up_unavailable" | "subscription_not_active" | "subscription_not_found" | "subscription_paid_through" | "subscription_resumable" | "tier_change_already_scheduled" | "tier_change_cadence_unsupported" | "tier_change_credit_exceeds_price" | "tier_change_cycle_unknown" | "tier_change_idempotency_conflict" | "tier_change_idempotency_key_required" | "tier_change_in_flight" | "tier_change_period_unknown" | "tier_change_provider_conflict" | "tier_change_refused" | "tier_change_renewal_due" | "tier_change_requires_linked_plan" | "tier_change_target_inactive" | "tier_change_unsupported_on_rail" | "trial_unsupported_on_rail" | "unknown_field" | "unknown_role" | "unsupported_media_type" | "usage_meter_invalid" | "usage_meter_not_found" | "usage_rate_card_invalid" | "use_dpop_nonce" | "webhook_account_mismatch" | "webhook_invalid" | "widget_generation_invalid";
|
|
2
|
+
export type OpenRailsErrorType = "api_error" | "authentication_error" | "authorization_error" | "card_error" | "invalid_request_error" | "rate_limit_error";
|
|
3
|
+
export declare const OPENRAILS_ERROR_CODES: Readonly<Record<OpenRailsErrorCode, {
|
|
4
|
+
status: number;
|
|
5
|
+
type: OpenRailsErrorType;
|
|
6
|
+
meaning: string;
|
|
7
|
+
}>>;
|