Retire Events subscriptions and owner payment gateways.
Deploy Ladill Events / deploy (push) Successful in 55s

Make Ladill Events free for all accounts, remove plan upgrade UI, force Ladill Pay only for tickets and contributions, and reinstate standard platform fees.
This commit is contained in:
isaacclad
2026-07-24 14:15:34 +00:00
parent ce5ef67a7c
commit 25ce2bc9de
10 changed files with 72 additions and 290 deletions
+22 -81
View File
@@ -3,11 +3,11 @@
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Events\ProSubscription;
use App\Models\PaymentGatewaySetting;
use App\Models\User;
use App\Services\Events\SubscriptionService;
use App\Services\Payments\MerchantGatewayService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class EventsProTest extends TestCase
@@ -21,14 +21,7 @@ class EventsProTest extends TestCase
config([
'billing.api_url' => 'https://ladill.com/api/billing',
'billing.api_key' => 'events-billing-key',
'events.pro.enabled' => true,
'events.pro.price_minor' => 4900,
'events.plans.pro.price_minor' => 4900,
'events.plans.enterprise.price_minor' => 14900,
'events.pro.period_days' => 30,
'events.pro.grace_days' => 3,
'events.free.max_live_events' => 2,
'events.free.max_tickets_per_month' => 100,
'events.pro.enabled' => false,
]);
}
@@ -37,92 +30,40 @@ class EventsProTest extends TestCase
return User::factory()->create(['public_id' => 'usr_'.uniqid()]);
}
public function test_subscribe_charges_wallet_and_activates(): void
public function test_subscriptions_are_retired(): 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_ends_with(parse_url($r->url(), PHP_URL_PATH) ?: '', '/debit')
&& $r['amount_minor'] === 4900
&& $r['service'] === 'events');
}
public function test_subscribe_enterprise_charges_wallet_and_activates(): void
{
Http::fake(['*/debit' => Http::response(['id' => 1], 201)]);
$user = $this->user();
$svc = app(SubscriptionService::class);
[$ok] = $svc->subscribeEnterprise($user);
$this->assertTrue($ok);
$this->assertTrue($svc->isEnterprise($user));
$sub = ProSubscription::where('user_id', $user->id)->first();
$this->assertSame('enterprise', $sub->plan);
$this->assertSame(14900, $sub->price_minor);
}
public function test_free_user_is_gated_to_event_limit(): void
{
$user = $this->user();
$svc = app(SubscriptionService::class);
$this->assertFalse($svc->gatingActive());
$this->assertTrue($svc->hasPaidPlan($user));
$this->assertTrue($svc->canCreateEvent($user));
$this->assertSame(0, $svc->liveEventCount($user));
}
public function test_free_user_cannot_use_payment_gateway(): void
{
$user = $this->user();
$svc = app(SubscriptionService::class);
$this->assertFalse($svc->canUsePaymentGateway($user));
$this->assertFalse(app(\App\Services\Payments\MerchantGatewayService::class)->isConfigured($user));
}
public function test_pro_user_can_use_payment_gateway_when_configured(): void
public function test_pro_routes_redirect_to_dashboard(): void
{
Http::fake(['*/debit' => Http::response(['id' => 1], 201)]);
$user = $this->user();
$svc = app(SubscriptionService::class);
$svc->subscribe($user);
$this->actingAs($this->user())
->get(route('events.pro.index'))
->assertRedirect(route('events.dashboard'));
\App\Models\PaymentGatewaySetting::create([
$this->actingAs($this->user())
->post(route('events.pro.subscribe'))
->assertRedirect(route('events.dashboard'));
}
public function test_owner_gateway_is_never_used(): void
{
$user = $this->user();
PaymentGatewaySetting::create([
'owner_ref' => $user->public_id,
'provider' => \App\Models\PaymentGatewaySetting::PROVIDER_PAYSTACK,
'provider' => PaymentGatewaySetting::PROVIDER_PAYSTACK,
'public_key' => 'pk_test',
'secret_key' => 'sk_test',
'is_active' => true,
]);
$this->assertTrue($svc->canUsePaymentGateway($user));
$this->assertTrue(app(\App\Services\Payments\MerchantGatewayService::class)->isConfigured($user));
}
public function test_invalid_credentials_and_downgrade_disable_owner_gateway_without_deleting_keys(): void
{
$user = $this->user();
ProSubscription::create([
'user_id' => $user->id, 'plan' => 'enterprise', 'status' => 'active',
'price_minor' => 14900, 'current_period_end' => now()->addMonth(),
]);
$setting = \App\Models\PaymentGatewaySetting::create([
'owner_ref' => $user->public_id, 'provider' => 'paystack',
'public_key' => 'bad', 'secret_key' => 'bad', 'is_active' => true,
]);
$gateway = app(\App\Services\Payments\MerchantGatewayService::class);
$this->assertFalse($gateway->shouldUseOwnerGateway($user));
$setting->update(['public_key' => 'pk_test_saved', 'secret_key' => 'sk_test_saved']);
$this->assertTrue($gateway->shouldUseOwnerGateway($user));
ProSubscription::where('user_id', $user->id)->update(['status' => 'past_due']);
$this->assertFalse($gateway->shouldUseOwnerGateway($user->fresh()));
$this->assertDatabaseHas('payment_gateway_settings', ['id' => $setting->id, 'is_active' => true]);
$this->assertFalse(app(MerchantGatewayService::class)->shouldUseOwnerGateway($user));
$this->assertFalse(app(MerchantGatewayService::class)->isConfigured($user));
}
}