Checkout events
Listen to what an embedded or overlay checkout does: ready, opened, paid, closed.
The checkout tells your page what happens through browser events on document. They need no
setup: the install code is enough.
<script>
document.addEventListener("fungies:checkout:completed", (event) => {
window.location.href = "/thank-you?order=" + encodeURIComponent(event.detail.orderNumber ?? "");
});
</script>Events are for your page: redirecting, refreshing what the buyer sees, analytics. They are not a record of a sale. Grant access and fulfil orders from webhooks, which reach your server even when the buyer closes the tab.
Events
| Event | When it fires | Extra detail fields |
|---|---|---|
fungies:checkout:ready | The checkout has loaded | |
fungies:checkout:opened | The overlay opened | |
fungies:checkout:closed | The overlay closed | reason: escape, backdrop, close-button or programmatic |
fungies:checkout:details-completed | The buyer finished the details step and the price was calculated | |
fungies:checkout:discount-applied | A discount code was accepted or refused | applied: true or false |
fungies:checkout:payment-submitted | The buyer pressed pay, or completed a free order | |
fungies:checkout:payment-declined | The payment did not go through. The buyer can try again in the same checkout | reason |
fungies:checkout:completed | The purchase finished | currency, totalMinor, taxMinor, lines, orderId, orderNumber |
fungies:checkout:resized | The checkout's box changed size, and once when it loads | width, height in CSS pixels |
fungies:checkout:error | The checkout could not be drawn | reason, and code where there is one |
fungies:checkout:complete and fungies:checkout:close fire beside completed and closed
with the same detail, so listeners written for the earlier names keep working.
The detail object
Every event's detail carries:
| Field | What it is |
|---|---|
v | The payload's version, 1 |
checkoutId | The element's id |
mode | embed, overlay or hosted |
instanceId | Which checkout on the page spoke, when the page holds more than one |
livemode | true for a live checkout, false for test mode, where it is known |
elementKind | The kind of element |
On completed, amounts are in minor units (cents for USD), and lines lists each offerId with
its quantity. orderId and orderNumber are present when the order is already known; do not
rely on them, and match the order from its webhook instead.
completed fires once per purchase. A payment that is still clearing does not fire it.
No event ever carries what the buyer typed: no e-mail, name, address, tax id, discount code or card detail.
Two checkouts of the same element
A page can hold several checkouts, even two of the same element. Use detail.instanceId, not
checkoutId, to tell which one an event came from.
Errors
fungies:checkout:error fires when a checkout cannot be drawn. Some reason values:
reason | What to fix |
|---|---|
offer-not-published | data-offer names an offer the element does not sell |
quantity-out-of-bounds | data-quantity is above what the offer allows, or the element sells several offers |
discount-code-malformed | The discount code in a hosted link is empty or too long |
environment-unsupported | The page is not served over https |
The browser console also explains each refusal, on a line starting with [fungies-element].
Last updated