Skip to content

Commit 349485e

Browse files
authored
fix!: Adjustment mapping and model sharing
fix: Map subscription transaction adjustments fix: Remove unused subscription classes fix: Ensure Adjustment items are mapped fix!: Transaction include to use core Adjustment fix!: Refactor Adjustments and related entities - CreateAdjustment now has a write specific AdjustmentItem - Adjustment entities are shared between Adjustments and Subscriptions - AdjustmentProration - AdjustmentType - AdjustmentTimePeriod BREAKING CHANGE: See below - To create an Adjustment you must now use `\Paddle\SDK\Resources\Adjustments\Operations\Create\AdjustmentItem` - Adjustment entities sub objects now utilise shared models
1 parent 917968f commit 349485e

19 files changed

+439
-537
lines changed

src/Entities/Adjustment.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Paddle\SDK\Entities;
1313

14-
use Paddle\SDK\Entities\Adjustment\AdjustmentItemTotals;
14+
use Paddle\SDK\Entities\Adjustment\AdjustmentItem;
1515
use Paddle\SDK\Entities\Shared\Action;
1616
use Paddle\SDK\Entities\Shared\AdjustmentStatus;
1717
use Paddle\SDK\Entities\Shared\CurrencyCode;
@@ -23,7 +23,7 @@ class Adjustment implements Entity
2323
/**
2424
* @internal
2525
*
26-
* @param array<AdjustmentItemTotals> $items
26+
* @param array<AdjustmentItem> $items
2727
*/
2828
protected function __construct(
2929
public string $id,
@@ -55,7 +55,7 @@ public static function from(array $data): self
5555
creditAppliedToBalance: $data['credit_applied_to_balance'] ?? null,
5656
currencyCode: CurrencyCode::from($data['currency_code']),
5757
status: AdjustmentStatus::from($data['status']),
58-
items: $data['items'],
58+
items: array_map(fn (array $item) => AdjustmentItem::from($item), $data['items']),
5959
totals: TotalAdjustments::from($data['totals']),
6060
payoutTotals: isset($data['payout_totals']) ? PayoutTotalsAdjustment::from($data['payout_totals']) : null,
6161
createdAt: DateTime::from($data['created_at']),

src/Entities/Adjustment/AdjustmentItem.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,31 @@
1111

1212
namespace Paddle\SDK\Entities\Adjustment;
1313

14+
use Paddle\SDK\Entities\Shared\AdjustmentItemTotals;
15+
use Paddle\SDK\Entities\Shared\AdjustmentProration;
16+
use Paddle\SDK\Entities\Shared\AdjustmentType;
17+
1418
class AdjustmentItem
1519
{
1620
public function __construct(
21+
public string $id,
1722
public string $itemId,
1823
public AdjustmentType $type,
1924
public string|null $amount,
25+
public AdjustmentProration|null $proration,
26+
public AdjustmentItemTotals $totals,
2027
) {
2128
}
29+
30+
public static function from(array $data): self
31+
{
32+
return new self(
33+
id: $data['id'],
34+
itemId: $data['item_id'],
35+
type: AdjustmentType::from($data['type']),
36+
amount: $data['amount'] ?? null,
37+
proration: $data['proration'] ? AdjustmentProration::from($data['proration']) : null,
38+
totals: AdjustmentItemTotals::from($data['totals']),
39+
);
40+
}
2241
}

src/Entities/Adjustment/AdjustmentItemTotals.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Entities/Collections/SubscriptionsTransactionCollection.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Entities/Shared/AdjustmentItemTotals.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@ public function __construct(
1919
public string $total,
2020
) {
2121
}
22+
23+
public static function from(array $data): self
24+
{
25+
return new self(
26+
subtotal: $data['subtotal'],
27+
tax: $data['tax'],
28+
total: $data['total'],
29+
);
30+
}
2231
}

src/Entities/Adjustment/AdjustmentProration.php renamed to src/Entities/Shared/AdjustmentProration.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* |-------------------------------------------------------------|.
1010
*/
1111

12-
namespace Paddle\SDK\Entities\Adjustment;
12+
namespace Paddle\SDK\Entities\Shared;
1313

1414
class AdjustmentProration
1515
{
@@ -18,4 +18,12 @@ public function __construct(
1818
public AdjustmentTimePeriod $billingPeriod,
1919
) {
2020
}
21+
22+
public static function from(array $data): self
23+
{
24+
return new self(
25+
rate: $data['rate'],
26+
billingPeriod: AdjustmentTimePeriod::from($data['billing_period']),
27+
);
28+
}
2129
}

src/Entities/Adjustment/AdjustmentTimePeriod.php renamed to src/Entities/Shared/AdjustmentTimePeriod.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
* |-------------------------------------------------------------|.
1010
*/
1111

12-
namespace Paddle\SDK\Entities\Adjustment;
12+
namespace Paddle\SDK\Entities\Shared;
13+
14+
use Paddle\SDK\Entities\DateTime;
1315

1416
class AdjustmentTimePeriod
1517
{
@@ -18,4 +20,12 @@ public function __construct(
1820
public \DateTimeInterface $endsAt,
1921
) {
2022
}
23+
24+
public static function from(array $data): self
25+
{
26+
return new self(
27+
startsAt: DateTime::from($data['starts_at']),
28+
endsAt: DateTime::from($data['ends_at']),
29+
);
30+
}
2131
}

src/Entities/Adjustment/AdjustmentType.php renamed to src/Entities/Shared/AdjustmentType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* |-------------------------------------------------------------|.
1010
*/
1111

12-
namespace Paddle\SDK\Entities\Adjustment;
12+
namespace Paddle\SDK\Entities\Shared;
1313

1414
enum AdjustmentType: string
1515
{

src/Entities/Subscription/SubscriptionAdjustment.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Entities/Subscription/SubscriptionAdjustmentItem.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@
1111

1212
namespace Paddle\SDK\Entities\Subscription;
1313

14-
use Paddle\SDK\Entities\Adjustment\AdjustmentType;
1514
use Paddle\SDK\Entities\Shared\AdjustmentItemTotals;
15+
use Paddle\SDK\Entities\Shared\AdjustmentProration;
16+
use Paddle\SDK\Entities\Shared\AdjustmentType;
1617

1718
class SubscriptionAdjustmentItem
1819
{
1920
public function __construct(
2021
public string $itemId,
2122
public AdjustmentType $type,
2223
public string|null $amount,
23-
public SubscriptionProration $proration,
24+
public AdjustmentProration $proration,
2425
public AdjustmentItemTotals $totals,
2526
) {
2627
}
28+
29+
public static function from(array $data): self
30+
{
31+
return new self(
32+
itemId: $data['item_id'],
33+
type: AdjustmentType::from($data['type']),
34+
amount: $data['amount'] ?? null,
35+
proration: AdjustmentProration::from($data['proration']),
36+
totals: AdjustmentItemTotals::from($data['totals']),
37+
);
38+
}
2739
}

0 commit comments

Comments
 (0)