An invoice PDF looks trivial until you add tenants, customers, and drafts. Then every download is an access-control decision. Here is how we handle it in StoreFlux, and where the edges are.
Who can download what
There are two download routes. Staff use the admin route, and customers use the storefront route for their own orders. Both run the same query handler.
The handler resolves the invoice first. For an order, it looks up the invoice that belongs to that order and the current tenant. If no invoice exists, the answer is not found, because there is nothing to render.
Then it checks ownership. A super admin can read across tenants. Everyone else must match the invoice's tenant, or the request throws an unauthorized tenant error.
A customer gets one more rule. They can only open invoices where the invoice's user is them, and a draft is never shown to a customer. For anyone else, the handler returns nothing, which becomes a not-found response. We chose not-found over forbidden on purpose, because a forbidden answer would confirm that the invoice exists.
Built from the record
The PDF is rendered from the invoice record, its line items, and the refund information for the order, so the figures match what the order says. The dates use the tenant's own time zone, so a store's invoices do not shift by a day because the server runs somewhere else.
Rendering
We use QuestPDF under its Community license, behind an interface (IInvoicePdfRenderer). The interface means the renderer can be swapped or tested without touching the handler.
One setting matters for stores that sell in more than one script. QuestPDF normally fails the whole document when a character has no glyph in the fonts it can see. We turn that check off, so a name in a script with no installed font shows a placeholder for those characters instead of failing the invoice. The container image installs DejaVu and Noto fonts for this.
What this does not claim
A PDF exists only where an invoice record exists. Invoices are created by hand or when an order is confirmed, depending on how the store is set up. We do not create a PDF for every order automatically.
The wording and due dates on these invoices are marked in our code as needing finance review. We do not claim the layout is a tax-compliant invoice in every country.
Open question
If you have shipped invoices across countries: how do you handle numbering and required fields when the rules change by jurisdiction? I would like to see what has worked in practice.
Top comments (0)