My site sells just one type of product of business software with several editions at different prices and uses WorldPay for payment processing. The pricing is currently very simply and if somebody wants one unit then they pay say ?00. If they want two units they pay ?,000, three copies then ?,500. Discounts for the purchasing of multiple licences is handled by recrediting their credit card following purchase ie. buy 5 copies for ?,500 and then receive ?00 back. It is a bit messy and also confusing for customers.
What I now intend to do is have the first copy at full price and then all subsequent copies at half price. So, if 2 bought the cost would be 500+250=?50 (yep, reducing prices to try and get more multiple sales through). If 5 bought then the cost would be 500+250+250+250+250=?,500.
The needed logic seems clear enough. The total purchase price that I am trying to achieve is :-
unitprice + ((quantity-1)*unitprice/2)
My problem is that I do not understand the WorldPay code. I can stumble about and know enough to implement the current pricing structure but not the new prices. A snippet of the code is as follows and if anyone can help to decipher it I would be very grateful :-
function calc(x) {
x.amount.value = 0;
var y = x.price.length;
var z = x.qty.length;
var a = Number(x.amount.value);
var b,c,d;
d = true;
while(y > 0) {
b = Number(CheckNull(x.price[y-1].value));
c = Number(CheckNull(x.qty[y-1].value));
if(c < 0) {
d = false;
c = 0;
x.qty[y-1].value = c;
}
a += (b * c);
// alert("x.price["+eval(y-1)+"].value = "+x.price[y-1].value+"\nx.qty["+eval(y-1)+"].value = "+x.qty[y-1].value+"\na = "+a);
y--;
}
if(d == false) {
alert("Negative quantities not permitted; these have been set to zero.");
}
return a;
}
Thanks
Jonny
What I now intend to do is have the first copy at full price and then all subsequent copies at half price. So, if 2 bought the cost would be 500+250=?50 (yep, reducing prices to try and get more multiple sales through). If 5 bought then the cost would be 500+250+250+250+250=?,500.
The needed logic seems clear enough. The total purchase price that I am trying to achieve is :-
unitprice + ((quantity-1)*unitprice/2)
My problem is that I do not understand the WorldPay code. I can stumble about and know enough to implement the current pricing structure but not the new prices. A snippet of the code is as follows and if anyone can help to decipher it I would be very grateful :-
function calc(x) {
x.amount.value = 0;
var y = x.price.length;
var z = x.qty.length;
var a = Number(x.amount.value);
var b,c,d;
d = true;
while(y > 0) {
b = Number(CheckNull(x.price[y-1].value));
c = Number(CheckNull(x.qty[y-1].value));
if(c < 0) {
d = false;
c = 0;
x.qty[y-1].value = c;
}
a += (b * c);
// alert("x.price["+eval(y-1)+"].value = "+x.price[y-1].value+"\nx.qty["+eval(y-1)+"].value = "+x.qty[y-1].value+"\na = "+a);
y--;
}
if(d == false) {
alert("Negative quantities not permitted; these have been set to zero.");
}
return a;
}
Thanks
Jonny