Skip to content

PTHMINT-119: SSE event stream support and EventManager#59

Open
zulquer wants to merge 1 commit intoPTHMINT-118from
PTHMINT-119
Open

PTHMINT-119: SSE event stream support and EventManager#59
zulquer wants to merge 1 commit intoPTHMINT-118from
PTHMINT-119

Conversation

@zulquer
Copy link
Copy Markdown
Collaborator

@zulquer zulquer commented Apr 23, 2026

This pull request introduces a new event streaming API for order events, allowing clients to subscribe to real-time updates using server-sent events (SSE). It includes new response models, event stream handling, and updates for backward compatibility with both singular and plural event field names in order responses.

The most important changes are:

Event Streaming API Implementation:

  • Added the EventManager class (event_manager.py) and its public interface (__init__.py) to manage event stream subscriptions for orders. This provides methods to subscribe to event streams using event tokens and URLs, or directly from order response objects. [1] [2]
  • Introduced the EventStream class (stream/__init__.py) to handle server-sent event streams, including deserialization of payloads and context manager support. This enables iteration over live event messages from the SSE endpoint.

Event Response Models:

  • Added new response models for SSE events: Event, EventData, and EventDataPayload, including recursive deserialization for nested payloads. [1] [2] [3] [4]

Order Response Backward Compatibility:

  • Updated the Order response model to support both singular and plural forms of event-related fields (events_token, event_token, etc.), with normalization logic to ensure compatibility with different API payloads. [1] [2] [3]

Example Usage:

  • Added a new example script subscribe_events.py demonstrating how to create a Cloud POS order and subscribe to its event stream using the new API.

Client Exports:

  • Re-exported ServerSentEvent and ServerSentEventStream from the client package for easier access.

Introduce Server-Sent Events support and helpers for subscribing to order event streams. Adds a generic SSE client (ServerSentEvent, ServerSentEventStream, StreamingResponse) and an EventStream adapter with Event/EventData response models under api.paths.events.stream. Adds EventManager to provide convenient subscribe_events/subscribe_order_events methods and exposes it via Sdk.get_event_manager(). Order response model now normalizes new plural events_* and legacy event_* fields for compatibility. Also export SSE types from multisafepay.client, include an example script, and add unit and E2E tests covering stream parsing, manager behavior, and compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant