This course is the followup to Building Modern Web Applications in Go. In this course, we go further than we did the first time around. We will build a sample E-Commerce application that consists of multiple, separate applications: a front end (which services content to the end user as web pages); a back end API (which is called by the front end as necessary), and a microservice that performs only one task, but performs it extremely well (dynamically building PDF invoices and sending them to customers as an email attachment).
This course is the followup to Building Modern Web Applications in Go. In this course, we go further than we did the first time around. We will build a sample E-Commerce application that consists of multiple, separate applications: a front end (which services content to the end user as web pages); a back end API (which is called by the front end as necessary), and a microservice that performs only one task, but performs it extremely well (dynamically building PDF invoices and sending them to customers as an email attachment).
The application will sell individual items, as well as allow users to purchase a monthly subscription. All credit card transactions will be processed through Stripe, which is arguably one of the most popular payment processing systems available today, and for good reason: developers love it. Stripe offers a rich API (application programming interface), and it is available in more than 35 countries around the world, and works with more than 135 currencies. Literally millions of organizations and businesses use Stripe’s software and APIs to accept payments, send payouts, and manage their businesses online with the Stripe dashboard. However, in many cases, developers want to be able to build a more customized solution, and not require end users to log in to both a web application and the Stripe dashboard. That is precisely the kind of thing that we will be covering in this course.
We will start with a simple Virtual Terminal, which can be used to process so-called "card not present" transactions. This will be a fully functional web application, built from the ground up on Go (sometimes referred to as Golang). The front end will be rendered using Go's rich html/template package, and authenticated users will be able to process credit card payments from a secure form, integrated with the Stripe API. In this section of the course, we will cover the following:
How to build a secure, production ready web application in Go
How to capture the necessary information for a secure online credit card transaction
How to call the Stripe API from a Go back end to create a paymentIntent (Stripe's object for authorizing and making a transaction)
Once we have that out of the way, we'll build a second web application in the next section of the course, consisting of a simple web site that allows users to purchase a product, or purchase a monthly subscription. Again, this will be a web application built from the ground up in Go. In this section of the course, we'll cover the following:
How to allow users to purchase a single product
How to allow users to purchase a recurring monthly subscription (a Stripe Plan)
How to handle cancellations and refunds
How to save all transaction information to a database (for refunds, reporting, etc).
How to refund a transaction
How to cancel a subscription
How to secure access to the front end (via session authentication)
How to secure access to the back end API (using stateful tokens)
How to manage users (add/edit/delete)
How to allow users to reset their passwords safely and securely
How to log a user out and cancel their account instantly, over websockets
Once this is complete, we'll start work on the microservice. A microservice is a particular approach to software development that has the basic premise of building very small applications that do one thing, but do it very well. A microservice does not care in the slightest about what application calls it; it is completely separate, and completely agnostic. We'll build a microserivce that does the following:
Accepts a JSON payload describing an individual purchase
Produces a PDF invoice with information from the JSON payload
Creates an email to the customer, and attaches the PDF to it
Sends the email
All of these components (front end, back end, and microservice) will be built using a single code base that produces multiple binaries, using Gnu Make.
What we are going to cover in this course
My background. I've worked in both academia and the private sector, at the same time, for quite a long time.
I make mistakes all the time, and I'm not going to hide that from you
We going to need Go, so let's install it
You may already have a Go IDE installed, but if not, here's one that will do the job.
You're going to need a Stripe account, but it's free, so go get one.
This is entirely optional, but Make will make your life easier, so let's install it.
We'll use MariaDB, a drop in replacement for MySQL. Let's install it.
There are many choices for a MySQL compatible database client. Let's install one.
Let's build a virtual credit card terminal.
The Go version of hello, world for the web.
We'll need some routes, handlers, and a render function. Let's build them.
Let's build a single page.
Let's make our IDE a bit easier to work with.
We'll need a form to process credit card transactions, so let's build one.
We'll need to connect to Stripe, so let's get the necessary changes in place.
Never assume information is valid in a form. Let's set up Bootstrap's client side validation.
Stripe's paymentIntent is how we'll charge a credit card. Let's get started.
We'll get our paymentIntent from our server, so let's get started.
Let's continue on our back end, and figure out how to use Make to build and run our code.
Let's finish up our back end code to get a paymentIntent from Stripe.
Let's work on our front end a bit more.
Finally, let's charge a credit card using Stripe.
It's helpful to generate a receipt, so let's make one.
Just a bit of housekeeping.
Let's review some of the things we've covered.
Let's take a look at what we are going to build in this section.
We'll need a database, so let's create one.
Let's connect our Go code to MariaDB.
We'll need a product page to sell our widget, so let's create one.
Our product page needs a form for e-commerce, so let's create it.
Let's try to avoid code duplication.
Let's improve our handler a bit.
Let's pass some information to our template.
Most users think in dollars and cents, and not just in cents. Let's make our price human readable.
Let's give this a try and see how it works.
Let's improve our database structure.
Database migrations keep your code and your database in sync. Let's use them.
We need some means of representing what's in the database and our Go code. Models are the way to go.
Let's write some functions to interact with the database.
Let's figure out how to save a transaction to the database.
Let's figure out how to save an order to the database.
Stripe sends us a lot of information. Let's figure out what we need.
We need a means of keeping track of who bought what.
Let's save customer information to the database.
Let's write some more database functions.
Let's continue with our database functions.
Let's see if this thing works.
Just some more work on the database functionality.
It's good practice to redirect the user after a POST request. Let's do that.
Let's make our code a bit cleaner.
Our changes mean that we have to update our Virtual Terminal a bit.
Everyone makes mistakes. I made one. Let's fix it.
Let's let users purchase a Stripe Plan.
Let's create a Stripe Plan.
Let's get started with our code.
We'll need another form, so let's build one.
The JavaScript to subscribe to a Stripe Plan is a bit different. Let's get started.
Just some more work with the JavaScript to buy a Stripe Plan.
We need to do some work after the subscription succeeds. Let's get started.
We'll need some new functions, so let's write them.
Let's put the finishing touches on our handler.
Let's continue working on the front end.
We need to save customer and transaction information, so let's do that.
Once again, we need a receipt. Let's build it.
Authentication has to be both safe, secure, and easy to use. Let's pick and approach and get started.
Users need a place to log in, so let's build a page for them.
Let's start with our JavaScript to authenticate users.
Authentication requires both a route and a handler, so let's set some up.
We're going to write a lot of JSON. Let's make our lives easier.
Let's get started with user authentication.
Sometimes you have to give a user bad news, like when their password is incorrect.
How do we make sure that a supplied password is valid?
Let's run a basic sanity check to make sure that things are wired up correctly.
Before we can send a token, we have to make one. Let's write the code to do so.
Let's build a safe, secure token, and send it to the user.
After we create a token, we'll need to get access to it later on. Let's save it to the database.
We need to put the token we get somewhere. Local storage seems like a good place.
We can vary content based on a user's status. Let's do that.
Let's get started checking for authentication.
Just a bit of clean up.
Let's get things wired up correctly so we can get started.
Our auth token comes as part of the header. Let's get it out of there so that we can work with it.
Let's make sure that the token passed to the back end is valid, and not expired.
Let's make sure everything works as expected.
Check your skills
How I solved the challenge.
Let's add some code to protect routes on the API
Let's make sure our protection works as expected.
Let's use the back end instead.
We have a nice back end. Let's use it.
It's always good to take a second (or third, or fourth) look at your code.
OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.
Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.
Find this site helpful? Tell a friend about us.
We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.
Your purchases help us maintain our catalog and keep our servers humming without ads.
Thank you for supporting OpenCourser.