Smart Payment Buttons: JavaScript error paypal is not defined

tlemens
Contributor
Contributor

Hi there,

 

I followed the guides on https://developer.paypal.com/docs/checkout/integrate/ and integrated the buttons here.

 

Occasionally I would get the following JavaScript errors (tracked with Sentry)

 

1) ReferenceError: paypal is not defined

 

2) Error: window navigated away

 

3) Error: Order could not be captured

 

How to fix those errors?

 

Thx in advance

Login to Me Too
1 REPLY 1

josh_g1
New Community Member

I ran into a similar problem using smart buttons a few days ago( roughly January 25, 2021 ).

 

I solved the problem by following some suggestions at php - PayPal Smart Payment Buttons error paypal.Buttons is not a function - Stack Overflow


The two steps below are a more clean and concise description of the changes.

I edited 2 parts of the autogenerated code.

  1. I set  data-namespace="paypal_sdk" in the script tag so the tag looks like:

 

  <script src="https://www.paypal.com/sdk/js?client-id=your-id-goes-here" data-sdk-integration-source="button-factory" data-namespace="paypal_sdk"></script>​

 

  • I replaced paypal with paypal_sdk in: 

 

    paypal_sdk.Buttons({
      style: {
        color: 'gold',
        shape: 'rect',
        label: 'pay',
        layout: 'vertical'
      }

 


I hope paypal fixes this soon in a way that doesn't break the workaround above.

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.