INVOICE PROCESSING

Block draft invoice send when Postgres event count diverges from Stripe meter

On Stripe's invoice.created webhook, recounts the customer's billable events in your Postgres ledger for the period and, if it disagrees with the metered quantity beyond…

CategoryInvoice Processing
Enginesim
Difficultyintermediate
Triggerwebhook
Steps6
Setup~15 min

How it runs

The automated pipeline, trigger to output.

  • TriggerStripe invoice.created webhook firesStripeStripe
  • ActionRead invoice period and metered quantitiesStripeStripe
  • ActionCount billable events in Postgres ledger for periodPostgreSQLPostgres
  • LogicCompute variance; exit if within tolerance
  • ActionPause invoice for manual review in StripeStripeStripe
  • OutputAlert billing team in Slack with both countsSlack

What it does

This is an event-driven gate that intercepts each draft invoice the moment Stripe creates it. It treats your application's own Postgres event ledger as the source of truth, recounts billable events for the invoice's period, and compares against what Stripe metered. A material gap pauses that single invoice rather than the whole batch.

When to use it

Use it when invoices finalize automatically and you want a per-invoice circuit breaker — catching a specific customer's mis-meter without delaying everyone else. Best when your billable events are already persisted in Postgres alongside the Stripe customer ID.

How it works

  1. 1Stripe's `invoice.created` webhook triggers the workflow for one draft invoice.
  2. 2Read the invoice's customer, period start/end, and metered line quantities.
  3. 3Query Postgres for the count of billable events for that customer within the exact period window.
  4. 4Logic step computes percent variance; if within tolerance, the workflow exits and lets Stripe finalize.
  5. 5If the variance exceeds threshold, call Stripe to mark the invoice for manual review (prevent auto-advance) and post a Slack alert with both counts and the customer link.

Set it up

What you configure once, before turning it on.

  1. 1
    Connect StripeCustomers, subscriptions, payments.
  2. 2
    Connect PostgresAny Postgres URL — query, write, migrate.
  3. 3
    Connect SlackChannels, DMs, threads, mentions.
  4. 4
    Set each agent's modelWe leave models unset so you pick the tier — fast + cheap, or top-quality.
  5. 5
    Tune it to your dataEdit the prompts, filters, and field mappings so it matches how your team works.
  6. 6
    Test, then turn it onRun once against a sample, confirm the output, then enable the trigger.

Run this workflow in your colony.

14-day trial. No DevOps. No Sales call. Provisioned in under a minute.