@solvapay/react 1.0.0-preview.17 → 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 +21 -0
- package/README.md +79 -69
- package/dist/index.cjs +391 -333
- package/dist/index.d.cts +236 -50
- package/dist/index.d.ts +236 -50
- package/dist/index.js +391 -333
- package/package.json +10 -8
package/dist/index.d.cts
CHANGED
|
@@ -200,7 +200,7 @@ interface Plan {
|
|
|
200
200
|
interval?: string;
|
|
201
201
|
features?: string[];
|
|
202
202
|
isFreeTier?: boolean;
|
|
203
|
-
metadata?: Record<string,
|
|
203
|
+
metadata?: Record<string, unknown>;
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
206
206
|
* Options for usePlans hook
|
|
@@ -342,66 +342,137 @@ interface PaymentFormProps {
|
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
/**
|
|
345
|
-
* SolvaPay Provider - Headless Context Provider
|
|
345
|
+
* SolvaPay Provider - Headless Context Provider for React.
|
|
346
346
|
*
|
|
347
|
-
* Provides subscription state
|
|
348
|
-
*
|
|
347
|
+
* Provides subscription state, payment methods, and customer data to child components
|
|
348
|
+
* via React Context. This is the root component that must wrap your app to use
|
|
349
|
+
* SolvaPay React hooks and components.
|
|
350
|
+
*
|
|
351
|
+
* Features:
|
|
352
|
+
* - Automatic subscription status checking
|
|
353
|
+
* - Customer reference caching in localStorage
|
|
354
|
+
* - Payment intent creation and processing
|
|
355
|
+
* - Authentication adapter support (Supabase, custom, etc.)
|
|
356
|
+
* - Zero-config with sensible defaults, or full customization
|
|
357
|
+
*
|
|
358
|
+
* @param props - Provider configuration
|
|
359
|
+
* @param props.config - Configuration object for API routes and authentication
|
|
360
|
+
* @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')
|
|
362
|
+
* @param props.config.api.createPayment - Endpoint for creating payment intents (default: '/api/create-payment-intent')
|
|
363
|
+
* @param props.config.api.processPayment - Endpoint for processing payments (default: '/api/process-payment')
|
|
364
|
+
* @param props.config.auth - Authentication configuration (optional)
|
|
365
|
+
* @param props.config.auth.adapter - Auth adapter for extracting user ID and token
|
|
366
|
+
* @param props.children - React children components
|
|
349
367
|
*
|
|
350
368
|
* @example
|
|
351
369
|
* ```tsx
|
|
370
|
+
* import { SolvaPayProvider } from '@solvapay/react';
|
|
371
|
+
*
|
|
352
372
|
* // Zero config (uses defaults)
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
373
|
+
* function App() {
|
|
374
|
+
* return (
|
|
375
|
+
* <SolvaPayProvider>
|
|
376
|
+
* <YourApp />
|
|
377
|
+
* </SolvaPayProvider>
|
|
378
|
+
* );
|
|
379
|
+
* }
|
|
356
380
|
*
|
|
357
381
|
* // Custom API routes
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
382
|
+
* function App() {
|
|
383
|
+
* return (
|
|
384
|
+
* <SolvaPayProvider
|
|
385
|
+
* config={{
|
|
386
|
+
* api: {
|
|
387
|
+
* checkSubscription: '/custom/api/subscription',
|
|
388
|
+
* createPayment: '/custom/api/payment'
|
|
389
|
+
* }
|
|
390
|
+
* }}
|
|
391
|
+
* >
|
|
392
|
+
* <YourApp />
|
|
393
|
+
* </SolvaPayProvider>
|
|
394
|
+
* );
|
|
395
|
+
* }
|
|
368
396
|
*
|
|
369
|
-
* //
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
* }
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
397
|
+
* // With Supabase auth adapter
|
|
398
|
+
* import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
|
|
399
|
+
*
|
|
400
|
+
* function App() {
|
|
401
|
+
* const adapter = createSupabaseAuthAdapter({
|
|
402
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
403
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
404
|
+
* });
|
|
405
|
+
*
|
|
406
|
+
* return (
|
|
407
|
+
* <SolvaPayProvider
|
|
408
|
+
* config={{
|
|
409
|
+
* auth: { adapter }
|
|
410
|
+
* }}
|
|
411
|
+
* >
|
|
412
|
+
* <YourApp />
|
|
413
|
+
* </SolvaPayProvider>
|
|
414
|
+
* );
|
|
415
|
+
* }
|
|
380
416
|
* ```
|
|
417
|
+
*
|
|
418
|
+
* @see {@link useSubscription} for accessing subscription data
|
|
419
|
+
* @see {@link useCheckout} for payment checkout flow
|
|
420
|
+
* @see {@link useSolvaPay} for accessing provider methods
|
|
421
|
+
* @since 1.0.0
|
|
381
422
|
*/
|
|
382
423
|
declare const SolvaPayProvider: React$1.FC<SolvaPayProviderProps>;
|
|
383
424
|
|
|
384
425
|
/**
|
|
385
|
-
*
|
|
426
|
+
* Payment form component for handling Stripe checkout.
|
|
386
427
|
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
428
|
+
* This component provides a complete payment form with Stripe integration,
|
|
429
|
+
* including card input, plan selection, and payment processing. It handles
|
|
430
|
+
* the entire checkout flow including payment intent creation and confirmation.
|
|
431
|
+
*
|
|
432
|
+
* Features:
|
|
433
|
+
* - Automatic Stripe Elements initialization
|
|
434
|
+
* - Payment intent creation on mount
|
|
435
|
+
* - Card input and validation
|
|
436
|
+
* - Payment processing with error handling
|
|
437
|
+
* - Automatic subscription refresh after payment
|
|
438
|
+
*
|
|
439
|
+
* @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)
|
|
442
|
+
* @param props.onSuccess - Callback when payment succeeds
|
|
443
|
+
* @param props.onError - Callback when payment fails
|
|
444
|
+
* @param props.returnUrl - Optional return URL after payment (for redirects)
|
|
445
|
+
* @param props.submitButtonText - Custom text for submit button (default: 'Pay Now')
|
|
446
|
+
* @param props.className - Custom CSS class for the form container
|
|
447
|
+
* @param props.buttonClassName - Custom CSS class for the submit button
|
|
389
448
|
*
|
|
390
449
|
* @example
|
|
391
450
|
* ```tsx
|
|
392
451
|
* import { PaymentForm } from '@solvapay/react';
|
|
452
|
+
* import { useRouter } from 'next/navigation';
|
|
393
453
|
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
454
|
+
* function CheckoutPage() {
|
|
455
|
+
* const router = useRouter();
|
|
456
|
+
*
|
|
457
|
+
* return (
|
|
458
|
+
* <PaymentForm
|
|
459
|
+
* planRef="pln_premium"
|
|
460
|
+
* agentRef="agt_myapi"
|
|
461
|
+
* onSuccess={() => {
|
|
462
|
+
* console.log('Payment successful!');
|
|
463
|
+
* router.push('/dashboard');
|
|
464
|
+
* }}
|
|
465
|
+
* onError={(error) => {
|
|
466
|
+
* console.error('Payment failed:', error);
|
|
467
|
+
* }}
|
|
468
|
+
* />
|
|
469
|
+
* );
|
|
470
|
+
* }
|
|
404
471
|
* ```
|
|
472
|
+
*
|
|
473
|
+
* @see {@link useCheckout} for programmatic checkout handling
|
|
474
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
475
|
+
* @since 1.0.0
|
|
405
476
|
*/
|
|
406
477
|
declare const PaymentForm: React$1.FC<PaymentFormProps>;
|
|
407
478
|
|
|
@@ -510,7 +581,7 @@ declare const Spinner: React$1.FC<{
|
|
|
510
581
|
}>;
|
|
511
582
|
|
|
512
583
|
interface StripePaymentFormWrapperProps {
|
|
513
|
-
onSuccess?: (paymentIntent:
|
|
584
|
+
onSuccess?: (paymentIntent: unknown) => void | Promise<void>;
|
|
514
585
|
onError?: (error: Error) => void;
|
|
515
586
|
returnUrl?: string;
|
|
516
587
|
submitButtonText?: string;
|
|
@@ -525,8 +596,45 @@ interface StripePaymentFormWrapperProps {
|
|
|
525
596
|
declare const StripePaymentFormWrapper: React$1.FC<StripePaymentFormWrapperProps>;
|
|
526
597
|
|
|
527
598
|
/**
|
|
528
|
-
* Hook to
|
|
529
|
-
*
|
|
599
|
+
* Hook to get current subscription status and information.
|
|
600
|
+
*
|
|
601
|
+
* Returns the current user's subscription status, including active
|
|
602
|
+
* subscriptions, plan details, and payment information. Automatically
|
|
603
|
+
* syncs with the SolvaPay backend and handles loading and error states.
|
|
604
|
+
*
|
|
605
|
+
* @returns Subscription data and status
|
|
606
|
+
* @returns subscriptions - Array of active subscriptions
|
|
607
|
+
* @returns hasPaidSubscription - Whether user has any paid subscription
|
|
608
|
+
* @returns isLoading - Loading state
|
|
609
|
+
* @returns error - Error state if subscription check fails
|
|
610
|
+
* @returns refetch - Function to manually refetch subscription data
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* ```tsx
|
|
614
|
+
* import { useSubscription } from '@solvapay/react';
|
|
615
|
+
*
|
|
616
|
+
* function Dashboard() {
|
|
617
|
+
* const { subscriptions, hasPaidSubscription, isLoading, refetch } = useSubscription();
|
|
618
|
+
*
|
|
619
|
+
* if (isLoading) return <Spinner />;
|
|
620
|
+
*
|
|
621
|
+
* if (!hasPaidSubscription) {
|
|
622
|
+
* return <UpgradePrompt />;
|
|
623
|
+
* }
|
|
624
|
+
*
|
|
625
|
+
* return (
|
|
626
|
+
* <div>
|
|
627
|
+
* <h2>Welcome, Premium User!</h2>
|
|
628
|
+
* <p>Active subscriptions: {subscriptions.length}</p>
|
|
629
|
+
* <button onClick={() => refetch()}>Refresh</button>
|
|
630
|
+
* </div>
|
|
631
|
+
* );
|
|
632
|
+
* }
|
|
633
|
+
* ```
|
|
634
|
+
*
|
|
635
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
636
|
+
* @see {@link useSubscriptionStatus} for detailed status information
|
|
637
|
+
* @since 1.0.0
|
|
530
638
|
*/
|
|
531
639
|
declare function useSubscription(): SubscriptionStatus & {
|
|
532
640
|
refetch: () => Promise<void>;
|
|
@@ -584,17 +692,95 @@ interface UseCheckoutReturn {
|
|
|
584
692
|
reset: () => void;
|
|
585
693
|
}
|
|
586
694
|
/**
|
|
587
|
-
* Hook to manage checkout flow
|
|
588
|
-
*
|
|
695
|
+
* Hook to manage checkout flow for payment processing.
|
|
696
|
+
*
|
|
697
|
+
* Handles payment intent creation and Stripe initialization. This hook
|
|
698
|
+
* manages the checkout state including loading, errors, Stripe instance,
|
|
699
|
+
* and client secret. Use this for programmatic checkout flows.
|
|
700
|
+
*
|
|
701
|
+
* @param planRef - Plan reference to subscribe to (required)
|
|
702
|
+
* @param agentRef - Optional agent reference for usage tracking
|
|
703
|
+
* @returns Checkout state and methods
|
|
704
|
+
* @returns loading - Whether checkout is in progress
|
|
705
|
+
* @returns error - Error state if checkout fails
|
|
706
|
+
* @returns stripePromise - Promise resolving to Stripe instance
|
|
707
|
+
* @returns clientSecret - Stripe payment intent client secret
|
|
708
|
+
* @returns startCheckout - Function to start the checkout process
|
|
709
|
+
* @returns reset - Function to reset checkout state
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* ```tsx
|
|
713
|
+
* import { useCheckout } from '@solvapay/react';
|
|
714
|
+
* import { PaymentElement } from '@stripe/react-stripe-js';
|
|
715
|
+
*
|
|
716
|
+
* function CustomCheckout() {
|
|
717
|
+
* const { loading, error, stripePromise, clientSecret, startCheckout } = useCheckout(
|
|
718
|
+
* 'pln_premium',
|
|
719
|
+
* 'agt_myapi'
|
|
720
|
+
* );
|
|
721
|
+
*
|
|
722
|
+
* useEffect(() => {
|
|
723
|
+
* startCheckout();
|
|
724
|
+
* }, []);
|
|
725
|
+
*
|
|
726
|
+
* if (loading) return <Spinner />;
|
|
727
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
728
|
+
* if (!clientSecret || !stripePromise) return null;
|
|
589
729
|
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
730
|
+
* return (
|
|
731
|
+
* <Elements stripe={await stripePromise} options={{ clientSecret }}>
|
|
732
|
+
* <PaymentElement />
|
|
733
|
+
* </Elements>
|
|
734
|
+
* );
|
|
735
|
+
* }
|
|
736
|
+
* ```
|
|
737
|
+
*
|
|
738
|
+
* @see {@link PaymentForm} for a complete payment form component
|
|
739
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
740
|
+
* @since 1.0.0
|
|
592
741
|
*/
|
|
593
742
|
declare function useCheckout(planRef: string, agentRef?: string): UseCheckoutReturn;
|
|
594
743
|
|
|
595
744
|
/**
|
|
596
|
-
* Hook to access SolvaPay context
|
|
597
|
-
*
|
|
745
|
+
* Hook to access SolvaPay context and provider methods.
|
|
746
|
+
*
|
|
747
|
+
* 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.
|
|
750
|
+
*
|
|
751
|
+
* Must be used within a `SolvaPayProvider` component.
|
|
752
|
+
*
|
|
753
|
+
* @returns SolvaPay context value with all provider methods and state
|
|
754
|
+
* @returns subscription - Subscription status and data
|
|
755
|
+
* @returns createPayment - Function to create payment intents
|
|
756
|
+
* @returns processPayment - Function to process payments
|
|
757
|
+
* @returns customerRef - Current customer reference
|
|
758
|
+
* @returns refetchSubscription - Function to refetch subscription data
|
|
759
|
+
*
|
|
760
|
+
* @example
|
|
761
|
+
* ```tsx
|
|
762
|
+
* import { useSolvaPay } from '@solvapay/react';
|
|
763
|
+
*
|
|
764
|
+
* function CustomComponent() {
|
|
765
|
+
* const { subscription, createPayment, processPayment } = useSolvaPay();
|
|
766
|
+
*
|
|
767
|
+
* const handlePayment = async () => {
|
|
768
|
+
* const intent = await createPayment({
|
|
769
|
+
* planRef: 'pln_premium',
|
|
770
|
+
* agentRef: 'agt_myapi'
|
|
771
|
+
* });
|
|
772
|
+
* // Process payment...
|
|
773
|
+
* };
|
|
774
|
+
*
|
|
775
|
+
* return <div>Subscription status: {subscription.hasPaidSubscription ? 'Active' : 'None'}</div>;
|
|
776
|
+
* }
|
|
777
|
+
* ```
|
|
778
|
+
*
|
|
779
|
+
* @throws {Error} If used outside of SolvaPayProvider
|
|
780
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
781
|
+
* @see {@link useSubscription} for subscription-specific hook
|
|
782
|
+
* @see {@link useCheckout} for checkout-specific hook
|
|
783
|
+
* @since 1.0.0
|
|
598
784
|
*/
|
|
599
785
|
declare function useSolvaPay(): SolvaPayContextValue;
|
|
600
786
|
|
package/dist/index.d.ts
CHANGED
|
@@ -200,7 +200,7 @@ interface Plan {
|
|
|
200
200
|
interval?: string;
|
|
201
201
|
features?: string[];
|
|
202
202
|
isFreeTier?: boolean;
|
|
203
|
-
metadata?: Record<string,
|
|
203
|
+
metadata?: Record<string, unknown>;
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
206
206
|
* Options for usePlans hook
|
|
@@ -342,66 +342,137 @@ interface PaymentFormProps {
|
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
/**
|
|
345
|
-
* SolvaPay Provider - Headless Context Provider
|
|
345
|
+
* SolvaPay Provider - Headless Context Provider for React.
|
|
346
346
|
*
|
|
347
|
-
* Provides subscription state
|
|
348
|
-
*
|
|
347
|
+
* Provides subscription state, payment methods, and customer data to child components
|
|
348
|
+
* via React Context. This is the root component that must wrap your app to use
|
|
349
|
+
* SolvaPay React hooks and components.
|
|
350
|
+
*
|
|
351
|
+
* Features:
|
|
352
|
+
* - Automatic subscription status checking
|
|
353
|
+
* - Customer reference caching in localStorage
|
|
354
|
+
* - Payment intent creation and processing
|
|
355
|
+
* - Authentication adapter support (Supabase, custom, etc.)
|
|
356
|
+
* - Zero-config with sensible defaults, or full customization
|
|
357
|
+
*
|
|
358
|
+
* @param props - Provider configuration
|
|
359
|
+
* @param props.config - Configuration object for API routes and authentication
|
|
360
|
+
* @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')
|
|
362
|
+
* @param props.config.api.createPayment - Endpoint for creating payment intents (default: '/api/create-payment-intent')
|
|
363
|
+
* @param props.config.api.processPayment - Endpoint for processing payments (default: '/api/process-payment')
|
|
364
|
+
* @param props.config.auth - Authentication configuration (optional)
|
|
365
|
+
* @param props.config.auth.adapter - Auth adapter for extracting user ID and token
|
|
366
|
+
* @param props.children - React children components
|
|
349
367
|
*
|
|
350
368
|
* @example
|
|
351
369
|
* ```tsx
|
|
370
|
+
* import { SolvaPayProvider } from '@solvapay/react';
|
|
371
|
+
*
|
|
352
372
|
* // Zero config (uses defaults)
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
373
|
+
* function App() {
|
|
374
|
+
* return (
|
|
375
|
+
* <SolvaPayProvider>
|
|
376
|
+
* <YourApp />
|
|
377
|
+
* </SolvaPayProvider>
|
|
378
|
+
* );
|
|
379
|
+
* }
|
|
356
380
|
*
|
|
357
381
|
* // Custom API routes
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
382
|
+
* function App() {
|
|
383
|
+
* return (
|
|
384
|
+
* <SolvaPayProvider
|
|
385
|
+
* config={{
|
|
386
|
+
* api: {
|
|
387
|
+
* checkSubscription: '/custom/api/subscription',
|
|
388
|
+
* createPayment: '/custom/api/payment'
|
|
389
|
+
* }
|
|
390
|
+
* }}
|
|
391
|
+
* >
|
|
392
|
+
* <YourApp />
|
|
393
|
+
* </SolvaPayProvider>
|
|
394
|
+
* );
|
|
395
|
+
* }
|
|
368
396
|
*
|
|
369
|
-
* //
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
* }
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
397
|
+
* // With Supabase auth adapter
|
|
398
|
+
* import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
|
|
399
|
+
*
|
|
400
|
+
* function App() {
|
|
401
|
+
* const adapter = createSupabaseAuthAdapter({
|
|
402
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
403
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
404
|
+
* });
|
|
405
|
+
*
|
|
406
|
+
* return (
|
|
407
|
+
* <SolvaPayProvider
|
|
408
|
+
* config={{
|
|
409
|
+
* auth: { adapter }
|
|
410
|
+
* }}
|
|
411
|
+
* >
|
|
412
|
+
* <YourApp />
|
|
413
|
+
* </SolvaPayProvider>
|
|
414
|
+
* );
|
|
415
|
+
* }
|
|
380
416
|
* ```
|
|
417
|
+
*
|
|
418
|
+
* @see {@link useSubscription} for accessing subscription data
|
|
419
|
+
* @see {@link useCheckout} for payment checkout flow
|
|
420
|
+
* @see {@link useSolvaPay} for accessing provider methods
|
|
421
|
+
* @since 1.0.0
|
|
381
422
|
*/
|
|
382
423
|
declare const SolvaPayProvider: React$1.FC<SolvaPayProviderProps>;
|
|
383
424
|
|
|
384
425
|
/**
|
|
385
|
-
*
|
|
426
|
+
* Payment form component for handling Stripe checkout.
|
|
386
427
|
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
428
|
+
* This component provides a complete payment form with Stripe integration,
|
|
429
|
+
* including card input, plan selection, and payment processing. It handles
|
|
430
|
+
* the entire checkout flow including payment intent creation and confirmation.
|
|
431
|
+
*
|
|
432
|
+
* Features:
|
|
433
|
+
* - Automatic Stripe Elements initialization
|
|
434
|
+
* - Payment intent creation on mount
|
|
435
|
+
* - Card input and validation
|
|
436
|
+
* - Payment processing with error handling
|
|
437
|
+
* - Automatic subscription refresh after payment
|
|
438
|
+
*
|
|
439
|
+
* @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)
|
|
442
|
+
* @param props.onSuccess - Callback when payment succeeds
|
|
443
|
+
* @param props.onError - Callback when payment fails
|
|
444
|
+
* @param props.returnUrl - Optional return URL after payment (for redirects)
|
|
445
|
+
* @param props.submitButtonText - Custom text for submit button (default: 'Pay Now')
|
|
446
|
+
* @param props.className - Custom CSS class for the form container
|
|
447
|
+
* @param props.buttonClassName - Custom CSS class for the submit button
|
|
389
448
|
*
|
|
390
449
|
* @example
|
|
391
450
|
* ```tsx
|
|
392
451
|
* import { PaymentForm } from '@solvapay/react';
|
|
452
|
+
* import { useRouter } from 'next/navigation';
|
|
393
453
|
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
454
|
+
* function CheckoutPage() {
|
|
455
|
+
* const router = useRouter();
|
|
456
|
+
*
|
|
457
|
+
* return (
|
|
458
|
+
* <PaymentForm
|
|
459
|
+
* planRef="pln_premium"
|
|
460
|
+
* agentRef="agt_myapi"
|
|
461
|
+
* onSuccess={() => {
|
|
462
|
+
* console.log('Payment successful!');
|
|
463
|
+
* router.push('/dashboard');
|
|
464
|
+
* }}
|
|
465
|
+
* onError={(error) => {
|
|
466
|
+
* console.error('Payment failed:', error);
|
|
467
|
+
* }}
|
|
468
|
+
* />
|
|
469
|
+
* );
|
|
470
|
+
* }
|
|
404
471
|
* ```
|
|
472
|
+
*
|
|
473
|
+
* @see {@link useCheckout} for programmatic checkout handling
|
|
474
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
475
|
+
* @since 1.0.0
|
|
405
476
|
*/
|
|
406
477
|
declare const PaymentForm: React$1.FC<PaymentFormProps>;
|
|
407
478
|
|
|
@@ -510,7 +581,7 @@ declare const Spinner: React$1.FC<{
|
|
|
510
581
|
}>;
|
|
511
582
|
|
|
512
583
|
interface StripePaymentFormWrapperProps {
|
|
513
|
-
onSuccess?: (paymentIntent:
|
|
584
|
+
onSuccess?: (paymentIntent: unknown) => void | Promise<void>;
|
|
514
585
|
onError?: (error: Error) => void;
|
|
515
586
|
returnUrl?: string;
|
|
516
587
|
submitButtonText?: string;
|
|
@@ -525,8 +596,45 @@ interface StripePaymentFormWrapperProps {
|
|
|
525
596
|
declare const StripePaymentFormWrapper: React$1.FC<StripePaymentFormWrapperProps>;
|
|
526
597
|
|
|
527
598
|
/**
|
|
528
|
-
* Hook to
|
|
529
|
-
*
|
|
599
|
+
* Hook to get current subscription status and information.
|
|
600
|
+
*
|
|
601
|
+
* Returns the current user's subscription status, including active
|
|
602
|
+
* subscriptions, plan details, and payment information. Automatically
|
|
603
|
+
* syncs with the SolvaPay backend and handles loading and error states.
|
|
604
|
+
*
|
|
605
|
+
* @returns Subscription data and status
|
|
606
|
+
* @returns subscriptions - Array of active subscriptions
|
|
607
|
+
* @returns hasPaidSubscription - Whether user has any paid subscription
|
|
608
|
+
* @returns isLoading - Loading state
|
|
609
|
+
* @returns error - Error state if subscription check fails
|
|
610
|
+
* @returns refetch - Function to manually refetch subscription data
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* ```tsx
|
|
614
|
+
* import { useSubscription } from '@solvapay/react';
|
|
615
|
+
*
|
|
616
|
+
* function Dashboard() {
|
|
617
|
+
* const { subscriptions, hasPaidSubscription, isLoading, refetch } = useSubscription();
|
|
618
|
+
*
|
|
619
|
+
* if (isLoading) return <Spinner />;
|
|
620
|
+
*
|
|
621
|
+
* if (!hasPaidSubscription) {
|
|
622
|
+
* return <UpgradePrompt />;
|
|
623
|
+
* }
|
|
624
|
+
*
|
|
625
|
+
* return (
|
|
626
|
+
* <div>
|
|
627
|
+
* <h2>Welcome, Premium User!</h2>
|
|
628
|
+
* <p>Active subscriptions: {subscriptions.length}</p>
|
|
629
|
+
* <button onClick={() => refetch()}>Refresh</button>
|
|
630
|
+
* </div>
|
|
631
|
+
* );
|
|
632
|
+
* }
|
|
633
|
+
* ```
|
|
634
|
+
*
|
|
635
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
636
|
+
* @see {@link useSubscriptionStatus} for detailed status information
|
|
637
|
+
* @since 1.0.0
|
|
530
638
|
*/
|
|
531
639
|
declare function useSubscription(): SubscriptionStatus & {
|
|
532
640
|
refetch: () => Promise<void>;
|
|
@@ -584,17 +692,95 @@ interface UseCheckoutReturn {
|
|
|
584
692
|
reset: () => void;
|
|
585
693
|
}
|
|
586
694
|
/**
|
|
587
|
-
* Hook to manage checkout flow
|
|
588
|
-
*
|
|
695
|
+
* Hook to manage checkout flow for payment processing.
|
|
696
|
+
*
|
|
697
|
+
* Handles payment intent creation and Stripe initialization. This hook
|
|
698
|
+
* manages the checkout state including loading, errors, Stripe instance,
|
|
699
|
+
* and client secret. Use this for programmatic checkout flows.
|
|
700
|
+
*
|
|
701
|
+
* @param planRef - Plan reference to subscribe to (required)
|
|
702
|
+
* @param agentRef - Optional agent reference for usage tracking
|
|
703
|
+
* @returns Checkout state and methods
|
|
704
|
+
* @returns loading - Whether checkout is in progress
|
|
705
|
+
* @returns error - Error state if checkout fails
|
|
706
|
+
* @returns stripePromise - Promise resolving to Stripe instance
|
|
707
|
+
* @returns clientSecret - Stripe payment intent client secret
|
|
708
|
+
* @returns startCheckout - Function to start the checkout process
|
|
709
|
+
* @returns reset - Function to reset checkout state
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* ```tsx
|
|
713
|
+
* import { useCheckout } from '@solvapay/react';
|
|
714
|
+
* import { PaymentElement } from '@stripe/react-stripe-js';
|
|
715
|
+
*
|
|
716
|
+
* function CustomCheckout() {
|
|
717
|
+
* const { loading, error, stripePromise, clientSecret, startCheckout } = useCheckout(
|
|
718
|
+
* 'pln_premium',
|
|
719
|
+
* 'agt_myapi'
|
|
720
|
+
* );
|
|
721
|
+
*
|
|
722
|
+
* useEffect(() => {
|
|
723
|
+
* startCheckout();
|
|
724
|
+
* }, []);
|
|
725
|
+
*
|
|
726
|
+
* if (loading) return <Spinner />;
|
|
727
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
728
|
+
* if (!clientSecret || !stripePromise) return null;
|
|
589
729
|
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
730
|
+
* return (
|
|
731
|
+
* <Elements stripe={await stripePromise} options={{ clientSecret }}>
|
|
732
|
+
* <PaymentElement />
|
|
733
|
+
* </Elements>
|
|
734
|
+
* );
|
|
735
|
+
* }
|
|
736
|
+
* ```
|
|
737
|
+
*
|
|
738
|
+
* @see {@link PaymentForm} for a complete payment form component
|
|
739
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
740
|
+
* @since 1.0.0
|
|
592
741
|
*/
|
|
593
742
|
declare function useCheckout(planRef: string, agentRef?: string): UseCheckoutReturn;
|
|
594
743
|
|
|
595
744
|
/**
|
|
596
|
-
* Hook to access SolvaPay context
|
|
597
|
-
*
|
|
745
|
+
* Hook to access SolvaPay context and provider methods.
|
|
746
|
+
*
|
|
747
|
+
* 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.
|
|
750
|
+
*
|
|
751
|
+
* Must be used within a `SolvaPayProvider` component.
|
|
752
|
+
*
|
|
753
|
+
* @returns SolvaPay context value with all provider methods and state
|
|
754
|
+
* @returns subscription - Subscription status and data
|
|
755
|
+
* @returns createPayment - Function to create payment intents
|
|
756
|
+
* @returns processPayment - Function to process payments
|
|
757
|
+
* @returns customerRef - Current customer reference
|
|
758
|
+
* @returns refetchSubscription - Function to refetch subscription data
|
|
759
|
+
*
|
|
760
|
+
* @example
|
|
761
|
+
* ```tsx
|
|
762
|
+
* import { useSolvaPay } from '@solvapay/react';
|
|
763
|
+
*
|
|
764
|
+
* function CustomComponent() {
|
|
765
|
+
* const { subscription, createPayment, processPayment } = useSolvaPay();
|
|
766
|
+
*
|
|
767
|
+
* const handlePayment = async () => {
|
|
768
|
+
* const intent = await createPayment({
|
|
769
|
+
* planRef: 'pln_premium',
|
|
770
|
+
* agentRef: 'agt_myapi'
|
|
771
|
+
* });
|
|
772
|
+
* // Process payment...
|
|
773
|
+
* };
|
|
774
|
+
*
|
|
775
|
+
* return <div>Subscription status: {subscription.hasPaidSubscription ? 'Active' : 'None'}</div>;
|
|
776
|
+
* }
|
|
777
|
+
* ```
|
|
778
|
+
*
|
|
779
|
+
* @throws {Error} If used outside of SolvaPayProvider
|
|
780
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
781
|
+
* @see {@link useSubscription} for subscription-specific hook
|
|
782
|
+
* @see {@link useCheckout} for checkout-specific hook
|
|
783
|
+
* @since 1.0.0
|
|
598
784
|
*/
|
|
599
785
|
declare function useSolvaPay(): SolvaPayContextValue;
|
|
600
786
|
|