6

This is the standard paypal form for buying stuff.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you@youremail.com">
<input type="hidden" name="item_name" value="Item Name">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="amount" value="0.00">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

I don't want this form, I want to do this with angularJS:

<button ng-click="checkOut()" class="btn btn-default">Buy</button>

this.checkOut = function () {
            var data = {
               ... // handle all data
            };

            $http.post('https://www.paypal.com/cgi-bin/webscr', data).success(function (data) {
                console.log("success " + data);
            }).error(function (data) {
                console.log("error " + data);
            });
        }

This gives me an error :

XMLHttpRequest cannot load https://www.paypal.com/cgi-bin/webscr. The request was redirected to 'https://www.paypal.com/home', which is disallowed for cross-origin requests that require preflight.

Any suggestions, how to do it angularJS, without the form?

Jaanus
  • 16,161
  • 49
  • 147
  • 202
  • If you want to make use of Paypal's services, you need to use their API, not just copy their code and expect it to work the same way. What are you attempting to do? – Brandon Horst May 23 '14 at 13:19

1 Answers1

3

PayPal doesn't support CORS right now so it's not possible to POST to PayPal using $http.

Gil Birman
  • 35,242
  • 14
  • 75
  • 119