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. This blog post explains how Paypal has been integrated in the Open Event Server in order to accept payments for tickets.
The integration of Paypal in the server involved the following steps:
- An endpoint to accept the Paypal token from the client applications.
- Using the token to get the approved payment details.
- Capturing the payment using the fetched payment details.
Endpoint for Paypal token
The server exposes an endpoint to get the Paypal token in order to accept payments.
|api.route(ChargeList, ‘charge_list’, ‘/orders/<identifier>/charge’, ‘/orders/<order_identifier>/charge’)|
The above endpoint accepts the Paypal token and uses that to get the payment details from Paypal and then capture the payments.
Getting Approved Payment Details
We use the Paypal Name-Value pair API in the project. First we get the credentials of the event organizer who will be accepting the payments using a call to the get_credentials helper method. It returns the data as the following dictionary:
Next, we use the credentials to get the approved payment details from paypal using the following code snippet.
Capturing the payments
After successfully fetching the payment details, the final step is to capture the payment. We set the amount to be charged to the amount of the order and the payer_id to be the payer id received from step 2. Then we simply make a POST request to the Paypal nvp server and capture the payments. The below method is responsible for executing this task:
- Paypal NVP : https://developer.paypal.com/docs/classic/api/NVPAPIOverview/
- Paypal Python SDK: https://github.com/paypal/PayPal-Python-SDK
- Flask REST JSON API: flask-rest-jsonapi