PHP code example of alfasix / alfakit-webhooks

1. Go to this page and download the library: Download alfasix/alfakit-webhooks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alfasix / alfakit-webhooks example snippets


use AlfaSix\AlfakitWebhooks\WebhooksPlugin;

$panel->plugin(
    WebhooksPlugin::make()
        ->events([
            'order.paid' => 'Order paid',
            'order.refunded' => 'Order refunded',
        ])
        ->modelEvents([Customer::class]) // customer.created, customer.updated, customer.deleted
        ->authorize(fn (User $user): bool => $user->is_admin),
);

use AlfaSix\AlfakitWebhooks\Webhooks;

Webhooks::dispatch('order.paid', ['order' => $order->only(['id', 'total'])]);

[$t, $v1] = /* parse "t=…,v1=…" from the X-Webhook-Signature header */;
$valid = abs(time() - $t) <= 300
    && hash_equals(hash_hmac('sha256', $t.'.'.$request->getContent(), $secret), $v1);
bash
composer vendor:publish --tag=alfakit-webhooks-migrations
php artisan migrate