Embedded Flow Events
Handle postMessage events from the embedded checkout iframe
This page lists events sent from the embedded checkout iframe to the parent application, allowing your app to respond to payment completion and receive integration diagnostics.
Validate incoming events
Before handling any checkout event, verify both:
event.originmatches the trusted checkout origin from thecheckout_session_urlyou received from Esenda.event.sourcematches your checkout iframe'scontentWindow.
Do not trust an event based only on its type. Other frames or pages can send messages with the same type.
This listener handles both checkout events:
const iframe = document.getElementById("payment-iframe");
const checkoutSessionUrl = "YOUR_CHECKOUT_SESSION_URL";
const checkoutOrigin = new URL(checkoutSessionUrl).origin;
window.addEventListener("message", (event) => {
if (
event.origin !== checkoutOrigin ||
event.source !== iframe.contentWindow
) {
return;
}
switch (event.data?.type) {
case "PAYMENT_FLOW_COMPLETED":
// Payment journey finished; the parent is responsible for closing the iframe
iframe.remove();
break;
case "INTEGRATION_DIAGNOSTIC":
// Optional: forward to your monitoring (checkout already logs to the console)
reportIntegrationDiagnostic(event.data);
break;
}
});
// Set src after the listener is registered so no early events are missed
iframe.src = checkoutSessionUrl;This example assumes an existing <iframe id="payment-iframe"> without a src attribute. Set checkoutSessionUrl to the checkout_session_url received from Esenda, not a value taken from an incoming message. Replace reportIntegrationDiagnostic with your own monitoring handler, or remove that case if you don't need it.
Payment Flow Completion Event
When the payment journey inside the iframe is completed, the iframe sends a postMessage event to the parent.
The event is sent after a short delay (approximately 3 seconds) to allow the payment status page to render inside the iframe.
Event Properties
| Property | Value | Type | Description |
|---|---|---|---|
type | PAYMENT_FLOW_COMPLETED | String | Indicates the payment journey has finished and the iframe can be closed |
orderId | e.g. 2d6586da-b5ad-4417-901a-c499dbdac774 | UUID | The unique identifier for the completed order |
See Validate incoming events for a listener example.
Example Flow
- The user completes the payment inside the iframe.
- The iframe waits ~3 seconds to allow the status page to render.
- The iframe sends
PAYMENT_FLOW_COMPLETEDto the parent viawindow.parent.postMessage. - The parent app receives the event and closes the iframe or performs post-payment actions.
Notes
- The parent app is responsible for closing the iframe — the iframe does not remove itself.
- The payload currently contains
orderId. Additional metadata may be included in future versions.
Integration Diagnostic Event
Whenever the checkout logs an integration diagnostic to the console, it also sends it to your page as an INTEGRATION_DIAGNOSTIC message. See Iframe Setup for what's checked, how to fix each problem and what can't be detected.
Not a payment result
Handling this event is optional. A diagnostic describes an integration problem, not a failed payment. Don't close the iframe, mark the order as failed or retry the payment in response to it.
Event Properties
| Property | Value | Type | Description |
|---|---|---|---|
type | INTEGRATION_DIAGNOSTIC | String | Identifies an integration diagnostic |
checkId | e.g. iframe-payment-permission | String | Identifies the check that reported the problem. See the list of checks. |
level | error or warning | String | Severity of the integration problem |
message | [Esenda Checkout] ... https://docs.esenda.com/docs/embedded-checkout/iframe-setup | String | Human-readable explanation, starting with the checkout prefix and ending with a documentation link |
docsUrl | e.g. https://docs.esenda.com/docs/embedded-checkout/iframe-setup | String | Documentation for resolving the problem |
Delivery
- Messages aren't retried. Register your listener before setting the iframe's
srcso you don't miss diagnostics sent on load. See the listener example. - Permission and sandbox checks run once the checkout has loaded its payment methods, so they may arrive shortly after the iframe renders.
- Treat
messageas plain display text. Don't render it as HTML or parse it. UsecheckIdandlevelfor any logic.