Paypal rest API billing agreements webhooks - paypal

So I am integrating the Paypal Rest API with my django site so I can introduce subscription based billing, so far everything is going great.
I have a interface for Billing plans, Billing agreements, Transaction history and everything to create and activate billing agreements ect.
However I need a way to be notified if a billing agreement is cancelled or a payment is made for a billing agreement so I though webhooks would be the way to go for this however I am not 100% sure that webhooks work for billing agreements?
Can anyone suggest a way I can track payments made for billing agreements or another method?

I can confirm that when a recurring payment is executed, one is notified via webhook event PAYMENT.SALE.COMPLETED as described here:
https://github.com/paypal/PayPal-Python-SDK/issues/132#issuecomment-261374087
JSON structure of the webhook event:
{
...
"resource": {
...
"billing_agreement_id": "I-38097XVV6XVU"
...
}
...
}
A list of all event names can be found here:
https://developer.paypal.com/docs/integration/direct/webhooks/event-names/

This might not be covered by paypal's webhooks notification. You can try it on sandbox and see if you get webhooks notification. Or you can use IPN, you should be able to get IPN notifications.

At this point, it seems that webhooks are not the right way to implement Paypal Recurring Payments. This is a recent Github thread where you can see how the workflow might be:
https://github.com/paypal/PayPal-REST-API-issues/issues/105
It's answered by one of the PayPal developers. Maybe we must use IPN until the webhooks development is done.

Related

What event is triggered from PayPal on successful recuring payment (for subscription)?

I have a subscription based web site where I would like to get statistics about all the current active subscribers and how many cycles they have made. This would have been easy task if the PayPal API had an endpoint for fetching all subscriptions but this is missing from their API. So I'm tracking this in our DB. I'm successfully recording the new subscriptions and the cancellations. But I'm not sure what event I should expect from PayPal to be triggered when a subscription renews.
In PayPal's documentation I have found only few events related to the subscriptions, and none of those seems to serve my needs. There are also an event called BILLING.SUBSCRIPTION.RE-ACTIVATED but it comes from "Billing plans and agreements" which is deprecated.
In SO I have found this post which advises to check for the PAYMENT.SALE.COMPLETED, but this is not perfect as I will get all sort of payments that hit this PayPal account (it is used not only for subscriptions but also for one-time payments).
It's PAYMENT.SALE.COMPLETED
For one time payments, a /v2/checkout/orders integration shouldn't trigger that same event, only the deprecated /v1/payments does AFAIK.
You can tell whether it's a subscription payment by the payload, subscription IDs begin with I-

Is the INVOICING.INVOICE.SCHEDULED automatically created?

I've implemented PayPal gateway in my application, and I'm looking for a way to send a notification to my customer when an upcoming renewal is coming.
Unfortunately in the documentation I didn't find a depth explaination about INVOICING.INVOICE.SCHEDULED but I'm guessing should be the same as invoice.upcoming of Stripe which is triggered when a recurring payment is going to be renewed.
My question is: INVOICING.INVOICE.SCHEDULED is sended by PayPal automatically when a recurring payment is going to be renewed?
Invoicing and Subscriptions are two separate PayPal products. I would not expect an Invoicing webhook in relation to a Subscription recurring payment.
The subscription webhooks are listed here: https://developer.paypal.com/docs/integration/direct/webhooks/event-names/#subscriptions
If you are looking for one that happens "in advance" of a scheduled payment, I am not aware of one.

Paypal doesn't fire webhook on BILLING.SUBSCRIPTION.CANCELLED in sandbox

I haven't tested in live, but currently I have a webhook subscribed to the following events
Billing subscription cancelled
Billing subscription created
Billing subscription re-activated
Billing subscription suspended
Billing subscription updated
I'm receiving Webhook events for CREATED but nothing is being sent when a user cancels the subscription from their PayPal dashboard.
Is this expected behavior? is there another event I should be subscribe to to capture that user action?
Is there a debug id that you can share so we can trouble shoot?
Thanks,
Usha
From Paypal support (I still don't understand why the BILLING.SUBSCRIPTION.CANCELLED doesn't fire when a user cancels from their dashboard, similar issue here: BILLING.SUBSCRIPTION.CANCELLED does not fire upon user action?)
"But surely users subscribing via the button is the most common method of subscribing (how else would they subscribe?). The IPN route seems like a completely non-developer-friendly one (seeing as there isn't even simulator events for it)"
If you integrate a solution which is not based on our REST API's and want to receive HTTP notifications, you need to use instant payment notification (IPN). The IPN simulator may not provide a method of simulating the events, but you can create subscriptions in our sandbox environment and setup a sandbox business account with IPN and test cancelling the subscriptions, which will generate an IPN for the cancellation. We have a sandbox testing guide available here if you're not familiar with that environment and want to get started.
"So why would webhooks ONLY fire for API-based subscriptions (and why would a business website subscribe users using the API rather than the simple button)? What is the logic behind this?"
It depends on the integration and needs of the individual business. Some businesses only use our REST-based API solutions for their complete integration, from checkout payments to subscriptions and logically, this makes sense to them to only have to use one set of API's for their complete integration. Other business only want / need a more simple solution such as using buttons and as these are legacy solutions which are not REST-based, they use our legacy HTTP notification service which is instant payment notification (IPN).

Paypal Payout Webhooks

I'm unable to find documentation by PayPal about how it handles webhooks for payouts. Are payouts treated the same as payments, so that a completed payout will initiate a payment completed webhook? In general, do payments and payouts translate to each other doing webhooks; or are there intricacies and gotchas someone from the paypal team could explain to me?
In a webhook perspective, the payouts transactions and sale transactions are not exactly the same thing. The payout event will be added into the webhooks supported event type list but not yet at this moment.
https://developer.paypal.com/webapps/developer/docs/integration/direct/rest-webhooks-overview/#event-type-support
So the classic IPN will still be your consideration of handling the "call-backs", for payouts and even other transaction types under RESTful API
Steps To work on payout:
go to paypal developers account and login using business account
Create new app and get client, secret etc
create some personal accounts.
Go to https://github.com/paypal/Payouts-PHP-SDK to get sample code. Update your credentials and it will work.
If you want a running code, go to https://www.voizacinc.com/ and submit inquiry. You will get working code.

Paypal IPN prior to renewal

I am setting up a Paypal IPN for a subscription service. After reviewing the documentation and speaking with Paypal, I'm still unsure as to whether the IPN feature will send out notifications before a subscription is renewed. I've got it to where it will notify a user when their account is charged for the renewal, but there is no prior notification that this transaction will take place.
Does anyone have any experience with setting this up and if it's possible?
Thanks!
IPN only notifies you when a payment is made or its status changes. For subscriptions you won't get one prior to renewal.
If you're using the Recurring Payments API, you can get that via GetRecurringPaymentsProfileDetails, which will tell you when the next billing cycle is.