Skip to content

feat(checkout): subscribe via Hypery's hosted subscribe page - #24

Merged
spacedevin merged 2 commits into
mainfrom
feat/hosted-subscribe
Sep 15, 2026
Merged

spacedevin merged 2 commits into
mainfrom
feat/hosted-subscribe

Conversation

@spacedevin

Copy link
Copy Markdown
Member

Switches kind: 'subscription' (and useAppSubscription().subscribe / SubscribeButton) to the hosted subscribe page from hyperyai/hypery#193.

Requires that server release (/api/marketplace/subscribe-sessions); against an older gateway subscribing will fail.

Flow

  • Ensure logged in (unchanged).
  • POST /api/marketplace/subscribe-sessions with {planId, interval?, state} (state from crypto.getRandomValues).
    • popup: returnOrigin = origin of config.redirectUri; opens hypery-subscribe 480x760; only a hypery:subscribe message from the gateway origin with matching sessionId + state is accepted (new accept hook on openPopup). Closed popup -> cancelled.
    • redirect / blocked popup: returnUrl = current URL minus subscribe params; persists {sessionId, state, input} in hypery_pending_subscribe; on return verifies state, strips params via history.replaceState, fetches result, sets status + new lastResult.
  • GET .../:id/result is authoritative: success only on completed -> data: {subscription, team}; cancelled/pending/expired -> cancelled; state mismatch -> STATE_MISMATCH error.
  • Subscription no longer uses /api/marketplace/subscribe or card-setup popups; purchase/topup untouched. idempotencyKey on subscription input is deprecated/ignored.
  • useAppSubscription refreshes after a redirect-return success. No team fields added to AppSubscription (server summaries don't expose them).

Checks

  • npx tsc --noEmit OK, npm run build OK, bun test src 50 pass (new subscribe-session.test.ts: body building, message validation, return parsing/cleanup, outcome mapping; docs-coverage passes).

Subscriptions now create a hosted subscribe session and open it in a popup
(or redirect), where the user picks the team, card and interval. The outcome
is verified with a random state and the session /result endpoint. Adds
lastResult to useCheckout, SubscribeSessionResult type, docs and tests.

Requires the gateway release with hosted subscribe sessions (hyperyai/hypery#193).
…up blockers

Open a named about:blank loading window synchronously before any await when
the user is already logged in, navigate it to the session URL once created,
close it if session creation fails, and fall back to redirect when blocked.
openPopup accepts an existing window.
@spacedevin
spacedevin merged commit 2c8b6d3 into main Sep 15, 2026
4 checks passed
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