From 48c5c56a4a7f1ee1150de956129fefa19085e245 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 20 Jul 2021 08:39:04 +1000 Subject: [PATCH] Fixes for webhook bug --- app/Jobs/Util/WebhookHandler.php | 16 +++++++--------- app/Observers/InvoiceObserver.php | 3 +++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index b074a5145edb..222ad861b8d5 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -111,12 +111,9 @@ class WebhookHandler implements ShouldQueue try { - $response = $client->post($subscription->target_url, [ - RequestOptions::JSON => $data, // or 'json' => [...] - ]); - - if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200) - $subscription->delete(); + $response = $client->post($subscription->target_url, [ + RequestOptions::JSON => $data, // or 'json' => [...] + ]); SystemLogger::dispatch( $response, @@ -127,10 +124,13 @@ class WebhookHandler implements ShouldQueue $this->company ); + // if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200) + // return true;// $subscription->delete(); + } catch(\Exception $e){ - // nlog($e->getMessage()); + nlog($e->getMessage()); SystemLogger::dispatch( $e->getMessage(), @@ -143,8 +143,6 @@ class WebhookHandler implements ShouldQueue } - - } public function failed($exception) diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index 1960ae5d374b..606d37c50a80 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -19,6 +19,8 @@ use App\Models\Webhook; class InvoiceObserver { + public $afterCommit = true; + /** * Handle the client "created" event. * @@ -27,6 +29,7 @@ class InvoiceObserver */ public function created(Invoice $invoice) { + $subscriptions = Webhook::where('company_id', $invoice->company->id) ->where('event_id', Webhook::EVENT_CREATE_INVOICE) ->exists();