fapshi 1.0.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fapshi might be problematic. Click here for more details.

package/index.js DELETED
@@ -1,318 +0,0 @@
1
- const axios = require("axios");
2
- const baseUrl = "https://live.fapshi.com";
3
-
4
- module.exports = class FAPSHI {
5
- /**
6
- *
7
- * @param {string} user : user name get for an services
8
- * @param {string} key : api key access
9
- */
10
- constructor(user, key) {
11
- if (!user || !key) throw new Error("Mention your user name and api key ");
12
-
13
- this.apiuser = user;
14
- this.key = key;
15
-
16
- this.headers = {
17
- apiuser: this.apiuser,
18
- apikey: this.key,
19
- };
20
- }
21
-
22
- /**
23
- * This function returns an object with the link where a user is to be redirected in order to complete his payment
24
- *
25
- * Below is a parameter template. Just amount is required
26
- *
27
- * data = {
28
- * "amount": Integer ,
29
- * "email": String,
30
- * "userId": String,
31
- * "externalId": String,
32
- * "redirectUrl": String,
33
- * "message": String
34
- * }
35
- */
36
- initiatePay(data) {
37
- const self = this;
38
- return new Promise(async function (resolve) {
39
- try {
40
- console.log("headers :" + JSON.stringify(self.headers));
41
- if (!data?.amount) return resolve(error("amount required", 400));
42
- if (!Number.isInteger(data.amount))
43
- return resolve(error("amount must be of type integer", 400));
44
- if (data.amount < 100)
45
- return resolve(error("amount cannot be less than 100 XAF", 400));
46
-
47
- const config = {
48
- method: "post",
49
- url: baseUrl + "/initiate-pay",
50
- headers: self.headers,
51
- data: data,
52
- };
53
- const response = await axios(config);
54
- response.data.statusCode = response.status;
55
- resolve(response.data);
56
- } catch (e) {
57
- console.log(e);
58
- const statusCode = e.response ? e.response.status : 500;
59
- const message = e.response && e.response.data ? e.response.data.message : "Erreur inconnue";
60
- resolve(error(message, statusCode));
61
- }
62
- });
63
- }
64
-
65
- /**
66
- * This function directly initiates a payment request to a user's mobile device and
67
- * returns an object with a transId property that is used to get the status of the payment
68
- *
69
- * Below is a parameter template. amount and phone are required
70
- *
71
- * data = {
72
- * "amount": Integer ,
73
- * "phone": String ,
74
- * "medium": String,
75
- * "name": String,
76
- * "email": String,
77
- * "userId": String,
78
- * "externalId": String,
79
- * "message": String
80
- * }
81
- */
82
- directPay(data) {
83
- const self = this;
84
- return new Promise(async function (resolve) {
85
- try {
86
- if (!data?.amount) return resolve(error("amount required", 400));
87
- if (!Number.isInteger(data.amount))
88
- return resolve(error("amount must be of type integer", 400));
89
- if (data.amount < 100)
90
- return resolve(error("amount cannot be less than 100 XAF", 400));
91
- if (!data?.phone) return resolve(error("phone number required", 400));
92
- if (typeof data.phone !== "string")
93
- return resolve(error("phone must be of type string", 400));
94
- if (!/^6[\d]{8}$/.test(data.phone))
95
- return resolve(error("invalid phone number", 400));
96
-
97
- const config = {
98
- method: "post",
99
- url: baseUrl + "/direct-pay",
100
- headers: self.headers,
101
- data: data,
102
- };
103
- const response = await axios(config);
104
- response.data.statusCode = response.status;
105
- resolve(response.data);
106
- } catch (e) {
107
- console.log(e);
108
- const statusCode = e.response ? e.response.status : 500;
109
- const message = e.response && e.response.data ? e.response.data.message : "Erreur inconnue";
110
- resolve(error(message, statusCode));
111
- }
112
- });
113
- }
114
-
115
- /**
116
- * This function returns an object containing the details of the transaction associated with the Id passed as parameter
117
- */
118
- paymentStatus(transId) {
119
- const self = this;
120
- return new Promise(async function (resolve) {
121
- try {
122
- if (!transId || typeof transId !== "string")
123
- return resolve(error("invalid type, string expected", 400));
124
- if (!/^[a-zA-Z0-9]{8,10}$/.test(transId))
125
- return resolve(error("invalid transaction id", 400));
126
-
127
- const config = {
128
- method: "get",
129
- url: baseUrl + "/payment-status/" + transId,
130
- headers: self.headers,
131
- };
132
- const response = await axios(config);
133
- response.data.statusCode = response.status;
134
- resolve(response.data);
135
- } catch (e) {
136
- console.log(e);
137
- const statusCode = e.response ? e.response.status : 500;
138
- const message = e.response && e.response.data ? e.response.data.message : "Erreur inconnue";
139
- resolve(error(message, statusCode));
140
- }
141
- });
142
- }
143
-
144
- /**
145
- * This function expires the transaction associated with the Id passed as parameter and returns an object containing the details of the transaction
146
- */
147
- expirePay(transId) {
148
- const self = this;
149
- return new Promise(async function (resolve) {
150
- try {
151
- if (!transId || typeof transId !== "string")
152
- return resolve(error("invalid type, string expected", 400));
153
- if (!/^[a-zA-Z0-9]{8,10}$/.test(transId))
154
- return resolve(error("invalid transaction id", 400));
155
-
156
- const config = {
157
- method: "post",
158
- url: baseUrl + "/expire-pay",
159
- data: { transId },
160
- headers: self.headers,
161
- };
162
- const response = await axios(config);
163
- response.data.statusCode = response.status;
164
- resolve(response.data);
165
- } catch (e) {
166
- console.log(e);
167
- const statusCode = e.response ? e.response.status : 500;
168
- const message = e.response && e.response.data ? e.response.data.message : "Erreur inconnue";
169
- resolve(error(message, statusCode));
170
- }
171
- });
172
- }
173
-
174
- /**
175
- * This function returns an array of objects containing the transaction details of the user Id passed as parameter
176
- */
177
- userTrans(userId) {
178
- const self = this;
179
- return new Promise(async function (resolve) {
180
- try {
181
- if (!userId || typeof userId !== "string")
182
- return resolve(error("invalid type, string expected", 400));
183
- if (!/^[a-zA-Z0-9-_]{1,100}$/.test(userId))
184
- return resolve(error("invalid user id", 400));
185
-
186
- const config = {
187
- method: "get",
188
- url: baseUrl + "/transaction/" + userId,
189
- headers: self.headers,
190
- };
191
- const response = await axios(config);
192
- resolve(response.data);
193
- } catch (e) {
194
- console.log(e);
195
- const statusCode = e.response ? e.response.status : 500;
196
- const message = e.response && e.response.data ? e.response.data.message : "Erreur inconnue";
197
- resolve(error(message, statusCode));
198
- }
199
- });
200
- }
201
-
202
- /**
203
- * This function returns an object containing the balance of a service
204
- */
205
- balance() {
206
- const self = this;
207
- return new Promise(async function (resolve) {
208
- try {
209
- const config = {
210
- method: "get",
211
- url: baseUrl + "/balance",
212
- headers: self.headers,
213
- };
214
- const response = await axios(config);
215
- response.data.statusCode = response.status;
216
- resolve(response.data);
217
- } catch (e) {
218
- console.log(e);
219
- const statusCode = e.response ? e.response.status : 500;
220
- const message = e.response && e.response.data ? e.response.data.message : "Erreur inconnue";
221
- resolve(error(message, statusCode));
222
- }
223
- });
224
- }
225
-
226
- /**
227
- * This function performs a payout to the phone number specified in the data parameter and
228
- * returns an object with a transId property that is used to get the status of the payment
229
- *
230
- * Note: In the live environment, payouts must be enabled for this to work. Contact support if needed
231
- *
232
- * Below is a parameter template. amount and phone are required
233
- *
234
- * data = {
235
- * "amount": Integer ,
236
- * "phone": String ,
237
- * "medium": String,
238
- * "name": String,
239
- * "email": String,
240
- * "userId": String,
241
- * "externalId": String,
242
- * "message": String
243
- * }
244
- */
245
- payout(data) {
246
- const self = this;
247
- return new Promise(async function (resolve) {
248
- try {
249
- if (!data?.amount) return resolve(error("amount required", 400));
250
- if (!Number.isInteger(data.amount))
251
- return resolve(error("amount must be of type integer", 400));
252
- if (data.amount < 100)
253
- return resolve(error("amount cannot be less than 100 XAF", 400));
254
- if (!data?.phone) return resolve(error("phone number required", 400));
255
- if (typeof data.phone !== "string")
256
- return resolve(error("phone must be of type string", 400));
257
- if (!/^6[\d]{8}$/.test(data.phone))
258
- return resolve(error("invalid phone number", 400));
259
-
260
- const config = {
261
- method: "post",
262
- url: baseUrl + "/payout",
263
- headers: self.headers,
264
- data: data,
265
- };
266
- const response = await axios(config);
267
- response.data.statusCode = response.status;
268
- resolve(response.data);
269
- } catch (e) {
270
- console.log(e);
271
- const statusCode = e.response ? e.response.status : 500;
272
- const message = e.response && e.response.data ? e.response.data.message : "Erreur inconnue";
273
- resolve(error(message, statusCode));
274
- }
275
- });
276
- }
277
-
278
- /**
279
- * This function returns an array containing the transactions that satisfy
280
- * the criteria specified in the parameter passed to the function
281
- *
282
- * Below is a parameter template.
283
- *
284
- * params = {
285
- * "status": enum [created, successful, failed, expired],
286
- * "medium": mobile money or orange money,
287
- * "start": Date in format yyyy-mm-dd,
288
- * "end": Date in format yyyy-mm-dd,
289
- * "amt": >= 100,
290
- * "limit": range(1, 100) default is 10,
291
- * "sort": asc || desc
292
- * }
293
- */
294
- search(params = {}) {
295
- const self = this;
296
- return new Promise(async function (resolve) {
297
- try {
298
- const config = {
299
- method: "get",
300
- url: baseUrl + "/search",
301
- params: params,
302
- headers: self.headers,
303
- };
304
- const response = await axios(config);
305
- resolve(response.data);
306
- } catch (e) {
307
- console.log(e);
308
- const statusCode = e.response ? e.response.status : 500;
309
- const message = e.response && e.response.data ? e.response.data.message : "Erreur inconnue";
310
- resolve(error(message, statusCode));
311
- }
312
- });
313
- }
314
- };
315
-
316
- function error(message, statusCode) {
317
- return { message, statusCode };
318
- }