diff --git a/src/client/Cosmetics.ts b/src/client/Cosmetics.ts index 7e694207f..380a25e87 100644 --- a/src/client/Cosmetics.ts +++ b/src/client/Cosmetics.ts @@ -31,6 +31,8 @@ export interface Pattern { notShown?: boolean; } +export const PURCHASE_SUCCESS_PARAM = "purchase-success"; + export async function patterns( userMe: UserMeResponse | null, ): Promise { @@ -109,8 +111,8 @@ export async function handlePurchase(priceId: string) { }, body: JSON.stringify({ priceId: priceId, - successUrl: `${window.location.href}purchase-success`, - cancelUrl: `${window.location.href}purchase-cancel`, + successUrl: `${window.location.href}#${PURCHASE_SUCCESS_PARAM}=true`, + cancelUrl: `${window.location.href}#${PURCHASE_SUCCESS_PARAM}=false`, }), }, ); @@ -139,7 +141,8 @@ export async function listAllProducts(): Promise> { const products = (await response.json()) as StripeProduct[]; const productMap = new Map(); products.forEach((product) => { - productMap.set(product.metadata.flare, product); + const flare = `${product.metadata.type}:${product.metadata.name}`; + productMap.set(flare, product); }); return productMap; } catch (error) { diff --git a/src/client/Main.ts b/src/client/Main.ts index 239f6184d..f4baf4cff 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -7,6 +7,7 @@ import { getServerConfigFromClient } from "../core/configuration/ConfigLoader"; import { GameType } from "../core/game/Game"; import { UserSettings } from "../core/game/UserSettings"; import { joinLobby } from "./ClientGameRunner"; +import { PURCHASE_SUCCESS_PARAM } from "./Cosmetics"; import "./DarkModeButton"; import { DarkModeButton } from "./DarkModeButton"; import "./FlagInput"; @@ -399,13 +400,24 @@ class Client { private handleHash() { const { hash } = window.location; - if (hash.startsWith("#")) { - const params = new URLSearchParams(hash.slice(1)); - const lobbyId = params.get("join"); - if (lobbyId && ID.safeParse(lobbyId).success) { - this.joinModal.open(lobbyId); - console.log(`joining lobby ${lobbyId}`); - } + if (!hash.startsWith("#")) { + return; + } + const params = new URLSearchParams(hash.slice(1)); + const lobbyId = params.get("join"); + if (lobbyId && ID.safeParse(lobbyId).success) { + this.joinModal.open(lobbyId); + console.log(`joining lobby ${lobbyId}`); + } + + const purchaseSuccess = params.get(PURCHASE_SUCCESS_PARAM); + // TODO: Add a purchase success/failure modal + if (purchaseSuccess === "true") { + alert("Purchase successful!"); + window.history.replaceState(null, "", window.location.pathname); + } else if (purchaseSuccess === "false") { + alert("Purchase cancelled"); + window.history.replaceState(null, "", window.location.pathname); } }