Set up a test environment
Each Lago organization is a single environment. Lago has no test mode and no separate test API keys. To test without touching production data, use a separate organization, for example “Company Staging” next to “Company Production”.- Replicate the same configuration in both organizations: billable metrics, Products, Rate Cards, Plans and webhook endpoints. Codes are scoped to an organization, so you can reuse the same codes in both.
- Contracts require the Product catalog. Make sure it is enabled on both organizations.
- Each organization has its own API keys. Point your test environment at the test organization’s key and keep keys out of source code.
- Your organization lives in one region. Send requests to
https://api.getlago.com/api/v2(US) orhttps://api.eu.getlago.com/api/v2(EU). See Lago Cloud.
Run the flow
The Contracts flow is: billable metric, Product, Rate Card and Rates, Plan with applied Rate Cards, customer, Contract, events, invoice.1
Define a billable metric
The billable metric defines how Lago aggregates usage events. Fixed Products do not need one.
- Access the Billable metrics section in the side menu.
- Create a new billable metric.
- Enter its name, the
codeyour events will send and its aggregation type. - Save the billable metric.
2
Create the Products
A Product is what you sell. A metered Product references a billable metric. A fixed Product has no metric and bills a quantity set on the Plan or Contract.Create each Product with its
Name, Code, Type (fixed or metered), its Billable metric for a metered Product, and an optional Product category.Learn more in Products. API: Create a Product.3
Create the Rate Cards and Rates
A Rate Card sets the currency, billing timing and proration for one Product. Its Rates set the price, the pricing model, the billing interval and when the price takes effect.Create one Rate Card per Product and currency, with at least one Rate. A Rate’s
effective_from cannot be before today in your organization timezone.Learn more in Rate Cards and Rates. API: Create a Rate Card.4
Create the Plan and apply Rate Cards
- Open Plans and click Create plan.
- Enter the Plan’s
Name,CodeandPlan currency. - Click Create plan.
- Open the Plan and select Rate cards under Overview.
- Open the Apply a rate card form, select the
Productand its Rate Card, then click Add rate card. Repeat for each Product.
5
Create a customer
- Open Customers.
- Click Create a customer.
- Enter the customer’s name and external ID.
- Click Create customer.
6
Create a Contract
The Contract applies the Plan to the customer and sets when billing starts.
- From the customer’s page or the Contract list, click Create contract.
- Check the
Customerand select thePlan. - Under Contract settings, click Add an external id and enter your Contract identifier.
- Enter the required
Code. - Set the start date and the
Billing anchor date. - Click Create contract.
pending Contract that becomes active at the start. To test right away, set the start date to today. In the API, omit started_at to start the Contract now.Learn more in Contracts and Billing timeline. API: Create a Contract.7
Send usage events
Your backend sends events to the Contract with
external_contract_id, which matches the Contract’s external_id, not its contract_code. Each event needs a unique transaction_id. The code must match the billable metric code.Send an event
timestamp is in Unix seconds and must fall inside the billing period you want to test. Keep the same transaction_id when you retry a request. Lago uses it for deduplication. To check what Lago received, open Developers and the Events tab.Learn more in Ingest usage. API: Ingest an event, Ingest a batch of events.8
Check current usage
Current usage shows the provisional amounts for the Contract’s open billing windows, before any invoice exists. Use it to confirm that events reach the right Product and price.In the Dashboard, open the Contract and click the Usage tab. Newly accepted events can take a moment to appear.Learn more in Retrieve usage. API: Retrieve Contract current usage.
Retrieve current usage
9
Receive webhooks
Lago notifies your application with webhooks, for example
contract.started when a Contract starts and invoice.created when an invoice is finalized. With a grace period, invoice.drafted fires when the draft is created.- Open Developers.
- Open the Webhooks tab.
- Click Add an endpoint.
- Enter a name and a public endpoint URL.
- Select Standard Webhooks as the signature and the events to receive.
- Click Create endpoint.
10
Check the invoice
Lago generates invoices on the Contract’s billing timeline. Rate Cards billed in arrears are invoiced when the billing period ends. Rate Cards billed in advance are invoiced at the start of the period.With a grace period, the invoice is created as a draft. While it is a draft, you can:
- Refresh it to include events sent after the period ended. API:
PUT /api/v2/invoices/{lago_id}/refresh. - Finalize it to test the rest of your flow without waiting for the grace period to end. API:
PUT /api/v2/invoices/{lago_id}/finalize. Finalization cannot be undone.
product_code, rate_card_code, rate_code, external_contract_id, units, from_datetime and to_datetime to trace it back to your pricing.Learn more in Invoices and Fees. API: List invoices, Retrieve an invoice.Test final billing
To test what happens when a customer leaves, end the Contract withDELETE /api/v2/contracts/{external_id}?contract_code={contract_code}. An active Contract becomes terminated and stops billing from that point, which can produce final fees. A pending Contract becomes canceled and never bills.
Limits of a test organization
- Lago does not simulate time. Billing runs on real dates, so an arrears invoice for a monthly Rate appears when the real billing period ends. To see invoices sooner, use a daily Rate (
billing_interval_unit: day) on a test Rate Card, set a nearbilling_anchor_date, or end the Contract. - An invoice records what the customer owes. It does not confirm payment. Check
payment_statusseparately fromstatus, and use your payment provider’s test mode in the test organization.