Skip to content

Commit 6d11512

Browse files
feat: Add on_resume support to subscription resume and pause operations (#111)
1 parent 31b5cc0 commit 6d11512

File tree

10 files changed

+92
-5
lines changed

10 files changed

+92
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
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.
88

9+
## [1.8.0] - 2024-12-19
10+
11+
### Added
12+
13+
- Added `on_resume` support to subscription resume and pause operations
14+
915
## [1.7.2] - 2024-12-17
1016

1117
### Fixed

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
class Client
6262
{
63-
private const SDK_VERSION = '1.7.2';
63+
private const SDK_VERSION = '1.8.0';
6464

6565
public readonly LoggerInterface $logger;
6666
public readonly Options $options;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* |------
7+
* | ! Generated code !
8+
* | Altering this code will result in changes being overwritten |
9+
* |-------------------------------------------------------------|.
10+
*/
11+
12+
namespace Paddle\SDK\Entities\Subscription;
13+
14+
use Paddle\SDK\PaddleEnum;
15+
16+
/**
17+
* @method static SubscriptionOnResume ContinueExistingBillingPeriod()
18+
* @method static SubscriptionOnResume StartNewBillingPeriod()
19+
*/
20+
final class SubscriptionOnResume extends PaddleEnum
21+
{
22+
private const ContinueExistingBillingPeriod = 'continue_existing_billing_period';
23+
private const StartNewBillingPeriod = 'start_new_billing_period';
24+
}

src/Resources/Subscriptions/Operations/PauseSubscription.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@
66

77
use Paddle\SDK\Entities\DateTime;
88
use Paddle\SDK\Entities\Subscription\SubscriptionEffectiveFrom;
9+
use Paddle\SDK\Entities\Subscription\SubscriptionOnResume;
10+
use Paddle\SDK\FiltersUndefined;
11+
use Paddle\SDK\Undefined;
912

1013
class PauseSubscription implements \JsonSerializable
1114
{
15+
use FiltersUndefined;
16+
1217
public function __construct(
1318
public readonly SubscriptionEffectiveFrom|null $effectiveFrom = null,
1419
public readonly \DateTimeInterface|null $resumeAt = null,
20+
public readonly SubscriptionOnResume|Undefined $onResume = new Undefined(),
1521
) {
1622
}
1723

1824
public function jsonSerialize(): array
1925
{
20-
return [
26+
return $this->filterUndefined([
2127
'effective_from' => $this->effectiveFrom,
2228
'resume_at' => isset($this->resumeAt) ? DateTime::from($this->resumeAt)?->format() : null,
23-
];
29+
'on_resume' => $this->onResume,
30+
]);
2431
}
2532
}

src/Resources/Subscriptions/Operations/ResumeSubscription.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,28 @@
55
namespace Paddle\SDK\Resources\Subscriptions\Operations;
66

77
use Paddle\SDK\Entities\DateTime;
8+
use Paddle\SDK\Entities\Subscription\SubscriptionOnResume;
89
use Paddle\SDK\Entities\Subscription\SubscriptionResumeEffectiveFrom;
10+
use Paddle\SDK\FiltersUndefined;
11+
use Paddle\SDK\Undefined;
912

1013
class ResumeSubscription implements \JsonSerializable
1114
{
15+
use FiltersUndefined;
16+
1217
public function __construct(
1318
public readonly SubscriptionResumeEffectiveFrom|\DateTimeInterface|null $effectiveFrom = null,
19+
public readonly SubscriptionOnResume|Undefined $onResume = new Undefined(),
1420
) {
1521
}
1622

1723
public function jsonSerialize(): array
1824
{
19-
return [
25+
return $this->filterUndefined([
2026
'effective_from' => $this->effectiveFrom instanceof \DateTimeInterface
2127
? DateTime::from($this->effectiveFrom)?->format()
2228
: $this->effectiveFrom,
23-
];
29+
'on_resume' => $this->onResume,
30+
]);
2431
}
2532
}

tests/Functional/Resources/Subscriptions/SubscriptionsClientTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Paddle\SDK\Entities\Subscription\SubscriptionNonCatalogPriceWithProduct;
2525
use Paddle\SDK\Entities\Subscription\SubscriptionNonCatalogProduct;
2626
use Paddle\SDK\Entities\Subscription\SubscriptionOnPaymentFailure;
27+
use Paddle\SDK\Entities\Subscription\SubscriptionOnResume;
2728
use Paddle\SDK\Entities\Subscription\SubscriptionProrationBillingMode;
2829
use Paddle\SDK\Entities\Subscription\SubscriptionResumeEffectiveFrom;
2930
use Paddle\SDK\Entities\Subscription\SubscriptionScheduledChangeAction;
@@ -355,6 +356,18 @@ public static function pauseOperationsProvider(): \Generator
355356
new Response(200, body: self::readRawJsonFixture('response/full_entity')),
356357
self::readRawJsonFixture('request/pause_full'),
357358
];
359+
360+
yield 'On resume continue existing billing period' => [
361+
new PauseSubscription(SubscriptionEffectiveFrom::Immediately(), new \DateTime('2023-10-09T16:30:00Z'), SubscriptionOnResume::ContinueExistingBillingPeriod()),
362+
new Response(200, body: self::readRawJsonFixture('response/full_entity')),
363+
self::readRawJsonFixture('request/pause_resume_existing_billing_period'),
364+
];
365+
366+
yield 'On resume start new billing period' => [
367+
new PauseSubscription(SubscriptionEffectiveFrom::Immediately(), new \DateTime('2023-10-09T16:30:00Z'), SubscriptionOnResume::StartNewBillingPeriod()),
368+
new Response(200, body: self::readRawJsonFixture('response/full_entity')),
369+
self::readRawJsonFixture('request/pause_resume_new_billing_period'),
370+
];
358371
}
359372

360373
/**
@@ -399,6 +412,18 @@ public static function resumeOperationsProvider(): \Generator
399412
new Response(200, body: self::readRawJsonFixture('response/full_entity')),
400413
self::readRawJsonFixture('request/resume_single_as_date'),
401414
];
415+
416+
yield 'On resume continue existing billing period' => [
417+
new ResumeSubscription(SubscriptionResumeEffectiveFrom::Immediately(), SubscriptionOnResume::ContinueExistingBillingPeriod()),
418+
new Response(200, body: self::readRawJsonFixture('response/full_entity')),
419+
self::readRawJsonFixture('request/resume_existing_billing_period'),
420+
];
421+
422+
yield 'On resume start new billing period' => [
423+
new ResumeSubscription(SubscriptionResumeEffectiveFrom::Immediately(), SubscriptionOnResume::StartNewBillingPeriod()),
424+
new Response(200, body: self::readRawJsonFixture('response/full_entity')),
425+
self::readRawJsonFixture('request/resume_new_billing_period'),
426+
];
402427
}
403428

404429
/**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"effective_from": "immediately",
3+
"resume_at": "2023-10-09T16:30:00.000000Z",
4+
"on_resume": "continue_existing_billing_period"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"effective_from": "immediately",
3+
"resume_at": "2023-10-09T16:30:00.000000Z",
4+
"on_resume": "start_new_billing_period"
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"effective_from": "immediately",
3+
"on_resume": "continue_existing_billing_period"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"effective_from": "immediately",
3+
"on_resume": "start_new_billing_period"
4+
}

0 commit comments

Comments
 (0)