33namespace NotificationChannels \OneSignal ;
44
55use Berkayk \OneSignal \OneSignalClient ;
6- use NotificationChannels \OneSignal \Exceptions \CouldNotSendNotification ;
7- use Illuminate \Notifications \Notification ;
86use Psr \Http \Message \ResponseInterface ;
7+ use Illuminate \Notifications \Notification ;
8+ use NotificationChannels \OneSignal \Exceptions \CouldNotSendNotification ;
99
1010class OneSignalChannel
1111{
12-
1312 /** @var OneSignalClient */
1413 protected $ oneSignal ;
1514
@@ -21,26 +20,28 @@ public function __construct(OneSignalClient $oneSignal)
2120 /**
2221 * Send the given notification.
2322 *
24- * @param mixed $notifiable
23+ * @param mixed $notifiable
2524 * @param \Illuminate\Notifications\Notification $notification
2625 *
2726 * @throws \NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification
2827 */
2928 public function send ($ notifiable , Notification $ notification )
3029 {
31- if (!$ userIds = $ notifiable ->routeNotificationFor ('OneSignal ' )) {
30+ if (! $ userIds = $ notifiable ->routeNotificationFor ('OneSignal ' )) {
3231 return ;
3332 }
3433
3534 $ payload = $ notification ->toOneSignal ($ notifiable )->toArray ();
35+
3636 if (is_array ($ userIds ) && array_key_exists ('email ' , $ userIds )) {
37- $ payload ['filters ' ] = collect ([[" field " => " email " , " value " => $ userIds ['email ' ]]]);
37+ $ payload ['filters ' ] = collect ([[' field ' => ' email ' , ' value ' => $ userIds ['email ' ]]]);
3838 } else {
3939 $ payload ['include_player_ids ' ] = collect ($ userIds );
4040 }
4141
4242 /** @var ResponseInterface $response */
4343 $ response = $ this ->oneSignal ->sendNotificationCustom ($ payload );
44+
4445 if ($ response ->getStatusCode () !== 200 ) {
4546 throw CouldNotSendNotification::serviceRespondedWithAnError ($ response );
4647 }
0 commit comments