We have now created the iap_isbn_service module. We have created a new book.info table. Consider this table the main table, where we will store data for all of the books. When the customer requests book data, we will search in this table. If the requested data is found, we will charge credits in exchange for book data.
In the model, we have also created the _books_data_by_isbn() method. This method will find a book from an ISBN number and generate the proper data so that it can be sent back to the customer. The status key in the result will be used to indicate whether the book data is found. It will be used to release reserved credit when the book data is not found.
We have also added /get_book_data route. The IAP customer will make a request on this URL to get the book details. We still need to add the code for capturing IAP credit for the service, which will be done in the next recipe. However, for testing purposes, you can make a test request through curl, like this:
curl --header "Content-Type: application/json"
--request POST
--data "{}"
http://localhost:8069/get_book_data
This will return something like this: {"jsonrpc": "2.0", "id": null, "result": {"test": "data"}}.
The rest of the steps in this recipe are from previous recipes, and don't need a detailed explanation. In the next recipe, we will update our module to capture the customer's credit and return the book data to them.