Getting started

Jump to section

This documentation will walk you through how to:

  • Set up a Chec account.
  • Install Commerce.js into your project.
  • Create a Commerce instance to use through your project.

Account setup

Before installing Commerce.js, you will first need to create a Chec account to get your API credentials.

  1. Sign up for a Chec account here.
  2. Navigate to the developer section under settings here.
  3. Obtain your generated public and secret keys.

Installation

Prerequisites

The only requirement for using Commerce.js is to have Node.js (version 10 or higher) installed on your machine.

Install the SDK with a package manager

If you're using npm or yarn, then adding the Commerce.js SDK to your project is really simple. Once you've created a directory for your project, navigate into your project's root folder in your terminal cd your-project-folder, and type the following:

npm install @chec/commerce.js
# or
yarn add @chec/commerce.js
Note

Note that examples provided using the Commerce.js SDK are using the latest version - available on npm.

Installing the SDK via our CDN

Another option would be to install the SDK via our CDN, you will need to include this script tag in your point of entry file, for instance in your index.html.

<script type="text/javascript" src="https://cdn.chec.io/v2/commerce.js"></script>
Tip

We recommend installing Commerce.js as a package to have access to all the methods included.

We're almost ready to go! We need to create a new Commerce instance and give it our public key (you can get your API keys from Chec Dashboard > Settings > Developer).

Tip

To read more about how we authenticate Chec's core endpoints, see here.

// Import the Commerce module
import Commerce from '@chec/commerce.js';

// Create a Commerce instance
const commerce = new Commerce('{public_api_key}');
Note

We've built in a console debugger into the Commerce.js SDK to help with debugging during development. To enable the debugger you can include the second argument true when you create your Commerce instance like so: const commerce = new Commerce('{public_api_key}', true);. Note that a test API key has to be provided as the first argument for the console to show messages - it won't work with a live key.

Awesome, you have set up your Chec account, installed the Commerce.js SDK and created your first Commerce instance! You now have access to the Commerce object in your application to build out a truly unique frontend presentation layer!


Next steps

Browse through the rest of our documentation to explore all the features of Commerce.js - listing products, add products to cart, or capture an order. Note that all requests made using the Commerce.js SDK will have responses that are returned asynchronously in a promise. Alternatively, if you want to dive more into reading a high-level overview of Commerce.js and its features, read more here.

Important

Please note that for all the following SDK documentation on Products, Cart, and Checkout, we import Commerce in every example using Commerce.js for the sake of brevity. In practice, you would follow the example of creating and exporting out your Commerce client in a file such as /lib/commerce.js.