From 9119f57a35cf7af85c16887600765fdce445b3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 1 Jun 2021 11:54:15 +0200 Subject: [PATCH] Return JSON response if some of required records wasn't found --- .../Gateways/Checkout3dsController.php | 16 ++++++++++++++++ .../Gateways/Checkout3ds/Checkout3dsRequest.php | 12 +++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Gateways/Checkout3dsController.php b/app/Http/Controllers/Gateways/Checkout3dsController.php index af6a4217f3f1..4dbada72ad86 100644 --- a/app/Http/Controllers/Gateways/Checkout3dsController.php +++ b/app/Http/Controllers/Gateways/Checkout3dsController.php @@ -19,6 +19,22 @@ class Checkout3dsController extends Controller { public function index(Checkout3dsRequest $request, string $company_key, string $company_gateway_id, string $hash) { + if (!$request->getCompany()) { + return response()->json(['message' => 'Company record not found.', 'company_key' => $company_key]); + } + + if (!$request->getCompanyGateway()) { + return response()->json(['message' => 'Company gateway record not found.', 'company_gateway_id' => $company_gateway_id]); + } + + if (!$request->getPaymentHash()) { + return response()->json(['message' => 'Hash record not found.', 'hash' => $hash]); + } + + if (!$request->getClient()) { + return response()->json(['message' => 'Client record not found.']); + } + return $request->getCompanyGateway() ->driver($request->getClient()) ->process3dsConfirmation($request); diff --git a/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php b/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php index 3b218f50548c..021379542094 100644 --- a/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php +++ b/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\Gateways\Checkout3ds; use App\Models\Client; +use App\Models\Company; use App\Models\CompanyGateway; use App\Models\PaymentHash; use App\Utils\Traits\MakesHash; @@ -34,18 +35,23 @@ class Checkout3dsRequest extends FormRequest ]; } + public function getCompany() + { + return Company::where('company_key', $this->company_key)->first(); + } + public function getCompanyGateway() { - return CompanyGateway::findOrFail($this->decodePrimaryKey($this->company_gateway_id)); + return CompanyGateway::find($this->decodePrimaryKey($this->company_gateway_id)); } public function getPaymentHash() { - return PaymentHash::where('hash', $this->hash)->firstOrFail(); + return PaymentHash::where('hash', $this->hash)->first(); } public function getClient() { - return Client::findOrFail($this->getPaymentHash()->data->client_id); + return Client::find($this->getPaymentHash()->data->client_id); } }