monime-package 1.0.7 → 1.0.9
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 +69 -0
- package/dist/index.d.mts +240 -1
- package/dist/index.d.ts +240 -1
- package/dist/index.js +1 -732
- package/dist/index.mjs +1 -694
- package/package.json +1 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,732 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
MonimeClient: () => MonimeClient,
|
|
34
|
-
createClient: () => createClient
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
37
|
-
|
|
38
|
-
// src/modules/checkout session/checkoutSession.ts
|
|
39
|
-
var import_axios = __toESM(require("axios"));
|
|
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.post(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");
|
|
186
|
-
async function createFinancialAccount(accountName, currency, client) {
|
|
187
|
-
if (accountName.trim() === "") {
|
|
188
|
-
return { success: false, error: new Error("accountName is required") };
|
|
189
|
-
}
|
|
190
|
-
const body = {
|
|
191
|
-
name: accountName,
|
|
192
|
-
currency,
|
|
193
|
-
description: "",
|
|
194
|
-
metadata: {}
|
|
195
|
-
};
|
|
196
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
197
|
-
try {
|
|
198
|
-
const res = await import_axios2.default.post(URL2, body, {
|
|
199
|
-
headers: {
|
|
200
|
-
"Idempotency-Key": `${value}`,
|
|
201
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
202
|
-
Authorization: `Bearer ${accessToken}`,
|
|
203
|
-
"Content-Type": "application/json"
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
const data = res.data;
|
|
207
|
-
return { success: true, data };
|
|
208
|
-
} catch (error) {
|
|
209
|
-
if (import_axios2.default.isAxiosError(error)) {
|
|
210
|
-
return { error, success: false };
|
|
211
|
-
}
|
|
212
|
-
return { error: new Error("unknown error"), success: false };
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
async function getFinancialAccount(financialAccountId, client) {
|
|
216
|
-
if (financialAccountId.trim() === "") {
|
|
217
|
-
return {
|
|
218
|
-
success: false,
|
|
219
|
-
error: new Error("financialAccountId is required")
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
223
|
-
try {
|
|
224
|
-
const res = await import_axios2.default.get(`${URL2}/${financialAccountId}`, {
|
|
225
|
-
headers: {
|
|
226
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
227
|
-
Authorization: `Bearer ${accessToken}`
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
const data = res.data;
|
|
231
|
-
return { success: true, data };
|
|
232
|
-
} catch (error) {
|
|
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, currency) => createFinancialAccount(name, currency, 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)) {
|
|
307
|
-
return { error, success: false };
|
|
308
|
-
}
|
|
309
|
-
return { error: new Error("unknown error"), success: false };
|
|
310
|
-
}
|
|
311
|
-
}
|
|
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
|
-
|
|
321
|
-
// src/modules/internalTransfer/internalTransfer.ts
|
|
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
|
-
};
|
|
332
|
-
}
|
|
333
|
-
if (sourceAccount.trim() === "" || destinationAccount.trim() === "") {
|
|
334
|
-
return {
|
|
335
|
-
success: false,
|
|
336
|
-
error: new Error("sourceAccount or destinationAccount is missing")
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
const body = {
|
|
340
|
-
amount: {
|
|
341
|
-
currency: "SLE",
|
|
342
|
-
value: amount
|
|
343
|
-
},
|
|
344
|
-
sourceFinancialAccount: {
|
|
345
|
-
id: sourceAccount
|
|
346
|
-
},
|
|
347
|
-
destinationFinancialAccount: {
|
|
348
|
-
id: destinationAccount
|
|
349
|
-
},
|
|
350
|
-
metadata: {}
|
|
351
|
-
};
|
|
352
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
353
|
-
try {
|
|
354
|
-
const res = await import_axios4.default.post(URL4, body, {
|
|
355
|
-
headers: {
|
|
356
|
-
"Idempotency-Key": `${value2}`,
|
|
357
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
358
|
-
Authorization: `Bearer ${accessToken}`,
|
|
359
|
-
"Content-Type": "application/json"
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
const data = res.data;
|
|
363
|
-
return { success: true, data };
|
|
364
|
-
} catch (error) {
|
|
365
|
-
if (import_axios4.default.isAxiosError(error)) {
|
|
366
|
-
return { error, success: false };
|
|
367
|
-
}
|
|
368
|
-
return { error: new Error("unkknown error"), success: false };
|
|
369
|
-
}
|
|
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
|
-
}
|
|
439
|
-
|
|
440
|
-
// src/modules/paymentCode/paymentCode.ts
|
|
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";
|
|
445
|
-
async function createPaymentCode(paymentName, amount, financialAccountId, name, phoneNumber, client) {
|
|
446
|
-
let financialAccount = null;
|
|
447
|
-
if (financialAccountId !== "") {
|
|
448
|
-
financialAccount = financialAccountId;
|
|
449
|
-
}
|
|
450
|
-
if (paymentName.trim() === "" || name.trim() === "" || phoneNumber.trim() === "") {
|
|
451
|
-
return {
|
|
452
|
-
success: false,
|
|
453
|
-
error: new Error("paymentName, name, or phoneNumber is missing")
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
if (amount <= 0) {
|
|
457
|
-
return {
|
|
458
|
-
success: false,
|
|
459
|
-
error: new Error("amonut number be greater than zero")
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
463
|
-
const bodyData = {
|
|
464
|
-
name: `${paymentName}`,
|
|
465
|
-
mode: "recurrent",
|
|
466
|
-
enable: true,
|
|
467
|
-
amount: {
|
|
468
|
-
currency: "SLE",
|
|
469
|
-
value: amount * 100
|
|
470
|
-
},
|
|
471
|
-
duration: "1h30m",
|
|
472
|
-
customer: {
|
|
473
|
-
name: `${name}`
|
|
474
|
-
},
|
|
475
|
-
reference: "",
|
|
476
|
-
authorizedPhoneNumber: phoneNumber,
|
|
477
|
-
// authorizedProviders: ["m17", "m18"],
|
|
478
|
-
recurrentPaymentTarget: {
|
|
479
|
-
expectedPaymentCount: 1,
|
|
480
|
-
expectedPaymentTotal: {
|
|
481
|
-
currency: "SLE",
|
|
482
|
-
value: amount * 100
|
|
483
|
-
}
|
|
484
|
-
},
|
|
485
|
-
financialAccountId: financialAccount,
|
|
486
|
-
metadata: {}
|
|
487
|
-
};
|
|
488
|
-
try {
|
|
489
|
-
const res = await import_axios5.default.post(URL5, bodyData, {
|
|
490
|
-
headers: {
|
|
491
|
-
"Idempotency-Key": `${value3}`,
|
|
492
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
493
|
-
Authorization: `Bearer ${accessToken}`,
|
|
494
|
-
"Content-Type": "application/json"
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
const data = res.data;
|
|
498
|
-
return { data, success: true };
|
|
499
|
-
} catch (error) {
|
|
500
|
-
if (import_axios5.default.isAxiosError(error)) {
|
|
501
|
-
return { error: error.response?.data, success: false };
|
|
502
|
-
}
|
|
503
|
-
return { error: new Error("unknown error"), success: false };
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
async function deletePaymentCode(paymentCodeId, client) {
|
|
507
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
508
|
-
if (paymentCodeId.trim() === "") {
|
|
509
|
-
return { success: false, error: new Error("paymentCodeId is required") };
|
|
510
|
-
}
|
|
511
|
-
try {
|
|
512
|
-
await import_axios5.default.delete(`${URL5}/${paymentCodeId}`, {
|
|
513
|
-
headers: {
|
|
514
|
-
"Idempotency-Key": `${value3}`,
|
|
515
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
516
|
-
Authorization: `Bearer ${accessToken}`,
|
|
517
|
-
"Content-Type": "application/json"
|
|
518
|
-
}
|
|
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
|
-
});
|
|
537
|
-
const data = res.data;
|
|
538
|
-
return { success: true, data };
|
|
539
|
-
} catch (error) {
|
|
540
|
-
if (import_axios5.default.isAxiosError(error)) {
|
|
541
|
-
return { error, success: false };
|
|
542
|
-
}
|
|
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 };
|
|
557
|
-
} catch (error) {
|
|
558
|
-
if (import_axios5.default.isAxiosError(error)) {
|
|
559
|
-
return { error, success: false };
|
|
560
|
-
}
|
|
561
|
-
return { error: new Error("unknown error"), success: false };
|
|
562
|
-
}
|
|
563
|
-
}
|
|
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
|
-
|
|
582
|
-
// src/modules/payout/payout.ts
|
|
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
|
-
};
|
|
593
|
-
}
|
|
594
|
-
if (amount <= 0) {
|
|
595
|
-
return {
|
|
596
|
-
error: new Error("amount must be greater than 0"),
|
|
597
|
-
success: false
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
601
|
-
const body = {
|
|
602
|
-
amount: {
|
|
603
|
-
currency: "SLE",
|
|
604
|
-
value: amount
|
|
605
|
-
},
|
|
606
|
-
source: {
|
|
607
|
-
financialAccountId: sourceAccount
|
|
608
|
-
},
|
|
609
|
-
destination,
|
|
610
|
-
metadata: {}
|
|
611
|
-
};
|
|
612
|
-
try {
|
|
613
|
-
const res = await import_axios6.default.post(URL6, body, {
|
|
614
|
-
headers: {
|
|
615
|
-
"Idempotency-Key": `${value4}`,
|
|
616
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
617
|
-
Authorization: `Bearer ${accessToken}`,
|
|
618
|
-
"Content-Type": "application/json"
|
|
619
|
-
}
|
|
620
|
-
});
|
|
621
|
-
const data = res.data;
|
|
622
|
-
return { success: true, data };
|
|
623
|
-
} catch (error) {
|
|
624
|
-
if (import_axios6.default.isAxiosError(error)) {
|
|
625
|
-
return { success: false, error };
|
|
626
|
-
}
|
|
627
|
-
return { success: false, error: new Error("unknown error") };
|
|
628
|
-
}
|
|
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
|
-
}
|
|
693
|
-
|
|
694
|
-
// src/client.ts
|
|
695
|
-
var MonimeClient = class {
|
|
696
|
-
monimeSpaceId;
|
|
697
|
-
accessToken;
|
|
698
|
-
financialAccount;
|
|
699
|
-
internalTransfer;
|
|
700
|
-
paymentCode;
|
|
701
|
-
payout;
|
|
702
|
-
financialTransaction;
|
|
703
|
-
checkoutSession;
|
|
704
|
-
constructor(options) {
|
|
705
|
-
this.accessToken = options.accessToken;
|
|
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);
|
|
713
|
-
}
|
|
714
|
-
/** @internal */
|
|
715
|
-
_getConfig() {
|
|
716
|
-
return {
|
|
717
|
-
monimeSpaceId: this.monimeSpaceId,
|
|
718
|
-
accessToken: this.accessToken
|
|
719
|
-
};
|
|
720
|
-
}
|
|
721
|
-
};
|
|
722
|
-
|
|
723
|
-
// src/index.ts
|
|
724
|
-
function createClient(options) {
|
|
725
|
-
return new MonimeClient(options);
|
|
726
|
-
}
|
|
727
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
728
|
-
0 && (module.exports = {
|
|
729
|
-
MonimeClient,
|
|
730
|
-
createClient
|
|
731
|
-
});
|
|
732
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";var We=Object.create;var I=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Ke=Object.getPrototypeOf,Le=Object.prototype.hasOwnProperty;var qe=(r,e)=>{for(var t in e)I(r,t,{get:e[t],enumerable:!0})},D=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of _e(e))!Le.call(r,n)&&n!==t&&I(r,n,{get:()=>e[n],enumerable:!(s=ze(e,n))||s.enumerable});return r};var m=(r,e,t)=>(t=r!=null?We(Ke(r)):{},D(e||!r||!r.__esModule?I(t,"default",{value:r,enumerable:!0}):t,r)),Ne=r=>D(I({},"__esModule",{value:!0}),r);var er={};qe(er,{MonimeClient:()=>T,createClient:()=>Ze});module.exports=Ne(er);var B=require("crypto"),p=m(require("axios")),je=(0,B.randomBytes)(20).toString("hex"),k="https://api.monime.io/v1/checkout-sessions";async function U(r,e,t,s,n,o,i,c,u,y){let{monimeSpaceId:M,accessToken:b,monimeVersion:S}=r._getConfig(),Ue={name:e,description:i,cancelUrl:o,successUrl:n,callbackState:null,reference:null,financialAccountId:c,lineItems:[{type:"custom",name:e,price:{currency:"SLE",value:t},quantity:s,reference:null,description:i,images:y}],paymentOptions:{card:{disable:!1},bank:{disable:!1,enabledProviders:["slb001","slb004","slb007"]},momo:{disable:!1,enabledProviders:["m17","m18"]},wallet:{disable:!1,enabledProviders:["dw001"]}},brandingOptions:{primaryColor:u},metadata:{}};try{return{success:!0,data:(await p.default.post(k,Ue,{headers:{"Monime-Space-Id":M,Authorization:`Bearer ${b}`,"Content-Type":"application/json","Idempotency-Key":je,...S?{"Monime-Version":S}:{}}})).data}}catch(O){return p.default.isAxiosError(O)?{error:O,success:!1}:{error:new Error("unknown error"),success:!1}}}async function W(r){let{accessToken:e,monimeSpaceId:t,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await p.default.get(k,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${e}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return p.default.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}async function z(r,e){let{accessToken:t,monimeSpaceId:s,monimeVersion:n}=r._getConfig();try{return{success:!0,data:(await p.default.get(`${k}/${e}`,{headers:{"Monime-Space-Id":s,Authorization:`Bearer ${t}`,...n?{"Monime-Version":n}:{}}})).data}}catch(o){return p.default.isAxiosError(o)?{error:o,success:!1}:{error:new Error("unknown error"),success:!1}}}async function _(r,e){let{accessToken:t,monimeSpaceId:s,monimeVersion:n}=r._getConfig();try{return await p.default.delete(`${k}/${e}`,{headers:{"Monime-Space-Id":s,Authorization:`Bearer ${t}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(o){return p.default.isAxiosError(o)?{error:o,success:!1}:{error:new Error("unknown error"),success:!1}}}function K(r){return{create:(e,t,s,n,o,i,c,u,y)=>U(r,e,t,s,n,o,i,c,u,y),get:()=>W(r),getOne:e=>z(r,e),delete:e=>_(r,e)}}var L=require("crypto"),h=m(require("axios")),$="https://api.monime.io/v1/financial-accounts",He=(0,L.randomBytes)(20).toString("hex");async function q(r,e,t){if(r.trim()==="")return{success:!1,error:new Error("accountName is required")};let s={name:r,currency:e,description:"",metadata:{}},{accessToken:n,monimeSpaceId:o,monimeVersion:i}=t._getConfig();try{return{success:!0,data:(await h.default.post($,s,{headers:{"Idempotency-Key":`${He}`,"Monime-Space-Id":`${o}`,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...i?{"Monime-Version":i}:{}}})).data}}catch(c){return h.default.isAxiosError(c)?{error:c,success:!1}:{error:new Error("unknown error"),success:!1}}}async function N(r,e){if(r.trim()==="")return{success:!1,error:new Error("financialAccountId is required")};let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await h.default.get(`${$}/${r}`,{headers:{"Monime-Space-Id":`${t}`,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(o){return h.default.isAxiosError(o)?{error:o,success:!1}:{error:new Error("unknown error"),success:!1}}}async function j(r){let{monimeSpaceId:e,accessToken:t,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await h.default.get($,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${t}`}})).data}}catch(n){return h.default.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}function H(r){return{create:(e,t)=>q(e,t,r),get:e=>N(e,r),getAll:()=>j(r)}}var C=m(require("axios")),J="https://api.monime.io/v1/financial-transactions";async function Q(r){let{monimeSpaceId:e,accessToken:t,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await C.default.get(J,{headers:{Authorization:`Bearer ${t}`,"Monime-Space-Id":`${e}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return C.default.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}async function X(r,e){let{accessToken:t,monimeSpaceId:s,monimeVersion:n}=r._getConfig();if(e.trim()==="")return{error:new Error("transactionId must not be empty"),success:!1};try{return{success:!0,data:(await C.default.get(`${J}/${e}`,{headers:{Authorization:`Bearer ${t}`,"Monime-Space-Id":`${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(o){return C.default.isAxiosError(o)?{error:o,success:!1}:{error:new Error("unknown error"),success:!1}}}function Y(r){return{get:e=>X(r,e),getAll:()=>Q(r)}}var Z=require("crypto"),d=m(require("axios")),R="https://api.monime.io/v1/internal-transfers",Je=(0,Z.randomBytes)(20).toString("hex");async function ee(r,e,t,s){if(s<=0)return{success:!1,error:new Error("amount must be larger that zero")};if(r.trim()===""||e.trim()==="")return{success:!1,error:new Error("sourceAccount or destinationAccount is missing")};let n={amount:{currency:"SLE",value:s},sourceFinancialAccount:{id:r},destinationFinancialAccount:{id:e},metadata:{}},{accessToken:o,monimeSpaceId:i,monimeVersion:c}=t._getConfig();try{return{success:!0,data:(await d.default.post(R,n,{headers:{"Idempotency-Key":`${Je}`,"Monime-Space-Id":`${i}`,Authorization:`Bearer ${o}`,"Content-Type":"application/json",...c?{"Monime-Version":c}:{}}})).data}}catch(u){return d.default.isAxiosError(u)?{error:u,success:!1}:{error:new Error("unkknown error"),success:!1}}}async function re(r){let{monimeSpaceId:e,accessToken:t,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await d.default.get(R,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${t}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return d.default.isAxiosError(n)?{success:!1,error:n}:{error:new Error("unkknown error"),success:!1}}}async function ne(r,e){let{accessToken:t,monimeSpaceId:s,monimeVersion:n}=r._getConfig();try{return{success:!0,data:(await d.default.get(`${R}/${e}`,{headers:{"Monime-Space-Id":`${s}`,Authorization:`Bearer ${t}`,...n?{"Monime-Version":n}:{}}})).data}}catch(o){return d.default.isAxiosError(o)?{success:!1,error:o}:{error:new Error("unkknown error"),success:!1}}}async function te(r,e){let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=r._getConfig();try{return await d.default.delete(`${R}/${e}`,{headers:{"Monime-Space-Id":`${t}`,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(o){return d.default.isAxiosError(o)?{success:!1,error:o}:{success:!1,error:new Error("unknown error")}}}function oe(r){return{create:(e,t,s)=>ee(e,t,r,s),get:e=>ne(r,e),getAll:()=>re(r),delete:e=>te(r,e)}}var se=require("crypto"),A=m(require("axios")),v="https://api.monime.io/v1/payments";async function ie(r,e){if(!r)return{success:!1,error:new Error("paymentId is required")};let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await A.default.get(`${v}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(o){return A.default.isAxiosError(o)?{success:!1,error:o}:{success:!1,error:new Error("Unknown error")}}}async function ae(r,e){let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=r._getConfig();try{return{success:!0,data:(await A.default.get(v,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}},params:e})).data}}catch(o){return A.default.isAxiosError(o)?{success:!1,error:o}:{success:!1,error:new Error("Unknown error")}}}async function ce(r,e,t){if(!r)return{success:!1,error:new Error("paymentId is required")};let{monimeSpaceId:s,accessToken:n,monimeVersion:o}=t._getConfig(),i=(0,se.randomBytes)(20).toString("hex");try{return{success:!0,data:(await A.default.patch(`${v}/${r}`,e,{headers:{"Idempotency-Key":i,"Monime-Space-Id":s,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...o?{"Monime-Version":o}:{}}})).data}}catch(c){return A.default.isAxiosError(c)?{success:!1,error:c}:{success:!1,error:new Error("Unknown error")}}}function ue(r){return{get:e=>ie(e,r),getAll:e=>ae(r,e),patch:(e,t)=>ce(e,t,r)}}var me=require("crypto"),g=m(require("axios")),le=(0,me.randomBytes)(20).toString("hex"),x="https://api.monime.io/v1/payment-codes";async function pe(r,e,t,s,n,o){let i=null;if(t!==""&&(i=t),r.trim()===""||s.trim()===""||n.trim()==="")return{success:!1,error:new Error("paymentName, name, or phoneNumber is missing")};if(e<=0)return{success:!1,error:new Error("amonut number be greater than zero")};let{accessToken:c,monimeSpaceId:u,monimeVersion:y}=o._getConfig(),M={name:`${r}`,mode:"recurrent",enable:!0,amount:{currency:"SLE",value:e*100},duration:"1h30m",customer:{name:`${s}`},reference:"",authorizedPhoneNumber:n,recurrentPaymentTarget:{expectedPaymentCount:1,expectedPaymentTotal:{currency:"SLE",value:e*100}},financialAccountId:i,metadata:{}};try{return{data:(await g.default.post(x,M,{headers:{"Idempotency-Key":`${le}`,"Monime-Space-Id":`${u}`,Authorization:`Bearer ${c}`,"Content-Type":"application/json",...y?{"Monime-Version":y}:{}}})).data,success:!0}}catch(b){return g.default.isAxiosError(b)?{error:b.response?.data,success:!1}:{error:new Error("unknown error"),success:!1}}}async function de(r,e){let{accessToken:t,monimeSpaceId:s,monimeVersion:n}=e._getConfig();if(r.trim()==="")return{success:!1,error:new Error("paymentCodeId is required")};try{return await g.default.delete(`${x}/${r}`,{headers:{"Idempotency-Key":`${le}`,"Monime-Space-Id":`${s}`,Authorization:`Bearer ${t}`,"Content-Type":"application/json",...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(o){return g.default.isAxiosError(o)?{error:o,success:!1}:{error:new Error("unknown error"),success:!1}}}async function ge(r){let{monimeSpaceId:e,accessToken:t,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await g.default.get(x,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${t}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return g.default.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}async function fe(r,e){let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await g.default.get(`${x}/${r}`,{headers:{"Monime-Space-Id":`${t}`,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(o){return g.default.isAxiosError(o)?{error:o,success:!1}:{error:new Error("unknown error"),success:!1}}}function ye(r){return{create:(e,t,s,n,o)=>pe(e,t,s,n,o,r),delete:e=>de(e,r),getAll:()=>ge(r),get:e=>fe(e,r)}}var he=require("crypto"),f=m(require("axios")),E="https://api.monime.io/v1/payouts",Qe=(0,he.randomBytes)(20).toString("hex");async function Ae(r,e,t,s){if(e.trim()==="")return{success:!1,error:new Error("sourceAccount cannot be empty")};if(r<=0)return{error:new Error("amount must be greater than 0"),success:!1};let{accessToken:n,monimeSpaceId:o,monimeVersion:i}=s._getConfig(),c={amount:{currency:"SLE",value:r},source:{financialAccountId:e},destination:t,metadata:{}};try{return{success:!0,data:(await f.default.post(E,c,{headers:{"Idempotency-Key":`${Qe}`,"Monime-Space-Id":`${o}`,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...i?{"Monime-Version":i}:{}}})).data}}catch(u){return f.default.isAxiosError(u)?{success:!1,error:u}:{success:!1,error:new Error("unknown error")}}}async function be(r){let{accessToken:e,monimeSpaceId:t,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await f.default.get(E,{headers:{"Monime-Space-Id":`${t}`,Authorization:`Bearer ${e}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return f.default.isAxiosError(n)?{success:!1,error:n}:{success:!1,error:new Error("unknown error")}}}async function Ce(r,e){let{accessToken:t,monimeSpaceId:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await f.default.get(`${E}/${r}`,{headers:{"Monime-Space-Id":`${s}`,Authorization:`Bearer ${t}`,...n?{"Monime-Version":n}:{}}})).data}}catch(o){return f.default.isAxiosError(o)?{success:!1,error:o}:{success:!1,error:new Error("unknown error")}}}async function Pe(r,e){let{accessToken:t,monimeSpaceId:s,monimeVersion:n}=e._getConfig();try{return await f.default.delete(`${E}/${r}`,{headers:{"Monime-Space-Id":`${s}`,Authorization:`Bearer ${t}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(o){return f.default.isAxiosError(o)?{success:!1,error:o}:{success:!1,error:new Error("unknown error")}}}function we(r){return{create:(e,t,s)=>Ae(e,s,t,r),get:()=>be(r),getOne:e=>Ce(e,r),delete:e=>Pe(e,r)}}var G=m(require("axios")),Xe="https://api.monime.io/v1/provider-kyc";async function Te(r,e){let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await G.default.get(`${Xe}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(o){return G.default.isAxiosError(o)?{success:!1,error:o}:{success:!1,error:new Error("Unknown error")}}}function Ie(r){return{get:e=>Te(e,r)}}var ke=require("crypto"),P=m(require("axios")),Re="https://api.monime.io/v1/receipts";async function xe(r,e){let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await P.default.get(`${Re}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(o){return P.default.isAxiosError(o)?{success:!1,error:o}:{success:!1,error:new Error("Unknown error")}}}async function Ee(r,e,t){let{monimeSpaceId:s,accessToken:n,monimeVersion:o}=t._getConfig(),i=(0,ke.randomBytes)(20).toString("hex");try{return{success:!0,data:(await P.default.post(`${Re}/${r}/redeem`,e,{headers:{"Idempotency-Key":i,"Monime-Space-Id":s,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...o?{"Monime-Version":o}:{}}})).data}}catch(c){return P.default.isAxiosError(c)?{success:!1,error:c}:{success:!1,error:new Error("Unknown error")}}}function Me(r){return{get:e=>xe(e,r),redeem:(e,t={})=>Ee(e,t,r)}}var Se=require("crypto"),V=m(require("axios")),Ye="https://api.monime.io/v1/ussd-otps";async function Oe(r,e){let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=e._getConfig(),o=(0,Se.randomBytes)(20).toString("hex");try{return{success:!0,data:(await V.default.post(Ye,r,{headers:{"Idempotency-Key":o,"Monime-Space-Id":t,Authorization:`Bearer ${s}`,"Content-Type":"application/json",...n?{"Monime-Version":n}:{}}})).data}}catch(i){return V.default.isAxiosError(i)?{success:!1,error:i}:{success:!1,error:new Error("Unknown error")}}}function $e(r){return{create:e=>Oe(e,r)}}var F=require("crypto"),l=m(require("axios")),w="https://api.monime.io/v1/webhooks";async function ve(r,e){let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=e._getConfig(),o=(0,F.randomBytes)(20).toString("hex");try{return{success:!0,data:(await l.default.post(w,r,{headers:{"Idempotency-Key":o,"Monime-Space-Id":t,Authorization:`Bearer ${s}`,"Content-Type":"application/json",...n?{"Monime-Version":n}:{}}})).data}}catch(i){return l.default.isAxiosError(i)?{success:!1,error:i}:{success:!1,error:new Error("Unknown error")}}}async function Ge(r,e){let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await l.default.get(`${w}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(o){return l.default.isAxiosError(o)?{success:!1,error:o}:{success:!1,error:new Error("Unknown error")}}}async function Ve(r){let{monimeSpaceId:e,accessToken:t,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await l.default.get(w,{headers:{"Monime-Space-Id":e,Authorization:`Bearer ${t}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return l.default.isAxiosError(n)?{success:!1,error:n}:{success:!1,error:new Error("Unknown error")}}}async function Fe(r,e,t){let{monimeSpaceId:s,accessToken:n,monimeVersion:o}=t._getConfig(),i=(0,F.randomBytes)(20).toString("hex");try{return{success:!0,data:(await l.default.patch(`${w}/${r}`,e,{headers:{"Idempotency-Key":i,"Monime-Space-Id":s,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...o?{"Monime-Version":o}:{}}})).data}}catch(c){return l.default.isAxiosError(c)?{success:!1,error:c}:{success:!1,error:new Error("Unknown error")}}}async function De(r,e){let{monimeSpaceId:t,accessToken:s,monimeVersion:n}=e._getConfig();try{return await l.default.delete(`${w}/${r}`,{headers:{"Monime-Space-Id":t,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(o){return l.default.isAxiosError(o)?{success:!1,error:o}:{success:!1,error:new Error("Unknown error")}}}function Be(r){return{create:e=>ve(e,r),get:e=>Ge(e,r),getAll:()=>Ve(r),update:(e,t)=>Fe(e,t,r),delete:e=>De(e,r)}}var T=class{monimeSpaceId;accessToken;monimeVersion;financialAccount;internalTransfer;paymentCode;payment;payout;providerKyc;receipt;ussdOtp;webhook;financialTransaction;checkoutSession;constructor(e){this.accessToken=e.accessToken,this.monimeSpaceId=e.monimeSpaceId,this.monimeVersion=e.monimeVersion,this.financialAccount=H(this),this.internalTransfer=oe(this),this.paymentCode=ye(this),this.payment=ue(this),this.payout=we(this),this.providerKyc=Ie(this),this.receipt=Me(this),this.ussdOtp=$e(this),this.webhook=Be(this),this.financialTransaction=Y(this),this.checkoutSession=K(this)}_getConfig(){return{monimeSpaceId:this.monimeSpaceId,accessToken:this.accessToken,monimeVersion:this.monimeVersion}}};function Ze(r){return new T(r)}0&&(module.exports={MonimeClient,createClient});
|