Skip to content

WebPushSender

Viames Marino edited this page Nov 24, 2026 · 2 revisions

Pair framework: WebPushSender

Pair\Push\WebPushSender delivers a single push notification to one subscription using VAPID and minishlink/web-push.

Requirements

Composer package:

composer require minishlink/web-push

If library is missing, constructor throws RuntimeException.

Constructor

$sender = new \Pair\Push\WebPushSender();

Optionally pass a custom VapidConfig. With Minishlink Web Push 11, a PSR-3 logger can also be supplied as logger.

Main method

send(Notification $notification, PushSubscription $subscription): DeliveryResult

Behavior:

  • builds WebPush auth config from VAPID keys
  • creates Minishlink subscription object
  • serializes notification payload as JSON
  • sends notification and parses report
  • marks invalid subscriptions (404, 410) with shouldDeleteSubscription=true

Browser endpoints

Pair sends aes128gcm payloads to Apple and Microsoft WNS. For an Edge subscription hosted at *.notify.windows.com, Pair uses the Minishlink 11 PSR-18 client to send the encrypted payload with X-WNS-Type: wns/raw. Other endpoints retain their existing content encoding.

Applications that accept browser subscriptions can call Pair\Push\PushEndpoint::isSupported($endpoint) to allow only HTTPS endpoints on the standard Google, Mozilla, Apple and Microsoft push hosts. Custom push services can retain their own endpoint validation.

Minimal example

$result = $sender->send($notification, $subscription);

if (!$result->success) {
    // inspect $result->error and $result->statusCode
}

See also: VapidConfig, PushDispatcher, PairPush.js.

Clone this wiki locally