Netcraft

// Case study · Automation

Stripe to Keez: one invoice for every Stripe payment, issued automatically

This is an internal automation at Netcraft Digital. Every day, a scheduled job reads the successful charges from two Stripe accounts, netcraft.digital and fisaedu.ro, and issues one invoice per charge in Keez, the Romanian accounting software we use. It has been live since 13 November 2026.

The rule was simple: invoice only payments that came through Stripe, never twice, and touch nothing else. The job uses read-only Stripe keys, takes the amount in lei from Stripe's balance transaction, looks up company details at ANAF (the Romanian tax authority) by tax ID, and recognises payments already invoiced by hand instead of invoicing them again.

At a glance

Type
Internal automation
Owner
Netcraft Digital SRL (our own)
Payment sources
2 Stripe accounts: netcraft.digital and fisaedu.ro
Live since
13 November 2026
First production run
10 invoices issued
Source: 13 November 2026
Schedule
Daily, plus on demand from fisaedu.ro after a payment
Runs on
netcraft.digital (Next.js on Vercel)

// Features

What users can do

  • Exactly one invoice per charge

    Each payment gets one row in a ledger. Rows that are issued, matched, marked or skipped are final and never looked at again. Rows that wait for data or failed are retried on the next run, and a draft already created in Keez is issued instead of creating a second one.

  • A lock between runs

    The daily run and the on-demand run for fisaedu.ro take the same Postgres advisory lock. If one is running, the other stops, so a payment can never get two invoices.

  • Company details from ANAF

    When the buyer is a company, its legal details are read from ANAF by the tax ID stored in Stripe. On netcraft.digital every buyer is a company, so a payment without a tax ID waits instead of being invoiced.

  • Manual invoices recognised

    Before issuing, the job looks in Keez for an invoice made by hand: same total in lei, the same buyer name (ignoring word order, case, diacritics and legal-form words), dated from 10 days before to 20 days after the payment. A match is recorded, not invoiced again.

  • Exclusions

    Some clients are invoiced by hand with activity reports. They are on an exclusion list and never get an automatic invoice.

  • Invoices on demand for fisaedu.ro

    fisaedu.ro can list the invoices for its payments, get the PDF from Keez and ask for an invoice right after a payment, through an API protected by a shared secret.

  • Dry run before any change

    A dry run against production Keez shows the invoices that would be issued, with full details, before any change goes live.

  • A report after every run

    Each run returns counts per outcome, and any payment that needs data or failed is logged for attention.

// Decisions

What we chose, and what we rejected

Each decision with its reason and the option we left out.

Read-only Stripe keys

We chose
Each Stripe account gives the job a restricted key that can only read.
Why
The job must invoice Stripe payments and touch nothing else.
Rejected
Full Stripe secret keys.

The amount comes from Stripe, not from contracts

We chose
The invoice total is the amount in lei from Stripe's balance transaction.
Why
The invoice matches the money that was actually received.
Rejected
Taking the amount from contract or list prices.

Match old invoices instead of marking them

We chose
Payments already invoiced by hand are found in Keez and recorded as matched.
Why
Each payment is checked against what was actually issued, so a payment invoiced by hand is never invoiced again.
Rejected
Marking every payment before a cut-off date as already invoiced. The option exists but is not used in production.

One scheduled job instead of webhooks in each app

We chose
A single daily job in netcraft.digital invoices both Stripe accounts, and fisaedu.ro calls the same code, under the same lock, when it needs an invoice at once.
Why
One place decides whether a payment has an invoice, so two paths cannot both issue one.
Rejected
Webhook-based invoicing inside fisaedu.ro, which we dropped in favour of this job.

How a payment becomes an invoice

  1. The job takes the Postgres lock; if another run holds it, it stops.
  2. It reads the successful charges from both Stripe accounts, from each account's start date.
  3. Payments with a final row in the ledger are skipped.
  4. For each new payment it looks for a matching invoice made by hand in Keez.
  5. If there is none, it builds the buyer (from ANAF for companies), creates the invoice in Keez and issues it.
  6. The result is written to the ledger and summarised in the run report.

If you need an automation like this for your own payments, see custom web app development.

// Stack

How it is built

Framework
Next.js on Vercel (netcraft.digital)
Scheduling
Vercel Cron, daily at 06:00 UTC, protected by a secret
Database
Postgres through Payload CMS (ledger collection)
Payment data
Stripe API with restricted read-only keys
Accounting
Keez API
Company data
ANAF public API

// FAQ

Frequently asked questions

Another question? Write to us; you get an answer from the developer within one working day.

What if the job runs twice, or two runs overlap?

Both runs take the same Postgres advisory lock, so the second one stops. Each payment also has a ledger row, and a final row is never processed again. A draft already in Keez is issued rather than created twice.

What about payments we already invoiced by hand?

The job looks for them in the accounting software by total, buyer name and a date window around the payment. A match is recorded and no new invoice is issued.

Can you build this for another accounting tool or payment provider?

The parts are the same: read-only access to the payments, a ledger with one row per payment, a lock, matching against existing invoices and a dry run before going live. The integration with the accounting software's API changes. Contact us with the tools you use.

Want something like this built?

Describe your product. You get a written scope, a fixed price and a delivery date within 24 hours.