.
This commit is contained in:
@@ -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 €${(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">€ ${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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user