diff --git a/app/Events/Invoice/InvoiceWasPaid.php b/app/Events/Invoice/InvoiceWasPaid.php index dffe4343d..af1ff6401 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 6c76c56b6..df2817bcf 100644 --- a/app/Jobs/Util/WebhookSingle.php +++ b/app/Jobs/Util/WebhookSingle.php @@ -50,6 +50,7 @@ class WebhookSingle implements ShouldQueue private string $includes; private Company $company; + /** * Create a new job instance. * @@ -125,48 +126,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 - ); - - } - catch(\GuzzleHttp\Exception\ConnectException $e){ - + ))->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 - ); - - } - 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."; + ))->handle(); + } catch (BadResponseException $e) { + if ($e->getResponse()->getStatusCode() >= 400 && $e->getResponse()->getStatusCode() < 500) { + $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]); @@ -175,16 +175,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; @@ -197,45 +197,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 - ); - - } - catch (ClientException $e) { - + ))->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 - ); - - - } - catch (\Exception $e) { - + ))->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]); @@ -243,7 +236,7 @@ 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 && @@ -255,9 +248,9 @@ class WebhookSingle implements ShouldQueue return $this->entity->client; } - return null; + } public function failed($exception = null) diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 11671d396..a8814c6e5 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -418,7 +418,6 @@ class EventServiceProvider extends ServiceProvider ], InvoiceWasPaid::class => [ InvoicePaidActivity::class, - CreateInvoicePdf::class, ], InvoiceWasViewed::class => [ InvoiceViewedActivity::class, @@ -436,7 +435,6 @@ class EventServiceProvider extends ServiceProvider ], InvoiceWasDeleted::class => [ InvoiceDeletedActivity::class, - CreateInvoicePdf::class, ], InvoiceWasArchived::class => [ InvoiceArchivedActivity::class,