views:

121

answers:

6

I am not using a pre-made shopping cart, I programming it myself. It works perfectly fine 99% of the time, but about once every couple months an order goes through for $0. I cannot figure out why. I make a test purchase with the same product and all the same info and I cannot get it to be $0 for me. I am not sure how to go about trouble shooting this, I do have a disclaimer saying that we do not honor erroneous prices. The client wants this to stop happening though. I am using PHP to do all of this. Since I cannot seem to duplicate the occurnace myself I am finding it hard to get to the bottom of the issue. Can anyone offer some advice on how to troubleshoot this?

Thanks!!

+1  A: 

Do you have a URL to the site?

Otherwise I can only guess that somewhere you are allowing data passed in by the user to determine the price (e.g. a hidden field or a parameter) which the user can override.

Make sure you are passing an ID for the product to your server side code, and multiply the price on the server * the order quantity. (e.g. never trust user input)

scunliffe
I am, I am never storing prices on client side, I retrieve prices form the server so users can't manipulate it.
John Isaacks
Here is the URL to the product page of the product that was purchased: http://www.kranichs.com/products/Kranichs/ring-331
John Isaacks
+3  A: 

Ultimately, you'll want to figure out why this is happening. Without seeing your code, I can't really help you out much with that. In the short term though, why not just add a sanity check at the end of the checkout process?

if ( $final_price < 1 ) {
    do_epic_fail(); // Show an error, whatever.
}
Eric Petroelje
I cannot explain why, but for some reason "do_epic_fail" made me crack up. I am definitely naming a function that the next chance I get.
Paolo Bergantino
Thanks, but some orders could possibly be free, if for example they were using a coupon code.
John Isaacks
Why don't you keep two seperate variables then? $base_cost and $discount? The total shown is $base_cost-$discount. You would use the above if statement on $base_cost.
ryeguy
@ryeguy that sounds like a good idea. Thanks.
John Isaacks
I lol'd. I'm adding custom error codes to a CMS at work and this might have to make an appearance :)
sanchothefat
A: 

Are you posting the amount details to the payment gateway from the client side (hidden form fields)? If so then it can easily overridden by using browser toolbars like web developer etc.

Always post the payment details from the server side.

Shoban
+3  A: 

I'd start by using some extensive order logging. Every click, every input, every sql query. Then when it happens again go through the logs of that order to see what happened.

There are a couple of possibilities that spring to mind. One, you have a transient error in the queries to pull the item totals. Maybe when the query fails you just default to 0.00. For example, what happens when they type -1 for the quantity or put in some text like 'ABC'

Alternatively you might have a sql injection issue where if the user puts something wrong in one of the fields it loads a zero value for price.

Whatever it is will come to light with the right logging.

Chris Lively
Can you point me to the right direction on how to get started on doing that? I am using PLESK if it matters. Thanks
John Isaacks
If you coded the shopping cart yourself, then just add a table to your database to store logging information. Then at various points (such as every time you run a sql query), log the post vars, sql query, and any other piece of information you have access to.
Chris Lively
The log will grow to be pretty big so monitor it often and trim as necessary.
Chris Lively
+1  A: 

Does your code rely on $_SESSION data? If a user was to wait a very long time, some necessary data might expire, but the checkout may still proceed.

As the others have said, it's difficult to comment further without source code.

David Caunt
Thanks I am storing the items in their cart in $_SESSION but not the prices for the items. The item was saved in the order too.
John Isaacks
A: 

If the final price is 0, perhaps check the order again to see if it actually contains any items. I could see possibly having an order for zero if you have any free items or special promotions going on, so perhaps this is the way to go.

This is a hard question to answer without seeing your source.

Heather