0

I am implementing Paypal Express using omnipay in Laravel 4. Status code: 302 found when my site try to redirect to paypal.

Error:

XMLHttpRequest cannot load https://www.sandbox.paypal.com/xxxxxxxx. No 'Access-Control-Allow-> Origin' header is present on the requested resource. Origin 'http://www.example.com' is ??> therefore not allowed access.

Actually I found that if I remove the following Jquery header in my purchase.blade.php it will work normally. I am using the Controller to submit the call to paypal (Not ajax call).

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

However, I need Jquery. Any idea or workaround??

Thanks

  • This is probably a similar problem described here and well answered: http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource – Mike W Jan 06 '15 at 21:38
  • could you post the code you are executing? Did you try to set your jquery scripts to https yet? Is your own server running on HTTPS or HTTP? – danielwinter Jan 08 '15 at 10:52

1 Answers1

0

may be a little but late but I have a similar problem lately. I am using AngularJS for my front-end, and using a service to call to my CodeIgniter apis for Omnipay.

Omnipay redirects to the Sandbox but you want to return the URL to your JS or Jquery instead of redirecting immediately from CodeIgniter/Laravel/whatever server-side framework.

Solution: instead of :

  $response->redirect(), 

replace it with:

   $url = $response->getRedirectUrl();
   print_r($url);

Hence, the url is returned as a callback to your Javascript, and in your Javascript (I am using Angular JS) controller, you can load it in window.location.

 angular.module('gateway',[])
 .controller('payCtrl', function ($scope,payService,$window){
 $scope.paymentParams={};  //payment params from your form
payService.makePayment($scope.paymentParams) //send payment details to server
  .success (function (data){
   $window.location=data; // the data will be "https://www.paypal.com etc etc, which you will pass to the $window service to redirect to the location. 

  })
  .error (function (err){
   //handle error
  });
});

Hope it helps someone out there.