@openrails/billing-ui 0.234.0 → 0.236.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 +142 -2
- package/README.md +119 -85
- package/dist/account/account-billing.d.ts +6 -5
- package/dist/account/change-card-dialog.d.ts +5 -2
- package/dist/account/payment-methods-panel.d.ts +6 -5
- package/dist/buy-button.d.ts +35 -0
- package/dist/cart.d.ts +18 -0
- package/dist/checkout.d.ts +1 -3
- package/dist/client/checkout.d.ts +28 -0
- package/dist/client/client.d.ts +98 -63
- package/dist/client/errors.d.ts +5 -4
- package/dist/client/generated/error-codes.d.ts +1 -1
- package/dist/client/generated/routes.d.ts +142 -99
- package/dist/client/generated/wire.d.ts +185 -98
- package/dist/client/index.d.ts +2 -2
- package/dist/client/types.d.ts +272 -29
- package/dist/{client-CWX6QpLa.js → client-BuvolBPT.js} +498 -326
- package/dist/client-BuvolBPT.js.map +1 -0
- package/dist/client.js +2 -2
- package/dist/components/stripe-card.d.ts +8 -2
- package/dist/components/stripe-wallets.d.ts +12 -0
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/frame.d.ts +5 -5
- package/dist/hooks-2d-XjpuI.js +526 -0
- package/dist/hooks-2d-XjpuI.js.map +1 -0
- package/dist/i18n/context.d.ts +1 -1
- package/dist/i18n/messages.d.ts +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +1985 -1667
- package/dist/index.js.map +1 -1
- package/dist/lib/money.d.ts +1 -0
- package/dist/lib/offer-label.d.ts +4 -0
- package/dist/locales/de.js +25 -4
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/en.d.ts +25 -4
- package/dist/locales/en.js +25 -4
- package/dist/locales/en.js.map +1 -1
- package/dist/locales/es.js +25 -4
- package/dist/locales/es.js.map +1 -1
- package/dist/locales/ja.js +16 -4
- package/dist/locales/ja.js.map +1 -1
- package/dist/locales/ko.js +16 -4
- package/dist/locales/ko.js.map +1 -1
- package/dist/locales/zh.js +16 -4
- package/dist/locales/zh.js.map +1 -1
- package/dist/offers.d.ts +33 -0
- package/dist/order-checkout.d.ts +30 -0
- package/dist/react/context.d.ts +6 -5
- package/dist/react/hooks.d.ts +17 -16
- package/dist/react/index.d.ts +1 -1
- package/dist/react/provider.d.ts +24 -2
- package/dist/react.js +2 -33
- package/dist/save-payment-method.d.ts +0 -6
- package/dist/styles.css +1 -1
- package/dist/types.d.ts +16 -16
- package/docs/payment-form-contract.md +6 -6
- package/package.json +2 -2
- package/dist/client-CWX6QpLa.js.map +0 -1
- package/dist/config-DZ97SQG2.js +0 -341
- package/dist/config-DZ97SQG2.js.map +0 -1
- package/dist/provider.d.ts +0 -18
- package/dist/react.js.map +0 -1
package/dist/client/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Account,
|
|
1
|
+
import { BillingError } from './errors';
|
|
2
|
+
import { Account, PublicConfig, PaymentAuthentication, CurrencyScales, Invoice, ListPage, NewCard, NextAction, Cart, Order, OrderPaymentInput, Page, Payment, PaymentMethod, Product, SolanaToken, Subscription, SubscriptionChange, SubscriptionChangePreview } from './types';
|
|
3
3
|
export interface BillingClientOptions {
|
|
4
4
|
/** OpenRails embedded mount. Default "/billing/v1". */
|
|
5
5
|
baseUrl?: string;
|
|
@@ -18,15 +18,13 @@ export interface BillingClientOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
currencies?: CurrencyScales;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
customerBase?: string;
|
|
21
|
+
/**
|
|
22
|
+
* A public catalog lookup: the products named by `keys` (at most 100 product
|
|
23
|
+
* keys), in one page.
|
|
24
|
+
*/
|
|
25
|
+
export interface ProductListOptions {
|
|
26
|
+
keys: string[];
|
|
27
|
+
signal?: AbortSignal;
|
|
30
28
|
}
|
|
31
29
|
export interface ListOptions {
|
|
32
30
|
limit?: number;
|
|
@@ -35,7 +33,15 @@ export interface ListOptions {
|
|
|
35
33
|
cursor?: string;
|
|
36
34
|
signal?: AbortSignal;
|
|
37
35
|
}
|
|
38
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* A subscription change: another price of its tier group, other seats of a
|
|
38
|
+
* per-seat price, or both. A quantity for a price that is not per seat is
|
|
39
|
+
* refused (`quantity_not_allowed`).
|
|
40
|
+
*/
|
|
41
|
+
export interface SubscriptionChangeInput {
|
|
42
|
+
priceId?: string;
|
|
43
|
+
quantity?: number;
|
|
44
|
+
}
|
|
39
45
|
export interface CursorOptions {
|
|
40
46
|
limit?: number;
|
|
41
47
|
cursor?: string | null;
|
|
@@ -61,6 +67,14 @@ export declare const isWalletAction: (next: NextAction | null | undefined) => bo
|
|
|
61
67
|
export declare function signWalletAction(next: NextAction, sendTransaction: SendSolanaTransaction): Promise<string>;
|
|
62
68
|
/** Total wait a GET may spend on its one retry. */
|
|
63
69
|
export declare const RETRY_BUDGET_MS = 2000;
|
|
70
|
+
/**
|
|
71
|
+
* An order request's answer. `error` is set when the payment failed: the
|
|
72
|
+
* order is open again and its `payment.last_payment_error` says why.
|
|
73
|
+
*/
|
|
74
|
+
export interface OrderResult {
|
|
75
|
+
order: Order;
|
|
76
|
+
error?: BillingError;
|
|
77
|
+
}
|
|
64
78
|
export declare function createBillingClient(options?: BillingClientOptions): {
|
|
65
79
|
baseUrl: string;
|
|
66
80
|
/** One page of the customer's subscriptions, newest first. */
|
|
@@ -81,47 +95,91 @@ export declare function createBillingClient(options?: BillingClientOptions): {
|
|
|
81
95
|
}): Promise<Subscription>;
|
|
82
96
|
/** Undoes a scheduled cancel before the period ends. */
|
|
83
97
|
resumeSubscription(subscriptionId: string): Promise<Subscription>;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
98
|
+
/** Gives the subscription its own card; `null` makes it follow the default. */
|
|
99
|
+
setSubscriptionPaymentMethod(subscriptionId: string, paymentMethodId: string | null): Promise<Subscription>;
|
|
100
|
+
/** What `changeSubscription` would charge now and at the next renewal. */
|
|
101
|
+
previewSubscriptionChange(subscriptionId: string, change: SubscriptionChangeInput, signal?: AbortSignal): Promise<SubscriptionChangePreview>;
|
|
87
102
|
/**
|
|
88
|
-
* Moves the subscription to another price of its tier group
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* resolves (`processing`, a
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
103
|
+
* Moves the subscription to another price of its tier group, to other
|
|
104
|
+
* seats of a per-seat price, or both. An upgrade and more seats charge
|
|
105
|
+
* the saved card now; a downgrade and fewer seats apply at period end.
|
|
106
|
+
* Reuse `idempotencyKey` until the change resolves (`processing`, a
|
|
107
|
+
* `subscription_change_in_flight` refusal or a lost response) so the
|
|
108
|
+
* stored result replays instead of charging twice. A Solana wallet next
|
|
109
|
+
* action is completed with `signWalletAction`, then repeated with `signature`.
|
|
95
110
|
*/
|
|
96
|
-
|
|
97
|
-
priceId: string;
|
|
111
|
+
changeSubscription(subscriptionId: string, input: SubscriptionChangeInput & {
|
|
98
112
|
idempotencyKey: string;
|
|
99
113
|
signature?: string;
|
|
100
|
-
}): Promise<
|
|
114
|
+
}): Promise<SubscriptionChange>;
|
|
101
115
|
listPaymentMethods(opts?: CursorOptions): Promise<ListPage<PaymentMethod>>;
|
|
102
116
|
/**
|
|
103
|
-
*
|
|
104
|
-
* token
|
|
117
|
+
* Saves a card entered in the page with the PSP `psp_id` in one call: the
|
|
118
|
+
* token of its own fields, or the card itself ("card"). A Stripe card the
|
|
119
|
+
* bank wants authenticated answers `requires_action`.
|
|
105
120
|
*/
|
|
106
121
|
addPaymentMethod(card: NewCard): Promise<PaymentMethod>;
|
|
122
|
+
/** The customer's cart, priced now. */
|
|
123
|
+
getCart(signal?: AbortSignal): Promise<Cart>;
|
|
107
124
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
125
|
+
* Puts a price in the cart or changes its line, and answers the cart.
|
|
126
|
+
* `quantity` 0 removes the line; omitted, the price's default. `amount`
|
|
127
|
+
* is the customer's choice on a price that takes one.
|
|
110
128
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
129
|
+
setCartLine(priceId: string, input?: {
|
|
130
|
+
quantity?: number;
|
|
131
|
+
amount?: string;
|
|
132
|
+
}): Promise<Cart>;
|
|
133
|
+
/** Empties the cart. */
|
|
134
|
+
clearCart(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Creates an order from `lines` or the cart (`cart: true`), and with
|
|
137
|
+
* `payment` pays it in the same call; `expectedTotal` is the total the
|
|
138
|
+
* customer saw. A failed payment resolves as payOrder's does.
|
|
139
|
+
*/
|
|
140
|
+
createOrder(input: {
|
|
141
|
+
lines?: {
|
|
142
|
+
price_id: string;
|
|
143
|
+
quantity?: number;
|
|
144
|
+
amount?: string;
|
|
145
|
+
}[];
|
|
146
|
+
cart?: boolean;
|
|
147
|
+
expectedTotal?: string;
|
|
148
|
+
payment?: OrderPaymentInput;
|
|
149
|
+
reusable?: boolean;
|
|
150
|
+
idempotencyKey: string;
|
|
151
|
+
}): Promise<OrderResult>;
|
|
152
|
+
/** One of the customer's orders: the resumable handle of a purchase. */
|
|
153
|
+
getOrder(orderId: string, signal?: AbortSignal): Promise<Order>;
|
|
154
|
+
/**
|
|
155
|
+
* Pays an open order. A failed payment resolves with the order (open,
|
|
156
|
+
* `payment.last_payment_error` saying why) and `error`, the 402.
|
|
157
|
+
* `idempotencyKey` is minted when the pay button renders: a retry with it
|
|
158
|
+
* answers what the first request answered.
|
|
159
|
+
*/
|
|
160
|
+
payOrder(orderId: string, input: {
|
|
161
|
+
payment: OrderPaymentInput;
|
|
162
|
+
expectedTotal: string;
|
|
163
|
+
reusable?: boolean;
|
|
113
164
|
idempotencyKey: string;
|
|
114
|
-
}): Promise<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
165
|
+
}): Promise<OrderResult>;
|
|
166
|
+
/** Reads the provider after the customer completed `next_action`. */
|
|
167
|
+
confirmOrder(orderId: string): Promise<OrderResult>;
|
|
168
|
+
/**
|
|
169
|
+
* Finishes saving a card the bank asked to authenticate, after the PSP's
|
|
170
|
+
* script answered its `next_action`.
|
|
171
|
+
*/
|
|
172
|
+
confirmPaymentMethod(paymentMethodId: string): Promise<PaymentMethod>;
|
|
118
173
|
/** The provider challenge a pending payment operation is waiting on. */
|
|
119
174
|
getPaymentAuthentication(operationId: string): Promise<PaymentAuthentication>;
|
|
120
175
|
confirmPaymentAuthentication(operationId: string): Promise<void>;
|
|
121
176
|
/** `pending` when the provider is still converging (202). */
|
|
122
177
|
removePaymentMethod(paymentMethodId: string): Promise<"removed" | "pending">;
|
|
123
|
-
/**
|
|
124
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Makes the card the default for one currency: it pays the currency's
|
|
180
|
+
* invoices and every subscription in it without its own card.
|
|
181
|
+
*/
|
|
182
|
+
setDefaultPaymentMethod(input: {
|
|
125
183
|
currency: string;
|
|
126
184
|
paymentMethodId: string;
|
|
127
185
|
}): Promise<void>;
|
|
@@ -136,34 +194,11 @@ export declare function createBillingClient(options?: BillingClientOptions): {
|
|
|
136
194
|
*/
|
|
137
195
|
getAccount(signal?: AbortSignal): Promise<Account>;
|
|
138
196
|
getInvoice(invoiceId: string, signal?: AbortSignal): Promise<Invoice>;
|
|
139
|
-
/** Products on sale, each with its current prices. */
|
|
140
|
-
listProducts(opts?: ListOptions): Promise<Page<Product>>;
|
|
141
|
-
/**
|
|
142
|
-
* Mints a hosted checkout session for the signed-in customer and one
|
|
143
|
-
* price. Render it with `<CheckoutFrame url>` when the session has a
|
|
144
|
-
* `url`, else with `<Checkout source={client.checkoutSource(id)}>`.
|
|
145
|
-
* Select a price by `priceId`, or by both `productKey` and `priceKey`.
|
|
146
|
-
* `successUrl` brings the buyer back from a redirect rail; it must be on
|
|
147
|
-
* one of this app's return origins.
|
|
148
|
-
*/
|
|
149
|
-
createCheckoutSession(input: {
|
|
150
|
-
priceKey?: string;
|
|
151
|
-
productKey?: string;
|
|
152
|
-
priceId?: string;
|
|
153
|
-
/** Customer-selected deposit in the price currency’s native units. */
|
|
154
|
-
amount?: string;
|
|
155
|
-
/** Defaults to true for recurring prices; false buys the initial term only. */
|
|
156
|
-
autoRenew?: boolean;
|
|
157
|
-
successUrl?: string;
|
|
158
|
-
}): Promise<CheckoutSessionLink>;
|
|
159
197
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* customer reads and pays it on that customer surface, signed in. A
|
|
163
|
-
* refusal the buyer can answer (an invalid card form, too many attempts)
|
|
164
|
-
* resolves as `failed`; an expired or unknown session as `expired`.
|
|
198
|
+
* The products on sale named by `keys`, each with its current prices.
|
|
199
|
+
* No keys name no products: nothing is fetched.
|
|
165
200
|
*/
|
|
166
|
-
|
|
201
|
+
listProducts(opts: ProductListOptions): Promise<Page<Product>>;
|
|
167
202
|
/**
|
|
168
203
|
* The deployment's public configuration: what the mount serves, the
|
|
169
204
|
* currency registry and the merchant's payment setup. React components
|
package/dist/client/errors.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface BillingErrorBody {
|
|
|
5
5
|
request_id?: string;
|
|
6
6
|
param?: string;
|
|
7
7
|
metadata?: Record<string, unknown>;
|
|
8
|
+
/** The order a failed payment left open (402 card_error). */
|
|
9
|
+
order?: unknown;
|
|
8
10
|
}
|
|
9
11
|
export declare class BillingError extends Error {
|
|
10
12
|
readonly status: number;
|
|
@@ -13,13 +15,12 @@ export declare class BillingError extends Error {
|
|
|
13
15
|
readonly param?: string;
|
|
14
16
|
readonly requestId?: string;
|
|
15
17
|
readonly metadata: Record<string, unknown>;
|
|
18
|
+
/** The order a failed payment left open, unvalidated. */
|
|
19
|
+
readonly order?: unknown;
|
|
16
20
|
constructor(status: number, body: BillingErrorBody);
|
|
17
21
|
}
|
|
18
22
|
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
|
+
/** A server failure (HTTP 5xx) from any client or host source that carries a numeric `status`. */
|
|
23
24
|
export declare const isServerError: (value: unknown) => boolean;
|
|
24
25
|
export declare function localError(code: string, message: string): BillingError;
|
|
25
26
|
export declare function readBillingError(res: Response): Promise<BillingError>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type OpenRailsErrorCode = "
|
|
1
|
+
export type OpenRailsErrorCode = "admission_captured" | "admission_not_found" | "allowance_meter_not_found" | "allowance_source_in_use" | "allowance_source_invalid" | "already_owned" | "application_required" | "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" | "checkout_attempt_closed" | "checkout_attempt_expired" | "checkout_attempts_exhausted" | "checkout_expired" | "checkout_not_found" | "checkout_offer_unavailable" | "checkout_payment_in_progress" | "checkout_request_invalid" | "checkout_session_expired" | "checkout_session_not_found" | "checkout_session_unavailable" | "credential_expired" | "credential_revoked" | "credit_grant_held" | "credit_grant_not_found" | "credit_grant_unavailable" | "csrf_origin_denied" | "currency_unsupported" | "custodian_capture_unavailable" | "customer_action_required" | "customer_email_required" | "customer_not_found" | "customer_payment_unsupported" | "customer_proof_required" | "customer_session_required" | "dashboard_invalid" | "database_busy" | "default_payment_method_invalid" | "default_payment_method_required" | "default_rate_card_not_found" | "default_rate_card_required" | "finding_action_failed" | "finding_not_actionable" | "hold_not_found" | "host_event_not_found" | "host_principal_invalid" | "hosted_checkout_unavailable" | "idempotency_key_in_progress" | "idempotency_key_in_use" | "idempotency_key_required" | "idempotency_key_reused" | "insufficient_credits" | "insufficient_funds" | "internal_error" | "invalid_cursor" | "invalid_customer_id" | "invalid_host_event_request" | "invalid_param" | "invalid_payment_method" | "invalid_psp_reference" | "invalid_query" | "invalid_request_body" | "invalid_settlement_status_request" | "invoice_action_not_allowed" | "invoice_not_retryable" | "invoice_retry_idempotency_conflict" | "invoice_retry_in_progress" | "invoice_retry_outcome_unknown" | "invoker_scoped_principal" | "merchant_binding_mismatch" | "merchant_config_read_only" | "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" | "network_account_linked" | "network_link_challenge_invalid" | "network_link_conflict" | "network_link_in_use" | "network_terms_required" | "order_has_recurring_line" | "order_line_unavailable" | "order_not_cancelable" | "order_not_payable" | "order_payment_in_progress" | "order_total_changed" | "payment_duplicate_refused" | "payment_exceeds_due" | "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_option_unavailable" | "payment_provider_rejected" | "permission_required" | "price_change_currency_mismatch" | "price_change_target_archived" | "price_increase_notice_too_short" | "price_key_cadence_conflict" | "price_key_not_found" | "price_migration_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_cancel_held" | "provider_operation_conflict" | "provider_operation_has_billing_evidence" | "provider_operation_not_found" | "provider_operation_not_open" | "provider_operation_not_refused" | "provider_operation_refused" | "provider_outcome_unknown" | "psp_claim_requires_proof" | "psp_credentials_rejected" | "psp_exists" | "psp_key_taken" | "psp_last_active" | "psp_not_found" | "purchase_review_resolved" | "quantity_not_allowed" | "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" | "request_body_too_large" | "resource_access_denied" | "resource_conflict" | "resource_not_found" | "revision_mismatch" | "route_not_found" | "scheduled_change_exists" | "service_credential_customer_scope_denied" | "service_unavailable" | "solana_rpc_unavailable" | "solana_transaction_refused" | "step_up_required" | "step_up_unavailable" | "stored_credential_required" | "subscription_change_already_scheduled" | "subscription_change_cadence_unsupported" | "subscription_change_credit_exceeds_price" | "subscription_change_cycle_unknown" | "subscription_change_idempotency_conflict" | "subscription_change_idempotency_key_required" | "subscription_change_in_flight" | "subscription_change_period_unknown" | "subscription_change_provider_conflict" | "subscription_change_refused" | "subscription_change_renewal_due" | "subscription_change_requires_linked_plan" | "subscription_change_target_inactive" | "subscription_change_unsupported_on_rail" | "subscription_not_active" | "subscription_not_found" | "subscription_paid_through" | "subscription_resumable" | "trial_unsupported_on_rail" | "unknown_field" | "unsupported_media_type" | "usage_meter_invalid" | "usage_meter_not_found" | "usage_rate_card_invalid" | "webhook_account_mismatch" | "webhook_invalid" | "widget_generation_invalid";
|
|
2
2
|
export type OpenRailsErrorType = "api_error" | "authentication_error" | "authorization_error" | "card_error" | "invalid_request_error" | "rate_limit_error";
|
|
3
3
|
export declare const OPENRAILS_ERROR_CODES: Readonly<Record<OpenRailsErrorCode, {
|
|
4
4
|
status: number;
|