Overview
By default, Superwall handles purchases through the platform’s native payment systems. However, you may need to integrate with a custom payment provider or subscription management service. TheCustomPurchaseControllerProvider allows you to implement your own purchase and restore logic while still leveraging Superwall’s paywall presentation and analytics.
When to Use Custom Purchase Handling
Use custom purchase handling when you need to:- Integrate with RevenueCat, Qonversion, or other subscription platforms
- Implement custom payment flows or validation
- Add server-side purchase verification
- Support alternative payment methods
- Track purchases in your own analytics system
- Handle complex subscription logic
Setup
Install your payment provider
First, install your payment provider SDK. For this example, we’ll use RevenueCat:
Wrap your app
Add the
CustomPurchaseControllerProvider to your component tree, inside SuperwallProvider:Purchase Controller Interface
Your controller must implement two methods:onPurchase
Called when a user initiates a purchase from a paywall.Promise<PurchaseResult | void>
- Success
- Cancelled
- Pending
- Failed
onPurchaseRestore
Called when a user initiates a restore purchases action. Returns:Promise<RestoreResult | void>
- Success
- Failed
Complete Examples
RevenueCat Integration
Server-Side Verification
Error Handling
Always handle errors gracefully and return informative error messages:Best Practices
Log Everything
Add comprehensive logging to debug purchase flows in production
Sync Status
Always sync subscription status after successful purchases
Handle Errors
Provide clear error messages for better user experience
Test Thoroughly
Test all purchase flows including success, failure, and cancellation
Test in sandbox mode
Test in sandbox mode
Always test purchases in sandbox/test mode before going to production:
Monitor purchase failures
Monitor purchase failures
Track purchase failures to identify issues:
Handle network issues
Handle network issues
Implement retry logic for network-related failures:
Related
CustomPurchaseControllerProvider
API reference for the purchase controller component
Handling Subscriptions
Learn about subscription status management
PurchaseController (Compat)
Compat SDK purchase controller interface
useUser
User and subscription management hook