javascript - Adding Discount code button to Paypal buy now button -


i'm trying add discount code paypal button, javascript works , says discount code valid isn't taking discount off amount when click buy button pay.

can me please

<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <p>please click on link pay</p> <input type="hidden" name="cmd" value="_cart" /> <input type="hidden" name="upload" value="1" /> <input type="hidden" name="business" value="<?php echo c_our_email; ?>" /> <input type="hidden" name="first_name" value="<?php echo strfordisp($ofirstname); ?>" /> <input type="hidden" name="last_name" value="<?php echo strfordisp($olastname); ?>" /> <input type="hidden" name="address1" value="<?php echo strfordisp($theorder["oaddress"]); ?>" /> <input type="hidden" name="address2" value="<?php echo strfordisp($theorder["oaddress2"]); ?>" /> <input type="hidden" name="address3" value="<?php echo strfordisp($theorder["oaddress3"]); ?>" /> <input type="hidden" name="city" value="<?php echo strfordisp($theorder["otown"]); ?>"> <input type="hidden" name="zip" value="<?php echo strfordisp($theorder["opostcode"]); ?>" />   <?php $orderdets = mysql_query("select * c4d_orderitems orderid='" . $_session["db_order"] . "' , confirm"); $iloop = 1; while ($orderrow = mysql_fetch_array($orderdets)) { $itemdesc = $orderrow["itemtypedesc"]; $itemdesc .= " " . $orderrow["dpostcode"]; $itemprice = $orderrow["cost"] + $orderrow["surcharge"] + $orderrow["insurancecost"]; ?> <input type='hidden' name="item_name_<?php echo $iloop; ?>" value='<?php echo strfordisp($itemdesc); ?>' /> <input type='hidden' name="item_number_<?php echo $iloop; ?>" value='<?php echo $orderrow["itemtype"]; ?>' /> <input type='hidden' name="amount_<?php echo $iloop; ?>" value='<?php   if ((strtoupper($ofirstname)=="pctrendstest") || (strtoupper($olastname)=="pctrendstest") || (substr($_server['remote_addr'],0,11)=="82.152.55.1"))   echo("0.01");   else echo $itemprice; ?>' />   <input type='hidden' name="baseamt_<?php echo $iloop; ?>" value='<?php if ((strtoupper($ofirstname)=="pctrendstest") || (strtoupper($olastname)=="pctrendstest") || (substr($_server['remote_addr'],0,11)=="82.152.55.1"))   echo("0.01");   else echo $itemprice; ?>' />  <input type="hidden" name="basedes_<?php echo $iloop; ?>" value="" />    <input type='hidden' name="quantity_<?php echo $iloop; ?>" value='1' />  <?     $iloop++;   }   ?> <input type="hidden" name="return" value="<?php echo c_site_root; ?>stage7.php" /> <meta http-equiv="return" content="3;url=stage7.php" /> <input type="hidden" name="cancel-return" value="<?php echo c_site_root; ?>order-cancel.php" /> <input type="hidden" name="notify_url" value="<?php echo c_site_root; ?>paypal.php" /> <input type="hidden" name="rm" value="2" /> <input type="hidden" name="invoice" value="<?php echo $_session["db_order"]; ?>" /> <input type="hidden" name="currency_code" value="gbp" /> <input type="hidden" name="no-shipping" value="1" /> <input type="hidden" name="button_subtype" value="products" /> <input type="hidden" name="bn" value="pp-buynowbf:btn_buynowcc_lg.gif:nonhostedguest" /> <input type="hidden" name="country" value="gb" />   enter coupon code <input type="text" size="10" name="coupcode"; /> <input type="button" value="check code" onclick="coupval =this.form.coupcode.value;  chkcoup();" />    <p class='fmenu'><input type="image" src="https://www.paypal.com/en_us/i/btn/btn_buynowcc_lg.gif" border="0" name="submit" alt="paypal - safer, easier way pay online!">      <img alt="" border="0" src="https://www.paypal.com/en_us/i/scr/pixel.gif" width="1" height="1"></p>      </form> 

the javascript is:

var discnt = 0;   // no default percent discount    var coupons = new array (  // place put coupon codes    "coup1",                 // 1st coupon value - comma seperated    "coup2",                 // 2nd coupon value - add want    "coup3"                  // 3rd coupon value ); var coupdc  = new array ( 5,10,15  // place put discounts coupon vals ); var coupval = "(blanket)"; // user entered coupon code function chkcoup () {      // check user coupon entry var i;   discnt = 0;              // assume worst   (i=0; i<coupons.length; i++) {     if (coupval == coupons[i]) {       discnt = coupdc[i];  // remember discount amt       alert ("this valid promo code! \n\n" + discnt + "%" +" discount in effect.");       return;      }   }   alert ("'" + coupval + "'  not valid promo code!"); } function pound (val) {      // force valid pound amount var str,pos,rnd=0;   if (val < .995) rnd = 1;  // old netscape browsers   str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape   pos = str.indexof (".");   if (pos > 0) str = str.substring (rnd, pos + 3);   return str; } function readform (obj1) {  // apply discount var amt,des;   amt = obj1.amount_<?php echo $iloop; ?>.value*1.0;       // base amount   des = obj1.basedes_<?php echo $iloop; ?>.value;           // base description   if (discnt > 0) {                   // if discount active     amt = pound (amt - (amt * discnt/100.0));     des = des + ", " + discnt + "%" + "dis, coup = " + coupval;   }   obj1.amount.value = pound (amt);   obj1.item_name.value = des;  } 


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -