0

From a developer perspective, what is the best way to capture (webhook wise) a user cancelling their PayPal subscription via their dashboard (and/or subscription payment failing)?

I've had some discussions with PayPal support and have learnt the following:

Subscription button:

-simple, elegant, works well to let user subscribe

-however, when user cancels subscription via their dashboard does NOT fire a BILLING.SUBSCRIPTION.CANCELLED webhook. Only an IPN HTTP "webhook" gets fired. From the paypal docs, IPN seems harder to integrate (not REST, and for example the IPN simulator doesn't even have "subscription cancellation" events)

Using API (PayPal PHP SDK):

-DOES fire BILLING.SUBSCRIPTION.CANCELLED webhook events when user cancels their subscription via their PayPal dashboard (why this doesn't work for button-created subscriptions I do not understand)

-However, seems much more complex to set up than the button (what does the web flow look like?)

Just some thoughts on the best approach would be appreciated.

gvanto
  • 1,936
  • 3
  • 21
  • 26

1 Answers1

0

It depends on the type of 'Subscribe' button.

Legacy 'Subscribe' buttons created via e.g. https://www.paypal.com/buttons , will not fire a BILLING.SUBSCRIPTION.CANCELLED webhook. Those buttons predate webhooks by 10 years, and only use the very old IPN service. Stay away...

Current smart subscribe buttons, created via e.g. https://www.paypal.com/billing/plans or following the documentation do trigger the BILLING.SUBSCRIPTION.CANCELLED webhook.

In general, you can make use of the CANCELLED webhook and track this status if you want to but it's not necessary. The most important best practice is to make use of PAYMENT.SALE.COMPLETED and record when a subscription was last actually successfully paid for. If it doesn't get paid for again on time, then it's lapsed and you treat it accordingly.

When creating a subscription, along with the plan_id you can pass a custom_id which will be returned in all the webhooks. This can be useful for reconciliation purposes so you know which user it's for.

Using API (PayPal PHP SDK):

That SDK is deprecated, don't use it. Any API calls should be done directly via HTTPS.

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
  • Thanks @Preston PHX, I have created the smart button, set up the webhooks in the developer application setting (sandbox) as per the docs, but not receiving any webhook notifications (when a sandbox buyer subscribes + cancels their subscription via their paypal dashboard). I have done a webhook simulator event (for payment completed: https://developer.paypal.com/developer/webhooksSimulator/) and that DOES come through, so the target URL for the webhook is correct. Have checked Paypal Status (https://www.paypal-status.com/product/sandbox) everything says functional... ( ? ) – gvanto Feb 25 '22 at 11:29
  • Simulator aside, what actual webhook events do you receive? Have you subscribed to all webhook events for the client id ? – Preston PHX Feb 25 '22 at 17:20
  • Hi Preston PHX, I am not receiving ANY webhook events. I've subscribed to "Payment sale completed" (which should fire when buyer subscribes) and "Billing subscription cancelled" (which should fire when buyer cancels their subscription via their Paypal dashboard). – gvanto Feb 27 '22 at 11:32
  • Are you sure you subscribed with the correct client ID? You'll need to contact PayPal for support if you're doing everything correctly, but the simplest explanation is that something is being done wrong – Preston PHX Feb 27 '22 at 11:50
  • I've set up the application (https://developer.paypal.com/developer/applications), then logged in with the associated seller account, set up the subscription plan and created the smart button, placed it on the development site. Then subscribed using the (test/sandbox) buyer account - all works. However, no webhook events received for the webhooks created under the above sandbox application...I've contacted paypal support (with all login info) and they simply claim "it is working on our end" ...so I'm kind of at a dead-end and pulling hair out here lol – gvanto Feb 27 '22 at 12:23
  • If it is "working on their end", have you the provided you with a log of a sent webhook? It should be visible in the Dashboard webhook event viewer, too, if it is indeed "working". Provide evidence of subscribing to webhooks and created sandbox transactions, and ask for a log of the sent webhook. – Preston PHX Feb 27 '22 at 13:28
  • Hi Preston PHX, yes support guy has provided a screenshot of the log of webhook events (https://developer.paypal.com/developer/dashboard/webhooks/sandbox) - and they seem to be working. But, this is for his own (test) account, not my account. And my account is showing nothing on the list of webhook events. I have followed the steps exactly as per the docs. – gvanto Feb 28 '22 at 07:42
  • Another test account is not relevant, _your_ account's subscription to and sending of webhooks needs to be troubleshooted by PayPal support – Preston PHX Feb 28 '22 at 09:34
  • Thanks Preston PHX, I've provided them with all login info to hopefully conduct a test...will let you know how it goes! – gvanto Feb 28 '22 at 16:49