Files
portal-api/app/Http/Controllers/Api/Admin/Payment/PaymentController.php
T
baodev0 c377c7e195 feat: add domain registration form and email notifications
- Create a new Blade view for domain registration (`registrant-tochuc.blade.php`) to capture organization and manager details.
- Implement email templates for new domain orders for both admin (`domain-order-new.blade.php`) and customers (`domain-order-received.blade.php`).
- Add CSV exports for client and domain data.
- Introduce tests for customer mass assignment, password reset, login throttling, and permission gating.
- Ensure service renewals use current pricing and validate ownership for virtual machines.
- Validate mass assignment behavior in service model.
2026-08-22 17:30:55 +07:00

143 lines
3.9 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Admin\Payment;
use App\Http\Controllers\Controller;
use App\Http\Requests\PaymentRequest;
use App\Models\Payment;
use App\Repositories\Payment\PaymentReppositoryInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class PaymentController extends Controller
{
public function __construct(
private readonly PaymentReppositoryInterface $paymentRepository
) {}
public function index(Request $request): JsonResponse
{
$payments = $this->paymentRepository->filter($request->all());
return response()->json([
'error' => false,
'data' => $payments
]);
}
public function forSelect(): JsonResponse
{
$payments = $this->paymentRepository->filter(['status' => 1]);
return response()->json([
'error' => false,
'data' => $payments->map(fn($p) => [
'id' => $p->id,
'name' => $p->name,
'type' => (int) $p->type,
'status' => (int) $p->status,
])->values(),
]);
}
public function store(PaymentRequest $request): JsonResponse
{
try {
DB::beginTransaction();
$payment = $this->paymentRepository->create($request->validated());
DB::commit();
return response()->json([
'error' => false,
'message' => 'Payment method created successfully',
'data' => $payment
], 201);
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'error' => true,
'message' => $e->getMessage()
], 500);
}
}
public function show(int $id): JsonResponse
{
$payment = $this->paymentRepository->find($id);
if (!$payment) {
return response()->json([
'error' => true,
'message' => "Can't find payment method by ID #" . $id
], 404);
}
return response()->json([
'error' => false,
'data' => $payment
]);
}
public function update(int $id, PaymentRequest $request): JsonResponse
{
$payment = $this->paymentRepository->find($id);
if (!$payment) {
return response()->json([
'error' => true,
'message' => "Can't find payment method by ID #" . $id
], 404);
}
$request->validated();
try {
DB::beginTransaction();
$this->paymentRepository->update($id, $request->all());
DB::commit();
return response()->json([
'error' => false,
'message' => 'Payment method updated successfully',
'data' => $this->paymentRepository->find($id)
]);
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'error' => true,
'message' => $e->getMessage()
], 500);
}
}
public function destroy(int $id): JsonResponse
{
$payment = $this->paymentRepository->find($id);
if (!$payment) {
return response()->json([
'error' => true,
'message' => "Can't find payment method by ID #" . $id
], 404);
}
try {
DB::beginTransaction();
$this->paymentRepository->delete($id);
DB::commit();
return response()->json([
'error' => false,
'message' => 'Payment method deleted successfully'
]);
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'error' => true,
'message' => $e->getMessage()
], 500);
}
}
}