Demo Application

Learn to build a fully functional Django e-commerce application using the FreshBooks APIs.

We'll cover the following

This lesson walks us through a Django e-commerce application that is integrated with FreshBooks APIs. The following endpoints integrate into the application workflow:

  1. Generate an invoice.
  2. Details of an invoice.
  3. Send an invoice by email.
  4. Add payment records.
  5. View all invoices.

In case we’re not authenticated, we can regenerate an access token by following this section.

Since it is a demo application, the data, prices, and currency values are fixed. We may find different currencies of items’ prices and invoices.

Workflow and APIs

Let's dive into the code and see how we’ve integrated different FreshBooks APIs into the e-commerce application. We can see the contents of the views.py file in the widget below. Let’s discuss it step by step:

  • Lines 10–13: We define the headers object for application authentication.
  • Lines 19–24: We defined the is_authenticated method. We invoke this function before making API calls to ensure that the call is authenticated.
  • Lines 127–150: We define the generate_invoice function. When we finish adding items to the cart, we use the invoices endpoint to create an invoice and proceed with our purchase.
  • Lines 153–162: We implement the invoice endpoint. This is used by a page that shows the details of the generated invoice.
  • Lines 165–180: We implement the functionality to send this invoice by email to the client.
  • Lines 183–199: We implement the payments endpoint. We make payment to the invoice by clicking the "Record Payment" button.
  • Lines 115–124: We implement the functionality to see all the invoices available in their FreshBooks account by clicking the "All Invoices" on the top right corner of the page.

Demo

Let’s click the "Run" button in the widget below. Once the server has started, we click on the URL against "Your application can be found at:" to view the application.

Note: The following application only shows the necessary files required to explain the FreshBooks APIs.

Get hands-on with 1200+ tech skills courses.