diff --git a/CHANGELOG.md b/CHANGELOG.md index 1de8048..0ea8a72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ 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.8.0] - 2024-12-19 + +### Added + +- Added `on_resume` support to subscription resume and pause operations + ## [1.7.2] - 2024-12-17 ### Fixed diff --git a/src/Client.php b/src/Client.php index 4a49986..5aff702 100644 --- a/src/Client.php +++ b/src/Client.php @@ -60,7 +60,7 @@ class Client { - private const SDK_VERSION = '1.7.2'; + private const SDK_VERSION = '1.8.0'; public readonly LoggerInterface $logger; public readonly Options $options; diff --git a/src/Entities/Subscription/SubscriptionOnResume.php b/src/Entities/Subscription/SubscriptionOnResume.php new file mode 100644 index 0000000..7e69622 --- /dev/null +++ b/src/Entities/Subscription/SubscriptionOnResume.php @@ -0,0 +1,24 @@ +filterUndefined([ 'effective_from' => $this->effectiveFrom, 'resume_at' => isset($this->resumeAt) ? DateTime::from($this->resumeAt)?->format() : null, - ]; + 'on_resume' => $this->onResume, + ]); } } diff --git a/src/Resources/Subscriptions/Operations/ResumeSubscription.php b/src/Resources/Subscriptions/Operations/ResumeSubscription.php index b81e5eb..52577f3 100644 --- a/src/Resources/Subscriptions/Operations/ResumeSubscription.php +++ b/src/Resources/Subscriptions/Operations/ResumeSubscription.php @@ -5,21 +5,28 @@ namespace Paddle\SDK\Resources\Subscriptions\Operations; use Paddle\SDK\Entities\DateTime; +use Paddle\SDK\Entities\Subscription\SubscriptionOnResume; use Paddle\SDK\Entities\Subscription\SubscriptionResumeEffectiveFrom; +use Paddle\SDK\FiltersUndefined; +use Paddle\SDK\Undefined; class ResumeSubscription implements \JsonSerializable { + use FiltersUndefined; + public function __construct( public readonly SubscriptionResumeEffectiveFrom|\DateTimeInterface|null $effectiveFrom = null, + public readonly SubscriptionOnResume|Undefined $onResume = new Undefined(), ) { } public function jsonSerialize(): array { - return [ + return $this->filterUndefined([ 'effective_from' => $this->effectiveFrom instanceof \DateTimeInterface ? DateTime::from($this->effectiveFrom)?->format() : $this->effectiveFrom, - ]; + 'on_resume' => $this->onResume, + ]); } } diff --git a/tests/Functional/Resources/Subscriptions/SubscriptionsClientTest.php b/tests/Functional/Resources/Subscriptions/SubscriptionsClientTest.php index 034eb53..1787172 100644 --- a/tests/Functional/Resources/Subscriptions/SubscriptionsClientTest.php +++ b/tests/Functional/Resources/Subscriptions/SubscriptionsClientTest.php @@ -24,6 +24,7 @@ use Paddle\SDK\Entities\Subscription\SubscriptionNonCatalogPriceWithProduct; use Paddle\SDK\Entities\Subscription\SubscriptionNonCatalogProduct; use Paddle\SDK\Entities\Subscription\SubscriptionOnPaymentFailure; +use Paddle\SDK\Entities\Subscription\SubscriptionOnResume; use Paddle\SDK\Entities\Subscription\SubscriptionProrationBillingMode; use Paddle\SDK\Entities\Subscription\SubscriptionResumeEffectiveFrom; use Paddle\SDK\Entities\Subscription\SubscriptionScheduledChangeAction; @@ -355,6 +356,18 @@ public static function pauseOperationsProvider(): \Generator new Response(200, body: self::readRawJsonFixture('response/full_entity')), self::readRawJsonFixture('request/pause_full'), ]; + + yield 'On resume continue existing billing period' => [ + new PauseSubscription(SubscriptionEffectiveFrom::Immediately(), new \DateTime('2023-10-09T16:30:00Z'), SubscriptionOnResume::ContinueExistingBillingPeriod()), + new Response(200, body: self::readRawJsonFixture('response/full_entity')), + self::readRawJsonFixture('request/pause_resume_existing_billing_period'), + ]; + + yield 'On resume start new billing period' => [ + new PauseSubscription(SubscriptionEffectiveFrom::Immediately(), new \DateTime('2023-10-09T16:30:00Z'), SubscriptionOnResume::StartNewBillingPeriod()), + new Response(200, body: self::readRawJsonFixture('response/full_entity')), + self::readRawJsonFixture('request/pause_resume_new_billing_period'), + ]; } /** @@ -399,6 +412,18 @@ public static function resumeOperationsProvider(): \Generator new Response(200, body: self::readRawJsonFixture('response/full_entity')), self::readRawJsonFixture('request/resume_single_as_date'), ]; + + yield 'On resume continue existing billing period' => [ + new ResumeSubscription(SubscriptionResumeEffectiveFrom::Immediately(), SubscriptionOnResume::ContinueExistingBillingPeriod()), + new Response(200, body: self::readRawJsonFixture('response/full_entity')), + self::readRawJsonFixture('request/resume_existing_billing_period'), + ]; + + yield 'On resume start new billing period' => [ + new ResumeSubscription(SubscriptionResumeEffectiveFrom::Immediately(), SubscriptionOnResume::StartNewBillingPeriod()), + new Response(200, body: self::readRawJsonFixture('response/full_entity')), + self::readRawJsonFixture('request/resume_new_billing_period'), + ]; } /** diff --git a/tests/Functional/Resources/Subscriptions/_fixtures/request/pause_resume_existing_billing_period.json b/tests/Functional/Resources/Subscriptions/_fixtures/request/pause_resume_existing_billing_period.json new file mode 100644 index 0000000..f741b5b --- /dev/null +++ b/tests/Functional/Resources/Subscriptions/_fixtures/request/pause_resume_existing_billing_period.json @@ -0,0 +1,5 @@ +{ + "effective_from": "immediately", + "resume_at": "2023-10-09T16:30:00.000000Z", + "on_resume": "continue_existing_billing_period" +} diff --git a/tests/Functional/Resources/Subscriptions/_fixtures/request/pause_resume_new_billing_period.json b/tests/Functional/Resources/Subscriptions/_fixtures/request/pause_resume_new_billing_period.json new file mode 100644 index 0000000..f9eb5a5 --- /dev/null +++ b/tests/Functional/Resources/Subscriptions/_fixtures/request/pause_resume_new_billing_period.json @@ -0,0 +1,5 @@ +{ + "effective_from": "immediately", + "resume_at": "2023-10-09T16:30:00.000000Z", + "on_resume": "start_new_billing_period" +} diff --git a/tests/Functional/Resources/Subscriptions/_fixtures/request/resume_existing_billing_period.json b/tests/Functional/Resources/Subscriptions/_fixtures/request/resume_existing_billing_period.json new file mode 100644 index 0000000..b0d7757 --- /dev/null +++ b/tests/Functional/Resources/Subscriptions/_fixtures/request/resume_existing_billing_period.json @@ -0,0 +1,4 @@ +{ + "effective_from": "immediately", + "on_resume": "continue_existing_billing_period" +} diff --git a/tests/Functional/Resources/Subscriptions/_fixtures/request/resume_new_billing_period.json b/tests/Functional/Resources/Subscriptions/_fixtures/request/resume_new_billing_period.json new file mode 100644 index 0000000..1a578ce --- /dev/null +++ b/tests/Functional/Resources/Subscriptions/_fixtures/request/resume_new_billing_period.json @@ -0,0 +1,4 @@ +{ + "effective_from": "immediately", + "on_resume": "start_new_billing_period" +}