This commit is contained in:
oliver
2026-06-09 18:16:29 -03:00
parent f26ecc8646
commit 5b59f6c1a8
3 changed files with 45 additions and 53 deletions
+3 -32
View File
@@ -894,38 +894,9 @@ function buyCredits(keyName) {
const backdrop = document.getElementById("credits-backdrop");
backdrop._keyName = keyName;
document.getElementById("credits-key-name").textContent = keyName;
// Detect coupon discount from trailing digits in the code
const couponInput = document.getElementById("coupon-input");
const couponCode =
couponApplied && couponInput ? couponInput.value.trim() : "";
const discountMatch = couponCode.match(/(\d+)$/);
const discountCents = discountMatch ? parseInt(discountMatch[1], 10) : 0;
const prices = [
{ value: "5.50", cents: 550 },
{ value: "11.00", cents: 1100 },
{ value: "22.00", cents: 2200 },
{ value: "55.00", cents: 5500 },
];
backdrop.querySelector(".credits-options").innerHTML = prices
.map(({ value, cents }, i) => {
const badgeHtml =
discountCents > 0
? `<span class="credits-first-month">🎉 1st Month &euro;${(Math.max(0, cents - discountCents) / 100).toFixed(2)}</span>`
: "";
return `
<label class="credits-option">
<input type="radio" name="credits-amount" value="${value}"${i === 0 ? " checked" : ""} />
<div class="credits-option-content">
<span class="credits-option-label">&euro;&thinsp;${value}</span>
${badgeHtml}
</div>
</label>`;
})
.join("");
// default to first option
const radios = backdrop.querySelectorAll('input[name="credits-amount"]');
radios.forEach((r, i) => (r.checked = i === 0));
backdrop.classList.add("open");
}