@nozle-js/react 0.10.0 → 0.10.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/dist/index.d.cts CHANGED
@@ -71,6 +71,7 @@ interface CheckoutSubscriptionResult {
71
71
  interface CompletedCheckoutResult extends CheckoutSubscriptionResult {
72
72
  type: "completed";
73
73
  status: string;
74
+ /** `credits` or `none`. */
74
75
  payment_source?: string;
75
76
  subscription_id?: string;
76
77
  plan_code?: string;
@@ -84,7 +85,9 @@ interface ScheduledCheckoutResult extends CheckoutSubscriptionResult {
84
85
  subscription_id?: string;
85
86
  plan_code?: string;
86
87
  effective_at?: string;
87
- pending_subscription_id?: string;
88
+ /** `upgrade` or `downgrade`. */
89
+ transition_direction?: string;
90
+ transition_policy?: string;
88
91
  }
89
92
  interface RazorpayCheckoutResult {
90
93
  type: "razorpay";
@@ -94,20 +97,40 @@ interface RazorpayCheckoutResult {
94
97
  amount_cents: number;
95
98
  currency: string;
96
99
  expires_at?: string;
100
+ /** Set for an invoice checkout. A paid upgrade returns `plan_upgrade_intent_id` instead. */
97
101
  invoice_id?: string;
102
+ plan_upgrade_intent_id?: string;
103
+ external_entity_id?: string;
104
+ external_subscription_id?: string;
98
105
  customer_id?: string;
99
106
  recurring?: boolean;
100
107
  mandate_max_amount_cents?: number;
101
108
  }
109
+ /**
110
+ * The checkout is not ready to collect payment yet: Razorpay while the order is
111
+ * being created, and Stripe when a quoted upgrade is replayed while its webhook is
112
+ * still pending. Recover with the checkout status call using `checkout_id`.
113
+ */
102
114
  interface ProcessingCheckoutResult {
103
115
  type: "processing";
104
116
  checkout_id: string;
105
117
  status: string;
118
+ amount_cents?: number;
119
+ currency?: string;
120
+ expires_at?: string;
121
+ invoice_id?: string;
122
+ plan_upgrade_intent_id?: string;
106
123
  }
124
+ /** A Razorpay payment link. The customer is redirected to `payment_url`. */
107
125
  interface HostedCheckoutResult {
108
126
  type: "hosted";
109
127
  payment_url: string;
110
128
  checkout_id?: string;
129
+ amount_cents?: number;
130
+ currency?: string;
131
+ expires_at?: string;
132
+ invoice_id?: string;
133
+ plan_upgrade_intent_id?: string;
111
134
  }
112
135
  interface RazorpayVerification {
113
136
  razorpay_order_id: string;
@@ -129,13 +152,19 @@ type VerifyCheckout = (checkoutId: string, verification: RazorpayVerification) =
129
152
  type GetCheckoutStatus = (checkoutId: string) => Promise<CheckoutStatus>;
130
153
  type CheckoutResult = {
131
154
  type: "stripe";
155
+ /** Not returned by plan and invoice checkout, which never issue a Stripe-hosted URL. */
132
156
  url?: string;
157
+ /** Embedded Checkout Session secret (`cs_...`). */
133
158
  clientSecret?: string;
134
159
  client_secret?: string;
160
+ /** Not returned by Nozle. Pass your Stripe publishable key to `Checkout`. */
135
161
  publishable_key?: string;
162
+ /** Not returned by Nozle. */
136
163
  stripe_account?: string;
137
164
  checkout_id?: string;
138
165
  invoice_id?: string;
166
+ /** Set instead of `invoice_id` for a paid upgrade. */
167
+ plan_upgrade_intent_id?: string;
139
168
  amount_cents?: number;
140
169
  currency?: string;
141
170
  external_entity_id?: string;
@@ -291,6 +320,7 @@ interface Plan$1 {
291
320
  declare function usePlans(): {
292
321
  plans: Plan$1[];
293
322
  isLoading: boolean;
323
+ error: Error | null;
294
324
  };
295
325
 
296
326
  interface UseCheckoutResult$1 {
@@ -444,7 +474,11 @@ interface StripeCheckoutProps {
444
474
  submitLabel?: string;
445
475
  /** Called with the paymentIntentId when payment succeeds without redirect */
446
476
  onSuccess?: (paymentIntentId: string) => void;
447
- /** Called when an embedded Checkout Session completes without a redirect. */
477
+ /**
478
+ * Called when an embedded Checkout Session completes without a redirect. It does
479
+ * not fire when the session redirects to `returnUrl`: show success from the return
480
+ * page, or reload billing status there.
481
+ */
448
482
  onComplete?: () => void;
449
483
  /** Called with the error when payment fails */
450
484
  onError?: (error: Error) => void;
package/dist/index.d.ts CHANGED
@@ -71,6 +71,7 @@ interface CheckoutSubscriptionResult {
71
71
  interface CompletedCheckoutResult extends CheckoutSubscriptionResult {
72
72
  type: "completed";
73
73
  status: string;
74
+ /** `credits` or `none`. */
74
75
  payment_source?: string;
75
76
  subscription_id?: string;
76
77
  plan_code?: string;
@@ -84,7 +85,9 @@ interface ScheduledCheckoutResult extends CheckoutSubscriptionResult {
84
85
  subscription_id?: string;
85
86
  plan_code?: string;
86
87
  effective_at?: string;
87
- pending_subscription_id?: string;
88
+ /** `upgrade` or `downgrade`. */
89
+ transition_direction?: string;
90
+ transition_policy?: string;
88
91
  }
89
92
  interface RazorpayCheckoutResult {
90
93
  type: "razorpay";
@@ -94,20 +97,40 @@ interface RazorpayCheckoutResult {
94
97
  amount_cents: number;
95
98
  currency: string;
96
99
  expires_at?: string;
100
+ /** Set for an invoice checkout. A paid upgrade returns `plan_upgrade_intent_id` instead. */
97
101
  invoice_id?: string;
102
+ plan_upgrade_intent_id?: string;
103
+ external_entity_id?: string;
104
+ external_subscription_id?: string;
98
105
  customer_id?: string;
99
106
  recurring?: boolean;
100
107
  mandate_max_amount_cents?: number;
101
108
  }
109
+ /**
110
+ * The checkout is not ready to collect payment yet: Razorpay while the order is
111
+ * being created, and Stripe when a quoted upgrade is replayed while its webhook is
112
+ * still pending. Recover with the checkout status call using `checkout_id`.
113
+ */
102
114
  interface ProcessingCheckoutResult {
103
115
  type: "processing";
104
116
  checkout_id: string;
105
117
  status: string;
118
+ amount_cents?: number;
119
+ currency?: string;
120
+ expires_at?: string;
121
+ invoice_id?: string;
122
+ plan_upgrade_intent_id?: string;
106
123
  }
124
+ /** A Razorpay payment link. The customer is redirected to `payment_url`. */
107
125
  interface HostedCheckoutResult {
108
126
  type: "hosted";
109
127
  payment_url: string;
110
128
  checkout_id?: string;
129
+ amount_cents?: number;
130
+ currency?: string;
131
+ expires_at?: string;
132
+ invoice_id?: string;
133
+ plan_upgrade_intent_id?: string;
111
134
  }
112
135
  interface RazorpayVerification {
113
136
  razorpay_order_id: string;
@@ -129,13 +152,19 @@ type VerifyCheckout = (checkoutId: string, verification: RazorpayVerification) =
129
152
  type GetCheckoutStatus = (checkoutId: string) => Promise<CheckoutStatus>;
130
153
  type CheckoutResult = {
131
154
  type: "stripe";
155
+ /** Not returned by plan and invoice checkout, which never issue a Stripe-hosted URL. */
132
156
  url?: string;
157
+ /** Embedded Checkout Session secret (`cs_...`). */
133
158
  clientSecret?: string;
134
159
  client_secret?: string;
160
+ /** Not returned by Nozle. Pass your Stripe publishable key to `Checkout`. */
135
161
  publishable_key?: string;
162
+ /** Not returned by Nozle. */
136
163
  stripe_account?: string;
137
164
  checkout_id?: string;
138
165
  invoice_id?: string;
166
+ /** Set instead of `invoice_id` for a paid upgrade. */
167
+ plan_upgrade_intent_id?: string;
139
168
  amount_cents?: number;
140
169
  currency?: string;
141
170
  external_entity_id?: string;
@@ -291,6 +320,7 @@ interface Plan$1 {
291
320
  declare function usePlans(): {
292
321
  plans: Plan$1[];
293
322
  isLoading: boolean;
323
+ error: Error | null;
294
324
  };
295
325
 
296
326
  interface UseCheckoutResult$1 {
@@ -444,7 +474,11 @@ interface StripeCheckoutProps {
444
474
  submitLabel?: string;
445
475
  /** Called with the paymentIntentId when payment succeeds without redirect */
446
476
  onSuccess?: (paymentIntentId: string) => void;
447
- /** Called when an embedded Checkout Session completes without a redirect. */
477
+ /**
478
+ * Called when an embedded Checkout Session completes without a redirect. It does
479
+ * not fire when the session redirects to `returnUrl`: show success from the return
480
+ * page, or reload billing status there.
481
+ */
448
482
  onComplete?: () => void;
449
483
  /** Called with the error when payment fails */
450
484
  onError?: (error: Error) => void;
package/dist/index.js CHANGED
@@ -2866,8 +2866,12 @@ function usePlans() {
2866
2866
  const { client } = useBillingContext();
2867
2867
  const [plans, setPlans] = useState([]);
2868
2868
  const [isLoading, setIsLoading] = useState(true);
2869
+ const [error, setError] = useState(null);
2869
2870
  useEffect(() => {
2870
2871
  let cancelled = false;
2872
+ setIsLoading(true);
2873
+ setError(null);
2874
+ setPlans([]);
2871
2875
  if (!client) {
2872
2876
  setIsLoading(false);
2873
2877
  return;
@@ -2876,6 +2880,12 @@ function usePlans() {
2876
2880
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
2877
2881
  const data = await response.json();
2878
2882
  if (!cancelled) setPlans(data.plans ?? []);
2883
+ }).catch((cause) => {
2884
+ if (!cancelled) {
2885
+ setError(
2886
+ cause instanceof Error ? cause : new Error("Failed to load plans")
2887
+ );
2888
+ }
2879
2889
  }).finally(() => {
2880
2890
  if (!cancelled) setIsLoading(false);
2881
2891
  });
@@ -2883,7 +2893,7 @@ function usePlans() {
2883
2893
  cancelled = true;
2884
2894
  };
2885
2895
  }, [client]);
2886
- return { plans, isLoading };
2896
+ return { plans, isLoading, error };
2887
2897
  }
2888
2898
  function useCheckout2() {
2889
2899
  const { createCheckout } = useBillingContext();
@@ -3214,10 +3224,11 @@ function PricingTable({
3214
3224
  }
3215
3225
  let cancelled = false;
3216
3226
  client.catalogFetch("/api/v1/plans").then(async (res) => {
3217
- if (!cancelled && res.ok) {
3218
- const data = await res.json();
3219
- setPlans(data.plans || []);
3220
- }
3227
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
3228
+ const data = await res.json();
3229
+ if (!cancelled) setPlans(data.plans || []);
3230
+ }).catch((cause) => {
3231
+ if (!cancelled) setCheckoutError(`Plans could not be loaded: ${cause instanceof Error ? cause.message : "unknown error"}`);
3221
3232
  }).finally(() => {
3222
3233
  if (!cancelled) setLoading(false);
3223
3234
  });