Search code examples
phppaypalwebhookspaypal-rest-sdk

What webhook event should I listen for when a recurring payment has been made


I'm using Paypal's REST-API to create billing agreements.

It's rather convoluted surrounding recurring payments and I need to discover which webhook event I should be listening for when a recurring payment has been made as at that point I need to increment the amount of days left a respective account has.

Reference: https://developer.paypal.com/docs/integration/direct/webhooks/event-names/


Solution

  • The event name I was looking for was PAYMENT.SALE.COMPLETED to make sure it's from a Billing Agreement for recurring payments check for the existence of billing_agreement_id

    eg

    $data = json_decode(file_get_contents("php://input"), true);
    $data = $data['resource'];
    
    if (!array_key_exists('billing_agreement_id', $data)) {
        // Not a payment for a billing agreement
        // handle single payments or:
        die();
    }