Skip to content

I built my first SaaS for AI agents. I gave it a UI anyway.

A cashier sees “Factura autorizada.” An ERP gets a webhook. Both are waiting for the same decision, and neither can get it from a 201.

4 min read

All writing

Every month I issued an invoice for my own work in Ecuador. I wanted to hand that job to an AI agent without teaching it to click through a form. That's where I started with Fiscalbase, my first SaaS.

Then I put the same invoicing flow behind a till you can run on a phone. At a café counter, someone has already ordered and paid by the time the person behind the till needs to know what happened to the invoice. There's no time to explain the sale to an assistant. A couple of taps on the right screen are enough.

An ERP starts from the opposite position. It already has the customer, the line items and the order. Making someone open a second screen and enter those again just gives the two systems another chance to disagree.

What a 201 actually tells you

On POST /v1/ec/invoices, Fiscalbase answers 201 Created with the invoice ID, a number and status: "pending". There is a real record to look up at that point. Fiscalbase still has to sign the XML and send it to Ecuador's tax authority, the SRI. Once the SRI receives it, the invoice can be submitted while the SRI decides whether to authorize it.

I could have made the request wait for a decision. That would save the client a step on a good day, when the SRI answers quickly. On a slow day the connection could time out after Fiscalbase had already created the invoice. The ERP would be left wondering whether it had anything to show for the request.

The ERP sends a stable Idempotency-Key for the order. If it loses the response, it can repeat the same request with the same key and get back the same invoice. It stores the invoice's id against the order. A retry answers “which invoice did I create?” The invoice's current status answers “what happened to it?”

At the till, the next thing is a receipt

In this recording, the cashier adds a cappuccino and a croissant, finds the buyer by cédula, and records a $4.75 debit-card payment. The card payment has already happened; Fiscalbase records how the buyer paid. The screen ends on Factura autorizada, with the invoice number and options for handing over the receipt.

A silent walkthrough of a $4.75 sale in Fiscalbase, recorded with a fictional café and a simulated authorization.

The till stays connected to a live stream. It shows Emitiendo la factura while the invoice is going through and Factura enviada al SRI if it's still waiting for the SRI to decide. The screen updates when the result arrives. The cashier can see whether the sale went through on their end without mistaking that for authorization.

In the ERP, the next thing is an event

After reading the 201 response, the ERP can get on with the next order. When the SRI authorizes the invoice, Fiscalbase sends a signed invoice.authorized webhook. The ERP verifies the signature, deduplicates delivery by webhook-id, and matches data.id to the invoice on the order. That's the ID it uses to fetch the authorized XML. The printable PDF can take a little longer. If the download returns 409 file_not_ready, the ERP retries that download using the same ID.

If the SRI returns the invoice at reception or declines to authorize it, the webhook is invoice.returned or invoice.not_authorized. The ERP can put the order in front of someone who can fix it, with the SRI's reason from data.sri_messages. Treating the first 201 as the final answer would lose that distinction.

The till and the ERP learn the same fact when the SRI decides. One shows it where a person is already working; the other delivers it where a system can act on it. An agent can check that same invoice by ID without opening the till. The part I needed to share was the meaning of “authorized.”

Try the flow in the Fiscalbase Sandbox. A simulator decides the outcome there, so nothing is sent to the SRI.

Keep reading.

Other problems I ran into on the job, and what fixed them.

Browse all writing

Let’s build yours.