worldline

Documentation

Node.js SDK

Introduction

The Node.js SDK helps you to communicate with the  Acquiring API . More specifically, it offers a fluent Node.js API that provides access to all the functionality of the RESTful Server API. Below, we discuss the following topics in detail.

  • Initialization of the SDK

  • Errors

  • Logging

  • Advanced use: Customization of the communication

The source code of the SDK and an example app are available on  Github . There you can find installation instructions.

The API documentation of the latest version of the SDK is available  here . For a specific major version, replace latest with the actual version in format <major>.x .

Initialization of the Node.js SDK

All JavaScript code snippets presented in the API Reference assume you have initialized the Node.js SDK before using them in your Development Environment. This section details the initialization of the Node.js SDK.

Initializing is simple, and requires only one key task: use our  acquiring-sdk-nodejs  package to create an instance of  Client , which contains the actual methods to communicate with the Acquiring API.

The  Client  needs the following input

  • The host, scheme, and port to which you connect. See  API endpoints  for the possible hosts.

  • The oauth2TokenUri , oauth2ClientId and oauth2ClientSecret . See  API endpoints  for the possible token URIs.

  • The name of the integrator, e.g. your company name.

  • Optional logging properties.

import * as acquiringSdk from "acquiring-sdk-nodejs";
 
const client = acquiringSdk.init({
  host: "api.preprod.acquiring.worldline-solutions.com",
  scheme: "https",
  port: 443,
  enableLogging: true, // defaults to false
  logger: logger, // if undefined console.log will be used
  oauth2TokenUri: "https://auth-test-eu-west-1.aws.bambora.com/connect/token",
  oauth2ClientId: "[your-oauth2-client-id]",
  oauth2ClientSecret: "[your-oauth2-client-secret]",
  integrator: "[your-company-name]"
});

If a proxy should be used, the input should additionally contain a proxy property:

const client = acquiringSdk.init({
  host: "api.preprod.acquiring.worldline-solutions.com",
  scheme: "https",
  port: 443,
  enableLogging: true, // defaults to false
  logger: logger, // if undefined console.log will be used
  oauth2TokenUri: "https://auth-test-eu-west-1.aws.bambora.com/connect/token",
  oauth2ClientId: "[your-oauth2-client-id]",
  oauth2ClientSecret: "[your-oauth2-client-secret]",
  integrator: "[your-company-name]",
  proxy: {
    host: "[hostname.of.the.proxy]",
    scheme: "http",
    port: 3128,
    credentials: "[username.for.the.proxy]:[password.for.the.proxy]"
  }
});

Only the nested  host  property is required; the  scheme  and  port  properties default to  http  and  3128  respectively, and the  credentials  property can be omitted if no proxy authentication is needed.

Errors

The following table is a summary that shows when each of these errors will be returned:

HTTP status code

Meaning

Description

200

Successful

Your request was processed correctly

201

Created

Your request was processed correctly, and a new resource was created.
The URI of this created resource is returned in the Location header of the response.

204

No Content

Your request was processed correctly

400

Bad Request

Your request is not correct and can't be processed. Please correct the mistake and try again.

403

Not Authorized

You're trying to do something that is not allowed or that you're not authorized to do.

404

Not Found

The object you were trying to access could not be found on the server.

409

Conflict

Your idempotent request resulted in a conflict. The first request has not finished yet.

409

Conflict

Your request resulted in a conflict. Either you submitted a duplicate request or you're trying to create something with a duplicate key.

500

Internal Server Error

Something went wrong on the Worldline platform.

502

Bad Gateway

The Worldline platform was unable to process a message from a downstream system.

503

Service Unavailable

The service that you're trying to reach is temporarily unavailable.
Please try again later.

other

Unexpected error

An unexpected error has occurred

Logging

The Node.js SDK supports logging of requests, responses and errors of the API communication.

In order to start using the logging feature, an implementation of the  Logger  interface should be provided. The example app provides an example implementations for logging.

Logging can be enabled by setting the  enableLogging  property when initializing a  Client  object, and providing the logger as an argument  logger . Alternatively, it can be enabled on an existing  Client  by calling  client.context.setEnableLogging(true) .

Advanced use: Customization of the communication

Client  uses an  http.Agent  to communicate with the RESTful API. By default, Node.js will provide the  http.Agent . If needed, you can provide your own instance instead. For instance,  https-proxy-agent  can be used to provide proxying using the  HTTP CONNECT method :

import { HttpsProxyAgent } from "https-proxy-agent";
 
const client = acquiringSdk.init({
  host: "api.preprod.acquiring.worldline-solutions.com",
  scheme: "https",
  port: 443,
  enableLogging: true, // defaults to false
  logger: logger, // if undefined console.log will be used
  oauth2TokenUri: "https://auth-test-eu-west-1.aws.bambora.com/connect/token",
  oauth2ClientId: "[your-oauth2-client-id]",
  oauth2ClientSecret: "[your-oauth2-client-secret]",
  integrator: "[your-company-name]",
  connectionOptions: {
    agent: new HttpsProxyAgent("[url.of.the.proxy]")
  }
});