Skip to content

Commit

Permalink
Merge pull request #147 from DotNetSimon/fix_webhook_event_type_for_r…
Browse files Browse the repository at this point in the history
…aw_body

Fix webhook event type for raw body
  • Loading branch information
freekmurze authored Sep 25, 2023
2 parents 0586057 + 7bf1209 commit 6f4f1e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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("<root>someXMLContent</root>")
Expand Down
2 changes: 1 addition & 1 deletion src/Events/WebhookCallEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions tests/CallWebhookJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<xml>anotherOption</xml>";
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;
});
});

0 comments on commit 6f4f1e0

Please sign in to comment.