driveflexfuel
New Member
- Messages
- 159
- Reaction score
- 0
- Points
- 0
I like paypal cart over google cart and now you can make your own promotion codes for paypal cart. I use the code below and it works great. If you are worried about security you can place the script in a .js file and secure the include folder. I hope this helps out some of you useing paypal carts.
Code:
<script type="text/javascript">
<!--
var discnt = 0; // no default percent discount
var coupons = new Array ( // place to put coupon codes
"coup1", // 1st coupon value - comma seperated
"coup2", // 2nd coupon value - add all you want
"coup3" // 3rd coupon value
);
var coupdc = new Array ( // place to put discounts for coupon vals
5,
10,
15
);
var coupval = "(blanket)"; // what user entered as coupon code
function ChkCoup () { // check user coupon entry
var i;
discnt = 0; // assume the worst
for (i=0; i<coupons.length; i++) {
if (coupval == coupons[i]) {
discnt = coupdc[i]; // remember the discount amt
alert ("This is a valid promo code! \n\n" + "$" + discnt +
" discount now in effect.");
return;
}
}
alert ("'" + coupval + "' is not a valid promo code!");
}
function Dollar (val) { // force to valid dollar amount
var str,pos,rnd=0;
if (val < .995) rnd = 1; // for 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 the discount
var amt,des;
amt = obj1.baseamt.value*1.0; // base amount
des = obj1.basedes.value; // base description
if (discnt > 0) { // only if discount is active
amt = Dollar (amt - discnt);
des = des + ", " + "$" + discnt + "dis, COUP = " + coupval;
}
obj1.amount.value = Dollar (amt);
obj1.item_name.value = des;
}
//-->
</script>
</head>
<body>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target = 'paypal';
return ReadForm (this);">
<p>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="Emailaddress.com" />
<input type="hidden" name="item_name" value="Item Name" />
<input type="hidden" name="amount" value="000.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="no_shipping" value="2" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-ShopCartBF">
<!-- Base Price -->
<input type="hidden" name="baseamt" value="0.00" />
<!-- Base Discription -->
<input type="hidden" name="basedes" value="4VAB-EV1 @369.99" />
Enter Coupon code:
<input type = "text"
size = "10"
name = "coupcode"; />
<input type="button" value="Varify Promo"
onclick="coupval = this.form.coupcode.value;
ChkCoup();" />
<br /><br />
<!--Page Contents-->
Input quantity >
<input type="text" name="quantity" value="1" size="4" />
<input type="image" src="addcart.gif" name="submit" alt="cart add" />
</p>
</form>