Get started
The thank-you page
The buyer's side: from the payment screen to them receiving it, on both selling paths.
Updated
The other pages cover what you do: catalog, charging, deliverable. This one covers what happens on the buyer's side — and it is where integrations get stuck, because it is the part with intermediate states.
The whole thread is this, and it holds on both selling paths:
payment screen → they pay → you find out they paid → you deliver
↑ polling ↑ polling again
Those two polling steps are the part nobody guesses. One at a time.
Path A: you have the invoice (checkout())
You have had invoiceId from the start, so this is the short path:
const { invoiceId, url } = await infi.checkout({
slug, productId,
customer: { externalId: "u_1", email },
successUrl: "https://your-app.com/thanks",
idempotencyKey: `sale:${orderId}`,
});
// send the buyer to `url`: they pay by card or Pix in the Stripe formStore the invoiceId → your user pair before showing the screen. It is how
you will know whose purchase it was when the payment comes back.
Path B: you sent a payment link
The link is the recommendation for anyone who does not want to build a screen. If you want to control the experience and still use a link — or to test the flow over HTTP — it is three steps, and the invoice only exists at the third.
# 1. what to show on the screen (public, no auth)
curl "$API/pay/$SLUG/links/$TOKEN"
# -> { "merchant": {...}, "product": {...}, "testMode": true,
# "unavailableReason": "buyer_country_required", … }
# 2. open the session with email and country
curl -X POST "$API/pay/$SLUG/links/$TOKEN/sessions" -H 'Content-Type: application/json' \
-d '{"email":"[email protected]","name":"Ana","buyerCountry":"US"}'
# -> 201 { "sessionId": "fa90ea6d-…", "legalSeller": { "name": "BEINFI LTD", "country": "GB" },
# "totals": {...}, "withdrawalWaiver": { "text": "Peço acesso imediato…" }, … }
# 3. charge — THIS step materialises the invoice
curl -X POST "$API/pay/$SLUG/links/$TOKEN/sessions/$SESSION_ID/charge" \
-H 'Content-Type: application/json' -d '{"method":"card","withdrawalWaiver":true}'
# -> 201 { "invoiceId": "inv_…", "provider": "infi_stripe_uk",
# "checkoutAction": { "kind": "stripe_checkout_elements", "clientSecret": "cs_test_…", … } }Three things that cost time if you do not know them:
- The invoice does not exist before step 3. The session has no
invoiceId— it appears in the charge response. Do not look for it earlier. - The charge is on the session, not on the invoice.
/sessions/{id}/charge, not/invoices/{id}/charge. The second one exists and serves path A. - A buyer in Brazil, or with no
buyerCountry, still sends CPF/CNPJ on this route: withouttaxIdthe session answers400 "A valid CPF or CNPJ is required.". A buyer from abroad, withbuyerCountry, does not. An invoice created bycheckout()asks for no document at all. withdrawalWaiver: trueis the buyer ticking the immediate-access request with the text the session returns. Without it,422 withdrawal_waiver_required.method: "card"is the Stripe form, not the method: inside it the buyer chooses card or, on aBRLsale, Pix.checkoutActiononly serves to mount the Payment Element; the link's page already does that.
These routes do not require an `Idempotency-Key`
The rule "every non-GET method requires the key" applies to the authenticated
API. The public /pay/* routes — the ones the buyer's browser calls — accept
requests without it.
An invoice nobody will pay: void it
checkout() creates a finalised and numbered invoice. If the buyer gave up,
it stays open in your reporting until you clean it up:
await infi.invoices.void(invoiceId); // -> status "void"A customer with no name and no email is refused: one of the two is required
(422 customer_name_required).
Finding out they paid
const paid = await infi.pay.waitForPaid({ slug, invoiceId, intervalMs: 700, timeoutMs: 15000 });Always pass timeoutMs. The default is 600000 — ten minutes — so on an
unpaid invoice, which is the normal case, your handler hangs instead of
answering.
In production the payment.confirmed webhook is the right path; in sandbox
registering one answers 503, so it is polling — details in
webhooks.
Do not read the invoice only once
Confirmation arrives through Stripe's webhook, a moment after the buyer pays. A
single read returns open and you show "waiting" to somebody who already paid.
With Pix it can take longer: the buyer is still in the bank app when they come
back to your page.
Delivering — and the second poll
Here is the mistake you can make with the whole doc open in front of you: the
grant does not exist the instant the invoice turns paid. Delivery runs after
the payment confirms, so the first read returns [].
if (paid) {
let grants = [];
for (let i = 0; i < 10 && grants.length === 0; i++) {
grants = await infi.invoices.deliverable(invoiceId);
if (grants.length === 0) await new Promise((r) => setTimeout(r, 500));
}
if (grants[0]) showButton(grants[0].downloadUrl);
}An empty list is a 200, never a 404 — deliberately, precisely so this is
safe to poll in a loop. The rest of the deliverable is in
delivering the product.
Testing all of this end to end
In sandbox you pay for real, in Stripe's test mode: open the page and use the
card 4242 4242 4242 4242, or choose Pix and authorize the test payment on
Stripe's instructions page. There is no route to "confirm as if I had paid". It
is spelled out in testing in the sandbox.
The whole page, together
// GET /thanks?invoice=...
const invoiceId = req.query.invoice;
const paid = await infi.pay.waitForPaid({ slug, invoiceId, intervalMs: 700, timeoutMs: 15000 });
if (!paid) return render("waiting", { invoiceId }); // let them reload
let grants = [];
for (let i = 0; i < 10 && grants.length === 0; i++) {
grants = await infi.invoices.deliverable(invoiceId);
if (grants.length === 0) await new Promise((r) => setTimeout(r, 500));
}
return render("thanks", {
download: grants[0]?.downloadUrl, // may be undefined: product with no deliverable
order: await myDb.byInvoice(invoiceId),
});download coming back undefined is not an error: it is a product with no
deliverable, or delivery that has not run yet. In both cases, showing "your
access arrives by email in a moment" beats an empty screen — and the email does
go out, as long as the address is real.
If the sale is reversed
Refunding is not only giving money back: with a digital product the buyer already has the file, and the link is still in their inbox. What decides what happens to the access is the amount of the refund — full switches it off, partial does not. It is in refunds.