Managing payments in your app: setting up inventory

Jen Person
Google Cloud - Community
3 min readJul 13, 2020

In my last post, I asked you to ponder what happens in an app after you click “pay”. Now it’s time to compile an inventory of products to sell!

An outdoor storefront
Image Source

Are you new to this series? Check out the first blog for an introduction and a table of contents!

The shop

I started crocheting years ago back when I lived in a part of the US that has a long winter. It gave me something to do on those dark winter days when venturing outside wasn’t an option. It also gave me a great skill for creating homemade holiday gifts! Everyone pretends to love a handmade scarf or pair of mittens. But my absolute favorite item to crochet is a cozy pair of socks! So with that in mind, welcome to the American Sock Market: an entirely made-up store where you can choose from multiple crochet patterns. You too can disappoint your loved ones with handmade lumpy practice socks year after year.

American Sock Market logo

Create products

Our store currently has an inventory of four different sock patterns:

Chart showing four different sock patterns: apple, donut, stripes, and blue, & prices: 9.99, 9.99, 5.99, 5.99 respectively

As my shop becomes more successful (as I’m sure it will), I’ll want to add more patterns. I also may want to raise or lower prices of patterns based on demand. That’s why I’m storing the information on my patterns in Cloud Firestore. I can then fetch this information and display it in my web app, using Firestore’s real-time capabilities to always show the latest in patterns and prices.

Cloud Firestore

Cloud Firestore is a flexible, scalable NoSQL cloud database for storing and syncing data for client- and server-side development. Its data model supports flexible, hierarchical data structures. Store your data in documents, organized into collections. Documents can contain complex nested objects in addition to subcollections.

Cloud Firestore provides the perfect solution to storing sock pattern data

A blanket and a crocket hook
Crochet is a fun, relatively cheap, and relaxing hobby. You should try it! Source

Store Images

Cloud Firestore is perfect for creating and updating product names and information. However, it’s not suitable for larger data like images. In my case, I need a place to store the images of the finished products so customers can see how good their socks will look…more or less. It really depends on your crochet prowess. For example, I’ve been told that my scarf “looks homemade”, which I guess means my socks wouldn’t look quite as good as the pictures either. That’s a true story, by the way.

animated graphic of the apple sock pattern
Sock it to me!

Anyway, let’s talk about storing those images. Cloud Storage is perfect for this use case. I add the images to Cloud Storage, acquire the download URLs for the items, and then upload them to Cloud Firestore to associate them with the items.

Associate objects in Cloud Storage with data in Cloud Firestore by generating a download URL for the object and storing it in Cloud Firestore

Store information about patterns in Firestore and Storage to make the details available to all customers

Ready?

With the structure and rationale outlined, you’re ready to build this part of the project! Here are some next steps to take:

--

--

Jen Person
Google Cloud - Community

Developer Relations Engineer for Google Cloud. Pun connoisseur.