Skip to content

AI credits: Confirm a top-up only once the balance grows - #4745

Draft
gcsecsey wants to merge 4 commits into
trunkfrom
gcsecsey/ai-credits-purchase-confirmation
Draft

AI credits: Confirm a top-up only once the balance grows#4745
gcsecsey wants to merge 4 commits into
trunkfrom
gcsecsey/ai-credits-purchase-confirmation

Conversation

@gcsecsey

Copy link
Copy Markdown
Member

Related issues

How AI was used in this PR

I used Opus 5 for implementation and tests.

Proposed Changes

Returning from WordPress.com checkout tells you nothing about whether the purchase worked — and today it does something worse than nothing. Both front ends throw you out of your conversation and into Settings on every return, including a cancelled one.

A cancelled checkout comes back exactly like a completed one, so the return itself proves nothing. This PR waits for the balance to actually grow, then says so: a toast in the Agentic UI, a card above the composer in Classic, both reading 500,000 AI credits added.

Every other outcome is silent. Cancelling is the most likely of them, and a "didn't work" message after a deliberate cancel is noise. The balance still refreshes either way, and you stay where you were.

A browser tab cannot receive the wp-studio:// return, and on desktop you may close the checkout tab instead of clicking through. So the same check also runs on window focus after checkout has been opened. One entry point now opens checkout everywhere, which covers both routes back.

The copy is the wording from the exploration in #4446. One thing it did not have: a View usage action on the toast. @shaunandrews — worth a look, along with staying silent after a cancel.

Testing Instructions

Use the balance setup steps in 236947-ghe-Automattic/wpcom.

  1. Buy the smallest top-up from Add AI credits. Confirm you stay where you were, and one toast reads N AI credits added. View usage opens Settings → Usage.
  2. Start checkout and cancel it. Confirm no message appears, and that you are not moved to Settings.
  3. Repeat step 1 in the browser UI (studio ui), which has no deep link. The purchase confirms when the Studio tab regains focus.
  4. Repeat step 1 in Classic. The confirmation is a card above the composer, and it clears itself after 8 seconds.

Check both color schemes.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

⚠️ Visual change: the Classic card needs a human review in light + dark mode.

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