Paypal Access-Control-Allow-Origin

こ雲淡風輕ζ 提交于 2020-01-06 04:13:18

问题


I'm trying to learn paypal payment. I have done a simple AngularJS application that use Paypal-Express-Checkout. As it says on the documentation, first of all I have to do the call SetExpressCheckout.

$http.post("https://api-3t.sandbox.paypal.com/nvp", request)
.success(function(data){
    console.log(data);
}).error(function(error){
    console.log(error);
});

In the object request there are all payment details. But when I run the script, the result of http call is: XMLHttpRequest cannot load https://api-3t.sandbox.paypal.com/nvp. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. I tried to search this error, but I find nothing. How can I solve?

UPDATE: If the request comes from a form does not give me any error but if it come from http.post function it give me an error


回答1:


You have to perform your Paypal transaction on the back end, and the message you're seeing is Paypal enforcing that notion. See this article on CORS for more info.

Your angular http call should be sending the basic transaction info to your server, which will then construct an API request for Paypal, handle the response from Paypal, and then convey that information for consumption by the client side.

[edited to add more info about CORS]



来源:https://stackoverflow.com/questions/36828320/paypal-access-control-allow-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!