Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add product to subscription.items #63

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ 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]

### Added

- Added `product` to `subscription.items[]`, see [related changelog](https://developer.paddle.com/changelog/2024/subscription-items-product?utm_source=dx&utm_medium=paddle-php-sdk)

## [1.1.2] - 2024-08-23

### Fixed
Expand Down
3 changes: 3 additions & 0 deletions src/Entities/Subscription/SubscriptionItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Paddle\SDK\Entities\DateTime;
use Paddle\SDK\Entities\Price;
use Paddle\SDK\Entities\Product;

class SubscriptionItem
{
Expand All @@ -26,6 +27,7 @@ private function __construct(
public \DateTimeInterface|null $nextBilledAt,
public SubscriptionTimePeriod|null $trialDates,
public Price $price,
public Product $product,
) {
}

Expand All @@ -45,6 +47,7 @@ public static function from(array $data): self
: null,
trialDates: isset($data['trial_dates']) ? SubscriptionTimePeriod::from($data['trial_dates']) : null,
price: Price::from($data['price']),
product: Product::from($data['product']),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Paddle\SDK\Notifications\Entities\Subscription;

use Paddle\SDK\Notifications\Entities\DateTime;
use Paddle\SDK\Notifications\Entities\Product;

class SubscriptionItem
{
Expand All @@ -25,6 +26,7 @@ private function __construct(
public \DateTimeInterface|null $nextBilledAt,
public SubscriptionTimePeriod|null $trialDates,
public SubscriptionPrice $price,
public Product|null $product,
) {
}

Expand All @@ -44,6 +46,7 @@ public static function from(array $data): self
: null,
trialDates: isset($data['trial_dates']) ? SubscriptionTimePeriod::from($data['trial_dates']) : null,
price: SubscriptionPrice::from($data['price']),
product: isset($data['product']) ? Product::from($data['product']) : null,
);
}
}
25 changes: 25 additions & 0 deletions tests/Functional/Resources/Events/EventsClientTest.php
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\Environment;
use Paddle\SDK\Notifications\Entities\Product;
use Paddle\SDK\Options;
use Paddle\SDK\Resources\Events\Operations\ListEvents;
use Paddle\SDK\Resources\Shared\Operations\List\Pager;
Expand Down Expand Up @@ -77,4 +78,28 @@ public static function listOperationsProvider(): \Generator
),
];
}

/**
* @test
*/
public function list_handles_subscription_events_with_and_without_products(): void
{
$this->mockClient->addResponse(new Response(200, body: self::readRawJsonFixture('response/list_default')));
$events = $this->client->events->list(new ListEvents());
$request = $this->mockClient->getLastRequest();

self::assertInstanceOf(RequestInterface::class, $request);
self::assertEquals('GET', $request->getMethod());

$subscriptionEvents = array_values(
array_filter(
iterator_to_array($events),
fn ($event) => (string) $event->eventType === 'subscription.updated',
),
);

$subscriptionEvent = $subscriptionEvents[0];
self::assertNull($subscriptionEvent->data->items[0]->product);
self::assertInstanceOf(Product::class, $subscriptionEvent->data->items[1]->product);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,17 @@
"updated_at": "2023-11-24T14:12:05.53Z",
"trial_dates": null,
"next_billed_at": "2023-12-24T14:11:11.447004Z",
"previously_billed_at": "2023-11-24T14:11:11.447004Z"
"previously_billed_at": "2023-11-24T14:11:11.447004Z",
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
}
],
"custom_data": null,
Expand Down Expand Up @@ -2773,9 +2783,9 @@
"meta": {
"pagination": {
"per_page": 10,
"estimated_total": 5574,
"estimated_total": 10,
"next": "http://sandbox-api.paddle.com/events?per_page=10&after=evt_01hfyd0v4xppkwmjaca5xyzh5d",
"has_more": true
"has_more": false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to fix issues when iterating with foreach or using iterator_to_array()

},
"request_id": "acca7502-1eaf-4a9e-9635-c6ab9844c8a5"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
"import_meta": null,
"created_at": "2023-02-23T13:55:22.538367Z",
"updated_at": "2023-11-09T14:07:16.051528Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
},
{
Expand Down Expand Up @@ -108,6 +118,16 @@
"import_meta": null,
"created_at": "2023-06-01T13:31:12.625056Z",
"updated_at": "2023-08-30T10:34:33.862679Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@
"import_meta": null,
"created_at": "2023-02-23T13:55:22.538367Z",
"updated_at": "2023-11-09T14:07:16.051528Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
},
{
Expand Down Expand Up @@ -245,6 +255,16 @@
"import_meta": null,
"created_at": "2023-06-01T13:31:12.625056Z",
"updated_at": "2023-08-30T10:34:33.862679Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
"import_meta": null,
"created_at": "2023-02-23T13:55:22.538367Z",
"updated_at": "2024-02-08T11:33:13.906492Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
}
],
Expand Down Expand Up @@ -158,6 +168,16 @@
"import_meta": null,
"created_at": "2023-02-23T13:55:22.538367Z",
"updated_at": "2023-11-09T14:07:16.051528Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
},
{
Expand Down Expand Up @@ -195,6 +215,16 @@
"import_meta": null,
"created_at": "2023-06-01T13:31:12.625056Z",
"updated_at": "2023-08-30T10:34:33.862679Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
}
],
Expand Down Expand Up @@ -275,6 +305,16 @@
"import_meta": null,
"created_at": "2023-02-23T13:57:54.249913Z",
"updated_at": "2023-06-29T10:23:34.8239Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
}
],
Expand Down Expand Up @@ -362,6 +402,16 @@
"import_meta": null,
"created_at": "2023-02-23T13:55:22.538367Z",
"updated_at": "2023-11-09T14:07:16.051528Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
},
{
Expand Down Expand Up @@ -399,6 +449,16 @@
"import_meta": null,
"created_at": "2023-06-01T13:31:12.625056Z",
"updated_at": "2023-08-30T10:34:33.862679Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,16 @@
"import_meta": null,
"created_at": "2023-02-23T13:55:22.538367Z",
"updated_at": "2023-11-09T14:07:16.051528Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
},
{
Expand Down Expand Up @@ -517,6 +527,16 @@
"import_meta": null,
"created_at": "2023-02-23T13:59:52.159927Z",
"updated_at": "2023-05-05T08:00:09.676093Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
}
],
Expand Down
Loading