@nozle-js/react 0.8.0 → 0.10.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/dist/index.d.ts CHANGED
@@ -1,8 +1,75 @@
1
1
  import * as React from 'react';
2
- import React__default, { ReactNode } from 'react';
2
+ import React__default, { ReactNode, CSSProperties } from 'react';
3
3
 
4
- interface CompletedCheckoutResult {
5
- type: 'completed';
4
+ /** A short-lived customer-portal credential issued by the merchant's backend. */
5
+ interface BillingPortalSession {
6
+ token: string;
7
+ /** Nozle Core base URL, without /graphql. Defaults to https://api.nozle.app/core. */
8
+ apiUrl?: string;
9
+ }
10
+ type CreateBillingPortalSession = (options: {
11
+ signal: AbortSignal;
12
+ }) => Promise<BillingPortalSession>;
13
+ declare class BillingPortalError extends Error {
14
+ readonly code: "session" | "unauthorized" | "request" | "changed";
15
+ constructor(code: "session" | "unauthorized" | "request" | "changed");
16
+ }
17
+
18
+ type CancellationOperation = "cancel" | "uncancel";
19
+ interface CancellationSubscription {
20
+ /** Core UUID, distinct from the external subscription identifier. */
21
+ id: string;
22
+ externalId: string;
23
+ name: string;
24
+ status: string;
25
+ endingAt: string | null;
26
+ pendingPlanName?: string | null;
27
+ }
28
+ interface CancellationPreview {
29
+ operation: CancellationOperation;
30
+ effectiveAt: string;
31
+ renewalAt: string | null;
32
+ }
33
+ interface CancellationInput {
34
+ /** External subscription identifier. The merchant authenticates the customer separately. */
35
+ subscriptionId: string;
36
+ operation: CancellationOperation;
37
+ signal: AbortSignal;
38
+ }
39
+ interface CancellationApplyInput extends CancellationInput {
40
+ idempotencyKey: string;
41
+ /** Required for cancellation; the server must reject a changed access-end date. */
42
+ expectedEffectiveAt?: string;
43
+ }
44
+ interface CancellationActions {
45
+ preview: (input: CancellationInput) => Promise<CancellationPreview>;
46
+ apply: (input: CancellationApplyInput) => Promise<unknown>;
47
+ }
48
+ interface CancellationControlProps {
49
+ subscription: CancellationSubscription;
50
+ actions: CancellationActions;
51
+ /** Read persisted state after every attempt, including an ambiguous network failure. */
52
+ refresh: (signal: AbortSignal) => Promise<CancellationSubscription | null>;
53
+ onChanged?: () => void;
54
+ onError?: (error: BillingPortalError) => void;
55
+ locale?: string;
56
+ timezone?: string;
57
+ nonce?: string;
58
+ }
59
+ /** Customer cancellation UI. All mutations go through the merchant's authenticated callbacks. */
60
+ declare function CancellationControl(props: CancellationControlProps): React.JSX.Element;
61
+
62
+ interface CheckoutSubscriptionResult {
63
+ external_entity_id?: string;
64
+ external_subscription_id?: string;
65
+ checkout_id?: string;
66
+ effective_at?: string;
67
+ renewal_at?: string | null;
68
+ amount_due_cents?: number | string;
69
+ currency?: string;
70
+ }
71
+ interface CompletedCheckoutResult extends CheckoutSubscriptionResult {
72
+ type: "completed";
6
73
  status: string;
7
74
  payment_source?: string;
8
75
  subscription_id?: string;
@@ -11,26 +78,80 @@ interface CompletedCheckoutResult {
11
78
  amount_cents?: number;
12
79
  currency?: string;
13
80
  }
14
- interface ScheduledCheckoutResult {
15
- type: 'scheduled';
81
+ interface ScheduledCheckoutResult extends CheckoutSubscriptionResult {
82
+ type: "scheduled";
16
83
  status: string;
17
84
  subscription_id?: string;
18
85
  plan_code?: string;
86
+ effective_at?: string;
87
+ pending_subscription_id?: string;
88
+ }
89
+ interface RazorpayCheckoutResult {
90
+ type: "razorpay";
91
+ checkout_id: string;
92
+ key_id: string;
93
+ order_id: string;
94
+ amount_cents: number;
95
+ currency: string;
96
+ expires_at?: string;
97
+ invoice_id?: string;
98
+ customer_id?: string;
99
+ recurring?: boolean;
100
+ mandate_max_amount_cents?: number;
101
+ }
102
+ interface ProcessingCheckoutResult {
103
+ type: "processing";
104
+ checkout_id: string;
105
+ status: string;
106
+ }
107
+ interface HostedCheckoutResult {
108
+ type: "hosted";
109
+ payment_url: string;
110
+ checkout_id?: string;
111
+ }
112
+ interface RazorpayVerification {
113
+ razorpay_order_id: string;
114
+ razorpay_payment_id: string;
115
+ razorpay_signature: string;
116
+ }
117
+ interface CheckoutStatus {
118
+ checkout_id: string;
119
+ provider: "razorpay" | "stripe";
120
+ status: "processing" | "awaiting_payment" | "succeeded" | "failed" | "expired" | "needs_review";
121
+ fulfillment_status: "pending" | "processing" | "succeeded";
122
+ amount_cents?: number;
123
+ currency?: string;
124
+ invoice_id?: string | null;
125
+ checkout?: CheckoutResult;
19
126
  }
127
+ /** Call your authenticated merchant backend, which calls Nozle using its secret key. */
128
+ type VerifyCheckout = (checkoutId: string, verification: RazorpayVerification) => Promise<CheckoutStatus>;
129
+ type GetCheckoutStatus = (checkoutId: string) => Promise<CheckoutStatus>;
20
130
  type CheckoutResult = {
21
- type: 'stripe';
131
+ type: "stripe";
22
132
  url?: string;
23
133
  clientSecret?: string;
24
134
  client_secret?: string;
25
- } | {
26
- type: 'razorpay';
27
- orderId: string;
28
- } | CompletedCheckoutResult | ScheduledCheckoutResult | {
135
+ publishable_key?: string;
136
+ stripe_account?: string;
137
+ checkout_id?: string;
138
+ invoice_id?: string;
139
+ amount_cents?: number;
140
+ currency?: string;
141
+ external_entity_id?: string;
142
+ external_subscription_id?: string;
143
+ } | RazorpayCheckoutResult | ProcessingCheckoutResult | HostedCheckoutResult | CompletedCheckoutResult | ScheduledCheckoutResult | {
29
144
  url: string;
30
145
  };
31
146
  interface CreateCheckoutInput {
32
147
  planCode: string;
33
148
  returnUrl: string;
149
+ idempotencyKey?: string;
150
+ registerMandate?: boolean;
151
+ /** Select the customer's external subscription for a plan change. */
152
+ subscriptionId?: string;
153
+ /** Opaque, server-issued confirmation for the displayed quote. */
154
+ quoteId?: string;
34
155
  }
35
156
  type CreateCheckout = (input: CreateCheckoutInput) => Promise<CheckoutResult>;
36
157
  interface NozleClient {
@@ -41,19 +162,125 @@ interface NozleClient {
41
162
  interface BillingContextValue {
42
163
  client: NozleClient;
43
164
  createCheckout?: CreateCheckout;
165
+ verifyCheckout?: VerifyCheckout;
166
+ getCheckoutStatus?: GetCheckoutStatus;
44
167
  }
45
168
  declare const BillingContext: React__default.Context<BillingContextValue | null>;
46
169
  interface BillingProviderProps {
47
170
  publishableKey: string;
48
171
  createCheckout?: CreateCheckout;
172
+ verifyCheckout?: VerifyCheckout;
173
+ getCheckoutStatus?: GetCheckoutStatus;
49
174
  baseUrl?: string;
50
175
  children: ReactNode;
51
176
  }
52
- declare function BillingProvider({ publishableKey, createCheckout, baseUrl, children, }: BillingProviderProps): React__default.ReactElement;
177
+ declare function BillingProvider({ publishableKey, createCheckout, verifyCheckout, getCheckoutStatus, baseUrl, children, }: BillingProviderProps): React__default.ReactElement;
53
178
  declare function useOptionalBillingContext(): BillingContextValue | null;
54
179
  declare function useBillingContext(): BillingContextValue;
55
180
  declare function useNozleClient(): NozleClient;
56
181
 
182
+ interface PortalPlan {
183
+ code: string;
184
+ name: string;
185
+ amountCents: string | number;
186
+ currency: string;
187
+ interval: string;
188
+ }
189
+ type PlanChangeOperation = "upgrade" | "downgrade";
190
+ interface PlanChangeState {
191
+ subscriptionId: string;
192
+ status: string;
193
+ currentPlan: PortalPlan;
194
+ endingAt: string | null;
195
+ pendingChange: {
196
+ id: string;
197
+ plan: PortalPlan;
198
+ effectiveAt: string;
199
+ } | null;
200
+ eligiblePlans: Array<PortalPlan & {
201
+ operation: PlanChangeOperation;
202
+ }>;
203
+ blockedReason: string | null;
204
+ checkout: CheckoutResult | null;
205
+ checkoutStatus: "none" | "awaiting_payment" | "processing" | "succeeded" | "failed" | "expired" | "needs_review";
206
+ }
207
+ interface PlanChangePreview {
208
+ operation: PlanChangeOperation;
209
+ timing: "immediate" | "end_of_period";
210
+ currency: string;
211
+ creditAmountCents: string | number;
212
+ debitAmountCents: string | number;
213
+ netAmountCents: string | number;
214
+ amountDueNowCents: string | number;
215
+ amountDueAtEffectiveCents: string | number;
216
+ effectiveAt: string;
217
+ renewalAt: string | null;
218
+ quoteToken: string;
219
+ }
220
+ interface PlanChangeInput {
221
+ subscriptionId: string;
222
+ signal: AbortSignal;
223
+ }
224
+ interface PlanChangePreviewInput extends PlanChangeInput {
225
+ targetPlanCode: string;
226
+ }
227
+ interface PlanChangeApplyInput extends PlanChangePreviewInput {
228
+ quoteToken: string;
229
+ idempotencyKey: string;
230
+ returnUrl: string;
231
+ }
232
+ interface PlanChangeWithdrawInput extends PlanChangeInput {
233
+ pendingChangeId: string;
234
+ idempotencyKey: string;
235
+ }
236
+ interface PlanChangeActions {
237
+ load: (input: PlanChangeInput) => Promise<PlanChangeState>;
238
+ status: (input: PlanChangeInput) => Promise<PlanChangeState>;
239
+ preview: (input: PlanChangePreviewInput) => Promise<PlanChangePreview>;
240
+ apply: (input: PlanChangeApplyInput) => Promise<CheckoutResult>;
241
+ withdraw: (input: PlanChangeWithdrawInput) => Promise<unknown>;
242
+ /** Merchant callbacks scoped to this selected subscription. */
243
+ verifyCheckout?: (input: PlanChangeInput & {
244
+ checkoutId: string;
245
+ verification: RazorpayVerification;
246
+ }) => Promise<CheckoutStatus>;
247
+ getCheckoutStatus?: (input: PlanChangeInput & {
248
+ checkoutId: string;
249
+ }) => Promise<CheckoutStatus>;
250
+ }
251
+ interface PlanChangeControlProps {
252
+ subscriptionId: string;
253
+ /** Change when another control updates this subscription; in-flight request keys are preserved. */
254
+ refreshKey?: string;
255
+ actions: PlanChangeActions;
256
+ onChanged?: () => void;
257
+ onError?: (error: BillingPortalError) => void;
258
+ returnUrl?: string;
259
+ locale?: string;
260
+ timezone?: string;
261
+ nonce?: string;
262
+ }
263
+ /** Payment-backed upgrades and scheduled downgrades for one external subscription. */
264
+ declare function PlanChangeControl(props: PlanChangeControlProps): React.JSX.Element;
265
+
266
+ interface BillingPortalProps {
267
+ /** Stable callback to an authenticated merchant endpoint. Never accept customer identity from browser input. */
268
+ createSession: CreateBillingPortalSession;
269
+ /** Optional authenticated merchant callbacks enabling cancel/keep controls. */
270
+ cancellationActions?: CancellationActions;
271
+ /** Optional authenticated merchant callbacks for upgrades and scheduled downgrades. */
272
+ planChangeActions?: PlanChangeActions;
273
+ /** Formats amounts and dates. Interface copy is currently English. */
274
+ locale?: string;
275
+ className?: string;
276
+ style?: CSSProperties;
277
+ /** CSP nonce for the component's scoped stylesheet. No Tailwind setup is required. */
278
+ nonce?: string;
279
+ onError?: (error: BillingPortalError) => void;
280
+ }
281
+ /** Native React customer portal. Uses customer-scoped GraphQL, with no iframe or global auth storage. */
282
+ declare function BillingPortal({ createSession, cancellationActions, planChangeActions, locale, className, style, nonce, onError, }: BillingPortalProps): React.JSX.Element;
283
+
57
284
  interface Plan$1 {
58
285
  code: string;
59
286
  name: string;
@@ -156,39 +383,55 @@ interface PlanComparisonProps {
156
383
  */
157
384
  declare function PlanComparison({ plans, features, }: PlanComparisonProps): React__default.ReactElement;
158
385
 
159
- interface CheckoutButtonProps {
386
+ interface RazorpayActions {
387
+ verifyCheckout?: VerifyCheckout;
388
+ getCheckoutStatus?: GetCheckoutStatus;
389
+ onSuccess?: (paymentId: string) => void;
390
+ onProcessing?: (status: CheckoutStatus) => void;
391
+ onDismiss?: () => void;
392
+ onError?: (error: Error) => void;
393
+ }
394
+ interface RazorpayOptions {
395
+ key: string;
396
+ order_id: string;
397
+ amount: number;
398
+ currency: string;
399
+ customer_id?: string;
400
+ recurring?: '1';
401
+ handler: (response: RazorpayVerification) => void;
402
+ modal: {
403
+ ondismiss: () => void;
404
+ };
405
+ }
406
+ interface RazorpayInstance {
407
+ open(): void;
408
+ close(): void;
409
+ on(event: string, callback: () => void): void;
410
+ }
411
+ declare global {
412
+ interface Window {
413
+ Razorpay?: new (options: RazorpayOptions) => RazorpayInstance;
414
+ }
415
+ }
416
+
417
+ interface CheckoutButtonProps extends Omit<RazorpayActions, "verifyCheckout" | "getCheckoutStatus"> {
160
418
  planCode: string;
161
419
  returnUrl?: string;
162
420
  label?: string;
163
421
  className?: string;
164
422
  style?: React__default.CSSProperties;
165
423
  onError?: (error: Error) => void;
424
+ /** @deprecated The server supplies the public Razorpay key in the checkout response. */
166
425
  razorpayKeyId?: string;
426
+ registerMandate?: boolean;
167
427
  onStripeClientSecret?: (clientSecret: string) => void;
168
428
  onSuccess?: (paymentId: string) => void;
169
429
  onComplete?: (result: CompletedCheckoutResult) => void;
170
430
  onScheduled?: (result: ScheduledCheckoutResult) => void;
171
431
  }
172
- interface RazorpayOptions {
173
- key: string;
174
- order_id: string;
175
- handler: (response: {
176
- razorpay_payment_id: string;
177
- }) => void;
178
- modal?: {
179
- ondismiss?: () => void;
180
- };
181
- }
182
- declare global {
183
- interface Window {
184
- Razorpay: new (options: RazorpayOptions) => {
185
- open(): void;
186
- };
187
- }
188
- }
189
- declare function CheckoutButton({ planCode, returnUrl, label, className, style, onError, razorpayKeyId, onStripeClientSecret, onSuccess, onComplete, onScheduled, }: CheckoutButtonProps): React__default.ReactElement;
432
+ declare function CheckoutButton({ planCode, returnUrl, label, className, style, onError, razorpayKeyId, registerMandate, onProcessing, onDismiss, onStripeClientSecret, onSuccess, onComplete, onScheduled, }: CheckoutButtonProps): React__default.ReactElement;
190
433
 
191
- interface CheckoutProps {
434
+ interface StripeCheckoutProps {
192
435
  /** Stripe PaymentIntent client secret */
193
436
  clientSecret: string;
194
437
  /** Stripe publishable key */
@@ -223,19 +466,47 @@ interface UseCheckoutResult {
223
466
  error: Error | null;
224
467
  }
225
468
  declare function useCheckout(): UseCheckoutResult;
226
- declare function Checkout({ clientSecret, publishableKey, stripeAccount, returnUrl, submitLabel, onSuccess, onComplete, onError, onReady, className, style, children, }: CheckoutProps): React__default.JSX.Element;
469
+ interface ProviderCheckoutProps {
470
+ checkout: CheckoutResult;
471
+ submitLabel?: string;
472
+ onSuccess?: (paymentId: string) => void;
473
+ onComplete?: () => void;
474
+ onProcessing?: (status: CheckoutStatus) => void;
475
+ onError?: (error: Error) => void;
476
+ className?: string;
477
+ returnUrl?: string;
478
+ verifyCheckout?: VerifyCheckout;
479
+ getCheckoutStatus?: GetCheckoutStatus;
480
+ onDismiss?: () => void;
481
+ }
482
+ type CheckoutProps = StripeCheckoutProps | ProviderCheckoutProps;
483
+ declare function Checkout(props: CheckoutProps): React__default.JSX.Element;
227
484
 
228
485
  interface ProrationPreview {
229
486
  credit: number;
230
487
  debit: number;
231
488
  net: number;
232
489
  nextBillingDate: string;
490
+ /** Currency of legacy major-unit preview amounts. Defaults to USD for existing integrations. */
491
+ currency?: string;
233
492
  }
234
493
  interface UpgradeModalProps {
235
494
  isOpen: boolean;
236
495
  planCode: string;
237
496
  returnUrl?: string;
497
+ subscriptionId?: string;
498
+ quoteId?: string;
499
+ idempotencyKey?: string;
238
500
  preview?: ProrationPreview;
501
+ locale?: string;
502
+ title?: string;
503
+ confirmLabel?: string;
504
+ confirmDisabled?: boolean;
505
+ busy?: boolean;
506
+ nonce?: string;
507
+ children?: React__default.ReactNode;
508
+ /** Authenticated merchant action. Allows the same confirmation UI without BillingProvider. */
509
+ onSubmit?: () => Promise<void>;
239
510
  onStripeClientSecret?: (clientSecret: string) => void;
240
511
  onCheckoutStarted?: () => void;
241
512
  onCompleted?: () => void;
@@ -244,11 +515,14 @@ interface UpgradeModalProps {
244
515
  onCancel?: () => void;
245
516
  onError?: (error: Error) => void;
246
517
  }
247
- declare function UpgradeModal({ isOpen, planCode, returnUrl, preview, onStripeClientSecret, onCheckoutStarted, onCompleted, onScheduled, onConfirm, onCancel, onError, }: UpgradeModalProps): React__default.ReactElement | null;
518
+ declare function UpgradeModal(props: UpgradeModalProps): React__default.ReactElement | null;
248
519
 
249
520
  interface UpgradeButtonProps {
250
521
  planCode: string;
251
522
  returnUrl?: string;
523
+ subscriptionId?: string;
524
+ quoteId?: string;
525
+ idempotencyKey?: string;
252
526
  preview?: ProrationPreview;
253
527
  label?: string;
254
528
  className?: string;
@@ -259,7 +533,7 @@ interface UpgradeButtonProps {
259
533
  onUpgraded?: () => void;
260
534
  onError?: (error: Error) => void;
261
535
  }
262
- declare function UpgradeButton({ planCode, returnUrl, preview, label, className, style, onStripeClientSecret, onCheckoutStarted, onDowngradeScheduled, onUpgraded, onError, }: UpgradeButtonProps): React__default.ReactElement;
536
+ declare function UpgradeButton({ planCode, returnUrl, subscriptionId, quoteId, idempotencyKey, preview, label, className, style, onStripeClientSecret, onCheckoutStarted, onDowngradeScheduled, onUpgraded, onError, }: UpgradeButtonProps): React__default.ReactElement;
263
537
 
264
538
  /**
265
539
  * Presentational entitlement gate. The merchant backend owns entitlement
@@ -457,4 +731,4 @@ interface PaymentMethodDisplayProps {
457
731
  }
458
732
  declare function PaymentMethodDisplay({ paymentMethod, onUpdatePaymentMethod, updateHref, }: PaymentMethodDisplayProps): React.JSX.Element;
459
733
 
460
- export { BillingContext, type BillingContextValue, BillingProvider, type BillingProviderProps, type Plan$1 as CatalogPlan, Checkout, CheckoutButton, type CheckoutButtonProps, type CheckoutProps, type CheckoutResult, type ComparisonFeature, type CompletedCheckoutResult, type CreateCheckout, type CreateCheckoutInput, FeatureGate, type FeatureGateProps, LockedOverlay, type LockedOverlayProps, type NozleClient, type PaymentMethod, PaymentMethodDisplay, type PaymentMethodDisplayProps, type Plan, PlanBadge, type PlanBadgeProps, PlanCard, type PlanCardProps, PlanComparison, type PlanComparisonProps, PlanGate, type PlanGateProps, type PricingPlan, PricingTable, type PricingTableProps, type ProrationPreview, type ScheduledCheckoutResult, UpgradeButton, type UpgradeButtonProps, UpgradeModal, type UpgradeModalProps, UpgradePrompt, type UpgradePromptProps, UsageAlert, type UsageAlertFeature, type UsageAlertProps, UsageDashboard, type UsageDashboardFeature, type UsageDashboardProps, UsageGate, type UsageGateProps, UsageMeter, type UsageMeterProps, type UseCheckoutResult, type UseCheckoutResult$1 as UseCheckoutSessionResult, getUsageMeterColor, useBillingContext, useCheckout, useCheckout$1 as useCheckoutSession, useNozleClient, useOptionalBillingContext, usePlans };
734
+ export { BillingContext, type BillingContextValue, BillingPortal, BillingPortalError, type BillingPortalProps, type BillingPortalSession, BillingProvider, type BillingProviderProps, type CancellationActions, type CancellationApplyInput, CancellationControl, type CancellationControlProps, type CancellationInput, type CancellationOperation, type CancellationPreview, type CancellationSubscription, type Plan$1 as CatalogPlan, Checkout, CheckoutButton, type CheckoutButtonProps, type CheckoutProps, type CheckoutResult, type CheckoutStatus, type CheckoutSubscriptionResult, type ComparisonFeature, type CompletedCheckoutResult, type CreateBillingPortalSession, type CreateCheckout, type CreateCheckoutInput, FeatureGate, type FeatureGateProps, type GetCheckoutStatus, type HostedCheckoutResult, LockedOverlay, type LockedOverlayProps, type NozleClient, type PaymentMethod, PaymentMethodDisplay, type PaymentMethodDisplayProps, type Plan, PlanBadge, type PlanBadgeProps, PlanCard, type PlanCardProps, type PlanChangeActions, type PlanChangeApplyInput, PlanChangeControl, type PlanChangeControlProps, type PlanChangeInput, type PlanChangeOperation, type PlanChangePreview, type PlanChangePreviewInput, type PlanChangeState, type PlanChangeWithdrawInput, PlanComparison, type PlanComparisonProps, PlanGate, type PlanGateProps, type PortalPlan, type PricingPlan, PricingTable, type PricingTableProps, type ProcessingCheckoutResult, type ProrationPreview, type RazorpayCheckoutResult, type RazorpayVerification, type ScheduledCheckoutResult, UpgradeButton, type UpgradeButtonProps, UpgradeModal, type UpgradeModalProps, UpgradePrompt, type UpgradePromptProps, UsageAlert, type UsageAlertFeature, type UsageAlertProps, UsageDashboard, type UsageDashboardFeature, type UsageDashboardProps, UsageGate, type UsageGateProps, UsageMeter, type UsageMeterProps, type UseCheckoutResult, type UseCheckoutResult$1 as UseCheckoutSessionResult, type VerifyCheckout, getUsageMeterColor, useBillingContext, useCheckout, useCheckout$1 as useCheckoutSession, useNozleClient, useOptionalBillingContext, usePlans };