Add URL promo code pre-fill and fix discount stacking logic

- Checkout page reads ?code= or ?promo= from URL, pre-fills and locks the
  promo field, shows the promo discount in the summary instead of the 15%
  bundle discount
- API: when a promo code % >= bundle %, replace the bundle discount entirely
  instead of stacking (e.g. MEMORIAL25 at 25% replaces the 15% bundle)
- Also checks discount code expiration in the query

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-21 15:06:19 -05:00
parent 5a07335b2f
commit d39e10485f
2 changed files with 31 additions and 13 deletions

View file

@ -182,6 +182,7 @@ function usd(c){return "$"+(c/100).toLocaleString("en-US",{minimumFractionDigits
var params=new URLSearchParams(window.location.search);
var rawKeys=(params.get("services")||"").split(",").map(function(s){return s.trim()}).filter(Boolean);
var frn=params.get("frn")||"";
var promoFromUrl=params.get("code")||params.get("promo")||"";
var slugs=[]; var seen={};
rawKeys.forEach(function(k){var s=CHECK_TO_SLUG[k]||k; if(SLUG_META[s]&&!seen[s]){slugs.push(s);seen[s]=1}});
if(slugs.indexOf("fcc-499a")>=0&&slugs.indexOf("fcc-499a-499q")>=0) slugs.splice(slugs.indexOf("fcc-499a"),1);
@ -326,15 +327,19 @@ function renderServices() {
var svcTotal=discountableTotal+nonDiscountableTotal;
var subtotal=svcTotal+govTotal;
var discountableSlugs = selectedSlugs.filter(function(s){ var m=SLUG_META[s]||{}; return m.price > 0 && !m.nodiscount; });
var hasDisc=discountableSlugs.length>=2;
var hasPromo=!!promoFromUrl;
var hasDisc=!hasPromo && discountableSlugs.length>=2;
var disc=hasDisc?Math.round(discountableTotal*0.15):0;
var promoDisc=hasPromo?Math.round(discountableTotal*0.25):0;
var summary=document.createElement("div");
summary.className="mt-4 p-4 bg-gray-50 border border-gray-200 rounded-lg";
var rows='<div class="flex justify-between text-sm mb-1"><span>'+selectedSlugs.length+' service'+(selectedSlugs.length>1?'s':'')+'</span><span>'+usd(svcTotal)+'</span></div>';
if(govTotal>0) rows+='<div class="flex justify-between text-sm text-gray-500 mb-1"><span>Government filing fees (passthrough)</span><span>'+usd(govTotal)+'</span></div>';
if(hasDisc) rows+='<div class="flex justify-between text-sm text-green-700 mb-1"><span>Bundle discount (15%)</span><span>-'+usd(disc)+'</span></div>';
rows+='<div class="flex justify-between font-bold text-base border-t border-gray-300 pt-2 mt-1"><span>Total</span><span>'+usd(subtotal-disc)+'</span></div>';
if(hasPromo) rows+='<div class="flex justify-between text-sm text-green-700 mb-1"><span>Memorial Day discount (25%) — code '+promoFromUrl.toUpperCase()+'</span><span>-'+usd(promoDisc)+'</span></div>';
else if(hasDisc) rows+='<div class="flex justify-between text-sm text-green-700 mb-1"><span>Bundle discount (15%)</span><span>-'+usd(disc)+'</span></div>';
var totalDisc=hasPromo?promoDisc:disc;
rows+='<div class="flex justify-between font-bold text-base border-t border-gray-300 pt-2 mt-1"><span>Total</span><span>'+usd(subtotal-totalDisc)+'</span></div>';
summary.innerHTML=rows;
listEl.appendChild(summary);
@ -397,6 +402,9 @@ function renderServices() {
'</form>';
listEl.appendChild(actions);
// Pre-fill promo code from URL
if(promoFromUrl){var promoEl=document.getElementById("pw-promo");if(promoEl){promoEl.value=promoFromUrl.toUpperCase();promoEl.readOnly=true;promoEl.style.background="#f0fdf4";promoEl.style.borderColor="#86efac";}}
// Batch checkout handler
document.getElementById("pw-batch-form").addEventListener("submit", function(e){
e.preventDefault();