JavaScript messages

We have three type of messages you can send to the Payson Iframe object.

  • lock – Used to lock iframe object from user interaction until is unlocked ot updated.
  • release –  Release an already locked iframe object.
  • updatePage – Reloads the iframe object (for example after updating of an order amount)

Code examples of messaging events

    function sendUpdate() {
        var iframe = document.getElementById('paysonIframe');
        iframe.contentWindow.postMessage('updatePage', '*');
    }

    function sendLockDown() {
        var iframe = document.getElementById('paysonIframe');
        iframe.contentWindow.postMessage('lock', '*');
    }

    function sendRelease() {
        var iframe = document.getElementById('paysonIframe');
        iframe.contentWindow.postMessage('release', '*');
    }

 

JavaScript callbacks

There are two different JavaScript events used in Checkout Iframe to message parent window about some changes in the purchase process.

  • PaysonEmbeddedAddressChanged – Sent when customer adress has been set or changed.
  • PaysonEmbeddedCheckoutResult – Sending a Checkout status  when purchase is complete.

Code example of listening of event

   document.addEventListener("PaysonEmbeddedAddressChanged",function(evt) {
        var address = evt.detail;
        
      //adress.City
        //adress.CountryCode
        //adress.FirstName
        //adress.LastName
        //adress.PostalCode
        //adress.Street
        //adress.Email
        
        // ** Do something **
    });

    document.addEventListener("PaysonEmbeddedCheckoutResult",function(evt) {
        var result= evt.result;
        
        if(result == 'ReadyToShip') {
             // Do something
        }

        if(result == 'Canceled') {
             // Do something
        }

        if(result == 'Denied') {
             // Do something
        }

        if(result == 'Expired') {
             // Do something
        }
    });