Skip to content

Commit

Permalink
feat:Add traffic_source for Notification Settings (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
vifer authored Oct 2, 2024
1 parent fbd7270 commit d373b56
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx&utm_medium=paddle-php-sdk) for information about changes to the Paddle Billing platform, the Paddle API, and other developer tools.

## [unreleased] - 2024-10-01

### Added

- Added `traffic_source` property to `NotificationSetting` entity
- Support notification settings `traffic_source` filter

# [1.3.1] - 2024-09-30

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ parameters:
- '#Method .+ should return .+ but returns Paddle\\SDK\\Entities\\Entity.#'
- '#Constant .+ is unused.#'
- '#Call to an undefined static method Paddle\\SDK\\PaddleEnum::Undefined\(\).#'
- '#Method Paddle\\SDK\\PaddleEnum::from\(\) should return static\(Paddle\\SDK\\PaddleEnum\) but returns MyCLabs\\Enum\\Enum<mixed>.#'
- '#Method Paddle\\SDK\\PaddleEnum::from\(\) should return static\(Paddle\\SDK\\PaddleEnum\) but returns MyCLabs\\Enum\\Enum<mixed>.#'
- '#MyCLabsMethodCallToEnumConstRector#'
2 changes: 1 addition & 1 deletion src/Entities/Adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function from(array $data): self
creditAppliedToBalance: $data['credit_applied_to_balance'] ?? null,
currencyCode: CurrencyCode::from($data['currency_code']),
status: AdjustmentStatus::from($data['status']),
items: array_map(fn (array $item) => AdjustmentItem::from($item), $data['items']),
items: array_map(fn (array $item): AdjustmentItem => AdjustmentItem::from($item), $data['items']),
totals: AdjustmentTotals::from($data['totals']),
payoutTotals: isset($data['payout_totals']) ? PayoutTotalsAdjustment::from($data['payout_totals']) : null,
createdAt: DateTime::from($data['created_at']),
Expand Down
3 changes: 3 additions & 0 deletions src/Entities/NotificationSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Paddle\SDK\Entities;

use Paddle\SDK\Entities\NotificationSetting\NotificationSettingTrafficSource;
use Paddle\SDK\Entities\NotificationSetting\NotificationSettingType;

class NotificationSetting implements Entity
Expand All @@ -28,6 +29,7 @@ private function __construct(
public bool $includeSensitiveFields,
public array $subscribedEvents,
public string $endpointSecretKey,
public NotificationSettingTrafficSource $trafficSource,
) {
}

Expand All @@ -43,6 +45,7 @@ public static function from(array $data): self
includeSensitiveFields: $data['include_sensitive_fields'],
subscribedEvents: array_map(fn (array $eventType): EventType => EventType::from($eventType), $data['subscribed_events'] ?? []),
endpointSecretKey: $data['endpoint_secret_key'],
trafficSource: NotificationSettingTrafficSource::from($data['traffic_source']),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* |------
* | ! Generated code !
* | Altering this code will result in changes being overwritten |
* |-------------------------------------------------------------|.
*/

namespace Paddle\SDK\Entities\NotificationSetting;

use Paddle\SDK\PaddleEnum;

/**
* @method static NotificationSettingTrafficSource All()
* @method static NotificationSettingTrafficSource Platform()
* @method static NotificationSettingTrafficSource Simulation()
*/
final class NotificationSettingTrafficSource extends PaddleEnum
{
private const All = 'all';
private const Platform = 'platform';
private const Simulation = 'simulation';
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function from(array $data): self
{
return new self(
transactionId: $data['transaction_id'],
items: array_map(fn (array $item) => SubscriptionAdjustmentItem::from($item), $data['items']),
items: array_map(fn (array $item): SubscriptionAdjustmentItem => SubscriptionAdjustmentItem::from($item), $data['items']),
totals: AdjustmentTotals::from($data['totals']),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Subscription/SubscriptionNextTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function from(array $data): self
billingPeriod: SubscriptionTimePeriod::from($data['billing_period']),
details: TransactionDetailsPreview::from($data['details']),
adjustments: array_map(
fn (array $adjustment) => SubscriptionAdjustmentPreview::from($adjustment),
fn (array $adjustment): SubscriptionAdjustmentPreview => SubscriptionAdjustmentPreview::from($adjustment),
$data['adjustments'],
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Paddle\SDK\Resources\NotificationSettings\Operations;

use Paddle\SDK\Entities\NotificationSetting\NotificationSettingTrafficSource;
use Paddle\SDK\HasParameters;
use Paddle\SDK\Resources\Shared\Operations\List\Pager;

Expand All @@ -12,6 +13,7 @@ class ListNotificationSettings implements HasParameters
public function __construct(
private readonly Pager|null $pager = null,
private readonly bool|null $active = null,
private readonly NotificationSettingTrafficSource|null $trafficSource = null,
) {
}

Expand All @@ -21,6 +23,7 @@ public function getParameters(): array
$this->pager?->getParameters() ?? [],
array_filter([
'active' => isset($this->active) ? ($this->active ? 'true' : 'false') : null,
'traffic_source' => $this->trafficSource?->getValue(),
]),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/PricingPreviews/Operations/PreviewPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
public readonly AddressPreview|Undefined|null $address = new Undefined(),
public readonly string|Undefined|null $customerIpAddress = new Undefined(),
) {
if (count($this->items) === 0) {
if ($this->items === []) {
throw InvalidArgumentException::arrayIsEmpty('items');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Http\Mock\Client as MockClient;
use Paddle\SDK\Client;
use Paddle\SDK\Entities\Event\EventTypeName;
use Paddle\SDK\Entities\NotificationSetting\NotificationSettingTrafficSource;
use Paddle\SDK\Entities\NotificationSetting\NotificationSettingType;
use Paddle\SDK\Environment;
use Paddle\SDK\Options;
Expand Down Expand Up @@ -205,6 +206,11 @@ public static function listOperationsProvider(): \Generator
sprintf('%s/notification-settings?active=false', Environment::SANDBOX->baseUrl()),
];

yield 'With traffic_source filter platform' => [
new ListNotificationSettings(trafficSource: NotificationSettingTrafficSource::Platform()),
sprintf('%s/notification-settings?traffic_source=platform', Environment::SANDBOX->baseUrl()),
];

yield 'With default pagination' => [
new ListNotificationSettings(
new Pager(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
},
"meta": {
"request_id": "fd55d51a-6242-4645-8572-af2a8b6f41b6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
},
{
"id": "ntfset_01gkpop8bkm3tm53itgkx6klk7",
Expand Down Expand Up @@ -202,7 +203,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "ntfset_01gkpop8bkm3tm53itgkx6klk7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "ntfset_01gkpop8bkm3tm53itgkx6klk7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
}
],
"meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
}
],
"meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "ntfset_01gkpop8bkm3tm53itgkx6klk7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "ntfset_01gkpop8bkm3tm53itgkx6klk7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
}
],
"meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
},
"meta": {
"request_id": "fd55d51a-6242-4645-8572-af2a8b6f41b6"
Expand Down

0 comments on commit d373b56

Please sign in to comment.