Skip to content

Commit

Permalink
feat!: Refactor operation names
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikeymike authored Jan 23, 2024
1 parent 7c9b17a commit 551ded5
Show file tree
Hide file tree
Showing 75 changed files with 429 additions and 398 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ 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.

## 0.1.1 - 2024-01-15
## [0.2.0] - 2024-01-23

### Changed

- Operations have been renamed to reduce import conflicts and the use of aliases
- Unused and abandoned dependency `php-http/message-factory` was removed

## [0.1.1] - 2024-01-15

### Fixed

Expand Down
24 changes: 24 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Upgrading

All breaking changes prior to v1 will be documented in this file to assist with upgrading.

## v0.2.0

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`.

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:

`Paddle\SDK\Resources\Prices\Operations\CreateOperation` => `Paddle\SDK\Resources\Prices\Operations\CreatePrice`
`Paddle\SDK\Resources\Prices\Operations\UpdateOperation` => `Paddle\SDK\Resources\Prices\Operations\UpdatePrice`
`Paddle\SDK\Resources\Prices\Operations\ListOperation` => `Paddle\SDK\Resources\Prices\Operations\ListPrices`

There are also some operations that are unique, these are detailed below:

`Paddle\SDK\Resources\PricingPreviews\Operations\PreviewPricesOperation` => `Paddle\SDK\Resources\PricingPreviews\Operations\PreviewPrice`
`\Paddle\SDK\Resources\Transactions\Operations\PreviewOperation` => `\Paddle\SDK\Resources\Transactions\Operations\PreviewTransaction`
`\Paddle\SDK\Resources\Subscriptions\Operations\CancelOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\CancelSubscription`
`\Paddle\SDK\Resources\Subscriptions\Operations\CreateOneTimeChargeOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\CreateOneTimeCharge`
`\Paddle\SDK\Resources\Subscriptions\Operations\PauseOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\PauseSubscription`
`\Paddle\SDK\Resources\Subscriptions\Operations\PreviewOneTimeChargeOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\PreviewOneTimeCharge`
`\Paddle\SDK\Resources\Subscriptions\Operations\PreviewUpdateOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\PreviewUpdateSubscription`
`\Paddle\SDK\Resources\Subscriptions\Operations\ResumeOperation` => `\Paddle\SDK\Resources\Subscriptions\Operations\ResumeSubscription`
10 changes: 5 additions & 5 deletions examples/catalog_management.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// │ Create Product │
// └────────────────┘
try {
$product = $paddle->products->create(new Products\Operations\CreateOperation(
$product = $paddle->products->create(new Products\Operations\CreateProduct(
name: 'Kitten Service',
taxCategory: TaxCategory::Standard,
description: 'Simply an awesome product',
Expand All @@ -57,7 +57,7 @@
// ┌───
// │ Update Product │
// └────────────────┘
$update = new Products\Operations\UpdateOperation(
$update = new Products\Operations\UpdateProduct(
name: 'Bear Service',
imageUrl: 'https://placebear.com/200/300',
customData: new CustomData(['beep' => 'boop']),
Expand All @@ -76,7 +76,7 @@
// │ Create Price │
// └──────────────┘
try {
$price = $paddle->prices->create(new Prices\Operations\CreateOperation(
$price = $paddle->prices->create(new Prices\Operations\CreatePrice(
description: 'Bear Hug',
productId: $product->id,
unitPrice: new Money('1000', CurrencyCode::GBP),
Expand All @@ -101,7 +101,7 @@
// ┌───
// │ Update Price │
// └──────────────┘
$update = new Prices\Operations\UpdateOperation(
$update = new Prices\Operations\UpdatePrice(
description: 'One-off Bear Hug',
unitPrice: new Money('500', CurrencyCode::GBP),
customData: new CustomData(['beep' => 'boop']),
Expand Down Expand Up @@ -154,7 +154,7 @@
// │ Get Products │
// └──────────────┘
try {
$products = $paddle->products->list(new Products\Operations\ListOperation(
$products = $paddle->products->list(new Products\Operations\ListProducts(
includes: [ProductIncludes::Prices],
statuses: [Status::Active],
));
Expand Down
4 changes: 2 additions & 2 deletions examples/event_polling.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Paddle\SDK\Exceptions\ApiError;
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse;
use Paddle\SDK\Resources\Events\Operations\ListOperation;
use Paddle\SDK\Resources\Events\Operations\ListEvents;
use Paddle\SDK\Resources\Shared\Operations\List\Pager;

require __DIR__ . '/../vendor/autoload.php';
Expand All @@ -25,7 +25,7 @@
$lastProcessedEventId = 'evt_01hfxx8t6ek9h399srcrp36jt3';

try {
$events = $paddle->events->list(new ListOperation(new Pager(after: $lastProcessedEventId)));
$events = $paddle->events->list(new ListEvents(new Pager(after: $lastProcessedEventId)));
} catch (ApiError|MalformedResponse $e) {
// Handle an error, terminate the poll
var_dump($e->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

class Client
{
private const SDK_VERSION = '0.1.1';
private const SDK_VERSION = '0.2.0';

public readonly LoggerInterface $logger;
public readonly Options $options;
Expand Down
14 changes: 7 additions & 7 deletions src/Resources/Addresses/AddressesClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
use Paddle\SDK\Entities\Shared\Status;
use Paddle\SDK\Exceptions\ApiError;
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse;
use Paddle\SDK\Resources\Addresses\Operations\CreateOperation;
use Paddle\SDK\Resources\Addresses\Operations\ListOperation;
use Paddle\SDK\Resources\Addresses\Operations\UpdateOperation;
use Paddle\SDK\Resources\Addresses\Operations\CreateAddress;
use Paddle\SDK\Resources\Addresses\Operations\ListAddresses;
use Paddle\SDK\Resources\Addresses\Operations\UpdateAddress;
use Paddle\SDK\ResponseParser;

class AddressesClient
Expand All @@ -34,7 +34,7 @@ public function __construct(
* @throws ApiError On a generic API error
* @throws MalformedResponse If the API response was not parsable
*/
public function list(string $customerId, ListOperation $listOperation = new ListOperation()): AddressCollection
public function list(string $customerId, ListAddresses $listOperation = new ListAddresses()): AddressCollection
{
$parser = new ResponseParser(
$this->client->getRaw("/customers/{$customerId}/addresses", $listOperation),
Expand Down Expand Up @@ -64,7 +64,7 @@ public function get(string $customerId, string $id): Address
* @throws ApiError\AddressApiError On an address specific API error
* @throws MalformedResponse If the API response was not parsable
*/
public function create(string $customerId, CreateOperation $createOperation): Address
public function create(string $customerId, CreateAddress $createOperation): Address
{
$parser = new ResponseParser(
$this->client->postRaw("/customers/{$customerId}/addresses", $createOperation),
Expand All @@ -78,7 +78,7 @@ public function create(string $customerId, CreateOperation $createOperation): Ad
* @throws ApiError\AddressApiError On an address specific API error
* @throws MalformedResponse If the API response was not parsable
*/
public function update(string $customerId, string $id, UpdateOperation $operation): Address
public function update(string $customerId, string $id, UpdateAddress $operation): Address
{
$parser = new ResponseParser(
$this->client->patchRaw("/customers/{$customerId}/addresses/{$id}", $operation),
Expand All @@ -94,6 +94,6 @@ public function update(string $customerId, string $id, UpdateOperation $operatio
*/
public function archive(string $customerId, string $id): Address
{
return $this->update($customerId, $id, new UpdateOperation(status: Status::Archived));
return $this->update($customerId, $id, new UpdateAddress(status: Status::Archived));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Paddle\SDK\FiltersUndefined;
use Paddle\SDK\Undefined;

class CreateOperation implements \JsonSerializable
class CreateAddress implements \JsonSerializable
{
use FiltersUndefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Paddle\SDK\HasParameters;
use Paddle\SDK\Resources\Shared\Operations\List\Pager;

class ListOperation implements HasParameters
class ListAddresses implements HasParameters
{
public function __construct(
private readonly ?Pager $pager = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Paddle\SDK\FiltersUndefined;
use Paddle\SDK\Undefined;

class UpdateOperation implements \JsonSerializable
class UpdateAddress implements \JsonSerializable
{
use FiltersUndefined;

Expand Down
8 changes: 4 additions & 4 deletions src/Resources/Adjustments/AdjustmentsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use Paddle\SDK\Entities\Collections\Paginator;
use Paddle\SDK\Exceptions\ApiError;
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse;
use Paddle\SDK\Resources\Adjustments\Operations\CreateOperation;
use Paddle\SDK\Resources\Adjustments\Operations\ListOperation;
use Paddle\SDK\Resources\Adjustments\Operations\CreateAdjustment;
use Paddle\SDK\Resources\Adjustments\Operations\ListAdjustments;
use Paddle\SDK\ResponseParser;

class AdjustmentsClient
Expand All @@ -32,7 +32,7 @@ public function __construct(
* @throws ApiError On a generic API error
* @throws MalformedResponse If the API response was not parsable
*/
public function list(ListOperation $listOperation = new ListOperation()): AdjustmentsAdjustmentCollection
public function list(ListAdjustments $listOperation = new ListAdjustments()): AdjustmentsAdjustmentCollection
{
$parser = new ResponseParser(
$this->client->getRaw('/adjustments', $listOperation),
Expand All @@ -49,7 +49,7 @@ public function list(ListOperation $listOperation = new ListOperation()): Adjust
* @throws ApiError\AdjustmentApiError On an adjustment specific API error
* @throws MalformedResponse If the API response was not parsable
*/
public function create(CreateOperation $createOperation): Adjustment
public function create(CreateAdjustment $createOperation): Adjustment
{
$parser = new ResponseParser(
$this->client->postRaw('/adjustments', $createOperation),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Paddle\SDK\Entities\Adjustment\AdjustmentItem;
use Paddle\SDK\Entities\Shared\Action;

class CreateOperation implements \JsonSerializable
class CreateAdjustment implements \JsonSerializable
{
/**
* @param array<AdjustmentItem> $items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Paddle\SDK\HasParameters;
use Paddle\SDK\Resources\Shared\Operations\List\Pager;

class ListOperation implements HasParameters
class ListAdjustments implements HasParameters
{
/**
* @param array<string> $ids
Expand Down
14 changes: 7 additions & 7 deletions src/Resources/Businesses/BusinessesClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
use Paddle\SDK\Entities\Shared\Status;
use Paddle\SDK\Exceptions\ApiError;
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse;
use Paddle\SDK\Resources\Businesses\Operations\CreateOperation;
use Paddle\SDK\Resources\Businesses\Operations\ListOperation;
use Paddle\SDK\Resources\Businesses\Operations\UpdateOperation;
use Paddle\SDK\Resources\Businesses\Operations\CreateBusiness;
use Paddle\SDK\Resources\Businesses\Operations\ListBusinesses;
use Paddle\SDK\Resources\Businesses\Operations\UpdateBusiness;
use Paddle\SDK\ResponseParser;

class BusinessesClient
Expand All @@ -34,7 +34,7 @@ public function __construct(
* @throws ApiError On a generic API error
* @throws MalformedResponse If the API response was not parsable
*/
public function list(string $customerId, ListOperation $listOperation = new ListOperation()): BusinessCollection
public function list(string $customerId, ListBusinesses $listOperation = new ListBusinesses()): BusinessCollection
{
$parser = new ResponseParser(
$this->client->getRaw("/customers/{$customerId}/businesses", $listOperation),
Expand Down Expand Up @@ -64,7 +64,7 @@ public function get(string $customerId, string $id): Business
* @throws ApiError\BusinessApiError On an business specific API error
* @throws MalformedResponse If the API response was not parsable
*/
public function create(string $customerId, CreateOperation $createOperation): Business
public function create(string $customerId, CreateBusiness $createOperation): Business
{
$parser = new ResponseParser(
$this->client->postRaw("/customers/{$customerId}/businesses", $createOperation),
Expand All @@ -78,7 +78,7 @@ public function create(string $customerId, CreateOperation $createOperation): Bu
* @throws ApiError\BusinessApiError On an business specific API error
* @throws MalformedResponse If the API response was not parsable
*/
public function update(string $customerId, string $id, UpdateOperation $operation): Business
public function update(string $customerId, string $id, UpdateBusiness $operation): Business
{
$parser = new ResponseParser(
$this->client->patchRaw("/customers/{$customerId}/businesses/{$id}", $operation),
Expand All @@ -94,6 +94,6 @@ public function update(string $customerId, string $id, UpdateOperation $operatio
*/
public function archive(string $customerId, string $id): Business
{
return $this->update($customerId, $id, new UpdateOperation(status: Status::Archived));
return $this->update($customerId, $id, new UpdateBusiness(status: Status::Archived));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Paddle\SDK\FiltersUndefined;
use Paddle\SDK\Undefined;

class CreateOperation implements \JsonSerializable
class CreateBusiness implements \JsonSerializable
{
use FiltersUndefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Paddle\SDK\HasParameters;
use Paddle\SDK\Resources\Shared\Operations\List\Pager;

class ListOperation implements HasParameters
class ListBusinesses implements HasParameters
{
/**
* @param array<string> $ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Paddle\SDK\FiltersUndefined;
use Paddle\SDK\Undefined;

class UpdateOperation implements \JsonSerializable
class UpdateBusiness implements \JsonSerializable
{
use FiltersUndefined;

Expand Down
14 changes: 7 additions & 7 deletions src/Resources/Customers/CustomersClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
use Paddle\SDK\Entities\Shared\Status;
use Paddle\SDK\Exceptions\ApiError;
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse;
use Paddle\SDK\Resources\Customers\Operations\CreateOperation;
use Paddle\SDK\Resources\Customers\Operations\ListOperation;
use Paddle\SDK\Resources\Customers\Operations\UpdateOperation;
use Paddle\SDK\Resources\Customers\Operations\CreateCustomer;
use Paddle\SDK\Resources\Customers\Operations\ListCustomers;
use Paddle\SDK\Resources\Customers\Operations\UpdateCustomer;
use Paddle\SDK\ResponseParser;

class CustomersClient
Expand All @@ -35,7 +35,7 @@ public function __construct(
* @throws ApiError On a generic API error
* @throws MalformedResponse If the API response was not parsable
*/
public function list(ListOperation $listOperation = new ListOperation()): CustomerCollection
public function list(ListCustomers $listOperation = new ListCustomers()): CustomerCollection
{
$parser = new ResponseParser(
$this->client->getRaw('/customers', $listOperation),
Expand Down Expand Up @@ -65,7 +65,7 @@ public function get(string $id): Customer
* @throws ApiError\CustomerApiError On a customer specific API error
* @throws MalformedResponse If the API response was not parsable
*/
public function create(CreateOperation $createOperation): Customer
public function create(CreateCustomer $createOperation): Customer
{
$parser = new ResponseParser(
$this->client->postRaw('/customers', $createOperation),
Expand All @@ -79,7 +79,7 @@ public function create(CreateOperation $createOperation): Customer
* @throws ApiError\CustomerApiError On a customer specific API error
* @throws MalformedResponse If the API response was not parsable
*/
public function update(string $id, UpdateOperation $operation): Customer
public function update(string $id, UpdateCustomer $operation): Customer
{
$parser = new ResponseParser(
$this->client->patchRaw("/customers/{$id}", $operation),
Expand All @@ -95,7 +95,7 @@ public function update(string $id, UpdateOperation $operation): Customer
*/
public function archive(string $id): Customer
{
return $this->update($id, new UpdateOperation(status: Status::Archived));
return $this->update($id, new UpdateCustomer(status: Status::Archived));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Paddle\SDK\FiltersUndefined;
use Paddle\SDK\Undefined;

class CreateOperation implements \JsonSerializable
class CreateCustomer implements \JsonSerializable
{
use FiltersUndefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Paddle\SDK\HasParameters;
use Paddle\SDK\Resources\Shared\Operations\List\Pager;

class ListOperation implements HasParameters
class ListCustomers implements HasParameters
{
/**
* @param array<string> $ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Paddle\SDK\FiltersUndefined;
use Paddle\SDK\Undefined;

class UpdateOperation implements \JsonSerializable
class UpdateCustomer implements \JsonSerializable
{
use FiltersUndefined;

Expand Down
Loading

0 comments on commit 551ded5

Please sign in to comment.