public function requestPaymentPlafond(Request $request){ try{ DB::beginTransaction(); $currentUser = Auth::user(); $account = Account::whereId($request->input('accountId'))->first(); $plafond = $account->plafond; $accountId = $request->input('accountId'); $totalToCheckout = $request->input('totalToCheckout'); $payPlafond = $request->input('payPlafond'); if($payPlafond){ if($plafond >= $totalToCheckout){ $transaction = AccountTransactions::create([ 'account_id' => $accountId, 'type' => 2, //1 -> rechargement; 2 -> payment 'value' => $totalToCheckout, 'created_by' => $currentUser->id, ]); $account->plafond -= $totalToCheckout; $account->updated_by = $currentUser->id; $account->save(); $paymentController = new PaymentsController(); $randomId = $paymentController->generateRandomId(); $payment = Payment::create([ 'payment_method_id' => 0, 'random_id' => $randomId, 'value' => 0, 'account_transaction_id' => $transaction->id, 'state' => 3, 'created_by' => $currentUser->id, ]); DB::commit(); return response()->json(true,200); }else{ return response()->json(false,404); } }else{ throw new \Exception('Permission denied'); } } catch (\Exception | \Throwable $e) { dd($e); DB::rollback(); $parametersToLog = [ 'error' => "Message: '{$e->getMessage()}' | File: '{$e->getFile()}' | Line: {$e->getLine()}" ]; Log::error('[OrdersController: requestPaymentPlafond] Error: ' . json_encode($parametersToLog)); return response()->json(trans('generic.error'), 500); } }