webmoney/backend/app/Http/Controllers/Api/PlanController.php
marcoitaloesp-ai 0adb5c889f
feat(subscriptions): sistema de assinaturas SaaS v1.49.0
- Criar tabela plans com Free, Pro Monthly, Pro Annual
- Criar tabela subscriptions com status e integração PayPal
- Criar tabela invoices com numeração sequencial WM-YYYY-NNNNNN
- Models: Plan, Subscription, Invoice com helpers
- User: hasActiveSubscription(), onTrial(), currentPlan(), etc.
- API: GET /api/plans (público)
- Seeder: PlansSeeder com 3 planos base
- Fase 2 do roadmap SaaS concluída
2025-12-17 10:46:34 +00:00

85 lines
2.8 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Plan;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
class PlanController extends Controller
{
/**
* List all active plans for pricing page
*/
public function index(): JsonResponse
{
$plans = Plan::active()->ordered()->get();
return response()->json([
'success' => true,
'data' => [
'plans' => $plans->map(function ($plan) {
return [
'id' => $plan->id,
'slug' => $plan->slug,
'name' => $plan->name,
'description' => $plan->description,
'price' => $plan->price,
'formatted_price' => $plan->formatted_price,
'monthly_price' => $plan->monthly_price,
'currency' => $plan->currency,
'billing_period' => $plan->billing_period,
'trial_days' => $plan->trial_days,
'features' => $plan->features,
'limits' => $plan->limits,
'is_free' => $plan->is_free,
'is_featured' => $plan->is_featured,
'has_trial' => $plan->has_trial,
'savings_percent' => $plan->savings_percent,
];
}),
],
]);
}
/**
* Get a single plan by slug
*/
public function show(string $slug): JsonResponse
{
$plan = Plan::where('slug', $slug)->where('is_active', true)->first();
if (!$plan) {
return response()->json([
'success' => false,
'message' => 'Plan not found',
], 404);
}
return response()->json([
'success' => true,
'data' => [
'plan' => [
'id' => $plan->id,
'slug' => $plan->slug,
'name' => $plan->name,
'description' => $plan->description,
'price' => $plan->price,
'formatted_price' => $plan->formatted_price,
'monthly_price' => $plan->monthly_price,
'currency' => $plan->currency,
'billing_period' => $plan->billing_period,
'trial_days' => $plan->trial_days,
'features' => $plan->features,
'limits' => $plan->limits,
'is_free' => $plan->is_free,
'is_featured' => $plan->is_featured,
'has_trial' => $plan->has_trial,
'savings_percent' => $plan->savings_percent,
],
],
]);
}
}