Table of Contents
- Installation
- Basic Setup
- Provider Configuration
- Components
- Hooks
- Payment Flow
- Purchase Management
- Complete Example
Installation
Install the required packages:Peer Dependencies
SolvaPay React requires:react^18.2.0 || ^19.0.0react-dom^18.2.0 || ^19.0.0@stripe/react-stripe-js(for payment forms)@stripe/stripe-js(for Stripe integration)
Basic Setup
1. Wrap Your App with Provider
TheSolvaPayProvider is required to use SolvaPay hooks and components:
2. Zero-Config Usage
By default,SolvaPayProvider uses these API endpoints:
/api/check-purchase- Check purchase status/api/create-payment-intent- Create payment intents/api/process-payment- Process payments
Provider Configuration
Custom API Routes
If your backend uses different API routes, configure them:With Supabase Authentication
Use the Supabase auth adapter for automatic user ID extraction:Custom Authentication Adapter
Create a custom auth adapter for other authentication systems:Components
PaymentForm
A complete payment form component with Stripe integration:PaymentForm Props
planRef(required) - Plan reference to subscribe toproductRef(optional) - Product reference for usage trackingonSuccess- Callback when payment succeedsonError- Callback when payment failsreturnUrl- Optional return URL after paymentsubmitButtonText- Custom submit button text (default: “Pay Now”)className- Custom CSS class for form containerbuttonClassName- Custom CSS class for submit button
PricingSelector
Select a pricing option from available options using the render-prop API:PurchaseGate
Conditionally render content based on purchase status using the render-prop pattern:ProductBadge
Display product subscription information using the render-prop pattern:Hooks
usePurchase
Check purchase status and access purchase data:usePurchase Return Values
loading- Boolean indicating if purchase check is in progresspurchases- Array of purchase objectsactivePurchase- The active purchase (or null)hasPaidPurchase- Boolean indicating if user has paid purchaseactivePaidPurchase- The active paid purchase (or null)hasProduct(productName)- Function to check if user has a specific productrefetch- Function to manually refetch purchase status
useCheckout
Programmatic checkout flow:useCustomer
Access customer information:usePlans
Fetch available plans:useSolvaPay
Access all SolvaPay functionality:Payment Flow
Simple Payment Flow
UsePaymentForm for a complete payment flow:
Custom Payment Flow
Build a custom payment flow with hooks:Purchase Management
Check Purchase Status
Display Purchase Details
Refresh Purchase Status
Complete Example
Here’s a complete React application with SolvaPay integration:Styling
SolvaPay components are headless and don’t include default styles. Style them to match your design system:Best Practices
-
Provider Placement: Place
SolvaPayProviderat the root of your app, above all routes. - Error Handling: Always handle errors from hooks and components.
- Loading States: Show loading states while purchase checks are in progress.
-
Refetch After Payment: Call
refetch()after successful payment to update purchase status. - Type Safety: Use TypeScript for better type safety and autocomplete.
- Custom Styling: Style components to match your design system.
Next Steps
- Next.js Integration Guide - Learn Next.js-specific integration
- Custom Authentication Adapters - Build custom auth adapters
- Usage Events - Track purchase and usage activity
- API Reference - Full API documentation