PTHMINT-119: SSE event stream support and EventManager#59
Open
zulquer wants to merge 4 commits intoPTHMINT-118from
Open
PTHMINT-119: SSE event stream support and EventManager#59zulquer wants to merge 4 commits intoPTHMINT-118from
zulquer wants to merge 4 commits intoPTHMINT-118from
Conversation
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.
a3ccc41 to
08221e9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
EventManagerclass (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]EventStreamclass (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:
Event,EventData, andEventDataPayload, including recursive deserialization for nested payloads. [1] [2] [3] [4]Order Response Backward Compatibility:
Orderresponse 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:
subscribe_events.pydemonstrating how to create a Cloud POS order and subscribe to its event stream using the new API.Client Exports:
ServerSentEventandServerSentEventStreamfrom the client package for easier access.