Overview
The@budgetbee/billing package provides integration with Polar for subscription management, payment processing, and billing operations.
Installation
package.json:
Package Information
Exports
Polar Client
The package exports a pre-configured Polar SDK client:Configuration
The Polar client is initialized with your access token from environment variables:Subscription Tiers
BudgetBee offers two subscription tiers:Pro
Individual users with advanced features
Teams
Organizations with collaboration features
Environment Variables
Configure your product IDs in.env:
Tier Checking Functions
The package provides helper functions to check subscription tiers:isPro()
Check if a price ID is for the Pro tier:isTeams()
Check if a price ID is for the Teams tier:isProOrTeams()
Check if a price ID is for either Pro or Teams:isProOrHigher()
Check if a price ID is Pro tier or higher:isTeamsOrHigher()
Check if a price ID is Teams tier or higher:Usage Examples
Feature Gating
Conditional UI Rendering
Subscription Status Check
Integration with Better Auth
BudgetBee uses Polar’s Better Auth plugin for seamless integration:Available Better Auth Plugins
The core package uses these Polar Better Auth plugins:API Operations
List Products
Get Subscription
List Customer Subscriptions
Create Checkout Session
Webhook Handling
Handle Polar webhooks to sync subscription status:Dependencies
The package depends on:Environment Variables
Required environment variables:Best Practices
Always check nulls
Subscription price IDs can be
null or undefined - all helper functions handle this safelyUse tier helpers
Use
isProOrHigher() instead of checking individual tiers for better maintainabilityCache subscription data
Cache subscription status to avoid repeated API calls
Handle webhooks
Always implement webhook handlers to keep subscription status in sync
Common Patterns
Middleware for Route Protection
Server Actions
Troubleshooting
Subscription not detected
Check that:POLAR_ACCESS_TOKENis set correctly- Product IDs match your Polar dashboard
- User’s subscription is active in Polar
Webhook not receiving events
Verify:- Webhook URL is publicly accessible
POLAR_WEBHOOK_SECRETmatches Polar dashboard- Webhook is enabled in Polar settings
Price ID comparison failing
Ensure you’re using the helper functions which handle:- Both monthly and yearly variants
- Null and undefined values
- Case sensitivity
Next Steps
Core Package
Learn about auth integration with Polar
Project Structure
Understand how billing fits in the monorepo

