npm package: @plasma-platform/service-balances
Description: SDK for service balances
Author: Mirza Sergey
Latest version: 1.9.0

![version](https://badgen.net/npm/v/@plasma-platform/service-balances)
![nextVersion](https://badgen.net/npm/v/@plasma-platform/service-balances/next)
![downloads](https://badgen.net/npm/dt/@plasma-platform/service-balances)
![license](https://badgen.net/npm/license/@plasma-platform/service-balances)
![dependency](https://badgen.net/npm/dependents/@plasma-platform/service-balances)  

* * *

[Full documentation](https://templatemonster.gitlab.io/PlasmaPlatform/Frontend/plasma-platform/?path=/story/plasma-platform-sdk--service-balances)  
install:  
`npm i @plasma-platform/service-balances -S`  

# Short documentation

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [BalancesService](#balancesservice)
    -   [Parameters](#parameters)
    -   [createNewDocument](#createnewdocument)
        -   [Examples](#examples)
    -   [getLinkAmazonS3Uploader](#getlinkamazons3uploader)
        -   [Examples](#examples-1)
    -   [requestTaxpayerDocument](#requesttaxpayerdocument)
        -   [Examples](#examples-2)
    -   [createTaxpayerDocument](#createtaxpayerdocument)
        -   [Parameters](#parameters-1)
        -   [Examples](#examples-3)
    -   [checkBalanceByUserId](#checkbalancebyuserid)
        -   [Parameters](#parameters-2)
        -   [Examples](#examples-4)
    -   [requestTaxpayerInfo](#requesttaxpayerinfo)
        -   [Examples](#examples-5)
    -   [requestTransactionInfo](#requesttransactioninfo)
        -   [Parameters](#parameters-3)
        -   [Examples](#examples-6)
    -   [requestTransactionList](#requesttransactionlist)
        -   [Parameters](#parameters-4)
        -   [Examples](#examples-7)
    -   [requestBalances](#requestbalances)
        -   [Parameters](#parameters-5)
        -   [Examples](#examples-8)
    -   [createPaymentMethod](#createpaymentmethod)
        -   [Parameters](#parameters-6)
        -   [Examples](#examples-9)
    -   [createPaymentMethod](#createpaymentmethod-1)
        -   [Parameters](#parameters-7)
        -   [Examples](#examples-10)
    -   [createWithdrawRequest](#createwithdrawrequest)
        -   [Parameters](#parameters-8)
        -   [Examples](#examples-11)
    -   [requestUserPaymentMethods](#requestuserpaymentmethods)
        -   [Examples](#examples-12)
    -   [requestUserWithdrawInformation](#requestuserwithdrawinformation)
        -   [Examples](#examples-13)
    -   [requestWithdraws](#requestwithdraws)
        -   [Examples](#examples-14)
    -   [getBalanceByOrderId](#getbalancebyorderid)
        -   [Parameters](#parameters-9)
        -   [Examples](#examples-15)
    -   [updateAutoWithdrawal](#updateautowithdrawal)
        -   [Examples](#examples-16)
    -   [getWithdrawalInfo](#getwithdrawalinfo)
        -   [Examples](#examples-17)
    -   [getWithdrawalInvoice](#getwithdrawalinvoice)
        -   [Examples](#examples-18)

## BalancesService

-   **See: <https://jsonplaceholder.typicode.com/>**

Balances Micro Service API

### Parameters

-   `url` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** service url
-   `token` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** user access tocken if available (optional, default `null`)

### createNewDocument

Creates new document based on your user_id ("transactions" scope is needed)

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.createNewDocument();
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response

### getLinkAmazonS3Uploader

Return link to upload your file ("transactions" scope is needed)

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.getLinkAmazonS3Uploader();
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response

### requestTaxpayerDocument

Returns taxpayer own document by his access_token ("transactions" scope is required)

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.requestTaxpayerDocument();
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response

### createTaxpayerDocument

Create taxpayer info or update existent one

#### Parameters

-   `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object with arguments
    -   `args.type` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** taxpayer info type (required)
    -   `args.countryId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Char code of "Country or Country Residence" (required)
    -   `args.countryId2` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Char code of "Country citizenship or Country incorporation"
    -   `args.stateId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Char code of "State / Province ID"
    -   `args.city` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** City
    -   `args.zip` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** ZIP-code
    -   `args.address` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Street & apt. or suite no.
    -   `args.address2` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Permanent residence address
    -   `args.personNumberType` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Tax Number for individual (e.g. "Foreign Tax ID Number")
    -   `args.companyNumberType` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Tax Number for Corporation (e.g. "Employer Identification Number(EIN)")
    -   `args.taxIdNumber` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Tax ID number (XXX-XX-XXXX)
    -   `args.taxClassification` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Tax classification
    -   `args.name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Name (shown on your income tax return)
    -   `args.businessName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Business name
    -   `args.organizationName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Name of organization
    -   `args.disregardedEntity` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Name of disregarded entity
    -   `args.chapter3Status` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Chapter 3 status
    -   `args.signature` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Signature
    -   `args.residenceNumbers` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Residence numbers (optional) (not implemented yet)

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.createTaxpayerDocument({});
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response

### checkBalanceByUserId

Check balance of the specified user

#### Parameters

-   `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** user id

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.checkBalanceByUserId();
})();
```

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array with balances info

### requestTaxpayerInfo

Returns taxpayer own information by his access_token

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.requestTaxpayerInfo();
})();
```

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array with balances info

### requestTransactionInfo

Returns taxpayer own information by his access_token

#### Parameters

-   `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Transaction unique ID

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.requestTransactionInfo('1');
})();
```

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array with balances info

### requestTransactionList

Request Transactions list of authenticated user by balance type

#### Parameters

-   `args` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** object of params
    -   `args.balanceType` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Balance type
    -   `args.types` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** filter by transactions types divided by comma (e.g. types: 'sale,refund')
    -   `args.type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Balance type filter by transactions type (e.g. type: 'sale')

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.requestTransactionInfo('1');
})();
```

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array with balances info

### requestBalances

Request balance of authenticated user by type or default

#### Parameters

-   `balanceType` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** type of balance needed (vendor|bonus)

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.requestBalances();
})();
```

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array with balances info

### createPaymentMethod

Creates new payment method ("transactions" scope is needed)

#### Parameters

-   `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object with arguments
    -   `args.paymentMethod` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Payment method (paypal, wire, skrill, payoneer) (required)
    -   `args.email` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** E-mail (required for paypal & skrill)
    -   `args.fullName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** First & last name (required for wire)
    -   `args.address` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Address (required for wire)
    -   `args.country` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Country char code (required for wire)
    -   `args.swiftCode` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** SWIFT-code (required for wire)
    -   `args.bankAccountId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Bank account number (required for wire)
    -   `args.bankName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Bank name (required for wire)
    -   `args.bankAddress` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Bank address (required for wire)
    -   `args.payonnerId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** (required for payoneer)

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.createPaymentMethod({});
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response

### createPaymentMethod

Updates existed payment method ("transactions" scope is needed)

#### Parameters

-   `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object with arguments
    -   `args.paymentMethod` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Payment method (paypal, wire, skrill, payoneer) (required)
    -   `args.email` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** E-mail (required for paypal & skrill)
    -   `args.fullName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** First & last name (required for wire)
    -   `args.address` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Address (required for wire)
    -   `args.country` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Country char code (required for wire)
    -   `args.swiftCode` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** SWIFT-code (required for wire)
    -   `args.bankAccountId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Bank account number (required for wire)
    -   `args.bankName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Bank name (required for wire)
    -   `args.bankAddress` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Bank address (required for wire)
    -   `args.payonnerId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** (required for payoneer)

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.createPaymentMethod({});
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response

### createWithdrawRequest

Creates new withdraw request ("transactions" scope is needed)

#### Parameters

-   `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object with arguments
    -   `args.amount` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** amount to withdraw (must be greater than balance) (required)
    -   `args.paymentMethod` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Payment method (paypal, wire, skrill, payoneer) (required)

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.createWithdrawRequest({});
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response

### requestUserPaymentMethods

Get all user payment methods ("transactions" scope is needed)

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.requestUserPaymentMethods();
})();
```

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array with balances info

### requestUserWithdrawInformation

Return user own last withdraw request ("transactions" scope is needed)

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.requestUserPaymentMethods();
})();
```

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array with balances info

### requestWithdraws

Return all withdraws

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.requestWithdraws();
})();
```

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array with balances info

### getBalanceByOrderId

Transaction - Request balance of order for balance_type

#### Parameters

-   `params` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
    -   `params.orderId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Order id (required).
    -   `params.balanceType` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Balance type.

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('http://service-balances.dev/api/v2/');
  const request = await balancesService.getBalanceByOrderId(params);
})();
```

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;any>** 

### updateAutoWithdrawal

Update auto withdrawal

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.updateAutoWithdrawal();
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response

### getWithdrawalInfo

Withdraw - Get withdrawal information for user

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.getWithdrawalInfo();
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object with withdrawal info

### getWithdrawalInvoice

Withdraw - Get withdrawal invoice information

#### Examples

```javascript
(async () => {
  const balancesService = new BalancesService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const balances = await balancesService.getWithdrawalInvoice();
})();
```

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object with invoice info