ingestlayer/recipes

Monitor failed payments in Postgres

Catch failed charges the second they happen, with the customer, amount, and decline reason attached, so a billing problem becomes a message instead of a churn surprise.

01source

sourcesdk.eventTypeScript SDK
matchpayment.failed

02pipeline · 2 steps

  • 01CTLfilter.matchamount ≥ 50.00 only
  • 02ENRenrich.entitycustomer → plan · MRR · CSM

03destinations · 1

  • towarehouse.pgPostgres
    tableevents.signups

the event

You emit payment.failed with this shape. The TypeScript SDK keeps the call type-safe, and the event is stored whole — so every field below is available to the pipeline by name.

  • customer_idstring
  • emailstring
  • amountnumberminor units
  • currencystringISO 4217
  • reasonstringprocessor decline code
  • attemptnumber

emit it

From your code with the TypeScript SDK — or any language over the REST endpoint and signed webhook ingress.

emit payment.failed
import { ingest } from "@ingestlayer/sdk";

await ingest("payment.failed", {
  customer_id: charge.customer,
  email:       charge.receipt_email,
  amount:      charge.amount,
  currency:    charge.currency,
  reason:      charge.failure_code,
  attempt:     charge.attempt,
}, {
  idempotencyKey: `${charge.id}:${charge.attempt}`,
});

route it to Postgres

Insert each event as a row into a table in your own Postgres.

  1. 01

    add the connection

    Paste a Postgres connection string. Connections originate from our EU region — allowlist those egress IPs on your database.

  2. 02

    point at a table

    Name the target table. Top-level event fields map to columns, and the full payload is also available as a jsonb column.

  3. 03

    map columns

    Match event fields to columns with $event.* references, or accept the default mapping into a typed events table.

in postgresdelivered
INSERT INTO events.signups
  (user_id, email, plan, source, payload)
VALUES
  ('u_018f', 'ada@acme.com', 'pro',
   'marketing-site', '{ … }'::jsonb);

notes

questions

How do I avoid alert spam on retries?
Filter on the attempt field, or set a dedupe window so repeated failures for the same charge collapse into one alert.
Can I only alert on high-value customers?
Yes. enrich.entity pulls MRR onto the event, then a filter keeps only the ones above your threshold.
Where does the decline reason come from?
Whatever you put in the reason field — usually the processor's decline code. ingestlayer passes it through untouched.
build this pipelineor read the quickstart →

failed payments, routed elsewhere

more, into Postgres