File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -46,14 +46,16 @@ class CallWebhookJob implements ShouldQueue
46
46
/** @var string|null */
47
47
public $ queue = null ;
48
48
49
- public array $ payload = [];
49
+ public array | string $ payload = [];
50
50
51
51
public array $ meta = [];
52
52
53
53
public array $ tags = [];
54
54
55
55
public string $ uuid = '' ;
56
56
57
+ public string $ outputType = "JSON " ;
58
+
57
59
protected ?Response $ response = null ;
58
60
59
61
protected ?string $ errorType = null ;
@@ -69,7 +71,7 @@ public function handle()
69
71
try {
70
72
$ body = strtoupper ($ this ->httpVerb ) === 'GET '
71
73
? ['query ' => $ this ->payload ]
72
- : ['body ' => json_encode ( $ this ->payload )];
74
+ : ['body ' => $ this ->generateBody ( )];
73
75
74
76
$ this ->response = $ this ->createRequest ($ body );
75
77
@@ -162,4 +164,12 @@ private function dispatchEvent(string $eventClass)
162
164
$ this ->transferStats
163
165
));
164
166
}
167
+
168
+ private function generateBody (): string
169
+ {
170
+ return match ($ this ->outputType ) {
171
+ "RAW " => $ this ->payload ,
172
+ default => json_encode ($ this ->payload ),
173
+ };
174
+ }
165
175
}
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ class WebhookCall
25
25
26
26
private array $ payload = [];
27
27
28
+ private string $ rawBody ;
28
29
private $ signWebhook = true ;
29
30
30
31
public static function create (): self
@@ -255,6 +256,14 @@ public function dispatchSyncUnless($condition): void
255
256
$ this ->dispatchSyncIf (! $ condition );
256
257
}
257
258
259
+ public function sendRawBody (string $ body ): self
260
+ {
261
+ $ this ->callWebhookJob ->payload = $ body ;
262
+ $ this ->callWebhookJob ->outputType = "RAW " ;
263
+
264
+ return $ this ;
265
+ }
266
+
258
267
protected function prepareForDispatch (): void
259
268
{
260
269
if (! $ this ->callWebhookJob ->webhookUrl ) {
Original file line number Diff line number Diff line change @@ -300,3 +300,24 @@ function baseGetRequest(array $overrides = []): array
300
300
return true ;
301
301
});
302
302
});
303
+
304
+ it ('send raw body data if rawBody is set ' , function () {
305
+ $ testBody = "<xml>anotherOption</xml> " ;
306
+ WebhookCall::create ()
307
+ ->url ('https://example.com/webhooks ' )
308
+ ->useSecret ('abc ' )
309
+ ->sendRawBody ($ testBody )
310
+ ->doNotSign ()
311
+ ->dispatch ();
312
+
313
+ $ baseRequest = baseRequest ();
314
+
315
+ $ baseRequest ['options ' ]['body ' ] = $ testBody ;
316
+ unset($ baseRequest ['options ' ]['headers ' ]['Signature ' ]);
317
+
318
+ artisan ('queue:work --once ' );
319
+
320
+ $ this
321
+ ->testClient
322
+ ->assertRequestsMade ([$ baseRequest ]);
323
+ });
You can’t perform that action at this time.
0 commit comments