What You’ll Build
Prerequisites
Before starting:- API Key: Get your API key from Settings → API Keys
- Webhook Endpoint: Have a URL ready to receive webhooks
- Checkout Flow: Create a checkout flow in Settings → Hosted Pages → Checkout Flows
Step 1: Create Customer Account
When a user signs up in your application, create a corresponding account in Alguna. Endpoint:POST /accounts
Step 2: Grant Trial Credits
Give new users trial credits to try your product before subscribing. Endpoint:POST /accounts/{id}/credits/grants
Check Credit Balance
Endpoint:GET /accounts/{accountId}/credits/balance?type=units
Optional: Check Credit Availability
Before performing an action, verify the user has sufficient credits. Endpoint:GET /accounts/{accountId}/credits/availability?type=units&required=10
Step 3: Handle Credit Depletion
When trial credits run out, Alguna sends a webhook so you can prompt the user to upgrade.Configure Webhook
- Navigate to Settings → Webhooks
- Add your endpoint URL
- Subscribe to
account.credits.balance_depleted
Webhook Payload
Step 4: Redirect to Hosted Checkout
When users are ready to subscribe, redirect them to Alguna’s hosted checkout.Option A: Simple Redirect (No Code)
Redirect users directly to your checkout flow URL:Option B: Server-Side Session (More Control)
Create a checkout session via API for more flexibility. Endpoint:POST /customer-session/checkout
url.
Step 5: Handle Checkout Completion
When a user completes checkout, Alguna sends a webhook confirming the subscription.Webhook Payload
- Update the user’s status in your application
- Grant access to paid features
- Optionally send a welcome email
Step 6: Send Usage Events
Track usage by sending events to Alguna. Events are processed within 15 minutes. Endpoint:POST /events
Usage Aggregation
Alguna can aggregate your events in different ways:
Configure aggregation in Billable Metrics in the dashboard.
Step 7: Add Customer Portal
Let users manage their subscription, view invoices, and update payment methods. Endpoint:POST /portal/customer-session/customer-portal
sessionUrl when they click “Manage Billing” in your app.
Portal Configuration
Complete Integration Flow
Key Webhooks
Subscribe to these webhooks in Settings → Webhooks:What You Don’t Need to Store
Alguna handles these for you:- Subscription IDs and status
- Product and plan details
- Usage calculations and overages
- Invoice generation and payment processing
Testing
- Use your Sandbox environment for testing
- Create test accounts and grant credits
- Deplete credits by sending test events
- Complete a test checkout
- Verify webhooks are received
Next Steps
Billable Metrics
Define how usage is measured and billed.
Customer Portal
Full portal configuration options.
Webhooks
Complete webhook reference.
API Reference
Full API documentation.