0

I am working on using Paypal payments advanced embedded / hosted checkout pages in my django site. I display an iframe for the paypal payment page, I submit the request, and it posts back to my site.

The view that handles the paypal response uses

response = redirect("shop_complete")
return response

but this makes my whole response page pop up in the iframe. I could just use a template that would look all right in that spot, but I would like to update the cart and the payment step at the same time. Is there anyway to make that response redirect the whole browser instead of just the frame?

Paul Becotte
  • 7,950
  • 2
  • 24
  • 39
  • So if you were to redirect the entire page, what would be in the iframe after redirect? – Drewness Feb 28 '14 at 17:02
  • basically you need javascript in the page you return to the iframe, to load a new url in the top level browser window (can also be done with meta tag) – Anentropic Feb 28 '14 at 17:40
  • There wouldn't be an iframe on the order complete page. – Paul Becotte Feb 28 '14 at 18:25
  • Anentropic - I am using this project to learn about web technology... do you have a link to where I could start looking for the javascript technique I would need? – Paul Becotte Feb 28 '14 at 18:26

1 Answers1

0

So, my solution wound up being to add an intermediary page that consist entirely of a script to redirect the top level of the browser. I got this script from

JavaScript post request like a form submit

<body>

<script type="text/javascript">
function post_to_url(path, params, method) {
    method = method || "post"; // Set method to post by default if not specified.

    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);
    form.setAttribute("target", "_top" )

    for(var key in params) {
        if(params.hasOwnProperty(key)) {
            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", key);
            hiddenField.setAttribute("value", params[key]);

            form.appendChild(hiddenField);
         }
    }

    document.body.appendChild(form);
    form.submit();
};
 window.onload = post_to_url('{% url "shop_paypal_redirect" %}', 
         {csrfmiddlewaretoken: '{{ csrf_token }}',
          result: '{{ result }}'});
</script>
</body>
Community
  • 1
  • 1
Paul Becotte
  • 7,950
  • 2
  • 24
  • 39