Getting started

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.

Install Commerce.js with TypeScript definitions

If you're using TypeScript for your application, Commerce.js has public typings added which you can easily install with the Commerce.js library.

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

Note that when using TypeScript, the definitions are always compliant with our latest version of the API. If you specify a custom API version, or your API key uses an older version, you may get type errors.

Instantiate Commerce with your API key

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

For more information on API keys authentication, read more on how we authenticate Chec's core endpoints.

// 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.