diff --git a/CHANGELOG.md b/CHANGELOG.md index dc80de8..d088441 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-webhook-server` will be documented in this file +## 1.8.0 - 2020-03-18 + +- add `uuid` + ## 1.7.0 - 2020-03-05 - add `dispatchNow` (#39) diff --git a/README.md b/README.md index 704bb55..7081bb7 100644 --- a/README.md +++ b/README.md @@ -295,6 +295,7 @@ All these events have these properties: - `tags`: the array of [tags](#adding-tags) used - `attempt`: the attempt number - `response`: the response returned by the remote app. Can be an instance of `\GuzzleHttp\Psr7\Response` or `null`. +- `uuid`: a unique string to identify this call. This uuid will be the same for all attempts of a webhook call. ## Testing diff --git a/src/CallWebhookJob.php b/src/CallWebhookJob.php index f3ca27d..3806ed7 100644 --- a/src/CallWebhookJob.php +++ b/src/CallWebhookJob.php @@ -45,6 +45,8 @@ class CallWebhookJob implements ShouldQueue public array $tags = []; + public string $uuid = ''; + private ?Response $response = null; private ?string $errorType = null; @@ -121,7 +123,8 @@ private function dispatchEvent(string $eventClass) $this->attempts(), $this->response, $this->errorType, - $this->errorMessage + $this->errorMessage, + $this->uuid )); } } diff --git a/src/Events/WebhookCallEvent.php b/src/Events/WebhookCallEvent.php index 3a6fd8f..42f26b2 100644 --- a/src/Events/WebhookCallEvent.php +++ b/src/Events/WebhookCallEvent.php @@ -26,6 +26,8 @@ abstract class WebhookCallEvent public ?string $errorMessage; + public string $uuid; + public function __construct( string $httpVerb, string $webhookUrl, @@ -36,7 +38,8 @@ public function __construct( int $attempt, ?Response $response, ?string $errorType, - ?string $errorMessage + ?string $errorMessage, + string $uuid ) { $this->httpVerb = $httpVerb; $this->webhookUrl = $webhookUrl; @@ -48,5 +51,6 @@ public function __construct( $this->response = $response; $this->errorType = $errorType; $this->errorMessage = $errorMessage; + $this->uuid = $uuid; } } diff --git a/src/WebhookCall.php b/src/WebhookCall.php index 70aeaa9..8452ed0 100644 --- a/src/WebhookCall.php +++ b/src/WebhookCall.php @@ -2,6 +2,7 @@ namespace Spatie\WebhookServer; +use Illuminate\Support\Str; use Spatie\WebhookServer\BackoffStrategy\BackoffStrategy; use Spatie\WebhookServer\Exceptions\CouldNotCallWebhook; use Spatie\WebhookServer\Exceptions\InvalidBackoffStrategy; @@ -12,6 +13,8 @@ class WebhookCall { protected CallWebhookJob $callWebhookJob; + protected string $uuid = ''; + protected string $secret; protected Signer $signer; @@ -25,6 +28,7 @@ public static function create(): self $config = config('webhook-server'); return (new static()) + ->uuid(Str::uuid()) ->onQueue($config['queue']) ->useHttpVerb($config['http_verb']) ->maximumTries($config['tries']) @@ -41,14 +45,14 @@ public function __construct() $this->callWebhookJob = app(CallWebhookJob::class); } - public function url(string $url) + public function url(string $url): self { $this->callWebhookJob->webhookUrl = $url; return $this; } - public function payload(array $payload) + public function payload(array $payload): self { $this->payload = $payload; @@ -57,35 +61,42 @@ public function payload(array $payload) return $this; } - public function onQueue(string $queue) + public function uuid(string $uuid): self + { + $this->uuid = $uuid; + + return $this; + } + + public function onQueue(string $queue): self { $this->callWebhookJob->queue = $queue; return $this; } - public function useSecret(string $secret) + public function useSecret(string $secret): self { $this->secret = $secret; return $this; } - public function useHttpVerb(string $verb) + public function useHttpVerb(string $verb): self { $this->callWebhookJob->httpVerb = $verb; return $this; } - public function maximumTries(int $tries) + public function maximumTries(int $tries): self { $this->callWebhookJob->tries = $tries; return $this; } - public function useBackoffStrategy(string $backoffStrategyClass) + public function useBackoffStrategy(string $backoffStrategyClass): self { if (! is_subclass_of($backoffStrategyClass, BackoffStrategy::class)) { throw InvalidBackoffStrategy::doesNotExtendBackoffStrategy($backoffStrategyClass); @@ -96,14 +107,14 @@ public function useBackoffStrategy(string $backoffStrategyClass) return $this; } - public function timeoutInSeconds(int $timeoutInSeconds) + public function timeoutInSeconds(int $timeoutInSeconds): self { $this->callWebhookJob->requestTimeout = $timeoutInSeconds; return $this; } - public function signUsing(string $signerClass) + public function signUsing(string $signerClass): self { if (! is_subclass_of($signerClass, Signer::class)) { throw InvalidSigner::doesImplementSigner($signerClass); @@ -114,35 +125,35 @@ public function signUsing(string $signerClass) return $this; } - public function withHeaders(array $headers) + public function withHeaders(array $headers): self { $this->headers = $headers; return $this; } - public function verifySsl(bool $verifySsl = true) + public function verifySsl(bool $verifySsl = true): self { $this->callWebhookJob->verifySsl = $verifySsl; return $this; } - public function doNotVerifySsl() + public function doNotVerifySsl(): self { $this->verifySsl(false); return $this; } - public function meta(array $meta) + public function meta(array $meta): self { $this->callWebhookJob->meta = $meta; return $this; } - public function withTags(array $tags) + public function withTags(array $tags): self { $this->callWebhookJob->tags = $tags;