How to use open banking platforms? Integrating Django with Plaid

What is Plaid and what it offers?

Plaid is an open banking platform that offers integrations with multiple institutions allowing companies to smoothly manage their financial operations within their own products. Founded in 2013 it currently operates in 7 countries around the world - USA, Canada, France, Spain, United Kingdom, Ireland, and the Netherlands. At the beginning of the year, it was acquired by Visa for $5.3 billion which is double the valuation of the company’s Series C made less than 2 years ago.

Looking for inspiration to utilise open banking? Here’s all you need to know to use it in your business.

There’s a plethora of use cases that can be covered with Plaid’s products (I will talk them through later) from personal finances, consumer payments, and lending to more investor-related ones like banking, brokerage, and business finances. In my article, I will focus on features and possibilities for apps helping to manage a home budget.

Plaid offers a quickstart example and libraries for most popular languages and platforms:

  • NodeJS,
  • Python,
  • Ruby,
  • Java,
  • Go,
  • iOS,
  • Android,
  • React,
  • React Native.

Of course, everything can be done manually through direct access to the API, but the libraries make the entire process smoother.

There are 3 environments:

  • Sandbox (allowing to connect 1 bank account),
  • Development,
  • Production.

The following examples are built using Sandbox.

Authentication

The first step to using Plaid is to authenticate using Link, which is an endpoint for obtaining access tokens. Plaid presents a list of banks that support the integration and asks for authorization to access data. This way an Item is created. Item is a resource on Plaid’s side that represents some financial institutions to put it in general terms.

Paid Authentication Flow

You can also refer to this description through Plaid’s official docs:

Plaid workflow

Products

All products’ overview can be found in the official docs, I’ll focus on the ones that were used in the application.

Identity

We’re going to use this endpoint to retrieve basic data about the user and accounts that they manage. Plaid offers quite extensive information including address, contact information and accounts details. Each account has, among others, unique id and balance information. This will be useful for obtaining and filtering further transaction data. Also, our application will display the available amount of money on the account (some money can be frozen in order to cover card payments etc.)

Transactions

Once we know details about the account we can ask Plaid to send transaction history for the specific account. Plaid automatically adds categories for the transactions, merchant’s name (or transaction description) allowing us to categorize payments, amount, currency codes and others. For readability, we’re going to mark incomes in black and expenses in red.

Code examples

On backend we want to store the access token for user:

class PlaidToken(models.Model):

  access_token = models.CharField(max_length=64, default='')

  user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

It’s created within this simple viewset (by default all views require authentication, djoser library is used to handle logging in):

class PlaidLinkViewSet(GenericViewSet):

  @transaction.atomic()

  def create(self, request: Request) -> Response:

      public_token = request.data['public_token']

      exchange = plaid_client.Item.public_token.exchange(public_token)

      token, created = PlaidToken.objects.get_or_create(

          user=request.user,

          defaults={'access_token': exchange['access_token']}

      )

      if not created:

          token.access_token = exchange['access_token']

          token.save()

      return Response(status=status.HTTP_204_NO_CONTENT)

For logging in we use slightly modified code from Plaid’s example:

var handler = Plaid.create({

// ...

env: 'sandbox',

// ...

key: "{{ public_key }}",

onSuccess: function(public_token, metadata) {

  $.ajaxSetup({beforeSend: function(xhr){

    xhr.setRequestHeader('Authorization', 'Token ' + localStorage.getItem('authToken'))

  }});

  $.post(

    "{% url 'accounting:plaid-link-list' %}",

    {public_token: public_token},

      () => {

        document.location = "{% url 'accounts' %}";

      }

  );

},

});

Identity and transactions also use Generic ViewSets. For example to get transactions list, user sends account id, system fetches token from database and makes a request to Plaid asking to filter data for specific account:

class TransactionsViewSet(GenericViewSet):

  def list(self, request: Request) -> Response:

      try:

          token = PlaidToken.objects.get(user=request.user)

      except PlaidToken.DoesNotExist:

          return Response(status=status.HTTP_404_NOT_FOUND)

      plaid_resp = plaid_client.Transactions.get(

          access_token=token.access_token,

          start_date='2010-01-01',

          end_date='2020-01-31',

          account_ids=[request.query_params['account']]

      )

      return Response(data={'content': plaid_resp['transactions']})

What we get as a result is following view for our budget management:

And that's how the app looks like at the end:

Unlimited possibilities

This is it when it comes to the demo prepared for you. If you want to get into more details of how it works, you can find the source code here. However, plaid offers a lot more when it comes to integrating banking solutions into your product.

Saving app

Home budget is the first step to integrating savings into your daily routines. With decent descriptions of payments and vendors, you can search for best discounts in places your user buys most often. It can help to structure the budget through the Income endpoint and analyze spending through the Transactions endpoint that we’ve used earlier in order to cut down on unnecessary expenses. This could be a hot topic, taking into account recent economic troubles.

User verification

Sometimes you are required to verify user identity. Here we can also make use of Plaid - the authorization process we’ve gone through at the beginning allows us to confirm that someone’s identity is real. In addition to this, some details like addresses or contact information can be pulled from the bank through the Identity endpoint. The biggest gain here would be the handling of the verification process by another institution which limits the problems caused by the need to manually process sensitive data.

Frictionless payments

In addition to reading data, Plaid offers the possibility to integrate frictionless payments after integrating with Stripe and Dwolla which can extend the possibilities for shops. What it means is that you can easily offer your users an option to make in-app purchases of goods and services or even securities together with an option to monitor the process through the Investments endpoint.

And that's not the end!

Well, it's the end of the article but not the possibilities of Plaid. The above examples barely scratch the surface of the potential of open banking platforms. Data that can be obtained with it is a complex source of information. Any idea to utilise it might be completed, the only thing that limits the possibilities is your creativity.

Looking for a reliable partner in developing your open banking product? Check how we helped mobile banks, the providers of wealth management apps and solutions for DIY investors and talk with us to see how we can support your project!

Navigate the changing IT landscape

Some highlighted content that we want to draw attention to to link to our other resources. It usually contains a link .