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") 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; + }); +}); +