@solvapay/react 1.0.0-preview.18 → 1.0.0-preview.19

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.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 SolvaPay Inc.
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
@@ -18,18 +18,19 @@ pnpm add @solvapay/react
18
18
  ### Zero-Config Usage (Recommended)
19
19
 
20
20
  ```tsx
21
- import { SolvaPayProvider, PaymentForm, useSubscription } from '@solvapay/react';
21
+ import { SolvaPayProvider, PaymentForm, useSubscription } from '@solvapay/react'
22
22
 
23
23
  export default function App() {
24
24
  return (
25
25
  <SolvaPayProvider>
26
26
  <CheckoutPage />
27
27
  </SolvaPayProvider>
28
- );
28
+ )
29
29
  }
30
30
  ```
31
31
 
32
32
  By default, `SolvaPayProvider` uses:
33
+
33
34
  - `/api/check-subscription` for subscription checks
34
35
  - `/api/create-payment-intent` for payment creation
35
36
  - `/api/process-payment` for payment processing
@@ -37,7 +38,7 @@ By default, `SolvaPayProvider` uses:
37
38
  ### Custom API Routes
38
39
 
39
40
  ```tsx
40
- import { SolvaPayProvider, PaymentForm } from '@solvapay/react';
41
+ import { SolvaPayProvider, PaymentForm } from '@solvapay/react'
41
42
 
42
43
  export default function App() {
43
44
  return (
@@ -52,34 +53,34 @@ export default function App() {
52
53
  >
53
54
  <CheckoutPage />
54
55
  </SolvaPayProvider>
55
- );
56
+ )
56
57
  }
57
58
  ```
58
59
 
59
60
  ### With Supabase Authentication
60
61
 
61
62
  ```tsx
62
- import { SolvaPayProvider } from '@solvapay/react';
63
- import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
63
+ import { SolvaPayProvider } from '@solvapay/react'
64
+ import { createSupabaseAuthAdapter } from '@solvapay/react-supabase'
64
65
 
65
66
  export default function App() {
66
67
  const adapter = createSupabaseAuthAdapter({
67
68
  supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
68
69
  supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
69
- });
70
+ })
70
71
 
71
72
  return (
72
73
  <SolvaPayProvider config={{ auth: { adapter } }}>
73
74
  <CheckoutPage />
74
75
  </SolvaPayProvider>
75
- );
76
+ )
76
77
  }
77
78
  ```
78
79
 
79
80
  ### Fully Custom Implementation
80
81
 
81
82
  ```tsx
82
- import { SolvaPayProvider } from '@solvapay/react';
83
+ import { SolvaPayProvider } from '@solvapay/react'
83
84
 
84
85
  export default function App() {
85
86
  return (
@@ -88,19 +89,19 @@ export default function App() {
88
89
  const res = await fetch('/api/custom/payment', {
89
90
  method: 'POST',
90
91
  body: JSON.stringify({ planRef, agentRef }),
91
- });
92
- if (!res.ok) throw new Error('Failed to create payment');
93
- return res.json();
92
+ })
93
+ if (!res.ok) throw new Error('Failed to create payment')
94
+ return res.json()
94
95
  }}
95
- checkSubscription={async (customerRef) => {
96
- const res = await fetch(`/api/custom/subscription?customerRef=${customerRef}`);
97
- if (!res.ok) throw new Error('Failed to check subscription');
98
- return res.json();
96
+ checkSubscription={async customerRef => {
97
+ const res = await fetch(`/api/custom/subscription?customerRef=${customerRef}`)
98
+ if (!res.ok) throw new Error('Failed to check subscription')
99
+ return res.json()
99
100
  }}
100
101
  >
101
102
  <CheckoutPage />
102
103
  </SolvaPayProvider>
103
- );
104
+ )
104
105
  }
105
106
  ```
106
107
 
@@ -111,6 +112,7 @@ export default function App() {
111
112
  Headless context provider that manages subscription state, payment methods, and customer references.
112
113
 
113
114
  **Features:**
115
+
114
116
  - Zero-config with sensible defaults
115
117
  - Auto-fetches subscriptions on mount
116
118
  - Built-in localStorage caching with user validation
@@ -118,6 +120,7 @@ Headless context provider that manages subscription state, payment methods, and
118
120
  - Customizable API routes via config
119
121
 
120
122
  **Props:**
123
+
121
124
  - `config?: SolvaPayConfig` - Configuration object (optional)
122
125
  - `config.api?` - Custom API route paths
123
126
  - `config.auth?` - Auth adapter configuration
@@ -127,18 +130,19 @@ Headless context provider that manages subscription state, payment methods, and
127
130
  - `children: React.ReactNode` - Child components
128
131
 
129
132
  **Config Options:**
133
+
130
134
  ```tsx
131
135
  interface SolvaPayConfig {
132
136
  api?: {
133
- checkSubscription?: string; // Default: '/api/check-subscription'
134
- createPayment?: string; // Default: '/api/create-payment-intent'
135
- processPayment?: string; // Default: '/api/process-payment'
136
- };
137
+ checkSubscription?: string // Default: '/api/check-subscription'
138
+ createPayment?: string // Default: '/api/create-payment-intent'
139
+ processPayment?: string // Default: '/api/process-payment'
140
+ }
137
141
  auth?: {
138
- adapter?: AuthAdapter; // Auth adapter for extracting user ID/token
139
- getToken?: () => Promise<string | null>; // Deprecated: use adapter
140
- getUserId?: () => Promise<string | null>; // Deprecated: use adapter
141
- };
142
+ adapter?: AuthAdapter // Auth adapter for extracting user ID/token
143
+ getToken?: () => Promise<string | null> // Deprecated: use adapter
144
+ getUserId?: () => Promise<string | null> // Deprecated: use adapter
145
+ }
142
146
  }
143
147
  ```
144
148
 
@@ -147,6 +151,7 @@ interface SolvaPayConfig {
147
151
  Component for selecting and displaying available plans.
148
152
 
149
153
  **Props:**
154
+
150
155
  - `agentRef?: string` - Agent reference to filter plans
151
156
  - `fetcher?: (agentRef: string) => Promise<Plan[]>` - Custom plan fetcher function
152
157
  - `onPlanSelect?: (plan: Plan) => void` - Callback when plan is selected
@@ -154,19 +159,18 @@ Component for selecting and displaying available plans.
154
159
  - `className?: string` - Container className
155
160
 
156
161
  **Example:**
162
+
157
163
  ```tsx
158
- import { PlanSelector, usePlans } from '@solvapay/react';
164
+ import { PlanSelector, usePlans } from '@solvapay/react'
159
165
 
160
166
  function PlansPage() {
161
- const { plans, loading } = usePlans({ agentRef: 'my-agent' });
162
-
167
+ const { plans, loading } = usePlans({ agentRef: 'my-agent' })
168
+
163
169
  return (
164
170
  <div>
165
- {loading ? 'Loading...' : plans.map(plan => (
166
- <div key={plan.reference}>{plan.name}</div>
167
- ))}
171
+ {loading ? 'Loading...' : plans.map(plan => <div key={plan.reference}>{plan.name}</div>)}
168
172
  </div>
169
- );
173
+ )
170
174
  }
171
175
  ```
172
176
 
@@ -175,6 +179,7 @@ function PlansPage() {
175
179
  Payment form component using Stripe PaymentElement. Automatically handles Stripe Elements provider setup.
176
180
 
177
181
  **Props:**
182
+
178
183
  - `planRef: string` - Plan reference for the payment
179
184
  - `agentRef?: string` - Optional agent reference
180
185
  - `onSuccess?: (paymentIntent: PaymentIntent) => void` - Callback on successful payment
@@ -186,8 +191,9 @@ Payment form component using Stripe PaymentElement. Automatically handles Stripe
186
191
  - `buttonClassName?: string` - Submit button className
187
192
 
188
193
  **Example:**
194
+
189
195
  ```tsx
190
- import { PaymentForm } from '@solvapay/react';
196
+ import { PaymentForm } from '@solvapay/react'
191
197
 
192
198
  function CheckoutPage() {
193
199
  return (
@@ -196,7 +202,7 @@ function CheckoutPage() {
196
202
  agentRef="agt_YOUR_AGENT"
197
203
  onSuccess={() => console.log('Payment successful!')}
198
204
  />
199
- );
205
+ )
200
206
  }
201
207
  ```
202
208
 
@@ -205,11 +211,13 @@ function CheckoutPage() {
205
211
  Displays current subscription plan with render props or className pattern.
206
212
 
207
213
  **Props:**
214
+
208
215
  - `children?: (props) => React.ReactNode` - Render prop function
209
216
  - `as?: React.ElementType` - Component to render (default: "div")
210
217
  - `className?: string | ((props) => string)` - ClassName or function
211
218
 
212
219
  **Example:**
220
+
213
221
  ```tsx
214
222
  <PlanBadge className="badge badge-primary" />
215
223
  ```
@@ -219,16 +227,18 @@ Displays current subscription plan with render props or className pattern.
219
227
  Controls access to content based on subscription status.
220
228
 
221
229
  **Props:**
230
+
222
231
  - `requirePlan?: string` - Optional plan name to require
223
232
  - `children: (props) => React.ReactNode` - Render prop function
224
233
 
225
234
  **Example:**
235
+
226
236
  ```tsx
227
237
  <SubscriptionGate requirePlan="Pro Plan">
228
238
  {({ hasAccess, loading, subscriptions }) => {
229
- if (loading) return <Loading />;
230
- if (!hasAccess) return <Paywall />;
231
- return <PremiumContent />;
239
+ if (loading) return <Loading />
240
+ if (!hasAccess) return <Paywall />
241
+ return <PremiumContent />
232
242
  }}
233
243
  </SubscriptionGate>
234
244
  ```
@@ -240,13 +250,13 @@ Controls access to content based on subscription status.
240
250
  Access subscription status, active subscriptions, and helper functions.
241
251
 
242
252
  ```tsx
243
- const {
244
- subscriptions, // Array of all subscriptions
245
- loading, // Loading state
246
- hasPaidSubscription, // Boolean: has any paid subscription
247
- activeSubscription, // Most recent active subscription
248
- refetch // Function to refetch subscriptions
249
- } = useSubscription();
253
+ const {
254
+ subscriptions, // Array of all subscriptions
255
+ loading, // Loading state
256
+ hasPaidSubscription, // Boolean: has any paid subscription
257
+ activeSubscription, // Most recent active subscription
258
+ refetch, // Function to refetch subscriptions
259
+ } = useSubscription()
250
260
  ```
251
261
 
252
262
  ### usePlans
@@ -254,15 +264,15 @@ const {
254
264
  Fetch and manage available plans.
255
265
 
256
266
  ```tsx
257
- const {
258
- plans, // Array of available plans
259
- loading, // Loading state
260
- error, // Error object if fetch failed
261
- refetch // Function to refetch plans
262
- } = usePlans({
263
- agentRef: 'my-agent', // Optional agent reference
264
- fetcher: customFetcher // Optional custom fetcher function
265
- });
267
+ const {
268
+ plans, // Array of available plans
269
+ loading, // Loading state
270
+ error, // Error object if fetch failed
271
+ refetch, // Function to refetch plans
272
+ } = usePlans({
273
+ agentRef: 'my-agent', // Optional agent reference
274
+ fetcher: customFetcher, // Optional custom fetcher function
275
+ })
266
276
  ```
267
277
 
268
278
  ### useSubscriptionStatus
@@ -271,11 +281,11 @@ Advanced subscription status helpers.
271
281
 
272
282
  ```tsx
273
283
  const {
274
- cancelledSubscription, // Most recent cancelled subscription
275
- shouldShowCancelledNotice, // Boolean: should show cancellation notice
276
- formatDate, // Helper to format dates
277
- getDaysUntilExpiration // Helper to get days until expiration
278
- } = useSubscriptionStatus();
284
+ cancelledSubscription, // Most recent cancelled subscription
285
+ shouldShowCancelledNotice, // Boolean: should show cancellation notice
286
+ formatDate, // Helper to format dates
287
+ getDaysUntilExpiration, // Helper to get days until expiration
288
+ } = useSubscriptionStatus()
279
289
  ```
280
290
 
281
291
  ### useCheckout
@@ -283,7 +293,7 @@ const {
283
293
  Manage checkout flow for a specific plan.
284
294
 
285
295
  ```tsx
286
- const { loading, error, startCheckout, reset } = useCheckout('plan_ref');
296
+ const { loading, error, startCheckout, reset } = useCheckout('plan_ref')
287
297
  ```
288
298
 
289
299
  ### useSolvaPay
@@ -291,14 +301,14 @@ const { loading, error, startCheckout, reset } = useCheckout('plan_ref');
291
301
  Access SolvaPay context directly.
292
302
 
293
303
  ```tsx
294
- const {
295
- subscriptionData, // Full subscription data
296
- loading, // Loading state
297
- createPayment, // Payment creation function
298
- processPayment, // Payment processing function
299
- customerRef, // Current customer reference
300
- updateCustomerRef // Function to update customer reference
301
- } = useSolvaPay();
304
+ const {
305
+ subscriptionData, // Full subscription data
306
+ loading, // Loading state
307
+ createPayment, // Payment creation function
308
+ processPayment, // Payment processing function
309
+ customerRef, // Current customer reference
310
+ updateCustomerRef, // Function to update customer reference
311
+ } = useSolvaPay()
302
312
  ```
303
313
 
304
314
  ## TypeScript
@@ -306,9 +316,9 @@ const {
306
316
  All components and hooks are fully typed. Import types as needed:
307
317
 
308
318
  ```tsx
309
- import type { PaymentFormProps, SubscriptionStatus, PaymentIntentResult } from '@solvapay/react';
319
+ import type { PaymentFormProps, SubscriptionStatus, PaymentIntentResult } from '@solvapay/react'
310
320
  ```
311
321
 
312
322
  ## More Information
313
323
 
314
- See `docs/architecture.md` for detailed architecture documentation.
324
+ See [`docs/guides/architecture.md`](../../docs/guides/architecture.md) for detailed architecture documentation.