PHP code example of webhook-platform / php

1. Go to this page and download the library: Download webhook-platform/php 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/ */

    

webhook-platform / php example snippets




use Railhook\Railhook;

$client = new Railhook(
    apiKey: getenv('RAILHOOK_API_KEY'),
    baseUrl: 'https://railhook.io', // default http://localhost:8080
);

$event = $client->events->send(
    type: 'order.completed',
    data: ['orderId' => 'ord_123', 'amount' => 99.99],
    idempotencyKey: 'order-123-completed', // optional
);
echo $event['eventId'], ' ', $event['deliveriesCreated'], "\n";



use Railhook\Webhook;
use Railhook\Exception\RailhookException;

try {
    $event = Webhook::constructEvent(
        file_get_contents('php://input'),
        getallheaders(),
        getenv('WEBHOOK_SECRET'),
    );
    error_log("{$event['eventId']}: " . json_encode($event['data']));
    http_response_code(200);
} catch (RailhookException $e) {
    http_response_code(400);
}
bash
composer 
bash
composer install
composer test
php scripts/live-api-smoke.php   # against a running stack (make up)