create(['subscription_status' => 'free']); $package = Package::factory()->reseller()->create(); $payload = [ 'webhook_id' => 'WH-activation', 'webhook_event' => [ 'event_type' => 'BILLING.SUBSCRIPTION.ACTIVATED', 'resource' => [ 'id' => 'I-123456', 'custom_id' => json_encode([ 'tenant_id' => $tenant->id, 'package_id' => $package->id, ]), ], ], ]; $response = $this->postJson('/paypal/webhook', $payload); $response->assertOk() ->assertJson(['status' => 'SUCCESS']); $this->assertEquals('active', $tenant->fresh()->subscription_status); } public function test_subscription_cancellation_deactivates_tenant_package(): void { $tenant = Tenant::factory()->create(['subscription_status' => 'active']); $package = Package::factory()->reseller()->create(); TenantPackage::factory()->create([ 'tenant_id' => $tenant->id, 'package_id' => $package->id, 'active' => true, ]); $payload = [ 'webhook_id' => 'WH-cancel', 'webhook_event' => [ 'event_type' => 'BILLING.SUBSCRIPTION.CANCELLED', 'resource' => [ 'id' => 'I-123456', 'custom_id' => json_encode([ 'tenant_id' => $tenant->id, 'package_id' => $package->id, ]), ], ], ]; $response = $this->postJson('/paypal/webhook', $payload); $response->assertOk() ->assertJson(['status' => 'SUCCESS']); $this->assertEquals('expired', $tenant->fresh()->subscription_status); $this->assertFalse($tenant->tenantPackages()->first()->fresh()->active); } }