A headless e-commerce for JAMstack sites
Go CSS HTML JavaScript Makefile
Latest commit 57c5ef9 Oct 12, 2017 @biilmann biilmann Merge pull request #88 from netlify/admin-access-to-coupons-and-settings
Add /coupons and /settings endpoints for admins
Permalink
Failed to load latest commit information.
.github Add missing project management files. Mar 15, 2017
api Return empty list when there's no coupons Oct 12, 2017
assetstores Linter fixes Jul 14, 2017
calculator Add ValidForProduct check to member discounts Oct 12, 2017
claims Use sub claim in JWT, not id. Aug 25, 2017
cmd Only mix in SMTP to instance config Oct 10, 2017
conf Add /coupons and /settings endpoints for admins Oct 12, 2017
context Add multi-tenant mode Aug 23, 2017
coupons Add /coupons and /settings endpoints for admins Oct 12, 2017
mailer Only mix in SMTP to instance config Oct 10, 2017
models Add column type to force MySQL Oct 11, 2017
payments Fix paypal payment creation Sep 22, 2017
www Fix Heroku button integration. Mar 16, 2017
.gitignore Add multi-tenant mode Aug 23, 2017
.travis.yml Turn email notifications off and update Go. Mar 16, 2017
CODE_OF_CONDUCT.md Add missing project management files. Mar 15, 2017
CONTRIBUTING.md Add missing project management files. Mar 15, 2017
Dockerfile Move to go-chi http router Jul 20, 2017
LICENSE Rename project to Netlify Commerce. (#9) Sep 22, 2016
Makefile Linter fixes Jul 14, 2017
README.md Mention what the mail template path is relative to Oct 10, 2017
app.json Add multi-tenant mode Aug 23, 2017
example.env Add multi-tenant mode Aug 23, 2017
glide.lock Add instance tests Aug 24, 2017
glide.yaml Add instance tests Aug 24, 2017
main.go rename all the code Mar 6, 2017
netlify.toml Move netlify.toml to the base of the repository. Mar 16, 2017

README.md

GoCommerce Build Status

A small go based API for static e-commerce sites.

It handles orders and payments. Integrates with Stripe for payments and will support international pricing and VAT verification.

GoCommerce is released under the MIT License. Please make sure you understand its implications and guarantees.

What your static site must support

Each product you want to sell from your static site must have unique URL where GoCommerce can find the meta data needed for calculating pricing and taxes in order to verify that the order is legitimate before using Stripe to charge the client.

The metadata can be anywhere on the page, and goes in a script tag in this format:

<script class="gocommerce-product" type="application/json">
{"sku": "my-product", "title": "My Product", "prices": [{"amount": "49.99", "currency": "USD"}], "type": "ebook"}
</script>

The minimum required is the Sku, title and at least one "price". Default currency is USD if nothing else specified.

VAT, Countries and Regions

GoCommerce will regularly check for a file called https://example.com/gocommerce/settings.json

This file should have settings with rules for VAT or currency regions.

This file is not required for GoCommerce to work, but will enable support for various advanced features. Currently it enables VAT calculations on a per country/product type basic.

The reason we make you include the file in the static site, is that you'll need to do the same VAT calculations client side during checkout to be able to show this to the user. The commerce-js client library can help you with this.

Here's an example settings file:

{
  "taxes": [{
    "percentage": 20,
    "product_types": ["ebook"],
    "countries": ["Austria", "Bulgaria", "Estonia", "France", "Gibraltar", "Slovakia", "United Kingdom"]
  }, {
    "percentage": 7,
    "product_types": ["book"],
    "countries": ["Austria", "Belgium", "Bulgaria", "Croatia", "Cyprus", "Denmark", "Estonia"]
  }]
}

Based on these rules, if an order includes a product with "type" set to "ebook" in the product metadata on the site and the users billing Address is set to "Austria", GoCommerce will verify that a 20 percentage tax has been included in that product.

JavaScript Client Library

The easiest way to use GoCommerce is with commerce-js.

Configuration

You may configure GoCommerce using either a configuration file named .env, environment variables, or a combination of both. Environment variables are prefixed with GOCOMMERCE_, and will always have precedence over values provided via file.

Top-Level

GOCOMMERCE_SITE_URL=https://example.netlify.com/

SITE_URL - string required

The base URL your site is located at.

OPERATOR_TOKEN - string Multi-instance mode only

The shared secret with an operator (usually Netlify) for this microservice. Used to verify requests have been proxied through the operator and the payload values can be trusted.

API

GOCOMMERCE_API_HOST=localhost
PORT=9999

API_HOST - string

Hostname to listen on.

PORT (no prefix) / API_PORT - number

Port number to listen on. Defaults to 8080.

API_ENDPOINT - string Multi-instance mode only

Controls what endpoint Netlify can access this API on.

Database

GOCOMMERCE_DB_DRIVER=sqlite3
DATABASE_URL=gotrue.db

DB_DRIVER - string required

Chooses what dialect of database you want. Choose from sqlite3, mysql, or postgres.

DATABASE_URL (no prefix) / DB_DATABASE_URL - string required

Connection string for the database. See the gorm examples for more details.

DB_NAMESPACE - string

Adds a prefix to all table names.

DB_AUTOMIGRATE - bool

If enabled, creates missing tables and columns upon startup.

Logging

LOG_LEVEL=debug

LOG_LEVEL - string

Controls what log levels are output. Choose from panic, fatal, error, warn, info, or debug. Defaults to info.

LOG_FILE - string

If you wish logs to be written to a file, set log_file to a valid file path.

Payment

Stripe

PAYMENT_STRIPE_ENABLED - bool

Whether Stripe is enabled as a payment provider or not.

PAYMENT_STRIPE_SECRET_KEY - string

The Stripe secret key used when authenticating with the Stripe API.

PayPal

PAYMENT_PAYPAL_ENABLED - bool

Whether PayPal is enabled as a payment provider or not.

PAYMENT_PAYPAL_CLIENT_ID - string PAYMENT_PAYPAL_SECRET - string

The OAuth credentials PayPal issued to you. GoCommerce will use them to obtain an access token.

PAYMENT_PAYPAL_ENV - string

The PayPal environment to use. Choose from production or sandbox.

Downloads

DOWNLOADS_PROVIDER - string

The provider to use for downloads. Choose from netlify or ``.

DOWNLOADS_NETLIFY_TOKEN - string

The authentication bearer token used to access the Netlify downloads API.

Coupons

COUPONS_URL - string

A URL that contains all the coupon information in JSON.

COUPONS_USER - string COUPONS_PASSWORD - string

HTTP Basic Authentication information to use if required to access the coupon information.

Webhooks

WEBHOOKS_ORDER - string WEBHOOKS_PAYMENT - string WEBHOOKS_UPDATE - string WEBHOOKS_REFUND - string

A URL to send a webhook to when the corresponding action has been performed.

WEBHOOKS_SECRET - string

A secret used to sign a JWT included in the X-Commerce-Signature header. This can be used to verify the webhook can from GoCommerce.

JSON Web Tokens (JWT)

GOCOMMERCE_JWT_SECRET=supersecretvalue

JWT_SECRET - string required

The secret used to verify JWT tokens with.

JWT_ADMIN_GROUP_NAME - string

The name of the admin group (if enabled). Defaults to admin.

E-Mail

Sending email is not required, but is highly recommended. If enabled, you must provide the required values below.

GOCOMMERCE_SMTP_HOST=smtp.mandrillapp.com
GOCOMMERCE_SMTP_PORT=587
GOCOMMERCE_SMTP_USER=smtp-delivery@example.com
GOCOMMERCE_SMTP_PASS=correcthorsebatterystaple
GOCOMMERCE_SMTP_ADMIN_EMAIL=support@example.com
GOCOMMERCE_MAILER_SUBJECTS_ORDER_CONFIRMATION="Please confirm"

SMTP_ADMIN_EMAIL - string required

The From email address for all emails sent. Order receipts are also sent to this address.

SMTP_HOST - string required

The mail server hostname to send emails through.

SMTP_PORT - number required

The port number to connect to the mail server on.

SMTP_USER - string

If the mail server requires authentication, the username to use.

SMTP_PASS - string

If the mail server requires authentication, the password to use.

MAILER_SUBJECTS_ORDER_CONFIRMATION - string

Email subject to use for order confirmations. Defaults to Order Confirmation.

MAILER_SUBJECTS_ORDER_RECEIVED - string

Email subject to use for orders sent to the store admin. Defaults to Order Received From {{ .Order.Email }}.

MAILER_TEMPLATES_ORDER_CONFIRMATION - string

URL path, relative to the SITE_URL, of an email template to use when sending an order confirmation. Order and Transaction variables are available.

Default Content (if template is unavailable):

<h2>Thank you for your order!</h2>

<ul>
{{ range .Order.LineItems }}
<li>{{ .Title }} <strong>{{ .Quantity }} x {{ .Price }}</strong></li>
{{ end }}
</ul>

<p>Total amount: <strong>{{ .Order.Total }}</strong></p>

MAILER_TEMPLATES_ORDER_RECEIVED - string

URL path, relative to the SITE_URL, of an email template to use when sending order details to the store admin. Order and Transaction variables are available.

Default Content (if template is unavailable):

<h2>Order Received From {{ .Order.Email }}</h2>

<ul>
{{ range .Order.LineItems }}
<li>{{ .Title }} <strong>{{ .Quantity }} x {{ .Price }}</strong></li>
{{ end }}
</ul>

<p>Total amount: <strong>{{ .Order.Total }}</strong></p>