2.3.5 • Published 2 months ago

checkout-sdk-node v2.3.5

Weekly downloads
3,197
License
MIT
Repository
-
Last release
2 months ago

build-status CI Tests CodeQL codecov

build-status GitHub release

zip badge

:rocket: Install

npm install checkout-sdk-node

:computer: Import

// ES6:
import { Checkout } from 'checkout-sdk-node';
// Common JS:
const { Checkout } = require('checkout-sdk-node');

If you don't have your API keys, you can sign up for a test account here.

:clapper: Initialize SDK

With api keys or access credentials

Based on how your account was set up, you will either have a pair or API key or a set of access credentials. Here is how you can use the SDK in both scenarios:

// API Keys
const cko = new Checkout('sk_XXXXXXXXX', {
    pk: 'pk_XXXXXXX'
});

// Access credentials
const cko = new Checkout('your api secret here', {
    client: 'ack_XXXXXXXX',
    scope: ['gateway'], // or whatever scope required
    environment: 'sandbox', // or 'production'
});

With environment variables

If your account uses API Keys (pk_XXX + sk_XXX), you can set the following environment variables, and the SK will pick them up:

  • CKO_SECRET_KEY (with a value like sk_XXX)
  • CKO_PUBLIC_KEY (with a value like pk_XXX)

If you use access credentials (ack_XXXX), you can set the following environment variables, and the SK will pick them up:

  • CKO_SECRET
  • CKO_CLIENT (with a value like ack_XXXX)
  • CKO_SCOPE (with a value of the scope or semicolon separated scopes in case you use multiple)
  • CKO_ENVIRONMENT (with a value like sandbox or production)

Set custom config

Basides the authentication, you also have the option to configure some extra elements about the SDK

const cko = new Checkout('...', {
    ..., //other authentication config
    host: "https://myProxyExample.com", // in case you need to use a custom host for tests
    timeout: 60000,   // HTTP request timout in ms
    agent: new http.Agent({ keepAlive: true }), // custom HTTP agent
    httpClient: 'axios' // specify axios httpClient, by default fetch. Optional
});

:wrench: SDK Environment (Sandbox/Production)

When using API Keys (pk_XXX + sk_XXX) the SDK will automatically figure out what environment you are using however, if you use access credentials (ack_XXXX), make sure you set the "environment" in the config, as shown above in the initialization.

:interrobang: Error handling

The SDK is using promises, and you can handle errors similar to any other HTTP call.

try {
    // some async request made with the SDK
    const action = await cko.payments.request({...});
    ...
} catch (error) {
    console.log(error.name, error.http_code, error.body)
    switch (error.name) {
        ...
    }
}

Here you have all the possible SDK specific errors:

error.nameerror.http_codeerror.body
AuthenticationError401undefined
ActionNotAllowed403undefined
UrlAlreadyRegistered409undefined
NotFoundError404undefined
BadGateway502undefined
ValidationError422object
TooManyRequestsError429object/undefined
ValueError429string describing error

:book: Examples of usage

You can see examples of how to use the SDK for every endpoint documented in our API Reference. All you have to do is to navigate to the endpoint you want to use, and select "Node" for the example on the right side.

NOTE: If you use access credentials (ack_XXXX) the link to the API reference relevant to you will be shared by your Solutions Engineers.

:eyeglasses: Try it on RunKit

You can try the SDK here.

2.3.5

2 months ago

2.3.4

3 months ago

2.3.3

4 months ago

2.3.2

5 months ago

2.2.3

10 months ago

2.2.5

8 months ago

2.2.4

9 months ago

2.3.0

6 months ago

2.3.1

6 months ago

2.2.2

11 months ago

2.2.1

1 year ago

2.2.0

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.3

2 years ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.26

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.11

4 years ago

1.0.12

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago