Skip to content

Fix - Payment state issue#35

Open
akbarsaputrait wants to merge 14 commits into
masterfrom
fix/payment-state-issue
Open

Fix - Payment state issue#35
akbarsaputrait wants to merge 14 commits into
masterfrom
fix/payment-state-issue

Conversation

@akbarsaputrait
Copy link
Copy Markdown
Member

@akbarsaputrait akbarsaputrait commented May 31, 2026

Summary

  • Checkout API enforcement — Force the checkout API to be used when a token is switched while an existing rozoPaymentId is present, preventing stale payment state from carrying over.
  • resetPayId for checkout mode — Added the ability to reset the payment ID in checkout mode, enabling cleaner flow re-initialization.
  • PostHog analytics — Added payment tracking events for confirmation and payment state transitions. Also added posthog-js as an optional peer dependency.
  • New example app — Replaced the playground with a full Next.js example app (examples/nextjs-app) featuring:
    • Live preview
    • Code snippet toggle
    • Logo and favicon support

Packages Released

Package Version
@rozoai/intent-common 0.1.18
@rozoai/intent-pay 0.1.26

Test Plan

  • Checkout flow: switch token mid-payment and verify the checkout API is used instead of stale payment state.
  • Reset paymentId in checkout mode and verify the flow can be cleanly re-initiated.
  • Verify PostHog events are emitted on payment confirmation and payment state transitions.
  • Verify the example app loads correctly at /, and that the live preview and code snippet toggle function as expected.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
intent-example Ready Ready Preview, Comment Jun 2, 2026 1:29pm

Request Review

….23, and improve payment state management in example app
@akbarsaputrait akbarsaputrait marked this pull request as ready for review June 1, 2026 14:51
@shawnmuggle
Copy link
Copy Markdown
Member

Overall

The setPaymentUnpaid generalization is a real fix and the optional-PostHog wiring (no-op when host doesn't pass an instance) is the right shape. One change in this PR is a real API break that needs a decision before merge, plus three reliability bugs found by a second-pass review.


🔴 P0 — Blocker

1. useRozoPay export is commented out — breaking change

  • packages/connectkit/src/index.ts:18// export { useRozoPay } from "./hooks/useRozoPay";
  • useRozoPay was a public hook. Commenting out the barrel export breaks every consumer who imports it directly.
  • Neither the PR description nor the CHANGELOG mentions this. If the deprecation is intentional (in favor of useRozoPayUI), please call it out as a breaking change + provide a migration note. Otherwise restore the export.

🟡 P1 — Should fix before publish

2. PAYMENT_FLOW_STARTED / PAYMENT_CANCELLED conflate intent vs. action

  • RozoPayProvider.tsx:233PAYMENT_FLOW_STARTED fires whenever the modal opens, before any user action.
  • RozoPayProvider.tsx:254PAYMENT_CANCELLED fires on close from preview / payment_unpaid, so "opened, looked, closed" gets logged as flow_started → cancelled, indistinguishable from "picked a method, quoted, then aborted".
  • Funnel rate will look much worse than reality on day one.
  • Suggestion: fire payment_flow_started on first quote request (or first method selection), and emit a distinct modal_dismissed for raw close events. Keep payment_cancelled only after a real method/quote action was taken.

3. Unsafe error narrowing — (error as Error).message.includes(...) can throw

  • packages/connectkit/src/components/Pages/Solana/PayWithSolanaToken/index.tsx:318
  • packages/connectkit/src/components/Pages/Stellar/PayWithStellarToken/index.tsx:342
  • packages/connectkit/src/components/Pages/Stellar/PayWithStellarToken/index.tsx:412
  • Each catches error: unknown then casts to Error and dereferences .message. If a non-Error is thrown (e.g. a wallet provider returning a plain object, a string, or undefined), the .message.includes(...) access throws inside the catch block, masking the original payment failure with a TypeError.
  • Guard with error instanceof Error ? error.message : String(error) before the .includes() check.

4. PAYMENT_CANCELLED payload may carry undefined payment_id

  • RozoPayProvider.tsx:254 — uses paymentState.rozoPaymentId, which can be undefined in payId / order-loaded flows even when pay.order.externalId is set.
  • Fall back to pay.order?.externalId ?? pay.order?.id (same pattern already used elsewhere in the file).

5. Event schema is drifting between SDK and host apps

  • intent-pay/.../lib/analytics/events.ts defines ROZO_EVENTS = {...GLOBAL_EVENTS, ...PAYMENT_EVENTS} only.
  • rozo-chat-ai/.../lib/analytics/events.ts defines a much larger union (WALLET, REWARDS, CHAT, UTILITY, plus PAGE_VIEWED).
  • Both will land in the same PostHog project. Worth extracting a shared @rozoai/analytics-events package now, before more apps fork their own copy.

Notes (verified, not findings)

  • package.json version is 0.1.23 and matches the CHANGELOG header — earlier diff snapshots showed 0.1.23-beta.3 but the current HEAD is correct ✓
  • posthog-js peer dep ^1.0.0 is correct — npm latest is still 1.377.0, not v2 ✓

Preview verification

/bridge on the preview loads cleanly. Confirm button gates correctly until token + address are filled. Package versions panel shows @rozoai/intent-pay@0.1.23.


Reviewed by Claude (Opus 4.7) + codex CLI second opinion (FAIL verdict).

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.

2 participants