problem with Laravel exceptions - not working for all errors

92 views Asked by At

I'm working on a project and Using a package for my purchase process and the problem is the error handler does't work

        public function purchase(PurchaseServiceRequest $request)
{
    $validated = (object)$request->validated();
    $serivce_id = $validated->service;

    try {
        $serivce = Service::findOrFail($serivce_id);
        $service_count = $this->getServiceCount($request, $validated);
        $total_amount = (int)$serivce->price * $service_count;

        $invoice = new Invoice();
        $invoice->amount($total_amount);

        $user = Auth::user();
        $paymentId = md5(uniqid());
        $transaction = $this->createUserTransaction($user, $serivce, $service_count, $validated, $invoice, $paymentId);

        $callbackUrl = route('dashboard.customers.services.purchase.result', [$serivce->id, 'payment_id' => $paymentId]);
        $payment = Payment::callbackUrl($callbackUrl);
        $payment_description = 'خرید ' . $service_count . ' عدد سرویس با قیمت هر واحد : ' . $serivce->price;
        $payment->config('description', $payment_description);

        $payment->purchase($invoice, function ($driver, $transactionId) use ($transaction) {
            $transaction->transaction_id = $transactionId;
            $transaction->save();
        });

        return $payment->pay()->render();
    } catch (PurchaseFailedException | Exception | Throwable | Error | SoapFault | ErrorException $e) {
        $error = [
            'message' => $e->getMessage(),
            'code' => $e->getCode(),
            'file' => $e->getFile() ?: null,
        ];
        $transaction->transaction_result = $error;
        $transaction->status = 0;
        $transaction->save();
    }
}

I have even Throwable but it doesn't catch the error

0

There are 0 answers