diff --git a/src/Provider/LaravelServiceProvider.php b/src/Provider/LaravelServiceProvider.php index f2f278d..4bf8356 100644 --- a/src/Provider/LaravelServiceProvider.php +++ b/src/Provider/LaravelServiceProvider.php @@ -24,12 +24,6 @@ public function boot() ], 'migrations'); } - protected function setupConfig() - { - $this->app->configure('webhooks-outgoing'); - parent::setupConfig(); - } - public function register() { parent::register(); diff --git a/src/Requests/EloquentRequest.php b/src/Requests/EloquentRequest.php index 0c1cec5..c8521ce 100644 --- a/src/Requests/EloquentRequest.php +++ b/src/Requests/EloquentRequest.php @@ -39,4 +39,7 @@ public function getMethod() return $this->method; } + public function signMessage() { + return false; + } } \ No newline at end of file diff --git a/src/Requests/RequestInterface.php b/src/Requests/RequestInterface.php index 45e6ef2..1d93982 100644 --- a/src/Requests/RequestInterface.php +++ b/src/Requests/RequestInterface.php @@ -11,4 +11,6 @@ public function getUrl(); public function getMethod(); public function getBody(); + + public function signMessage(); } \ No newline at end of file diff --git a/src/Services/RequestService.php b/src/Services/RequestService.php index 8c4e27e..516fa27 100644 --- a/src/Services/RequestService.php +++ b/src/Services/RequestService.php @@ -47,6 +47,10 @@ public function fire(RequestInterface $request) try { $httpRequest = new \GuzzleHttp\Psr7\Request($request->getMethod(), $request->getUrl(), ['Content-Type' => 'application/json'], json_encode($request->getBody())); + if($request->signMessage()) { + $httpRequest = $httpRequest->withHeader('X-Signature', $request->getSignature($httpRequest->getBody())); + } + $this->eventDispatcher->fire(new WebhookIsSending($request)); $response = $this->send($httpRequest); @@ -59,8 +63,23 @@ public function fire(RequestInterface $request) return $response; } + catch(\GuzzleHttp\Exception\ClientException $e){ + \Log::info("\GuzzleHttp\Exception\ClientException"); + + $this->eventDispatcher->fire(new WebhookEncounteredGuzzleError($request, $e)); + + if ($e->hasResponse()) { + $response = $e->getResponse(); + + $request->response_code = $response->getStatusCode(); + } + + $this->requests->save($request); + } catch(\GuzzleHttp\Exception\RequestException $e) { + \Log::info("\GuzzleHttp\Exception\RequestException"); + $this->eventDispatcher->fire(new WebhookEncounteredGuzzleError($request, $e)); if ($e->hasResponse()) { @@ -71,7 +90,7 @@ public function fire(RequestInterface $request) $this->requests->save($request); - throw $e; + // throw $e; } } diff --git a/src/Webhooks.php b/src/Webhooks.php index bcb0b55..3558274 100644 --- a/src/Webhooks.php +++ b/src/Webhooks.php @@ -35,6 +35,17 @@ public function generate($url, $body, $method='post') return $request; } + public function generateExt($url, $body, $params=[]) + { + if(!isset($params) || !isset($params['method'])){ + $params['method'] = 'post'; + } + + $request = $this->requests->create(array_merge(compact(['url', 'body']), $params)); + + return $request; + } + public function create($data) { $request = $this->requests->create($data);