Skip to content

apimatic/sample-customized-typescript-sdk

Repository files navigation

Getting Started with Fintech Payment & Banking API

Introduction

A fintech API for user onboarding, account management, and payments.

Building

Requirements

The SDK relies on Node.js and npm (to resolve dependencies). It also requires Typescript version >=4.1. You can download and install Node.js and npm from the official Node.js website.

NOTE: npm is installed by default when Node.js is installed.

Verify Successful Installation

Run the following commands in the command prompt or shell of your choice to check if Node.js and npm are successfully installed:

  • Node.js: node --version

  • npm: npm --version

Version Check

Install Dependencies

  • To resolve all dependencies, go to the SDK root directory and run the following command with npm:
npm install
  • This will install all dependencies in the node_modules folder.

Resolve Dependencies

Installation

The following section explains how to use the generated library in a new project.

1. Initialize the Node Project

  • Open an IDE/text editor for JavaScript like Visual Studio Code. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.

  • Click on File and select Open Folder. Select an empty folder of your project, the folder will become visible in the sidebar on the left.

Open Folder

  • To initialize the Node project, click on Terminal and select New Terminal. Execute the following command in the terminal:
npm init --y

Initialize the Node Project

2. Add Dependencies to the Client Library

  • The created project manages its dependencies using its package.json file. In order to add a dependency on the Fintech Payment & Banking APILib client library, double click on the package.json file in the bar on the left and add the dependency to the package in it.

Add FintechPaymentBankingApilib Dependency

  • To install the package in the project, run the following command in the terminal:
npm install

Install FintechPaymentBankingApilib Dependency

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 test

Or you can also run tests with coverage report:

npm run test:coverage

Test Coverage

The following test files cover all SDK controllers and their endpoints:

Test File Controller
test/controllers/accountsController.test.ts AccountsController
test/controllers/paymentsController.test.ts PaymentsController

Customization: The test files in test/controllers/ were added as SDK customizations beyond the generated output.

Initialize the API Client

Note: Documentation for the client can be found here.

The following parameters are configurable for the API Client:

Parameter Type Description
timeout number Timeout for API calls.
Default: 30000
httpClientOptions Partial<HttpClientOptions> Stable configurable http client options.
unstableHttpClientOptions any Unstable configurable http client options.
logging PartialLoggingOptions Logging Configuration to enable logging
basicAuthCredentials BasicAuthCredentials The credential object for basicAuth
customAuthCredentials CustomAuthCredentials The credential object for customAuth

The API client can be initialized as follows:

Code-Based Client Initialization

import { Client, LogLevel } from 'fintech-payment-banking-apilib';

const client = new Client({
  basicAuthCredentials: {
    username: 'Username',
    password: 'Password',
  },
  customAuthCredentials: {
    'hash': 'hash',
  },
  timeout: 30000,
  logging: {
    logLevel: LogLevel.Info,
    logRequest: {
      logBody: true,
    },
    logResponse: {
      logHeaders: true,
    },
  },
});

Configuration-Based Client Initialization

import * as path from 'path';
import * as fs from 'fs';
import { Client } from 'fintech-payment-banking-apilib';

// 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 'fintech-payment-banking-apilib';

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

Authorization

This API uses the following authentication schemes.

Customization: The customAuth provider is implemented in src/authentication.ts using a custom customAuthenticationProvider. This replaces the generated customHeaderAuthenticationProvider from @apimatic/authentication-adapters and applies the hash header to every outgoing request.

List of APIs

Webhooks

Flows

Customization: Flows are custom additions to the generated SDK that orchestrate multi-step operations across controllers.

Flow Description
Refund Flow Fetches a payment, validates eligibility, submits a full or partial refund, and waits for terminal status in one call.

Signature Verification

The handler expects the signature to be delivered in the X-Fintech-Ed25519-Signature header as a 128-character hex-encoded string (64 bytes).

Initialize the handler with your Ed25519 public key:

import { FintechWebhooksHandler } from 'fintech-payment-banking-apilib';

const handler = new FintechWebhooksHandler('<64-hex-char-ed25519-public-key>');

// Verify and parse an incoming webhook request
const result = handler.verifyAndParseEvent(request);

To use a custom signature header name, pass it as the second argument to CustomSignatureVerifier directly:

import { CustomSignatureVerifier } from 'fintech-payment-banking-apilib';

const verifier = new CustomSignatureVerifier('<public-key-hex>', 'X-My-Custom-Signature');

Customization: Webhook signature verification has been replaced from the generated HMAC-SHA256 implementation with Ed25519 public-key cryptography, implemented in src/customSignatureVerifier.ts.

SDK Infrastructure

Configuration

HTTP

Utilities

Workflow

The Sdk Save Changes workflow synchronizes customization changes from this SDK repository to the build repository. It is triggered automatically on pushes to the main branch, and runs only when the commit message starts with customize:. It uses the APIMatic CLI to save customizations into the build source tree and commits those updates to the main branch of the build repository.

Required Secrets

The following secret has been configured in the repository settings to enable the workflow:

1. BUILD_REPO_TOKEN (Required)

  • Type: Personal Access Token (PAT)
  • Permissions Needed:
    • repo - Read/write access to repository contents
  • Purpose: Grants authenticated access to apimatic/sample-build-with-sdk-source-tree to push customization updates to the build repository

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors