There are two ways to handle canceling a purchase. One technique is to hold purchase information in a temporary file, or in session storage, until the customer is ready to confirm this. Once confirmed, the purchase information can be stored permanently in the database after payment confirmation. Another technique we will discuss here is storing the purchase information immediately and then providing the customer with a cancel option. If a purchase is canceled, we simply delete the document from the database.
Before we approach the changes that need to be made to the /path/to/repo/www/chapter_05/purchase.py web script, we must first discuss the pymongo.collection.Collection.delete_* methods.