diff --git a/app/Http/Controllers/PaymentWebhookController.php b/app/Http/Controllers/PaymentWebhookController.php index f6681520a91d..881fce5b116d 100644 --- a/app/Http/Controllers/PaymentWebhookController.php +++ b/app/Http/Controllers/PaymentWebhookController.php @@ -21,13 +21,18 @@ class PaymentWebhookController extends Controller public function __invoke(PaymentWebhookRequest $request, string $company_key, string $company_gateway_id) { - MultiDB::findAndSetDbByCompanyKey($company_key); + // MultiDB::findAndSetDbByCompanyKey($company_key); $payment = $request->getPayment(); + + if(!$payment) + return response()->json(['message' => 'Payment record not found.'], 400); + $client = is_null($payment) ? $request->getClient() : $payment->client; - // $contact= $client->primary_contact()->first(); - // Auth::guard('contact')->login($contact, true); + if(!$client) + return response()->json(['message' => 'Client record not found.'], 400); + return $request->getCompanyGateway() ->driver($client) diff --git a/app/Http/Requests/Payments/PaymentWebhookRequest.php b/app/Http/Requests/Payments/PaymentWebhookRequest.php index f0b8927ab247..2642f2458e93 100644 --- a/app/Http/Requests/Payments/PaymentWebhookRequest.php +++ b/app/Http/Requests/Payments/PaymentWebhookRequest.php @@ -27,7 +27,7 @@ class PaymentWebhookRequest extends Request public function authorize() { - MultiDB::findAndSetDbByCompanyKey($this->getCompany()->company_key); + MultiDB::findAndSetDbByCompanyKey($this->company_key); return true; } @@ -45,7 +45,7 @@ class PaymentWebhookRequest extends Request * @param mixed $id * @return null|\App\Models\CompanyGateway */ - public function getCompanyGateway(): ?CompanyGateway + public function getCompanyGateway() { return CompanyGateway::findOrFail($this->decodePrimaryKey($this->company_gateway_id)); } @@ -56,13 +56,13 @@ class PaymentWebhookRequest extends Request * @param string $hash * @return null|\App\Models\PaymentHash */ - public function getPaymentHash(): ?PaymentHash + public function getPaymentHash() { if ($this->query('hash')) { return PaymentHash::where('hash', $this->query('hash'))->firstOrFail(); } - return null; + return false; } /** @@ -94,7 +94,7 @@ class PaymentWebhookRequest extends Request // If none of previously done logics is correct, we'll just display // not found page. - abort(404); + return false; } /** @@ -102,11 +102,14 @@ class PaymentWebhookRequest extends Request * * @return null|\App\Models\Client */ - public function getClient(): ?Client + public function getClient() { $hash = $this->getPaymentHash(); - return Client::find($hash->data->client_id)->firstOrFail(); + if($hash) + return Client::find($hash->data->client_id)->firstOrFail(); + + return false; } /**