Quick overview
This workflow listens to Lago payment webhooks, retries failed invoice collections up to three times, stores a durable dunning state in an n8n Data Table, and emails billing when a retry is requested, customer action is required, or a payment is recovered.
How it works
- Receives verified and deduplicated payment events from Lago via a webhook trigger.
- Normalizes the webhook payload to extract the invoice ID, customer identifiers, payment status, and a recommended handling action.
- For payment failures, fetches the invoice and customer from Lago, loads the current retry count from an n8n Data Table, and retries the invoice payment in Lago when the invoice is still unpaid and the three-attempt cap is not reached.
- Records the updated dunning state (retry requested or manual review required) in the n8n Data Table and prepares a billing notification message.
- For events that require customer authentication, preserves the current retry count in the n8n Data Table and prepares an alert that includes the payment action URL.
- For successful payments, marks the invoice as recovered in the n8n Data Table while retaining the accumulated retry count.
- Sends a plain-text email to the billing address for retry, manual review, customer action required, and recovery outcomes.
Setup
- Add your Lago API credential to the Lago Trigger and all Lago nodes used to get invoices, get customers, and retry payments.
- Configure an SMTP credential for the email node and replace the default to/from addresses ([email protected] and [email protected]).
- Create (or select) an n8n Data Table for “Lago Dunning State” and ensure it includes fields for invoice/customer identifiers, event and payment status, retry_count, state/last_action, total_amount_cents, and last_event_at.
- Activate the workflow and ensure Lago can deliver webhook events to the trigger’s registered endpoint.