I'm incorporating paypal into my site , however, once I receive the token and try to redirect to paypal's site, nothing happens. I'm using knockout.js on my front end. When I click a button to make a GET request, the values are sent over to a corresponding CakePHP action which verifies the data and then redirect to paypal's site to finish the transaction.
Now here's the strange part. At first I assumed I messed up the jQuery to make the GET but that doesn't seem to be the case. When I make the GET request with the header('location...') code included in the corresponding action, the network tab shows the request failed as "canceled". However, when I comment out the header('location..') code the request goes through successfully.
Here's GET request on
//order_processing.js
$.getJSON("/orders/pay_for_order/" + itemNumbers + "/" + quantities + "/" + prices + "/" + productNames + "/" + self.fullName() + "/" + self.addressLine1() + " " + self.addressLine2() + "/" + self.city() + "/" + self.state() + "/" + self.ZIP() + "/" + self.email(),function(data) {
});
Here's the action that the request goes to
//OrdersController
function pay_for_order($id = null){
//processing code here
//get token from paypal
if($finalize_order->verifyPrice($item_numbers, $prices) == TRUE){
//when I comment out this header redirect the GET request is successful, but of course then does not redirect
header( 'Location: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$token ) ;
}
}
I know my calls to paypal are working correctly to get the token, because when I copy/paste the link into the address bar it then redirects (meaning the token was successfully received). This to me seems like it's an issue with jQuery making the request. However, I'm confused as to why the GET request fails when I have the header redirect included, but when it's commented out the GET passes.
Update
I swapped out the header redirect for the following and it doesn't fail, however, it doesn't redirect either. This code showing up in the response as well, so I think this probably means CakePHP does not like header('location') redirects.
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$token.'">';