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();