PHP code example of monkeyscloud / monkeyslegion-webhooks
1. Go to this page and download the library: Download monkeyscloud/monkeyslegion-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/ */
monkeyscloud / monkeyslegion-webhooks example snippets
use MonkeysLegion\Webhooks\WebhookManager;
$manager = $container->get(WebhookManager::class);
// Register a webhook endpoint
$manager->register('orders.created', 'https://example.com/webhook', 'secret');
// Dispatch an event to all matching webhooks
$manager->dispatch('orders.created', ['order_id' => 123, 'total' => 99.99]);
// In your routes
#[Route('POST', '/webhook/stripe')]
#[Middleware(['webhook.verify:stripe'])]
public function handleStripe(ServerRequestInterface $request): Response
{
$payload = $request->getParsedBody();
// Payload is already verified
}
use MonkeysLegion\Webhooks\WebhookSigner;
$signer = new WebhookSigner('your-secret');
$signature = $signer->sign($payload);
if ($signer->verify($payload, $signature)) {
// Verified!
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.