From 6740e348a19e7578b81c86eba95e47adc89f0ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 4 Aug 2021 15:44:43 +0200 Subject: [PATCH] Refactor PaymentWebhookController --- .../Controllers/PaymentWebhookController.php | 22 +++++-------------- app/Models/CompanyGateway.php | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/PaymentWebhookController.php b/app/Http/Controllers/PaymentWebhookController.php index 01b38c3aba..67907deb57 100644 --- a/app/Http/Controllers/PaymentWebhookController.php +++ b/app/Http/Controllers/PaymentWebhookController.php @@ -13,26 +13,14 @@ namespace App\Http\Controllers; use App\Http\Requests\Payments\PaymentWebhookRequest; -use App\Libraries\MultiDB; -use Auth; class PaymentWebhookController extends Controller { - public function __invoke(PaymentWebhookRequest $request, string $company_key, string $company_gateway_id) + public function __invoke(PaymentWebhookRequest $request) { - - $payment = $request->getPayment(); - - if(!$payment) - return response()->json(['message' => 'Payment record not found.'], 400); - - $client = is_null($payment) ? $request->getClient() : $payment->client; - - if(!$client) - return response()->json(['message' => 'Client record not found.'], 400); - - return $request->getCompanyGateway() - ->driver($client) - ->processWebhookRequest($request, $payment); + return $request + ->getCompanyGateway() + ->driver() + ->processWebhookRequest($request); } } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index b9105b566e..f7efd1c79e 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -118,7 +118,7 @@ class CompanyGateway extends BaseModel } /* This is the public entry point into the payment superclass */ - public function driver(Client $client) + public function driver(Client $client = null) { $class = static::driver_class();