Explains how to retrieve Payment Intent status directly from the Payment Window UI.

The window.postMessage()method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.

Message events

Currently, there is only one event with the type coinify.payment-intent.updated.

The message data object contains the following properties:

PropertyDescription
stateShows the state of a Payment Intent.
stateReasonShows the specific reason behind the the state.

You can find all possible state and stateReason values with their explanations on our Resource page.

For example, here's a message event for a completed Payment Intent with the exact amount paid as it was requested:

{
  type: 'coinify.payment-intent.updated',
  stateReason: 'completed_exact_amount',
  state: 'completed'
}

Retrieve message events

Please find the code snippet example of how you can retrieve the message events from our Payment Window and fetch the state and the stateReason properties from the data object and act based on their values accordingly:

window.addEventListener(
    'message',
    (event) => {
      if (event.data.type === 'coinify.payment-intent.updated') {
       // if you want to react on every event - your code goes here
       // or you can be more specific:
       const { state, stateReason } = event.data;
       if (state === 'completed') {
         // code to e.g. close the Payment window
       }
      }
    },
    false,
  );