4

I'm using PayPal webhooks to get subscription information automatically.

However, we have to wait about 20 seconds between the payment and the subscription activation.

Is it because of the sandbox environment? Is the production environment faster?

This is important because the customers have to wait and if waiting time could be avoided, it would be better.

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
NicolasSens
  • 117
  • 1
  • 9

1 Answers1

8

The sandbox is slower in general, but you will need to test yourself in live -- and the speed of asynchronous notifications vary in different conditions.

If you need a faster notification, what you can do is have the client-side onApprove event call your server (with a JS fetch similar to this demo, plus a body payload if desired), and have the server route that handles that fetch use the Subscriptions API to get the status of the subscription, and see whether it is in fact active in that API response direct from PayPal.

Such a client-side trigger of a server route would happen in parallel to waiting for the webhook notification, so whichever completes first will mark the subscription as active in your records. This way you are not relying on either the client-side trigger nor waiting for the webhook, but rather whichever happens first.

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
  • Brilliant. This should be considered as the best answer. – lsmpascal Aug 10 '22 at 13:19
  • @PrestonPHX So basically we are checking the BILLING.SUBSCRIPTION.ACTIVATED to ensure that the subscription has been activated from the client side? My only problem is that I have a kindergarten level of knowledge when it comes to javascript :( – Cavalier Jul 18 '23 at 01:33
  • No, it does not involve that webhook, and the client-side portion is simple, even as simple as a redirect. – Preston PHX Jul 18 '23 at 02:25
  • @PrestonPHX Sorry for all the questions. Still trying to wrap my head around all of this. From the client side, it does a fetch thing to my api and I send a request to paypal to get the subscription details. And I am looking for status "ACTIVE"?? Doesn't the webhook "BILLING.SUBSCRIPTION.ACTIVATED ,that I receive quickly from the webhook, give me the status that the subscription was activated? And If I understand it correctly, an active status does not mean the payment was successful though, correct? – Cavalier Jul 19 '23 at 04:27
  • If you want to wait for webhooks in all cases, fine. Do that. You're the one saying it's not fast enough. The first payment of a subscription does not happen immediately on approval, therefore the webhook for this payment event will not occur at that moment either, not until the event takes place. – Preston PHX Jul 19 '23 at 09:03