Skip to content

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

Open
zulquer wants to merge 4 commits intoPTHMINT-118from
PTHMINT-119
Open

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

zulquer and others added 4 commits April 22, 2026 17:20
Introduce a CredentialResolver protocol, AuthScope dataclass and a default ScopedCredentialResolver to support resolving API keys by auth scope (default_account, partner_affiliate, terminal_group). Update Client and Sdk to accept an optional credential_resolver (and make api_key optional when a resolver is provided), add Client._resolve_api_key and auth_scope plumbing for request creation, and export ScopedCredentialResolver from the package. Add validation to require at least one credential source and improve error messages for missing/unknown scoped keys. Update and add unit tests to cover resolver behavior, header wiring, and SDK initialization with resolver-only configuration.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Introduce POS receipt models and manager, and add order cancel transaction support with terminal-group scoped auth.

- Add PosManager and POS /receipt response models (merchant, order, payment, related_transactions, Receipt) and wire it into the SDK.
- Add cancel transaction request/response models and integrate cancel_transaction into OrderManager.
- Extend OrderManager.create and cancel_transaction to accept optional terminal_group_id and pass AuthScope to the client; ensure order_id path segments are encoded.
- Add unit and integration tests for new behavior (order create scoped auth, cancel_transaction, get_receipt, OrderManager operations) and example scripts (cloud_pos_order, cancel, get_receipt).

These changes enable Cloud POS workflows (create, wait/cancel, fetch receipt) and support terminal-group scoped authentication for relevant endpoints.
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.
@zulquer zulquer force-pushed the PTHMINT-118 branch 2 times, most recently from a3ccc41 to 08221e9 Compare April 30, 2026 10:40
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