Can't retrieve events of Paypal webhook

Viewed 312

I'm trying to implement a Paypal Webhook. I need an event every time a user paid with Paypal for a product.

enter image description here

I created a webhook linked to the "PAYEMENT.SALE.COMPLETED" event.

And this is my handleWebHook.php file on my server:

<?php
include "vendor/autoload.php";

use PayPal\Api\Webhook;
use PayPal\Api\WebhookEvent;
use PayPal\Api\WebhookEventType;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\ApiContext;

$apiContext = new ApiContext(
    new OAuthTokenCredential(
        'my client id',     // ClientID
        'my client secret'      // ClientSecret
    )
);
$apiContext->setConfig(
    array(
        'log.LogEnabled' => true,
        'log.FileName' => 'PayPal.log',
        'log.LogLevel' => 'DEBUG'
    )
);

$params = array(
);

// ### Search Webhook events
try {
    $output = WebhookEvent::all($params, $apiContext);
} catch (Exception $ex) {
    exit(1);
}

//ResultPrinter::printResult("Search Webhook events", "WebhookEventList", null, $params, $output);

$log  = "Datas: " . print_r($output) . "  " . date("F j, Y, g:i a").PHP_EOL.
    "-------------------------".PHP_EOL;
file_put_contents('./log_'.date("j.n.Y").'.log', $log, FILE_APPEND);

I tried to simulate webhook event with the API call https://api.sandbox.paypal.com/v1/notifications/simulate-event and with the online webhook simulator.

It seems to work in both ways, the result of the API call is a 202 Accepted with a lot of infirmation in the body including

"resource_type": "sale",
"event_type": "PAYMENT.SALE.COMPLETED",
"summary": "A successful sale payment was made for $ 0.48 USD", 

But I can't retrieve those events on my listener, my logs are empty and even if I manually go to the handleWebHook.php page on a browser, I got

PayPal\Api\WebhookEventList Object ( [_propMap:PayPal\Common\PayPalModel:private] => Array ( [events] => Array ( ) [count] => 0 ) )

witch mean there are no event.

I also tried the https://api.sandbox.paypal.com/v1/notifications/webhooks-events API call, but I've got the same result

{
    "events": [],
    "count": 0
}

in the request response body.

Why can't I retrieve the event on my listener ?

0 Answers
Related