diff --git a/CHANGELOG.md b/CHANGELOG.md index 3022672..081ee04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ 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. +## [1.7.0] - 2024-12-11 + +### Added + +- Support for adjustment type, see [related changelog](https://developer.paddle.com/changelog/2024/refund-credit-full-total?utm_source=dx&utm_medium=paddle-php-sdk) +- Added Vietnamese Dong (`VND`) as a supported currency for payments [related changelog](https://developer.paddle.com/changelog/2024/vietnamese-dong-vnd-supported-currency?utm_source=dx&utm_medium=paddle-php-sdk) + ## [1.6.0] - 2024-12-05 ### Added diff --git a/src/Client.php b/src/Client.php index c29e4f7..5e8dadd 100644 --- a/src/Client.php +++ b/src/Client.php @@ -60,7 +60,7 @@ class Client { - private const SDK_VERSION = '1.6.0'; + private const SDK_VERSION = '1.7.0'; public readonly LoggerInterface $logger; public readonly Options $options; diff --git a/src/Entities/Adjustment.php b/src/Entities/Adjustment.php index 1494712..3391d1f 100644 --- a/src/Entities/Adjustment.php +++ b/src/Entities/Adjustment.php @@ -13,6 +13,7 @@ use Paddle\SDK\Entities\Adjustment\AdjustmentItem; use Paddle\SDK\Entities\Adjustment\AdjustmentTaxRatesUsed; +use Paddle\SDK\Entities\Adjustment\AdjustmentType; use Paddle\SDK\Entities\Shared\Action; use Paddle\SDK\Entities\Shared\AdjustmentStatus; use Paddle\SDK\Entities\Shared\AdjustmentTotals; @@ -41,6 +42,7 @@ private function __construct( public array $taxRatesUsed, public \DateTimeInterface $createdAt, public \DateTimeInterface|null $updatedAt, + public AdjustmentType $type, ) { } @@ -62,6 +64,7 @@ public static function from(array $data): self taxRatesUsed: array_map(fn (array $taxRateUsed): AdjustmentTaxRatesUsed => AdjustmentTaxRatesUsed::from($taxRateUsed), $data['tax_rates_used'] ?? []), createdAt: DateTime::from($data['created_at']), updatedAt: DateTime::from($data['updated_at']), + type: AdjustmentType::from($data['type']), ); } } diff --git a/src/Entities/Adjustment/AdjustmentType.php b/src/Entities/Adjustment/AdjustmentType.php new file mode 100644 index 0000000..4574194 --- /dev/null +++ b/src/Entities/Adjustment/AdjustmentType.php @@ -0,0 +1,17 @@ + AdjustmentTaxRatesUsed::from($taxRateUsed), $data['tax_rates_used'] ?? []), createdAt: DateTime::from($data['created_at']), updatedAt: isset($data['updated_at']) ? DateTime::from($data['updated_at']) : null, + type: isset($data['type']) ? AdjustmentType::from($data['type']) : null, ); } } diff --git a/src/Notifications/Entities/Adjustment/AdjustmentType.php b/src/Notifications/Entities/Adjustment/AdjustmentType.php new file mode 100644 index 0000000..363b728 --- /dev/null +++ b/src/Notifications/Entities/Adjustment/AdjustmentType.php @@ -0,0 +1,17 @@ + $items + * + * @throws InvalidArgumentException */ public function __construct( public readonly Action $action, - public readonly array $items, + public readonly array|Undefined $items, public readonly string $reason, public readonly string $transactionId, + public readonly AdjustmentType|Undefined $type = new Undefined(), ) { + if ($this->type === AdjustmentType::Partial() && ($this->items instanceof Undefined || empty($this->items))) { + throw InvalidArgumentException::arrayIsEmpty('items'); + } } public function jsonSerialize(): array { $items = []; - foreach ($this->items as $item) { - $items[] = [ - 'item_id' => $item->itemId, - 'type' => $item->type->getValue(), - 'amount' => $item->amount, - ]; + if (! $this->items instanceof Undefined) { + foreach ($this->items as $item) { + $items[] = [ + 'item_id' => $item->itemId, + 'type' => $item->type->getValue(), + 'amount' => $item->amount, + ]; + } } - return [ + return $this->filterUndefined([ 'action' => $this->action, 'items' => $items, 'reason' => $this->reason, 'transaction_id' => $this->transactionId, - ]; + 'type' => $this->type, + ]); } } diff --git a/tests/Functional/Resources/Adjustments/_fixtures/response/full_entity.json b/tests/Functional/Resources/Adjustments/_fixtures/response/full_entity.json index 9b8f6bf..84e0afa 100644 --- a/tests/Functional/Resources/Adjustments/_fixtures/response/full_entity.json +++ b/tests/Functional/Resources/Adjustments/_fixtures/response/full_entity.json @@ -2,6 +2,7 @@ "data": { "id": "adj_01h8c65c2ggq5nxswnnwv78e75", "action": "refund", + "type": "partial", "transaction_id": "txn_01h8bxpvx398a7zbawb77y0kp5", "subscription_id": "sub_01h8bxswamxysj44zt5n48njwh", "customer_id": "ctm_01h8441jn5pcwrfhwh78jqt8hk", diff --git a/tests/Functional/Resources/Adjustments/_fixtures/response/list_default.json b/tests/Functional/Resources/Adjustments/_fixtures/response/list_default.json index 746c380..8e777bb 100644 --- a/tests/Functional/Resources/Adjustments/_fixtures/response/list_default.json +++ b/tests/Functional/Resources/Adjustments/_fixtures/response/list_default.json @@ -3,6 +3,7 @@ { "id": "adj_01h8c65c2ggq5nxswnnwv78e75", "action": "refund", + "type": "partial", "transaction_id": "txn_01h8bxpvx398a7zbawb77y0kp5", "subscription_id": "sub_01h8bxswamxysj44zt5n48njwh", "customer_id": "ctm_01h8441jn5pcwrfhwh78jqt8hk", @@ -55,6 +56,7 @@ { "id": "adj_01h8bxezh16gm6t8rx21dx271b", "action": "credit", + "type": "partial", "credit_applied_to_balance": true, "transaction_id": "txn_01h8bx69629a16wwm9z8rjmak3", "subscription_id": "sub_01h8bx8fmywym11t6swgzba704", @@ -114,6 +116,7 @@ { "id": "adj_01h7jgzjqt2s8sab70e03ptkhv", "action": "credit", + "type": "partial", "credit_applied_to_balance": true, "transaction_id": "txn_01h7jgd9bkwjscj3ae15g5d3vs", "subscription_id": "sub_01h7ht5z5wdg9pz18jx1fagp8k", @@ -173,6 +176,7 @@ { "id": "adj_01h7jf6ptkfsc93hzc20fgf8wy", "action": "credit", + "type": "partial", "credit_applied_to_balance": true, "transaction_id": "txn_01h7je77vc1qmzxntem45ebb5q", "subscription_id": "sub_01h7ht5z5wdg9pz18jx1fagp8k", @@ -232,6 +236,7 @@ { "id": "adj_01h468w41ttb2j2bh8av74gwt1", "action": "credit", + "type": "partial", "credit_applied_to_balance": true, "transaction_id": "txn_01h468crc3b3fe98a5ft53recb", "subscription_id": "sub_01h468kv3jhs5jk330gszncsgt", diff --git a/tests/Functional/Resources/Adjustments/_fixtures/response/minimal_entity.json b/tests/Functional/Resources/Adjustments/_fixtures/response/minimal_entity.json index 3a7c419..3d8e904 100644 --- a/tests/Functional/Resources/Adjustments/_fixtures/response/minimal_entity.json +++ b/tests/Functional/Resources/Adjustments/_fixtures/response/minimal_entity.json @@ -2,6 +2,7 @@ "data": { "id": "adj_01h8c65c2ggq5nxswnnwv78e75", "action": "refund", + "type": "partial", "transaction_id": "txn_01h8bxpvx398a7zbawb77y0kp5", "subscription_id": "sub_01h8bxswamxysj44zt5n48njwh", "customer_id": "ctm_01h8441jn5pcwrfhwh78jqt8hk", diff --git a/tests/Functional/Resources/Simulations/_fixtures/request/adjustment_updated_payload.json b/tests/Functional/Resources/Simulations/_fixtures/request/adjustment_updated_payload.json index 3ec5b3d..00876c6 100644 --- a/tests/Functional/Resources/Simulations/_fixtures/request/adjustment_updated_payload.json +++ b/tests/Functional/Resources/Simulations/_fixtures/request/adjustment_updated_payload.json @@ -1,6 +1,7 @@ { "id": "adj_01hvgf2s84dr6reszzg29zbvcm", "action": "refund", + "type": "partial", "transaction_id": "txn_01hvcc93znj3mpqt1tenkjb04y", "subscription_id": "sub_01hvccbx32q2gb40sqx7n42430", "customer_id": "ctm_01hrffh7gvp29kc7xahm8wddwa", diff --git a/tests/Functional/Resources/Simulations/_fixtures/request/update_full.json b/tests/Functional/Resources/Simulations/_fixtures/request/update_full.json index d9623f3..aa9b8e6 100644 --- a/tests/Functional/Resources/Simulations/_fixtures/request/update_full.json +++ b/tests/Functional/Resources/Simulations/_fixtures/request/update_full.json @@ -6,6 +6,7 @@ "payload": { "id": "adj_01hvgf2s84dr6reszzg29zbvcm", "action": "refund", + "type": "partial", "transaction_id": "txn_01hvcc93znj3mpqt1tenkjb04y", "subscription_id": "sub_01hvccbx32q2gb40sqx7n42430", "tax_rates_used": [], diff --git a/tests/Functional/Resources/Simulations/_fixtures/response/full_entity_adjustment_updated.json b/tests/Functional/Resources/Simulations/_fixtures/response/full_entity_adjustment_updated.json index ddf035e..8b58846 100644 --- a/tests/Functional/Resources/Simulations/_fixtures/response/full_entity_adjustment_updated.json +++ b/tests/Functional/Resources/Simulations/_fixtures/response/full_entity_adjustment_updated.json @@ -8,6 +8,7 @@ "payload": { "id": "adj_01hvgf2s84dr6reszzg29zbvcm", "action": "refund", + "type": "partial", "transaction_id": "txn_01hvcc93znj3mpqt1tenkjb04y", "subscription_id": "sub_01hvccbx32q2gb40sqx7n42430", "customer_id": "ctm_01hrffh7gvp29kc7xahm8wddwa",