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 add orders on behalf of others and accept payments onsite. This blog post goes over the implementation of the onsite attendee feature in the Open Event Server.
Normally we expect the payload for a POST request of order to contain already created attendees also. In this case we want to create the attendees internally inside the server. Hence we need some way to differentiate between the two types of orders. The most basic and easy to implement option is to use a query parameter to specify if the attendees are onsite or not. We use ?onsite=true in order to specify that the attendees are onsite and hence should be created internally.
In the POST request, we check if the query parameters contains the onsite param as true or not. If it is true then we create the attendees using a helper function. The helper function will be discussed in detail later in the article.
In order to create attendees on the server, we need the information about each ticket bought and it’s quantity. This data is expected in the format declared in the OnsiteTicketSchema.
Creating onsite Attendees
Following are the few points which we need to focus on when creating onsite attendees:
- Validate if the ticket’s data is provided or not. We raise an error if the ticket data is not provided.
- Verify if the ticket is sold out or not. We raise an error if the ticket is sold out.
- In case an error is raised in any step then we delete the already created attendees. This is a very important point to keep in mind.
The complete method can be checked here.
- Query parameters in Flask: https://scotch.io/bar-talk/processing-incoming-request-data-in-flask#toc-query-arguments
- Optional attributes in Flask-rest-json-api: https://flask-rest-jsonapi.readthedocs.io/en/latest/resource_manager.html#optional-attributes
- Errors in Flask-rest-json-api: https://flask-rest-jsonapi.readthedocs.io/en/latest/errors.html