File tree 3 files changed +40
-0
lines changed
3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Spatie \WebhookServer \Events ;
4
+
5
+ class WebhookCallDispatchedEvent
6
+ {
7
+ public function __construct (
8
+ public string $ httpVerb ,
9
+ public string $ webhookUrl ,
10
+ public array |string $ payload ,
11
+ public array $ headers ,
12
+ public array $ meta ,
13
+ public array $ tags ,
14
+ public string $ uuid ,
15
+ ) {
16
+ }
17
+ }
Original file line number Diff line number Diff line change 5
5
use Illuminate \Foundation \Bus \PendingDispatch ;
6
6
use Illuminate \Support \Str ;
7
7
use Spatie \WebhookServer \BackoffStrategy \BackoffStrategy ;
8
+ use Spatie \WebhookServer \Events \WebhookCallDispatchedEvent ;
8
9
use Spatie \WebhookServer \Exceptions \CouldNotCallWebhook ;
9
10
use Spatie \WebhookServer \Exceptions \InvalidBackoffStrategy ;
10
11
use Spatie \WebhookServer \Exceptions \InvalidSigner ;
@@ -229,6 +230,16 @@ public function dispatch(): PendingDispatch
229
230
{
230
231
$ this ->prepareForDispatch ();
231
232
233
+ event (new WebhookCallDispatchedEvent (
234
+ $ this ->callWebhookJob ->httpVerb ,
235
+ $ this ->callWebhookJob ->webhookUrl ,
236
+ $ this ->callWebhookJob ->payload ,
237
+ $ this ->callWebhookJob ->headers ,
238
+ $ this ->callWebhookJob ->meta ,
239
+ $ this ->callWebhookJob ->tags ,
240
+ $ this ->callWebhookJob ->uuid ,
241
+ ));
242
+
232
243
return dispatch ($ this ->callWebhookJob );
233
244
}
234
245
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ use Illuminate \Support \Facades \Event ;
3
4
use Illuminate \Support \Facades \Queue ;
5
+ use Spatie \WebhookServer \Events \WebhookCallDispatchedEvent ;
4
6
use function PHPUnit \Framework \assertTrue ;
5
7
use Spatie \WebhookServer \CallWebhookJob ;
6
8
use Spatie \WebhookServer \Exceptions \CouldNotCallWebhook ;
155
157
156
158
Queue::assertPushed (CallWebhookJob::class);
157
159
});
160
+
161
+ it ('will fire an event when a webhook is initially dispatched ' , function () {
162
+ Event::fake ();
163
+
164
+ $ url = 'https://localhost ' ;
165
+
166
+ WebhookCall::create ()->url ($ url )->useSecret ('123 ' )->dispatchIf (true );
167
+
168
+ Event::assertDispatched (WebhookCallDispatchedEvent::class, 1 );
169
+ });
You can’t perform that action at this time.
0 commit comments