Let’s walk through the next steps in the checkout process!
Are you new to this series? Check out the first blog for an introduction and a table of contents!
Knowing that my crochet patterns are sure to be a hit, I’m eager to get going with the next step of building my shop! So far, I have a function that adds the inventory data to Cloud Firestore and a function that creates items in Stripe.
As discussed in the last blog, Checkout creates a secure, Stripe-hosted payment page that lets you collect payments quickly. Checkout requires server-side and client-side components. On the server side, you create a Checkout Session. This returns a Session ID, which you pass back to the client to complete checkout.
A Checkout Session represents the details of your customer’s intent to purchase. You create a Session when your customer wants to pay for something. After redirecting your customer to a Checkout Session, Stripe presents a payment form where your customer can complete their purchase.
Stripe Checkout requires both server and client components
Once your customer has completed a purchase, they are redirected back to your site. This means we need a server solution in which to create a Session.
Server for security
The Stripe Checkout client-server handshake is necessary to protect the validity of your data. For example, if pricing information were passed directly from the client, then there would be the potential for that price to be modified by the user. Rest assured I will not sell my sock patterns for less! I painstakingly created these patterns and if I don’t value my time, nobody else will! Whenever possible and appropriate, ensure that the client cannot modify data, especially if it’s data related to getting paid.
Use a server to ensure that the client cannot modify key data
There are plenty of Google Cloud solutions available that meet this need for a server environment. I’m using Cloud Run.
According to something written by a marketer with much better writing talent than I, Cloud Run enables you to write code your way by deploying any container that listens for requests or events. You can build applications in your favorite language, with your favorite dependencies and tools, and deploy them in seconds. And it abstracts away all infrastructure management by automatically scaling up and down from zero almost instantaneously — depending on traffic. Cloud Run only charges you for the exact resources you use.
Now you might be wondering why I’m using Cloud Run for this and not Cloud Functions, considering the first iteration of this project used Cloud Functions. Cloud Functions can also be a great tool to use here. Personally, I want to explore the flexibility that Cloud Run provides. If Node.js isn’t your jam, you can write this same functionality in the language of your choice and deploy it to Cloud Run the same way. And in the event you decide you want to take your app elsewhere, simply build your container and deploy it to the service of your choice.
Now that you have an overview of Stripe Checkout and Cloud Run, you’re ready to build this part of the project! Here are some next steps to take: