Skip to content

A (really) simple yet effective self-hosted commerce solution πŸ›οΈ

License

Notifications You must be signed in to change notification settings

billz/simple-commerce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

(Really) Simple Commerce πŸ›οΈ

I needed a simple, fast, responsive, self-hosted commerce solution to sell a featured product plus a few accessories. The existing commerce projects I found didn't fit my requirements, so I created my own. Rather than rely on a database backend, all relevant settings (shop, product, shipping and inventory) are instead managed with JSON files. Stripe is used as the payment processor. The shop is still operational, which now serves as a live demo.

After successfully running this side business for several years, I decided to sunset the physical product and open source the software project. This repo is the end result. It's worked more-or-less flawlessly for me and done all that I've asked of it.

Getting started

Begin by cloning this repository, then install the PHP and JavaScript dependencies by using their associated package managers.

Install PHP dependencies

Run Composer to install the PHP dependencies listed in composer.json:

composer install

This will install the required PHP packages and generate a composer.lock file.

Install JavaScript dependencies

Either npm or yarn can be used to install JavaScript dependencies in package.json.

If using npm execute:

npm install

Alternatively, if using Yarn execute:

yarn install

Either of these methods will install the required JavaScript packages and generate a package-lock.json or yarn.lock file.

Create an .env file

In the project root, create a file called .env and add the following contents:

# Stripe keys
STRIPE_SECRET_KEY=my-stripe-secret-key

# Stripe checkout session vars
DOMAIN=http://localhost:8888

Replace my-stripe-secret-key with your Stripe test or live key. Substitute http://localhost:8888 for your local (or live) shop URL.

Manage products and shop settings

Products, shipping rates and shop settings are defined in JSON files located in /assets, as shown below:

β”œβ”€β”€ assets/
β”‚   └── json/
β”‚       β”œβ”€β”€ products.json
β”‚       β”œβ”€β”€ shipping_rates.json
β”‚       └── shop.json

All relevant details for products you wish to sell are defined in products.json. I've retained the original products as examples to help you get started. The product detail fields should be mostly self-explanatory. To prevent PHP errors, be sure to only modify the value in JSON's attribute-value pairs:

"id": "3",
        "category": "accessory",
        "status": "new",
        "inventory": 0,
        "name": "Upcycled pilot's bag",
...

In the above example, the attribute is "category" and the corresponding value is "accessory". The same applies to the attribute-value pairs in shipping_rates.json and shop.json. These may of course be modified or extended by changing the associated PHP code.

Stripe checkout

Stripe's Node.js library for the Stripe API is used to handle payment processing. At checkout time, create-session.php creates a Stripe object with \Stripe\Stripe::setApiKey($_ENV['STRIPE_SECRET_KEY']). The basket items are enumerated and a checkout session is created with shipping options, payment methods and a success or failure callback URL. For full details see Stripe's checkout session documentation.

I used the PM2 daemon process manager to keep Stripe's Node.js backend online 24/7. Over many years of operation it never missed a beat.

Naturally, other payment processing solutions are available but I found Stripe fairly easy to integrate.

Hosting requirements

My commerce site ran reliably on a Linode 1GB Nanode shared server and required almost zero maintenance, apart from periodically updating shop settings and inventories. Your hosting needs may differ.

About

A (really) simple yet effective self-hosted commerce solution πŸ›οΈ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published