What You’ll Build
Prerequisites
Before starting:- API key — from Settings → Connections → Developers → API keys. See the Developer quick start for base URLs, headers and the SDK.
- Webhook endpoint — a URL ready to receive webhooks; see the Webhooks quick start.
- A plan to sell — a plan with the prices you want at checkout; see Plans. Create one in the dashboard or with Create a plan.
Step 1: Create the Customer
When a user signs up in your application, create a corresponding customer in Alguna. Endpoint:POST /customers
name and currency are required. Put your own identifier in aliases so you can address the customer by it later. Reference: Create a customer.
Response:
Step 2: Grant Trial Credits
Give new users credits to try your product before subscribing. Credits are granted against a subscription, so create the subscription first — a free or trial plan is enough. Endpoint:POST /subscriptions/{id}/credits/grant
amount and reason are required. Set credit_type to units for a usage allowance, or monetary for a currency balance. Add expires_at if the grant should lapse. Reference: Grant credits to a subscription; concepts in Credit grants.
Check the Balance
Endpoint:GET /subscriptions/{id}/credits/balance
Gate Work Before You Do It
To check whether a customer can afford an action, and hold the credit while the work runs, use the realtime gate: Endpoint:POST /credits/check
allowed, the priced charges per metric, and a reservation_id for the hold. When the work finishes, settle it with POST /credits/track, passing the reservation_id and close: true. See Credit Consumption.
Step 3: Handle Credit Depletion
When trial credits run out, Alguna sends a webhook so you can prompt the user to upgrade.Configure Webhook
- Go to Settings → Connections → Developers → Webhooks
- Add your endpoint URL and copy the signing secret
- Subscribe to
account.credits.balance_depleted
Webhook Payload
Step 4: Send Users to Checkout
When a user is ready to subscribe, create a checkout session and redirect them to it. Endpoint:POST /checkout-sessions
url. For a guest checkout, omit customer_id and pass a customer object instead; the customer is created when checkout completes. The response also carries status (created here; successful once paid) and a session_token.
To render checkout inside your own page rather than redirecting, see Embedded Checkout. Reference: Create a checkout session.
Step 5: Handle Checkout Completion
When a user completes checkout, Alguna sends a webhook confirming the subscription.Webhook Payload
clientReferenceId to find the record on your side.
When you receive this:
- 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. Endpoint:POST /events
Send up to 100 events per request. The response lists which were
ingested and which failed. Full details, including cURL, Python and SDK examples: Send usage events.
Usage Aggregation
Alguna can aggregate your events in different ways:
Define metrics in Billable Metrics in the dashboard or with
POST /metrics — see Create metrics.
Step 7: Add the Customer Portal
Let users manage their subscription, view invoices and update payment methods. Endpoint:POST /customer-portal-sessions
Portal Configuration
Each setting falls back to your organization’s default when omitted.Complete Integration Flow
Key Webhooks
Subscribe to these webhooks under Settings → Connections → Developers → 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
- Build against sandbox:
https://api.sandbox.alguna.iowith a key from app.sandbox.alguna.io - Create test accounts and grant credits
- Deplete credits by sending test events
- Complete a test checkout with your processor’s test cards
- Verify webhooks are received and signatures verify
Next Steps
Billable Metrics
Define how usage is measured and billed.
Customer Portal
Full portal configuration options.
Webhooks
Complete webhook reference.
Developer quick start
Auth, SDK, errors and sandbox in one page.