add controllers, servoices
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Finance;
|
||||
|
||||
use App\Http\Controllers\Api\BaseApiController;
|
||||
use App\Http\Requests\Payments\PaymentTransactionCreateRequest;
|
||||
use App\Http\Requests\Payments\PaymentTransactionStatusRequest;
|
||||
use App\Http\Resources\Payments\PaymentTransactionResource;
|
||||
use App\Services\Payments\PaymentTransactionService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class PaymentTransactionController extends BaseApiController
|
||||
{
|
||||
public function __construct(private PaymentTransactionService $service)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function store(PaymentTransactionCreateRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$transaction = $this->service->create($payload);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'transaction' => new PaymentTransactionResource($transaction->toArray()),
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function byPayment(int $paymentId): JsonResponse
|
||||
{
|
||||
$transactions = $this->service->getByPayment($paymentId);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'transactions' => PaymentTransactionResource::collection($transactions),
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateStatus(PaymentTransactionStatusRequest $request, string $transactionId): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$updated = $this->service->updateStatus($transactionId, $payload['status']);
|
||||
|
||||
if (!$updated) {
|
||||
return response()->json(['ok' => false, 'message' => 'Transaction not found.'], 404);
|
||||
}
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user