Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 18, 2022 08:58 pm GMT

Sky Cart: An Open Source, cloud-agnostic shopping cart using Stripe Checkout

Sky Cart lets you embed Stripe Checkout on your site in a flash

Earlier this month, Josh Nussbaum (@joshnuss) announced Sky Cart, a new open source project, which uses Svelte, Prisma, Vitest and Stripe Checkout to add a shopping cart to a web site:

With a few short lines of code, he created a headless, cloud-agnostic shopping cart embed that takes advantage of the hosted purchase flow provided by Stripe Checkout.

Using Sky Cart

Since Sky Cart is headless, the UI implementation depends on your web apps framework. Products for Sky Cart are provided through the Stripe API - to get started, create a Stripe account and visit the Products page in the Dashboard to create products for your site.

Under the hood, Sky Cart uses the Stripe API to provide a list of products for sale. These can be made available on your site using Sky Carts Catalog API.

Youll need to build the UI to expose a product list on your site. There are APIs available for creating a cart, as well as adding, removing, and updating items in your cart.

Sky Carts README provides additional information about using the library on your own project, as well as instructions for Development and Production deployments.

How Sky Cart was built

SvelteKit

If youve used Svelte before, youve probably come across SvelteKit, which is a minimal application framework for building Svelte apps. With SvelteKit, the functionality for Sky Cart is provided by way of serverless cloud functions.

Sky Cart uses SvelteKit as an abstraction layer for a variety of common serverless cloud hosting services. SvelteKit allows deployment to providers like CloudFlare, Vercel, and Netlify using plugins called Adapters.

Since functionality for SkyCart is built on top of serverless functions, your web app can scale just like any other serverless project - this means multiple carts can be run in parallel without any fuss or degradation of performance.

Testing

Unit testing for Sky Cart is provided by Vitest, and is used to ensure that the library remains functional even as new changes are merged into future releases. Test cases written with Vitest are in the repos /test/ folder - check out cart.test.js to see an example of syntax used for testing.

Data layer

Prisma provides Object-Relation Mapping (ORM) for the data types used by Stripe Checkout for assembling a cart and the associated charges when users make a purchase. This again is a wonderfully simple implementation - you can see the entire object model for Sky Cart in schema.prisma.

Stripe Checkout

Sky Cart is used to coordinate and maintain a list of products to purchase from a Stripe Account. It provides APIs for users to add items to their cart, remove items, and update totals. Once users decide to make a purchase, a call to Sky Carts checkout API sends users to a Stripes hosted Checkout experience, where they can securely complete their purchase.

Making Sky Cart available as Open Source Software (OSS)

Josh to fill in this section - why make this project available as OSS?

Josh built Sky Cart to learn more about using Prisma & Vitest with SvelteKit. Since SvelteKit is still quite new, this project was a great way to dig a bit deeper into SvelteKits developer experience. By building a simple tool with SvelteKit, Josh was able to provide feedback for the SvelteKit team while creating some resources that would help others integrate Prisma with SvelteKit.

The project came around as the result of an idea Josh had for using Stripe to provide catalog and purchasing functionality for an ecommerce site. Because Stripe manages product & pricing data as well as the checkout process, it made sense to experiment with adding a cart between those two resources.

During the process of building Sky Cart, Josh identified and built a few open source utilities, which are published and available as NPM packages:

If youre building with SvelteKit, check out these OSS resources as well:

Contributions Welcome

Since Sky Cart is completely open source, you can propose new features, add new functionality, or help maintain it by heading to GitHub in the repo joshnuss/sky-cart.

Give it a try!

And thats it! Sky Cart is available for use straight away. You can add it to your site today by following the instructions in the README.md for Sky Cart. Make sure to follow Joshua Nussbaum on twitter @joshnuss, too!


Original Link: https://dev.to/stripe/sky-cart-an-open-source-cloud-agnostic-shopping-cart-using-stripe-checkout-o5k

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To