🐛 Fixed paid checkout returning to homepage instead of originating page#28485
Draft
9larsons wants to merge 1 commit into
Draft
🐛 Fixed paid checkout returning to homepage instead of originating page#284859larsons wants to merge 1 commit into
9larsons wants to merge 1 commit into
Conversation
ref https://linear.app/ghost/issue/PLA-86 ref #28369 - checkoutPlan() already derived a contextual cancelUrl from window.location but had no equivalent fallback for successUrl, so the standard signup/upgrade callers omitted it and the backend fell back to the site-root default — landing paid members on the homepage after Stripe Checkout instead of the article they just unlocked - mirrors the existing cancelUrl logic and continueGiftCheckout(), which already does this for gift flows - backend sanitizeReturnUrl() already enforces same-origin, so the contextual URL flows through safely with no server change needed
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
When a member starts a paid signup or upgrade from a page other than the homepage, Portal returned them to the site root after a successful Stripe Checkout (e.g.
https://example.com/?stripe=success) instead of the page where checkout began. Cancelling checkout already returned to the originating page, so the behaviour was inconsistent — and especially disruptive for paywall flows, where a member who just paid to unlock an article was bounced to the homepage instead of back to the article.Root cause
checkoutPlan()inapps/portal/src/utils/api.jsalready derived a contextualcancelUrlfromwindow.locationwhen none was supplied, but had no equivalent fallback forsuccessUrl. The two standard callers (signup and upgrade inapps/portal/src/actions.js) don't pass one, sosuccessUrlarrived at the backend asundefinedand Ghost fell back to the configured site-root default (stripe-api.js→checkoutSessionSuccessUrl).Fix
Derive a contextual
successUrlfromwindow.locationwhen none is supplied, mirroring the existingcancelUrllogic. This is the same approachcontinueGiftCheckout()already uses for gift flows (and matches #27643 / #27827).No backend change is needed:
sanitizeReturnUrl()already enforces that return URLs are same-origin / within the site subpath, so the contextual URL flows through safely.Behaviour preserved
_generateSuccessUrl); the contextual URL only applies when no welcome page is set.referrer, so the member returns to the originating page after confirming (an improvement over the previous site-root referrer).Tests
Added unit tests in
apps/portal/test/api.test.jscovering:successUrl/cancelUrlderived from the current page when none suppliedsuccessUrl/cancelUrlare preservedref https://linear.app/ghost/issue/PLA-86
fixes #28369