Skip to content

Commit

Permalink
Add Notification::fromRequest method
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston-paddle committed Sep 13, 2024
1 parent f50c00b commit 5bc39dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions examples/webhook_verification_PSR7.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
if ($isVerified) {
echo "Webhook is verified\n";

$data = json_decode((string) $request->getBody(), true, JSON_THROW_ON_ERROR);
$notification = Notification::from($data);
$notification = Notification::fromRequest($request);
$id = $notification->id;
$event = $notification->event;
$eventId = $event->eventId;
Expand Down
10 changes: 10 additions & 0 deletions src/Notifications/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Paddle\SDK\Entities\Event;
use Paddle\SDK\Notifications\Entities\Entity;
use Psr\Http\Message\ServerRequestInterface;

class Notification implements Entity
{
Expand All @@ -22,4 +23,13 @@ public static function from(array $data): self
Event::from($data),
);
}

public static function fromRequest(ServerRequestInterface $request): self
{
return self::from(json_decode(
(string) $request->getBody(),
true,
JSON_THROW_ON_ERROR,
));
}
}

0 comments on commit 5bc39dc

Please sign in to comment.