phpexact-onlinepicqer-exact-php-client

How to subscribe with Exact Online Webhooks


I can able to subscribe webhook using exact online API,i am not able to get response to CallbackURL from webhook notification.

I subscribed using below request:

$subscription = new \Picqer\Financials\Exact\WebhookSubscription($connection);
$subscription->deleteSubscriptions();
$subscription->CallbackURL = $callback;
$subscription->Topic = $topic;
$subscription->save(); 

Please give me suggestion to get webhook notification through exact online php API.


Solution

  • After successfully registering of webhook.

    I found the solution how to handle request in CallbackURL.

    $input = file_get_contents('php://input');
    

    you will get json response.

    follow below example you can able to validate your webhook response.

    $requestContent= file_get_contents('php://input');  // (this is json response)
    $webhookSecret='XXXXXXXXXXXXXXXX'; //your webhook Secret key
    
    $returnvalue=authenticate($requestContent,$webhookSecret); // this will get either true/false
    function authenticate($requestContent, $webhookSecret)
        {
            $matches = [];
            $matched = preg_match('/^{"Content":(.*),"HashCode":"(.*)"}$/', $requestContent, $matches);
    
            if ($matched === 1 && isset($matches[1]) && isset($matches[2])) {
                return $matches[2] === strtoupper(hash_hmac('sha256', $matches[1], $webhookSecret));
            }
            return false;
        }
    

    enter image description here