Skip to content

Get started

Your first sale

From zero to a paid invoice: which path to pick, what to store, and what to do about the double click.

Updated

There are three ways to charge for a product, and they solve the same problem with very different amounts of work on your side. Choose first, implement after.

Which path is yours

What you buildWhen to use it
Payment linknothingA one-off sale, charging over WhatsApp, a first sale before an app exists
checkout()your own "thanks" pageYou have an app and want the buyer inside it, but do not want to build a payment screen
embed (@beinfi/checkout)the iframe's spot in your appYou want the payment without the buyer leaving your app

All three end at the same payment page, the same invoice and the same webhook. The payment form is always Stripe's, on BEINFI LTD's account: the difference is how much of the experience around it is yours.

In doubt, start with the link

It is the only one that asks nothing of your app. You switch later — the product and the catalog are the same.

The middle path, end to end

Assuming you already have a published product (see catalog), a key and the registration submitted (in sandbox it approves instantly — see testing in the sandbox):

// 1. creates customer + invoice, and returns the hosted URL
const { invoice, url } = await infi.checkout({
  slug: "your-tenant",
  productId,
  customer: {
    externalId: yourUserId,         // YOUR user's id
    email: "[email protected]",  // no CPF/CNPJ is asked for
  },
  successUrl: "https://your-app.com/thanks",
});
 
// 2. STORE THIS. It is the step nobody documents and everybody forgets.
await db.orders.insert({ userId: yourUserId, invoiceId: invoice.id, status: "open" });

You have to map `invoiceId` → your user

We do not know who your user is — you pass an externalId and we return an invoiceId. When the payment confirms, the webhook carries the invoiceId, not your user. If you did not store the pair, you received money and do not know whose it is.

It is the most important architectural decision on this page and it fits in one column of one table in your database.

Where the buyer pays

Send the person to the url. It is Infi's page, carrying your store's name, and the buyer does not leave it:

  1. picks the country (tax and the payment methods depend on it);
  2. sees the total and BEINFI LTD as the seller;
  3. ticks the immediate-access request (without it the charge answers 422 withdrawal_waiver_required);
  4. pays in the Stripe form: card, or Pix when the sale is in BRL. Card with 3DS also finishes there.

Want the payment inside your app? Use the embed (@beinfi/checkout), which opens the same page in an iframe. There the form accepts card and Link only: Pix and the other methods that redirect would pull the iframe out of place.

Do not call `pay.charge` with `pix` or `boleto`

There is no direct Pix, copy-and-paste QR or boleto in the charge response anymore. Pix is Stripe's and shows up in the form. The charge returns a checkoutAction (the session's clientSecret and the publishableKey of BEINFI LTD's account) that only serves to mount the Payment Element — and Infi's page already does that.

Knowing that they paid

Do not trust the redirect or what the charge returns: it comes back pending. Payment is asynchronous, and Stripe's webhook is what confirms.

// production: signed webhook
// sandbox: polling, because registering a webhook answers 503
const paid = await infi.pay.waitForPaid({ slug, invoiceId: invoice.id, timeoutMs: 15000 });

When it confirms, use the event's invoiceId to find the order you stored in step 2. Details in webhooks.

The buyer clicked "Buy" twice

Every non-GET method on the authenticated API requires an Idempotency-Key (the public /pay/* routes, which the buyer's browser calls, do not). This is not bureaucracy: it is what keeps two clicks from becoming two invoices.

// the SAME key for the SAME purchase intent
const key = `order-${yourUserId}-${productId}-${new Date().toISOString().slice(0,10)}`;
 
const { invoiceId, url } = await infi.checkout({ slug, productId, customer, idempotencyKey: key });

From @beinfi/[email protected] on, checkout() accepts idempotencyKey (and since 0.10.4 checkout() returns invoiceId already typed as string, with no ! needed). The resource methods (products.create, invoices.create, coupons.create, …) already took the key as their last argument.

  • Same key, same body → you get the original response back. One invoice.
  • Same key, different body → 409 idempotency_key_reused. That is protection: it means you reused the key for something else.
  • No key → 400 idempotency_key_required.

The SDK generates one when you do not pass it — which protects against a network retry, not against a double click, because each new call gets a new key. For the double click, the key has to come from something stable in your intent, as above.

The simplest fix is not letting them click twice

Disable the button on the first click and treat the Idempotency-Key as the safety net, not as the first line of defence.

Before selling: the name the buyer sees

Your tenant is born with a placeholder name. If you do not change it, the checkout and the payment link literally say "New app" — and nobody buys from a store called New app.

await infi.account.update({ name: "Orvalho Coffee" });
// optional, cited in the payment mandate:
await infi.account.update({ termsUrl: "https://orvalhocoffee.com/terms" });

It takes effect immediately, with no republishing and no new link — the same link starts showing the new name. infi.account.get() reads it back. (From @beinfi/[email protected]; before that it is PATCH /account/tenant.)

You sold. Now deliver

If what you sell is a file or an access, do not build that by hand: attach the deliverable to the product and Infi sends the buyer their personal link when the payment confirms — and returns the same link to you, to show on your thanks page. It is in delivering the product.

The buyer's side — finding out they paid, delivery, and the two polls nobody guesses — is in the thank-you page.