diff --git a/app/Events/Invoice/InvoiceWasPaid.php b/app/Events/Invoice/InvoiceWasPaid.php index dffe4343d2c2..af1ff64011fa 100644 --- a/app/Events/Invoice/InvoiceWasPaid.php +++ b/app/Events/Invoice/InvoiceWasPaid.php @@ -48,4 +48,5 @@ class InvoiceWasPaid $this->company = $company; $this->event_vars = $event_vars; } + } diff --git a/app/Jobs/Util/WebhookSingle.php b/app/Jobs/Util/WebhookSingle.php index b780fcd523aa..23749f84c64e 100644 --- a/app/Jobs/Util/WebhookSingle.php +++ b/app/Jobs/Util/WebhookSingle.php @@ -46,6 +46,7 @@ class WebhookSingle implements ShouldQueue private string $includes; private Company $company; + /** * Create a new job instance. * @@ -121,41 +122,47 @@ class WebhookSingle implements ShouldQueue RequestOptions::JSON => $data, // or 'json' => [...] ]); - SystemLogger::dispatch( + (new SystemLogger( array_merge((array) $response, $data), SystemLog::CATEGORY_WEBHOOK, SystemLog::EVENT_WEBHOOK_SUCCESS, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->resolveClient(), $this->company - ); + ))->handle(); } catch(\GuzzleHttp\Exception\ConnectException $e) { nlog("connection problem"); nlog($e->getCode()); nlog($e->getMessage()); - SystemLogger::dispatch( + (new SystemLogger( ['message' => "Error connecting to ". $subscription->target_url], SystemLog::CATEGORY_WEBHOOK, SystemLog::EVENT_WEBHOOK_FAILURE, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->resolveClient(), $this->company - ); + ))->handle(); } catch (BadResponseException $e) { if ($e->getResponse()->getStatusCode() >= 400 && $e->getResponse()->getStatusCode() < 500) { - $message = "Server encountered a problem when connecting to {$subscription->target_url} => status code ". $e->getResponse()->getStatusCode(). " scheduling retry."; + $message = "There was a problem when connecting to {$subscription->target_url} => status code ". $e->getResponse()->getStatusCode(); nlog($message); - SystemLogger::dispatch( + (new SystemLogger( ['message' => $message], SystemLog::CATEGORY_WEBHOOK, SystemLog::EVENT_WEBHOOK_FAILURE, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->resolveClient(), $this->company - ); + ))->handle(); + + /* Some 400's should never be repeated */ + if(in_array($e->getResponse()->getStatusCode(), [404, 410])){ + $this->fail(); + return; + } $this->release($this->backoff()[$this->attempts()-1]); } @@ -163,16 +170,16 @@ class WebhookSingle implements ShouldQueue if ($e->getResponse()->getStatusCode() >= 500) { nlog("endpoint returned a 500, failing"); - $message = "Server encountered a problem when connecting to {$subscription->target_url} => status code ". $e->getResponse()->getStatusCode(). " no retry attempted."; + $message = "The was a problem when connecting to {$subscription->target_url} => status code ". $e->getResponse()->getStatusCode(). " no retry attempted."; - SystemLogger::dispatch( + (new SystemLogger( ['message' => $message], SystemLog::CATEGORY_WEBHOOK, SystemLog::EVENT_WEBHOOK_FAILURE, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->resolveClient(), $this->company - ); + ))->handle(); $this->fail(); return; @@ -181,38 +188,38 @@ class WebhookSingle implements ShouldQueue nlog("Server exception"); $error = json_decode($e->getResponse()->getBody()->getContents()); - SystemLogger::dispatch( + (new SystemLogger( ['message' => $error], SystemLog::CATEGORY_WEBHOOK, SystemLog::EVENT_WEBHOOK_FAILURE, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->resolveClient(), $this->company - ); + ))->handle(); } catch (ClientException $e) { nlog("Client exception"); $error = json_decode($e->getResponse()->getBody()->getContents()); - SystemLogger::dispatch( + (new SystemLogger( ['message' => $error], SystemLog::CATEGORY_WEBHOOK, SystemLog::EVENT_WEBHOOK_FAILURE, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->resolveClient(), $this->company - ); + ))->handle(); } catch (\Exception $e) { nlog("Exception handler => " . $e->getMessage()); nlog($e->getCode()); - SystemLogger::dispatch( + (new SystemLogger( $e->getMessage(), SystemLog::CATEGORY_WEBHOOK, SystemLog::EVENT_WEBHOOK_FAILURE, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->resolveClient(), $this->company, - ); + ))->handle(); $this->release($this->backoff()[$this->attempts()-1]); } @@ -220,7 +227,6 @@ class WebhookSingle implements ShouldQueue private function resolveClient() { - nlog(get_class($this->entity)); //make sure it isn't an instance of the Client Model if (!$this->entity instanceof \App\Models\Client && @@ -230,9 +236,9 @@ class WebhookSingle implements ShouldQueue $this->entity->client()->exists()) { return $this->entity->client; } - return null; + } public function failed($exception = null) diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 1b7d2ba1a4d4..b0949dc593df 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -416,7 +416,6 @@ class EventServiceProvider extends ServiceProvider ], InvoiceWasPaid::class => [ InvoicePaidActivity::class, - CreateInvoicePdf::class, ], InvoiceWasViewed::class => [ InvoiceViewedActivity::class, @@ -434,7 +433,6 @@ class EventServiceProvider extends ServiceProvider ], InvoiceWasDeleted::class => [ InvoiceDeletedActivity::class, - CreateInvoicePdf::class, ], InvoiceWasArchived::class => [ InvoiceArchivedActivity::class,