@nozle-js/react 0.10.1 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nozle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -13,7 +13,7 @@ React components for Nozle's public catalog, checkout, and customer billing port
13
13
  ## Install
14
14
 
15
15
  ```bash
16
- npm install @nozle-js/react@0.10.0 react react-dom @stripe/stripe-js @stripe/react-stripe-js
16
+ npm install @nozle-js/react@0.10.2 react react-dom @stripe/stripe-js @stripe/react-stripe-js
17
17
  ```
18
18
 
19
19
  ## Merchant-backed checkout
@@ -50,6 +50,79 @@ The merchant endpoint authenticates the user, derives the Nozle customer from th
50
50
 
51
51
  `createCheckout` returns a `stripe`, `razorpay`, `hosted`, `processing`, `completed`, or `scheduled` result. Nozle payment fulfillment determines activation; Razorpay requires capture. A browser redirect or callback alone does not prove activation.
52
52
 
53
+ ## Payment providers: Stripe and Razorpay
54
+
55
+ Your merchant backend returns whatever result Nozle gives for the customer's connected provider, and `CheckoutButton` handles each `type`:
56
+
57
+ | Result `type` | Provider | What `CheckoutButton` does |
58
+ | --- | --- | --- |
59
+ | `stripe` | Stripe | Calls `onStripeClientSecret` with the `cs_` Embedded Checkout secret. Render `Checkout` with it |
60
+ | `razorpay` | Razorpay | Loads Razorpay's `checkout.js`, opens the modal, then calls your `verifyCheckout` and polls your `getCheckoutStatus` (30 attempts, one second apart) |
61
+ | `hosted` | Razorpay | Declared in the result types; `POST /checkout` does not return it for Razorpay. Invoice payment URLs and credit top-ups return a `payment_url` (an rzp.io payment link) with no checkout id to poll; the React component navigates to `payment_url` (HTTPS only) if one is returned |
62
+ | `processing` | Razorpay or Stripe | Polls `getCheckoutStatus`. For Razorpay it opens the order once ready; Stripe returns `processing` when a quoted upgrade is replayed while its webhook is pending |
63
+ | `completed`, `scheduled` | Either | Calls `onComplete` or `onScheduled`. No payment is collected |
64
+
65
+ Plan and invoice checkout return the Stripe secret but never a Stripe-hosted URL or your Stripe publishable key (credit top-up purchases do return a Stripe-hosted `payment_url`, valid for 24 hours), so pass your own `pk_` key for the connected Stripe account to `Checkout`. For Razorpay, the server supplies `key_id`, `order_id`, amount and currency; `razorpayKeyId` is deprecated. Razorpay supports only INR.
66
+
67
+ ```tsx
68
+ import { useState } from "react";
69
+ import { BillingProvider, Checkout, CheckoutButton } from "@nozle-js/react";
70
+
71
+ export function Upgrade({ csrfToken }: { csrfToken: string }) {
72
+ const [clientSecret, setClientSecret] = useState<string>();
73
+ const post = (path: string, body: object) =>
74
+ fetch(path, {
75
+ method: "POST",
76
+ credentials: "include",
77
+ headers: { "Content-Type": "application/json", "X-CSRF-Token": csrfToken },
78
+ body: JSON.stringify(body),
79
+ }).then((response) => {
80
+ if (!response.ok) throw new Error("Request failed");
81
+ return response.json();
82
+ });
83
+
84
+ return (
85
+ <BillingProvider
86
+ publishableKey="pk_your_catalog_key"
87
+ createCheckout={({ planCode, returnUrl, idempotencyKey }) =>
88
+ post("/api/billing/checkout", { planCode, returnUrl, idempotencyKey })
89
+ }
90
+ // Razorpay only. Your backend calls nozle.verifyCheckout / nozle.checkoutStatus
91
+ // with an sk_ key and the customer and subscription scope it derived.
92
+ verifyCheckout={(checkoutId, verification) =>
93
+ post(`/api/billing/checkout/${checkoutId}/verify`, verification)
94
+ }
95
+ getCheckoutStatus={(checkoutId) =>
96
+ fetch(`/api/billing/checkout/${checkoutId}`, { credentials: "include" }).then(
97
+ (response) => {
98
+ if (!response.ok) throw new Error("Status failed");
99
+ return response.json();
100
+ },
101
+ )
102
+ }
103
+ >
104
+ <CheckoutButton
105
+ planCode="pro_monthly"
106
+ onStripeClientSecret={setClientSecret}
107
+ onSuccess={() => window.location.reload()}
108
+ onComplete={() => window.location.reload()}
109
+ />
110
+ {clientSecret && (
111
+ <Checkout
112
+ clientSecret={clientSecret}
113
+ publishableKey="pk_live_your_stripe_key"
114
+ onComplete={() => window.location.reload()}
115
+ />
116
+ )}
117
+ </BillingProvider>
118
+ );
119
+ }
120
+ ```
121
+
122
+ The Stripe `Checkout` component's `onComplete` does not fire when the session redirects to the `return_url`. Show success from the return page, or reload billing status there, rather than relying on `onComplete` alone. A new-subscription checkout retried while the subscription is still incomplete fails with HTTP 422 `subscription_incomplete`, even with the same idempotency key; your backend can recover with an invoice checkout for the `invoice_id` from the first response. An invoice checkout retried with the same key and a different body currently returns HTTP 500, not 409.
123
+
124
+ `CheckoutButton` rejects a Razorpay result without `checkout_id`, `key_id` and `order_id`, and fails when `BillingProvider` has no `verifyCheckout`. A modal `payment.failed` event shows "Payment failed. You can retry checkout." For a UPI AutoPay mandate, pass `registerMandate` to `CheckoutButton`; the modal then receives `customer_id` and `recurring: "1"` from the result. Show success only after both `status` and `fulfillment_status` are `succeeded`. See the [Stripe](https://docs.nozle.dev/integrations/stripe) and [Razorpay](https://docs.nozle.dev/integrations/razorpay) integration guides.
125
+
53
126
  ## Components
54
127
 
55
128
  - `PricingTable` and `usePlans` read the public catalog with the publishable key.
package/dist/index.cjs CHANGED
@@ -3230,10 +3230,11 @@ function PricingTable({
3230
3230
  }
3231
3231
  let cancelled = false;
3232
3232
  client.catalogFetch("/api/v1/plans").then(async (res) => {
3233
- if (!cancelled && res.ok) {
3234
- const data = await res.json();
3235
- setPlans(data.plans || []);
3236
- }
3233
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
3234
+ const data = await res.json();
3235
+ if (!cancelled) setPlans(data.plans || []);
3236
+ }).catch((cause) => {
3237
+ if (!cancelled) setCheckoutError(`Plans could not be loaded: ${cause instanceof Error ? cause.message : "unknown error"}`);
3237
3238
  }).finally(() => {
3238
3239
  if (!cancelled) setLoading(false);
3239
3240
  });