Skip to content

Commit

Permalink
fix!: Refactor Adjustments and related entities
Browse files Browse the repository at this point in the history
- CreateAdjustment now has a write specific AdjustmentItem
- Adjustment entities are shared between Adjustments and Subscriptions
  - AdjustmentProration
  - AdjustmentType
  - AdjustmentTimePeriod

BREAKING CHANGE: To create an Adjustment you must now use `\Paddle\SDK\Resources\Adjustments\Operations\Create\AdjustmentItem`
  • Loading branch information
mikeymike committed Feb 7, 2024
1 parent 7551ef9 commit 4fff2e4
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 123 deletions.
6 changes: 3 additions & 3 deletions src/Entities/Adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Paddle\SDK\Entities;

use Paddle\SDK\Entities\Adjustment\AdjustmentItemTotals;
use Paddle\SDK\Entities\Adjustment\AdjustmentItem;
use Paddle\SDK\Entities\Shared\Action;
use Paddle\SDK\Entities\Shared\AdjustmentStatus;
use Paddle\SDK\Entities\Shared\CurrencyCode;
Expand All @@ -23,7 +23,7 @@ class Adjustment implements Entity
/**
* @internal
*
* @param array<AdjustmentItemTotals> $items
* @param array<AdjustmentItem> $items
*/
protected function __construct(
public string $id,
Expand Down Expand Up @@ -55,7 +55,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: $data['items'],
items: array_map(fn (array $item) => AdjustmentItem::from($item), $data['items']),
totals: TotalAdjustments::from($data['totals']),
payoutTotals: isset($data['payout_totals']) ? PayoutTotalsAdjustment::from($data['payout_totals']) : null,
createdAt: DateTime::from($data['created_at']),
Expand Down
19 changes: 19 additions & 0 deletions src/Entities/Adjustment/AdjustmentItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,31 @@

namespace Paddle\SDK\Entities\Adjustment;

use Paddle\SDK\Entities\Shared\AdjustmentItemTotals;
use Paddle\SDK\Entities\Shared\AdjustmentProration;
use Paddle\SDK\Entities\Shared\AdjustmentType;

class AdjustmentItem
{
public function __construct(
public string $id,
public string $itemId,
public AdjustmentType $type,
public string|null $amount,
public AdjustmentProration|null $proration,
public AdjustmentItemTotals $totals,
) {
}

public static function from(array $data): self
{
return new self(
id: $data['id'],
itemId: $data['item_id'],
type: AdjustmentType::from($data['type']),
amount: $data['amount'] ?? null,
proration: $data['proration'] ? AdjustmentProration::from($data['proration']) : null,
totals: AdjustmentItemTotals::from($data['totals']),
);
}
}
40 changes: 0 additions & 40 deletions src/Entities/Adjustment/AdjustmentItemTotals.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* |-------------------------------------------------------------|.
*/

namespace Paddle\SDK\Entities\Adjustment;
namespace Paddle\SDK\Entities\Shared;

class AdjustmentProration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* |-------------------------------------------------------------|.
*/

namespace Paddle\SDK\Entities\Adjustment;
namespace Paddle\SDK\Entities\Shared;

use Paddle\SDK\Entities\DateTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* |-------------------------------------------------------------|.
*/

namespace Paddle\SDK\Entities\Adjustment;
namespace Paddle\SDK\Entities\Shared;

enum AdjustmentType: string
{
Expand Down
7 changes: 4 additions & 3 deletions src/Entities/Subscription/SubscriptionAdjustmentItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@

namespace Paddle\SDK\Entities\Subscription;

use Paddle\SDK\Entities\Adjustment\AdjustmentType;
use Paddle\SDK\Entities\Shared\AdjustmentItemTotals;
use Paddle\SDK\Entities\Shared\AdjustmentProration;
use Paddle\SDK\Entities\Shared\AdjustmentType;

class SubscriptionAdjustmentItem
{
public function __construct(
public string $itemId,
public AdjustmentType $type,
public string|null $amount,
public SubscriptionProration $proration,
public AdjustmentProration $proration,
public AdjustmentItemTotals $totals,
) {
}
Expand All @@ -31,7 +32,7 @@ public static function from(array $data): self
itemId: $data['item_id'],
type: AdjustmentType::from($data['type']),
amount: $data['amount'] ?? null,
proration: SubscriptionProration::from($data['proration']),
proration: AdjustmentProration::from($data['proration']),
totals: AdjustmentItemTotals::from($data['totals']),
);
}
Expand Down
63 changes: 0 additions & 63 deletions src/Entities/Transaction/TransactionAdjustment.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@
* |-------------------------------------------------------------|.
*/

namespace Paddle\SDK\Entities\Transaction;
namespace Paddle\SDK\Resources\Adjustments\Operations\Create;

use Paddle\SDK\Entities\Shared\AdjustmentItemTotals;
use Paddle\SDK\Entities\Shared\Type;
use Paddle\SDK\Entities\Shared\AdjustmentType;

class TransactionAdjustmentItem
class AdjustmentItem
{
public function __construct(
public string $id,
public string $itemId,
public Type $type,
public AdjustmentType $type,
public string|null $amount,
public TransactionProration $proration,
public AdjustmentItemTotals $totals,
) {
}
}
2 changes: 1 addition & 1 deletion src/Resources/Adjustments/Operations/CreateAdjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Paddle\SDK\Resources\Adjustments\Operations;

use Paddle\SDK\Entities\Adjustment\AdjustmentItem;
use Paddle\SDK\Entities\Shared\Action;
use Paddle\SDK\Resources\Adjustments\Operations\Create\AdjustmentItem;

class CreateAdjustment implements \JsonSerializable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use GuzzleHttp\Psr7\Response;
use Http\Mock\Client as MockClient;
use Paddle\SDK\Client;
use Paddle\SDK\Entities\Adjustment\AdjustmentItem;
use Paddle\SDK\Entities\Adjustment\AdjustmentType;
use Paddle\SDK\Entities\Shared\Action;
use Paddle\SDK\Entities\Shared\AdjustmentStatus;
use Paddle\SDK\Entities\Shared\AdjustmentType;
use Paddle\SDK\Environment;
use Paddle\SDK\Options;
use Paddle\SDK\Resources\Adjustments\Operations\Create\AdjustmentItem;
use Paddle\SDK\Resources\Adjustments\Operations\CreateAdjustment;
use Paddle\SDK\Resources\Adjustments\Operations\ListAdjustments;
use Paddle\SDK\Resources\Shared\Operations\List\Pager;
Expand Down

0 comments on commit 4fff2e4

Please sign in to comment.