Skip to content

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

Open
zulquer wants to merge 2 commits into
masterfrom
PTHMINT-119
Open

PTHMINT-119: SSE event stream support and EventManager#59
zulquer wants to merge 2 commits into
masterfrom
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.

@zulquer zulquer force-pushed the PTHMINT-118 branch 2 times, most recently from a3ccc41 to 08221e9 Compare April 30, 2026 10:40
Base automatically changed from PTHMINT-118 to master May 8, 2026 09:18
zulquer added 2 commits May 11, 2026 12:34
Introduce Server-Sent Events support and higher-level helpers for subscribing to order event streams. Adds multisafepay.client.sse (ServerSentEvent, ServerSentEventStream, StreamingResponse) and an EventStream adapter under api.paths.events.stream to deserialize SSE payloads into Event/EventData models. Adds EventManager for subscribing by token or from an Order response, and exposes get_event_manager() on the Sdk. Extend Order response to include events_token/events_url/events_stream_url with normalization for backward compatibility with legacy event_token/event_stream_url fields. Include an example (examples/event_manager/subscribe_events.py), update examples/order_manager/cloud_pos_order.py, update README with usage and env vars, export SSE types from client.__init__, and add unit and e2e tests for stream and manager behavior. Also contains small formatting/.env and test tweaks.
Introduce streaming HTTP support across the SDK: add HTTPStreamResponse and open_stream(...) to the HTTPTransport protocol and export HTTPStreamResponse from transport package. Update RequestsTransport to share request preparation with a new open_stream implementation and return a _RequestsStreamResponse adapter that exposes readline(), close(), and raise_for_status(). Modify SSE client and EventStream to use the configured transport.open_stream(...) (and raise a clear error if the transport lacks streaming support), and pass the client transport from EventManager to EventStream.open. Update README and unit tests to reflect streaming behavior and ensure streams are closed on failing status checks.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.44%. Comparing base (8954459) to head (e36297e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #59      +/-   ##
==========================================
- Coverage   92.83%   92.44%   -0.39%     
==========================================
  Files         164      172       +8     
  Lines        2889     3192     +303     
==========================================
+ Hits         2682     2951     +269     
- Misses        207      241      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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