Skip to main content
This guide introduces how to get started with using the Cobo Payments JavaScript SDK, which allows you to integrate the Cobo payments service into your existing application using the JavaScript programming language. To learn more about the initial setup steps necessary for utilizing the Payments API, see Send your first request. You can go to GitHub to access the source code of the SDK.

Prerequisites

  • Install Node.js and NPM.
  • Follow the instructions in Preparation for development environment to set up your Cobo account and create your organization. If an organization has already been set up, ask your organization admin to invite you to join the organization.
  • Follow the instructions in Send your first request to generate an API key and an API secret, and register the API key on Cobo Portal.

Create a project and install the SDK

  1. Create a project directory and initialize NPM:
mkdir waas2-js && cd waas2-js
npm init -y
  1. Install the SDK:
npm install @cobo/cobo-waas2 --save
The directory structure after installation is as follows:
waas2-js/
├─ node_modules/
├─ package.json
├─ package-lock.json
└─ (to be created later) index.js
If your project already has package.json and package-lock.json, you can directly copy them to the root directory and run npm install to pull dependencies.
  1. Create a file index.js in the root directory and paste the following code into it.
The directory structure after installation is as follows:
waas2-js/
├─ node_modules/
├─ package.json
├─ package-lock.json
└─ (to be created later) index.js
If your project already has package.json and package-lock.json, you can directly copy them to the root directory and run npm install to pull dependencies.

Configure API key and HTTP host

  1. Set the API secret.
// Initialize the default API client
const apiClient = CoboWaas2.ApiClient.instance
// Set the API secret
apiClient.setPrivateKey("<YOUR_API_SECRET_IN_HEX>");
  1. Select which environment you want to use.
// Select the development environment
apiClient.setEnv(CoboWaas2.Env.DEV);

// Select the production environment
apiClient.setEnv(CoboWaas2.Env.PROD);

Code sample

For operation-specific documentation and sample code, see the docs folder in the Payments GitHub repository.