diff --git a/src/CallWebhookJob.php b/src/CallWebhookJob.php index 5c67a29..b173ccb 100644 --- a/src/CallWebhookJob.php +++ b/src/CallWebhookJob.php @@ -64,8 +64,6 @@ class CallWebhookJob implements ShouldQueue public function handle() { - $client = $this->getClient(); - $lastAttempt = $this->attempts() >= $this->tries; try { @@ -73,14 +71,7 @@ public function handle() ? ['query' => $this->payload] : ['body' => json_encode($this->payload)]; - $this->response = $client->request($this->httpVerb, $this->webhookUrl, array_merge([ - 'timeout' => $this->requestTimeout, - 'verify' => $this->verifySsl, - 'headers' => $this->headers, - 'on_stats' => function (TransferStats $stats) { - $this->transferStats = $stats; - }, - ], $body, is_null($this->proxy) ? [] : ['proxy' => $this->proxy])); + $this->response = $this->createRequest($body); if (! Str::startsWith($this->response->getStatusCode(), 2)) { throw new Exception('Webhook call failed'); @@ -135,6 +126,20 @@ protected function getClient(): ClientInterface return app(Client::class); } + protected function createRequest(array $body): Response + { + $client = $this->getClient(); + + return $client->request($this->httpVerb, $this->webhookUrl, array_merge([ + 'timeout' => $this->requestTimeout, + 'verify' => $this->verifySsl, + 'headers' => $this->headers, + 'on_stats' => function (TransferStats $stats) { + $this->transferStats = $stats; + }, + ], $body, is_null($this->proxy) ? [] : ['proxy' => $this->proxy])); + } + protected function shouldBeRemovedFromQueue(): bool { return false;