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

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
@@ -8,22 +8,35 @@ export { defaultAuthAdapter } from './adapters/auth.js';
8
8
  * TypeScript type definitions for @solvapay/react
9
9
  */
10
10
 
11
- interface SubscriptionInfo {
11
+ interface PurchaseInfo {
12
12
  reference: string;
13
+ productName: string;
14
+ productReference: string;
13
15
  planName: string;
14
- agentName: string;
15
16
  status: string;
16
17
  startDate: string;
17
18
  endDate?: string;
18
19
  cancelledAt?: string;
19
20
  cancellationReason?: string;
20
21
  amount?: number;
22
+ currency?: string;
23
+ planType?: string;
24
+ isRecurring?: boolean;
25
+ nextBillingDate?: string;
26
+ billingCycle?: string;
27
+ transactionId?: string;
28
+ usage?: {
29
+ used: number;
30
+ quota: number | null;
31
+ unit: string;
32
+ remaining: number | null;
33
+ };
21
34
  }
22
- interface CustomerSubscriptionData {
35
+ interface CustomerPurchaseData {
23
36
  customerRef?: string;
24
37
  email?: string;
25
38
  name?: string;
26
- subscriptions: SubscriptionInfo[];
39
+ purchases: PurchaseInfo[];
27
40
  }
28
41
  interface PaymentIntentResult {
29
42
  clientSecret: string;
@@ -31,31 +44,31 @@ interface PaymentIntentResult {
31
44
  accountId?: string;
32
45
  customerRef?: string;
33
46
  }
34
- interface SubscriptionStatus {
47
+ interface PurchaseStatus {
35
48
  loading: boolean;
36
49
  customerRef?: string;
37
50
  email?: string;
38
51
  name?: string;
39
- subscriptions: SubscriptionInfo[];
52
+ purchases: PurchaseInfo[];
40
53
  hasPlan: (planName: string) => boolean;
41
54
  /**
42
- * Primary active subscription (paid or free) - most recent subscription with status === 'active'
43
- * Backend keeps subscriptions as 'active' until expiration, even when cancelled.
44
- * null if no active subscription exists
55
+ * Primary active purchase (paid or free) - most recent purchase with status === 'active'
56
+ * Backend keeps purchases as 'active' until expiration, even when cancelled.
57
+ * null if no active purchase exists
45
58
  */
46
- activeSubscription: SubscriptionInfo | null;
59
+ activePurchase: PurchaseInfo | null;
47
60
  /**
48
- * Check if user has any active paid subscription (amount > 0)
49
- * Checks subscriptions with status === 'active'.
50
- * Backend keeps subscriptions as 'active' until expiration, even when cancelled.
61
+ * Check if user has any active paid purchase (amount > 0)
62
+ * Checks purchases with status === 'active'.
63
+ * Backend keeps purchases as 'active' until expiration, even when cancelled.
51
64
  */
52
- hasPaidSubscription: boolean;
65
+ hasPaidPurchase: boolean;
53
66
  /**
54
- * Most recent active paid subscription (sorted by startDate)
55
- * Returns subscription with status === 'active' and amount > 0.
56
- * null if no active paid subscription exists
67
+ * Most recent active paid purchase (sorted by startDate)
68
+ * Returns purchase with status === 'active' and amount > 0.
69
+ * null if no active paid purchase exists
57
70
  */
58
- activePaidSubscription: SubscriptionInfo | null;
71
+ activePaidPurchase: PurchaseInfo | null;
59
72
  }
60
73
  /**
61
74
  * SolvaPay Provider Configuration
@@ -67,7 +80,7 @@ interface SolvaPayConfig {
67
80
  * Defaults to standard Next.js API routes
68
81
  */
69
82
  api?: {
70
- checkSubscription?: string;
83
+ checkPurchase?: string;
71
84
  createPayment?: string;
72
85
  processPayment?: string;
73
86
  };
@@ -125,15 +138,15 @@ interface SolvaPayConfig {
125
138
  onError?: (error: Error, context: string) => void;
126
139
  }
127
140
  interface SolvaPayContextValue {
128
- subscription: SubscriptionStatus;
129
- refetchSubscription: () => Promise<void>;
141
+ purchase: PurchaseStatus;
142
+ refetchPurchase: () => Promise<void>;
130
143
  createPayment: (params: {
131
144
  planRef: string;
132
- agentRef?: string;
145
+ productRef?: string;
133
146
  }) => Promise<PaymentIntentResult>;
134
147
  processPayment?: (params: {
135
148
  paymentIntentId: string;
136
- agentRef: string;
149
+ productRef: string;
137
150
  planRef?: string;
138
151
  }) => Promise<ProcessPaymentResult>;
139
152
  customerRef?: string;
@@ -151,33 +164,34 @@ interface SolvaPayProviderProps {
151
164
  */
152
165
  createPayment?: (params: {
153
166
  planRef: string;
154
- agentRef?: string;
167
+ productRef?: string;
155
168
  }) => Promise<PaymentIntentResult>;
156
- checkSubscription?: () => Promise<CustomerSubscriptionData>;
169
+ checkPurchase?: () => Promise<CustomerPurchaseData>;
157
170
  processPayment?: (params: {
158
171
  paymentIntentId: string;
159
- agentRef: string;
172
+ productRef: string;
160
173
  planRef?: string;
161
174
  }) => Promise<ProcessPaymentResult>;
162
175
  children: React.ReactNode;
163
176
  }
164
177
  interface PlanBadgeProps {
165
178
  children?: (props: {
166
- subscriptions: SubscriptionInfo[];
179
+ purchases: PurchaseInfo[];
167
180
  loading: boolean;
168
181
  displayPlan: string | null;
169
182
  shouldShow: boolean;
170
183
  }) => React.ReactNode;
171
184
  as?: React.ElementType;
172
185
  className?: string | ((props: {
173
- subscriptions: SubscriptionInfo[];
186
+ purchases: PurchaseInfo[];
174
187
  }) => string);
175
188
  }
176
- interface SubscriptionGateProps {
189
+ interface PurchaseGateProps {
177
190
  requirePlan?: string;
191
+ requireProduct?: string;
178
192
  children: (props: {
179
193
  hasAccess: boolean;
180
- subscriptions: SubscriptionInfo[];
194
+ purchases: PurchaseInfo[];
181
195
  loading: boolean;
182
196
  }) => React.ReactNode;
183
197
  }
@@ -189,7 +203,7 @@ interface PaymentError extends Error {
189
203
  type?: string;
190
204
  }
191
205
  /**
192
- * Plan interface for subscription plans
206
+ * Plan interface for plans
193
207
  */
194
208
  interface Plan {
195
209
  reference: string;
@@ -209,11 +223,11 @@ interface UsePlansOptions {
209
223
  /**
210
224
  * Fetcher function to retrieve plans
211
225
  */
212
- fetcher: (agentRef: string) => Promise<Plan[]>;
226
+ fetcher: (productRef: string) => Promise<Plan[]>;
213
227
  /**
214
- * Agent reference to fetch plans for
228
+ * Product reference to fetch plans for
215
229
  */
216
- agentRef?: string;
230
+ productRef?: string;
217
231
  /**
218
232
  * Optional filter function to filter plans
219
233
  */
@@ -245,13 +259,13 @@ interface UsePlansReturn {
245
259
  */
246
260
  interface PlanSelectorProps {
247
261
  /**
248
- * Agent reference to fetch plans for
262
+ * Product reference to fetch plans for
249
263
  */
250
- agentRef?: string;
264
+ productRef?: string;
251
265
  /**
252
266
  * Fetcher function to retrieve plans
253
267
  */
254
- fetcher: (agentRef: string) => Promise<Plan[]>;
268
+ fetcher: (productRef: string) => Promise<Plan[]>;
255
269
  /**
256
270
  * Optional filter function
257
271
  */
@@ -268,27 +282,27 @@ interface PlanSelectorProps {
268
282
  * Render prop function
269
283
  */
270
284
  children: (props: UsePlansReturn & {
271
- subscriptions: SubscriptionInfo[];
285
+ purchases: PurchaseInfo[];
272
286
  isPaidPlan: (planName: string) => boolean;
273
287
  isCurrentPlan: (planName: string) => boolean;
274
288
  }) => React.ReactNode;
275
289
  }
276
290
  /**
277
- * Return type for useSubscriptionStatus hook
291
+ * Return type for usePurchaseStatus hook
278
292
  *
279
- * Provides advanced subscription status helpers and utilities.
280
- * Focuses on cancelled subscription logic and date formatting.
281
- * For basic subscription data and paid status, use useSubscription() instead.
293
+ * Provides advanced purchase status helpers and utilities.
294
+ * Focuses on cancelled purchase logic and date formatting.
295
+ * For basic purchase data and paid status, use usePurchase() instead.
282
296
  */
283
- interface SubscriptionStatusReturn {
297
+ interface PurchaseStatusReturn {
284
298
  /**
285
- * Most recent cancelled paid subscription (sorted by startDate)
286
- * null if no cancelled paid subscription exists
299
+ * Most recent cancelled paid purchase (sorted by startDate)
300
+ * null if no cancelled paid purchase exists
287
301
  */
288
- cancelledSubscription: SubscriptionInfo | null;
302
+ cancelledPurchase: PurchaseInfo | null;
289
303
  /**
290
- * Whether to show cancelled subscription notice
291
- * true if cancelledSubscription exists
304
+ * Whether to show cancelled purchase notice
305
+ * true if cancelledPurchase exists
292
306
  */
293
307
  shouldShowCancelledNotice: boolean;
294
308
  /**
@@ -312,9 +326,9 @@ interface PaymentFormProps {
312
326
  */
313
327
  planRef: string;
314
328
  /**
315
- * Agent reference. Required for processing payment after confirmation.
329
+ * Product reference. Required for processing payment after confirmation.
316
330
  */
317
- agentRef?: string;
331
+ productRef?: string;
318
332
  /**
319
333
  * Callback when payment succeeds
320
334
  */
@@ -340,16 +354,17 @@ interface PaymentFormProps {
340
354
  */
341
355
  buttonClassName?: string;
342
356
  }
357
+ type PurchaseStatusValue = 'pending' | 'active' | 'trialing' | 'past_due' | 'cancelled' | 'expired' | 'suspended' | 'refunded';
343
358
 
344
359
  /**
345
360
  * SolvaPay Provider - Headless Context Provider for React.
346
361
  *
347
- * Provides subscription state, payment methods, and customer data to child components
362
+ * Provides purchase state, payment methods, and customer data to child components
348
363
  * via React Context. This is the root component that must wrap your app to use
349
364
  * SolvaPay React hooks and components.
350
365
  *
351
366
  * Features:
352
- * - Automatic subscription status checking
367
+ * - Automatic purchase status checking
353
368
  * - Customer reference caching in localStorage
354
369
  * - Payment intent creation and processing
355
370
  * - Authentication adapter support (Supabase, custom, etc.)
@@ -358,7 +373,7 @@ interface PaymentFormProps {
358
373
  * @param props - Provider configuration
359
374
  * @param props.config - Configuration object for API routes and authentication
360
375
  * @param props.config.api - API route configuration (optional, uses defaults if not provided)
361
- * @param props.config.api.checkSubscription - Endpoint for checking subscription status (default: '/api/check-subscription')
376
+ * @param props.config.api.checkPurchase - Endpoint for checking purchase status (default: '/api/check-purchase')
362
377
  * @param props.config.api.createPayment - Endpoint for creating payment intents (default: '/api/create-payment-intent')
363
378
  * @param props.config.api.processPayment - Endpoint for processing payments (default: '/api/process-payment')
364
379
  * @param props.config.auth - Authentication configuration (optional)
@@ -384,7 +399,7 @@ interface PaymentFormProps {
384
399
  * <SolvaPayProvider
385
400
  * config={{
386
401
  * api: {
387
- * checkSubscription: '/custom/api/subscription',
402
+ * checkPurchase: '/custom/api/purchase',
388
403
  * createPayment: '/custom/api/payment'
389
404
  * }
390
405
  * }}
@@ -415,7 +430,7 @@ interface PaymentFormProps {
415
430
  * }
416
431
  * ```
417
432
  *
418
- * @see {@link useSubscription} for accessing subscription data
433
+ * @see {@link usePurchase} for accessing purchase data
419
434
  * @see {@link useCheckout} for payment checkout flow
420
435
  * @see {@link useSolvaPay} for accessing provider methods
421
436
  * @since 1.0.0
@@ -434,11 +449,11 @@ declare const SolvaPayProvider: React$1.FC<SolvaPayProviderProps>;
434
449
  * - Payment intent creation on mount
435
450
  * - Card input and validation
436
451
  * - Payment processing with error handling
437
- * - Automatic subscription refresh after payment
452
+ * - Automatic purchase refresh after payment
438
453
  *
439
454
  * @param props - Payment form configuration
440
- * @param props.planRef - Plan reference to subscribe to (required)
441
- * @param props.agentRef - Agent reference for usage tracking (required)
455
+ * @param props.planRef - Plan reference to purchase (required)
456
+ * @param props.productRef - Product reference for usage tracking
442
457
  * @param props.onSuccess - Callback when payment succeeds
443
458
  * @param props.onError - Callback when payment fails
444
459
  * @param props.returnUrl - Optional return URL after payment (for redirects)
@@ -457,7 +472,7 @@ declare const SolvaPayProvider: React$1.FC<SolvaPayProviderProps>;
457
472
  * return (
458
473
  * <PaymentForm
459
474
  * planRef="pln_premium"
460
- * agentRef="agt_myapi"
475
+ * productRef="prd_myapi"
461
476
  * onSuccess={() => {
462
477
  * console.log('Payment successful!');
463
478
  * router.push('/dashboard');
@@ -479,20 +494,20 @@ declare const PaymentForm: React$1.FC<PaymentFormProps>;
479
494
  /**
480
495
  * Headless Plan Badge Component
481
496
  *
482
- * Displays subscription status with complete styling control.
497
+ * Displays purchase status with complete styling control.
483
498
  * Supports render props, custom components, or className patterns.
484
499
  *
485
- * Prevents flickering by hiding the badge during initial load and when no subscription exists.
486
- * Shows the badge once loading completes AND an active subscription exists (paid or free).
500
+ * Prevents flickering by hiding the badge during initial load and when no purchase exists.
501
+ * Shows the badge once loading completes AND an active purchase exists (paid or free).
487
502
  * Badge only updates when the plan name actually changes (prevents unnecessary re-renders).
488
503
  *
489
- * Displays the primary active subscription (paid or free) to show current plan status.
504
+ * Displays the primary active purchase (paid or free) to show current plan status.
490
505
  *
491
506
  * @example
492
507
  * ```tsx
493
508
  * // Render prop pattern
494
509
  * <PlanBadge>
495
- * {({ subscriptions, loading, displayPlan, shouldShow }) => (
510
+ * {({ purchases, loading, displayPlan, shouldShow }) => (
496
511
  * shouldShow ? (
497
512
  * <div>{displayPlan}</div>
498
513
  * ) : null
@@ -506,42 +521,42 @@ declare const PaymentForm: React$1.FC<PaymentFormProps>;
506
521
  declare const PlanBadge: React$1.FC<PlanBadgeProps>;
507
522
 
508
523
  /**
509
- * Headless Subscription Gate Component
524
+ * Headless Purchase Gate Component
510
525
  *
511
- * Controls access to content based on subscription status.
526
+ * Controls access to content based on purchase status.
512
527
  * Uses render props to give developers full control over locked/unlocked states.
513
528
  *
514
529
  * @example
515
530
  * ```tsx
516
- * <SubscriptionGate requirePlan="Pro Plan">
531
+ * <PurchaseGate requirePlan="Pro Plan">
517
532
  * {({ hasAccess, loading }) => {
518
533
  * if (loading) return <Skeleton />;
519
534
  * if (!hasAccess) return <Paywall />;
520
535
  * return <PremiumContent />;
521
536
  * }}
522
- * </SubscriptionGate>
537
+ * </PurchaseGate>
523
538
  * ```
524
539
  */
525
- declare const SubscriptionGate: React$1.FC<SubscriptionGateProps>;
540
+ declare const PurchaseGate: React$1.FC<PurchaseGateProps>;
526
541
 
527
542
  /**
528
543
  * Headless Plan Selector Component
529
544
  *
530
545
  * Provides plan selection logic with complete styling control via render props.
531
- * Integrates plan fetching, subscription status, and selection state management.
546
+ * Integrates plan fetching, purchase status, and selection state management.
532
547
  *
533
548
  * Features:
534
549
  * - Fetches and manages plans
535
550
  * - Tracks selected plan
536
551
  * - Provides helpers for checking if plan is current/paid
537
- * - Integrates with subscription context
552
+ * - Integrates with purchase context
538
553
  *
539
554
  * @example
540
555
  * ```tsx
541
556
  * <PlanSelector
542
- * agentRef="agent_123"
543
- * fetcher={async (agentRef) => {
544
- * const res = await fetch(`/api/list-plans?agentRef=${agentRef}`);
557
+ * productRef="prd_123"
558
+ * fetcher={async (productRef) => {
559
+ * const res = await fetch(`/api/list-plans?productRef=${productRef}`);
545
560
  * const data = await res.json();
546
561
  * return data.plans;
547
562
  * }}
@@ -596,36 +611,36 @@ interface StripePaymentFormWrapperProps {
596
611
  declare const StripePaymentFormWrapper: React$1.FC<StripePaymentFormWrapperProps>;
597
612
 
598
613
  /**
599
- * Hook to get current subscription status and information.
614
+ * Hook to get current purchase status and information.
600
615
  *
601
- * Returns the current user's subscription status, including active
602
- * subscriptions, plan details, and payment information. Automatically
616
+ * Returns the current user's purchase status, including active
617
+ * purchases, plan details, and payment information. Automatically
603
618
  * syncs with the SolvaPay backend and handles loading and error states.
604
619
  *
605
- * @returns Subscription data and status
606
- * @returns subscriptions - Array of active subscriptions
607
- * @returns hasPaidSubscription - Whether user has any paid subscription
620
+ * @returns Purchase data and status
621
+ * @returns purchases - Array of active purchases
622
+ * @returns hasPaidPurchase - Whether user has any paid purchase
608
623
  * @returns isLoading - Loading state
609
- * @returns error - Error state if subscription check fails
610
- * @returns refetch - Function to manually refetch subscription data
624
+ * @returns error - Error state if purchase check fails
625
+ * @returns refetch - Function to manually refetch purchase data
611
626
  *
612
627
  * @example
613
628
  * ```tsx
614
- * import { useSubscription } from '@solvapay/react';
629
+ * import { usePurchase } from '@solvapay/react';
615
630
  *
616
631
  * function Dashboard() {
617
- * const { subscriptions, hasPaidSubscription, isLoading, refetch } = useSubscription();
632
+ * const { purchases, hasPaidPurchase, isLoading, refetch } = usePurchase();
618
633
  *
619
634
  * if (isLoading) return <Spinner />;
620
635
  *
621
- * if (!hasPaidSubscription) {
636
+ * if (!hasPaidPurchase) {
622
637
  * return <UpgradePrompt />;
623
638
  * }
624
639
  *
625
640
  * return (
626
641
  * <div>
627
642
  * <h2>Welcome, Premium User!</h2>
628
- * <p>Active subscriptions: {subscriptions.length}</p>
643
+ * <p>Active purchases: {purchases.length}</p>
629
644
  * <button onClick={() => refetch()}>Refresh</button>
630
645
  * </div>
631
646
  * );
@@ -633,10 +648,10 @@ declare const StripePaymentFormWrapper: React$1.FC<StripePaymentFormWrapperProps
633
648
  * ```
634
649
  *
635
650
  * @see {@link SolvaPayProvider} for required context provider
636
- * @see {@link useSubscriptionStatus} for detailed status information
651
+ * @see {@link usePurchaseStatus} for detailed status information
637
652
  * @since 1.0.0
638
653
  */
639
- declare function useSubscription(): SubscriptionStatus & {
654
+ declare function usePurchase(): PurchaseStatus & {
640
655
  refetch: () => Promise<void>;
641
656
  };
642
657
 
@@ -663,7 +678,7 @@ interface CustomerInfo {
663
678
  }
664
679
  /**
665
680
  * Hook to access customer information
666
- * Returns customer data (email, name, customerRef) separate from subscription data
681
+ * Returns customer data (email, name, customerRef) separate from purchase data
667
682
  *
668
683
  * @example
669
684
  * ```tsx
@@ -698,8 +713,9 @@ interface UseCheckoutReturn {
698
713
  * manages the checkout state including loading, errors, Stripe instance,
699
714
  * and client secret. Use this for programmatic checkout flows.
700
715
  *
701
- * @param planRef - Plan reference to subscribe to (required)
702
- * @param agentRef - Optional agent reference for usage tracking
716
+ * @param options - Checkout options
717
+ * @param options.planRef - Plan reference to purchase (required)
718
+ * @param options.productRef - Optional product reference for usage tracking
703
719
  * @returns Checkout state and methods
704
720
  * @returns loading - Whether checkout is in progress
705
721
  * @returns error - Error state if checkout fails
@@ -714,10 +730,10 @@ interface UseCheckoutReturn {
714
730
  * import { PaymentElement } from '@stripe/react-stripe-js';
715
731
  *
716
732
  * function CustomCheckout() {
717
- * const { loading, error, stripePromise, clientSecret, startCheckout } = useCheckout(
718
- * 'pln_premium',
719
- * 'agt_myapi'
720
- * );
733
+ * const { loading, error, stripePromise, clientSecret, startCheckout } = useCheckout({
734
+ * planRef: 'pln_premium',
735
+ * productRef: 'prd_myapi',
736
+ * });
721
737
  *
722
738
  * useEffect(() => {
723
739
  * startCheckout();
@@ -739,46 +755,49 @@ interface UseCheckoutReturn {
739
755
  * @see {@link SolvaPayProvider} for required context provider
740
756
  * @since 1.0.0
741
757
  */
742
- declare function useCheckout(planRef: string, agentRef?: string): UseCheckoutReturn;
758
+ declare function useCheckout(options: {
759
+ planRef: string;
760
+ productRef?: string;
761
+ }): UseCheckoutReturn;
743
762
 
744
763
  /**
745
764
  * Hook to access SolvaPay context and provider methods.
746
765
  *
747
766
  * This is the base hook that provides access to all SolvaPay functionality
748
- * including subscription data, payment methods, and customer information.
749
- * Other hooks like `useSubscription` and `useCheckout` use this internally.
767
+ * including purchase data, payment methods, and customer information.
768
+ * Other hooks like `usePurchase` and `useCheckout` use this internally.
750
769
  *
751
770
  * Must be used within a `SolvaPayProvider` component.
752
771
  *
753
772
  * @returns SolvaPay context value with all provider methods and state
754
- * @returns subscription - Subscription status and data
773
+ * @returns purchase - Purchase status and data
755
774
  * @returns createPayment - Function to create payment intents
756
775
  * @returns processPayment - Function to process payments
757
776
  * @returns customerRef - Current customer reference
758
- * @returns refetchSubscription - Function to refetch subscription data
777
+ * @returns refetchPurchase - Function to refetch purchase data
759
778
  *
760
779
  * @example
761
780
  * ```tsx
762
781
  * import { useSolvaPay } from '@solvapay/react';
763
782
  *
764
783
  * function CustomComponent() {
765
- * const { subscription, createPayment, processPayment } = useSolvaPay();
784
+ * const { purchase, createPayment, processPayment } = useSolvaPay();
766
785
  *
767
786
  * const handlePayment = async () => {
768
787
  * const intent = await createPayment({
769
788
  * planRef: 'pln_premium',
770
- * agentRef: 'agt_myapi'
789
+ * productRef: 'prd_myapi'
771
790
  * });
772
791
  * // Process payment...
773
792
  * };
774
793
  *
775
- * return <div>Subscription status: {subscription.hasPaidSubscription ? 'Active' : 'None'}</div>;
794
+ * return <div>Purchase status: {purchase.hasPaidPurchase ? 'Active' : 'None'}</div>;
776
795
  * }
777
796
  * ```
778
797
  *
779
798
  * @throws {Error} If used outside of SolvaPayProvider
780
799
  * @see {@link SolvaPayProvider} for required context provider
781
- * @see {@link useSubscription} for subscription-specific hook
800
+ * @see {@link usePurchase} for purchase-specific hook
782
801
  * @see {@link useCheckout} for checkout-specific hook
783
802
  * @since 1.0.0
784
803
  */
@@ -787,16 +806,16 @@ declare function useSolvaPay(): SolvaPayContextValue;
787
806
  /**
788
807
  * Hook to manage plan fetching and selection
789
808
  *
790
- * Provides a reusable way to fetch, filter, sort and select subscription plans.
809
+ * Provides a reusable way to fetch, filter, sort and select plans.
791
810
  * Handles loading and error states automatically.
792
- * Uses a global cache to prevent duplicate fetches when multiple components use the same agentRef.
811
+ * Uses a global cache to prevent duplicate fetches when multiple components use the same productRef.
793
812
  *
794
813
  * @example
795
814
  * ```tsx
796
815
  * const plans = usePlans({
797
- * agentRef: 'agent_123',
798
- * fetcher: async (agentRef) => {
799
- * const res = await fetch(`/api/list-plans?agentRef=${agentRef}`);
816
+ * productRef: 'prd_123',
817
+ * fetcher: async (productRef) => {
818
+ * const res = await fetch(`/api/list-plans?productRef=${productRef}`);
800
819
  * const data = await res.json();
801
820
  * return data.plans;
802
821
  * },
@@ -812,78 +831,78 @@ declare function useSolvaPay(): SolvaPayContextValue;
812
831
  declare function usePlans(options: UsePlansOptions): UsePlansReturn;
813
832
 
814
833
  /**
815
- * Hook providing advanced status and helper functions for subscription management
834
+ * Hook providing advanced status and helper functions for purchase management
816
835
  *
817
- * Focuses on cancelled subscription logic and date formatting utilities.
818
- * For basic subscription data and paid status checks, use useSubscription() instead.
836
+ * Focuses on cancelled purchase logic and date formatting utilities.
837
+ * For basic purchase data and paid status checks, use usePurchase() instead.
819
838
  *
820
839
  * @example
821
840
  * ```tsx
822
- * const { cancelledSubscription, shouldShowCancelledNotice, formatDate, getDaysUntilExpiration } = useSubscriptionStatus();
841
+ * const { cancelledPurchase, shouldShowCancelledNotice, formatDate, getDaysUntilExpiration } = usePurchaseStatus();
823
842
  *
824
- * if (shouldShowCancelledNotice && cancelledSubscription) {
825
- * const formattedDate = formatDate(cancelledSubscription.endDate);
826
- * const daysLeft = getDaysUntilExpiration(cancelledSubscription.endDate);
843
+ * if (shouldShowCancelledNotice && cancelledPurchase) {
844
+ * const formattedDate = formatDate(cancelledPurchase.endDate);
845
+ * const daysLeft = getDaysUntilExpiration(cancelledPurchase.endDate);
827
846
  * }
828
847
  * ```
829
848
  */
830
- declare function useSubscriptionStatus(): SubscriptionStatusReturn;
849
+ declare function usePurchaseStatus(): PurchaseStatusReturn;
831
850
 
832
851
  /**
833
- * Subscription utility functions
852
+ * Purchase utility functions
834
853
  *
835
- * Provides shared logic for filtering and prioritizing subscriptions
854
+ * Provides shared logic for filtering and prioritizing purchases
836
855
  */
837
856
 
838
857
  /**
839
- * Filter subscriptions to only include active ones
858
+ * Filter purchases to only include active ones
840
859
  *
841
860
  * Rules:
842
- * - Keep subscriptions with status === 'active'
843
- * - Filter out subscriptions with status === 'cancelled', 'expired', 'suspended', 'refunded', etc.
861
+ * - Keep purchases with status === 'active'
862
+ * - Filter out purchases with status === 'cancelled', 'expired', 'suspended', 'refunded', etc.
844
863
  *
845
- * Note: Backend now keeps subscriptions with status 'active' until expiration,
864
+ * Note: Backend now keeps purchases with status 'active' until expiration,
846
865
  * even when cancelled. Cancellation is tracked via cancelledAt field.
847
866
  */
848
- declare function filterSubscriptions(subscriptions: SubscriptionInfo[]): SubscriptionInfo[];
867
+ declare function filterPurchases(purchases: PurchaseInfo[]): PurchaseInfo[];
849
868
  /**
850
- * Get active subscriptions
869
+ * Get active purchases
851
870
  *
852
- * Returns subscriptions with status === 'active'.
853
- * Note: Backend keeps subscriptions as 'active' until expiration, even when cancelled.
854
- * Use cancelledAt field to check if a subscription is cancelled.
871
+ * Returns purchases with status === 'active'.
872
+ * Note: Backend keeps purchases as 'active' until expiration, even when cancelled.
873
+ * Use cancelledAt field to check if a purchase is cancelled.
855
874
  */
856
- declare function getActiveSubscriptions(subscriptions: SubscriptionInfo[]): SubscriptionInfo[];
875
+ declare function getActivePurchases(purchases: PurchaseInfo[]): PurchaseInfo[];
857
876
  /**
858
- * Get cancelled subscriptions with valid endDate (not expired)
877
+ * Get cancelled purchases with valid endDate (not expired)
859
878
  *
860
- * Returns subscriptions with cancelledAt set and status === 'active' that have a future endDate.
861
- * Backend keeps cancelled subscriptions as 'active' until expiration.
879
+ * Returns purchases with cancelledAt set and status === 'active' that have a future endDate.
880
+ * Backend keeps cancelled purchases as 'active' until expiration.
862
881
  */
863
- declare function getCancelledSubscriptionsWithEndDate(subscriptions: SubscriptionInfo[]): SubscriptionInfo[];
882
+ declare function getCancelledPurchasesWithEndDate(purchases: PurchaseInfo[]): PurchaseInfo[];
864
883
  /**
865
- * Get the most recent subscription by startDate
884
+ * Get the most recent purchase by startDate
866
885
  */
867
- declare function getMostRecentSubscription(subscriptions: SubscriptionInfo[]): SubscriptionInfo | null;
886
+ declare function getMostRecentPurchase(purchases: PurchaseInfo[]): PurchaseInfo | null;
868
887
  /**
869
- * Get the primary subscription to display
888
+ * Get the primary purchase to display
870
889
  *
871
890
  * Prioritization:
872
- * 1. Active subscriptions (most recent by startDate)
873
- * 2. null if no valid subscriptions
891
+ * 1. Active purchases (most recent by startDate)
892
+ * 2. null if no valid purchases
874
893
  *
875
- * Note: Backend keeps subscriptions as 'active' until expiration, so we only
876
- * need to check for active subscriptions. Cancelled subscriptions are still
894
+ * Note: Backend keeps purchases as 'active' until expiration, so we only
895
+ * need to check for active purchases. Cancelled purchases are still
877
896
  * active until their endDate.
878
897
  */
879
- declare function getPrimarySubscription(subscriptions: SubscriptionInfo[]): SubscriptionInfo | null;
898
+ declare function getPrimaryPurchase(purchases: PurchaseInfo[]): PurchaseInfo | null;
880
899
  /**
881
- * Check if a subscription is paid
882
- * Uses subscription amount field: amount > 0 = paid, amount === 0 or undefined = free
900
+ * Check if a purchase is paid
901
+ * Uses purchase amount field: amount > 0 = paid, amount === 0 or undefined = free
883
902
  *
884
- * @param sub - Subscription to check
885
- * @returns true if subscription is paid (amount > 0)
903
+ * @param purchase - Purchase to check
904
+ * @returns true if purchase is paid (amount > 0)
886
905
  */
887
- declare function isPaidSubscription(sub: SubscriptionInfo): boolean;
906
+ declare function isPaidPurchase(purchase: PurchaseInfo): boolean;
888
907
 
889
- export { AuthAdapter, type CustomerInfo, type CustomerSubscriptionData, type PaymentError, PaymentForm, type PaymentFormProps, type PaymentIntentResult, type Plan, PlanBadge, type PlanBadgeProps, PlanSelector, type PlanSelectorProps, type SolvaPayConfig, type SolvaPayContextValue, SolvaPayProvider, type SolvaPayProviderProps, Spinner, StripePaymentFormWrapper, SubscriptionGate, type SubscriptionGateProps, type SubscriptionInfo, type SubscriptionStatus, type SubscriptionStatusReturn, type UsePlansOptions, type UsePlansReturn, filterSubscriptions, getActiveSubscriptions, getCancelledSubscriptionsWithEndDate, getMostRecentSubscription, getPrimarySubscription, isPaidSubscription, useCheckout, useCustomer, usePlans, useSolvaPay, useSubscription, useSubscriptionStatus };
908
+ export { AuthAdapter, type CustomerInfo, type CustomerPurchaseData, type PaymentError, PaymentForm, type PaymentFormProps, type PaymentIntentResult, type Plan, PlanBadge, type PlanBadgeProps, PlanSelector, type PlanSelectorProps, PurchaseGate, type PurchaseGateProps, type PurchaseInfo, type PurchaseStatus, type PurchaseStatusReturn, type PurchaseStatusValue, type SolvaPayConfig, type SolvaPayContextValue, SolvaPayProvider, type SolvaPayProviderProps, Spinner, StripePaymentFormWrapper, type UsePlansOptions, type UsePlansReturn, filterPurchases, getActivePurchases, getCancelledPurchasesWithEndDate, getMostRecentPurchase, getPrimaryPurchase, isPaidPurchase, useCheckout, useCustomer, usePlans, usePurchase, usePurchaseStatus, useSolvaPay };