From ae5dc4745e40dd70981ed538768d1960c88df9ea Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 22 May 2026 00:56:44 -0500 Subject: [PATCH] Fix: fetch actual discount type/value from API instead of hardcoding 25% The checkout page was hardcoding 25% for all promo codes. Now fetches /api/v1/discount/:code to get real discount_type (percent vs flat) and discount_value, then displays correct amount. Co-Authored-By: Claude Opus 4.6 (1M context) --- site/public/order/fcc-compliance/index.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/site/public/order/fcc-compliance/index.html b/site/public/order/fcc-compliance/index.html index 087bb5c..91ffcf6 100644 --- a/site/public/order/fcc-compliance/index.html +++ b/site/public/order/fcc-compliance/index.html @@ -194,6 +194,9 @@ var listEl=document.getElementById("pw-svc-list"); var entityBar=document.getElementById("pw-entity-bar"); var bundleTip=document.getElementById("pw-bundle-tip"); +// Fetch promo code info from API if present +if(promoFromUrl){fetch(API+"/api/v1/discount/"+encodeURIComponent(promoFromUrl)).then(function(r){return r.json()}).then(function(d){if(d.valid){window._promoInfo=d;var cb=document.querySelector(".svc-cb:checked");if(cb)cb.dispatchEvent(new Event("change",{bubbles:true}));}}).catch(function(){});} + if(frn){ fetch(API+"/api/v1/fcc/lookup?frn="+frn+"&quick=1").then(function(r){return r.json()}).then(function(d){ if(d.entity_name){ @@ -331,13 +334,14 @@ function renderServices() { 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 promoDisc=0; + if(hasPromo&&window._promoInfo){var pi=window._promoInfo;if(pi.discount_type==="percent")promoDisc=Math.round(discountableTotal*pi.discount_value/100);else promoDisc=Math.min(pi.discount_value,discountableTotal);} var summary=document.createElement("div"); summary.className="mt-4 p-4 bg-gray-50 border border-gray-200 rounded-lg"; var rows='
'+selectedSlugs.length+' service'+(selectedSlugs.length>1?'s':'')+''+usd(svcTotal)+'
'; if(govTotal>0) rows+='
Government filing fees (passthrough)'+usd(govTotal)+'
'; - if(hasPromo) rows+='
Memorial Day discount (25%) — code '+promoFromUrl.toUpperCase()+'-'+usd(promoDisc)+'
'; + if(hasPromo&&promoDisc>0) rows+='
Discount — code '+promoFromUrl.toUpperCase()+(window._promoInfo?(" ("+window._promoInfo.description+")"):"")+'-'+usd(promoDisc)+'
'; else if(hasDisc) rows+='
Bundle discount (15%)-'+usd(disc)+'
'; var totalDisc=hasPromo?promoDisc:disc; rows+='
Total'+usd(subtotal-totalDisc)+'
';