Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/njosefbeck/unicorn-mart
A proof of concept e-commerce store leveraging Contentful, GatsbyJS, Stripe, and serverless via clay.run
https://github.com/njosefbeck/unicorn-mart
aws-lambda contentful gatsbyjs netlify serverless stripe-checkout
Last synced: 2 months ago
JSON representation
A proof of concept e-commerce store leveraging Contentful, GatsbyJS, Stripe, and serverless via clay.run
- Host: GitHub
- URL: https://github.com/njosefbeck/unicorn-mart
- Owner: njosefbeck
- License: mit
- Created: 2017-10-20T13:50:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T15:15:05.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T13:19:41.740Z (8 months ago)
- Topics: aws-lambda, contentful, gatsbyjs, netlify, serverless, stripe-checkout
- Language: JavaScript
- Homepage: https://unicorn-mart.netlify.com/
- Size: 4.3 MB
- Stars: 21
- Watchers: 2
- Forks: 4
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unicorn-mart
A proof of concept for an e-commerce store powered by [Contentful](https://contentful.com), [Gatsby.js](https://www.gatsbyjs.org), [Stripe](https://stripe.com/), [Clay](https://www.clay.run), and hosted by [Netlify](https://netlify.com).
**This project has been updated to use Gatsby v2**
**This project uses the [old version of Stripe Checkout](https://stripe.com/docs/checkout). For an updated e-commerce Gatsby + Stripe integration, see my project [dragon-mart](https://github.com/njosefbeck/dragon-mart).**
## The Goal
I wanted to create a simple e-commerce solution that leverages the awesomeness that is static generators, while still giving clients a CMS to manage their inventory. My goal is always to get off of using WordPress whenever a CMS is required by a client. Bye bye WordPress!
## To Run
Of course you'll need to create accounts and download all the things you'll need to download to use the above services and tools. Once that's all set up, and you've cloned the repo:
1. Run ```npm install```.
2. In Contentful, create a ```Product``` content type. To run this example exactly as is, your content type should have six fields:
* Name (short text)
* Product Id (integer)
* Price (integer)
* Images (media, many files)
* Colors (short text, list)
* Sizes (short text, list)
3. Make a product in Contentful. Mine, of course, was a unicorn! The images are included as a zip file in this project.
4. Make your own ```.env``` file at the root of the project, and put your Contentful Space Id and Access Token there.
5. For Clay serverless function, I basically just used the code [here](https://www.clay.run/services/kareemclay/stripe-starter-function). If you want to change the implementation, feel free to fork what Kareem has and edit it! My version actually just returns a "success" object and doesn't do any charging. In the front-end code, you'll just need to change the endpoint URL in cart.js to point to your own endpoint.## What I Learned / Remaining Questions
First, though I love Contentful, it might have made more sense to handle inventory in Stripe itself. This way I could have treated it more easily as inventory, with specific stock, SKUs, etc. That beind said, I know there are ways to alter the data that gets stored in Contentful through their [Management API](https://www.contentful.com/developers/docs/references/content-management-api/), so I also could have leveraged that. An extension of this project would be to implement that functionality.
Second, creating a Gatsby plugin to inject Stripe's Checkout JS library was surprisingly simple, thanks to the examples provided by Gatsby. I have since made two standalone Gatsby / Stripe plugins for implementing Stripe Checkout ([download on npm](https://www.npmjs.com/package/gatsby-plugin-stripe-checkout)) and Stripe Elements ([download on npm](https://www.npmjs.com/package/gatsby-plugin-stripe-elements)).
Third, going serverless with Clay was great! Such an awesome team, and such a great product. I especially like how easy it is, the logs, and the ability to easily copy and customize what others have done.
Fourth, this project could be extended / improved in (I'm sure) a multitude of ways. Notably:
* Implement Redux (mostly for funsies)
* Use Contentful's [Management API](https://www.contentful.com/developers/docs/references/content-management-api/) to show how to decrease inventory and ultimately show if a product is 'sold out' on the front-end
* Make a store with multiple products
* Implement Stripe Elements instead of Stripe Checkout
* Have the Clay serverless function e-mail a receipt to the customer and an order summary to meIf you're interested in tackling any of these things, feel free to fork! Also, I'm sure my current code could use some refactoring or cleaning up. Feel free to fork and go wild! :) Any questions or comments, get in touch [via Twitter](https://twitter.com/njosefbeck)!