From fe948cb65e6bf8f7cdee24d5a2666a6e27434b7b Mon Sep 17 00:00:00 2001 From: evanpelle Date: Mon, 4 Aug 2025 20:06:55 -0700 Subject: [PATCH] Alert on payment success or failure. (#1705) ## Description: Alert on payment success or failure. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I have read and accepted the CLA agreement (only required once). ## Please put your Discord username so you can be contacted if a bug or regression is found: evan --- src/client/Cosmetics.ts | 5 ++--- src/client/Main.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/client/Cosmetics.ts b/src/client/Cosmetics.ts index 01a4a5de0..bfd991c4a 100644 --- a/src/client/Cosmetics.ts +++ b/src/client/Cosmetics.ts @@ -41,9 +41,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.origin}#purchase-completed=true`, + cancelUrl: `${window.location.origin}#purchase-completed=false`, }), }, ); diff --git a/src/client/Main.ts b/src/client/Main.ts index 732a58c12..03d04c777 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -423,8 +423,25 @@ class Client { private handleHash() { const { hash } = window.location; + + const alertAndStrip = (message: string) => { + alert(message); + history.replaceState( + null, + "", + window.location.pathname + window.location.search, + ); + }; + if (hash.startsWith("#")) { const params = new URLSearchParams(hash.slice(1)); + if (params.get("purchase-completed") === "true") { + alertAndStrip("purchase succeeded"); + return; + } else if (params.get("purchase-completed") === "false") { + alertAndStrip("purchase failed"); + return; + } const lobbyId = params.get("join"); if (lobbyId && ID.safeParse(lobbyId).success) { this.joinModal.open(lobbyId);