App\services\PushService::sendNotification PHP Method

sendNotification() public method

public sendNotification ( Invoice $invoice, $type )
$invoice app\models\Invoice
$type
    public function sendNotification(Invoice $invoice, $type)
    {
        if (!IOS_PUSH_CERTIFICATE) {
            return;
        }
        //check user has registered for push notifications
        if (!$this->checkDeviceExists($invoice->account)) {
            return;
        }
        //Harvest an array of devices that are registered for this notification type
        $devices = json_decode($invoice->account->devices, TRUE);
        foreach ($devices as $device) {
            if ($device["notify_{$type}"] == TRUE && $device['device'] == 'ios') {
                $this->pushMessage($invoice, $device['token'], $type);
            }
        }
    }

Usage Example

 /**
  * @param PaymentWasCreated $event
  */
 public function createdPayment(PaymentWasCreated $event)
 {
     // only send emails for online payments
     if (!$event->payment->account_gateway_id) {
         return;
     }
     $this->contactMailer->sendPaymentConfirmation($event->payment);
     $this->sendEmails($event->payment->invoice, 'paid', $event->payment);
     $this->pushService->sendNotification($event->payment->invoice, 'paid');
 }