开发者

How to handle a price change in DB just when a customer is placing an order online?

开发者 https://www.devze.com 2023-03-29 04:05 出处:网络
I have a Product database table with columns such as product_id, price, and inventory_count. A user clicks to buy a certain product at a certain price. My program generates a confirmation page listin

I have a Product database table with columns such as product_id, price, and inventory_count.

A user clicks to buy a certain product at a certain price. My program generates a confirmation page listing the product and the price. Everything is fine and the user clicks "Confirm". My program 开发者_如何转开发updates the inventory_count of that product and charges the user's credit card the amount listed in the product's price.

But during the time after the confirmation page is generated but before the user clicks "Confirm", the price of that product has been changed. So the user might have seen a price of $10 in the confirmation page but after he clicks "Confirm" the price in the Product table has already been changed to $11 and that's what he will be charged.

What's the best way to handle a situation like this? I'm using MySQL and Python if that's relevant.


Create a new table for pending purchases with the price you intend to actually charge, and add items to it when you generate the confirmation page.

Deduct from the Product table's inventory_count when you add an item to the Pending table, then you can re-increment the inventory_count if the purchase doesn't go through.


You definitely should carry over the price from the time the customer last had the chance to change his mind. I'm sure that's also a legal issue in which you'd not look so good.

Anyway, can't be to hard to implement one last check after the customer has confirmed, right? Maybe you then could show a notice that the price has changed.


I my opinion you should avoid situations like this (if I were your customer I would be disappointed). But if you can't, when customer press confirm, do the last check of price and show message to user if it changed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号