GAROPABA::--:-- AVAILABLE::REMOTE FULLSTACK ROLE LCP::… STACK::ASTRO · PYTHON · TYPESCRIPT
PTENES
← Projects
API integration

Every paid order becomes a tax document on its own

A Worker listens for the paid order on Shopify and issues the tax document on CloudInvoice on the spot, no manual entry. Idempotency blocks duplicates, and a dry-run mode tests the whole chain without issuing a real document.

TypeScriptCloudflare WorkersShopify APICloudInvoice APIWebhooks
Status In production
Year 2026
Context Fashion retail · operation in Portugal
0
Tax documents issued during the dry run
Production
Chain proven, waiting for the first sale

The problem

Entering tax documents by hand is the kind of task nobody wants, and it is exactly where most errors happen: wrong series, wrong warehouse, a product that does not match the registry. Here, someone opened CloudInvoice to enter every store order one by one. Beyond the time, the same legal entity also runs a physical operation, so the document had to come out isolated by series, warehouse and family, or the bookkeeping of both fronts would blend together.

What I built

A Cloudflare Worker, in TypeScript, sitting between Shopify and CloudInvoice:

  • Listens to the store’s paid-order webhook.
  • Translates the order into the tax format, applying the rules for series, warehouse and family.
  • Creates customers and products on demand, without requiring manual registration first.
  • Deducts stock in the same operation.
  • Issues the document and returns the generated number.

Technical decisions

Idempotency before anything else. A webhook is delivered at least once, not exactly once. Without an idempotency key, a redelivery duplicates the invoice, and that is an accounting problem, not a software bug. Every order is marked before issuance; reprocessing returns the document already created.

A Worker instead of a server. Volume is low and irregular, with spikes during campaigns. With no server, there is no idle machine costing money and no forgotten host turning into a security incident later. It scales on its own during the spike.

Dry-run mode. An error in a tax integration does not turn into a red log line, it turns into a legal document someone has to void afterwards. The dry-run mode walks the entire chain against the real company, assembles the document, and deletes the draft at the end, without issuing anything.

Explicit failure, visible from the outside. When CloudInvoice rejects a document, the error is recorded along with the order that caused it. A health endpoint exposes the last invoice issued, and an external monitor emails if it stops responding: silent failure is worse than no integration at all.

How I verified it

The dry run went through production, against the real company: a test order produced the draft with the exact total, on the right series, creating the shipping product that did not exist in the registry yet. Draft deleted, no document issued.

Checking that document field by field against the order, an error the log did not show turned up: the net price was rounded before the tax was reapplied, and the total came out a few cents off. Only the comparison revealed it.

I also reprocessed the same order to confirm idempotency, and tested both the new-customer and new-product paths.

What is still missing: the first real sale. The chain is proven in production.