@etransfer/core
v1.11.0-alpha.0
Published
![ES Version](https://img.shields.io/badge/ES-2020-yellow) ![Node Version](https://img.shields.io/badge/node-18.x-green) [![NPM Package Version][npm-image-version]][npm-url]
Downloads
2,389
Keywords
Readme
@etransfer/core
This package integrates the main business functions of etransfer deposit and withdrawal, such as obtaining authorization tokens, initiating withdrawals, etc.
You only need to quote this package to easily access the etransfer deposit and withdrawal functions.
Installation
Using NPM
npm install @etransfer/core
Using Yarn
yarn add @etransfer/core
Prerequisites
Package.json Scripts
| Script | Description |
| -------- | -------------------------------------------------- |
| clean | Uses rm
to remove dist/
|
| build | Uses tsc
to build package and dependent packages |
| lint | Uses eslint
to lint package |
| lint:fix | Uses eslint
to check and fix any warnings |
| format | Uses prettier
to format the code |
How to use
See the @etransfer/example
for usage examples.
See more Developer Documentation.
Init
import { eTransferCore } from '@etransfer/core';
import { IStorageSuite } from '@etransfer/types';
class Store implements IStorageSuite {
async getItem(key: string) {
return localStorage.getItem(key);
}
async setItem(key: string, value: string) {
return localStorage.setItem(key, value);
}
async removeItem(key: string) {
return localStorage.removeItem(key);
}
}
eTransferCore.init({
etransferUrl: 'etransfer service url',
etransferAuthUrl: 'etransfer authorization service url' ,
storage: new Store()
});
Get authorization
// Get new authorization from the interface, hang on the request header and set data to storage.
await eTransferCore.getAuthTokenFromApi()
// Get authorization from storage, if the data expired, get new authorization from the interface.
await eTransferCore.getAuthToken();
Withdraw
// First, as shown above, init eTransferCore.
// Then, as shown above, get authorization and hang on the request header.
// Then, you can withdraw with correct params.
const { orderId, transactionId} = await eTransferCore.sendWithdrawOrder();