10

I had set up Paypal webhooks to track the recurring payments. I had set up webhook for

  1. BILLING.SUBSCRIPTION.UPDATED
  2. BILLING.SUBSCRIPTION.RE-ACTIVATED
  3. BILLING.SUBSCRIPTION.RENEWED
  4. BILLING.SUBSCRIPTION.CANCELLED
  5. BILLING.SUBSCRIPTION.EXPIRED
  6. BILLING.SUBSCRIPTION.SUSPENDED
  7. BILLING.SUBSCRIPTION.PAYMENT.FAILED
  8. BILLING.SUBSCRIPTION.ACTIVATED

I am not getting any event apart from Activate. can anyone help me to find out the hook that I need to set up to track transactions for the recurring subscription billing?

Thanks

Vinay Sharma
  • 360
  • 3
  • 16
  • Have any of the other things that would trigger the other events actually occurred? – Preston PHX Apr 30 '20 at 17:40
  • Billing.Subscription.created also works. but I am not sure if I can test other hooks. I created a subscription yesterday and it was set up for every day but haven't got any event fired for reccuring payment. – Vinay Sharma Apr 30 '20 at 17:47

2 Answers2

8

See https://developer.paypal.com/docs/integration/direct/webhooks/event-names/#subscriptions

It looks like you want PAYMENT.SALE.COMPLETED

There is also one for refunded and reversed.

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
  • 1
    so it will also work for the first payment made. How can I get a subscription id and other data with it? So I can create the user transactions on my side. – Vinay Sharma Apr 30 '20 at 18:50
  • What data do you get for this event? – Preston PHX Apr 30 '20 at 19:15
  • I want to know what data this webhook sends to our server. Also if a subscription gets charged do I also got subscription id. I basically need the subscription id and transaction id of the payment. – Vinay Sharma Apr 30 '20 at 19:38
  • There is a webhook simulator in developer.paypal.com , if you want to use that, however the best way to know what data you will obtain for a subscription payment, specifically , is to do a test subscription payment with an active webhook subscription, and log the data received – Preston PHX Apr 30 '20 at 19:47
  • the only id you get is "parent_payment". – Divern Jul 06 '20 at 22:13
  • How did you manage to get ANY hooks? Ive ticked everything on the web hook setup screen but I still receive no events for anything. Is there a global setting that needs to be enabled or something? – Raj Jan 09 '21 at 23:30
  • How do you know if a PAYMENT.SALE.COMPLETED is a renewal? Do I have keep track in db or is there some way simpler to know. – user1889992 May 09 '23 at 18:57
  • 1
    The simplest way is usually to include something uniquely identifying the profile/user when creating the subscription, in the `custom_id` field parameter to createSubscription. This custom value is then returned in every future webhook event for the subscription. Other then that additional field to aid in reconciliation, yes keep track of everything in your own database. – Preston PHX May 09 '23 at 19:44
  • Preston, you rock, thanks. Consider making a course on Paypal, I think you will do very well. :-) – user1889992 May 09 '23 at 20:48
7

In the webhook simulator PAYMENT.SALE.COMPLETED is not fully shown, but it is correct to use when payment for a subscription is made. It also has a subscription_id (it called billing_agreement_id for some reason).

{
    "id": "WH-528005538C798144N-7H391362AP602264K",
    "create_time": "2021-04-17T22:45:35.950Z",
    "resource_type": "sale",
    "event_type": "PAYMENT.SALE.COMPLETED",
    "summary": "Payment completed for CAD 14.55 CAD",
    "resource": {
        "billing_agreement_id": "I-37B4TLL0FAJJ",
        "amount": {
            "total": "14.55",
            "currency": "CAD",
            "details": {
                "subtotal": "14.55"
            }
        },
        "payment_mode": "INSTANT_TRANSFER",
        "update_time": "2021-04-17T22:44:02Z",
        "create_time": "2021-04-17T22:44:02Z",
        "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
        "transaction_fee": {
            "currency": "CAD",
            "value": "0.72"
        },
        "protection_eligibility": "ELIGIBLE",
        "links": [
            {
                "method": "GET",
                "rel": "self",
                "href": "https://api.sandbox.paypal.com/v1/payments/sale/44P499886K055384U"
            },
            {
                "method": "POST",
                "rel": "refund",
                "href": "https://api.sandbox.paypal.com/v1/payments/sale/44P499886K055384U/refund"
            }
        ],
        "id": "44P499886K055384U",
        "state": "completed",
        "invoice_number": ""
    },
    "status": "PENDING",
    "transmissions": [
        {
            "webhook_url": "https://webhook.site/7ece4e68-de87-46df-a341-5d3dc580efe6",
            "transmission_id": "b02ef980-9fce-11eb-b0ec-5bc241fbaaf3",
            "status": "PENDING"
        }
    ],
    "links": [
        {
            "href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-528005538C798144N-7H391362AP602264K",
            "rel": "self",
            "method": "GET",
            "encType": "application/json"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-528005538C798144N-7H391362AP602264K/resend",
            "rel": "resend",
            "method": "POST",
            "encType": "application/json"
        }
    ],
    "event_version": "1.0"
}