mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 23:57:33 -05:00 
			
		
		
		
	Merge pull request #4656 from beganovich/v5-better-error-handling-for-payments-in-cp
(v5) Wrap processPaymentView & processPaymentRequest into try-catch
This commit is contained in:
		
						commit
						08eb60ecbd
					
				@ -12,14 +12,17 @@
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Controllers\ClientPortal;
 | 
			
		||||
 | 
			
		||||
use App\Exceptions\PaymentFailed;
 | 
			
		||||
use App\Factory\PaymentFactory;
 | 
			
		||||
use App\Http\Controllers\Controller;
 | 
			
		||||
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
 | 
			
		||||
use App\Jobs\Invoice\InjectSignature;
 | 
			
		||||
use App\Jobs\Util\SystemLogger;
 | 
			
		||||
use App\Models\CompanyGateway;
 | 
			
		||||
use App\Models\Invoice;
 | 
			
		||||
use App\Models\Payment;
 | 
			
		||||
use App\Models\PaymentHash;
 | 
			
		||||
use App\Models\SystemLog;
 | 
			
		||||
use App\Utils\Number;
 | 
			
		||||
use App\Utils\Traits\MakesDates;
 | 
			
		||||
use App\Utils\Traits\MakesHash;
 | 
			
		||||
@ -256,27 +259,50 @@ class PaymentController extends Controller
 | 
			
		||||
            return $this->processCreditPayment($request, $data);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $gateway
 | 
			
		||||
            ->driver(auth()->user()->client)
 | 
			
		||||
            ->setPaymentMethod($payment_method_id)
 | 
			
		||||
            ->setPaymentHash($payment_hash)
 | 
			
		||||
            ->checkRequirements()
 | 
			
		||||
            ->processPaymentView($data);
 | 
			
		||||
        try {
 | 
			
		||||
            return $gateway
 | 
			
		||||
                ->driver(auth()->user()->client)
 | 
			
		||||
                ->setPaymentMethod($payment_method_id)
 | 
			
		||||
                ->setPaymentHash($payment_hash)
 | 
			
		||||
                ->checkRequirements()
 | 
			
		||||
                ->processPaymentView($data);
 | 
			
		||||
        } catch(\Exception $e) {
 | 
			
		||||
            SystemLogger::dispatch(
 | 
			
		||||
                $e->getMessage(),
 | 
			
		||||
                SystemLog::CATEGORY_GATEWAY_RESPONSE,
 | 
			
		||||
                SystemLog::EVENT_GATEWAY_ERROR,
 | 
			
		||||
                SystemLog::TYPE_FAILURE,
 | 
			
		||||
                auth('contact')->user()->client
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            throw new PaymentFailed($e->getMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function response(PaymentResponseRequest $request)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        $gateway = CompanyGateway::findOrFail($request->input('company_gateway_id'));
 | 
			
		||||
 | 
			
		||||
        $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->payment_hash])->first();
 | 
			
		||||
 | 
			
		||||
        return $gateway
 | 
			
		||||
            ->driver(auth()->user()->client)
 | 
			
		||||
            ->setPaymentMethod($request->input('payment_method_id'))
 | 
			
		||||
            ->setPaymentHash($payment_hash)
 | 
			
		||||
            ->checkRequirements()
 | 
			
		||||
            ->processPaymentResponse($request);
 | 
			
		||||
        try {
 | 
			
		||||
            return $gateway
 | 
			
		||||
                ->driver(auth()->user()->client)
 | 
			
		||||
                ->setPaymentMethod($request->input('payment_method_id'))
 | 
			
		||||
                ->setPaymentHash($payment_hash)
 | 
			
		||||
                ->checkRequirements()
 | 
			
		||||
                ->processPaymentResponse($request);
 | 
			
		||||
        } catch(\Exception $e) {
 | 
			
		||||
            SystemLogger::dispatch(
 | 
			
		||||
                $e->getMessage(),
 | 
			
		||||
                SystemLog::CATEGORY_GATEWAY_RESPONSE,
 | 
			
		||||
                SystemLog::EVENT_GATEWAY_FAILURE,
 | 
			
		||||
                SystemLog::TYPE_FAILURE,
 | 
			
		||||
                auth('contact')->user()->client
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            throw new PaymentFailed($e->getMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user