-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: New example of how to verify a webhook when framework does not …
…support PSR7 (#53)
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
* @PaddleHQ/dx | ||
* @PaddleHQ/developer-experience |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |