Skip to content

Instantly share code, notes, and snippets.

@involer
Created April 17, 2015 16:37
Show Gist options
  • Save involer/bd02cfdba89f8fd15429 to your computer and use it in GitHub Desktop.
Save involer/bd02cfdba89f8fd15429 to your computer and use it in GitHub Desktop.
Listening to Paddle Checkout Events
var event_method = window.addEventListener ? "addEventListener" : "attachEvent";
var my_eventer = window[event_method];
var message_event = event_method == "attachEvent" ? "onmessage" : "message";
// Listen to message from child window
my_eventer(message_event, function(event) {
if(event.data.action == 'complete') {
console.log('Checkout Complete');
} else if(event.data.action == 'close') {
console.log('Checkout Closed');
}
}, false);
@manchumahara
Copy link

This code helped me but not directly. seems the latest paddle.js has a bit different.

As per my findings the current paddle.js gives the event.data.action value as "event", there is another property event.data.event_name which is the actual event name and event name has format like 'checkout.closed', 'checkout.completed'

here is my modified code.

 // Listen to message from child window
        my_eventer(message_event, function(event) {
            console.log(event);
            if(event.data.action == 'event' && event.data.event_name == 'checkout.completed') {
                console.log('Checkout Complete');
            } else if(event.data.action == 'event' && event.data.event_name == 'checkout.closed') {
                console.log('Checkout Closed');
            }
        }, false);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment