monime-package 1.0.4 → 1.0.6
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.
- package/README.md +811 -89
- package/dist/index.d.mts +783 -88
- package/dist/index.d.ts +783 -88
- package/dist/index.js +483 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +475 -67
- package/dist/index.mjs.map +1 -1
- package/package.json +39 -37
package/dist/index.js
CHANGED
|
@@ -35,11 +35,154 @@ __export(index_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
38
|
-
// src/modules/
|
|
38
|
+
// src/modules/checkout session/checkoutSession.ts
|
|
39
39
|
var import_axios = __toESM(require("axios"));
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
var URL = "https://api.monime.io/v1/checkout-sessions";
|
|
41
|
+
async function createCheckout(client, name, amount, quantity, successUrl, cancelUrl, description, financialAccountId, primaryColor, images) {
|
|
42
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
43
|
+
const body = {
|
|
44
|
+
name,
|
|
45
|
+
description,
|
|
46
|
+
cancelUrl,
|
|
47
|
+
successUrl,
|
|
48
|
+
callbackState: null,
|
|
49
|
+
reference: null,
|
|
50
|
+
financialAccountId,
|
|
51
|
+
lineItems: [
|
|
52
|
+
{
|
|
53
|
+
type: "custom",
|
|
54
|
+
name,
|
|
55
|
+
price: {
|
|
56
|
+
currency: "SLE",
|
|
57
|
+
value: amount
|
|
58
|
+
},
|
|
59
|
+
quantity,
|
|
60
|
+
reference: null,
|
|
61
|
+
description,
|
|
62
|
+
images
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
paymentOptions: {
|
|
66
|
+
card: {
|
|
67
|
+
disable: false
|
|
68
|
+
},
|
|
69
|
+
bank: {
|
|
70
|
+
disable: false,
|
|
71
|
+
enabledProviders: ["slb001", "slb004", "slb007"]
|
|
72
|
+
// disabledProviders: ["slb001"],
|
|
73
|
+
},
|
|
74
|
+
momo: {
|
|
75
|
+
disable: false,
|
|
76
|
+
enabledProviders: ["m17", "m18"]
|
|
77
|
+
// disabledProviders: ["m17"],
|
|
78
|
+
},
|
|
79
|
+
wallet: {
|
|
80
|
+
disable: false,
|
|
81
|
+
enabledProviders: ["dw001"]
|
|
82
|
+
// disabledProviders: ["dw001"],
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
brandingOptions: {
|
|
86
|
+
primaryColor
|
|
87
|
+
},
|
|
88
|
+
metadata: {}
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
const res = await import_axios.default.patch(URL, body, {
|
|
92
|
+
headers: {
|
|
93
|
+
"Monime-Space-Id": monimeSpaceId,
|
|
94
|
+
Authorization: `Bearer ${accessToken}`
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const data = res.data;
|
|
98
|
+
return { success: true, data };
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (import_axios.default.isAxiosError(error)) {
|
|
101
|
+
return { error, success: false };
|
|
102
|
+
}
|
|
103
|
+
return { error: new Error("unknown error"), success: false };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function getAllCheckout(client) {
|
|
107
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
108
|
+
try {
|
|
109
|
+
const res = await import_axios.default.get(URL, {
|
|
110
|
+
headers: {
|
|
111
|
+
"Monime-Space-Id": monimeSpaceId,
|
|
112
|
+
Authorization: `Bearer ${accessToken}`
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const data = res.data;
|
|
116
|
+
return { success: true, data };
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (import_axios.default.isAxiosError(error)) {
|
|
119
|
+
return { error, success: false };
|
|
120
|
+
}
|
|
121
|
+
return { error: new Error("unknown error"), success: false };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function getOnecheckout(client, checkoutId) {
|
|
125
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
126
|
+
try {
|
|
127
|
+
const res = await import_axios.default.get(`${URL}/${checkoutId}`, {
|
|
128
|
+
headers: {
|
|
129
|
+
"Monime-Space-Id": monimeSpaceId,
|
|
130
|
+
Authorization: `Bearer ${accessToken}`
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const data = res.data;
|
|
134
|
+
return { success: true, data };
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (import_axios.default.isAxiosError(error)) {
|
|
137
|
+
return { error, success: false };
|
|
138
|
+
}
|
|
139
|
+
return { error: new Error("unknown error"), success: false };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function deleteCheckout(client, checkoutId) {
|
|
143
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
144
|
+
try {
|
|
145
|
+
await import_axios.default.delete(`${URL}/${checkoutId}`, {
|
|
146
|
+
headers: {
|
|
147
|
+
"Monime-Space-Id": monimeSpaceId,
|
|
148
|
+
Authorization: `Bearer ${accessToken}`
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return { success: true };
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (import_axios.default.isAxiosError(error)) {
|
|
154
|
+
return { error, success: false };
|
|
155
|
+
}
|
|
156
|
+
return { error: new Error("unknown error"), success: false };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/modules/checkout session/index.ts
|
|
161
|
+
function CheckoutSessionAPI(client) {
|
|
162
|
+
return {
|
|
163
|
+
create: (name, amount, quantity, successUrl, cancelUrl, description, financialAccountId, primaryColor, images) => createCheckout(
|
|
164
|
+
client,
|
|
165
|
+
name,
|
|
166
|
+
amount,
|
|
167
|
+
quantity,
|
|
168
|
+
successUrl,
|
|
169
|
+
cancelUrl,
|
|
170
|
+
description,
|
|
171
|
+
financialAccountId,
|
|
172
|
+
primaryColor,
|
|
173
|
+
images
|
|
174
|
+
),
|
|
175
|
+
get: () => getAllCheckout(client),
|
|
176
|
+
getOne: (checkoutId) => getOnecheckout(client, checkoutId),
|
|
177
|
+
delete: (checkoutId) => deleteCheckout(client, checkoutId)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/modules/financialAccount/financialAccount.ts
|
|
182
|
+
var import_node_crypto = require("crypto");
|
|
183
|
+
var import_axios2 = __toESM(require("axios"));
|
|
184
|
+
var URL2 = "https://api.monime.io/v1/financial-accounts";
|
|
185
|
+
var value = (0, import_node_crypto.randomBytes)(20).toString("hex");
|
|
43
186
|
async function createFinancialAccount(accountName, client) {
|
|
44
187
|
if (accountName.trim() === "") {
|
|
45
188
|
return { success: false, error: new Error("accountName is required") };
|
|
@@ -52,7 +195,7 @@ async function createFinancialAccount(accountName, client) {
|
|
|
52
195
|
};
|
|
53
196
|
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
54
197
|
try {
|
|
55
|
-
const res = await
|
|
198
|
+
const res = await import_axios2.default.post(URL2, body, {
|
|
56
199
|
headers: {
|
|
57
200
|
"Idempotency-Key": `${value}`,
|
|
58
201
|
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
@@ -63,7 +206,7 @@ async function createFinancialAccount(accountName, client) {
|
|
|
63
206
|
const data = res.data;
|
|
64
207
|
return { success: true, data };
|
|
65
208
|
} catch (error) {
|
|
66
|
-
if (
|
|
209
|
+
if (import_axios2.default.isAxiosError(error)) {
|
|
67
210
|
return { error, success: false };
|
|
68
211
|
}
|
|
69
212
|
return { error: new Error("unknown error"), success: false };
|
|
@@ -71,11 +214,14 @@ async function createFinancialAccount(accountName, client) {
|
|
|
71
214
|
}
|
|
72
215
|
async function getFinancialAccount(financialAccountId, client) {
|
|
73
216
|
if (financialAccountId.trim() === "") {
|
|
74
|
-
return {
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
error: new Error("financialAccountId is required")
|
|
220
|
+
};
|
|
75
221
|
}
|
|
76
222
|
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
77
223
|
try {
|
|
78
|
-
const res = await
|
|
224
|
+
const res = await import_axios2.default.get(`${URL2}/${financialAccountId}`, {
|
|
79
225
|
headers: {
|
|
80
226
|
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
81
227
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -84,29 +230,116 @@ async function getFinancialAccount(financialAccountId, client) {
|
|
|
84
230
|
const data = res.data;
|
|
85
231
|
return { success: true, data };
|
|
86
232
|
} catch (error) {
|
|
87
|
-
if (
|
|
233
|
+
if (import_axios2.default.isAxiosError(error)) {
|
|
234
|
+
return { error, success: false };
|
|
235
|
+
}
|
|
236
|
+
return { error: new Error("unknown error"), success: false };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function getAllFinancialAccount(client) {
|
|
240
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
241
|
+
try {
|
|
242
|
+
const res = await import_axios2.default.get(URL2, {
|
|
243
|
+
headers: {
|
|
244
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
245
|
+
Authorization: `Bearer ${accessToken}`
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
const data = res.data;
|
|
249
|
+
return { success: true, data };
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (import_axios2.default.isAxiosError(error)) {
|
|
252
|
+
return { error, success: false };
|
|
253
|
+
}
|
|
254
|
+
return { error: new Error("unknown error"), success: false };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// src/modules/financialAccount/index.ts
|
|
259
|
+
function FinancialAccountAPI(client) {
|
|
260
|
+
return {
|
|
261
|
+
create: (name) => createFinancialAccount(name, client),
|
|
262
|
+
get: (financialAccountId) => getFinancialAccount(financialAccountId, client),
|
|
263
|
+
getAll: () => getAllFinancialAccount(client)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// src/modules/financialTransaction/financialTransaction.ts
|
|
268
|
+
var import_axios3 = __toESM(require("axios"));
|
|
269
|
+
var URL3 = "https://api.monime.io/v1/financial-transactions";
|
|
270
|
+
async function getAllTransaction(client) {
|
|
271
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
272
|
+
try {
|
|
273
|
+
const res = await import_axios3.default.get(URL3, {
|
|
274
|
+
headers: {
|
|
275
|
+
Authorization: `Bearer ${accessToken}`,
|
|
276
|
+
"Monime-Space-Id": `${monimeSpaceId}`
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
const data = res.data;
|
|
280
|
+
return { success: true, data };
|
|
281
|
+
} catch (error) {
|
|
282
|
+
if (import_axios3.default.isAxiosError(error)) {
|
|
283
|
+
return { error, success: false };
|
|
284
|
+
}
|
|
285
|
+
return { error: new Error("unknown error"), success: false };
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async function getTransaction(client, transactionId) {
|
|
289
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
290
|
+
if (transactionId.trim() === "") {
|
|
291
|
+
return {
|
|
292
|
+
error: new Error("transactionId must not be empty"),
|
|
293
|
+
success: false
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
const res = await import_axios3.default.get(`${URL3}/${transactionId}`, {
|
|
298
|
+
headers: {
|
|
299
|
+
Authorization: `Bearer ${accessToken}`,
|
|
300
|
+
"Monime-Space-Id": `${monimeSpaceId}`
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
const data = res.data;
|
|
304
|
+
return { success: true, data };
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (import_axios3.default.isAxiosError(error)) {
|
|
88
307
|
return { error, success: false };
|
|
89
308
|
}
|
|
90
309
|
return { error: new Error("unknown error"), success: false };
|
|
91
310
|
}
|
|
92
311
|
}
|
|
93
312
|
|
|
313
|
+
// src/modules/financialTransaction/index.ts
|
|
314
|
+
function FinancialTransactionAPI(client) {
|
|
315
|
+
return {
|
|
316
|
+
get: (transactionId) => getTransaction(client, transactionId),
|
|
317
|
+
getAll: () => getAllTransaction(client)
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
94
321
|
// src/modules/internalTransfer/internalTransfer.ts
|
|
95
|
-
var
|
|
96
|
-
var
|
|
97
|
-
var
|
|
98
|
-
var value2 = (0,
|
|
99
|
-
async function createInternalTransfer(sourceAccount, destinationAccount, client,
|
|
100
|
-
if (
|
|
101
|
-
return {
|
|
322
|
+
var import_node_crypto2 = require("crypto");
|
|
323
|
+
var import_axios4 = __toESM(require("axios"));
|
|
324
|
+
var URL4 = "https://api.monime.io/v1/internal-transfers";
|
|
325
|
+
var value2 = (0, import_node_crypto2.randomBytes)(20).toString("hex");
|
|
326
|
+
async function createInternalTransfer(sourceAccount, destinationAccount, client, amount) {
|
|
327
|
+
if (amount <= 0) {
|
|
328
|
+
return {
|
|
329
|
+
success: false,
|
|
330
|
+
error: new Error("amount must be larger that zero")
|
|
331
|
+
};
|
|
102
332
|
}
|
|
103
333
|
if (sourceAccount.trim() === "" || destinationAccount.trim() === "") {
|
|
104
|
-
return {
|
|
334
|
+
return {
|
|
335
|
+
success: false,
|
|
336
|
+
error: new Error("sourceAccount or destinationAccount is missing")
|
|
337
|
+
};
|
|
105
338
|
}
|
|
106
339
|
const body = {
|
|
107
340
|
amount: {
|
|
108
341
|
currency: "SLE",
|
|
109
|
-
value:
|
|
342
|
+
value: amount
|
|
110
343
|
},
|
|
111
344
|
sourceFinancialAccount: {
|
|
112
345
|
id: sourceAccount
|
|
@@ -118,9 +351,9 @@ async function createInternalTransfer(sourceAccount, destinationAccount, client,
|
|
|
118
351
|
};
|
|
119
352
|
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
120
353
|
try {
|
|
121
|
-
const res = await
|
|
354
|
+
const res = await import_axios4.default.post(URL4, body, {
|
|
122
355
|
headers: {
|
|
123
|
-
"Idempotency-Key": `${
|
|
356
|
+
"Idempotency-Key": `${value2}`,
|
|
124
357
|
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
125
358
|
Authorization: `Bearer ${accessToken}`,
|
|
126
359
|
"Content-Type": "application/json"
|
|
@@ -129,28 +362,102 @@ async function createInternalTransfer(sourceAccount, destinationAccount, client,
|
|
|
129
362
|
const data = res.data;
|
|
130
363
|
return { success: true, data };
|
|
131
364
|
} catch (error) {
|
|
132
|
-
if (
|
|
365
|
+
if (import_axios4.default.isAxiosError(error)) {
|
|
133
366
|
return { error, success: false };
|
|
134
367
|
}
|
|
135
368
|
return { error: new Error("unkknown error"), success: false };
|
|
136
369
|
}
|
|
137
370
|
}
|
|
371
|
+
async function getAllInternalTransfers(client) {
|
|
372
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
373
|
+
try {
|
|
374
|
+
const res = await import_axios4.default.get(URL4, {
|
|
375
|
+
headers: {
|
|
376
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
377
|
+
Authorization: `Bearer ${accessToken}`
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
const data = res.data;
|
|
381
|
+
return { success: true, data };
|
|
382
|
+
} catch (error) {
|
|
383
|
+
if (import_axios4.default.isAxiosError(error)) {
|
|
384
|
+
return { success: false, error };
|
|
385
|
+
}
|
|
386
|
+
return { error: new Error("unkknown error"), success: false };
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
async function getInternalTransfer(client, internalTransferId) {
|
|
390
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
391
|
+
try {
|
|
392
|
+
const res = await import_axios4.default.get(`${URL4}/${internalTransferId}`, {
|
|
393
|
+
headers: {
|
|
394
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
395
|
+
Authorization: `Bearer ${accessToken}`
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
const data = res.data;
|
|
399
|
+
return { success: true, data };
|
|
400
|
+
} catch (error) {
|
|
401
|
+
if (import_axios4.default.isAxiosError(error)) {
|
|
402
|
+
return { success: false, error };
|
|
403
|
+
}
|
|
404
|
+
return { error: new Error("unkknown error"), success: false };
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async function deleteInternalTransfer(client, internalTransferId) {
|
|
408
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
409
|
+
try {
|
|
410
|
+
await import_axios4.default.delete(`${URL4}/${internalTransferId}`, {
|
|
411
|
+
headers: {
|
|
412
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
413
|
+
Authorization: `Bearer ${accessToken}`
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
return { success: true };
|
|
417
|
+
} catch (error) {
|
|
418
|
+
if (import_axios4.default.isAxiosError(error)) {
|
|
419
|
+
return { success: false, error };
|
|
420
|
+
}
|
|
421
|
+
return { success: false, error: new Error("unknown error") };
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// src/modules/internalTransfer/index.ts
|
|
426
|
+
function InternalTransferAPI(client) {
|
|
427
|
+
return {
|
|
428
|
+
create: (sourceAccount, destinationAccount, amount) => createInternalTransfer(
|
|
429
|
+
sourceAccount,
|
|
430
|
+
destinationAccount,
|
|
431
|
+
client,
|
|
432
|
+
amount
|
|
433
|
+
),
|
|
434
|
+
get: (internalTransferId) => getInternalTransfer(client, internalTransferId),
|
|
435
|
+
getAll: () => getAllInternalTransfers(client),
|
|
436
|
+
delete: (internalTransferId) => deleteInternalTransfer(client, internalTransferId)
|
|
437
|
+
};
|
|
438
|
+
}
|
|
138
439
|
|
|
139
440
|
// src/modules/paymentCode/paymentCode.ts
|
|
140
|
-
var
|
|
141
|
-
var
|
|
142
|
-
var value3 = (0,
|
|
143
|
-
var
|
|
441
|
+
var import_node_crypto3 = require("crypto");
|
|
442
|
+
var import_axios5 = __toESM(require("axios"));
|
|
443
|
+
var value3 = (0, import_node_crypto3.randomBytes)(20).toString("hex");
|
|
444
|
+
var URL5 = "https://api.monime.io/v1/payment-codes";
|
|
144
445
|
async function createPaymentCode(paymentName, amount, financialAccountId, name, phoneNumber, client) {
|
|
145
446
|
let financialAccount = null;
|
|
146
447
|
if (financialAccountId !== "") {
|
|
147
448
|
financialAccount = financialAccountId;
|
|
148
449
|
}
|
|
149
450
|
if (paymentName.trim() === "" || name.trim() === "" || phoneNumber.trim() === "") {
|
|
150
|
-
return {
|
|
451
|
+
return {
|
|
452
|
+
success: false,
|
|
453
|
+
error: new Error("paymentName, name, or phoneNumber is missing")
|
|
454
|
+
};
|
|
151
455
|
}
|
|
152
456
|
if (amount <= 0) {
|
|
153
|
-
return {
|
|
457
|
+
return {
|
|
458
|
+
success: false,
|
|
459
|
+
error: new Error("amonut number be greater than zero")
|
|
460
|
+
};
|
|
154
461
|
}
|
|
155
462
|
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
156
463
|
const bodyData = {
|
|
@@ -179,7 +486,7 @@ async function createPaymentCode(paymentName, amount, financialAccountId, name,
|
|
|
179
486
|
metadata: {}
|
|
180
487
|
};
|
|
181
488
|
try {
|
|
182
|
-
const res = await
|
|
489
|
+
const res = await import_axios5.default.post(URL5, bodyData, {
|
|
183
490
|
headers: {
|
|
184
491
|
"Idempotency-Key": `${value3}`,
|
|
185
492
|
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
@@ -190,7 +497,7 @@ async function createPaymentCode(paymentName, amount, financialAccountId, name,
|
|
|
190
497
|
const data = res.data;
|
|
191
498
|
return { data, success: true };
|
|
192
499
|
} catch (error) {
|
|
193
|
-
if (
|
|
500
|
+
if (import_axios5.default.isAxiosError(error)) {
|
|
194
501
|
return { error: error.response?.data, success: false };
|
|
195
502
|
}
|
|
196
503
|
return { error: new Error("unknown error"), success: false };
|
|
@@ -202,7 +509,7 @@ async function deletePaymentCode(paymentCodeId, client) {
|
|
|
202
509
|
return { success: false, error: new Error("paymentCodeId is required") };
|
|
203
510
|
}
|
|
204
511
|
try {
|
|
205
|
-
|
|
512
|
+
await import_axios5.default.delete(`${URL5}/${paymentCodeId}`, {
|
|
206
513
|
headers: {
|
|
207
514
|
"Idempotency-Key": `${value3}`,
|
|
208
515
|
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
@@ -210,38 +517,85 @@ async function deletePaymentCode(paymentCodeId, client) {
|
|
|
210
517
|
"Content-Type": "application/json"
|
|
211
518
|
}
|
|
212
519
|
});
|
|
520
|
+
return { success: true };
|
|
521
|
+
} catch (error) {
|
|
522
|
+
if (import_axios5.default.isAxiosError(error)) {
|
|
523
|
+
return { error, success: false };
|
|
524
|
+
}
|
|
525
|
+
return { error: new Error("unknown error"), success: false };
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
async function getAllPaymentCode(client) {
|
|
529
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
530
|
+
try {
|
|
531
|
+
const res = await import_axios5.default.get(URL5, {
|
|
532
|
+
headers: {
|
|
533
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
534
|
+
Authorization: `Bearer ${accessToken}`
|
|
535
|
+
}
|
|
536
|
+
});
|
|
213
537
|
const data = res.data;
|
|
214
|
-
|
|
215
|
-
|
|
538
|
+
return { success: true, data };
|
|
539
|
+
} catch (error) {
|
|
540
|
+
if (import_axios5.default.isAxiosError(error)) {
|
|
541
|
+
return { error, success: false };
|
|
216
542
|
}
|
|
217
|
-
return { success:
|
|
543
|
+
return { error: new Error("unknown error"), success: false };
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
async function getPaymentCode(paymentCodeId, client) {
|
|
547
|
+
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
548
|
+
try {
|
|
549
|
+
const res = await import_axios5.default.get(`${URL5}/${paymentCodeId}`, {
|
|
550
|
+
headers: {
|
|
551
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
552
|
+
Authorization: `Bearer ${accessToken}`
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
const data = res.data;
|
|
556
|
+
return { success: true, data };
|
|
218
557
|
} catch (error) {
|
|
219
|
-
if (
|
|
558
|
+
if (import_axios5.default.isAxiosError(error)) {
|
|
220
559
|
return { error, success: false };
|
|
221
560
|
}
|
|
222
561
|
return { error: new Error("unknown error"), success: false };
|
|
223
562
|
}
|
|
224
563
|
}
|
|
225
564
|
|
|
565
|
+
// src/modules/paymentCode/index.ts
|
|
566
|
+
function PaymentCodeAPI(client) {
|
|
567
|
+
return {
|
|
568
|
+
create: (paymentName, amount, financialAccount, username, phoneNumber) => createPaymentCode(
|
|
569
|
+
paymentName,
|
|
570
|
+
amount,
|
|
571
|
+
financialAccount,
|
|
572
|
+
username,
|
|
573
|
+
phoneNumber,
|
|
574
|
+
client
|
|
575
|
+
),
|
|
576
|
+
delete: (paymentCodeId) => deletePaymentCode(paymentCodeId, client),
|
|
577
|
+
getAll: () => getAllPaymentCode(client),
|
|
578
|
+
get: (paymentCodeId) => getPaymentCode(paymentCodeId, client)
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
226
582
|
// src/modules/payout/payout.ts
|
|
227
|
-
var
|
|
228
|
-
var
|
|
229
|
-
var
|
|
230
|
-
var value4 = (0,
|
|
231
|
-
async function
|
|
232
|
-
if (
|
|
233
|
-
return {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
for (let value5 of africell) {
|
|
238
|
-
if (phoneNumber.startsWith(value5)) {
|
|
239
|
-
provider = "m18";
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
583
|
+
var import_node_crypto4 = require("crypto");
|
|
584
|
+
var import_axios6 = __toESM(require("axios"));
|
|
585
|
+
var URL6 = "https://api.monime.io/v1/payouts";
|
|
586
|
+
var value4 = (0, import_node_crypto4.randomBytes)(20).toString("hex");
|
|
587
|
+
async function createPayout(amount, sourceAccount, destination, client) {
|
|
588
|
+
if (sourceAccount.trim() === "") {
|
|
589
|
+
return {
|
|
590
|
+
success: false,
|
|
591
|
+
error: new Error("sourceAccount cannot be empty")
|
|
592
|
+
};
|
|
242
593
|
}
|
|
243
594
|
if (amount <= 0) {
|
|
244
|
-
return {
|
|
595
|
+
return {
|
|
596
|
+
error: new Error("amount must be greater than 0"),
|
|
597
|
+
success: false
|
|
598
|
+
};
|
|
245
599
|
}
|
|
246
600
|
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
247
601
|
const body = {
|
|
@@ -252,15 +606,11 @@ async function CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, clien
|
|
|
252
606
|
source: {
|
|
253
607
|
financialAccountId: sourceAccount
|
|
254
608
|
},
|
|
255
|
-
destination
|
|
256
|
-
type: "momo",
|
|
257
|
-
provider,
|
|
258
|
-
phoneNumber
|
|
259
|
-
},
|
|
609
|
+
destination,
|
|
260
610
|
metadata: {}
|
|
261
611
|
};
|
|
262
612
|
try {
|
|
263
|
-
const res = await
|
|
613
|
+
const res = await import_axios6.default.post(URL6, body, {
|
|
264
614
|
headers: {
|
|
265
615
|
"Idempotency-Key": `${value4}`,
|
|
266
616
|
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
@@ -271,37 +621,95 @@ async function CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, clien
|
|
|
271
621
|
const data = res.data;
|
|
272
622
|
return { success: true, data };
|
|
273
623
|
} catch (error) {
|
|
274
|
-
if (
|
|
624
|
+
if (import_axios6.default.isAxiosError(error)) {
|
|
275
625
|
return { success: false, error };
|
|
276
626
|
}
|
|
277
627
|
return { success: false, error: new Error("unknown error") };
|
|
278
628
|
}
|
|
279
629
|
}
|
|
630
|
+
async function getAllPayout(client) {
|
|
631
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
632
|
+
try {
|
|
633
|
+
const res = await import_axios6.default.get(URL6, {
|
|
634
|
+
headers: {
|
|
635
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
636
|
+
Authorization: `Bearer ${accessToken}`
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
const data = res.data;
|
|
640
|
+
return { success: true, data };
|
|
641
|
+
} catch (error) {
|
|
642
|
+
if (import_axios6.default.isAxiosError(error)) {
|
|
643
|
+
return { success: false, error };
|
|
644
|
+
}
|
|
645
|
+
return { success: false, error: new Error("unknown error") };
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
async function getPayout(payoutId, client) {
|
|
649
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
650
|
+
try {
|
|
651
|
+
const res = await import_axios6.default.get(`${URL6}/${payoutId}`, {
|
|
652
|
+
headers: {
|
|
653
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
654
|
+
Authorization: `Bearer ${accessToken}`
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
const data = res.data;
|
|
658
|
+
return { success: true, data };
|
|
659
|
+
} catch (error) {
|
|
660
|
+
if (import_axios6.default.isAxiosError(error)) {
|
|
661
|
+
return { success: false, error };
|
|
662
|
+
}
|
|
663
|
+
return { success: false, error: new Error("unknown error") };
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
async function deletePayout(payoutId, client) {
|
|
667
|
+
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
668
|
+
try {
|
|
669
|
+
await import_axios6.default.delete(`${URL6}/${payoutId}`, {
|
|
670
|
+
headers: {
|
|
671
|
+
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
672
|
+
Authorization: `Bearer ${accessToken}`
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
return { success: true };
|
|
676
|
+
} catch (error) {
|
|
677
|
+
if (import_axios6.default.isAxiosError(error)) {
|
|
678
|
+
return { success: false, error };
|
|
679
|
+
}
|
|
680
|
+
return { success: false, error: new Error("unknown error") };
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// src/modules/payout/index.ts
|
|
685
|
+
function PayoutAPI(client) {
|
|
686
|
+
return {
|
|
687
|
+
create: (amount, destination, sourceAccount) => createPayout(amount, sourceAccount, destination, client),
|
|
688
|
+
get: () => getAllPayout(client),
|
|
689
|
+
getOne: (payoutId) => getPayout(payoutId, client),
|
|
690
|
+
delete: (payoutId) => deletePayout(payoutId, client)
|
|
691
|
+
};
|
|
692
|
+
}
|
|
280
693
|
|
|
281
694
|
// src/client.ts
|
|
282
695
|
var MonimeClient = class {
|
|
283
696
|
monimeSpaceId;
|
|
284
697
|
accessToken;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
//method for payment code
|
|
292
|
-
createPaymentCode;
|
|
293
|
-
deletePaymentCode;
|
|
294
|
-
//method for payout
|
|
295
|
-
createPayout;
|
|
698
|
+
financialAccount;
|
|
699
|
+
internalTransfer;
|
|
700
|
+
paymentCode;
|
|
701
|
+
payout;
|
|
702
|
+
financialTransaction;
|
|
703
|
+
checkoutSession;
|
|
296
704
|
constructor(options) {
|
|
297
705
|
this.accessToken = options.accessToken;
|
|
298
|
-
this.monimeSpaceId = options.
|
|
299
|
-
this.
|
|
300
|
-
this.
|
|
301
|
-
this.
|
|
302
|
-
this.
|
|
303
|
-
this.
|
|
304
|
-
this.
|
|
706
|
+
this.monimeSpaceId = options.monimeSpaceId;
|
|
707
|
+
this.financialAccount = FinancialAccountAPI(this);
|
|
708
|
+
this.internalTransfer = InternalTransferAPI(this);
|
|
709
|
+
this.paymentCode = PaymentCodeAPI(this);
|
|
710
|
+
this.payout = PayoutAPI(this);
|
|
711
|
+
this.financialTransaction = FinancialTransactionAPI(this);
|
|
712
|
+
this.checkoutSession = CheckoutSessionAPI(this);
|
|
305
713
|
}
|
|
306
714
|
/** @internal */
|
|
307
715
|
_getConfig() {
|