Payment Basics
ShipFlutter provides a flexible payment system that adapts to different platforms:
- Mobile: RevenueCat for App Store and Google Play
- Web: LemonSqueezy for web payments
Structure
The payment system is organized into client and server components:
Directoryapp/
Directorylib/core/account/payments/
Directorymobile/ // RevenueCat implementation
- …
Directoryweb/ // LemonSqueezy implementation
- …
Directorymodels/ // Shared payment models
- …
Directoryui/ // Payment UI components
- …
- payments_service.dart // Platform-agnostic interface
Directoryweb/payment/
- lemon_squeezy.js // LemonSqueezy SDK interop
Directoryfunctions/src/payment/
- revenue_cat.ts // Mobile webhooks
- lemon_squeezy.ts // Web webhooks
- payments_schema.ts // Shared types
Basic Usage
// Get paywall with available packagesfinal paywall = await paymentsService.instance.getPaywall();
// Access packagesfinal packages = paywall.packages;
try { // Purchase a package final entitlements = await paymentsService.instance.purchase( package, );
// Handle success if (entitlements.isNotEmpty) { // User has access }} on PaymentException catch (e) { // Handle payment errors}
// Check current accessfinal hasAccess = await paymentsService.instance.hasEntitlement();
// Listen to changespaymentsService.instance .observeActiveEntitlements() .listen((entitlements) { // Handle entitlement changes });
Payment Models
The system uses these core models:
// Package represents a purchasable itemclass PaymentPackage { final String id; final String productId; final String title; final String description; final String price; final String currency; final int? subscriptionDuration; final int? trialDuration;}
// Paywall groups packages with presentationclass PaymentPaywall { final String id; final String title; final List<PaymentPackage> packages;}
Paywall and Trial UI
ShipFlutter includes responsive and ready-to-use payment UI components that are compliant with Apple App Store and Google Play store. The UI automatically adapts to the platform (mobile/web) and handles all payment flows.
// Show paywallcontext.go('/paywall');// Show trialcontext.go('/trial');
// Or use the widget directlyPaywallView( onClose: (isSuccessful) { // Handle result },);
Webhooks Integration
The payment system uses Firebase Functions to handle webhooks from both providers:
-
RevenueCat -
/api/v1/payment/event/rc
- Handles subscription events
- Updates entitlements
- Manages trial periods
-
LemonSqueezy -
/api/v1/payment/event/ls
- Processes web payments
- Manages subscription lifecycle
- Syncs product data
Next Steps
-
Set up payment providers:
- RevenueCat Setup for mobile
- LemonSqueezy Setup for web
-
Configure Entitlements to manage user access
-
Customize the payment UI to match your app’s design