Skip to content

Commit 6f4f1e0

Browse files
authored
Merge pull request #147 from DotNetSimon/fix_webhook_event_type_for_raw_body
Fix webhook event type for raw body
2 parents 0586057 + 7bf1209 commit 6f4f1e0

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ or activate the `throw_exception_on_failure` global option of the `webhook-serve
352352

353353
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.
354354

355-
Due to type mismatch in the Signer API, it is currently not support to sign raw data requests
355+
Due to type mismatch in the Signer API, it is currently not support to sign raw data requests.
356+
When using the _sendRawBody_ option, you will receive a _string_ payload in the WebhookEvents.
356357
```php
357358
WebhookCall::create()
358359
->sendRawBody("<root>someXMLContent</root>")

src/Events/WebhookCallEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ abstract class WebhookCallEvent
1010
public function __construct(
1111
public string $httpVerb,
1212
public string $webhookUrl,
13-
public array $payload,
13+
public array|string $payload,
1414
public array $headers,
1515
public array $meta,
1616
public array $tags,

tests/CallWebhookJobTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,32 @@ function baseGetRequest(array $overrides = []): array
321321
->testClient
322322
->assertRequestsMade([$baseRequest]);
323323
});
324+
325+
326+
it('send raw body data in event if rawBody is set', function () {
327+
$this->testClient->throwConnectionException();
328+
329+
$testBody = "<xml>anotherOption</xml>";
330+
WebhookCall::create()
331+
->url('https://example.com/webhooks')
332+
->useSecret('abc')
333+
->sendRawBody($testBody)
334+
->doNotSign()
335+
->dispatch();
336+
337+
$baseRequest = baseRequest();
338+
339+
$baseRequest['options']['body'] = $testBody;
340+
unset($baseRequest['options']['headers']['Signature']);
341+
342+
artisan('queue:work --once');
343+
344+
Event::assertDispatched(WebhookCallFailedEvent::class, function (WebhookCallFailedEvent $event) use ($testBody) {
345+
expect($event->errorType)->not->toBeNull()
346+
->and($event->errorMessage)->not->toBeNull()
347+
->and($event->payload)->toBe($testBody);
348+
349+
return true;
350+
});
351+
});
352+

0 commit comments

Comments
 (0)