feat: replace WebSocket with REST + polling + webhooks (0.4.0)#7
Merged
Conversation
Replaces the WebSocket-based PortalSDK with a REST HTTP client that
mirrors the TypeScript SDK's async operation pattern.
## New architecture
- PortalClient: HTTP client using java.net.http.HttpClient (Java 17)
- AsyncOperation<T>: record { streamId, CompletableFuture<T> done }
- PollOptions: builder for polling interval/timeout/per-event callback
- StreamEvent: base event with type, index, timestamp, isTerminal()
- WebhookPayload: extends StreamEvent with streamId field
## Async operations
Methods that trigger a portal async operation return AsyncOperation<T>
immediately. Events resolve the done future via:
- Polling: client.pollUntilComplete(streamId, PollOptions.defaults())
- Webhooks: client.deliverWebhookPayload(rawBody, xPortalSignature)
(HMAC-SHA256 verified, routed to matching CompletableFuture)
## New model classes
AuthResponseData, AuthResponseStatus, KeyHandshakeResult,
RecurringPaymentResponseContent, RecurringPaymentStatus,
InvoicePaymentResponse, PayInvoiceResponse, EventsResponse,
VersionResponse, InfoResponse, WalletInfoResponse, RequestInvoiceParams
## Removed
- PortalSDK.java (WebSocket-based)
- PortalWsClient.java
- Response.java / ResponseDeserializer.java
- command/ package (all WS request/response/notification classes)
Aligns with lib PR#171 (refactor/portal-rest: REST + polling + webhooks)
4c2b8de to
af545f3
Compare
- requestSinglePayment: use payment_request: {...} not flat body
- requestPaymentRaw: use payment_request: {...} not flat body
- requestRecurringPayment: use payment_request: {...} not flat body
- requestInvoice: use content: {...} not flat body
All four endpoints expect a nested wrapper field — flattening the
content into the top-level body caused 400/422 errors at runtime.
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.
Summary
Replaces the WebSocket-based
PortalSDKwith a REST HTTP client that mirrors the TypeScript SDK's async operation pattern.Architecture
All async methods return
AsyncOperation<T>immediately:streamId— available right away (use it to track the operation)done—CompletableFuture<T>that resolves with the typed result when a terminal event arrivesEvents are delivered via:
client.deliverWebhookPayload(rawBody, signature)(HMAC-SHA256 verified)client.pollUntilComplete(op, PollOptions)as a fallbackStreamEventis used only internally and for per-event callbacks (PollOptions.onEvent). Terminal payloads are deserialized directly toT— no raw JSON is ever exposed in the public API.Async methods
requestSinglePayment(...)AsyncOperation<InvoiceStatus>requestPaymentRaw(...)AsyncOperation<InvoiceStatus>requestRecurringPayment(...)AsyncOperation<RecurringPaymentResponseContent>requestInvoice(...)AsyncOperation<InvoicePaymentResponse>requestCashu(...)AsyncOperation<CashuResponseStatus>authenticateKey(...)AsyncOperation<AuthResponseData>newKeyHandshakeUrl(...)AsyncOperation<KeyHandshakeResult>Sync methods
health(),version(),info(),fetchProfile(),payInvoice(),closeRecurringPayment(),issueJwt(),verifyJwt(),addRelay(),removeRelay(),mintCashu(),burnCashu(),sendCashuDirect(),calculateNextOccurrence(),fetchNip05Profile(),getWalletInfo()New classes
PortalClientjava.net.http(Java 17, no new deps)AsyncOperation<T>streamId+CompletableFuture<T> donePollOptionsStreamEventWebhookPayloadstreamIdInvoiceStatusInvoicePaymentResponseKeyHandshakeResultAuthResponseDataRecurringPaymentResponseContentRemoved
PortalSDK.java(WebSocket)PortalWsClient.javaResponse.java/ResponseDeserializer.javacommand/package (all WS request/response/notification classes)org.java-websocketdependencyNotes
wheatley/rest-api-webhooks)