From 3db50a1f7afb7fd9f4bcd2a4f76fe56ea9bc31f0 Mon Sep 17 00:00:00 2001 From: SimonB Date: Tue, 19 Sep 2023 15:51:35 +0100 Subject: [PATCH 1/2] Update WebhookCallEvent.php to accept string payload and add additional test to capture this case. --- src/Events/WebhookCallEvent.php | 2 +- tests/CallWebhookJobTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Events/WebhookCallEvent.php b/src/Events/WebhookCallEvent.php index 86c2934..aeed36d 100644 --- a/src/Events/WebhookCallEvent.php +++ b/src/Events/WebhookCallEvent.php @@ -10,7 +10,7 @@ abstract class WebhookCallEvent public function __construct( public string $httpVerb, public string $webhookUrl, - public array $payload, + public array|string $payload, public array $headers, public array $meta, public array $tags, diff --git a/tests/CallWebhookJobTest.php b/tests/CallWebhookJobTest.php index e2281cc..b8db727 100644 --- a/tests/CallWebhookJobTest.php +++ b/tests/CallWebhookJobTest.php @@ -321,3 +321,32 @@ function baseGetRequest(array $overrides = []): array ->testClient ->assertRequestsMade([$baseRequest]); }); + + +it('send raw body data in event if rawBody is set', function () { + $this->testClient->throwConnectionException(); + + $testBody = "anotherOption"; + WebhookCall::create() + ->url('https://example.com/webhooks') + ->useSecret('abc') + ->sendRawBody($testBody) + ->doNotSign() + ->dispatch(); + + $baseRequest = baseRequest(); + + $baseRequest['options']['body'] = $testBody; + unset($baseRequest['options']['headers']['Signature']); + + artisan('queue:work --once'); + + Event::assertDispatched(WebhookCallFailedEvent::class, function (WebhookCallFailedEvent $event) use ($testBody) { + expect($event->errorType)->not->toBeNull() + ->and($event->errorMessage)->not->toBeNull() + ->and($event->payload)->toBe($testBody); + + return true; + }); +}); + From 7bf12090906ae33ef4c8394e82ef29a8c7048a7d Mon Sep 17 00:00:00 2001 From: SimonB Date: Tue, 19 Sep 2023 15:55:04 +0100 Subject: [PATCH 2/2] Update Readme with further details. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15e265b..27ab217 100644 --- a/README.md +++ b/README.md @@ -352,7 +352,8 @@ or activate the `throw_exception_on_failure` global option of the `webhook-serve By default, all webhooks will transform the payload into JSON. Instead of sending JSON, you can send any string by using the `sendRawBody(string $body)` option instead. -Due to type mismatch in the Signer API, it is currently not support to sign raw data requests +Due to type mismatch in the Signer API, it is currently not support to sign raw data requests. +When using the _sendRawBody_ option, you will receive a _string_ payload in the WebhookEvents. ```php WebhookCall::create() ->sendRawBody("someXMLContent")