Overview
Use merchant WebSockets for realtime invoice and payment updates across your account. These streams emit canonicalPepayEvent frames for invoice.* and invoice_payment.*.
If you are building commerce order UIs, use the commerce stream to receive commerce.order.* updates. See WebSockets (commerce).
For webhook signature validation, see Webhooks (merchant).
Authentication in the SDK
The SDK connects via query params, so use a short-livedws_token minted server-side. WebSocket headers (for direct x-api-key auth) are supported by the raw endpoint but are not wired into the SDK today.
Request
Mint a ws_token
Connect to merchant events
Filters you can pass
types: Comma-separated event types (supports wildcards, e.g.invoice.*).invoice_type: Optional invoice type filter.invoice_id: Scope to a single invoice.customer_id: Scope to a merchant customer.environment:devnetormainnet.format:event_v1(recommended).
Common use cases
- Merchant dashboards:
types=invoice.*,invoice_payment.*with optionalenvironmentfilter. - Single-invoice UI: pass
invoice_idto reduce noise. - Commerce order tracking: use the commerce stream with
types=commerce.order.*and optionalorder_id.
Commerce stream (order lifecycle)
Use the commerce stream forcommerce.order.* updates and linked invoice/payment context. See WebSockets (commerce) for the full guide.
Response
Example event frame:Event frames and delivery
object=event: business events (PepayEvent).object=ws_control: replay/resync hints (listen viastream.on('control')).object=ws_error: terminal error (connection closes).- Delivery is at-least-once; dedupe by
event.id.
Relationship to webhooks
- Merchant WebSockets deliver the same event types as merchant webhooks.
- The WebSocket stream includes replay + REST backfill, making it more redundant and reliable than webhooks for realtime consumption.
- Webhooks remain best for server-to-server side effects and audit trails.
Recovery and backfill
connectMerchantEvents and connectCommerceEvents return a PepayEventStream that:
- Replays from
since=<last_event_id>on reconnect. - Backfills missed events over REST (
/api/v1/events). - Buffers WS frames during backfill and emits in order.
- Recovery is disabled if no API key is available. To force it, pass
recovery.request.authwith the appropriate key. - Use
connectMerchantEventsRaworconnectCommerceEventsRawif you want raw websockets without REST backfill.
SDK configuration
webSocketFactoryis required outside the browser (usewsin Node).websocketBaseUrloverrides the default ws URL.wsHeartbeatMs,wsIdleTimeoutMs, andwsPingMessagecontrol liveness behavior.retrycontrols reconnect backoff.
Examples
- Persist the last seen
event.idin durable storage so you can resume after deploys/restarts.

