Smart Payment Buttons: JavaScript error paypal is not defined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Labels:
-
PayPal HTML Buttons
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- 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.
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Change the button from Sandbox to Production in REST APIs
- Issue with Rendering Trustly Payment Button via PayPal JavaScript SDK in SDKs
- Error: "Unable to change shipping method. Please try again." in PayPal popup in REST APIs
- Need Help Upgrading to PayPal complete payments in PayPal Upgrade Community
- Venmo button not showing with Javascript SDK in Live - why, and how can I fix it? in SDKs