feat: 구독/결제 API 확장 (Plan, Subscription, Payment)

- Plan/Subscription/Payment 모델에 상태 상수, 스코프, 헬퍼 메서드 추가
- PlanService, SubscriptionService, PaymentService 생성
- PlanController, SubscriptionController, PaymentController 생성
- FormRequest 9개 생성 (Plan 3개, Subscription 3개, Payment 3개)
- Swagger 문서 3개 생성 (PlanApi, SubscriptionApi, PaymentApi)
- API 라우트 22개 등록 (Plan 7개, Subscription 8개, Payment 7개)
- Pint 코드 스타일 정리
This commit is contained in:
2025-12-18 16:20:29 +09:00
parent 7278c4742f
commit 45780ea351
35 changed files with 3025 additions and 29 deletions

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Requests\V1\Payment;
use Illuminate\Foundation\Http\FormRequest;
class PaymentActionRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'reason' => ['nullable', 'string', 'max:500'],
'transaction_id' => ['nullable', 'string', 'max:100'],
];
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests\V1\Payment;
use App\Models\Tenants\Payment;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class PaymentIndexRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'status' => ['nullable', 'string', Rule::in(Payment::STATUSES)],
'payment_method' => ['nullable', 'string', Rule::in(Payment::PAYMENT_METHODS)],
'start_date' => ['nullable', 'date'],
'end_date' => ['nullable', 'date', 'after_or_equal:start_date'],
'search' => ['nullable', 'string', 'max:100'],
'sort_by' => ['nullable', 'string', 'in:created_at,paid_at,amount'],
'sort_dir' => ['nullable', 'string', 'in:asc,desc'],
'per_page' => ['nullable', 'integer', 'min:1', 'max:100'],
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Requests\V1\Payment;
use App\Models\Tenants\Payment;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class PaymentStoreRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'subscription_id' => ['required', 'integer', 'exists:subscriptions,id'],
'amount' => ['required', 'numeric', 'min:0'],
'payment_method' => ['required', 'string', Rule::in(Payment::PAYMENT_METHODS)],
'transaction_id' => ['nullable', 'string', 'max:100'],
'memo' => ['nullable', 'string', 'max:500'],
'auto_complete' => ['nullable', 'boolean'],
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Requests\V1\Plan;
use Illuminate\Foundation\Http\FormRequest;
class PlanIndexRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'is_active' => ['nullable', 'boolean'],
'billing_cycle' => ['nullable', 'string', 'in:monthly,yearly,lifetime'],
'search' => ['nullable', 'string', 'max:100'],
'sort_by' => ['nullable', 'string', 'in:price,name,created_at'],
'sort_dir' => ['nullable', 'string', 'in:asc,desc'],
'per_page' => ['nullable', 'integer', 'min:1', 'max:100'],
];
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests\V1\Plan;
use App\Models\Tenants\Plan;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class PlanStoreRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:100'],
'code' => ['required', 'string', 'max:50', 'unique:plans,code'],
'description' => ['nullable', 'string', 'max:500'],
'price' => ['required', 'numeric', 'min:0'],
'billing_cycle' => ['required', 'string', Rule::in(Plan::BILLING_CYCLES)],
'features' => ['nullable', 'array'],
'features.*' => ['string', 'max:200'],
'is_active' => ['nullable', 'boolean'],
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Requests\V1\Plan;
use App\Models\Tenants\Plan;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class PlanUpdateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$planId = $this->route('id');
return [
'name' => ['sometimes', 'required', 'string', 'max:100'],
'code' => ['sometimes', 'required', 'string', 'max:50', Rule::unique('plans', 'code')->ignore($planId)],
'description' => ['nullable', 'string', 'max:500'],
'price' => ['sometimes', 'required', 'numeric', 'min:0'],
'billing_cycle' => ['sometimes', 'required', 'string', Rule::in(Plan::BILLING_CYCLES)],
'features' => ['nullable', 'array'],
'features.*' => ['string', 'max:200'],
'is_active' => ['nullable', 'boolean'],
];
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Http\Requests\V1\Subscription;
use Illuminate\Foundation\Http\FormRequest;
class SubscriptionCancelRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'reason' => ['nullable', 'string', 'max:500'],
];
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests\V1\Subscription;
use App\Models\Tenants\Subscription;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class SubscriptionIndexRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'status' => ['nullable', 'string', Rule::in(Subscription::STATUSES)],
'valid_only' => ['nullable', 'boolean'],
'expiring_within' => ['nullable', 'integer', 'min:1', 'max:365'],
'start_date' => ['nullable', 'date'],
'end_date' => ['nullable', 'date', 'after_or_equal:start_date'],
'sort_by' => ['nullable', 'string', 'in:started_at,ended_at,created_at'],
'sort_dir' => ['nullable', 'string', 'in:asc,desc'],
'per_page' => ['nullable', 'integer', 'min:1', 'max:100'],
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Requests\V1\Subscription;
use App\Models\Tenants\Payment;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class SubscriptionStoreRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'plan_id' => ['required', 'integer', 'exists:plans,id'],
'started_at' => ['nullable', 'date'],
'payment_method' => ['nullable', 'string', Rule::in(Payment::PAYMENT_METHODS)],
'transaction_id' => ['nullable', 'string', 'max:100'],
'auto_complete' => ['nullable', 'boolean'],
];
}
}