How to Prevent Duplicate Order Charges in WP E-Commerce

Duplicate orders can happen for a number of reason in WP E-Commerce, usually the result of a bug or server error. This doesn’t tend to be a problem unless of course your customers are being charged more than once for the same order. At its core, WP E-Commerce does not verify if a user’s cart has been paid for before sending it through a merchant gateway. Herein lies the problem. To prevent a user from being charged more than once for a single order, WordPress needs to keep track of which user carts have been paid for and prevent carts from being processed through a merchant gateway if it’s already been processed. Sound tricky? Well we made a plugin that does this!
The WPEC Prevent Duplicate Charges plugin is available for download on GitHub (https://github.com/ProQSolutions/wpec-prevent-duplicate-charges).

About This Plugin

This plugin is for WP E-Commerce carts experiencing occasional duplicate charges. The cause can be the result of PHP errors, your bad code, or user error. But the root problem, I found, is the same. This plugin doesn’t fix the problems in your code, but it will prevent your customers from being charged more than once for a single order, even if caused by server issues or user error.

How This Plugin Works

If for any reason an order has been submitted for checkout more than once, it will not be allowed to proceed through the designated gateway, and instead redirected to transaction results. The plugin will go through the following:

  1. When an order is submitted at checkout, it checks to see if the current cart has been associated with an approved purchase log.
  2. If it has, then it redirects the user to the transaction results page immediately, empties the cart, and doesn’t let the merchant charge anything.
  3. If it hasn’t been associate with an approved purchased log, then the plugin adds hooks to narrow in at the moment a merchant plugin updates the transaction to “Approved”
  4. At this moment, when the merchant approves the transaction, the plugin creates an associate from the cart to the purchase log using wpecdup_processed_cart_[uniqueid]

When This Plugin Fails

When a merchant plugin’s submit() function is called, if an error is thrown before the merchant plugin has had a chance to call set_transaction_details, then this plugin will not work. If this plugin does not prevent duplicate orders for you, then an error lies in the submit() function of the merchant plugin.