A receipt that expires is not a receipt
A member went looking for a receipt from May, and the link I had emailed him in May was already dead. Stripe hosts a tidy invoice page, and then it expires, and the member is left holding a URL that used to be a receipt. A receipt you can lose is not really a receipt. So this week I stopped sending links to someone else's page and started rendering my own.
The shape
PA Gym OS is the membership and billing platform I built to run Persistence Athletics after I replaced Wodify. It is a Next.js app on Node with Postgres underneath, and Stripe is only a card vault: the local invoice row is the source of truth for every figure a member owes. Until this week the only receipt a member could get was a link to Stripe's hosted invoice page, which expires, and which does nothing at all inside the native app because it opens in a new tab the app's WebView will not open. Now every invoice and receipt email carries a self-contained branded PDF, and a member can pull or email their own copy from the billing screen. It renders with pdf-lib in about 240 lines, from the stored row only, and it never expires because it is a file, not a link.
old: the only receipt was a link to Stripe's hosted invoice page, which expired and did nothing inside the app's WebView
new: a branded PDF built from the stored invoice row, attached to every receipt email and downloadable from the billing screen, that never expiresRender from what you stored, never recompute
The one rule the renderer follows is that it does no arithmetic. Every figure and date on the page, the subtotal, the discount, the tax, the total, the paid date, comes straight off the stored invoice row and its line items. There is no tax math, no plan-price lookup, no date construction. That is the first rule in my payment-paths playbook: the numbers a member sees on a document are the numbers I billed, byte for byte, not a fresh calculation that might disagree with the charge. The only trick worth naming is tax. The stored line items already include tax rows, and the totals block also prints a tax line, so I filter the tax-category rows out of the table to keep tax from showing up twice. The non-tax rows sum to the stored subtotal, the totals block prints subtotal minus discount plus tax, and the two reconcile to the stored amount exactly.
The link that worked on the web and vanished in the app
The thing that actually pushed this out was not the expiry. It was a member telling me he could not find his invoice in the app at all. The old receipt was an anchor tag with target="_blank", which on the web opens a new tab and on the phone opens nothing, because the native app runs the member portal inside a WebView and a WebView has nowhere to open a new tab. So the receipt was not just expiring, it was invisible to every member on a phone. The new route streams the PDF inline with the right content type, which the iOS WebView renders in place instead of trying to hand off to a tab that does not exist. The member taps Invoice PDF and the receipt is simply there.
Their invoice, and only theirs
A member-facing document endpoint is a place to be careful, because the invoice id sits right there in the URL and a curious member could try a neighbor's number. The route checks that the invoice actually belongs to the member asking before it renders a single byte, and returns a flat 403 if it does not. The email button sends the PDF to the member's own account email, never to an address they can type, so the destination is never user-controlled. And because rendering can fail on a bad row, the attach step on the automated emails is wrapped so a failed PDF never takes down the receipt email or the payment webhook: worst case the email goes out without the attachment, which is exactly how it went out last month, never a broken charge.
What I learned
A link to someone else's page is not a document you own. Stripe's hosted invoice is convenient right up until it expires, and then my member is holding a dead URL and I am the one who looks like I lost his receipt. Rendering the PDF myself from data I already store means the receipt lasts as long as the member does, works offline, and does not depend on a third party keeping a page alive on my behalf.
A document must show the number you charged, not a fresh calculation. The renderer does no math on purpose. If it recomputed tax or looked up a plan price, a rounding difference or a since-changed price could put a figure on the receipt that does not match what came off the card. Reading straight from the stored row means the paper and the charge can never drift apart.
A link that works on the web can be invisible in the app. target="_blank" is a no-op inside a WebView, so a receipt that opened fine in a browser opened nothing on a member's phone, and I only learned that because a member told me. The fix was to stream the file inline so the WebView renders it in place. Test the thing where the user actually is, which for my members is a phone, not my laptop.
If your software hands customers a receipt that can expire out from under them, owning that document is the kind of plumbing Autosterea builds.
First published on ravikantdewangan.com.

