From 97a48238b8748cdb11dccc30add56cc5edb87ef5 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 7 Jun 2026 18:56:24 -0300 Subject: [PATCH] follow webhook redirect: parse response and open checkout URL --- index.html | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 92c2974..e6fe707 100644 --- a/index.html +++ b/index.html @@ -2417,7 +2417,7 @@ } try { - await fetch(ORDER_WEBHOOK, { + const res = await fetch(ORDER_WEBHOOK, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -2434,6 +2434,27 @@ utm_content: document.getElementById('utm_content').value || null, }), }); + + if (!res.ok) { console.error('Webhook error:', res.status); return; } + + // Try to parse the response for a redirect URL + const ct = res.headers.get('content-type') || ''; + let data; + if (ct.indexOf('json') !== -1) { + data = await res.json(); + } else { + data = await res.text(); + } + + const checkoutUrl = (data && typeof data === 'object') + ? (data.url || data.checkout_url || data.checkoutUrl || data.redirect || data.redirect_url) + : null; + + if (checkoutUrl && checkoutUrl.startsWith('http')) { + window.open(checkoutUrl, '_blank'); + } else if (typeof data === 'string' && data.startsWith('http')) { + window.open(data, '_blank'); + } } catch (err) { console.error('Order webhook failed:', err); }