diff --git a/scripts/autoload/donation_service.gd b/scripts/autoload/donation_service.gd
index 7b58834..c5f463e 100644
--- a/scripts/autoload/donation_service.gd
+++ b/scripts/autoload/donation_service.gd
@@ -5,6 +5,7 @@ const DEFAULT_URL := "https://s3q.ranaze.com/api/donations"
const REQUEST_TIMEOUT_SECONDS := 30.0
const POLL_INTERVAL_SECONDS := 3.0
const POLL_LIMIT := 200
+const CHECKOUT_STORAGE_KEY := "medmindDonationCheckoutUrl"
signal checkout_started(donation_id: String, checkout_url: String)
signal donation_status_changed(status: String, donation: Dictionary)
@@ -139,14 +140,14 @@ func _on_status_completed(result: int, response_code: int, _headers: PackedStrin
func _prepare_browser_window() -> void:
if OS.has_feature("web"):
JavaScriptBridge.eval(
- "window.medmindDonationWindow = window.open('about:blank', 'medmind_donation_checkout'); if (window.medmindDonationWindow) { window.medmindDonationWindow.document.title = 'MedMind secure checkout'; window.medmindDonationWindow.document.body.innerHTML = 'Opening secure checkout...This window will continue to Stripe.
'; }",
+ "window.localStorage.removeItem('%s'); window.medmindDonationWindow = window.open('about:blank', 'medmind_donation_checkout'); if (window.medmindDonationWindow) { var medmindWaitingWindow = window.medmindDonationWindow; medmindWaitingWindow.document.title = 'MedMind secure checkout'; medmindWaitingWindow.document.body.innerHTML = 'Opening secure checkout...This window will continue to Stripe.
'; medmindWaitingWindow.setInterval(function () { var checkoutUrl = medmindWaitingWindow.localStorage.getItem('%s'); if (checkoutUrl) { var checkout = medmindWaitingWindow.document.getElementById('medmind-checkout'); checkout.innerHTML = 'Secure checkout is ready.
Continue to Stripe
'; medmindWaitingWindow.document.getElementById('medmind-checkout-link').href = checkoutUrl; medmindWaitingWindow.localStorage.removeItem('%s'); medmindWaitingWindow.location.replace(checkoutUrl); } }, 150); }" % [CHECKOUT_STORAGE_KEY, CHECKOUT_STORAGE_KEY, CHECKOUT_STORAGE_KEY],
true)
func _open_checkout_url(url: String) -> void:
if OS.has_feature("web"):
JavaScriptBridge.eval(
- "var medmindCheckoutUrl = %s; var medmindCheckoutWindow = window.open(medmindCheckoutUrl, 'medmind_donation_checkout'); if (medmindCheckoutWindow) { window.medmindDonationWindow = medmindCheckoutWindow; medmindCheckoutWindow.focus(); } else if (window.medmindDonationWindow && !window.medmindDonationWindow.closed) { window.medmindDonationWindow.location.replace(medmindCheckoutUrl); window.medmindDonationWindow.focus(); } else { window.location.assign(medmindCheckoutUrl); }" % JSON.stringify(url),
+ "var medmindCheckoutUrl = %s; window.localStorage.setItem('%s', medmindCheckoutUrl); if (window.medmindDonationWindow && !window.medmindDonationWindow.closed) { window.medmindDonationWindow.focus(); } else { var medmindCheckoutWindow = window.open(medmindCheckoutUrl, 'medmind_donation_checkout'); if (medmindCheckoutWindow) { window.medmindDonationWindow = medmindCheckoutWindow; medmindCheckoutWindow.focus(); } else { window.location.assign(medmindCheckoutUrl); } }" % [JSON.stringify(url), CHECKOUT_STORAGE_KEY],
true)
else:
OS.shell_open(url)
@@ -155,7 +156,7 @@ func _open_checkout_url(url: String) -> void:
func _close_browser_window() -> void:
if OS.has_feature("web"):
JavaScriptBridge.eval(
- "if (window.medmindDonationWindow && !window.medmindDonationWindow.closed) { window.medmindDonationWindow.close(); } window.medmindDonationWindow = null;",
+ "window.localStorage.removeItem('%s'); if (window.medmindDonationWindow && !window.medmindDonationWindow.closed) { window.medmindDonationWindow.close(); } window.medmindDonationWindow = null;" % CHECKOUT_STORAGE_KEY,
true)