Throw an renderable exception instead of returning view

This commit is contained in:
Benjamin Beganović 2020-10-26 11:02:23 +01:00
parent f73ad4bef7
commit 6e6e73825c
2 changed files with 24 additions and 8 deletions

View File

@ -0,0 +1,21 @@
<?php
namespace App\Exceptions;
use Exception;
class PaymentFailed extends Exception
{
public function report()
{
// ..
}
public function render($request)
{
return render('gateways.unsuccessful', [
'message' => $this->getMessage(),
'code' => $this->getCode(),
]);
}
}

View File

@ -12,6 +12,7 @@
namespace App\PaymentDrivers\CheckoutCom; namespace App\PaymentDrivers\CheckoutCom;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Models\PaymentType; use App\Models\PaymentType;
@ -92,10 +93,7 @@ trait Utilities
$this->checkout->client $this->checkout->client
); );
return render('gateways.unsuccessful', [ throw new PaymentFailed($_payment->status, $_payment->http_code);
'code' => $_payment->http_code,
'message' => $_payment->status,
]);
} }
private function processPendingPayment(\Checkout\Models\Payments\Payment $_payment) private function processPendingPayment(\Checkout\Models\Payments\Payment $_payment)
@ -148,9 +146,6 @@ trait Utilities
$this->checkout->client, $this->checkout->client,
); );
return render('gateways.unsuccessful', [ throw new PaymentFailed($error, $e->getCode());
'error' => $e->getCode(),
'message' => $error,
]);
} }
} }