Checkout failure should not remove the items from the cart. Maybe you are changing urls on checkout failure to add or remove www from the url? Maybe you have a clear cart on the failure page? By default, a failed checkout would not clear the cart, so I'd have to dig into why that is happening.