Skip to content

Commit

Permalink
Docs: New example of how to verify a webhook when framework does not …
Browse files Browse the repository at this point in the history
…support PSR7 (#53)
  • Loading branch information
vifer authored May 1, 2024
1 parent bb0339f commit 9549153
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @PaddleHQ/dx
* @PaddleHQ/developer-experience
26 changes: 26 additions & 0 deletions examples/webhook_verification_PSR7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

require 'vendor/autoload.php';

/*
* Verify a webhook request using PSR-7 when using a framework that does not support PSR-7.
* Only requirement is to install guzzlehttp/psr7 package `composer require guzzlehttp/psr7`
* @see https://developer.paddle.com/webhooks/signature-verification#verify-sdks?utm_source=dx&utm_medium=paddle-php-sdk
*/

use GuzzleHttp\Psr7\ServerRequest;
use Paddle\SDK\Notifications\Secret;
use Paddle\SDK\Notifications\Verifier;

// Create a PSR-7 compliant request object using the global variables, You don't need this line if you are using a framework that supports PSR-7
$request = ServerRequest::fromGlobals();

$isVerified = (new Verifier())->verify($request, new Secret('WEBHOOK_SECRET_KEY'));

if ($isVerified) {
echo "Webhook is verified\n";
} else {
echo "Webhook is not verified\n";
}

0 comments on commit 9549153

Please sign in to comment.