Request icon
Query icon
Script icon
If icon
Create icon
SlackIncomingWebhook icon
Log icon
Schedule icon
Webhook icon

Reconcile Stripe Charges Against Internal Orders with Kestra

Reconcile Stripe against internal orders in Kestra - match on metadata order id, flag gaps and amount mismatches, alert via GitHub issue and Slack.

Categories
Business

Finance closes the books monthly; payment drift accumulates daily. A charge succeeds in Stripe and the order row never lands, an amount gets edited in one system and not the other, a refund changes a total. None of it fails loudly - it surfaces at month-end as an hour of archaeology. This blueprint reconciles the two sides on a cadence and turns every mismatch into a GitHub issue the same way a failing test does.

How it works

  1. fetch_stripe_charges (io.kestra.plugin.core.http.Request) pulls charges from the Stripe API over the lookback_hours window with Authorization: Bearer {{ secret('STRIPE_SECRET_KEY') }}. The internal order id travels in each charge's metadata.order_id.
  2. fetch_internal_orders (io.kestra.plugin.jdbc.postgresql.Query, FETCH) reads orders with status = 'paid' from the same window straight from your database.
  3. reconcile (io.kestra.plugin.scripts.python.Script, stdlib only) joins both sides on order id and classifies every record: missing_internal_order (charged, no order), missing_stripe_charge (order marked paid, no charge), amount_mismatch (outside amount_tolerance_cents), plus a count of charges carrying no order metadata at all. Results are emitted with Kestra.outputs, including the first 20 discrepancies for the alert.
  4. recon_gate (io.kestra.plugin.core.flow.If) opens a labeled GitHub issue with a discrepancy table and posts a Slack summary when the count is non-zero; a clean run logs a one-line all-clear instead.
  5. The flow-level errors handler alerts Slack when the run itself breaks, so a dead API token never reads as a quiet reconciliation.

What you get

  • A daily verdict on whether Stripe and your ledger still agree, with the exact orders that do not.
  • A GitHub issue as the durable record, with kind, order id, and both amounts in a table.
  • Counts and the discrepancy list as flow outputs for dashboards or downstream automation.
  • A tolerance input, so rounding rules and partial captures do not page anyone.

Who it's for

  • Finance and revenue ops teams who currently reconcile exports by hand.
  • Engineering teams owning an order table plus Stripe, without a billing platform in between.
  • Anyone who has found a paid order with no matching charge a week too late.

Why orchestrate this with Kestra

A reconciliation script in cron tells nobody when it breaks: an expired Stripe key, a renamed column, a network blip - each one silently skips a day of the audit. Kestra wraps the same three steps in scheduled and webhook triggers, retries, a failure path that alerts, execution history you can replay, and outputs you can build the next workflow on.

Prerequisites

  • A Stripe account with charge read access.
  • An internal orders table (default schema finance.orders with order_id, amount_cents, currency, status, created_at) - adjust the SQL to yours.
  • Charges tagged with metadata.order_id so both sides can be joined.
  • A Kestra instance with network access to Stripe and the database.

Secrets

  • STRIPE_SECRET_KEY: Stripe secret key with charge read access.
  • POSTGRES_JDBC_URL: JDBC URL for the orders database.
  • POSTGRES_USERNAME: database username.
  • POSTGRES_PASSWORD: database password.
  • GITHUB_TOKEN: token with issue create access in repository.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for alerts.

Quick start

  1. Add the six secrets above to your Kestra instance.
  2. Point fetch_internal_orders at your real orders table.
  3. Set repository to the repo that should receive discrepancy issues.
  4. Run manually once and inspect reconcile outputs, then enable the daily_close schedule.

How to extend

  • Fetch balance_transactions instead of charges to reconcile at payout granularity.
  • Add refunds and disputes to the python match by pulling /v1/refunds in a second HTTP task.
  • Split the issue by kind with a Switch task so missing orders and amount mismatches reach different owners.
  • Load the daily verdict into a table with a follow-up jdbc.postgresql.Query for a reconciliation history dashboard.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.