Offers
Something on sale at a fixed price, with a checkout page: how to create it, share its address and take it off sale.
An offer is something on sale at a fixed price, with a checkout page of its own. You create the offer, give the address of its checkout to buyers, and each purchase made there becomes a charge.
Operations
| Operation in the contract | What it does |
|---|---|
createOffer | Puts an offer on sale and returns it, with its checkout_url. Requires the offers:write scope |
getOffer | Returns one offer by its id, on sale or archived. Requires the offers:read scope |
listOffers | Returns the offers of the environment, newest first, paginated by cursor. Requires the offers:read scope |
archiveOffer | Takes an offer off sale, for good, and returns it. Requires the offers:write scope |
The route, the fields and the limits of each operation are in the OpenAPI contract, under these names. The offers of the API are the ones of the dashboard, in Ofertas: an offer created in one appears in the other.
What a key needs
offers:writeto create and to archive,offers:readto read and to list. Writing does not include reading: a key withoffers:writealone creates an offer and cannot read it back. See What a key can do.- A key created before offers were in the API has neither scope. A scope is never added to a key that exists: create another key in the dashboard.
- Without the scope the answer is
403with theinsufficient_scopecode.
Creating an offer
You send the name, as the buyer will read it on the checkout page, and the price, in cents. The answer is the offer, on sale at once.
- The name and the price never change. To change one, archive the offer and create another.
- A name that is only blank space is refused, with
422and theoffer_invalidcode. - There is no
Idempotency-Key: every call creates another offer. If a request fails with a network error or a timeout, list the offers before trying again. An offer created twice by mistake can be archived. - With a live key the offer is created, and it cannot be bought yet. The real bank is not connected. Use a test key.
The checkout address
checkout_url is the address of the checkout page of the offer. Whoever opens it can buy, without an account: the buyer types a name and an e-mail address and receives a PIX code to pay.
- Use the address as the API returns it. Do not build it from the
id. - An address you already gave out keeps working. It is safe to put in an e-mail, an ad or a page: if the checkout ever moves, the old address leads to the new one.
- It stops selling when the offer is archived.
What a purchase creates
Each purchase creates a charge in the environment of the offer, for the price of the offer. The charge expires 24 hours after the purchase.
- It is a charge like any other: it has the same states, it sends the same webhooks, and
getChargeandlistChargesreturn it to a key withcharges:read. - Its
offer_idis the offer, and itscustomeris who bought. See Charges from an offer. - There is no filter by offer. To know what an offer sold, read the charges page by page and keep the ones with its
offer_id. - In test mode, pay the charge of a purchase with
simulatePayment, like any other charge. See Test mode.
An offer sends no webhook of its own. What happens to a purchase is told by the events of its charge. See Webhooks.
Archiving an offer
archiveOffer takes the offer off sale, and there is no way back. The answer is the offer, with archived_at.
- Archiving an archived offer changes nothing and returns it as it is. It is safe to repeat.
- The charges the offer already created stay as they are, and a purchase that was already made can still be paid.
- An archived offer is still returned by
getOfferandlistOffers.archived_atisnullwhile the offer is on sale.
Listing offers
listOffers returns the newest offers first, on sale and archived. Each page brings next_cursor: pass it as cursor to read the next page. A null next_cursor means this is the last page.
Identifiers
The id of an offer has the same format as the one of a charge, with the prefix ofr. For example, ofr_01h455vb4pex5vsknk084sn02q. See Identifiers.
Offers of another environment
Asking for an offer that does not belong to the environment of your key, to read it or to archive it, returns 404 with the offer_not_found code, exactly as if it did not exist.