onApprove not called workarounds


I capture order details and save them when onApprove is fired.  Sometimes the user closes the tab soon after paying, and we get the payment but not the full order details.  This is evidently a well-known problem.  My workaround is to add an onbeforeunload event to pop up the standard 'Stay on Page/Leave page' confirmation box.

This event is enabled when the PayPal buttons are displayed, and disabled after onApprove fires.

My question is whether the time when it is active can be refined.  Specifically, is there a way to be notified when the user completes payment, or when they close the PayPal popup window without paying?

Login to Me Too


Hello @adrianhb1 

Thank you for posting to the PayPal Community.

There are a few reasons that OnApprove may not be responding, one is having an alert() in the OnApprove function. Some browsers will block the alert and the OnApprove functions at the same time, so if you have an alert, make certain to remove it.


To ensure that you receive notifications about a payment, even if the buyer closes the browser before returning to your website, subscribe to webhooks. Webhooks will notify your server for a variety of events, such as the order being created, payment declines, payment successes, to name a few.


Here is the documentation on webhooks:



Here is the integration documentation:



Here is how to subscribe to events:



These are the different events you can subscribe to:



All webhook events (except using the simulator) are recorded in the webhooks dashboard:



If you would like to test webhooks, you can use sandbox or the webhooks simulator:



You can use https://webhook.site to create a test webhook listener so you can test webhooks in Sandbox/Simulator to see if it will work for you.


Unlike Instant Payment notifications, webhooks will only be sent for events for which you choose to subscribe. This will ensure that only the notifications that you choose will be received.


Thank you,




Login to Me Too


Thank you Jennifer


I thought about webhooks, but the problem is that the order details are saved as browser context.  A webhook call will not have access to this, so I'm in the same position of possibly having to store the order details when the user clicks the PayPal button, and being aware that they may well not continue to purchase.


So currently I have a bold banner asking the user not to close the window, and a "Stay on page/Leave page confirmation" if they do.  So far there have been no more occurrences.



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.