Skip to content

Commit

Permalink
fix: Implement missing events, add readonly entity properties and add…
Browse files Browse the repository at this point in the history
…itional test coverage
  • Loading branch information
davidgrayston-paddle committed Sep 17, 2024
1 parent 009ef00 commit 7de34b3
Show file tree
Hide file tree
Showing 88 changed files with 4,990 additions and 89 deletions.
5 changes: 1 addition & 4 deletions examples/webhook_verification_PSR7.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use GuzzleHttp\Psr7\ServerRequest;
use Paddle\SDK\Entities\Event;
use Paddle\SDK\Entities\Transaction;
use Paddle\SDK\Notifications\Events\TransactionUpdated;
use Paddle\SDK\Notifications\Secret;
use Paddle\SDK\Notifications\Verifier;
Expand All @@ -32,9 +31,7 @@
$occurredAt = $event->occurredAt;

if ($event instanceof TransactionUpdated) {
/** @var Transaction $transaction */
$transaction = $event->data;
$transactionId = $transaction->id;
$transactionId = $event->transaction->id;
}
} else {
echo "Webhook is not verified\n";
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function from(array $data): self
$entity = $type[0] ?? 'Unknown';
$identifier = str_replace('_', '', ucwords(implode('_', $type), '_'));

/** @var class-string<Event> $entity */
/** @var class-string<Event> $event */
$event = sprintf('\Paddle\SDK\Notifications\Events\%s', $identifier);

if (! class_exists($event) || ! is_subclass_of($event, self::class)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/AddressCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Address $data,
public readonly Address $address,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $address, $notificationId);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/Notifications/Events/AddressImported.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Paddle\SDK\Notifications\Events;

use Paddle\SDK\Entities\Event;
use Paddle\SDK\Entities\Event\EventTypeName;
use Paddle\SDK\Notifications\Entities\Address;
use Paddle\SDK\Notifications\Entities\Entity;

final class AddressImported extends Event
{
private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
public readonly Address $address,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $address, $notificationId);
}

/**
* @param Address $data
*/
public static function fromEvent(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Entity $data,
string|null $notificationId = null,
): static {
return new self($eventId, $eventType, $occurredAt, $data, $notificationId);
}
}
4 changes: 2 additions & 2 deletions src/Notifications/Events/AddressUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Address $data,
public readonly Address $address,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $address, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/AdjustmentCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Adjustment $data,
public readonly Adjustment $adjustment,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $adjustment, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/AdjustmentUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Adjustment $data,
public readonly Adjustment $adjustment,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $adjustment, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/BusinessCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Business $data,
public readonly Business $business,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $business, $notificationId);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/Notifications/Events/BusinessImported.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Paddle\SDK\Notifications\Events;

use Paddle\SDK\Entities\Event;
use Paddle\SDK\Entities\Event\EventTypeName;
use Paddle\SDK\Notifications\Entities\Business;
use Paddle\SDK\Notifications\Entities\Entity;

final class BusinessImported extends Event
{
private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
public readonly Business $business,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $business, $notificationId);
}

/**
* @param Business $data
*/
public static function fromEvent(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Entity $data,
string|null $notificationId = null,
): static {
return new self($eventId, $eventType, $occurredAt, $data, $notificationId);
}
}
4 changes: 2 additions & 2 deletions src/Notifications/Events/BusinessUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Business $data,
public readonly Business $business,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $business, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/CustomerCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Customer $data,
public readonly Customer $customer,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $customer, $notificationId);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/Notifications/Events/CustomerImported.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Paddle\SDK\Notifications\Events;

use Paddle\SDK\Entities\Event;
use Paddle\SDK\Entities\Event\EventTypeName;
use Paddle\SDK\Notifications\Entities\Customer;
use Paddle\SDK\Notifications\Entities\Entity;

final class CustomerImported extends Event
{
private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
public readonly Customer $customer,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $customer, $notificationId);
}

/**
* @param Customer $data
*/
public static function fromEvent(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Entity $data,
string|null $notificationId = null,
): static {
return new self($eventId, $eventType, $occurredAt, $data, $notificationId);
}
}
4 changes: 2 additions & 2 deletions src/Notifications/Events/CustomerUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Customer $data,
public readonly Customer $customer,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $customer, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/DiscountCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Discount $data,
public readonly Discount $discount,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $discount, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/DiscountImported.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Discount $data,
public readonly Discount $discount,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $discount, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/DiscountUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Discount $data,
public readonly Discount $discount,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $discount, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/PayoutCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Payout $data,
public readonly Payout $payout,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $payout, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/PayoutPaid.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Payout $data,
public readonly Payout $payout,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $payout, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/PriceCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Price $data,
public readonly Price $price,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $price, $notificationId);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/Notifications/Events/PriceImported.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Paddle\SDK\Notifications\Events;

use Paddle\SDK\Entities\Event;
use Paddle\SDK\Entities\Event\EventTypeName;
use Paddle\SDK\Notifications\Entities\Entity;
use Paddle\SDK\Notifications\Entities\Price;

final class PriceImported extends Event
{
private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
public readonly Price $price,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $price, $notificationId);
}

/**
* @param Price $data
*/
public static function fromEvent(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Entity $data,
string|null $notificationId = null,
): static {
return new self($eventId, $eventType, $occurredAt, $data, $notificationId);
}
}
4 changes: 2 additions & 2 deletions src/Notifications/Events/PriceUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Price $data,
public readonly Price $price,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $price, $notificationId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/Events/ProductCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private function __construct(
string $eventId,
EventTypeName $eventType,
\DateTimeInterface $occurredAt,
Product $data,
public readonly Product $product,
string|null $notificationId,
) {
parent::__construct($eventId, $eventType, $occurredAt, $data, $notificationId);
parent::__construct($eventId, $eventType, $occurredAt, $product, $notificationId);
}

/**
Expand Down
Loading

0 comments on commit 7de34b3

Please sign in to comment.