-
Notifications
You must be signed in to change notification settings - Fork 1k
Subscription upgrade/downgrade + tier management #3927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ import { | |||||||||||||||||||||||||||||||||||||
| } from "../core/Schemas"; | ||||||||||||||||||||||||||||||||||||||
| import { UserSettings } from "../core/game/UserSettings"; | ||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||
| changeSubscriptionTier, | ||||||||||||||||||||||||||||||||||||||
| createCheckoutSession, | ||||||||||||||||||||||||||||||||||||||
| getApiBase, | ||||||||||||||||||||||||||||||||||||||
| getUserMe, | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -41,10 +42,41 @@ export async function purchaseCosmetic( | |||||||||||||||||||||||||||||||||||||
| const colorPaletteName = resolved.colorPalette?.name; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (resolved.type === "subscription") { | ||||||||||||||||||||||||||||||||||||||
| const sub = c as Subscription; | ||||||||||||||||||||||||||||||||||||||
| const userMe = await getUserMe(); | ||||||||||||||||||||||||||||||||||||||
| const flares = userMe === false ? [] : (userMe.player.flares ?? []); | ||||||||||||||||||||||||||||||||||||||
| if (flares.some((f) => f.startsWith("subscription:"))) { | ||||||||||||||||||||||||||||||||||||||
| alert(translateText("store.already_subscribed")); | ||||||||||||||||||||||||||||||||||||||
| const currentSub = | ||||||||||||||||||||||||||||||||||||||
| userMe === false ? null : (userMe.player.subscription ?? null); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (currentSub) { | ||||||||||||||||||||||||||||||||||||||
| if (currentSub.tier === sub.name) { | ||||||||||||||||||||||||||||||||||||||
| alert(translateText("store.already_subscribed")); | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Direction-aware confirm based on priceMonthly. We don't have the | ||||||||||||||||||||||||||||||||||||||
| // server's sortOrder client-side — priceMonthly is a good proxy. | ||||||||||||||||||||||||||||||||||||||
| const currentCosmetic = | ||||||||||||||||||||||||||||||||||||||
| (await fetchCosmetics())?.subscriptions?.[currentSub.tier] ?? null; | ||||||||||||||||||||||||||||||||||||||
| const isUpgrade = | ||||||||||||||||||||||||||||||||||||||
| currentCosmetic !== null | ||||||||||||||||||||||||||||||||||||||
| ? sub.priceMonthly > currentCosmetic.priceMonthly | ||||||||||||||||||||||||||||||||||||||
| : true; | ||||||||||||||||||||||||||||||||||||||
| const targetName = translateCosmetic("subscriptions", sub.name); | ||||||||||||||||||||||||||||||||||||||
| const confirmKey = isUpgrade | ||||||||||||||||||||||||||||||||||||||
| ? "store.confirm_upgrade" | ||||||||||||||||||||||||||||||||||||||
| : "store.confirm_downgrade"; | ||||||||||||||||||||||||||||||||||||||
| const confirmed = window.confirm( | ||||||||||||||||||||||||||||||||||||||
| translateText(confirmKey, { tier: targetName }), | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
| if (!confirmed) return; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const ok = await changeSubscriptionTier(sub.name); | ||||||||||||||||||||||||||||||||||||||
| if (!ok) { | ||||||||||||||||||||||||||||||||||||||
| alert(translateText("store.change_tier_failed")); | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| alert(translateText("store.change_tier_success", { tier: targetName })); | ||||||||||||||||||||||||||||||||||||||
| window.location.reload(); | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -360,9 +392,14 @@ export function resolveCosmetics( | |||||||||||||||||||||||||||||||||||||
| // Subscriptions | ||||||||||||||||||||||||||||||||||||||
| const flares = | ||||||||||||||||||||||||||||||||||||||
| userMeResponse === false ? [] : (userMeResponse.player.flares ?? []); | ||||||||||||||||||||||||||||||||||||||
| const currentSubTier = | ||||||||||||||||||||||||||||||||||||||
| userMeResponse === false | ||||||||||||||||||||||||||||||||||||||
| ? null | ||||||||||||||||||||||||||||||||||||||
| : (userMeResponse.player.subscription?.tier ?? null); | ||||||||||||||||||||||||||||||||||||||
| for (const [subKey, sub] of Object.entries(cosmetics.subscriptions ?? {})) { | ||||||||||||||||||||||||||||||||||||||
| const key = `subscription:${subKey}`; | ||||||||||||||||||||||||||||||||||||||
| const rel = flares.includes(key) | ||||||||||||||||||||||||||||||||||||||
| const isCurrent = subKey === currentSubTier || flares.includes(key); | ||||||||||||||||||||||||||||||||||||||
| const rel: ResolvedCosmetic["relationship"] = isCurrent | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+395
to
+402
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use flare ownership only as a fallback.
Proposed change- const isCurrent = subKey === currentSubTier || flares.includes(key);
+ const isCurrent =
+ currentSubTier !== null ? subKey === currentSubTier : flares.includes(key);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| ? "owned" | ||||||||||||||||||||||||||||||||||||||
| : sub.product | ||||||||||||||||||||||||||||||||||||||
| ? "purchasable" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid defaulting unknown tier comparisons to “upgrade” messaging.
On Line 60–67, when the current tier is missing from
cosmetics.subscriptions,isUpgradedefaults totrue, so downgrade paths can show upgrade billing text. Use a neutral fallback confirm message when direction is unknown.💡 Suggested fix
Add a neutral translation key:
"store": { + "confirm_change_tier": "Switch to {tier}?", "confirm_upgrade": "Upgrade to {tier}? You'll be charged the prorated difference now.", "confirm_downgrade": "Downgrade to {tier}? You'll get account credit for the unused portion of your current plan.",📝 Committable suggestion
🤖 Prompt for AI Agents