Implementing Tax Endpoint in Open Event Server
The Open Event Server enables organizers to manage events from concerts to conferences and meetups. It offers features for events with several tracks and venues. The Event organizers may want to charge taxes on the event tickets. The Open Event Server has a Tax endpoint in order to support it. This blog goes over it’s implementation details in the project.
Model
First up, we will discuss what fields have been stored in the database for Tax endpoint. The most important fields are as follows:
- The tax rate charged in percentage
- The id for the Tax
- The registered company
- The country
- The address of the event organiser
- The additional message to be included as the invoice footer
We also store a field to specify whether the tax should be included in the ticket price or not. Each Event can have only one associated Tax information. You can checkout the full model for reference here.
Schema
We have defined two schemas for the Tax endpoint. This is because there are a few fields which contain sensitive information and should only be shown to the event organizer or the admin itself while the others can be shown to the public. Fields like name and rate aren’t sensitive and can be disclosed to the public. They have been defined in the TaxSchemaPublic class. Sensitive information like the tax id, address, registered company have been included in the TaxSchema class which inherits from the TaxSchemaPublic class. You can checkout the full schema for reference here.
Resources
The endpoint supports all the CRUD operations i.e. Create, Read, Update and Delete.
Create and Update
The Tax entry for an Event can be created using a POST request to the /taxes endpoint. We analyze if the posted data contains a related event id or identifier which is necessary as every tax entry is supposed to be related with an event. Moreover we also check whether a tax entry already exists for the event or not since an event should have only one tax entry. An error is raised if that is not the case otherwise the tax entry is created and saved in the database. An existing entry can be updated using the same endpoint by making a PATCH request.
Read
A Tax entry can be fetched using a GET request to the /taxes/{tax_id} endpoint with the id for the tax entry. The entry for an Event can also be fetched from /events/{event_id}/tax endpoint.
Delete
An existing Tax entry can be deleted by making a DELETE request to the /taxes/{tax_id} endpoint with the id of the entry. We make sure the tax entry exists. An error is raised if that is not the case else we delete it from the database.
References
- Marshmallow: http://marshmallow.readthedocs.io/en/latest/index.html
- Flask: http://flask.pocoo.org
You must be logged in to post a comment.