Handle buyer errors

DocsCurrentAdvancedLast updated: May 24th 2023, @ 8:14:20 pm


Handle buyer errors to provide a unique buyer experience.

Know before you code

  • These capabilities modify an existing checkout integration.
  • Complete the steps in Get started to get the following sandbox account information from the Developer Dashboard:
    • Your sandbox account login information
    • Your access token
  • These client-side and server-side integration capabilities use the following:

Handle errors

These procedures apply to standard and advanced integrations.

Buyer checkout error

If an error prevents buyer checkout, alert the user that an error has occurred with the buttons using the onError callback:

paypal.Buttons({
  onError: function (err) {
    // For example, redirect to a specific error page
    window.location.href = "/your-error-page-here";
  }
}).render('#paypal-button-container');

This error handler is a catch-all. Errors at this point are not expected to be handled beyond showing a generic error message or page.

Script not loading error

If null pointer errors prevent the script from loading, provide a different checkout experience:

if (window.paypal && window.paypal.Buttons) {
  // render the buttons
} else {
  // show a fallback experience
}