我在Laravel 4中使用omnipay实现Paypal Express。 状态码:302我的网站尝试重定向到paypal时找到。
错误:
XMLHttpRequest无法加载https://www.sandbox.paypal.com/xxxxxxxx。否'访问控制 - 允许 - >原产地'标头出现在请求的资源上。起源' http://www.example.com'是??>因此不允许访问。
实际上我发现如果我在purchase.blade.php中删除以下Jquery标头,它将正常工作。我正在使用Controller向paypal提交电话(不是ajax电话)。
<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>
但是,我需要Jquery。 任何想法或解决方法??
由于
答案 0 :(得分:0)
可能有点但迟到但我最近遇到了类似的问题。我正在使用AngularJS作为我的前端,并使用服务来调用我的CodeIgniter apis for Omnipay。
Omnipay会重定向到Sandbox,但您希望将URL返回到JS或Jquery,而不是立即从CodeIgniter / Laravel /任何服务器端框架重定向。
解决方案:而不是:
$response->redirect(),
将其替换为:
$url = $response->getRedirectUrl();
print_r($url);
因此,url作为Javascript的回调返回,在你的Javascript(我使用的是Angular JS)控制器中,你可以在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
});
});
希望它可以帮助那些人。