Discount codes for web forms
mario_gudelj Feb 29, 2012 10:25 PMQuestion:
I have been using two web forms to allow access to a secure zone. Of them, one is for the trial user access and another is for the paid user access.
The problem is: Can I use discount codes for the secure zone access? I can't see the way of integrating eCommerce discount codes with web forms.
Answer:
Discount codes don't actually work with secure zone access since you have to accept payment through web forms. However, I hired an outside developer to write some code for me, which I don't mind sharing:
Put this in the Head of your document:
<script type="text/javascript">
function refreshAmountToCharge() {
var frm = document.forms[0];
var defaultAmountToCharge = 100;
var couponCode = "ABC123"; // A tribute to Michael Jackson...
var percentOff = 50;
var couponCode2 = "DISCOUNT2";
var percentOff2 = 67;
var couponCode3 = "DISCOUNT3";
var percentOff3 = 99;
var couponCode4 = "DISCOUNT4";
var percentOff4 = 75;
/* Fixed amount coupon c*/
var fixedCouponCode1 = "FIXED1";
var fixedAmount1 = 20.00;
var fixedCouponCode2 = "FIXED2";
var fixedAmount2 = 6.00;
var fixedCouponCode3 = "FIXED3";
var fixedAmount3 = 7.00;
var amountToCharge = defaultAmountToCharge.toFixed(2);
if (frm.couponCode.value.toUpperCase() == couponCode)
amountToCharge = (defaultAmountToCharge - (defaultAmountToCharge * percentOff / 100)).toFixed(2);
else if (frm.couponCode.value.toUpperCase() == couponCode2)
amountToCharge = (defaultAmountToCharge - (defaultAmountToCharge * percentOff2 / 100)).toFixed(2);
else if (frm.couponCode.value.toUpperCase() == couponCode3)
amountToCharge = (defaultAmountToCharge - (defaultAmountToCharge * percentOff3 / 100)).toFixed(2);
else if (frm.couponCode.value.toUpperCase() == couponCode4)
amountToCharge = (defaultAmountToCharge - (defaultAmountToCharge * percentOff4 / 100)).toFixed(2);
else if (frm.couponCode.value.toUpperCase() == fixedCouponCode1)
amountToCharge = (defaultAmountToCharge - fixedAmount1).toFixed(2);
else if (frm.couponCode.value.toUpperCase() == fixedCouponCode2)
amountToCharge = (defaultAmountToCharge - fixedAmount2).toFixed(2);
else if (frm.couponCode.value.toUpperCase() == fixedCouponCode3)
amountToCharge = (defaultAmountToCharge - fixedAmount3).toFixed(2);
frm.Amount.value = amountToCharge;
}
// ----------- End Coupon Code Javascript ---------------------
</script>
Then, you'll need a Coupon Code field in your form:
<div class="item"> <label for="couponCode">Coupon Code</label><br /> <input type="text" name="couponCode" id="couponCode" class="cat_textbox" /> <a href="javascript:refreshAmountToCharge()">Update</a> </div>
That's it. Let me know if you have any questions. You can set multiple codes, either percentage based or fixed amount. Experiment with it to make sure it works as expected.


