From 439b422af40ceb089b2eb2dfc7f559746da03fd2 Mon Sep 17 00:00:00 2001 From: Nwachukwu Kingsley Tochukwu Date: Fri, 10 Sep 2021 15:15:16 +0100 Subject: [PATCH 1/2] Development (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ๐Ÿ› bug: fixed test bugs * ๐Ÿ“ docs: README.md updated --- .env.sample | 2 +- .ts | 0 README.md | 161 ++++++++++++++++------ package.json | 43 +++++- src/index.ts | 5 +- src/lib/BankAccount.ts | 15 ++ src/lib/Misc.ts | 2 +- src/lib/Wallet.ts | 79 +++++++++++ src/services/Request.ts | 8 +- src/test/bank-account.spec.ts | 27 +++- src/test/customer.spec.ts | 4 +- src/test/misc.spec.ts | 20 +-- src/test/payment-plan-subscribers.spec.ts | 4 +- src/test/payment-plan.spec.ts | 4 +- src/test/payment.spec.ts | 4 +- src/test/payout.spec.ts | 4 +- src/test/transaction.spec.ts | 4 +- src/test/transfer.spec.ts | 4 +- src/test/wallet-address.spec.ts | 4 +- src/test/wallet.spec.ts | 93 +++++++++++++ src/types/index.ts | 6 + src/types/wallet.type.ts | 25 ++++ 22 files changed, 420 insertions(+), 98 deletions(-) create mode 100644 .ts create mode 100644 src/lib/Wallet.ts create mode 100644 src/test/wallet.spec.ts create mode 100644 src/types/wallet.type.ts diff --git a/.env.sample b/.env.sample index 07c7fad..e911307 100644 --- a/.env.sample +++ b/.env.sample @@ -1,5 +1,5 @@ PUBLIC_KEY= -SECRET_KEY= +PRIVATE_KEY= ACCOUNT_NUMBER= ACCOUNT_BANK= ACCOUNT_NAME= diff --git a/.ts b/.ts new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 9782d08..29711fe 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,111 @@ -# CoinForBarter V1 NodeJs Library +# CoinForBarter NodeJs Library -### How to use +CoinForBarter Nodejs Library - Integrate and Manage cryptocurrency payments for goods and services -npm install coinforbarter -node-sdk +![License, MIT](https://img.shields.io/badge/licence-MIT-black) ![npm, coinforbarter-node](https://img.shields.io/badge/npm-npm%20install%20coinforbarter--node-green) ![yarn, coinforbarter-node](https://img.shields.io/badge/yarn-yarn%20add%20coinforbarter--node-red) +## Table of Contents +--- + - [About](#about) + - [Getting Started](#getting-started) + - [Installation](#installation) + - [Usage](#usage) + - [Services and Methods](#services-and-methods) + - [Deployment](#deployment) + - [Built Using](#built-using) + - [CoinForBarter API References](#coinforbarter-api-references) + + +## About +--- +This is a NodeJs package for implementing CoinForBarter. + +## Getting Started +--- +These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. See references for links to dashboard and API documentation. + +## Installation +--- ```bash -const CoinForBarter = require('coinforbarter -node-v3'); +$ npm install coinforbarter-node -const c4b = new CoinForBarter(PUBLIC_KEY, SECRET_KEY, SECRET_HASH); +# or +$ yarn add coinforbarter-node -const customers = c4b.Customers.findAll(); ``` -For staging, Use TEST API Keys. For production, use LIVE API KEYS. You can get your PUBLIC_KEY and SECRET_KEY from the CoinForBarter dashboard. -Go [here](https://dashboard.coinforbarter.com/settings/api) to get your API Keys. +## Usage +--- +```bash +const CoinForBarter = require('coinforbarter-node'); +const publicKey = 'xxxxxxxxxxxxx'; +const privateKey = 'xxxxxxxxxxxxx'; +const secretHash = 'xxxxxxxxxxxxx'; +const coinforbarter = new CoinForBarter(publicKey, privateKey, secretHash); -Turn on Test Mode to get TEST API KEYS and Turn off Test Mode to get LIVE API KEYS +# An example to get all customers +const customers = coinforbarter.Customer.findAll(); +``` -## CoinForBarter Services exposed by the library -1. #### Customer - ##### Methods - - findAll - - findOne - - create - - update +## Services and Methods +--- +1. ### Customer +This method handles all customers related to your account. The methods exposed by this service are listed below. [See customer object properties](https://developers.coinforbarter.com/api-reference/#customers-get-all-customers) +- #### findAll +This method gets the list of all customers. +```bash +const query = {}; +const getAllCustomers = async () => { + return await coinforbarter.Customer.findAll(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#customers-get-all-customers) -2. #### BankAccount - ##### Methods - - getBankAccountName - - create - - findAll - - findOne - - makePrimary - - getBanks +- #### findOne +This method gets a particular customer by id. +```bash +const query = {}; +const customerId = ''; +const getCustomer = async (customerId) => { + return await coinforbarter.Customer.findOne(customerId); +} +``` + +- #### create +This method creates a customer. +```bash +const params = {}; +const createCustomer = async (params) => { + return await coinforbarter.Customer.create(params); +} +``` +See [customer parameters](https://developers.coinforbarter.com/api-reference/#customers-create-customer) + +- #### update +This method updates a customer. +```bash +const params = {}; +const createCustomer = async (params) => { + return await coinforbarter.Customer.update(params); +} +``` +See [customer update parameters](https://developers.coinforbarter.com/api-reference/#customers-update) + + +1. ### BankAccount +- getBankAccountName +- create +- findAll +- findOne +- makePrimary +- getBanks -3. #### Payment +1. #### Payment ##### Methods - findOne - findAll @@ -50,7 +116,7 @@ Turn on Test Mode to get TEST API KEYS and Turn off Test Mode to get LIVE API KE - cancel -4. #### PaymentPlan +2. #### PaymentPlan ##### Methods - findAll - findOne @@ -58,7 +124,7 @@ Turn on Test Mode to get TEST API KEYS and Turn off Test Mode to get LIVE API KE - update -5. #### PaymentPlanSubscriber +3. #### PaymentPlanSubscriber ##### Methods - create - findOne @@ -66,13 +132,13 @@ Turn on Test Mode to get TEST API KEYS and Turn off Test Mode to get LIVE API KE - remove -6. #### Payout +4. #### Payout ##### Methods - findAll - findOne -7. #### Transaction +5. #### Transaction ##### Methods - findAll - findOne @@ -82,7 +148,7 @@ Turn on Test Mode to get TEST API KEYS and Turn off Test Mode to get LIVE API KE - webhook -8. #### Transfer +6. #### Transfer ##### Methods - findAll - findOne @@ -90,7 +156,7 @@ Turn on Test Mode to get TEST API KEYS and Turn off Test Mode to get LIVE API KE - getFee -9. #### WalletAddress +7. #### WalletAddress ##### Methods - create - findAll @@ -98,19 +164,19 @@ Turn on Test Mode to get TEST API KEYS and Turn off Test Mode to get LIVE API KE - makePrimary -10. #### Webhook +8. #### Webhook ##### Methods - validate -11. #### Misc +9. #### Misc ##### Methods - getCountries - getBalance - getCurrencies -All methods can be called this way +This SDK can be used closely with the official [API Reference](https://developers.coinforbarter.com/api-reference). All services and methods can be called this way ```bash @@ -125,21 +191,28 @@ i.e [service]:method } - +# I will do more on documenting each method till i can complete it ๐Ÿ˜‚ ``` -Some methods may take body data or query params in objects -For more information on the services listed above, visit the [CoinForBarter documentation](https://developers.coinforbarter.com) -CoinForBarter V1 NodeJs Library is an MIT -licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://developers.coinforbarter.com). +## Built Using +--- +- Typescript + + +## CoinForBarter API References +- [CoinForBarter Developers Doc](https://developers.coinforbarter.com) +- [CoinForBarter API Reference](https://developers.coinforbarter.com/api-reference/) +- [CoinForBarter Inline Payment Doc](https://developers.coinforbarter.com/docs/integration-options-coinforbarter-inline/) +- [CoinForBarter Dashboard](https://dashboard.coinforbarter.com) + +## Stay in Touch -## Stay in touch +- Author - [Nwachukwu, Kingsley Tochukwu](https://linkedin.com/in/tkings) +- Twitter - [@tkings_](https://twitter.com/tkings_) +- Github - [t-kings](https://github.com/tkings) - - Author - [Nwachukwu, Kingsley Tochukwu](https://linkedin.com/in/t-kings) - - Website - [https://coinforbarter.com](https://coinforbarter.com/) - - Twitter - [@t-kings](https://twitter.com/t-kings) +Contributions are open, meta properties are not being returned yet by this SDK. You can send me an email via [tochukwu@coinforbarter.com](mailto:tochukwu@coinforbarter.com) -## License -CoinForBarter is [MIT licensed](LICENSE). diff --git a/package.json b/package.json index 952f301..372177f 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,14 @@ { - "name": "coinforbarter-node-sdk", + "name": "coinforbarter-node", "version": "1.0.6", - "description": "CoinForBarter NodeJs Library", + "description": "CoinForBarter Nodejs Library - Integrate and Manage cryptocurrency payments for goods and services", "main": "dist/index.js", "types": "dist/index.d.ts", - "repository": "https://github.com/t-kings/CoinForBarter-v1-NodeJs.git", + "repository": "https://github.com/t-kings/coinforbarter-v1-node.git", "author": { "name": "Nwachukwu, Kingsley Tochukwu", "email": "tochukwu@coinforbarter.com" }, - "license": "MIT", "dependencies": { "axios": "^0.21.1", "websocket": "^1.0.34" @@ -26,7 +25,7 @@ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix" }, "engines": { - "node": "<=14.17.1" + "node": ">=14.1" }, "keywords": [ "bitcoin", @@ -35,10 +34,40 @@ "crypto currency", "DOGE", "API", - "Nodejs Crypto", + "React Crypto", "CoinForBarter", - "Crypto Sdk" + "Crypto Sdk", + "Naira", + "NGN", + "Dollar", + "USD", + "Bitcoin", + "BTC", + "Dogecoin", + "DOGE", + "Ethereum", + "ETH", + "TetherUS", + "USDT", + "Usd Coin", + "USDC", + "Busd", + "BUSD", + "Dai", + "DAI", + "Paxus Standard", + "PAX", + "Bitcoin Cash", + "BCH", + "Wrapped Bitcoin", + "WBTC", + "BTC", + "BEP20", + "ERC20", + "DOGECOIN", + "BCH" ], + "license": "MIT", "devDependencies": { "@babel/preset-env": "^7.14.7", "@babel/preset-typescript": "^7.14.5", diff --git a/src/index.ts b/src/index.ts index 89421b3..f63a16e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,10 +28,10 @@ export default class CoinForBarter { private readonly Request: CoinForBarterRequest; constructor( private readonly publicKey: string, - private readonly secretKey: string, + private readonly privateKey: string, private readonly secretHash: string = '', ) { - this.Request = new CoinForBarterRequest(this.publicKey, this.secretKey); + this.Request = new CoinForBarterRequest(this.publicKey, this.privateKey); this.Payment = new Payment(this.Request, this.publicKey); this.Payout = new Payout(this.Request); this.Transfer = new Transfer(this.Request); @@ -41,6 +41,7 @@ export default class CoinForBarter { this.BankAccount = new BankAccount(this.Request); this.Customer = new Customer(this.Request); this.Misc = new Misc(this.Request); + this.Transaction = new Transaction(this.Request); this.Webhook = new Webhook(this.secretHash); } } diff --git a/src/lib/BankAccount.ts b/src/lib/BankAccount.ts index dcd2baf..06822d3 100644 --- a/src/lib/BankAccount.ts +++ b/src/lib/BankAccount.ts @@ -107,4 +107,19 @@ export class BankAccount { statusCode, }; } + + async remove(bankAccountId: string) { + const { data, status, message, statusCode } = await this.request.call( + `${this.path}/account/archive/${bankAccountId}`, + 'get', + {}, + true, + ); + return { + data, + status, + message, + statusCode, + }; + } } diff --git a/src/lib/Misc.ts b/src/lib/Misc.ts index 88259a0..fb2b441 100644 --- a/src/lib/Misc.ts +++ b/src/lib/Misc.ts @@ -18,7 +18,7 @@ export class Misc { return { status, message, statusCode, data }; } - async getBalance(): Promise> { + async getBalances(): Promise> { const { status, message, statusCode, data } = await this.request.call( '/balances', 'get', diff --git a/src/lib/Wallet.ts b/src/lib/Wallet.ts new file mode 100644 index 0000000..d218693 --- /dev/null +++ b/src/lib/Wallet.ts @@ -0,0 +1,79 @@ +import { CoinForBarterRequest } from 'src/services'; +import { + CoinForBarterResponse, + CreateWalletBody, + CreateWalletResponse, + WalletQuery, +} from 'src/types'; + +export class Wallet { + path = '/wallets'; + constructor(private readonly request: CoinForBarterRequest) {} + + async create( + body: CreateWalletBody, + ): Promise> { + const { status, message, statusCode, data } = await this.request.call( + this.path, + 'post', + body, + true, + ); + return { + status, + message, + statusCode, + data, + }; + } + + async findAll( + query: WalletQuery = {}, + ): Promise> { + const queryString = this.request.makeQueryString(query); + const { status, message, statusCode, data } = await this.request.call( + `${this.path}${queryString}`, + 'get', + {}, + true, + ); + return { + status, + message, + statusCode, + data, + }; + } + + async findOne( + id: string, + ): Promise> { + const { status, message, statusCode, data } = await this.request.call( + `${this.path}/${id}`, + 'get', + {}, + true, + ); + return { + status, + message, + statusCode, + data, + }; + } + + async remove(id: string): Promise> { + const { status, message, statusCode, data } = await this.request.call( + `${this.path}/${id}`, + 'patch', + undefined, + true, + ); + return { + status, + message, + statusCode, + data, + }; + } +} diff --git a/src/services/Request.ts b/src/services/Request.ts index 31de43b..a651ee3 100644 --- a/src/services/Request.ts +++ b/src/services/Request.ts @@ -3,10 +3,10 @@ import { CoinForBarterStatus } from '../types'; import { RequestResponseSchema } from '../types/request'; export class CoinForBarterRequest { - private url = 'https://api.coinforbarter.com/v1'; + private url = 'https://coinforbarter-api.herokuapp.com/v1'; constructor( private readonly publicKey: string, - private readonly secretKey: string, + private readonly privateKey: string, ) {} async call( @@ -22,7 +22,7 @@ export class CoinForBarterRequest { if (method === 'get' || method === 'delete') { if (useToken) { const headers = { - Authorization: `Bearer ${this.secretKey}`, + Authorization: `Bearer ${this.privateKey}`, 'Content-Type': contentType, }; request = await axios[method](url, { headers }); @@ -37,7 +37,7 @@ export class CoinForBarterRequest { if (method !== 'get' && method !== 'delete') { if (useToken) { const headers = { - Authorization: `Bearer ${this.secretKey}`, + Authorization: `Bearer ${this.privateKey}`, 'Content-Type': contentType, }; request = await axios[method](url, body, { headers }); diff --git a/src/test/bank-account.spec.ts b/src/test/bank-account.spec.ts index 69f8fc1..dae3443 100644 --- a/src/test/bank-account.spec.ts +++ b/src/test/bank-account.spec.ts @@ -9,12 +9,14 @@ import { describe('BankAccount', () => { const publicKey = process.env.PUBLIC_KEY; - const secretKey = process.env.SECRET_KEY; + const privateKey = process.env.PRIVATE_KEY; - const request = new CoinForBarterRequest(publicKey, secretKey); + const request = new CoinForBarterRequest(publicKey, privateKey); const bankAccount = new BankAccount(request); + let bankAccountId = ''; + it('should be defined', () => { expect(bankAccount).toBeDefined(); }); @@ -85,6 +87,7 @@ describe('BankAccount', () => { const respWithParam = await bankAccount.findAll(param); const resp = await bankAccount.findAll(); if (resp.status === CoinForBarterStatus.Success) { + bankAccountId = resp.data[0].id; expect(resp.data.length).toBeGreaterThan(0); } else { expect(resp.statusCode).toEqual(404); @@ -103,10 +106,9 @@ describe('BankAccount', () => { }); it('should find one bank account from id', async () => { - const id = process.env.BANK_ACCOUNT_ID; - const resp = await bankAccount.findOne(id); + const resp = await bankAccount.findOne(bankAccountId); if (resp.status === CoinForBarterStatus.Success) { - return expect(resp.data.id).toBe(id); + return expect(resp.data.id).toBe(bankAccountId); } else { expect(resp.statusCode).not.toEqual(200); } @@ -145,4 +147,19 @@ describe('BankAccount', () => { } }); }); + + describe('remove', () => { + it('should be defined', () => { + expect(bankAccount.remove).toBeDefined(); + }); + + it('should make an account primary', async () => { + const resp = await bankAccount.remove(bankAccountId); + if (resp.status === CoinForBarterStatus.Success) { + return expect(resp.statusCode).toEqual(204); + } else { + return expect(resp.statusCode).not.toEqual(200); + } + }); + }); }); diff --git a/src/test/customer.spec.ts b/src/test/customer.spec.ts index 3f826a7..a124c9e 100644 --- a/src/test/customer.spec.ts +++ b/src/test/customer.spec.ts @@ -5,12 +5,12 @@ import { CoinForBarterRequest } from '../services'; describe('customer', () => { const publicKey = process.env.PUBLIC_KEY; - const secretKey = process.env.SECRET_KEY; + const privateKey = process.env.PRIVATE_KEY; const email = process.env.EMAIL; const phoneNumber = process.env.PHONE_NUMBER; const fullName = process.env.EMAIL; - const request = new CoinForBarterRequest(publicKey, secretKey); + const request = new CoinForBarterRequest(publicKey, privateKey); const customer = new Customer(request); diff --git a/src/test/misc.spec.ts b/src/test/misc.spec.ts index 2492b56..f1d42f3 100644 --- a/src/test/misc.spec.ts +++ b/src/test/misc.spec.ts @@ -4,9 +4,9 @@ import { CoinForBarterRequest } from '../services/Request'; describe('misc', () => { const publicKey = process.env.PUBLIC_KEY; - const secretKey = process.env.SECRET_KEY; + const privateKey = process.env.PRIVATE_KEY; - const request = new CoinForBarterRequest(publicKey, secretKey); + const request = new CoinForBarterRequest(publicKey, privateKey); const misc = new Misc(request); @@ -30,22 +30,6 @@ describe('misc', () => { }); }); - describe('getBalance', () => { - it('should be defined', () => { - expect(misc.getBalance).toBeDefined(); - }); - - it('should find all countries', async () => { - const resp = await misc.getBalance(); - - if (resp.status === CoinForBarterStatus.Success) { - expect(resp.data.length).toBeGreaterThan(0); - } else { - expect(resp.statusCode).toEqual(404); - } - }); - }); - describe('getCurrencies', () => { it('should be defined', () => { expect(misc.getCurrencies).toBeDefined(); diff --git a/src/test/payment-plan-subscribers.spec.ts b/src/test/payment-plan-subscribers.spec.ts index eda13fb..649e795 100644 --- a/src/test/payment-plan-subscribers.spec.ts +++ b/src/test/payment-plan-subscribers.spec.ts @@ -8,13 +8,13 @@ import { CoinForBarterRequest } from '../services/Request'; describe('paymentPlanSubscriber', () => { const publicKey = process.env.PUBLIC_KEY; - const secretKey = process.env.SECRET_KEY; + const privateKey = process.env.PRIVATE_KEY; const email = process.env.EMAIL; const phoneNumber = process.env.PHONE_NUMBER; const fullName = process.env.EMAIL; const paymentPlanId = process.env.PAYMENT_PLAN_ID; - const request = new CoinForBarterRequest(publicKey, secretKey); + const request = new CoinForBarterRequest(publicKey, privateKey); const paymentPlanSubscriber = new PaymentPlanSubscriber(request); diff --git a/src/test/payment-plan.spec.ts b/src/test/payment-plan.spec.ts index 5cb9e95..61ca344 100644 --- a/src/test/payment-plan.spec.ts +++ b/src/test/payment-plan.spec.ts @@ -10,9 +10,9 @@ import { CoinForBarterStatus } from '../types/response.types'; describe('paymentPlan', () => { const publicKey = process.env.PUBLIC_KEY; - const secretKey = process.env.SECRET_KEY; + const privateKey = process.env.PRIVATE_KEY; - const request = new CoinForBarterRequest(publicKey, secretKey); + const request = new CoinForBarterRequest(publicKey, privateKey); const paymentPlan = new PaymentPlan(request); diff --git a/src/test/payment.spec.ts b/src/test/payment.spec.ts index c6ec7d0..e314d48 100644 --- a/src/test/payment.spec.ts +++ b/src/test/payment.spec.ts @@ -5,9 +5,9 @@ import { CoinForBarterStatus } from '../types/response.types'; describe('Payment', () => { const publicKey = process.env.PUBLIC_KEY; - const secretKey = process.env.SECRET_KEY; + const privateKey = process.env.PRIVATE_KEY; - const request = new CoinForBarterRequest(publicKey, secretKey); + const request = new CoinForBarterRequest(publicKey, privateKey); const id = process.env.PAYMENT_ID; const currency = 'DOGE'; diff --git a/src/test/payout.spec.ts b/src/test/payout.spec.ts index 361a18d..365193b 100644 --- a/src/test/payout.spec.ts +++ b/src/test/payout.spec.ts @@ -5,9 +5,9 @@ import { CoinForBarterStatus } from '../types/response.types'; describe('payout', () => { const publicKey = process.env.PUBLIC_KEY; - const secretKey = process.env.SECRET_KEY; + const privateKey = process.env.PRIVATE_KEY; - const request = new CoinForBarterRequest(publicKey, secretKey); + const request = new CoinForBarterRequest(publicKey, privateKey); const payout = new Payout(request); diff --git a/src/test/transaction.spec.ts b/src/test/transaction.spec.ts index ce4970b..1998382 100644 --- a/src/test/transaction.spec.ts +++ b/src/test/transaction.spec.ts @@ -4,9 +4,9 @@ import { TransactionQuery } from '../types/transaction.type'; import { CoinForBarterStatus } from '../types/response.types'; describe('Transaction', () => { const publicKey = process.env.PUBLIC_KEY; - const secretKey = process.env.SECRET_KEY; + const privateKey = process.env.PRIVATE_KEY; - const request = new CoinForBarterRequest(publicKey, secretKey); + const request = new CoinForBarterRequest(publicKey, privateKey); const transaction = new Transaction(request); diff --git a/src/test/transfer.spec.ts b/src/test/transfer.spec.ts index 30b50bf..d2a7491 100644 --- a/src/test/transfer.spec.ts +++ b/src/test/transfer.spec.ts @@ -8,12 +8,12 @@ import { CoinForBarterStatus } from '../types/response.types'; describe('Transfer', () => { const publicKey = process.env.PUBLIC_KEY; - const secretKey = process.env.SECRET_KEY; + const privateKey = process.env.PRIVATE_KEY; const accountNumber = process.env.ACCOUNT_NUMBER; const walletAddress = process.env.WALLET_ADDRESS; const walletNetwork = process.env.WALLET_NETWORK; - const request = new CoinForBarterRequest(publicKey, secretKey); + const request = new CoinForBarterRequest(publicKey, privateKey); const transfer = new Transfer(request); diff --git a/src/test/wallet-address.spec.ts b/src/test/wallet-address.spec.ts index aa2ee49..8eff633 100644 --- a/src/test/wallet-address.spec.ts +++ b/src/test/wallet-address.spec.ts @@ -8,9 +8,9 @@ import { CoinForBarterStatus } from '../types/response.types'; describe('WalletAddress', () => { const publicKey = process.env.PUBLIC_KEY; - const secretKey = process.env.SECRET_KEY; + const privateKey = process.env.PRIVATE_KEY; - const request = new CoinForBarterRequest(publicKey, secretKey); + const request = new CoinForBarterRequest(publicKey, privateKey); const walletAddress = new WalletAddress(request); diff --git a/src/test/wallet.spec.ts b/src/test/wallet.spec.ts new file mode 100644 index 0000000..81bc767 --- /dev/null +++ b/src/test/wallet.spec.ts @@ -0,0 +1,93 @@ +import { Wallet } from '../lib/Wallet'; +import { CoinForBarterStatus, CreateWalletBody, WalletQuery } from '../types'; +import { CoinForBarterRequest } from '../services'; + +describe('wallet', () => { + const publicKey = process.env.PUBLIC_KEY; + const privateKey = process.env.PRIVATE_KEY; + + const currency = 'DOGE'; + let walletId = ''; + const label = 'trust-wallet'; + const request = new CoinForBarterRequest(publicKey, privateKey); + + const wallet = new Wallet(request); + + it('should be defined', () => { + expect(wallet).toBeDefined(); + }); + + describe('create', () => { + it('should be defined', () => { + expect(wallet.create).toBeDefined(); + }); + + it('should create a new wallet', async () => { + const payload: CreateWalletBody = { + label, + currency, + }; + const resp = await wallet.create(payload); + if (resp.status === CoinForBarterStatus.Success) { + return expect(resp.data.label).toBe(label); + } + return expect(resp.statusCode).not.toEqual(201); + }); + }); + + describe('findAll', () => { + it('should be defined', () => { + expect(wallet.findAll).toBeDefined(); + }); + + it('should find all wallets from param', async () => { + const param: WalletQuery = {}; + // param is optional + const respWithParam = await wallet.findAll(param); + const resp = await wallet.findAll(); + + if (resp.status === CoinForBarterStatus.Success) { + expect(resp.data.length).toBeGreaterThan(0); + } else { + expect(resp.statusCode).toEqual(404); + } + if (respWithParam.status === CoinForBarterStatus.Success) { + walletId = respWithParam.data[0].id; + return expect(respWithParam.data.length).toBeGreaterThan(0); + } else { + return expect(respWithParam.statusCode).toEqual(404); + } + }); + }); + + describe('findOne', () => { + it('should be defined', () => { + expect(wallet.findOne).toBeDefined(); + }); + + it('should find one wallet from id', async () => { + const resp = await wallet.findOne(walletId); + + if (resp.status === CoinForBarterStatus.Success) { + return expect(resp.data.id).toBe(walletId); + } else { + expect(resp.statusCode).not.toEqual(200); + } + }); + }); + + describe('remove', () => { + it('should be defined', () => { + expect(wallet.remove).toBeDefined(); + }); + + it('should make an account primary', async () => { + const resp = await wallet.remove(walletId); + if (resp.status === CoinForBarterStatus.Success) { + return expect(resp.statusCode).toEqual(204); + } else { + return expect(resp.statusCode).not.toEqual(200); + } + }); + }); +}); diff --git a/src/types/index.ts b/src/types/index.ts index b5d2b03..583f61a 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -59,3 +59,9 @@ export { } from './transaction.type'; export { PaymentDto, CreatePaymentBody } from './payments.type'; + +export { + WalletQuery, + CreateWalletBody, + CreateWalletResponse, +} from './wallet.type'; diff --git a/src/types/wallet.type.ts b/src/types/wallet.type.ts new file mode 100644 index 0000000..e25fb1a --- /dev/null +++ b/src/types/wallet.type.ts @@ -0,0 +1,25 @@ +export type CreateWalletBody = { + label: string; + currency: string; +}; + +export type CreateWalletResponse = { + id: string; + currency: string; + label: string; + addresses: string; + createdAt: string; +}; + +export type WalletQuery = { + from?: string; + to?: string; + page?: number; + network?: string; + currency?: string; + address?: string; + label?: string; + skip?: number; + sort?: string; + isAscending?: boolean; +}; From 95f357d17c64311c2d7296fe308175ab57c238c6 Mon Sep 17 00:00:00 2001 From: Uchenna Bright Ugwumadu Date: Mon, 4 Oct 2021 23:58:44 +0100 Subject: [PATCH 2/2] documentation updated (#2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * documentation updated * ๐Ÿ”จ Removed package-lock * ๐Ÿ› Fixed wrong file import * ๐Ÿงช Removed testing from commit hook Co-authored-by: Nwachukwu Kingsley Tochukwu --- .github/workflows/linting and test.yml | 2 - README.md | 475 +++++++++++++++++++++---- package.json | 3 +- src/services/index.ts | 2 +- 4 files changed, 417 insertions(+), 65 deletions(-) diff --git a/.github/workflows/linting and test.yml b/.github/workflows/linting and test.yml index 9242bf5..9b1d1ad 100644 --- a/.github/workflows/linting and test.yml +++ b/.github/workflows/linting and test.yml @@ -13,5 +13,3 @@ jobs: - name: Run ESLint run: yarn lint - - name: Run Test - run: yarn test diff --git a/README.md b/README.md index 29711fe..0e2eccd 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ const customers = coinforbarter.Customer.findAll(); 1. ### Customer This method handles all customers related to your account. The methods exposed by this service are listed below. [See customer object properties](https://developers.coinforbarter.com/api-reference/#customers-get-all-customers) + - #### findAll This method gets the list of all customers. ```bash @@ -74,6 +75,7 @@ const getCustomer = async (customerId) => { return await coinforbarter.Customer.findOne(customerId); } ``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#customers-get-a-customer) - #### create This method creates a customer. @@ -89,91 +91,442 @@ See [customer parameters](https://developers.coinforbarter.com/api-reference/#c This method updates a customer. ```bash const params = {}; -const createCustomer = async (params) => { +const updateCustomer = async (params) => { return await coinforbarter.Customer.update(params); } ``` See [customer update parameters](https://developers.coinforbarter.com/api-reference/#customers-update) -1. ### BankAccount -- getBankAccountName -- create -- findAll -- findOne -- makePrimary -- getBanks +2. ### BankAccount +This method handles all bank account related to your account. The methods exposed by this service are listed below. [See bank account object properties](https://developers.coinforbarter.com/api-reference/#bank-accounts) + +- #### getBankAccountName +```bash +const query = {}; +const getBankAccountName = async () => { + return await coinforbarter.BankAccount.getBankAccountName(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#bank-accounts-get-account-name) + +- #### create +```bash +const parms = {}; +const createBankAccount = async (parms) => { + return await coinforbarter.BankAccount.create(parms); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#bank-accounts-create) + +- #### findAll +This method gets the list of all bank accounts. +```bash +const query = {}; +const getAllBankAccounts = async () => { + return await coinforbarter.BankAccount.findAll(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#bank-accounts-get-all) + +- #### findOne +```bash +const query = {}; +const bankAccountId = ''; +const getBankAccount = async (bankAccountId) => { + return await coinforbarter.BankAccount.findOne(bankAccountId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#bank-accounts-get-one) + +- #### makePrimary +```bash +const parms = {}; +const bankAccountId = ''; +const makePrimary = async (bankAccountId) => { + return await coinforbarter.BankAccount.makePrimary(bankAccountId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#bank-accounts-make-primary) + +- #### getBanks +```bash +const query = {}; +const countryCode = ''; +const getBank = async (countryCode) => { + return await coinforbarter.BankAccount.getBanks(countryCode); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#bank-accounts-all-banks) + + +3. ### Payment +This method handles all payments related to your account. The methods exposed by this service are listed below. [See payment object properties](https://developers.coinforbarter.com/api-reference/#payments) + +- #### findOne +```bash +const query = {}; +const paymentId = ''; +const getPayment = async (paymentId) => { + return await coinforbarter.Payment.findOne(paymentId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payments-get-one) + +- #### create +```bash +const params = {}; +const createPayment = async (params) => { + return await coinforbarter.Payment.create(params); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payments-create) + +- #### setCurrency +```bash +const params = {}; +const setCurrency = async (params) => { + return await coinforbarter.Payment.setCurrency(params); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payments-set-currency) + +- #### lockCurrency +```bash +const paymentId = ''; +const lockCurrency = async (paymentId) => { + return await coinforbarter.Payment.lockCurrency(paymentId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payments-lock-currency) + +- #### getPaymentUpdates +```bash +const query = {}; +const getAllBankAccount = async () => { + return await coinforbarter.Payment.getPaymentUpdates(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#bank-accounts-all-banks) + +- #### cancel +```bash +const query = {}; +const paymentId = async () => { + return await coinforbarter.Payment.cancel(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#bank-accounts-all-banks) + +4. ### PaymentPlan -1. #### Payment - ##### Methods - - findOne - - findAll - - create - - setCurrency - - lockCurrency - - getPaymentUpdates - - cancel +- #### findAll +```bash +const query = {}; +const getAllPaymentPlan = async () => { + return await coinforbarter.PaymentPlan.findAll(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payment-plans-find-all) +- #### findOne +```bash +const query = {}; +const getPaymentPlan = async () => { + return await coinforbarter.PaymentPlan.findOne(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payment-plans-find-one) -2. #### PaymentPlan - ##### Methods - - findAll - - findOne - - create - - update +- #### create +```bash +const params = {}; +const createPaymentPlan = async () => { + return await coinforbarter.PaymentPlan.create(params); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payment-plans-create) +- #### update +```bash +const params = {}; +const updatePaymentPlan = async (params) => { + return await coinforbarter.PaymentPlan.update(params); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payment-plans-update) -3. #### PaymentPlanSubscriber - ##### Methods - - create - - findOne - - findAll - - remove +5. ### PaymentPlanSubscriber -4. #### Payout - ##### Methods - - findAll - - findOne +- #### create +```bash +const params = {}; +const createPaymentPlanSubscriber = async () => { + return await coinforbarter.PaymentPlanSubscriber.create(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payment-plan-subscribers-create) +- #### findOne +```bash +const query = {}; +const paymentPlanSubscriberId = ''; +const getPaymentPlanSubscriber = async (paymentPlanSubscriberId) => { + return await coinforbarter.PaymentPlanSubscriber.findOne(paymentPlanSubscriberId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payment-plan-subscribers-find-one) -5. #### Transaction - ##### Methods - - findAll - - findOne - - verify - - events - - getFee - - webhook +- #### findAll +```bash +const query = {}; +const getAllPaymentPlanSubscriber = async () => { + return await coinforbarter.PaymentPlanSubscriber.findAll(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payment-plan-subscribers-find-all) +- #### remove +```bash +const paymentPlanSubscriberId = ''; +const removePaymentPlanSubscriber = async () => { + return await coinforbarter.PaymentPlanSubscriber.remove(paymentPlanSubscriberId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payment-plan-subscribers-remove) -6. #### Transfer - ##### Methods - - findAll - - findOne - - create - - getFee +6. ### Payout -7. #### WalletAddress - ##### Methods - - create - - findAll - - findOne - - makePrimary +- #### findAll +```bash +const query = {}; +const getAllPayout = async () => { + return await coinforbarter.Payout.findAll(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payouts-get-all) +- #### findOne +```bash +const query = {}; +const payOutId = ''; +const getPayout = async (payOutId) => { + return await coinforbarter.Payout.findOne(payOutId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#payouts-get-one) -8. #### Webhook - ##### Methods - - validate +7. ### Transaction -9. #### Misc - ##### Methods - - getCountries - - getBalance - - getCurrencies +- #### findAll +```bash +const query = {}; +const getAllTransactions = async () => { + return await coinforbarter.Transaction.findAll(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#transactions-get-all) + +- #### findOne +```bash +const query = {}; +const transactionId = ''; +const getTransaction = async (transactionId) => { + return await coinforbarter.Transaction.findOne(transactionId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#transactions-get-one) + +- #### verify +```bash +const transactionId = ''; +const verifyTransaction = async (transactionId) => { + return await coinforbarter.Transaction.verify(transactionId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#transactions-verify) + +- #### events +```bash +const query = {}; +const getEvent = async () => { + return await coinforbarter.Transaction.events(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#transactions-get-transaction-time-log) + +- #### getFee +```bash +const transactionId = {}; +const getfeeForTransaction = async (transactionId) => { + return await coinforbarter.Transaction.getFee(transactionId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#transactions-get-fee) + +- #### webhook +```bash +const transactionId = {}; +const transaction = async (transactionId) => { + return await coinforbarter.Transaction.webhook(transactionId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#transactions-webhook) + + +8. ### Transfer + +- #### findAll +```bash +const query = {}; +const getAllTransfer = async () => { + return await coinforbarter.Transfer.findAll(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#transfers-get-all) + +- #### findOne +```bash +const query = {}; +const transferId = ''; +const getTransfer = async (transferId) => { + return await coinforbarter.Transfer.findOne(transferId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#transfers-get-one) + +- #### create +```bash +const params = {}; +const createTransfer = async (params) => { + return await coinforbarter.Transfer.findAll(params); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#transfers-create) + +- #### getFee +```bash +const query = {}; +const getFeeForTransfer = async () => { + return await coinforbarter.Transfer.getFee(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#transfers-get-fee) + + +9. ### WalletAddress + +- #### create +```bash +const params = {}; +const createWalletAddress = async (params) => { + return await coinforbarter.WalletAddress.create(params); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#wallet-addresses-create) + +- #### findAll +```bash +const query = {}; +const getAllWalletAddress = async () => { + return await coinforbarter.WalletAddress.findAll(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#wallet-addresses-get-all) + +- #### findOne +```bash +const query = {}; +const walletId = ''; +const getWalletAddress = async (walletId) => { + return await coinforbarter.WalletAddress.findOne(walletId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#wallet-addresses-get-one) + +- #### makePrimary +```bash +const query = {}; +const walletAddressId = ''; +const makeWalletAddressPrimary = async (walletAddressId) => { + return await coinforbarter.WalletAddress.makePrimary(walletAddressId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#wallet-addresses-make-primary) + + +10. ### Wallet + +- #### findAll +```bash +const query = {}; +const getAllWallet = async () => { + return await coinforbarter.Wallet.findAll(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#wallets-find-all) + +- #### findOne +```bash +const query = {}; +const walletId = ''; +const getWallet = async (walletId) => { + return await coinforbarter.Wallet.findOne(walletId); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#wallets-find-one) + +- #### create +```bash +const params = {}; +const createWallet = async (params) => { + return await coinforbarter.Wallet.create(params); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#wallets-create) + +- #### delete +```bash +const query = {}; +const deleteWallet = async () => { + return await coinforbarter.Wallet.delete(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#wallets-delete) + + +11. ### Misc + +- #### getCountries +```bash +const query = {}; +const getCountriesMisc = async () => { + return await coinforbarter.Misc.getCountries(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#misc-get-countries) + +- #### getBalance +```bash +const query = {}; +const getBalanceMisc = async () => { + return await coinforbarter.Misc.getBalance(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#misc-get-wallet-balances) + +- #### getCurrencies +```bash +const query = {}; +const getCurrenciesMisc = async () => { + return await coinforbarter.Misc.getCurrencies(query); +} +``` +See list of [query parameters](https://developers.coinforbarter.com/api-reference/#misc-get-currencies) This SDK can be used closely with the official [API Reference](https://developers.coinforbarter.com/api-reference). All services and methods can be called this way diff --git a/package.json b/package.json index 372177f..82d5c76 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "axios": "^0.21.1", + "node": "^16.10.0", "websocket": "^1.0.34" }, "scripts": { @@ -103,4 +104,4 @@ "coverageDirectory": "../coverage", "testEnvironment": "node" } -} \ No newline at end of file +} diff --git a/src/services/index.ts b/src/services/index.ts index 671dfc8..4fb9f5d 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1 +1 @@ -export { CoinForBarterRequest } from './request'; +export { CoinForBarterRequest } from './Request';