Esenda
Embedded Checkout

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.origin matches the trusted checkout origin from the checkout_session_url you received from Esenda.
  • event.source matches your checkout iframe's contentWindow.

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

PropertyValueTypeDescription
typePAYMENT_FLOW_COMPLETEDStringIndicates the payment journey has finished and the iframe can be closed
orderIde.g. 2d6586da-b5ad-4417-901a-c499dbdac774UUIDThe unique identifier for the completed order

See Validate incoming events for a listener example.

Example Flow

  1. The user completes the payment inside the iframe.
  2. The iframe waits ~3 seconds to allow the status page to render.
  3. The iframe sends PAYMENT_FLOW_COMPLETED to the parent via window.parent.postMessage.
  4. 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

PropertyValueTypeDescription
typeINTEGRATION_DIAGNOSTICStringIdentifies an integration diagnostic
checkIde.g. iframe-payment-permissionStringIdentifies the check that reported the problem. See the list of checks.
levelerror or warningStringSeverity of the integration problem
message[Esenda Checkout] ... https://docs.esenda.com/docs/embedded-checkout/iframe-setupStringHuman-readable explanation, starting with the checkout prefix and ending with a documentation link
docsUrle.g. https://docs.esenda.com/docs/embedded-checkout/iframe-setupStringDocumentation for resolving the problem

Delivery

  • Messages aren't retried. Register your listener before setting the iframe's src so 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 message as plain display text. Don't render it as HTML or parse it. Use checkId and level for any logic.

On this page