1.0.0 • Published 4 years ago

bleumi-pay-sdk-nodejs v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Bleumi Pay SDK for NodeJS

The Bleumi Pay SDK is a one-stop shop to help you integrate ERC-20 payments into your business or application. The SDK bundles Bleumi Pay API into one SDK to ease implementation and support.

bleumi-pay-sdk-nodejs is a TypeScrpit-NodeJS library that provides an interface between your NodeJS application and Bleumi Pay API. This tutorial covers the basics, including examples, needed to use the SDK.

Getting Started

The Bleumi Pay SDK for NodeJS bundles TypeScript definition files for use in TypeScript projects and to support tools that can read .d.ts files. Our goal is to keep these TypeScript definition files updated with each release for any public api.

Pre-requisites

Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets a few of these requirements:

Development Environment

  • Use TypeScript v2.x
  • Includes the TypeScript definitions for node. You can use npm to install this by typing the following into a terminal window:

    npm install --save-dev @types/node
  • If you are targeting at es5 or older ECMA standards, your tsconfig.json has to include 'es5' and 'es2015.promise' under compilerOptions.lib. See tsconfig.json for an example.

Obtain An API Key

Bleumi Pay SDK uses API keys to authenticate requests. You can obtain an API key through the Bleumi Pay developer portal.

Install Package

npm (scoped)

In Node.js

npm install bleumi-pay-sdk-nodejs -g

Run Sample Code

The following code creates a wallet to accept payment from the buyer specific for the ECR-20 Token.

import { Erc20PaymentsApi, Erc20PaymentsApiApiKeys } from './api/erc20PaymentsApi';
import { WalletCreateInput, WalletRefundOperationInput, WalletSettleOperationInput, EthAddress, EthNetwork } from './model/models';

// Instantiate clients
const bleumiPay = new Erc20PaymentsApi();

async function createWallet(id: string) {
    try {
        bleumiPay.setApiKey(Erc20PaymentsApiApiKeys.ApiKeyAuth, '<YOUR_API_KEY>')
        const buyer = new EthAddress('<BUYER_ADDR>');
        const merchant = new EthAddress('<MERCHANT_ADDR>');

        const walletCreateInput = new WalletCreateInput();
        walletCreateInput.id = id;
        walletCreateInput.buyerAddress = buyer;
        walletCreateInput.transferAddress = merchant;

        const chain = EthNetwork.Ropsten;
        const response = await bleumiPay.createWallet(walletCreateInput, chain);
        const walletCreateOutput = response.body;
        console.log(JSON.stringify(walletCreateOutput));
    } catch (err) {
        console.error('Error statusCode:', err.response.statusCode);
        console.error('Error reponse:', err.response.body);
    }
}

More examples can be found under each method in SDK Classes section.

SDK Classes

ClassMethodHTTP requestDescription
Erc20PaymentsApicreateWalletPOST /v1/payment/erc20/walletCreate an unique wallet address to accept payments for an ERC-20 token from a buyer
Erc20PaymentsApigetWalletGET /v1/payment/erc20/wallet/{id}Return a specific wallet
Erc20PaymentsApilistWalletsGET /v1/payment/erc20/walletReturns a list of wallets
Erc20PaymentsApisettleWalletPOST /v1/payment/erc20/wallet/{id}/settleSettle a payment, amount received will be transferred even if less than payment amount
Erc20PaymentsApirefundWalletPOST /v1/payment/erc20/wallet/{id}/refundRefund wallet
Erc20PaymentsApigetWalletOperationGET /v1/payment/erc20/wallet/{id}/operation/{txid}Return a specific operation of the wallet
Erc20PaymentsApigetWalletOperationsGET /v1/payment/erc20/wallet/{id}/operationReturn the list of operations performed by the mechant on a specific wallet

Documentation For Models

Limitations

License

Copyright 2019 Bleumi, Inc.

Code licensed under the MIT License.