Skip to content

Commit

Permalink
[1.x] Do not allow updating quantities to zero (#174)
Browse files Browse the repository at this point in the history
* Do not allow updating quantities to zero

* Update src/Subscription.php

* Update Subscription.php
  • Loading branch information
driesvints authored Nov 15, 2022
1 parent a30a3a8 commit 1bef15e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ public function updateQuantity($quantity, array $options = [])
{
$this->guardAgainstUpdates('update quantities');

if ($quantity < 1) {
throw new LogicException('Paddle does not allow subscriptions to have a quantity of zero.');
}

$this->updatePaddleSubscription(array_merge($options, [
'quantity' => $quantity,
'prorate' => $this->prorate,
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Unit;

use Laravel\Paddle\Subscription;
use LogicException;
use PHPUnit\Framework\TestCase;

class SubscriptionTest extends TestCase
Expand Down Expand Up @@ -36,4 +37,13 @@ public function test_it_can_determine_if_a_trial_has_expired()

$this->assertFalse($subscription->hasExpiredTrial());
}

public function test_it_cannot_update_its_quantity_to_zero()
{
$subscription = new Subscription();

$this->expectException(LogicException::class);

$subscription->updateQuantity(0);
}
}

0 comments on commit 1bef15e

Please sign in to comment.