Skip to content

Commit 551ded5

Browse files
authored
feat!: Refactor operation names
The change prevents the need to alias when working with different resource operations. BREAKING CHANGE: All operation classes have been renamed, this will require consumer class instantiations to be updated accordingly.
1 parent 7c9b17a commit 551ded5

File tree

75 files changed

+429
-398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+429
-398
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88
99
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.
1010

11-
## 0.1.1 - 2024-01-15
11+
## [0.2.0] - 2024-01-23
12+
13+
### Changed
14+
15+
- Operations have been renamed to reduce import conflicts and the use of aliases
16+
- Unused and abandoned dependency `php-http/message-factory` was removed
17+
18+
## [0.1.1] - 2024-01-15
1219

1320
### Fixed
1421

UPGRADING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Upgrading
2+
3+
All breaking changes prior to v1 will be documented in this file to assist with upgrading.
4+
5+
## v0.2.0
6+
7+
This version includes a breaking change to the naming of operations. Prior to this version operations were commonly named `<type>Operation`, e.g. `CreateOperation` which posed problems when using more than one resource such as when creating a product and price. The new naming convention includes the resource to prevent the need of aliasing in these circumstances. e.g. `CreatePrice` and `CreateProduct`.
8+
9+
To upgrade to `0.2.0` from any earlier version you will need to refactor your use of operations to use the new names. These follow a common pattern that can be seen below:
10+
11+
`Paddle\SDK\Resources\Prices\Operations\CreateOperation` => `Paddle\SDK\Resources\Prices\Operations\CreatePrice`
12+
`Paddle\SDK\Resources\Prices\Operations\UpdateOperation` => `Paddle\SDK\Resources\Prices\Operations\UpdatePrice`
13+
`Paddle\SDK\Resources\Prices\Operations\ListOperation` => `Paddle\SDK\Resources\Prices\Operations\ListPrices`
14+
15+
There are also some operations that are unique, these are detailed below:
16+
17+
`Paddle\SDK\Resources\PricingPreviews\Operations\PreviewPricesOperation` => `Paddle\SDK\Resources\PricingPreviews\Operations\PreviewPrice`
18+
`\Paddle\SDK\Resources\Transactions\Operations\PreviewOperation` => `\Paddle\SDK\Resources\Transactions\Operations\PreviewTransaction`
19+
`\Paddle\SDK\Resources\Subscriptions\Operations\CancelOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\CancelSubscription`
20+
`\Paddle\SDK\Resources\Subscriptions\Operations\CreateOneTimeChargeOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\CreateOneTimeCharge`
21+
`\Paddle\SDK\Resources\Subscriptions\Operations\PauseOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\PauseSubscription`
22+
`\Paddle\SDK\Resources\Subscriptions\Operations\PreviewOneTimeChargeOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\PreviewOneTimeCharge`
23+
`\Paddle\SDK\Resources\Subscriptions\Operations\PreviewUpdateOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\PreviewUpdateSubscription`
24+
`\Paddle\SDK\Resources\Subscriptions\Operations\ResumeOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\ResumeSubscription`

examples/catalog_management.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
// │ Create Product │
4141
// └────────────────┘
4242
try {
43-
$product = $paddle->products->create(new Products\Operations\CreateOperation(
43+
$product = $paddle->products->create(new Products\Operations\CreateProduct(
4444
name: 'Kitten Service',
4545
taxCategory: TaxCategory::Standard,
4646
description: 'Simply an awesome product',
@@ -57,7 +57,7 @@
5757
// ┌───
5858
// │ Update Product │
5959
// └────────────────┘
60-
$update = new Products\Operations\UpdateOperation(
60+
$update = new Products\Operations\UpdateProduct(
6161
name: 'Bear Service',
6262
imageUrl: 'https://placebear.com/200/300',
6363
customData: new CustomData(['beep' => 'boop']),
@@ -76,7 +76,7 @@
7676
// │ Create Price │
7777
// └──────────────┘
7878
try {
79-
$price = $paddle->prices->create(new Prices\Operations\CreateOperation(
79+
$price = $paddle->prices->create(new Prices\Operations\CreatePrice(
8080
description: 'Bear Hug',
8181
productId: $product->id,
8282
unitPrice: new Money('1000', CurrencyCode::GBP),
@@ -101,7 +101,7 @@
101101
// ┌───
102102
// │ Update Price │
103103
// └──────────────┘
104-
$update = new Prices\Operations\UpdateOperation(
104+
$update = new Prices\Operations\UpdatePrice(
105105
description: 'One-off Bear Hug',
106106
unitPrice: new Money('500', CurrencyCode::GBP),
107107
customData: new CustomData(['beep' => 'boop']),
@@ -154,7 +154,7 @@
154154
// │ Get Products │
155155
// └──────────────┘
156156
try {
157-
$products = $paddle->products->list(new Products\Operations\ListOperation(
157+
$products = $paddle->products->list(new Products\Operations\ListProducts(
158158
includes: [ProductIncludes::Prices],
159159
statuses: [Status::Active],
160160
));

examples/event_polling.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Paddle\SDK\Exceptions\ApiError;
66
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse;
7-
use Paddle\SDK\Resources\Events\Operations\ListOperation;
7+
use Paddle\SDK\Resources\Events\Operations\ListEvents;
88
use Paddle\SDK\Resources\Shared\Operations\List\Pager;
99

1010
require __DIR__ . '/../vendor/autoload.php';
@@ -25,7 +25,7 @@
2525
$lastProcessedEventId = 'evt_01hfxx8t6ek9h399srcrp36jt3';
2626

2727
try {
28-
$events = $paddle->events->list(new ListOperation(new Pager(after: $lastProcessedEventId)));
28+
$events = $paddle->events->list(new ListEvents(new Pager(after: $lastProcessedEventId)));
2929
} catch (ApiError|MalformedResponse $e) {
3030
// Handle an error, terminate the poll
3131
var_dump($e->getMessage());

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
class Client
5353
{
54-
private const SDK_VERSION = '0.1.1';
54+
private const SDK_VERSION = '0.2.0';
5555

5656
public readonly LoggerInterface $logger;
5757
public readonly Options $options;

src/Resources/Addresses/AddressesClient.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
use Paddle\SDK\Entities\Shared\Status;
1919
use Paddle\SDK\Exceptions\ApiError;
2020
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse;
21-
use Paddle\SDK\Resources\Addresses\Operations\CreateOperation;
22-
use Paddle\SDK\Resources\Addresses\Operations\ListOperation;
23-
use Paddle\SDK\Resources\Addresses\Operations\UpdateOperation;
21+
use Paddle\SDK\Resources\Addresses\Operations\CreateAddress;
22+
use Paddle\SDK\Resources\Addresses\Operations\ListAddresses;
23+
use Paddle\SDK\Resources\Addresses\Operations\UpdateAddress;
2424
use Paddle\SDK\ResponseParser;
2525

2626
class AddressesClient
@@ -34,7 +34,7 @@ public function __construct(
3434
* @throws ApiError On a generic API error
3535
* @throws MalformedResponse If the API response was not parsable
3636
*/
37-
public function list(string $customerId, ListOperation $listOperation = new ListOperation()): AddressCollection
37+
public function list(string $customerId, ListAddresses $listOperation = new ListAddresses()): AddressCollection
3838
{
3939
$parser = new ResponseParser(
4040
$this->client->getRaw("/customers/{$customerId}/addresses", $listOperation),
@@ -64,7 +64,7 @@ public function get(string $customerId, string $id): Address
6464
* @throws ApiError\AddressApiError On an address specific API error
6565
* @throws MalformedResponse If the API response was not parsable
6666
*/
67-
public function create(string $customerId, CreateOperation $createOperation): Address
67+
public function create(string $customerId, CreateAddress $createOperation): Address
6868
{
6969
$parser = new ResponseParser(
7070
$this->client->postRaw("/customers/{$customerId}/addresses", $createOperation),
@@ -78,7 +78,7 @@ public function create(string $customerId, CreateOperation $createOperation): Ad
7878
* @throws ApiError\AddressApiError On an address specific API error
7979
* @throws MalformedResponse If the API response was not parsable
8080
*/
81-
public function update(string $customerId, string $id, UpdateOperation $operation): Address
81+
public function update(string $customerId, string $id, UpdateAddress $operation): Address
8282
{
8383
$parser = new ResponseParser(
8484
$this->client->patchRaw("/customers/{$customerId}/addresses/{$id}", $operation),
@@ -94,6 +94,6 @@ public function update(string $customerId, string $id, UpdateOperation $operatio
9494
*/
9595
public function archive(string $customerId, string $id): Address
9696
{
97-
return $this->update($customerId, $id, new UpdateOperation(status: Status::Archived));
97+
return $this->update($customerId, $id, new UpdateAddress(status: Status::Archived));
9898
}
9999
}

src/Resources/Addresses/Operations/CreateOperation.php renamed to src/Resources/Addresses/Operations/CreateAddress.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Paddle\SDK\FiltersUndefined;
1010
use Paddle\SDK\Undefined;
1111

12-
class CreateOperation implements \JsonSerializable
12+
class CreateAddress implements \JsonSerializable
1313
{
1414
use FiltersUndefined;
1515

src/Resources/Addresses/Operations/ListOperation.php renamed to src/Resources/Addresses/Operations/ListAddresses.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Paddle\SDK\HasParameters;
1010
use Paddle\SDK\Resources\Shared\Operations\List\Pager;
1111

12-
class ListOperation implements HasParameters
12+
class ListAddresses implements HasParameters
1313
{
1414
public function __construct(
1515
private readonly ?Pager $pager = null,

src/Resources/Addresses/Operations/UpdateOperation.php renamed to src/Resources/Addresses/Operations/UpdateAddress.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Paddle\SDK\FiltersUndefined;
1111
use Paddle\SDK\Undefined;
1212

13-
class UpdateOperation implements \JsonSerializable
13+
class UpdateAddress implements \JsonSerializable
1414
{
1515
use FiltersUndefined;
1616

src/Resources/Adjustments/AdjustmentsClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use Paddle\SDK\Entities\Collections\Paginator;
1818
use Paddle\SDK\Exceptions\ApiError;
1919
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse;
20-
use Paddle\SDK\Resources\Adjustments\Operations\CreateOperation;
21-
use Paddle\SDK\Resources\Adjustments\Operations\ListOperation;
20+
use Paddle\SDK\Resources\Adjustments\Operations\CreateAdjustment;
21+
use Paddle\SDK\Resources\Adjustments\Operations\ListAdjustments;
2222
use Paddle\SDK\ResponseParser;
2323

2424
class AdjustmentsClient
@@ -32,7 +32,7 @@ public function __construct(
3232
* @throws ApiError On a generic API error
3333
* @throws MalformedResponse If the API response was not parsable
3434
*/
35-
public function list(ListOperation $listOperation = new ListOperation()): AdjustmentsAdjustmentCollection
35+
public function list(ListAdjustments $listOperation = new ListAdjustments()): AdjustmentsAdjustmentCollection
3636
{
3737
$parser = new ResponseParser(
3838
$this->client->getRaw('/adjustments', $listOperation),
@@ -49,7 +49,7 @@ public function list(ListOperation $listOperation = new ListOperation()): Adjust
4949
* @throws ApiError\AdjustmentApiError On an adjustment specific API error
5050
* @throws MalformedResponse If the API response was not parsable
5151
*/
52-
public function create(CreateOperation $createOperation): Adjustment
52+
public function create(CreateAdjustment $createOperation): Adjustment
5353
{
5454
$parser = new ResponseParser(
5555
$this->client->postRaw('/adjustments', $createOperation),

0 commit comments

Comments
 (0)