Search code examples
postpaypalwebhookspaypal-sandboxcancellation

Paypal sandbox cancel webhook not working


The webhook for a subscription activation BILLING.SUBSCRIPTION.ACTIVATED in the Paypal's sandbox works very well.

Nevertheless, when I'm trying to cancel the subscription from a customer sandbox account, no webhook post is received.

It should be BILLING.SUBSCRIPTION.CANCELLED.

In fact, the status is "pending" from the sandbox admin account: enter image description here

Does it wait until the subscription's end date in order to send the cancellation? Or does it wait a few hours for safety reasons?

Here are the details from the paypal sandbox web site:

{
    "id": "WH-3BV96304FY002321K-38Y64104YL460680C",
    "create_time": "2022-07-04T17:51:34.874Z",
    "resource_type": "subscription",
    "event_type": "BILLING.SUBSCRIPTION.CANCELLED",
    "summary": "Subscription cancelled",
    "resource": {
        "quantity": "1",
        "subscriber": {
            "email_address": "[email protected]",
            "payer_id": "X3FWGFE2SAXUL",
            "name": {
                "given_name": "Anyname",
                "surname": "Walker"
            },
            "shipping_address": {
                "address": {
                    "address_line_1": "Great st 25",
                    "admin_area_2": "New York",
                    "admin_area_1": "NY",
                    "postal_code": "10002",
                    "country_code": "US"
                }
            }
        },
        "create_time": "2022-07-04T17:49:00Z",
        "plan_overridden": false,
        "shipping_amount": {
            "currency_code": "USD",
            "value": "0.0"
        },
        "start_time": "2022-07-04T17:46:51Z",
        "update_time": "2022-07-04T17:51:25Z",
        "billing_info": {
            "outstanding_balance": {
                "currency_code": "USD",
                "value": "0.0"
            },
            "cycle_executions": [
                {
                    "tenure_type": "REGULAR",
                    "sequence": 1,
                    "cycles_completed": 1,
                    "cycles_remaining": 0,
                    "current_pricing_scheme_version": 1,
                    "total_cycles": 0
                }
            ],
            "last_payment": {
                "amount": {
                    "currency_code": "USD",
                    "value": "3.99"
                },
                "time": "2022-07-04T17:49:01Z"
            },
            "failed_payments_count": 0
        },
        "links": [
            {
                "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-6BR7NSX98KLF",
                "rel": "self",
                "method": "GET",
                "encType": "application/json"
            }
        ],
        "id": "I-6BR7NSX98KLF",
        "plan_id": "P-5XR3459593FMK2CYGA",
        "status": "CANCELLED",
        "status_update_time": "2022-07-04T17:51:25Z"
    },
    "status": "PENDING",
    "transmissions": [
        {
            "webhook_url": "https://www.myapp.com/webhook",
            "http_status": 440,
            "reason_phrase": "HTTP/1.1 200 Connection established",
            "response_headers": {
                "Server": "gunicorn",
                "Connection": "keep-alive",
                "Content-Length": "5",
                "Date": "Mon, 04 Jul 2022 18:15:52 GMT",
                "Content-Type": "text/html; charset=utf-8",
                "Via": "1.1 google"
            },
            "transmission_id": "02cba350-fbc2-9abc-d537a3be4540",
            "status": "PENDING",
            "timestamp": "2022-07-04T17:52:03Z"
        }
    ],
    "links": [
        {
            "href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-3BV96304FY002321K-38Y64104YL460680C",
            "rel": "self",
            "method": "GET",
            "encType": "application/json"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-3BV96304FY002321K-38Y64104YL460680C/resend",
            "rel": "resend",
            "method": "POST",
            "encType": "application/json"
        }
    ],
    "event_version": "1.0",
    "resource_version": "2.0"
}

Solution

  • Pending means pending delivery to the subscribed webhook URL. The event ocurred, and delivery to the URL was attempted, but that URL did not respond with an HTTP 200 success message for the webhook to be marked as successfully delivered. In fact, according to the details logged in your question:

            "webhook_url": "https://www.myapp.com/webhook",
            "http_status": 440,
    

    That URL instead responded with an HTTP 440 status

    Assuming the URL is correct and that you changed it to "myapp" for this question, the issue is that you need to debug the endpoint/code at that URL so that it responds with a 200 success status when webhook deliveries are posted to it. Then their status will stop being Pending.