2

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

Lorenzo
  • 215
  • 4
  • 10

1 Answers1

3

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]

DeeDee
  • 2,641
  • 2
  • 17
  • 21
  • In this [photo](https://www.paypalobjects.com/webstatic/en_US/developer/docs/ec/overview-ec-ecapiflow.gif) summarizes the express checkout mode. In the first stage I have to call the SetExpressCheckout API. I think it does not matter whether the call from the client or server – Lorenzo Apr 24 '16 at 20:36
  • @Lorenzo I stand by what I said. Here's the documentation for this API feature: https://developer.paypal.com/webapps/developer/docs/classic/express-checkout/integration-guide/ECGettingStarted/#id084RN060BPF – DeeDee Apr 25 '16 at 03:55
  • So why if I call the address with a form I do not give any error? I do not understand. @DeeDee – Lorenzo Apr 25 '16 at 17:02