npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@teamb/newbank-sdk

v1.4.17

Published

Newbank SDK is an SDK provided by Newbank-teamb for use by developers of merchants wishing to integrate our PaymentGateway service to their website and use it for the transactions done by their clients.

Downloads

38

Readme

Newbank SDK

Newbank SDK is an SDK provided by Newbank-teamb for use by developers of merchants wishing to integrate our PaymentGateway service to their website and use it for the transactions done by their clients.

Installation

Pre-requists In order to use the SDK Download and install Node.js and npm from here.

Then run the following command :

npm install @teamb/newbank-sdk

Initialisation

To use the SDK you should join Newbank by integrating your business application to get your api token from our service.

To start working with the SDK instantiate the NewBank client and provide the token you've just been provided.

import {NewbankSdk} from "@teamb/newbank-sdk";

const token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // your business api token
const newbankSdk = new NewbankSdk(token);

API Interface

authorizePayment(paymentInformation)

Sends a payment authorization request to the backend and receives a transaction ID if accepted.

import {PaymentInfoDTO} from "@teamb/newbank-sdk";
import {AuthorizeDto} from "@teamb/newbank-sdk";

const paymentInfo: PaymentInfoDTO = {
    cardNumber: cardNumber,
    cvv: cvv,
    expirationDate: expiryDate,
    amount: '500',
};
response: AuthorizeDto = await newbankSdk.authorizePayment(paymentInfo);

Parameters:

  • paymentInformation: Payment information (credit card, amount, etc.).

Return:

  • transactionId: The transaction ID if the request is accepted.

confirmPayment(transactionId)

Sends a payment confirmation request for the previously authorized transaction.

import {PaymentInfoDTO} from "@teamb/newbank-sdk";
import {AuthorizeDto} from "@teamb/newbank-sdk";

const confirmationMessage = await newbankSdk.confirmPayment(response.transactionId);
console.log(confirmationMessage);

Return:

  • response : A message indicating whether the transaction is confirmed or not.

Parameters:

  • transactionId: The ID of the transaction to be confirmed.

pay(paymentInformation)

Includes the steps of sending a payment authorization request to the backend via the authorizePayment(paymentInformation) method and, if accepted, confirms the transaction using the confirmPayment(transactionId) function.

import {PaymentInfoDTO} from "@teamb/newbank-sdk";
import {AuthorizeDto} from "@teamb/newbank-sdk";

const paymentInfo: PaymentInfoDTO = {
          cardNumber: cardNumber,
          cvv: cvv,
          expirationDate: expiryDate,
          amount: '500',
};
const response = await newbankSdk.pay(paymentInfo);
console.log(response);

Parameters:

  • paymentInformation: Payment information.

Return:

  • response: A message indicating whether the transaction is confirmed or not.

getBackendStatus()

Sends a request to retrieve the status of backend services.

import {BackendStatusDto} from "@teamb/newbank-sdk";

const backendStatus: BackendStatusDto = await newbankSdk.getBackendStatus();

console.log(JSON.stringify(backendStatus));

Return:

  • a json list with each element containing the following fields:
    • name: The name of the backend service.
    • status: The status of the backend service. It can be either 1 (up), 2 (down) or 3 (degraded).

getMetrics(metricsQuery)

Sends a request to retrieve the metrics of the payment website.

import {MetricRequestDto} from "@teamb/newbank-sdk";

const metricsQuery: MetricRequestDto = {
    period: "L6H",
    resolution: "5M",
    metrics: [
        "transactionCount",
        "TransactionSuccessRate",
        "TransactionFailureRate",
        "totalAmountSpent"
    ],
    filters: {
        status: ["AUTHORISED", "CONFIRMED"],
        creditCardType: ["credit"]
    }
};

const metrics = await newbankSdk.getMetrics(metricsQuery);
console.log(JSON.stringify(metrics));

Parameters:

  • metricsQuery: Object containing the metrics query.

restrictions:

  • period or timeRange must be specified.
  • period and timeRange are mutually exclusive. if both are specified, timeRange is ignored.
  • resolution must be specified and must be one of the following values:
    • 5M (5 minutes).
    • 15M (15 minutes).
    • 30M (30 minutes).
    • H (1 hour).
    • D (1 day).
    • W (1 week).
    • M (1 month).
    • Y (1 year).
  • metrics must be a list of one or more of the following values:
    • transactionCount: The number of transactions.
    • TransactionSuccessRate: The percentage of successful transactions.
    • TransactionFailureRate: The percentage of failed transactions.
    • totalAmountSpent: The total amount spent.
    • averageAmountSpent: The average amount spent per transaction.
    • totalFees: The total fees paid.
    • averageFees: The average fees paid per transaction.
    • totalRequestsCount: The total number of requests sent from the web service to the payment gateway.
    • successfulRequestsCount: The number of successful requests sent from the web service to the payment gateway.
    • failedRequestsCount: The number of failed requests sent from the web service to the payment gateway.
    • successfulRequestsRate : The percentage of successful requests sent from the web service to the payment gateway.
    • failedRequestsRate : The percentage of failed requests sent from the web service to the payment gateway.
    • averageRequestTime: The average time taken by the payment gateway to process a request.
  • filters must be a list of one or more of the following values:
    • status: By passing the filter, only the metrics concerning the transactions with the specified status are returned. The possible values are:
      • AUTHORISED
      • CONFIRMED
      • FAILED
      • PENDING_SETTLEMENT
      • SETTLED
    • creditCardType: By passing the filter, only the metrics concerning the transactions with the specified credit card type are returned. This filter takes only one value. If multiple values are passed, only the first one is considered. The possible values are:
      • credit
      • debit

The client may choose how to visualize the data returned by the getBackenStatus() and getMetrics(metricsQuery) methods. Grafana dashboards examples and a setup guide can be found here.

Return:

  • metrics: A list of metrics with their values and timestamps.

Retry policies

Payment calls can be retried using an exponential backoff strategy.

import {NewbankSdk, RetrySettings} from "@teamb/newbank-sdk";

const retrySettings = new RetrySettings({ retries: 2,
                                          factor:2,
                                          minTimeout: 1000,
                                          maxTimeout: 3000,
                                          randomize: true });
const token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
const newbankSdk = new NewbankSdk(token, retrySettings);

The retrial concerns all subsequent calls made by the SDK.

The RetrySettings class provides a convenient way to configure retry behavior :

retries: The maximum number of retry attempts. Default is 3.

factor: The exponential factor to determine the delay between retries. Default is 2.

minTimeout: The minimum time (in milliseconds) to wait before the first retry. Default is 1000.

maxTimeout: The maximum time (in milliseconds) between two retry attempts. Default is 3000.

randomize: A boolean indicating whether to randomize the timeouts. Default is true.