Checkout Elements

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

EventWhen it firesExtra detail fields
fungies:checkout:readyThe checkout has loaded
fungies:checkout:openedThe overlay opened
fungies:checkout:closedThe overlay closedreason: escape, backdrop, close-button or programmatic
fungies:checkout:details-completedThe buyer finished the details step and the price was calculated
fungies:checkout:discount-appliedA discount code was accepted or refusedapplied: true or false
fungies:checkout:payment-submittedThe buyer pressed pay, or completed a free order
fungies:checkout:payment-declinedThe payment did not go through. The buyer can try again in the same checkoutreason
fungies:checkout:completedThe purchase finishedcurrency, totalMinor, taxMinor, lines, orderId, orderNumber
fungies:checkout:resizedThe checkout's box changed size, and once when it loadswidth, height in CSS pixels
fungies:checkout:errorThe checkout could not be drawnreason, 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:

FieldWhat it is
vThe payload's version, 1
checkoutIdThe element's id
modeembed, overlay or hosted
instanceIdWhich checkout on the page spoke, when the page holds more than one
livemodetrue for a live checkout, false for test mode, where it is known
elementKindThe 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:

reasonWhat to fix
offer-not-publisheddata-offer names an offer the element does not sell
quantity-out-of-boundsdata-quantity is above what the offer allows, or the element sells several offers
discount-code-malformedThe discount code in a hosted link is empty or too long
environment-unsupportedThe page is not served over https

The browser console also explains each refusal, on a line starting with [fungies-element].

Last updated