In the first part of the tutorial, we created a basic CRUD API. We are going to make a small addition to this by adding an endpoint that works with a 3rd party API. This section is also going to illustrate how to work with secret environment variables and how to accept credit card payments using Stripe.
A common extension of Serverless Stack (that we have noticed) is to add a billing API that works with Stripe. In the case of our notes app we are going to allow our users to pay a fee for storing a certain number of notes. The flow is going to look something like this:
The user is going to select the number of notes he wants to store and puts in his credit card information.
We are going to generate a one time token by calling the Stripe SDK on the frontend to verify that the credit card info is valid.
We will then call an API passing in the number of notes and the generated token.
The API will take the number of notes, figure out how much to charge (based on our pricing plan), and call the Stripe API to charge our user.
We aren’t going to do much else in the way of storing this info in our database. We’ll leave that as an exercise for the reader.
Let’s get started with first setting up our Stripe account.