jQuery(document).ready(function ($) {
    $("#pw-pay").on("click", function () {
        let {pay_link, complete} = $(this).data();
        let popup = popupLink(pay_link, 900, 900);

        let timer = setInterval(function () {
            if (popup.closed) {
                window.location.href = complete;
                clearInterval(timer);
            }
        }, 500);
    });
});

function popupLink(link, width, height) {
    let _top = window.outerHeight / 2 + window.screenY - height / 2;
    let _left = window.outerWidth / 2 + window.screenX - width / 2;
    let params = `scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=${width},height=${height},left=${_left},top=${_top}`;

    return open(link, "", params);
}