Skip to content

Commit c2bdd65

Browse files
authored
Merge pull request #14 from thepeerstack/factor-new-endpoint
feat: factor in get businesses endpoint
2 parents b97fbd7 + ffcab8b commit c2bdd65

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ let user = thepeer.indexUser("Thor Odin", "thor", "[email protected]");
5656
- link_id (string)
5757
- amount (integer)
5858
- `returns`: object
59+
* getBusinesses
60+
- `accepts`:
61+
- channel (string)
62+
- `returns`: object
5963

6064
## Extra
6165

lib/Thepeer.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ const crypto = require('crypto')
33
const Helper = require('./utils/Helper')
44

55
/**
6-
* @class ThePeer
6+
* @class Thepeer
77
*/
8-
class ThePeer {
8+
class Thepeer {
99
/**
1010
*This is a constructor for creating a Peer Instance
1111
* @param {string} secretkey - Thepeer secret key
12-
* @returns { ThePeer } - An instance of thePeer
12+
* @returns { Thepeer } - An instance of Thepeer
1313
*/
1414
constructor (secretkey) {
1515
this.secretKey = secretkey
@@ -27,7 +27,7 @@ class ThePeer {
2727
* @param {object} payload - The payload to be verified.
2828
* @param {string} signature - The signature to compare with
2929
* @returns { Boolean } - True if same signature otherwise false
30-
* @memberof ThePeer
30+
* @memberof Thepeer
3131
*/
3232
validateSignature (payload, signature) {
3333
return signature === crypto.createHmac('sha1', this.secretKey).update(payload).digest('hex')
@@ -38,7 +38,7 @@ class ThePeer {
3838
* @param {string} identifier - The identifier of the user
3939
* @param {string} email - The email of the user
4040
* @returns {JSON} A JSON response containing the details of the user
41-
* @memberof ThePeer
41+
* @memberof Thepeer
4242
*/
4343
async indexUser (name, identifier, email) {
4444
try {
@@ -58,7 +58,7 @@ class ThePeer {
5858
* @param {string} reference - The reference returned when the user was indexed
5959
* @param {string} identifier - The identifier of the user
6060
* @returns {JSON} A JSON response containing the details of the user
61-
* @memberof ThePeer
61+
* @memberof Thepeer
6262
*/
6363
async updateUser (reference, identifier) {
6464
try {
@@ -75,7 +75,7 @@ class ThePeer {
7575
/**
7676
* @param {string} reference - The reference returned when the user was indexed
7777
* @returns {JSON} A JSON response containing the details of the user
78-
* @memberof ThePeer
78+
* @memberof Thepeer
7979
*/
8080
async deleteUser (reference) {
8181
try {
@@ -90,7 +90,7 @@ class ThePeer {
9090
/**
9191
* @param {string} reference - The reference returned when the user was indexed
9292
* @returns {JSON} A JSON response containing the details of the user
93-
* @memberof ThePeer
93+
* @memberof Thepeer
9494
*/
9595
async getUser (reference) {
9696
try {
@@ -106,7 +106,7 @@ class ThePeer {
106106
*
107107
* @param {string} linkid - The id of a user linked account
108108
* @returns {JSON} A JSON response containing the details of the user
109-
* @memberof ThePeer
109+
* @memberof Thepeer
110110
*/
111111
async getLink (linkid) {
112112
try {
@@ -124,7 +124,7 @@ class ThePeer {
124124
* @param {int} amount - amount in kobo
125125
* @param {string} remark - The reason for initiating a direct charge
126126
* @returns {JSON} A JSON response containing the details of the user
127-
* @memberof ThePeer
127+
* @memberof Thepeer
128128
*/
129129
async chargeLink (linkid, amount, remark) {
130130
try {
@@ -144,7 +144,7 @@ class ThePeer {
144144
* @param {*} reference - The direct charge reference sent via webhook
145145
* @param {string} event - Event type (success, insufficient_funds)
146146
* @returns {JSON} A JSON response containing the details of the user
147-
* @memberof ThePeer
147+
* @memberof Thepeer
148148
*/
149149
async authorizeCharge (reference, event) {
150150
try {
@@ -157,6 +157,21 @@ class ThePeer {
157157
Helper.processError(e)
158158
}
159159
}
160+
161+
/**
162+
* Get a list of all integrated businesses and their respective images
163+
* @param {string} channel - Channel type (send, checkout, direct_charge)
164+
* @returns {JSON} A JSON response containing the details of the businesses
165+
* @memberof Thepeer
166+
*/
167+
async getBusinesses (channel) {
168+
try {
169+
const response = await this.request.get(`/businesses?channel=${channel}`)
170+
return response.data
171+
} catch (e) {
172+
Helper.processError(e)
173+
}
174+
}
160175
}
161176

162-
module.exports = ThePeer
177+
module.exports = Thepeer

0 commit comments

Comments
 (0)