xtempore
xtempore

Reputation: 5505

How to fix error 400 loading PayPal SDK JS

I'm trying to integrate with PayPal and can't get the sdk/js to load.

I literally pared this back to their example code, and it still gives an HTTP error 400 loading the SDK js. Following steps as given here... https://developer.paypal.com/docs/subscriptions/integrate/#4-create-a-subscription

<!DOCTYPE html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>

<body>
<script
        src="https://www.paypal.com/sdk/js?client-id=AeRCvNJjX_wuV8I8KnIxllYZhizA7I3JZBzQJk4O2q8DoC1ORE9GZM1S1wJd2ch7XZWfsG3GHAYIUWhc&vault=true">
</script>

<div id="paypal-button-container"></div>

<script>
    paypal.Buttons({
        createSubscription: function(data, actions) {
            return actions.subscription.create({
                'plan_id': 'P-3S4679857D7841235LUOV5VY'
            });
        },

        onApprove: function(data, actions) {
            alert('You have successfully created subscription ' + data.subscriptionID);
        }
    }).render('#paypal-button-container');
</script>
</body>
</html>

The SDK js doesn't load. Looking at the response I can see an HTTP error 400 on the sdk/js request, and a paypal-debug-id value.

I've checked and rechecked that I'm passing the correct client-id.

FWIW: I noticed that in some of their other button examples you can use "sb" in place of your client id. If I use just client-id=sb, it shows a payment button, but if I include "&value=true" or use my actual client-id it goes back to error 404.

Upvotes: 6

Views: 6189

Answers (3)

Rasim SEN
Rasim SEN

Reputation: 21

in my case, I removed some of the initialOptions parameters, and then it worked. I think that PayPal docs and example project is not the updated one anymore

Upvotes: 0

deadcoder0904
deadcoder0904

Reputation: 8683

I faced the same error.

In my case, I accidentally clicked on a link & it opened up & said:

throw new Error("SDK Validation error: 'Query parameter buyer-country disallowed in production env'" );

It is hilarious how this wasted an hour of my time. Wish, the error could've been in Network tab. It wasn't. I only found by accident.

Upvotes: 3

xtempore
xtempore

Reputation: 5505

After beating my head against the wall on this for hours, I finally stumbled across the answer in the PayPal forums. Turns out to be some sort of issue with cookies. Clearing all the cookies related to PayPal seems to have fixed the problem.

Leaving this question here in case it helps someone else avoid the headaches it gave me!

Upvotes: 4

Related Questions