mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-04 22:59:41 +00:00
Discount subscriptions per billed period
discount (label, percent_off or amount_off, duration once, repeating or forever) when creating subscriptions and per subscription of checkout sessions, the discount field on subscriptions and the subscription.discount_ended event type.
This commit is contained in:
10 files changed
+104
-2
No files matched your search
@@ -203,6 +203,18 @@ class AppSubscriptionsTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_a_subscription_is_created_with_a_discount(): void
|
||||
{
|
||||
$discount = ['label' => 'SUMMER20', 'percent_off' => 20, 'duration' => 'repeating', 'duration_in_periods' => 3];
|
||||
$this->respond(201, $this->subscription(['discount' => [...$discount, 'amount_off' => null, 'periods_remaining' => 3]]));
|
||||
|
||||
$subscription = $this->owner()->appSubscriptions()->create(['name' => 'Pro', 'unit' => 'month', 'price' => '9.99', 'discount' => $discount]);
|
||||
|
||||
$this->assertSame($discount, $this->sentJson(0)['discount']);
|
||||
$this->assertSame('SUMMER20', $subscription->discount->label);
|
||||
$this->assertSame(3, $subscription->discount->periods_remaining);
|
||||
}
|
||||
|
||||
public function test_a_missing_user_id_is_reported(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
@@ -153,6 +153,18 @@ class CheckoutSessionsTest extends TestCase
|
||||
$this->assertSame('2026-12-01T00:00:00+00:00', $this->sentJson(0)['subscriptions'][1]['trial_ends_at']);
|
||||
}
|
||||
|
||||
public function test_session_subscriptions_carry_a_discount(): void
|
||||
{
|
||||
$this->respond(201, $this->sessionData());
|
||||
|
||||
$this->owner()->checkoutSessions()->create(['subscriptions' => [
|
||||
['name' => 'Pro', 'unit' => 'month', 'price' => 4.99, 'discount' => ['label' => 'WELCOME', 'amount_off' => '1.00', 'duration' => 'once']],
|
||||
]]);
|
||||
|
||||
$this->assertSame('POST /api/v1/checkout-sessions Bearer user-token', $this->request(0));
|
||||
$this->assertSame(['label' => 'WELCOME', 'amount_off' => '1.00', 'duration' => 'once'], $this->sentJson(0)['subscriptions'][0]['discount']);
|
||||
}
|
||||
|
||||
public function test_nothing_is_requested_until_a_method_is_called(): void
|
||||
{
|
||||
$this->owner()->checkoutSessions();
|
||||
@@ -174,5 +186,6 @@ class CheckoutSessionsTest extends TestCase
|
||||
$this->assertContains('checkout.expired', EventType::all());
|
||||
$this->assertContains('subscription.activated', EventType::all());
|
||||
$this->assertContains('subscription.trial_will_end', EventType::all());
|
||||
$this->assertContains('subscription.discount_ended', EventType::all());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user