@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/LICENSE +21 -0
- package/README.md +79 -2
- package/dist/index.cjs +16 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -2
- package/dist/index.d.ts +36 -2
- package/dist/index.js +16 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
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.
|
|
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.
|
|
@@ -147,7 +220,7 @@ formats amounts/dates. Errors use `code: "session" | "unauthorized" | "request"
|
|
|
147
220
|
Pass `planChangeActions` to `BillingPortal`, or use the standalone `PlanChangeControl`.
|
|
148
221
|
Its adapter provides `load`, `status`, `preview`, `apply`, and `withdraw`; use
|
|
149
222
|
`verifyCheckout` and `getCheckoutStatus` for scoped payment verification/recovery.
|
|
150
|
-
The Node.js `0.9.0` and Python `0.9.0` SDKs
|
|
223
|
+
The Node.js `0.9.0` and Python `0.9.0` SDKs introduced the matching backend methods. Use `0.9.1` of either backend SDK for the Feature Event timestamp fix used by provider capture.
|
|
151
224
|
|
|
152
225
|
Load eligible plans for the selected external subscription, confirm the signed quote,
|
|
153
226
|
and retain the same quote and idempotency key for uncertain retries. Upgrades activate
|
|
@@ -159,3 +232,7 @@ See the [billing portal guide](https://docs.nozle.dev/sdks/react/billing-portal)
|
|
|
159
232
|
complete typed adapters, standalone controls, and the runnable Node/Python integrations.
|
|
160
233
|
The hosted Nozle backend supports these flows; self-hosted deployments need the matching
|
|
161
234
|
subscription-management endpoints and cancellation-date guard.
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
Proprietary. Contact Nozle about licensing.
|
package/dist/index.cjs
CHANGED
|
@@ -2872,8 +2872,12 @@ function usePlans() {
|
|
|
2872
2872
|
const { client } = useBillingContext();
|
|
2873
2873
|
const [plans, setPlans] = React.useState([]);
|
|
2874
2874
|
const [isLoading, setIsLoading] = React.useState(true);
|
|
2875
|
+
const [error, setError] = React.useState(null);
|
|
2875
2876
|
React.useEffect(() => {
|
|
2876
2877
|
let cancelled = false;
|
|
2878
|
+
setIsLoading(true);
|
|
2879
|
+
setError(null);
|
|
2880
|
+
setPlans([]);
|
|
2877
2881
|
if (!client) {
|
|
2878
2882
|
setIsLoading(false);
|
|
2879
2883
|
return;
|
|
@@ -2882,6 +2886,12 @@ function usePlans() {
|
|
|
2882
2886
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
2883
2887
|
const data = await response.json();
|
|
2884
2888
|
if (!cancelled) setPlans(data.plans ?? []);
|
|
2889
|
+
}).catch((cause) => {
|
|
2890
|
+
if (!cancelled) {
|
|
2891
|
+
setError(
|
|
2892
|
+
cause instanceof Error ? cause : new Error("Failed to load plans")
|
|
2893
|
+
);
|
|
2894
|
+
}
|
|
2885
2895
|
}).finally(() => {
|
|
2886
2896
|
if (!cancelled) setIsLoading(false);
|
|
2887
2897
|
});
|
|
@@ -2889,7 +2899,7 @@ function usePlans() {
|
|
|
2889
2899
|
cancelled = true;
|
|
2890
2900
|
};
|
|
2891
2901
|
}, [client]);
|
|
2892
|
-
return { plans, isLoading };
|
|
2902
|
+
return { plans, isLoading, error };
|
|
2893
2903
|
}
|
|
2894
2904
|
function useCheckout2() {
|
|
2895
2905
|
const { createCheckout } = useBillingContext();
|
|
@@ -3220,10 +3230,11 @@ function PricingTable({
|
|
|
3220
3230
|
}
|
|
3221
3231
|
let cancelled = false;
|
|
3222
3232
|
client.catalogFetch("/api/v1/plans").then(async (res) => {
|
|
3223
|
-
if (!
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
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"}`);
|
|
3227
3238
|
}).finally(() => {
|
|
3228
3239
|
if (!cancelled) setLoading(false);
|
|
3229
3240
|
});
|