Payment Implementation
Learn how to implement subscription payments in your a0 app using thea0-purchases library.
The a0 payment system uses the
a0-purchases
library. All apps built with a0 come with the necessary configuration and providers built in.Prerequisites
Before implementing payments in your code, ensure you have:1
Completed Payment Setup
Defined your features and plans (either in the dashboard UI or by editing
.a0/monetization.yaml via the Monetization tab), and created at least one offering. See the Payment Setup guide.2
Synced to Providers
Synced your plans to Stripe and/or Apple App Store Connect.
3
Created Offerings
Created at least one offering and set it as current - this is required for paywalls to display products.
If you’re using the a0 coding agent: it can edit
.a0/monetization.yaml directly (same as build.yaml and general.yaml), then sync to Apple/Stripe. It should not tell you to do it yourself.Understanding Offerings Structure
Before building your paywall, it’s important to understand how offerings are structured:offerings.allis an object with offering IDs as keys (not an array) -offerings.currentcontains the offering marked as current in your a0 dashboard - If no offering is set as current,offerings.currentwill benull- Useofferings.currentwhen possible, or access specific offerings via their ID fromofferings.all
Building a Paywall
Here’s a simple paywall component using theuseA0Purchases hook:
Checking Premium Status
The simplest way to gate content is using theisPremium property:
Checking Specific Entitlements
isPremium returns true if the user has ANY active entitlement. If you have multiple
features/entitlements and need to check specific ones, use getCustomerInfo().Advanced Implementation
Custom Paywall with Package Details
Handling Purchase States
Testing Purchases
Test Credentials
Stripe Test Cards:- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - More test cards in Stripe docs
- Use App Store Connect sandbox tester accounts
- Subscriptions auto-renew every few minutes for testing
- Clear purchase history in Settings → App Store → Sandbox Account
Testing Flow
1
Enable Test Mode
For Stripe, ensure you synced to the sandbox environment in your payment setup.
2
Test Purchase Flow
Make test purchases using the test credentials above.
3
Verify Entitlements
Check that
isPremium updates correctly and specific entitlements are active.4
Test Restore
Clear app data and test the restore purchases functionality.
Troubleshooting
offerings.all[0] returns undefined
offerings.all[0] returns undefined
Cause:
offerings.all is an object (with offering IDs as keys), not an arraySolution:
Use one of these patterns instead:Paywall shows 'No products available'
Paywall shows 'No products available'
Cause: No offerings created or no current offering setSolution:
- Go to a0 dashboard → Payments → Offerings
- Create an offering with your subscription plans
- Set it as the current offering
Purchase fails immediately
Purchase fails immediately
Common causes:
- Not synced to payment provider
- Testing with production credentials
- Invalid product identifiers
isPremium not updating after purchase
isPremium not updating after purchase
Entitlements showing as undefined
Entitlements showing as undefined
Cause: Features not properly configured in a0 dashboardSolution:
- Verify feature names match exactly (case-sensitive)
- Ensure plans include the features you’re checking
- Sync plans to payment providers after changes