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:
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\BankAccount\StoreBankAccountRequest;
|
||||
use App\Http\Requests\V1\BankAccount\UpdateBankAccountRequest;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Services\BankAccountService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Card\StoreCardRequest;
|
||||
use App\Http\Requests\V1\Card\UpdateCardRequest;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Services\CardService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Deposit\StoreDepositRequest;
|
||||
use App\Http\Requests\V1\Deposit\UpdateDepositRequest;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Services\DepositService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
88
app/Http/Controllers/Api/V1/PaymentController.php
Normal file
88
app/Http/Controllers/Api/V1/PaymentController.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Payment\PaymentActionRequest;
|
||||
use App\Http\Requests\V1\Payment\PaymentIndexRequest;
|
||||
use App\Http\Requests\V1\Payment\PaymentStoreRequest;
|
||||
use App\Http\Response\ApiResponse;
|
||||
use App\Services\PaymentService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PaymentService $paymentService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 결제 목록
|
||||
*/
|
||||
public function index(PaymentIndexRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->paymentService->index($request->validated());
|
||||
|
||||
return ApiResponse::handle('message.fetched', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 요약 통계
|
||||
*/
|
||||
public function summary(PaymentIndexRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->paymentService->summary($request->validated());
|
||||
|
||||
return ApiResponse::handle('message.fetched', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 상세
|
||||
*/
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->paymentService->show($id);
|
||||
|
||||
return ApiResponse::handle('message.fetched', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 등록 (수동)
|
||||
*/
|
||||
public function store(PaymentStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->paymentService->store($request->validated());
|
||||
|
||||
return ApiResponse::handle('message.created', $result, 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 완료 처리
|
||||
*/
|
||||
public function complete(PaymentActionRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->paymentService->complete($id, $request->validated()['transaction_id'] ?? null);
|
||||
|
||||
return ApiResponse::handle('message.payment.completed', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 취소
|
||||
*/
|
||||
public function cancel(PaymentActionRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->paymentService->cancel($id, $request->validated()['reason'] ?? null);
|
||||
|
||||
return ApiResponse::handle('message.payment.cancelled', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 환불 처리
|
||||
*/
|
||||
public function refund(PaymentActionRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->paymentService->refund($id, $request->validated()['reason'] ?? null);
|
||||
|
||||
return ApiResponse::handle('message.payment.refunded', $result);
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Payroll\CalculatePayrollRequest;
|
||||
use App\Http\Requests\V1\Payroll\PayPayrollRequest;
|
||||
use App\Http\Requests\V1\Payroll\StorePayrollRequest;
|
||||
use App\Http\Requests\V1\Payroll\UpdatePayrollRequest;
|
||||
use App\Http\Requests\V1\Payroll\UpdatePayrollSettingRequest;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Services\PayrollService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
88
app/Http/Controllers/Api/V1/PlanController.php
Normal file
88
app/Http/Controllers/Api/V1/PlanController.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Plan\PlanIndexRequest;
|
||||
use App\Http\Requests\V1\Plan\PlanStoreRequest;
|
||||
use App\Http\Requests\V1\Plan\PlanUpdateRequest;
|
||||
use App\Http\Response\ApiResponse;
|
||||
use App\Services\PlanService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PlanService $planService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 요금제 목록 (관리자용)
|
||||
*/
|
||||
public function index(PlanIndexRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->planService->index($request->validated());
|
||||
|
||||
return ApiResponse::handle('message.fetched', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 활성 요금제 목록 (공개용)
|
||||
*/
|
||||
public function active(): JsonResponse
|
||||
{
|
||||
$result = $this->planService->active();
|
||||
|
||||
return ApiResponse::handle('message.fetched', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 요금제 등록
|
||||
*/
|
||||
public function store(PlanStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->planService->store($request->validated());
|
||||
|
||||
return ApiResponse::handle('message.created', $result, 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* 요금제 상세
|
||||
*/
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->planService->show($id);
|
||||
|
||||
return ApiResponse::handle('message.fetched', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 요금제 수정
|
||||
*/
|
||||
public function update(PlanUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->planService->update($id, $request->validated());
|
||||
|
||||
return ApiResponse::handle('message.updated', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 요금제 삭제
|
||||
*/
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$this->planService->destroy($id);
|
||||
|
||||
return ApiResponse::handle('message.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* 요금제 활성/비활성 토글
|
||||
*/
|
||||
public function toggle(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->planService->toggle($id);
|
||||
|
||||
return ApiResponse::handle('message.updated', $result);
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Purchase\StorePurchaseRequest;
|
||||
use App\Http\Requests\V1\Purchase\UpdatePurchaseRequest;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Services\PurchaseService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
use App\Exports\DailyReportExport;
|
||||
use App\Exports\ExpenseEstimateExport;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Report\DailyReportRequest;
|
||||
use App\Http\Requests\V1\Report\ExpenseEstimateRequest;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Services\ReportService;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Sale\StoreSaleRequest;
|
||||
use App\Http\Requests\V1\Sale\UpdateSaleRequest;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Services\SaleService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Site\StoreSiteRequest;
|
||||
use App\Http\Requests\V1\Site\UpdateSiteRequest;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Services\SiteService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
98
app/Http/Controllers/Api/V1/SubscriptionController.php
Normal file
98
app/Http/Controllers/Api/V1/SubscriptionController.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Subscription\SubscriptionCancelRequest;
|
||||
use App\Http\Requests\V1\Subscription\SubscriptionIndexRequest;
|
||||
use App\Http\Requests\V1\Subscription\SubscriptionStoreRequest;
|
||||
use App\Http\Response\ApiResponse;
|
||||
use App\Services\SubscriptionService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class SubscriptionController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SubscriptionService $subscriptionService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 구독 목록
|
||||
*/
|
||||
public function index(SubscriptionIndexRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->subscriptionService->index($request->validated());
|
||||
|
||||
return ApiResponse::handle('message.fetched', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 현재 활성 구독
|
||||
*/
|
||||
public function current(): JsonResponse
|
||||
{
|
||||
$result = $this->subscriptionService->current();
|
||||
|
||||
return ApiResponse::handle('message.fetched', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 등록
|
||||
*/
|
||||
public function store(SubscriptionStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->subscriptionService->store($request->validated());
|
||||
|
||||
return ApiResponse::handle('message.created', $result, 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 상세
|
||||
*/
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->subscriptionService->show($id);
|
||||
|
||||
return ApiResponse::handle('message.fetched', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 취소
|
||||
*/
|
||||
public function cancel(SubscriptionCancelRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->subscriptionService->cancel($id, $request->validated()['reason'] ?? null);
|
||||
|
||||
return ApiResponse::handle('message.subscription.cancelled', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 갱신
|
||||
*/
|
||||
public function renew(SubscriptionStoreRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->subscriptionService->renew($id, $request->validated());
|
||||
|
||||
return ApiResponse::handle('message.subscription.renewed', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 일시정지
|
||||
*/
|
||||
public function suspend(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->subscriptionService->suspend($id);
|
||||
|
||||
return ApiResponse::handle('message.subscription.suspended', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 재개
|
||||
*/
|
||||
public function resume(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->subscriptionService->resume($id);
|
||||
|
||||
return ApiResponse::handle('message.subscription.resumed', $result);
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Withdrawal\StoreWithdrawalRequest;
|
||||
use App\Http\Requests\V1\Withdrawal\UpdateWithdrawalRequest;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Services\WithdrawalService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\WorkSetting\UpdateAttendanceSettingRequest;
|
||||
use App\Http\Requests\V1\WorkSetting\UpdateWorkSettingRequest;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Services\WorkSettingService;
|
||||
|
||||
class WorkSettingController extends Controller
|
||||
|
||||
21
app/Http/Requests/V1/Payment/PaymentActionRequest.php
Normal file
21
app/Http/Requests/V1/Payment/PaymentActionRequest.php
Normal 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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
29
app/Http/Requests/V1/Payment/PaymentIndexRequest.php
Normal file
29
app/Http/Requests/V1/Payment/PaymentIndexRequest.php
Normal 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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Http/Requests/V1/Payment/PaymentStoreRequest.php
Normal file
27
app/Http/Requests/V1/Payment/PaymentStoreRequest.php
Normal 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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
25
app/Http/Requests/V1/Plan/PlanIndexRequest.php
Normal file
25
app/Http/Requests/V1/Plan/PlanIndexRequest.php
Normal 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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
29
app/Http/Requests/V1/Plan/PlanStoreRequest.php
Normal file
29
app/Http/Requests/V1/Plan/PlanStoreRequest.php
Normal 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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Http/Requests/V1/Plan/PlanUpdateRequest.php
Normal file
31
app/Http/Requests/V1/Plan/PlanUpdateRequest.php
Normal 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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,26 +2,287 @@
|
||||
|
||||
namespace App\Models\Tenants;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* 결제 모델
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $subscription_id 구독 ID
|
||||
* @property float $amount 결제 금액
|
||||
* @property string $payment_method 결제 수단
|
||||
* @property string|null $transaction_id PG 거래 ID
|
||||
* @property Carbon|null $paid_at 결제일시
|
||||
* @property string $status 결제 상태
|
||||
* @property string|null $memo 메모
|
||||
*
|
||||
* @mixin IdeHelperPayment
|
||||
*/
|
||||
class Payment extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
// =========================================================================
|
||||
// 상수 정의
|
||||
// =========================================================================
|
||||
|
||||
/** 결제 상태 */
|
||||
public const STATUS_PENDING = 'pending';
|
||||
|
||||
public const STATUS_COMPLETED = 'completed';
|
||||
|
||||
public const STATUS_FAILED = 'failed';
|
||||
|
||||
public const STATUS_CANCELLED = 'cancelled';
|
||||
|
||||
public const STATUS_REFUNDED = 'refunded';
|
||||
|
||||
public const STATUSES = [
|
||||
self::STATUS_PENDING,
|
||||
self::STATUS_COMPLETED,
|
||||
self::STATUS_FAILED,
|
||||
self::STATUS_CANCELLED,
|
||||
self::STATUS_REFUNDED,
|
||||
];
|
||||
|
||||
/** 상태 라벨 */
|
||||
public const STATUS_LABELS = [
|
||||
self::STATUS_PENDING => '대기',
|
||||
self::STATUS_COMPLETED => '완료',
|
||||
self::STATUS_FAILED => '실패',
|
||||
self::STATUS_CANCELLED => '취소',
|
||||
self::STATUS_REFUNDED => '환불',
|
||||
];
|
||||
|
||||
/** 결제 수단 */
|
||||
public const METHOD_CARD = 'card';
|
||||
|
||||
public const METHOD_BANK = 'bank';
|
||||
|
||||
public const METHOD_VIRTUAL = 'virtual';
|
||||
|
||||
public const METHOD_CASH = 'cash';
|
||||
|
||||
public const METHOD_FREE = 'free';
|
||||
|
||||
public const PAYMENT_METHODS = [
|
||||
self::METHOD_CARD,
|
||||
self::METHOD_BANK,
|
||||
self::METHOD_VIRTUAL,
|
||||
self::METHOD_CASH,
|
||||
self::METHOD_FREE,
|
||||
];
|
||||
|
||||
/** 결제 수단 라벨 */
|
||||
public const METHOD_LABELS = [
|
||||
self::METHOD_CARD => '카드',
|
||||
self::METHOD_BANK => '계좌이체',
|
||||
self::METHOD_VIRTUAL => '가상계좌',
|
||||
self::METHOD_CASH => '현금',
|
||||
self::METHOD_FREE => '무료',
|
||||
];
|
||||
|
||||
// =========================================================================
|
||||
// 모델 설정
|
||||
// =========================================================================
|
||||
|
||||
protected $fillable = [
|
||||
'subscription_id', 'amount', 'payment_method', 'transaction_id', 'paid_at', 'status', 'memo',
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'subscription_id',
|
||||
'amount',
|
||||
'payment_method',
|
||||
'transaction_id',
|
||||
'paid_at',
|
||||
'status',
|
||||
'memo',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function subscription()
|
||||
protected $casts = [
|
||||
'amount' => 'float',
|
||||
'paid_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $attributes = [
|
||||
'status' => self::STATUS_PENDING,
|
||||
'payment_method' => self::METHOD_CARD,
|
||||
];
|
||||
|
||||
// =========================================================================
|
||||
// 스코프
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 완료된 결제만
|
||||
*/
|
||||
public function scopeCompleted(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', self::STATUS_COMPLETED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 상태
|
||||
*/
|
||||
public function scopeOfStatus(Builder $query, string $status): Builder
|
||||
{
|
||||
return $query->where('status', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 결제 수단
|
||||
*/
|
||||
public function scopeOfMethod(Builder $query, string $method): Builder
|
||||
{
|
||||
return $query->where('payment_method', $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* 기간별 필터
|
||||
*/
|
||||
public function scopeBetweenDates(Builder $query, ?string $startDate, ?string $endDate): Builder
|
||||
{
|
||||
if ($startDate) {
|
||||
$query->where('paid_at', '>=', $startDate);
|
||||
}
|
||||
if ($endDate) {
|
||||
$query->where('paid_at', '<=', $endDate.' 23:59:59');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 관계
|
||||
// =========================================================================
|
||||
|
||||
public function subscription(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Subscription::class);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 접근자
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 상태 라벨
|
||||
*/
|
||||
public function getStatusLabelAttribute(): string
|
||||
{
|
||||
return self::STATUS_LABELS[$this->status] ?? $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 수단 라벨
|
||||
*/
|
||||
public function getPaymentMethodLabelAttribute(): string
|
||||
{
|
||||
return self::METHOD_LABELS[$this->payment_method] ?? $this->payment_method;
|
||||
}
|
||||
|
||||
/**
|
||||
* 포맷된 금액
|
||||
*/
|
||||
public function getFormattedAmountAttribute(): string
|
||||
{
|
||||
return number_format($this->amount).'원';
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 완료 여부
|
||||
*/
|
||||
public function getIsCompletedAttribute(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 환불 가능 여부
|
||||
*/
|
||||
public function getIsRefundableAttribute(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_COMPLETED;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 헬퍼 메서드
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 결제 완료 처리
|
||||
*/
|
||||
public function complete(?string $transactionId = null): bool
|
||||
{
|
||||
if ($this->status !== self::STATUS_PENDING) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->status = self::STATUS_COMPLETED;
|
||||
$this->paid_at = now();
|
||||
|
||||
if ($transactionId) {
|
||||
$this->transaction_id = $transactionId;
|
||||
}
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 실패 처리
|
||||
*/
|
||||
public function fail(?string $reason = null): bool
|
||||
{
|
||||
if ($this->status !== self::STATUS_PENDING) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->status = self::STATUS_FAILED;
|
||||
|
||||
if ($reason) {
|
||||
$this->memo = $reason;
|
||||
}
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 취소 처리
|
||||
*/
|
||||
public function cancel(?string $reason = null): bool
|
||||
{
|
||||
if (! in_array($this->status, [self::STATUS_PENDING, self::STATUS_COMPLETED])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->status = self::STATUS_CANCELLED;
|
||||
|
||||
if ($reason) {
|
||||
$this->memo = $reason;
|
||||
}
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 환불 처리
|
||||
*/
|
||||
public function refund(?string $reason = null): bool
|
||||
{
|
||||
if ($this->status !== self::STATUS_COMPLETED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->status = self::STATUS_REFUNDED;
|
||||
|
||||
if ($reason) {
|
||||
$this->memo = $reason;
|
||||
}
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,68 @@
|
||||
|
||||
namespace App\Models\Tenants;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* 요금제 모델
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name 요금제명
|
||||
* @property string $code 요금제 코드
|
||||
* @property string|null $description 설명
|
||||
* @property float $price 가격
|
||||
* @property string $billing_cycle 결제 주기
|
||||
* @property array|null $features 기능 목록
|
||||
* @property bool $is_active 활성 여부
|
||||
*
|
||||
* @mixin IdeHelperPlan
|
||||
*/
|
||||
class Plan extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
// =========================================================================
|
||||
// 상수 정의
|
||||
// =========================================================================
|
||||
|
||||
/** 결제 주기 */
|
||||
public const BILLING_MONTHLY = 'monthly';
|
||||
|
||||
public const BILLING_YEARLY = 'yearly';
|
||||
|
||||
public const BILLING_LIFETIME = 'lifetime';
|
||||
|
||||
public const BILLING_CYCLES = [
|
||||
self::BILLING_MONTHLY,
|
||||
self::BILLING_YEARLY,
|
||||
self::BILLING_LIFETIME,
|
||||
];
|
||||
|
||||
/** 결제 주기 라벨 */
|
||||
public const BILLING_CYCLE_LABELS = [
|
||||
self::BILLING_MONTHLY => '월간',
|
||||
self::BILLING_YEARLY => '연간',
|
||||
self::BILLING_LIFETIME => '평생',
|
||||
];
|
||||
|
||||
// =========================================================================
|
||||
// 모델 설정
|
||||
// =========================================================================
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'code', 'description', 'price', 'billing_cycle', 'features', 'is_active',
|
||||
'name',
|
||||
'code',
|
||||
'description',
|
||||
'price',
|
||||
'billing_cycle',
|
||||
'features',
|
||||
'is_active',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -22,8 +72,103 @@ class Plan extends Model
|
||||
'price' => 'float',
|
||||
];
|
||||
|
||||
public function subscriptions()
|
||||
protected $attributes = [
|
||||
'is_active' => true,
|
||||
'billing_cycle' => self::BILLING_MONTHLY,
|
||||
];
|
||||
|
||||
// =========================================================================
|
||||
// 스코프
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 활성 요금제만
|
||||
*/
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 주기별 필터
|
||||
*/
|
||||
public function scopeOfCycle(Builder $query, string $cycle): Builder
|
||||
{
|
||||
return $query->where('billing_cycle', $cycle);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 관계
|
||||
// =========================================================================
|
||||
|
||||
public function subscriptions(): HasMany
|
||||
{
|
||||
return $this->hasMany(Subscription::class);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 접근자
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 결제 주기 라벨
|
||||
*/
|
||||
public function getBillingCycleLabelAttribute(): string
|
||||
{
|
||||
return self::BILLING_CYCLE_LABELS[$this->billing_cycle] ?? $this->billing_cycle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 포맷된 가격
|
||||
*/
|
||||
public function getFormattedPriceAttribute(): string
|
||||
{
|
||||
return number_format($this->price).'원';
|
||||
}
|
||||
|
||||
/**
|
||||
* 활성 구독 수
|
||||
*/
|
||||
public function getActiveSubscriptionCountAttribute(): int
|
||||
{
|
||||
return $this->subscriptions()
|
||||
->where('status', Subscription::STATUS_ACTIVE)
|
||||
->count();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 헬퍼 메서드
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 월 환산 가격 계산
|
||||
*/
|
||||
public function getMonthlyPrice(): float
|
||||
{
|
||||
return match ($this->billing_cycle) {
|
||||
self::BILLING_YEARLY => round($this->price / 12, 2),
|
||||
self::BILLING_LIFETIME => 0,
|
||||
default => $this->price,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 연 환산 가격 계산
|
||||
*/
|
||||
public function getYearlyPrice(): float
|
||||
{
|
||||
return match ($this->billing_cycle) {
|
||||
self::BILLING_MONTHLY => $this->price * 12,
|
||||
self::BILLING_LIFETIME => 0,
|
||||
default => $this->price,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 기능 포함 여부
|
||||
*/
|
||||
public function hasFeature(string $feature): bool
|
||||
{
|
||||
return in_array($feature, $this->features ?? [], true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,36 +2,312 @@
|
||||
|
||||
namespace App\Models\Tenants;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* 구독 모델
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $tenant_id 테넌트 ID
|
||||
* @property int $plan_id 요금제 ID
|
||||
* @property Carbon $started_at 시작일
|
||||
* @property Carbon|null $ended_at 종료일
|
||||
* @property string $status 상태
|
||||
* @property Carbon|null $cancelled_at 취소일
|
||||
* @property string|null $cancel_reason 취소 사유
|
||||
*
|
||||
* @mixin IdeHelperSubscription
|
||||
*/
|
||||
class Subscription extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
// =========================================================================
|
||||
// 상수 정의
|
||||
// =========================================================================
|
||||
|
||||
/** 구독 상태 */
|
||||
public const STATUS_ACTIVE = 'active';
|
||||
|
||||
public const STATUS_CANCELLED = 'cancelled';
|
||||
|
||||
public const STATUS_EXPIRED = 'expired';
|
||||
|
||||
public const STATUS_PENDING = 'pending';
|
||||
|
||||
public const STATUS_SUSPENDED = 'suspended';
|
||||
|
||||
public const STATUSES = [
|
||||
self::STATUS_ACTIVE,
|
||||
self::STATUS_CANCELLED,
|
||||
self::STATUS_EXPIRED,
|
||||
self::STATUS_PENDING,
|
||||
self::STATUS_SUSPENDED,
|
||||
];
|
||||
|
||||
/** 상태 라벨 */
|
||||
public const STATUS_LABELS = [
|
||||
self::STATUS_ACTIVE => '활성',
|
||||
self::STATUS_CANCELLED => '취소됨',
|
||||
self::STATUS_EXPIRED => '만료됨',
|
||||
self::STATUS_PENDING => '대기',
|
||||
self::STATUS_SUSPENDED => '일시정지',
|
||||
];
|
||||
|
||||
// =========================================================================
|
||||
// 모델 설정
|
||||
// =========================================================================
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id', 'plan_id', 'started_at', 'ended_at', 'status',
|
||||
'tenant_id',
|
||||
'plan_id',
|
||||
'started_at',
|
||||
'ended_at',
|
||||
'status',
|
||||
'cancelled_at',
|
||||
'cancel_reason',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'started_at', 'ended_at',
|
||||
protected $casts = [
|
||||
'started_at' => 'datetime',
|
||||
'ended_at' => 'datetime',
|
||||
'cancelled_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function tenant()
|
||||
protected $attributes = [
|
||||
'status' => self::STATUS_PENDING,
|
||||
];
|
||||
|
||||
// =========================================================================
|
||||
// 스코프
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 활성 구독만
|
||||
*/
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', self::STATUS_ACTIVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 유효한 구독 (활성 + 미만료)
|
||||
*/
|
||||
public function scopeValid(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', self::STATUS_ACTIVE)
|
||||
->where(function ($q) {
|
||||
$q->whereNull('ended_at')
|
||||
->orWhere('ended_at', '>', now());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 만료 예정 (N일 이내)
|
||||
*/
|
||||
public function scopeExpiringWithin(Builder $query, int $days): Builder
|
||||
{
|
||||
return $query->where('status', self::STATUS_ACTIVE)
|
||||
->whereNotNull('ended_at')
|
||||
->where('ended_at', '<=', now()->addDays($days))
|
||||
->where('ended_at', '>', now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 테넌트
|
||||
*/
|
||||
public function scopeForTenant(Builder $query, int $tenantId): Builder
|
||||
{
|
||||
return $query->where('tenant_id', $tenantId);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 관계
|
||||
// =========================================================================
|
||||
|
||||
public function tenant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
|
||||
public function plan()
|
||||
public function plan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Plan::class);
|
||||
}
|
||||
|
||||
public function payments()
|
||||
public function payments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Payment::class);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 접근자
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 상태 라벨
|
||||
*/
|
||||
public function getStatusLabelAttribute(): string
|
||||
{
|
||||
return self::STATUS_LABELS[$this->status] ?? $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 만료 여부
|
||||
*/
|
||||
public function getIsExpiredAttribute(): bool
|
||||
{
|
||||
if (! $this->ended_at) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->ended_at->isPast();
|
||||
}
|
||||
|
||||
/**
|
||||
* 남은 일수
|
||||
*/
|
||||
public function getRemainingDaysAttribute(): ?int
|
||||
{
|
||||
if (! $this->ended_at) {
|
||||
return null; // 무제한
|
||||
}
|
||||
|
||||
if ($this->is_expired) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return now()->diffInDays($this->ended_at, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 유효 여부
|
||||
*/
|
||||
public function getIsValidAttribute(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_ACTIVE && ! $this->is_expired;
|
||||
}
|
||||
|
||||
/**
|
||||
* 총 결제 금액
|
||||
*/
|
||||
public function getTotalPaidAttribute(): float
|
||||
{
|
||||
return (float) $this->payments()
|
||||
->where('status', Payment::STATUS_COMPLETED)
|
||||
->sum('amount');
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 헬퍼 메서드
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 구독 활성화
|
||||
*/
|
||||
public function activate(): bool
|
||||
{
|
||||
if ($this->status !== self::STATUS_PENDING) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->status = self::STATUS_ACTIVE;
|
||||
$this->started_at = $this->started_at ?? now();
|
||||
|
||||
// 종료일 계산 (요금제 주기에 따라)
|
||||
if (! $this->ended_at && $this->plan) {
|
||||
$this->ended_at = match ($this->plan->billing_cycle) {
|
||||
Plan::BILLING_MONTHLY => $this->started_at->copy()->addMonth(),
|
||||
Plan::BILLING_YEARLY => $this->started_at->copy()->addYear(),
|
||||
Plan::BILLING_LIFETIME => null,
|
||||
default => $this->started_at->copy()->addMonth(),
|
||||
};
|
||||
}
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 갱신
|
||||
*/
|
||||
public function renew(?Carbon $newEndDate = null): bool
|
||||
{
|
||||
if ($this->status !== self::STATUS_ACTIVE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($newEndDate) {
|
||||
$this->ended_at = $newEndDate;
|
||||
} elseif ($this->plan) {
|
||||
$baseDate = $this->ended_at ?? now();
|
||||
$this->ended_at = match ($this->plan->billing_cycle) {
|
||||
Plan::BILLING_MONTHLY => $baseDate->copy()->addMonth(),
|
||||
Plan::BILLING_YEARLY => $baseDate->copy()->addYear(),
|
||||
Plan::BILLING_LIFETIME => null,
|
||||
default => $baseDate->copy()->addMonth(),
|
||||
};
|
||||
}
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 취소
|
||||
*/
|
||||
public function cancel(?string $reason = null): bool
|
||||
{
|
||||
if (! in_array($this->status, [self::STATUS_ACTIVE, self::STATUS_PENDING])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->status = self::STATUS_CANCELLED;
|
||||
$this->cancelled_at = now();
|
||||
$this->cancel_reason = $reason;
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 일시정지
|
||||
*/
|
||||
public function suspend(): bool
|
||||
{
|
||||
if ($this->status !== self::STATUS_ACTIVE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->status = self::STATUS_SUSPENDED;
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 재개
|
||||
*/
|
||||
public function resume(): bool
|
||||
{
|
||||
if ($this->status !== self::STATUS_SUSPENDED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->status = self::STATUS_ACTIVE;
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 취소 가능 여부
|
||||
*/
|
||||
public function isCancellable(): bool
|
||||
{
|
||||
return in_array($this->status, [self::STATUS_ACTIVE, self::STATUS_PENDING]);
|
||||
}
|
||||
}
|
||||
|
||||
276
app/Services/PaymentService.php
Normal file
276
app/Services/PaymentService.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Tenants\Payment;
|
||||
use App\Models\Tenants\Subscription;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
class PaymentService extends Service
|
||||
{
|
||||
// =========================================================================
|
||||
// 결제 목록/상세
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 결제 목록
|
||||
*/
|
||||
public function index(array $params): LengthAwarePaginator
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
// 테넌트의 구독에 속한 결제만 조회
|
||||
$subscriptionIds = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->pluck('id');
|
||||
|
||||
$query = Payment::query()
|
||||
->whereIn('subscription_id', $subscriptionIds)
|
||||
->with(['subscription.plan:id,name,code']);
|
||||
|
||||
// 상태 필터
|
||||
if (! empty($params['status'])) {
|
||||
$query->ofStatus($params['status']);
|
||||
}
|
||||
|
||||
// 결제 수단 필터
|
||||
if (! empty($params['payment_method'])) {
|
||||
$query->ofMethod($params['payment_method']);
|
||||
}
|
||||
|
||||
// 날짜 범위 필터
|
||||
$query->betweenDates(
|
||||
$params['start_date'] ?? null,
|
||||
$params['end_date'] ?? null
|
||||
);
|
||||
|
||||
// 검색 (거래 ID, 메모)
|
||||
if (! empty($params['search'])) {
|
||||
$search = $params['search'];
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('transaction_id', 'like', "%{$search}%")
|
||||
->orWhere('memo', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
// 정렬
|
||||
$sortBy = $params['sort_by'] ?? 'created_at';
|
||||
$sortDir = $params['sort_dir'] ?? 'desc';
|
||||
$query->orderBy($sortBy, $sortDir);
|
||||
|
||||
$perPage = $params['per_page'] ?? 20;
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 상세
|
||||
*/
|
||||
public function show(int $id): Payment
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
// 테넌트 검증을 위해 구독 통해 조회
|
||||
$subscriptionIds = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->pluck('id');
|
||||
|
||||
return Payment::query()
|
||||
->whereIn('subscription_id', $subscriptionIds)
|
||||
->with(['subscription.plan'])
|
||||
->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 요약 통계
|
||||
*/
|
||||
public function summary(array $params = []): array
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$subscriptionIds = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->pluck('id');
|
||||
|
||||
$query = Payment::query()
|
||||
->whereIn('subscription_id', $subscriptionIds);
|
||||
|
||||
// 날짜 범위 필터
|
||||
if (! empty($params['start_date']) || ! empty($params['end_date'])) {
|
||||
$query->betweenDates(
|
||||
$params['start_date'] ?? null,
|
||||
$params['end_date'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
$stats = $query->selectRaw('
|
||||
COUNT(*) as total_count,
|
||||
SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) as completed_count,
|
||||
SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) as pending_count,
|
||||
SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) as failed_count,
|
||||
SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) as cancelled_count,
|
||||
SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) as refunded_count,
|
||||
SUM(CASE WHEN status = ? THEN amount ELSE 0 END) as total_completed_amount,
|
||||
SUM(CASE WHEN status = ? THEN amount ELSE 0 END) as total_refunded_amount
|
||||
', [
|
||||
Payment::STATUS_COMPLETED,
|
||||
Payment::STATUS_PENDING,
|
||||
Payment::STATUS_FAILED,
|
||||
Payment::STATUS_CANCELLED,
|
||||
Payment::STATUS_REFUNDED,
|
||||
Payment::STATUS_COMPLETED,
|
||||
Payment::STATUS_REFUNDED,
|
||||
])->first();
|
||||
|
||||
// 결제 수단별 집계
|
||||
$byMethod = Payment::query()
|
||||
->whereIn('subscription_id', $subscriptionIds)
|
||||
->completed()
|
||||
->selectRaw('payment_method, COUNT(*) as count, SUM(amount) as total_amount')
|
||||
->groupBy('payment_method')
|
||||
->get()
|
||||
->keyBy('payment_method')
|
||||
->map(fn ($item) => [
|
||||
'count' => (int) $item->count,
|
||||
'total_amount' => (float) $item->total_amount,
|
||||
])
|
||||
->toArray();
|
||||
|
||||
return [
|
||||
'total_count' => (int) $stats->total_count,
|
||||
'completed_count' => (int) $stats->completed_count,
|
||||
'pending_count' => (int) $stats->pending_count,
|
||||
'failed_count' => (int) $stats->failed_count,
|
||||
'cancelled_count' => (int) $stats->cancelled_count,
|
||||
'refunded_count' => (int) $stats->refunded_count,
|
||||
'total_completed_amount' => (float) $stats->total_completed_amount,
|
||||
'total_refunded_amount' => (float) $stats->total_refunded_amount,
|
||||
'net_amount' => (float) ($stats->total_completed_amount - $stats->total_refunded_amount),
|
||||
'by_method' => $byMethod,
|
||||
];
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 결제 처리
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 결제 생성 (수동)
|
||||
*/
|
||||
public function store(array $data): Payment
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
// 구독 확인
|
||||
$subscription = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->findOrFail($data['subscription_id']);
|
||||
|
||||
return DB::transaction(function () use ($data, $subscription, $userId) {
|
||||
$payment = Payment::create([
|
||||
'subscription_id' => $subscription->id,
|
||||
'amount' => $data['amount'],
|
||||
'payment_method' => $data['payment_method'] ?? Payment::METHOD_CARD,
|
||||
'transaction_id' => $data['transaction_id'] ?? null,
|
||||
'status' => Payment::STATUS_PENDING,
|
||||
'memo' => $data['memo'] ?? null,
|
||||
'created_by' => $userId,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
// 자동 완료 처리
|
||||
if (! empty($data['auto_complete']) && $data['auto_complete']) {
|
||||
$payment->complete($data['transaction_id'] ?? null);
|
||||
}
|
||||
|
||||
return $payment->fresh(['subscription.plan']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 완료 처리
|
||||
*/
|
||||
public function complete(int $id, ?string $transactionId = null): Payment
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$subscriptionIds = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->pluck('id');
|
||||
|
||||
$payment = Payment::query()
|
||||
->whereIn('subscription_id', $subscriptionIds)
|
||||
->findOrFail($id);
|
||||
|
||||
if (! $payment->complete($transactionId)) {
|
||||
throw new BadRequestHttpException(__('error.payment.not_completable'));
|
||||
}
|
||||
|
||||
$payment->updated_by = $userId;
|
||||
$payment->save();
|
||||
|
||||
// 구독이 대기 중이면 활성화
|
||||
$subscription = $payment->subscription;
|
||||
if ($subscription->status === Subscription::STATUS_PENDING) {
|
||||
$subscription->activate();
|
||||
}
|
||||
|
||||
return $payment->fresh(['subscription.plan']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제 취소
|
||||
*/
|
||||
public function cancel(int $id, ?string $reason = null): Payment
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$subscriptionIds = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->pluck('id');
|
||||
|
||||
$payment = Payment::query()
|
||||
->whereIn('subscription_id', $subscriptionIds)
|
||||
->findOrFail($id);
|
||||
|
||||
if (! $payment->cancel($reason)) {
|
||||
throw new BadRequestHttpException(__('error.payment.not_cancellable'));
|
||||
}
|
||||
|
||||
$payment->updated_by = $userId;
|
||||
$payment->save();
|
||||
|
||||
return $payment->fresh(['subscription.plan']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 환불 처리
|
||||
*/
|
||||
public function refund(int $id, ?string $reason = null): Payment
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$subscriptionIds = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->pluck('id');
|
||||
|
||||
$payment = Payment::query()
|
||||
->whereIn('subscription_id', $subscriptionIds)
|
||||
->findOrFail($id);
|
||||
|
||||
if (! $payment->refund($reason)) {
|
||||
throw new BadRequestHttpException(__('error.payment.not_refundable'));
|
||||
}
|
||||
|
||||
$payment->updated_by = $userId;
|
||||
$payment->save();
|
||||
|
||||
return $payment->fresh(['subscription.plan']);
|
||||
}
|
||||
}
|
||||
164
app/Services/PlanService.php
Normal file
164
app/Services/PlanService.php
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Tenants\Plan;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class PlanService extends Service
|
||||
{
|
||||
// =========================================================================
|
||||
// 요금제 목록/상세
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 요금제 목록 (관리자용)
|
||||
*/
|
||||
public function index(array $params): LengthAwarePaginator
|
||||
{
|
||||
$query = Plan::query();
|
||||
|
||||
// 활성 상태 필터
|
||||
if (isset($params['is_active'])) {
|
||||
$query->where('is_active', (bool) $params['is_active']);
|
||||
}
|
||||
|
||||
// 결제 주기 필터
|
||||
if (! empty($params['billing_cycle'])) {
|
||||
$query->ofCycle($params['billing_cycle']);
|
||||
}
|
||||
|
||||
// 검색 (이름, 코드, 설명)
|
||||
if (! empty($params['search'])) {
|
||||
$search = $params['search'];
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'like', "%{$search}%")
|
||||
->orWhere('code', 'like', "%{$search}%")
|
||||
->orWhere('description', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
// 정렬
|
||||
$sortBy = $params['sort_by'] ?? 'price';
|
||||
$sortDir = $params['sort_dir'] ?? 'asc';
|
||||
$query->orderBy($sortBy, $sortDir);
|
||||
|
||||
$perPage = $params['per_page'] ?? 20;
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 활성 요금제 목록 (공개용)
|
||||
*/
|
||||
public function active(): Collection
|
||||
{
|
||||
return Plan::active()
|
||||
->orderBy('price', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 요금제 상세
|
||||
*/
|
||||
public function show(int $id): Plan
|
||||
{
|
||||
return Plan::query()
|
||||
->withCount(['subscriptions as active_subscriptions_count' => function ($q) {
|
||||
$q->where('status', 'active');
|
||||
}])
|
||||
->findOrFail($id);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 요금제 생성/수정/삭제
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 요금제 생성
|
||||
*/
|
||||
public function store(array $data): Plan
|
||||
{
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
return Plan::create([
|
||||
'name' => $data['name'],
|
||||
'code' => $data['code'],
|
||||
'description' => $data['description'] ?? null,
|
||||
'price' => $data['price'],
|
||||
'billing_cycle' => $data['billing_cycle'] ?? Plan::BILLING_MONTHLY,
|
||||
'features' => $data['features'] ?? null,
|
||||
'is_active' => $data['is_active'] ?? true,
|
||||
'created_by' => $userId,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 요금제 수정
|
||||
*/
|
||||
public function update(int $id, array $data): Plan
|
||||
{
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$plan = Plan::findOrFail($id);
|
||||
|
||||
$plan->fill([
|
||||
'name' => $data['name'] ?? $plan->name,
|
||||
'code' => $data['code'] ?? $plan->code,
|
||||
'description' => $data['description'] ?? $plan->description,
|
||||
'price' => $data['price'] ?? $plan->price,
|
||||
'billing_cycle' => $data['billing_cycle'] ?? $plan->billing_cycle,
|
||||
'features' => $data['features'] ?? $plan->features,
|
||||
'is_active' => $data['is_active'] ?? $plan->is_active,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
$plan->save();
|
||||
|
||||
return $plan->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* 요금제 삭제
|
||||
*/
|
||||
public function destroy(int $id): bool
|
||||
{
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$plan = Plan::findOrFail($id);
|
||||
|
||||
// 활성 구독이 있으면 삭제 불가
|
||||
$activeCount = $plan->subscriptions()
|
||||
->whereIn('status', ['active', 'pending'])
|
||||
->count();
|
||||
|
||||
if ($activeCount > 0) {
|
||||
throw new \Symfony\Component\HttpKernel\Exception\BadRequestHttpException(
|
||||
__('error.plan.has_active_subscriptions')
|
||||
);
|
||||
}
|
||||
|
||||
$plan->deleted_by = $userId;
|
||||
$plan->save();
|
||||
$plan->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 요금제 활성/비활성 토글
|
||||
*/
|
||||
public function toggle(int $id): Plan
|
||||
{
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$plan = Plan::findOrFail($id);
|
||||
$plan->is_active = ! $plan->is_active;
|
||||
$plan->updated_by = $userId;
|
||||
$plan->save();
|
||||
|
||||
return $plan;
|
||||
}
|
||||
}
|
||||
297
app/Services/SubscriptionService.php
Normal file
297
app/Services/SubscriptionService.php
Normal file
@@ -0,0 +1,297 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Tenants\Payment;
|
||||
use App\Models\Tenants\Plan;
|
||||
use App\Models\Tenants\Subscription;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
class SubscriptionService extends Service
|
||||
{
|
||||
// =========================================================================
|
||||
// 구독 목록/상세
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 구독 목록
|
||||
*/
|
||||
public function index(array $params): LengthAwarePaginator
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$query = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->with(['plan:id,name,code,price,billing_cycle']);
|
||||
|
||||
// 상태 필터
|
||||
if (! empty($params['status'])) {
|
||||
$query->where('status', $params['status']);
|
||||
}
|
||||
|
||||
// 유효한 구독만
|
||||
if (! empty($params['valid_only']) && $params['valid_only']) {
|
||||
$query->valid();
|
||||
}
|
||||
|
||||
// 만료 예정 (N일 이내)
|
||||
if (! empty($params['expiring_within'])) {
|
||||
$query->expiringWithin((int) $params['expiring_within']);
|
||||
}
|
||||
|
||||
// 날짜 범위 필터
|
||||
if (! empty($params['start_date'])) {
|
||||
$query->where('started_at', '>=', $params['start_date']);
|
||||
}
|
||||
if (! empty($params['end_date'])) {
|
||||
$query->where('started_at', '<=', $params['end_date']);
|
||||
}
|
||||
|
||||
// 정렬
|
||||
$sortBy = $params['sort_by'] ?? 'started_at';
|
||||
$sortDir = $params['sort_dir'] ?? 'desc';
|
||||
$query->orderBy($sortBy, $sortDir);
|
||||
|
||||
$perPage = $params['per_page'] ?? 20;
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 현재 활성 구독
|
||||
*/
|
||||
public function current(): ?Subscription
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
return Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->valid()
|
||||
->with(['plan', 'payments' => function ($q) {
|
||||
$q->completed()->orderBy('paid_at', 'desc')->limit(5);
|
||||
}])
|
||||
->orderBy('started_at', 'desc')
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 상세
|
||||
*/
|
||||
public function show(int $id): Subscription
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
return Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->with([
|
||||
'plan',
|
||||
'payments' => function ($q) {
|
||||
$q->orderBy('paid_at', 'desc');
|
||||
},
|
||||
])
|
||||
->findOrFail($id);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 구독 생성/취소
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 구독 생성 (결제 포함)
|
||||
*/
|
||||
public function store(array $data): Subscription
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
// 요금제 확인
|
||||
$plan = Plan::active()->findOrFail($data['plan_id']);
|
||||
|
||||
// 이미 활성 구독이 있는지 확인
|
||||
$existingSubscription = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->valid()
|
||||
->first();
|
||||
|
||||
if ($existingSubscription) {
|
||||
throw new BadRequestHttpException(__('error.subscription.already_active'));
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($data, $plan, $tenantId, $userId) {
|
||||
// 구독 생성
|
||||
$subscription = Subscription::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'plan_id' => $plan->id,
|
||||
'started_at' => $data['started_at'] ?? now(),
|
||||
'status' => Subscription::STATUS_PENDING,
|
||||
'created_by' => $userId,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
// 결제 생성 (무료 요금제가 아닌 경우)
|
||||
if ($plan->price > 0) {
|
||||
$payment = Payment::create([
|
||||
'subscription_id' => $subscription->id,
|
||||
'amount' => $plan->price,
|
||||
'payment_method' => $data['payment_method'] ?? Payment::METHOD_CARD,
|
||||
'status' => Payment::STATUS_PENDING,
|
||||
'created_by' => $userId,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
// 결제 완료 처리 (실제 PG 연동 시 수정 필요)
|
||||
if (! empty($data['auto_complete']) && $data['auto_complete']) {
|
||||
$payment->complete($data['transaction_id'] ?? null);
|
||||
|
||||
// 구독 활성화
|
||||
$subscription->activate();
|
||||
}
|
||||
} else {
|
||||
// 무료 요금제는 바로 활성화
|
||||
Payment::create([
|
||||
'subscription_id' => $subscription->id,
|
||||
'amount' => 0,
|
||||
'payment_method' => Payment::METHOD_FREE,
|
||||
'status' => Payment::STATUS_COMPLETED,
|
||||
'paid_at' => now(),
|
||||
'created_by' => $userId,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
$subscription->activate();
|
||||
}
|
||||
|
||||
return $subscription->fresh(['plan', 'payments']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 취소
|
||||
*/
|
||||
public function cancel(int $id, ?string $reason = null): Subscription
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$subscription = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->findOrFail($id);
|
||||
|
||||
if (! $subscription->isCancellable()) {
|
||||
throw new BadRequestHttpException(__('error.subscription.not_cancellable'));
|
||||
}
|
||||
|
||||
$subscription->cancel($reason);
|
||||
$subscription->updated_by = $userId;
|
||||
$subscription->save();
|
||||
|
||||
return $subscription->fresh(['plan']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 갱신
|
||||
*/
|
||||
public function renew(int $id, array $data = []): Subscription
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$subscription = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->findOrFail($id);
|
||||
|
||||
if ($subscription->status !== Subscription::STATUS_ACTIVE) {
|
||||
throw new BadRequestHttpException(__('error.subscription.not_renewable'));
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($subscription, $data, $userId) {
|
||||
$plan = $subscription->plan;
|
||||
|
||||
// 결제 생성
|
||||
if ($plan->price > 0) {
|
||||
$payment = Payment::create([
|
||||
'subscription_id' => $subscription->id,
|
||||
'amount' => $plan->price,
|
||||
'payment_method' => $data['payment_method'] ?? Payment::METHOD_CARD,
|
||||
'status' => Payment::STATUS_PENDING,
|
||||
'created_by' => $userId,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
// 결제 완료 처리
|
||||
if (! empty($data['auto_complete']) && $data['auto_complete']) {
|
||||
$payment->complete($data['transaction_id'] ?? null);
|
||||
$subscription->renew();
|
||||
}
|
||||
} else {
|
||||
// 무료 갱신
|
||||
Payment::create([
|
||||
'subscription_id' => $subscription->id,
|
||||
'amount' => 0,
|
||||
'payment_method' => Payment::METHOD_FREE,
|
||||
'status' => Payment::STATUS_COMPLETED,
|
||||
'paid_at' => now(),
|
||||
'created_by' => $userId,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
$subscription->renew();
|
||||
}
|
||||
|
||||
$subscription->updated_by = $userId;
|
||||
$subscription->save();
|
||||
|
||||
return $subscription->fresh(['plan', 'payments']);
|
||||
});
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 구독 상태 관리
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 구독 일시정지
|
||||
*/
|
||||
public function suspend(int $id): Subscription
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$subscription = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->findOrFail($id);
|
||||
|
||||
if (! $subscription->suspend()) {
|
||||
throw new BadRequestHttpException(__('error.subscription.not_suspendable'));
|
||||
}
|
||||
|
||||
$subscription->updated_by = $userId;
|
||||
$subscription->save();
|
||||
|
||||
return $subscription->fresh(['plan']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 구독 재개
|
||||
*/
|
||||
public function resume(int $id): Subscription
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$subscription = Subscription::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->findOrFail($id);
|
||||
|
||||
if (! $subscription->resume()) {
|
||||
throw new BadRequestHttpException(__('error.subscription.not_resumable'));
|
||||
}
|
||||
|
||||
$subscription->updated_by = $userId;
|
||||
$subscription->save();
|
||||
|
||||
return $subscription->fresh(['plan']);
|
||||
}
|
||||
}
|
||||
364
app/Swagger/v1/PaymentApi.php
Normal file
364
app/Swagger/v1/PaymentApi.php
Normal file
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
|
||||
namespace App\Swagger\v1;
|
||||
|
||||
/**
|
||||
* @OA\Tag(name="Payments", description="결제 관리")
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="Payment",
|
||||
* type="object",
|
||||
* description="결제 정보",
|
||||
*
|
||||
* @OA\Property(property="id", type="integer", example=1, description="결제 ID"),
|
||||
* @OA\Property(property="subscription_id", type="integer", example=1, description="구독 ID"),
|
||||
* @OA\Property(property="amount", type="number", format="float", example=29000, description="결제 금액"),
|
||||
* @OA\Property(property="payment_method", type="string", enum={"card","bank","virtual","cash","free"}, example="card", description="결제 수단"),
|
||||
* @OA\Property(property="payment_method_label", type="string", example="카드", description="결제 수단 라벨"),
|
||||
* @OA\Property(property="transaction_id", type="string", example="TXN123456789", nullable=true, description="PG 거래 ID"),
|
||||
* @OA\Property(property="paid_at", type="string", format="date-time", example="2025-01-15T10:30:00", nullable=true, description="결제일시"),
|
||||
* @OA\Property(property="status", type="string", enum={"pending","completed","failed","cancelled","refunded"}, example="completed", description="상태"),
|
||||
* @OA\Property(property="status_label", type="string", example="완료", description="상태 라벨"),
|
||||
* @OA\Property(property="memo", type="string", example="정기 결제", nullable=true, description="메모"),
|
||||
* @OA\Property(property="formatted_amount", type="string", example="29,000원", description="포맷된 금액"),
|
||||
* @OA\Property(property="is_completed", type="boolean", example=true, description="완료 여부"),
|
||||
* @OA\Property(property="is_refundable", type="boolean", example=true, description="환불 가능 여부"),
|
||||
* @OA\Property(property="subscription", type="object", nullable=true,
|
||||
* @OA\Property(property="id", type="integer", example=1),
|
||||
* @OA\Property(property="plan", type="object",
|
||||
* @OA\Property(property="id", type="integer", example=1),
|
||||
* @OA\Property(property="name", type="string", example="스타터"),
|
||||
* @OA\Property(property="code", type="string", example="starter")
|
||||
* ),
|
||||
* description="구독 정보"
|
||||
* ),
|
||||
* @OA\Property(property="created_at", type="string", format="date-time"),
|
||||
* @OA\Property(property="updated_at", type="string", format="date-time")
|
||||
* )
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="PaymentCreateRequest",
|
||||
* type="object",
|
||||
* required={"subscription_id","amount","payment_method"},
|
||||
* description="결제 등록 요청 (수동)",
|
||||
*
|
||||
* @OA\Property(property="subscription_id", type="integer", example=1, description="구독 ID"),
|
||||
* @OA\Property(property="amount", type="number", format="float", example=29000, minimum=0, description="결제 금액"),
|
||||
* @OA\Property(property="payment_method", type="string", enum={"card","bank","virtual","cash","free"}, example="card", description="결제 수단"),
|
||||
* @OA\Property(property="transaction_id", type="string", example="TXN123456789", maxLength=100, nullable=true, description="PG 거래 ID"),
|
||||
* @OA\Property(property="memo", type="string", example="정기 결제", maxLength=500, nullable=true, description="메모"),
|
||||
* @OA\Property(property="auto_complete", type="boolean", example=true, description="자동 완료 처리")
|
||||
* )
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="PaymentActionRequest",
|
||||
* type="object",
|
||||
* description="결제 액션 요청",
|
||||
*
|
||||
* @OA\Property(property="reason", type="string", example="고객 요청", maxLength=500, nullable=true, description="사유"),
|
||||
* @OA\Property(property="transaction_id", type="string", example="TXN123456789", maxLength=100, nullable=true, description="PG 거래 ID")
|
||||
* )
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="PaymentSummary",
|
||||
* type="object",
|
||||
* description="결제 요약 통계",
|
||||
*
|
||||
* @OA\Property(property="total_count", type="integer", example=50, description="전체 건수"),
|
||||
* @OA\Property(property="completed_count", type="integer", example=45, description="완료 건수"),
|
||||
* @OA\Property(property="pending_count", type="integer", example=2, description="대기 건수"),
|
||||
* @OA\Property(property="failed_count", type="integer", example=1, description="실패 건수"),
|
||||
* @OA\Property(property="cancelled_count", type="integer", example=1, description="취소 건수"),
|
||||
* @OA\Property(property="refunded_count", type="integer", example=1, description="환불 건수"),
|
||||
* @OA\Property(property="total_completed_amount", type="number", format="float", example=1305000, description="완료 총액"),
|
||||
* @OA\Property(property="total_refunded_amount", type="number", format="float", example=29000, description="환불 총액"),
|
||||
* @OA\Property(property="net_amount", type="number", format="float", example=1276000, description="순 금액"),
|
||||
* @OA\Property(property="by_method", type="object",
|
||||
* @OA\Property(property="card", type="object",
|
||||
* @OA\Property(property="count", type="integer", example=40),
|
||||
* @OA\Property(property="total_amount", type="number", format="float", example=1160000)
|
||||
* ),
|
||||
* @OA\Property(property="bank", type="object",
|
||||
* @OA\Property(property="count", type="integer", example=5),
|
||||
* @OA\Property(property="total_amount", type="number", format="float", example=145000)
|
||||
* ),
|
||||
* description="결제 수단별 집계"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
class PaymentApi
|
||||
{
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/api/v1/payments",
|
||||
* tags={"Payments"},
|
||||
* summary="결제 목록 조회",
|
||||
* description="테넌트의 결제 목록을 조회합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="status", in="query", description="상태 필터", @OA\Schema(type="string", enum={"pending","completed","failed","cancelled","refunded"})),
|
||||
* @OA\Parameter(name="payment_method", in="query", description="결제 수단", @OA\Schema(type="string", enum={"card","bank","virtual","cash","free"})),
|
||||
* @OA\Parameter(name="start_date", in="query", description="시작일 (결제일 기준)", @OA\Schema(type="string", format="date")),
|
||||
* @OA\Parameter(name="end_date", in="query", description="종료일 (결제일 기준)", @OA\Schema(type="string", format="date")),
|
||||
* @OA\Parameter(name="search", in="query", description="검색어 (거래ID, 메모)", @OA\Schema(type="string", maxLength=100)),
|
||||
* @OA\Parameter(name="sort_by", in="query", description="정렬 기준", @OA\Schema(type="string", enum={"created_at","paid_at","amount"}, default="created_at")),
|
||||
* @OA\Parameter(name="sort_dir", in="query", description="정렬 방향", @OA\Schema(type="string", enum={"asc","desc"}, default="desc")),
|
||||
* @OA\Parameter(ref="#/components/parameters/Page"),
|
||||
* @OA\Parameter(ref="#/components/parameters/Size"),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="조회 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(
|
||||
* property="data",
|
||||
* type="object",
|
||||
* @OA\Property(property="current_page", type="integer", example=1),
|
||||
* @OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/Payment")),
|
||||
* @OA\Property(property="per_page", type="integer", example=20),
|
||||
* @OA\Property(property="total", type="integer", example=50)
|
||||
* )
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function index() {}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/api/v1/payments/summary",
|
||||
* tags={"Payments"},
|
||||
* summary="결제 요약 통계",
|
||||
* description="테넌트의 결제 요약 통계를 조회합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="start_date", in="query", description="시작일", @OA\Schema(type="string", format="date")),
|
||||
* @OA\Parameter(name="end_date", in="query", description="종료일", @OA\Schema(type="string", format="date")),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="조회 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/PaymentSummary")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function summary() {}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/api/v1/payments/{id}",
|
||||
* tags={"Payments"},
|
||||
* summary="결제 상세 조회",
|
||||
* description="결제 상세 정보를 조회합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="결제 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="조회 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Payment")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="결제 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function show() {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/payments",
|
||||
* tags={"Payments"},
|
||||
* summary="결제 등록 (수동)",
|
||||
* description="수동으로 결제를 등록합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* required=true,
|
||||
*
|
||||
* @OA\JsonContent(ref="#/components/schemas/PaymentCreateRequest")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=201,
|
||||
* description="등록 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Payment")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="잘못된 요청", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="구독 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function store() {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/payments/{id}/complete",
|
||||
* tags={"Payments"},
|
||||
* summary="결제 완료 처리",
|
||||
* description="대기 중인 결제를 완료 처리합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="결제 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* required=false,
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
*
|
||||
* @OA\Property(property="transaction_id", type="string", example="TXN123456789", description="PG 거래 ID")
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="완료 처리 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Payment")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="완료 처리 불가 상태", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="결제 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function complete() {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/payments/{id}/cancel",
|
||||
* tags={"Payments"},
|
||||
* summary="결제 취소",
|
||||
* description="결제를 취소합니다. 대기(pending) 또는 완료(completed) 상태에서만 가능합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="결제 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* required=false,
|
||||
*
|
||||
* @OA\JsonContent(ref="#/components/schemas/PaymentActionRequest")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="취소 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Payment")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="취소 불가 상태", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="결제 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function cancel() {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/payments/{id}/refund",
|
||||
* tags={"Payments"},
|
||||
* summary="환불 처리",
|
||||
* description="완료된 결제를 환불 처리합니다. 완료(completed) 상태에서만 가능합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="결제 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* required=false,
|
||||
*
|
||||
* @OA\JsonContent(ref="#/components/schemas/PaymentActionRequest")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="환불 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Payment")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="환불 불가 상태", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="결제 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function refund() {}
|
||||
}
|
||||
303
app/Swagger/v1/PlanApi.php
Normal file
303
app/Swagger/v1/PlanApi.php
Normal file
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
|
||||
namespace App\Swagger\v1;
|
||||
|
||||
/**
|
||||
* @OA\Tag(name="Plans", description="요금제 관리")
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="Plan",
|
||||
* type="object",
|
||||
* description="요금제 정보",
|
||||
*
|
||||
* @OA\Property(property="id", type="integer", example=1, description="요금제 ID"),
|
||||
* @OA\Property(property="name", type="string", example="스타터", description="요금제명"),
|
||||
* @OA\Property(property="code", type="string", example="starter", description="요금제 코드"),
|
||||
* @OA\Property(property="description", type="string", example="기본 기능을 제공하는 요금제입니다.", nullable=true, description="설명"),
|
||||
* @OA\Property(property="price", type="number", format="float", example=29000, description="가격"),
|
||||
* @OA\Property(property="billing_cycle", type="string", enum={"monthly","yearly","lifetime"}, example="monthly", description="결제 주기"),
|
||||
* @OA\Property(property="billing_cycle_label", type="string", example="월간", description="결제 주기 라벨"),
|
||||
* @OA\Property(property="features", type="array", @OA\Items(type="string"), example={"사용자 5명","저장공간 10GB"}, nullable=true, description="기능 목록"),
|
||||
* @OA\Property(property="is_active", type="boolean", example=true, description="활성 여부"),
|
||||
* @OA\Property(property="formatted_price", type="string", example="29,000원", description="포맷된 가격"),
|
||||
* @OA\Property(property="active_subscriptions_count", type="integer", example=15, description="활성 구독 수"),
|
||||
* @OA\Property(property="created_at", type="string", format="date-time"),
|
||||
* @OA\Property(property="updated_at", type="string", format="date-time")
|
||||
* )
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="PlanCreateRequest",
|
||||
* type="object",
|
||||
* required={"name","code","price","billing_cycle"},
|
||||
* description="요금제 등록 요청",
|
||||
*
|
||||
* @OA\Property(property="name", type="string", example="스타터", maxLength=100, description="요금제명"),
|
||||
* @OA\Property(property="code", type="string", example="starter", maxLength=50, description="요금제 코드 (unique)"),
|
||||
* @OA\Property(property="description", type="string", example="기본 기능을 제공하는 요금제입니다.", maxLength=500, nullable=true, description="설명"),
|
||||
* @OA\Property(property="price", type="number", format="float", example=29000, minimum=0, description="가격"),
|
||||
* @OA\Property(property="billing_cycle", type="string", enum={"monthly","yearly","lifetime"}, example="monthly", description="결제 주기"),
|
||||
* @OA\Property(property="features", type="array", @OA\Items(type="string", maxLength=200), example={"사용자 5명","저장공간 10GB"}, nullable=true, description="기능 목록"),
|
||||
* @OA\Property(property="is_active", type="boolean", example=true, description="활성 여부")
|
||||
* )
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="PlanUpdateRequest",
|
||||
* type="object",
|
||||
* description="요금제 수정 요청",
|
||||
*
|
||||
* @OA\Property(property="name", type="string", example="스타터", maxLength=100, description="요금제명"),
|
||||
* @OA\Property(property="code", type="string", example="starter", maxLength=50, description="요금제 코드"),
|
||||
* @OA\Property(property="description", type="string", example="기본 기능을 제공하는 요금제입니다.", maxLength=500, nullable=true, description="설명"),
|
||||
* @OA\Property(property="price", type="number", format="float", example=29000, minimum=0, description="가격"),
|
||||
* @OA\Property(property="billing_cycle", type="string", enum={"monthly","yearly","lifetime"}, example="monthly", description="결제 주기"),
|
||||
* @OA\Property(property="features", type="array", @OA\Items(type="string", maxLength=200), nullable=true, description="기능 목록"),
|
||||
* @OA\Property(property="is_active", type="boolean", description="활성 여부")
|
||||
* )
|
||||
*/
|
||||
class PlanApi
|
||||
{
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/api/v1/plans",
|
||||
* tags={"Plans"},
|
||||
* summary="요금제 목록 조회",
|
||||
* description="요금제 목록을 조회합니다. (관리자용)",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="is_active", in="query", description="활성 상태 필터", @OA\Schema(type="boolean")),
|
||||
* @OA\Parameter(name="billing_cycle", in="query", description="결제 주기", @OA\Schema(type="string", enum={"monthly","yearly","lifetime"})),
|
||||
* @OA\Parameter(name="search", in="query", description="검색어 (이름, 코드, 설명)", @OA\Schema(type="string", maxLength=100)),
|
||||
* @OA\Parameter(name="sort_by", in="query", description="정렬 기준", @OA\Schema(type="string", enum={"price","name","created_at"}, default="price")),
|
||||
* @OA\Parameter(name="sort_dir", in="query", description="정렬 방향", @OA\Schema(type="string", enum={"asc","desc"}, default="asc")),
|
||||
* @OA\Parameter(ref="#/components/parameters/Page"),
|
||||
* @OA\Parameter(ref="#/components/parameters/Size"),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="조회 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(
|
||||
* property="data",
|
||||
* type="object",
|
||||
* @OA\Property(property="current_page", type="integer", example=1),
|
||||
* @OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/Plan")),
|
||||
* @OA\Property(property="per_page", type="integer", example=20),
|
||||
* @OA\Property(property="total", type="integer", example=5)
|
||||
* )
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function index() {}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/api/v1/plans/active",
|
||||
* tags={"Plans"},
|
||||
* summary="활성 요금제 목록",
|
||||
* description="활성화된 요금제 목록을 조회합니다. (공개용)",
|
||||
* security={{"ApiKeyAuth":{}}},
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="조회 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/Plan"))
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function active() {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/plans",
|
||||
* tags={"Plans"},
|
||||
* summary="요금제 등록",
|
||||
* description="새로운 요금제를 등록합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* required=true,
|
||||
*
|
||||
* @OA\JsonContent(ref="#/components/schemas/PlanCreateRequest")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=201,
|
||||
* description="등록 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Plan")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="잘못된 요청", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=422, description="유효성 검증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function store() {}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/api/v1/plans/{id}",
|
||||
* tags={"Plans"},
|
||||
* summary="요금제 상세 조회",
|
||||
* description="요금제 상세 정보를 조회합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="요금제 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="조회 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Plan")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="요금제 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function show() {}
|
||||
|
||||
/**
|
||||
* @OA\Put(
|
||||
* path="/api/v1/plans/{id}",
|
||||
* tags={"Plans"},
|
||||
* summary="요금제 수정",
|
||||
* description="요금제 정보를 수정합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="요금제 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* required=true,
|
||||
*
|
||||
* @OA\JsonContent(ref="#/components/schemas/PlanUpdateRequest")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="수정 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Plan")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="잘못된 요청", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="요금제 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=422, description="유효성 검증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function update() {}
|
||||
|
||||
/**
|
||||
* @OA\Delete(
|
||||
* path="/api/v1/plans/{id}",
|
||||
* tags={"Plans"},
|
||||
* summary="요금제 삭제",
|
||||
* description="요금제를 삭제합니다. 활성 구독이 있으면 삭제할 수 없습니다. (Soft Delete)",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="요금제 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="삭제 성공",
|
||||
*
|
||||
* @OA\JsonContent(ref="#/components/schemas/ApiResponse")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="활성 구독 존재", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="요금제 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function destroy() {}
|
||||
|
||||
/**
|
||||
* @OA\Patch(
|
||||
* path="/api/v1/plans/{id}/toggle",
|
||||
* tags={"Plans"},
|
||||
* summary="요금제 활성/비활성 토글",
|
||||
* description="요금제의 활성 상태를 토글합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="요금제 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="토글 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Plan")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="요금제 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function toggle() {}
|
||||
}
|
||||
362
app/Swagger/v1/SubscriptionApi.php
Normal file
362
app/Swagger/v1/SubscriptionApi.php
Normal file
@@ -0,0 +1,362 @@
|
||||
<?php
|
||||
|
||||
namespace App\Swagger\v1;
|
||||
|
||||
/**
|
||||
* @OA\Tag(name="Subscriptions", description="구독 관리")
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="Subscription",
|
||||
* type="object",
|
||||
* description="구독 정보",
|
||||
*
|
||||
* @OA\Property(property="id", type="integer", example=1, description="구독 ID"),
|
||||
* @OA\Property(property="tenant_id", type="integer", example=1, description="테넌트 ID"),
|
||||
* @OA\Property(property="plan_id", type="integer", example=1, description="요금제 ID"),
|
||||
* @OA\Property(property="started_at", type="string", format="date-time", example="2025-01-01T00:00:00", description="시작일"),
|
||||
* @OA\Property(property="ended_at", type="string", format="date-time", example="2025-02-01T00:00:00", nullable=true, description="종료일"),
|
||||
* @OA\Property(property="status", type="string", enum={"pending","active","cancelled","expired","suspended"}, example="active", description="상태"),
|
||||
* @OA\Property(property="status_label", type="string", example="활성", description="상태 라벨"),
|
||||
* @OA\Property(property="cancelled_at", type="string", format="date-time", nullable=true, description="취소일"),
|
||||
* @OA\Property(property="cancel_reason", type="string", nullable=true, description="취소 사유"),
|
||||
* @OA\Property(property="is_expired", type="boolean", example=false, description="만료 여부"),
|
||||
* @OA\Property(property="is_valid", type="boolean", example=true, description="유효 여부"),
|
||||
* @OA\Property(property="remaining_days", type="integer", example=30, nullable=true, description="남은 일수 (무제한은 null)"),
|
||||
* @OA\Property(property="total_paid", type="number", format="float", example=29000, description="총 결제 금액"),
|
||||
* @OA\Property(property="plan", type="object", nullable=true,
|
||||
* @OA\Property(property="id", type="integer", example=1),
|
||||
* @OA\Property(property="name", type="string", example="스타터"),
|
||||
* @OA\Property(property="code", type="string", example="starter"),
|
||||
* @OA\Property(property="price", type="number", format="float", example=29000),
|
||||
* @OA\Property(property="billing_cycle", type="string", example="monthly"),
|
||||
* description="요금제 정보"
|
||||
* ),
|
||||
* @OA\Property(property="payments", type="array", @OA\Items(ref="#/components/schemas/Payment"), nullable=true, description="결제 내역"),
|
||||
* @OA\Property(property="created_at", type="string", format="date-time"),
|
||||
* @OA\Property(property="updated_at", type="string", format="date-time")
|
||||
* )
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="SubscriptionCreateRequest",
|
||||
* type="object",
|
||||
* required={"plan_id"},
|
||||
* description="구독 등록 요청",
|
||||
*
|
||||
* @OA\Property(property="plan_id", type="integer", example=1, description="요금제 ID"),
|
||||
* @OA\Property(property="started_at", type="string", format="date", example="2025-01-01", nullable=true, description="시작일 (미지정 시 현재)"),
|
||||
* @OA\Property(property="payment_method", type="string", enum={"card","bank","virtual","cash","free"}, example="card", description="결제 수단"),
|
||||
* @OA\Property(property="transaction_id", type="string", example="TXN123456", nullable=true, description="PG 거래 ID"),
|
||||
* @OA\Property(property="auto_complete", type="boolean", example=true, description="자동 결제 완료 처리")
|
||||
* )
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="SubscriptionCancelRequest",
|
||||
* type="object",
|
||||
* description="구독 취소 요청",
|
||||
*
|
||||
* @OA\Property(property="reason", type="string", example="서비스 불만족", maxLength=500, nullable=true, description="취소 사유")
|
||||
* )
|
||||
*/
|
||||
class SubscriptionApi
|
||||
{
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/api/v1/subscriptions",
|
||||
* tags={"Subscriptions"},
|
||||
* summary="구독 목록 조회",
|
||||
* description="테넌트의 구독 목록을 조회합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="status", in="query", description="상태 필터", @OA\Schema(type="string", enum={"pending","active","cancelled","expired","suspended"})),
|
||||
* @OA\Parameter(name="valid_only", in="query", description="유효한 구독만", @OA\Schema(type="boolean")),
|
||||
* @OA\Parameter(name="expiring_within", in="query", description="N일 이내 만료 예정", @OA\Schema(type="integer", minimum=1, maximum=365)),
|
||||
* @OA\Parameter(name="start_date", in="query", description="시작일 (시작일 기준)", @OA\Schema(type="string", format="date")),
|
||||
* @OA\Parameter(name="end_date", in="query", description="종료일 (시작일 기준)", @OA\Schema(type="string", format="date")),
|
||||
* @OA\Parameter(name="sort_by", in="query", description="정렬 기준", @OA\Schema(type="string", enum={"started_at","ended_at","created_at"}, default="started_at")),
|
||||
* @OA\Parameter(name="sort_dir", in="query", description="정렬 방향", @OA\Schema(type="string", enum={"asc","desc"}, default="desc")),
|
||||
* @OA\Parameter(ref="#/components/parameters/Page"),
|
||||
* @OA\Parameter(ref="#/components/parameters/Size"),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="조회 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(
|
||||
* property="data",
|
||||
* type="object",
|
||||
* @OA\Property(property="current_page", type="integer", example=1),
|
||||
* @OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/Subscription")),
|
||||
* @OA\Property(property="per_page", type="integer", example=20),
|
||||
* @OA\Property(property="total", type="integer", example=10)
|
||||
* )
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function index() {}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/api/v1/subscriptions/current",
|
||||
* tags={"Subscriptions"},
|
||||
* summary="현재 활성 구독 조회",
|
||||
* description="테넌트의 현재 활성 구독을 조회합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="조회 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Subscription", nullable=true)
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function current() {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/subscriptions",
|
||||
* tags={"Subscriptions"},
|
||||
* summary="구독 등록",
|
||||
* description="새로운 구독을 등록합니다. 이미 활성 구독이 있으면 등록할 수 없습니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* required=true,
|
||||
*
|
||||
* @OA\JsonContent(ref="#/components/schemas/SubscriptionCreateRequest")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=201,
|
||||
* description="등록 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Subscription")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="이미 활성 구독 존재", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="요금제 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function store() {}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/api/v1/subscriptions/{id}",
|
||||
* tags={"Subscriptions"},
|
||||
* summary="구독 상세 조회",
|
||||
* description="구독 상세 정보를 조회합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="구독 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="조회 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Subscription")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="구독 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function show() {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/subscriptions/{id}/cancel",
|
||||
* tags={"Subscriptions"},
|
||||
* summary="구독 취소",
|
||||
* description="구독을 취소합니다. 활성(active) 또는 대기(pending) 상태에서만 가능합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="구독 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* required=false,
|
||||
*
|
||||
* @OA\JsonContent(ref="#/components/schemas/SubscriptionCancelRequest")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="취소 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Subscription")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="취소 불가 상태", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="구독 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function cancel() {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/subscriptions/{id}/renew",
|
||||
* tags={"Subscriptions"},
|
||||
* summary="구독 갱신",
|
||||
* description="구독을 갱신합니다. 활성(active) 상태에서만 가능합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="구독 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* required=false,
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
*
|
||||
* @OA\Property(property="payment_method", type="string", enum={"card","bank","virtual","cash","free"}, example="card"),
|
||||
* @OA\Property(property="transaction_id", type="string", example="TXN654321"),
|
||||
* @OA\Property(property="auto_complete", type="boolean", example=true)
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="갱신 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Subscription")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="갱신 불가 상태", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="구독 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function renew() {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/subscriptions/{id}/suspend",
|
||||
* tags={"Subscriptions"},
|
||||
* summary="구독 일시정지",
|
||||
* description="구독을 일시정지합니다. 활성(active) 상태에서만 가능합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="구독 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="일시정지 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Subscription")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="일시정지 불가 상태", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="구독 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function suspend() {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/subscriptions/{id}/resume",
|
||||
* tags={"Subscriptions"},
|
||||
* summary="구독 재개",
|
||||
* description="일시정지된 구독을 재개합니다. 일시정지(suspended) 상태에서만 가능합니다.",
|
||||
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
|
||||
*
|
||||
* @OA\Parameter(name="id", in="path", required=true, description="구독 ID", @OA\Schema(type="integer")),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="재개 성공",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* allOf={
|
||||
*
|
||||
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||||
* @OA\Schema(
|
||||
*
|
||||
* @OA\Property(property="data", ref="#/components/schemas/Subscription")
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=400, description="재개 불가 상태", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=404, description="구독 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
|
||||
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
|
||||
* )
|
||||
*/
|
||||
public function resume() {}
|
||||
}
|
||||
@@ -41,4 +41,4 @@ public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('loans');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -43,4 +43,4 @@ public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('barobill_settings');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -86,4 +86,4 @@ public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tax_invoices');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
use App\Http\Controllers\Api\V1\ApprovalLineController;
|
||||
use App\Http\Controllers\Api\V1\AttendanceController;
|
||||
use App\Http\Controllers\Api\V1\BankAccountController;
|
||||
use App\Http\Controllers\Api\V1\BarobillSettingController;
|
||||
use App\Http\Controllers\Api\V1\BoardController;
|
||||
use App\Http\Controllers\Api\V1\CardController;
|
||||
use App\Http\Controllers\Api\V1\CategoryController;
|
||||
@@ -38,8 +39,8 @@
|
||||
use App\Http\Controllers\Api\V1\ItemMaster\ItemFieldController;
|
||||
use App\Http\Controllers\Api\V1\ItemMaster\ItemMasterController;
|
||||
use App\Http\Controllers\Api\V1\ItemMaster\ItemPageController;
|
||||
use App\Http\Controllers\Api\V1\ItemMaster\ItemSectionController;
|
||||
// use App\Http\Controllers\Api\V1\MaterialController; // REMOVED: materials 테이블 삭제됨
|
||||
use App\Http\Controllers\Api\V1\ItemMaster\ItemSectionController;
|
||||
use App\Http\Controllers\Api\V1\ItemMaster\SectionTemplateController;
|
||||
use App\Http\Controllers\Api\V1\ItemMaster\UnitOptionController;
|
||||
use App\Http\Controllers\Api\V1\ItemsBomController;
|
||||
@@ -49,10 +50,12 @@
|
||||
use App\Http\Controllers\Api\V1\LoanController;
|
||||
use App\Http\Controllers\Api\V1\MenuController;
|
||||
use App\Http\Controllers\Api\V1\ModelSetController;
|
||||
use App\Http\Controllers\Api\V1\PaymentController;
|
||||
use App\Http\Controllers\Api\V1\PayrollController;
|
||||
// use App\Http\Controllers\Api\V1\ProductBomItemController; // REMOVED: products 테이블 삭제됨
|
||||
// use App\Http\Controllers\Api\V1\ProductController; // REMOVED: products 테이블 삭제됨
|
||||
use App\Http\Controllers\Api\V1\PayrollController;
|
||||
use App\Http\Controllers\Api\V1\PermissionController;
|
||||
use App\Http\Controllers\Api\V1\PlanController;
|
||||
use App\Http\Controllers\Api\V1\PostController;
|
||||
use App\Http\Controllers\Api\V1\PricingController;
|
||||
use App\Http\Controllers\Api\V1\PurchaseController;
|
||||
@@ -65,8 +68,8 @@
|
||||
use App\Http\Controllers\Api\V1\RolePermissionController;
|
||||
use App\Http\Controllers\Api\V1\SaleController;
|
||||
use App\Http\Controllers\Api\V1\SiteController;
|
||||
use App\Http\Controllers\Api\V1\SubscriptionController;
|
||||
use App\Http\Controllers\Api\V1\TaxInvoiceController;
|
||||
use App\Http\Controllers\Api\V1\BarobillSettingController;
|
||||
// 설계 전용 (디자인 네임스페이스)
|
||||
use App\Http\Controllers\Api\V1\TenantController;
|
||||
use App\Http\Controllers\Api\V1\TenantFieldSettingController;
|
||||
@@ -407,6 +410,40 @@
|
||||
Route::post('/{id}/settle', [LoanController::class, 'settle'])->whereNumber('id')->name('v1.loans.settle');
|
||||
});
|
||||
|
||||
// Plan API (요금제 관리)
|
||||
Route::prefix('plans')->group(function () {
|
||||
Route::get('', [PlanController::class, 'index'])->name('v1.plans.index');
|
||||
Route::post('', [PlanController::class, 'store'])->name('v1.plans.store');
|
||||
Route::get('/active', [PlanController::class, 'active'])->name('v1.plans.active');
|
||||
Route::get('/{id}', [PlanController::class, 'show'])->whereNumber('id')->name('v1.plans.show');
|
||||
Route::put('/{id}', [PlanController::class, 'update'])->whereNumber('id')->name('v1.plans.update');
|
||||
Route::delete('/{id}', [PlanController::class, 'destroy'])->whereNumber('id')->name('v1.plans.destroy');
|
||||
Route::patch('/{id}/toggle', [PlanController::class, 'toggle'])->whereNumber('id')->name('v1.plans.toggle');
|
||||
});
|
||||
|
||||
// Subscription API (구독 관리)
|
||||
Route::prefix('subscriptions')->group(function () {
|
||||
Route::get('', [SubscriptionController::class, 'index'])->name('v1.subscriptions.index');
|
||||
Route::post('', [SubscriptionController::class, 'store'])->name('v1.subscriptions.store');
|
||||
Route::get('/current', [SubscriptionController::class, 'current'])->name('v1.subscriptions.current');
|
||||
Route::get('/{id}', [SubscriptionController::class, 'show'])->whereNumber('id')->name('v1.subscriptions.show');
|
||||
Route::post('/{id}/cancel', [SubscriptionController::class, 'cancel'])->whereNumber('id')->name('v1.subscriptions.cancel');
|
||||
Route::post('/{id}/renew', [SubscriptionController::class, 'renew'])->whereNumber('id')->name('v1.subscriptions.renew');
|
||||
Route::post('/{id}/suspend', [SubscriptionController::class, 'suspend'])->whereNumber('id')->name('v1.subscriptions.suspend');
|
||||
Route::post('/{id}/resume', [SubscriptionController::class, 'resume'])->whereNumber('id')->name('v1.subscriptions.resume');
|
||||
});
|
||||
|
||||
// Payment API (결제 관리)
|
||||
Route::prefix('payments')->group(function () {
|
||||
Route::get('', [PaymentController::class, 'index'])->name('v1.payments.index');
|
||||
Route::post('', [PaymentController::class, 'store'])->name('v1.payments.store');
|
||||
Route::get('/summary', [PaymentController::class, 'summary'])->name('v1.payments.summary');
|
||||
Route::get('/{id}', [PaymentController::class, 'show'])->whereNumber('id')->name('v1.payments.show');
|
||||
Route::post('/{id}/complete', [PaymentController::class, 'complete'])->whereNumber('id')->name('v1.payments.complete');
|
||||
Route::post('/{id}/cancel', [PaymentController::class, 'cancel'])->whereNumber('id')->name('v1.payments.cancel');
|
||||
Route::post('/{id}/refund', [PaymentController::class, 'refund'])->whereNumber('id')->name('v1.payments.refund');
|
||||
});
|
||||
|
||||
// Sale API (매출 관리)
|
||||
Route::prefix('sales')->group(function () {
|
||||
Route::get('', [SaleController::class, 'index'])->name('v1.sales.index');
|
||||
|
||||
Reference in New Issue
Block a user