paymentRepository->filter($request->all()); return response()->json([ 'error' => false, 'data' => $payments ]); } public function store(PaymentRequest $request): JsonResponse { $request->validated(); try { DB::beginTransaction(); $payment = $this->paymentRepository->create($request->all()); 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); } } }