abiieez
abiieez

Reputation: 3189

Redirect Parent Page after PayPal Express Checkout

I have a parent page which has PayPal button on it. Pressing the button will trigger a mini-browser where user is able to login and make payment.

The following code closes PayPal mini browser after user made payment successfully.

// Add javascript to close Digital Goods frame. You may want to
                // add more javascript code to
                // display some info message indicating status of purchase in
                // the parent window
                response.setContentType("text/html");
                response.getWriter()
                        .println(
                                "<script>\n alert(\"Payment Successful\");\n// add relevant message above or remove the line if not required \n window.onload = function(){\nif(window.opener){\nwindow.close();\n}\nelse{\nif(top.dg.isOpen() == true){\ntop.dg.closeFlow();\nreturn true;\n}\n}\n};\n</script>");

The mini browser is closed successfully, however the parent page on my application remains the same. How do I update the parent page with the payment status ?

Upvotes: 3

Views: 1812

Answers (1)

abiieez
abiieez

Reputation: 3189

I solved this by adding the following JS code before window.close(); to access the form at the parent page. After getting the form I can submit the page or show dialog notification about the status.

    window.onload = function() {
    if (window.opener) {
        window.opener.document.forms[0].submit(); // submit form
        window.close();
    } else {
        if (top.dg.isOpen() == true) {
            top.document.forms[0].submit(); // submit form
            top.dg.closeFlow();
            return true;
        }
    }
};

Upvotes: 5

Related Questions