Add POS Pro subscription billing and free-tier limits.
Deploy Ladill POS / deploy (push) Successful in 43s
Deploy Ladill POS / deploy (push) Successful in 43s
Wallet-backed Pro unlocks unlimited products, restaurant mode, catalog imports, and ecosystem sync features. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Pos\ProSubscription;
|
||||
use App\Models\User;
|
||||
use App\Services\Pos\SubscriptionService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PosProTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
config([
|
||||
'billing.api_url' => 'https://ladill.com/api/billing',
|
||||
'billing.api_key' => 'pos-billing-key',
|
||||
'pos.pro.enabled' => true,
|
||||
'pos.pro.price_minor' => 7900,
|
||||
]);
|
||||
}
|
||||
|
||||
private function user(): User
|
||||
{
|
||||
return User::factory()->create(['public_id' => 'usr_'.uniqid()]);
|
||||
}
|
||||
|
||||
public function test_subscribe_charges_wallet_and_activates(): void
|
||||
{
|
||||
Http::fake(['*/debit' => Http::response(['id' => 1], 201)]);
|
||||
$user = $this->user();
|
||||
$svc = app(SubscriptionService::class);
|
||||
|
||||
[$ok] = $svc->subscribe($user);
|
||||
|
||||
$this->assertTrue($ok);
|
||||
$this->assertTrue($svc->isPro($user));
|
||||
Http::assertSent(fn ($r) => str_contains($r->url(), '/debit') && $r['service'] === 'pos');
|
||||
}
|
||||
|
||||
public function test_free_user_cannot_use_restaurant_mode(): void
|
||||
{
|
||||
$this->assertFalse(app(SubscriptionService::class)->canUseRestaurantMode($this->user()));
|
||||
}
|
||||
|
||||
public function test_renew_suspends_after_grace_when_unpaid(): void
|
||||
{
|
||||
Http::fake(['*/debit' => Http::response(['balance_minor' => 0], 402)]);
|
||||
$user = $this->user();
|
||||
$sub = ProSubscription::create([
|
||||
'user_id' => $user->id, 'status' => 'active', 'price_minor' => 7900,
|
||||
'auto_renew' => true, 'started_at' => now()->subDays(40),
|
||||
'current_period_end' => now()->subDays(5),
|
||||
]);
|
||||
|
||||
app(SubscriptionService::class)->renewIfDue($sub->fresh());
|
||||
|
||||
$this->assertSame('past_due', $sub->fresh()->status);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user