bk-sdk
v1.0.0
Published
The Boku Direct Payments API is a payment gateway API that enables merchants to accept payments through local payment methods such as digital wallets and carrier/mobile billing. It acts as a bridge between merchants and payment issuers (wallets, mobile ca
Downloads
13
Readme
Getting Started with Boku Direct Payments API
Introduction
API Security
Security is a significant consideration for payment platforms. As part of the registration process for each registered merchant account, merchants receive a security key used to authenticate communications in either direction.
Developers should consult the Boku API Signature Authentication Guide for additional details with respect to implementing security on the Boku APIs.
API Usage
When a consumer chooses to use a local payment-method (wallet), the consumer must go through an 'optin' flow to authenticate. This is accomplished using a redirect to the issuer's app or website where the consumer authenticates and completes the opt-in process.
After the consumer adds their local payment-method (wallet), as their registered payment method, the 'charge' method is used to charge the consumer's local payment-method.
If a customer decides to refund a transaction, the 'refund-charge' method can be used to refund the transaction.
API Versioning
The Boku Payment Gateway API is versioned to provide support for changes to functionality without affecting existing integrations. Each API URL includes version information that enables distinct functionality across different versions.
There are several types of changes that could result in a new API version:
- New API functionality – new APIs, new parameters, additional information in responses, improved error reporting.
- Deprecated API functionality – deprecated APIs, deprecated parameters, deprecated error messages.
- Changes in functionality – existing functional behavior changes such as the returned result of a call. A warning is changed to an error. Validation becomes stricter or more lenient.
In these cases, Boku will release a new API version through a new endpoint(s). When new versions of existing APIs are added, support for existing versions is maintained. Unless otherwise stated, as a rule, compatibility is maintained across versions. Prior supported endpoints should have unchanged behavior. If an API is deprecated and scheduled to be removed, a notice of not less than 6 months will be given. Requests for extensions to this period can be considered.
Boku may make changes to the API within an existing version without changing the version number. An example of a non-versioning change would be the addition of an optional field to a request or to a response.
API Calls
URL Scheme
All the below API calls are against URLs that follow the pattern,
https://${api-node}.boku.com/${api-family}/${api-version}/${api-call}
Definitions for the above placeholders:
- api-node: This follows the pattern '${country}-api4' (e.g. 'us-api4').
- 'country' is the two letter country code of the end-user's payment-method against which the call is made.
- The country code is required and is used for more efficient routing of the request.
- The country code in the url must match the country code supplied in the
optin-request.countryelement.
- api-family: Groups a family of related API methods.
- In this API, family is either one of:
- 'optin' - For interacting with the user or handset to obtain billing approval.
- 'billing' - For actually performing billing operations against the user.
- In this API, family is either one of:
- api-version: In this version of the API, this value is always the string '3.0'.
- Calls under different version numbers may be used in the future to introduce non-compatible API changes.
- api-call: The name particular API call or method to invoke, for example 'charge' or 'refund-charge'.
- This usually matches the XML root element name, sans the '-request' suffix.
Fully qualified API call URLs are documented with each of the example calls detailed below.
Install the Package
Run the following command from your project directory to install the package from npm:
npm install [email protected]For additional package details, see the Npm page for the [email protected] npm.
Test the SDK
To validate the functionality of this SDK, you can execute all tests located in the test directory. This SDK utilizes Jest as both the testing framework and test runner.
To run the tests, navigate to the root directory of the SDK and execute the following command:
npm run testOr you can also run tests with coverage report:
npm run test:coverageInitialize the API Client
Note: Documentation for the client can be found here.
The following parameters are configurable for the API Client:
| Parameter | Type | Description |
| --- | --- | --- |
| country | string | Country code in ISO 3166-1-alpha-2 standardDefault: 'gb' |
| environment | Environment | The API environment. Default: Environment.MerchantTestEnvironment |
| timeout | number | Timeout for API calls.Default: 0 |
| httpClientOptions | Partial<HttpClientOptions> | Stable configurable http client options. |
| unstableHttpClientOptions | any | Unstable configurable http client options. |
The API client can be initialized as follows:
Code-Based Client Initialization
import { Client, Environment } from 'bk-sdk';
const client = new Client({
timeout: 0,
environment: Environment.MerchantTestEnvironment,
country: 'gb',
});Configuration-Based Client Initialization
import * as path from 'path';
import * as fs from 'fs';
import { Client } from 'bk-sdk';
// Provide absolute path for the configuration file
const absolutePath = path.resolve('./config.json');
// Read the configuration file content
const fileContent = fs.readFileSync(absolutePath, 'utf-8');
// Initialize client from JSON configuration content
const client = Client.fromJsonConfig(fileContent);See the Configuration-Based Client Initialization section for details.
Environment-Based Client Initialization
import * as dotenv from 'dotenv';
import * as path from 'path';
import * as fs from 'fs';
import { Client } from 'bk-sdk';
// Optional - Provide absolute path for the .env file
const absolutePath = path.resolve('./.env');
if (fs.existsSync(absolutePath)) {
// Load environment variables from .env file
dotenv.config({ path: absolutePath, override: true });
}
// Initialize client using environment variables
const client = Client.fromEnvironment(process.env);See the Environment-Based Client Initialization section for details.
Environments
The SDK can be configured to use a different environment for making API calls. Available environments are:
Fields
| Name | Description | | --- | --- | | MerchantTestEnvironment | Default | | ProductionEnvironment | - |
List of APIs
SDK Infrastructure
Configuration
- HttpClientOptions
- RetryConfiguration
- ProxySettings
- Configuration-Based Client Initialization
- Environment-Based Client Initialization
