Paypal subscription webhook for recurring payment
Asked Answered
D

2

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

Devin answered 30/4, 2020 at 16:37 Comment(3)
Have any of the other things that would trigger the other events actually occurred?Langsdon
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.Devin
are these events sent to the webhook in sandbox mode?Ishii
L
9

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.

Langsdon answered 30/4, 2020 at 18:24 Comment(9)
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.Devin
What data do you get for this event?Langsdon
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.Devin
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 receivedLangsdon
the only id you get is "parent_payment".Riancho
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?Unlade
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.Fantail
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.Langsdon
Preston, you rock, thanks. Consider making a course on Paypal, I think you will do very well. :-)Fantail
C
10

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"
}
Crittenden answered 17/4, 2021 at 21:56 Comment(1)
It helps us to figure out an answer if you ask a question.Communize
L
9

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.

Langsdon answered 30/4, 2020 at 18:24 Comment(9)
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.Devin
What data do you get for this event?Langsdon
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.Devin
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 receivedLangsdon
the only id you get is "parent_payment".Riancho
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?Unlade
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.Fantail
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.Langsdon
Preston, you rock, thanks. Consider making a course on Paypal, I think you will do very well. :-)Fantail

© 2022 - 2024 — McMap. All rights reserved.