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) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-22 00:56:44 -05:00
parent fdbed5c097
commit ae5dc4745e

View file

@ -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='<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(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>';
if(hasPromo&&promoDisc>0) rows+='<div class="flex justify-between text-sm text-green-700 mb-1"><span>Discount — code '+promoFromUrl.toUpperCase()+(window._promoInfo?(" ("+window._promoInfo.description+")"):"")+'</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>';