I am converting a payment module from OsCommerce to ZenCart, but I can't seem to stop it from approving orders.

When it comes back with an error, it redirects to main_page=checkout_payment&payment_error=mythingy&error=stuff
Which is fine, except that an order is created in the database which is 'pending' and the current order/cart is still open so that you can just keep doing it over and over (the order shouldn't be created in the database when it fails I assume, I will log it in the payment module's database still).

My question is - which function should the confirmation check be in? (of whether the response code is approved or not). And how do you halt the order so it wont end up in the database?