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.mjs
CHANGED
|
@@ -1,694 +1 @@
|
|
|
1
|
-
// src/modules/checkout session/checkoutSession.ts
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
var URL = "https://api.monime.io/v1/checkout-sessions";
|
|
4
|
-
async function createCheckout(client, name, amount, quantity, successUrl, cancelUrl, description, financialAccountId, primaryColor, images) {
|
|
5
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
6
|
-
const body = {
|
|
7
|
-
name,
|
|
8
|
-
description,
|
|
9
|
-
cancelUrl,
|
|
10
|
-
successUrl,
|
|
11
|
-
callbackState: null,
|
|
12
|
-
reference: null,
|
|
13
|
-
financialAccountId,
|
|
14
|
-
lineItems: [
|
|
15
|
-
{
|
|
16
|
-
type: "custom",
|
|
17
|
-
name,
|
|
18
|
-
price: {
|
|
19
|
-
currency: "SLE",
|
|
20
|
-
value: amount
|
|
21
|
-
},
|
|
22
|
-
quantity,
|
|
23
|
-
reference: null,
|
|
24
|
-
description,
|
|
25
|
-
images
|
|
26
|
-
}
|
|
27
|
-
],
|
|
28
|
-
paymentOptions: {
|
|
29
|
-
card: {
|
|
30
|
-
disable: false
|
|
31
|
-
},
|
|
32
|
-
bank: {
|
|
33
|
-
disable: false,
|
|
34
|
-
enabledProviders: ["slb001", "slb004", "slb007"]
|
|
35
|
-
// disabledProviders: ["slb001"],
|
|
36
|
-
},
|
|
37
|
-
momo: {
|
|
38
|
-
disable: false,
|
|
39
|
-
enabledProviders: ["m17", "m18"]
|
|
40
|
-
// disabledProviders: ["m17"],
|
|
41
|
-
},
|
|
42
|
-
wallet: {
|
|
43
|
-
disable: false,
|
|
44
|
-
enabledProviders: ["dw001"]
|
|
45
|
-
// disabledProviders: ["dw001"],
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
brandingOptions: {
|
|
49
|
-
primaryColor
|
|
50
|
-
},
|
|
51
|
-
metadata: {}
|
|
52
|
-
};
|
|
53
|
-
try {
|
|
54
|
-
const res = await axios.post(URL, body, {
|
|
55
|
-
headers: {
|
|
56
|
-
"Monime-Space-Id": monimeSpaceId,
|
|
57
|
-
Authorization: `Bearer ${accessToken}`
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
const data = res.data;
|
|
61
|
-
return { success: true, data };
|
|
62
|
-
} catch (error) {
|
|
63
|
-
if (axios.isAxiosError(error)) {
|
|
64
|
-
return { error, success: false };
|
|
65
|
-
}
|
|
66
|
-
return { error: new Error("unknown error"), success: false };
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async function getAllCheckout(client) {
|
|
70
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
71
|
-
try {
|
|
72
|
-
const res = await axios.get(URL, {
|
|
73
|
-
headers: {
|
|
74
|
-
"Monime-Space-Id": monimeSpaceId,
|
|
75
|
-
Authorization: `Bearer ${accessToken}`
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
const data = res.data;
|
|
79
|
-
return { success: true, data };
|
|
80
|
-
} catch (error) {
|
|
81
|
-
if (axios.isAxiosError(error)) {
|
|
82
|
-
return { error, success: false };
|
|
83
|
-
}
|
|
84
|
-
return { error: new Error("unknown error"), success: false };
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async function getOnecheckout(client, checkoutId) {
|
|
88
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
89
|
-
try {
|
|
90
|
-
const res = await axios.get(`${URL}/${checkoutId}`, {
|
|
91
|
-
headers: {
|
|
92
|
-
"Monime-Space-Id": monimeSpaceId,
|
|
93
|
-
Authorization: `Bearer ${accessToken}`
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
const data = res.data;
|
|
97
|
-
return { success: true, data };
|
|
98
|
-
} catch (error) {
|
|
99
|
-
if (axios.isAxiosError(error)) {
|
|
100
|
-
return { error, success: false };
|
|
101
|
-
}
|
|
102
|
-
return { error: new Error("unknown error"), success: false };
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
async function deleteCheckout(client, checkoutId) {
|
|
106
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
107
|
-
try {
|
|
108
|
-
await axios.delete(`${URL}/${checkoutId}`, {
|
|
109
|
-
headers: {
|
|
110
|
-
"Monime-Space-Id": monimeSpaceId,
|
|
111
|
-
Authorization: `Bearer ${accessToken}`
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
return { success: true };
|
|
115
|
-
} catch (error) {
|
|
116
|
-
if (axios.isAxiosError(error)) {
|
|
117
|
-
return { error, success: false };
|
|
118
|
-
}
|
|
119
|
-
return { error: new Error("unknown error"), success: false };
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// src/modules/checkout session/index.ts
|
|
124
|
-
function CheckoutSessionAPI(client) {
|
|
125
|
-
return {
|
|
126
|
-
create: (name, amount, quantity, successUrl, cancelUrl, description, financialAccountId, primaryColor, images) => createCheckout(
|
|
127
|
-
client,
|
|
128
|
-
name,
|
|
129
|
-
amount,
|
|
130
|
-
quantity,
|
|
131
|
-
successUrl,
|
|
132
|
-
cancelUrl,
|
|
133
|
-
description,
|
|
134
|
-
financialAccountId,
|
|
135
|
-
primaryColor,
|
|
136
|
-
images
|
|
137
|
-
),
|
|
138
|
-
get: () => getAllCheckout(client),
|
|
139
|
-
getOne: (checkoutId) => getOnecheckout(client, checkoutId),
|
|
140
|
-
delete: (checkoutId) => deleteCheckout(client, checkoutId)
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// src/modules/financialAccount/financialAccount.ts
|
|
145
|
-
import { randomBytes } from "crypto";
|
|
146
|
-
import axios2 from "axios";
|
|
147
|
-
var URL2 = "https://api.monime.io/v1/financial-accounts";
|
|
148
|
-
var value = randomBytes(20).toString("hex");
|
|
149
|
-
async function createFinancialAccount(accountName, currency, client) {
|
|
150
|
-
if (accountName.trim() === "") {
|
|
151
|
-
return { success: false, error: new Error("accountName is required") };
|
|
152
|
-
}
|
|
153
|
-
const body = {
|
|
154
|
-
name: accountName,
|
|
155
|
-
currency,
|
|
156
|
-
description: "",
|
|
157
|
-
metadata: {}
|
|
158
|
-
};
|
|
159
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
160
|
-
try {
|
|
161
|
-
const res = await axios2.post(URL2, body, {
|
|
162
|
-
headers: {
|
|
163
|
-
"Idempotency-Key": `${value}`,
|
|
164
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
165
|
-
Authorization: `Bearer ${accessToken}`,
|
|
166
|
-
"Content-Type": "application/json"
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
const data = res.data;
|
|
170
|
-
return { success: true, data };
|
|
171
|
-
} catch (error) {
|
|
172
|
-
if (axios2.isAxiosError(error)) {
|
|
173
|
-
return { error, success: false };
|
|
174
|
-
}
|
|
175
|
-
return { error: new Error("unknown error"), success: false };
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
async function getFinancialAccount(financialAccountId, client) {
|
|
179
|
-
if (financialAccountId.trim() === "") {
|
|
180
|
-
return {
|
|
181
|
-
success: false,
|
|
182
|
-
error: new Error("financialAccountId is required")
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
186
|
-
try {
|
|
187
|
-
const res = await axios2.get(`${URL2}/${financialAccountId}`, {
|
|
188
|
-
headers: {
|
|
189
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
190
|
-
Authorization: `Bearer ${accessToken}`
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
const data = res.data;
|
|
194
|
-
return { success: true, data };
|
|
195
|
-
} catch (error) {
|
|
196
|
-
if (axios2.isAxiosError(error)) {
|
|
197
|
-
return { error, success: false };
|
|
198
|
-
}
|
|
199
|
-
return { error: new Error("unknown error"), success: false };
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async function getAllFinancialAccount(client) {
|
|
203
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
204
|
-
try {
|
|
205
|
-
const res = await axios2.get(URL2, {
|
|
206
|
-
headers: {
|
|
207
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
208
|
-
Authorization: `Bearer ${accessToken}`
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
const data = res.data;
|
|
212
|
-
return { success: true, data };
|
|
213
|
-
} catch (error) {
|
|
214
|
-
if (axios2.isAxiosError(error)) {
|
|
215
|
-
return { error, success: false };
|
|
216
|
-
}
|
|
217
|
-
return { error: new Error("unknown error"), success: false };
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// src/modules/financialAccount/index.ts
|
|
222
|
-
function FinancialAccountAPI(client) {
|
|
223
|
-
return {
|
|
224
|
-
create: (name, currency) => createFinancialAccount(name, currency, client),
|
|
225
|
-
get: (financialAccountId) => getFinancialAccount(financialAccountId, client),
|
|
226
|
-
getAll: () => getAllFinancialAccount(client)
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// src/modules/financialTransaction/financialTransaction.ts
|
|
231
|
-
import axios3 from "axios";
|
|
232
|
-
var URL3 = "https://api.monime.io/v1/financial-transactions";
|
|
233
|
-
async function getAllTransaction(client) {
|
|
234
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
235
|
-
try {
|
|
236
|
-
const res = await axios3.get(URL3, {
|
|
237
|
-
headers: {
|
|
238
|
-
Authorization: `Bearer ${accessToken}`,
|
|
239
|
-
"Monime-Space-Id": `${monimeSpaceId}`
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
const data = res.data;
|
|
243
|
-
return { success: true, data };
|
|
244
|
-
} catch (error) {
|
|
245
|
-
if (axios3.isAxiosError(error)) {
|
|
246
|
-
return { error, success: false };
|
|
247
|
-
}
|
|
248
|
-
return { error: new Error("unknown error"), success: false };
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
async function getTransaction(client, transactionId) {
|
|
252
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
253
|
-
if (transactionId.trim() === "") {
|
|
254
|
-
return {
|
|
255
|
-
error: new Error("transactionId must not be empty"),
|
|
256
|
-
success: false
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
try {
|
|
260
|
-
const res = await axios3.get(`${URL3}/${transactionId}`, {
|
|
261
|
-
headers: {
|
|
262
|
-
Authorization: `Bearer ${accessToken}`,
|
|
263
|
-
"Monime-Space-Id": `${monimeSpaceId}`
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
const data = res.data;
|
|
267
|
-
return { success: true, data };
|
|
268
|
-
} catch (error) {
|
|
269
|
-
if (axios3.isAxiosError(error)) {
|
|
270
|
-
return { error, success: false };
|
|
271
|
-
}
|
|
272
|
-
return { error: new Error("unknown error"), success: false };
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// src/modules/financialTransaction/index.ts
|
|
277
|
-
function FinancialTransactionAPI(client) {
|
|
278
|
-
return {
|
|
279
|
-
get: (transactionId) => getTransaction(client, transactionId),
|
|
280
|
-
getAll: () => getAllTransaction(client)
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// src/modules/internalTransfer/internalTransfer.ts
|
|
285
|
-
import { randomBytes as randomBytes2 } from "crypto";
|
|
286
|
-
import axios4 from "axios";
|
|
287
|
-
var URL4 = "https://api.monime.io/v1/internal-transfers";
|
|
288
|
-
var value2 = randomBytes2(20).toString("hex");
|
|
289
|
-
async function createInternalTransfer(sourceAccount, destinationAccount, client, amount) {
|
|
290
|
-
if (amount <= 0) {
|
|
291
|
-
return {
|
|
292
|
-
success: false,
|
|
293
|
-
error: new Error("amount must be larger that zero")
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
if (sourceAccount.trim() === "" || destinationAccount.trim() === "") {
|
|
297
|
-
return {
|
|
298
|
-
success: false,
|
|
299
|
-
error: new Error("sourceAccount or destinationAccount is missing")
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
const body = {
|
|
303
|
-
amount: {
|
|
304
|
-
currency: "SLE",
|
|
305
|
-
value: amount
|
|
306
|
-
},
|
|
307
|
-
sourceFinancialAccount: {
|
|
308
|
-
id: sourceAccount
|
|
309
|
-
},
|
|
310
|
-
destinationFinancialAccount: {
|
|
311
|
-
id: destinationAccount
|
|
312
|
-
},
|
|
313
|
-
metadata: {}
|
|
314
|
-
};
|
|
315
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
316
|
-
try {
|
|
317
|
-
const res = await axios4.post(URL4, body, {
|
|
318
|
-
headers: {
|
|
319
|
-
"Idempotency-Key": `${value2}`,
|
|
320
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
321
|
-
Authorization: `Bearer ${accessToken}`,
|
|
322
|
-
"Content-Type": "application/json"
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
const data = res.data;
|
|
326
|
-
return { success: true, data };
|
|
327
|
-
} catch (error) {
|
|
328
|
-
if (axios4.isAxiosError(error)) {
|
|
329
|
-
return { error, success: false };
|
|
330
|
-
}
|
|
331
|
-
return { error: new Error("unkknown error"), success: false };
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
async function getAllInternalTransfers(client) {
|
|
335
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
336
|
-
try {
|
|
337
|
-
const res = await axios4.get(URL4, {
|
|
338
|
-
headers: {
|
|
339
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
340
|
-
Authorization: `Bearer ${accessToken}`
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
const data = res.data;
|
|
344
|
-
return { success: true, data };
|
|
345
|
-
} catch (error) {
|
|
346
|
-
if (axios4.isAxiosError(error)) {
|
|
347
|
-
return { success: false, error };
|
|
348
|
-
}
|
|
349
|
-
return { error: new Error("unkknown error"), success: false };
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
async function getInternalTransfer(client, internalTransferId) {
|
|
353
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
354
|
-
try {
|
|
355
|
-
const res = await axios4.get(`${URL4}/${internalTransferId}`, {
|
|
356
|
-
headers: {
|
|
357
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
358
|
-
Authorization: `Bearer ${accessToken}`
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
const data = res.data;
|
|
362
|
-
return { success: true, data };
|
|
363
|
-
} catch (error) {
|
|
364
|
-
if (axios4.isAxiosError(error)) {
|
|
365
|
-
return { success: false, error };
|
|
366
|
-
}
|
|
367
|
-
return { error: new Error("unkknown error"), success: false };
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
async function deleteInternalTransfer(client, internalTransferId) {
|
|
371
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
372
|
-
try {
|
|
373
|
-
await axios4.delete(`${URL4}/${internalTransferId}`, {
|
|
374
|
-
headers: {
|
|
375
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
376
|
-
Authorization: `Bearer ${accessToken}`
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
return { success: true };
|
|
380
|
-
} catch (error) {
|
|
381
|
-
if (axios4.isAxiosError(error)) {
|
|
382
|
-
return { success: false, error };
|
|
383
|
-
}
|
|
384
|
-
return { success: false, error: new Error("unknown error") };
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
// src/modules/internalTransfer/index.ts
|
|
389
|
-
function InternalTransferAPI(client) {
|
|
390
|
-
return {
|
|
391
|
-
create: (sourceAccount, destinationAccount, amount) => createInternalTransfer(
|
|
392
|
-
sourceAccount,
|
|
393
|
-
destinationAccount,
|
|
394
|
-
client,
|
|
395
|
-
amount
|
|
396
|
-
),
|
|
397
|
-
get: (internalTransferId) => getInternalTransfer(client, internalTransferId),
|
|
398
|
-
getAll: () => getAllInternalTransfers(client),
|
|
399
|
-
delete: (internalTransferId) => deleteInternalTransfer(client, internalTransferId)
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// src/modules/paymentCode/paymentCode.ts
|
|
404
|
-
import { randomBytes as randomBytes3 } from "crypto";
|
|
405
|
-
import axios5 from "axios";
|
|
406
|
-
var value3 = randomBytes3(20).toString("hex");
|
|
407
|
-
var URL5 = "https://api.monime.io/v1/payment-codes";
|
|
408
|
-
async function createPaymentCode(paymentName, amount, financialAccountId, name, phoneNumber, client) {
|
|
409
|
-
let financialAccount = null;
|
|
410
|
-
if (financialAccountId !== "") {
|
|
411
|
-
financialAccount = financialAccountId;
|
|
412
|
-
}
|
|
413
|
-
if (paymentName.trim() === "" || name.trim() === "" || phoneNumber.trim() === "") {
|
|
414
|
-
return {
|
|
415
|
-
success: false,
|
|
416
|
-
error: new Error("paymentName, name, or phoneNumber is missing")
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
if (amount <= 0) {
|
|
420
|
-
return {
|
|
421
|
-
success: false,
|
|
422
|
-
error: new Error("amonut number be greater than zero")
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
426
|
-
const bodyData = {
|
|
427
|
-
name: `${paymentName}`,
|
|
428
|
-
mode: "recurrent",
|
|
429
|
-
enable: true,
|
|
430
|
-
amount: {
|
|
431
|
-
currency: "SLE",
|
|
432
|
-
value: amount * 100
|
|
433
|
-
},
|
|
434
|
-
duration: "1h30m",
|
|
435
|
-
customer: {
|
|
436
|
-
name: `${name}`
|
|
437
|
-
},
|
|
438
|
-
reference: "",
|
|
439
|
-
authorizedPhoneNumber: phoneNumber,
|
|
440
|
-
// authorizedProviders: ["m17", "m18"],
|
|
441
|
-
recurrentPaymentTarget: {
|
|
442
|
-
expectedPaymentCount: 1,
|
|
443
|
-
expectedPaymentTotal: {
|
|
444
|
-
currency: "SLE",
|
|
445
|
-
value: amount * 100
|
|
446
|
-
}
|
|
447
|
-
},
|
|
448
|
-
financialAccountId: financialAccount,
|
|
449
|
-
metadata: {}
|
|
450
|
-
};
|
|
451
|
-
try {
|
|
452
|
-
const res = await axios5.post(URL5, bodyData, {
|
|
453
|
-
headers: {
|
|
454
|
-
"Idempotency-Key": `${value3}`,
|
|
455
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
456
|
-
Authorization: `Bearer ${accessToken}`,
|
|
457
|
-
"Content-Type": "application/json"
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
const data = res.data;
|
|
461
|
-
return { data, success: true };
|
|
462
|
-
} catch (error) {
|
|
463
|
-
if (axios5.isAxiosError(error)) {
|
|
464
|
-
return { error: error.response?.data, success: false };
|
|
465
|
-
}
|
|
466
|
-
return { error: new Error("unknown error"), success: false };
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
async function deletePaymentCode(paymentCodeId, client) {
|
|
470
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
471
|
-
if (paymentCodeId.trim() === "") {
|
|
472
|
-
return { success: false, error: new Error("paymentCodeId is required") };
|
|
473
|
-
}
|
|
474
|
-
try {
|
|
475
|
-
await axios5.delete(`${URL5}/${paymentCodeId}`, {
|
|
476
|
-
headers: {
|
|
477
|
-
"Idempotency-Key": `${value3}`,
|
|
478
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
479
|
-
Authorization: `Bearer ${accessToken}`,
|
|
480
|
-
"Content-Type": "application/json"
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
return { success: true };
|
|
484
|
-
} catch (error) {
|
|
485
|
-
if (axios5.isAxiosError(error)) {
|
|
486
|
-
return { error, success: false };
|
|
487
|
-
}
|
|
488
|
-
return { error: new Error("unknown error"), success: false };
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
async function getAllPaymentCode(client) {
|
|
492
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
493
|
-
try {
|
|
494
|
-
const res = await axios5.get(URL5, {
|
|
495
|
-
headers: {
|
|
496
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
497
|
-
Authorization: `Bearer ${accessToken}`
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
const data = res.data;
|
|
501
|
-
return { success: true, data };
|
|
502
|
-
} catch (error) {
|
|
503
|
-
if (axios5.isAxiosError(error)) {
|
|
504
|
-
return { error, success: false };
|
|
505
|
-
}
|
|
506
|
-
return { error: new Error("unknown error"), success: false };
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
async function getPaymentCode(paymentCodeId, client) {
|
|
510
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
511
|
-
try {
|
|
512
|
-
const res = await axios5.get(`${URL5}/${paymentCodeId}`, {
|
|
513
|
-
headers: {
|
|
514
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
515
|
-
Authorization: `Bearer ${accessToken}`
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
const data = res.data;
|
|
519
|
-
return { success: true, data };
|
|
520
|
-
} catch (error) {
|
|
521
|
-
if (axios5.isAxiosError(error)) {
|
|
522
|
-
return { error, success: false };
|
|
523
|
-
}
|
|
524
|
-
return { error: new Error("unknown error"), success: false };
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
// src/modules/paymentCode/index.ts
|
|
529
|
-
function PaymentCodeAPI(client) {
|
|
530
|
-
return {
|
|
531
|
-
create: (paymentName, amount, financialAccount, username, phoneNumber) => createPaymentCode(
|
|
532
|
-
paymentName,
|
|
533
|
-
amount,
|
|
534
|
-
financialAccount,
|
|
535
|
-
username,
|
|
536
|
-
phoneNumber,
|
|
537
|
-
client
|
|
538
|
-
),
|
|
539
|
-
delete: (paymentCodeId) => deletePaymentCode(paymentCodeId, client),
|
|
540
|
-
getAll: () => getAllPaymentCode(client),
|
|
541
|
-
get: (paymentCodeId) => getPaymentCode(paymentCodeId, client)
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// src/modules/payout/payout.ts
|
|
546
|
-
import { randomBytes as randomBytes4 } from "crypto";
|
|
547
|
-
import axios6 from "axios";
|
|
548
|
-
var URL6 = "https://api.monime.io/v1/payouts";
|
|
549
|
-
var value4 = randomBytes4(20).toString("hex");
|
|
550
|
-
async function createPayout(amount, sourceAccount, destination, client) {
|
|
551
|
-
if (sourceAccount.trim() === "") {
|
|
552
|
-
return {
|
|
553
|
-
success: false,
|
|
554
|
-
error: new Error("sourceAccount cannot be empty")
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
if (amount <= 0) {
|
|
558
|
-
return {
|
|
559
|
-
error: new Error("amount must be greater than 0"),
|
|
560
|
-
success: false
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
564
|
-
const body = {
|
|
565
|
-
amount: {
|
|
566
|
-
currency: "SLE",
|
|
567
|
-
value: amount
|
|
568
|
-
},
|
|
569
|
-
source: {
|
|
570
|
-
financialAccountId: sourceAccount
|
|
571
|
-
},
|
|
572
|
-
destination,
|
|
573
|
-
metadata: {}
|
|
574
|
-
};
|
|
575
|
-
try {
|
|
576
|
-
const res = await axios6.post(URL6, body, {
|
|
577
|
-
headers: {
|
|
578
|
-
"Idempotency-Key": `${value4}`,
|
|
579
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
580
|
-
Authorization: `Bearer ${accessToken}`,
|
|
581
|
-
"Content-Type": "application/json"
|
|
582
|
-
}
|
|
583
|
-
});
|
|
584
|
-
const data = res.data;
|
|
585
|
-
return { success: true, data };
|
|
586
|
-
} catch (error) {
|
|
587
|
-
if (axios6.isAxiosError(error)) {
|
|
588
|
-
return { success: false, error };
|
|
589
|
-
}
|
|
590
|
-
return { success: false, error: new Error("unknown error") };
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
async function getAllPayout(client) {
|
|
594
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
595
|
-
try {
|
|
596
|
-
const res = await axios6.get(URL6, {
|
|
597
|
-
headers: {
|
|
598
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
599
|
-
Authorization: `Bearer ${accessToken}`
|
|
600
|
-
}
|
|
601
|
-
});
|
|
602
|
-
const data = res.data;
|
|
603
|
-
return { success: true, data };
|
|
604
|
-
} catch (error) {
|
|
605
|
-
if (axios6.isAxiosError(error)) {
|
|
606
|
-
return { success: false, error };
|
|
607
|
-
}
|
|
608
|
-
return { success: false, error: new Error("unknown error") };
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
async function getPayout(payoutId, client) {
|
|
612
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
613
|
-
try {
|
|
614
|
-
const res = await axios6.get(`${URL6}/${payoutId}`, {
|
|
615
|
-
headers: {
|
|
616
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
617
|
-
Authorization: `Bearer ${accessToken}`
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
const data = res.data;
|
|
621
|
-
return { success: true, data };
|
|
622
|
-
} catch (error) {
|
|
623
|
-
if (axios6.isAxiosError(error)) {
|
|
624
|
-
return { success: false, error };
|
|
625
|
-
}
|
|
626
|
-
return { success: false, error: new Error("unknown error") };
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
async function deletePayout(payoutId, client) {
|
|
630
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
631
|
-
try {
|
|
632
|
-
await axios6.delete(`${URL6}/${payoutId}`, {
|
|
633
|
-
headers: {
|
|
634
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
635
|
-
Authorization: `Bearer ${accessToken}`
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
return { success: true };
|
|
639
|
-
} catch (error) {
|
|
640
|
-
if (axios6.isAxiosError(error)) {
|
|
641
|
-
return { success: false, error };
|
|
642
|
-
}
|
|
643
|
-
return { success: false, error: new Error("unknown error") };
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
// src/modules/payout/index.ts
|
|
648
|
-
function PayoutAPI(client) {
|
|
649
|
-
return {
|
|
650
|
-
create: (amount, destination, sourceAccount) => createPayout(amount, sourceAccount, destination, client),
|
|
651
|
-
get: () => getAllPayout(client),
|
|
652
|
-
getOne: (payoutId) => getPayout(payoutId, client),
|
|
653
|
-
delete: (payoutId) => deletePayout(payoutId, client)
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
// src/client.ts
|
|
658
|
-
var MonimeClient = class {
|
|
659
|
-
monimeSpaceId;
|
|
660
|
-
accessToken;
|
|
661
|
-
financialAccount;
|
|
662
|
-
internalTransfer;
|
|
663
|
-
paymentCode;
|
|
664
|
-
payout;
|
|
665
|
-
financialTransaction;
|
|
666
|
-
checkoutSession;
|
|
667
|
-
constructor(options) {
|
|
668
|
-
this.accessToken = options.accessToken;
|
|
669
|
-
this.monimeSpaceId = options.monimeSpaceId;
|
|
670
|
-
this.financialAccount = FinancialAccountAPI(this);
|
|
671
|
-
this.internalTransfer = InternalTransferAPI(this);
|
|
672
|
-
this.paymentCode = PaymentCodeAPI(this);
|
|
673
|
-
this.payout = PayoutAPI(this);
|
|
674
|
-
this.financialTransaction = FinancialTransactionAPI(this);
|
|
675
|
-
this.checkoutSession = CheckoutSessionAPI(this);
|
|
676
|
-
}
|
|
677
|
-
/** @internal */
|
|
678
|
-
_getConfig() {
|
|
679
|
-
return {
|
|
680
|
-
monimeSpaceId: this.monimeSpaceId,
|
|
681
|
-
accessToken: this.accessToken
|
|
682
|
-
};
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
|
|
686
|
-
// src/index.ts
|
|
687
|
-
function createClient(options) {
|
|
688
|
-
return new MonimeClient(options);
|
|
689
|
-
}
|
|
690
|
-
export {
|
|
691
|
-
MonimeClient,
|
|
692
|
-
createClient
|
|
693
|
-
};
|
|
694
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import{randomBytes as Se}from"crypto";import d from"axios";var Oe=Se(20).toString("hex"),P="https://api.monime.io/v1/checkout-sessions";async function v(r,e,o,s,n,t,i,u,m,p){let{monimeSpaceId:E,accessToken:b,monimeVersion:M}=r._getConfig(),Me={name:e,description:i,cancelUrl:t,successUrl:n,callbackState:null,reference:null,financialAccountId:u,lineItems:[{type:"custom",name:e,price:{currency:"SLE",value:o},quantity:s,reference:null,description:i,images:p}],paymentOptions:{card:{disable:!1},bank:{disable:!1,enabledProviders:["slb001","slb004","slb007"]},momo:{disable:!1,enabledProviders:["m17","m18"]},wallet:{disable:!1,enabledProviders:["dw001"]}},brandingOptions:{primaryColor:m},metadata:{}};try{return{success:!0,data:(await d.post(P,Me,{headers:{"Monime-Space-Id":E,Authorization:`Bearer ${b}`,"Content-Type":"application/json","Idempotency-Key":Oe,...M?{"Monime-Version":M}:{}}})).data}}catch(S){return d.isAxiosError(S)?{error:S,success:!1}:{error:new Error("unknown error"),success:!1}}}async function G(r){let{accessToken:e,monimeSpaceId:o,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await d.get(P,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${e}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return d.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}async function V(r,e){let{accessToken:o,monimeSpaceId:s,monimeVersion:n}=r._getConfig();try{return{success:!0,data:(await d.get(`${P}/${e}`,{headers:{"Monime-Space-Id":s,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data}}catch(t){return d.isAxiosError(t)?{error:t,success:!1}:{error:new Error("unknown error"),success:!1}}}async function F(r,e){let{accessToken:o,monimeSpaceId:s,monimeVersion:n}=r._getConfig();try{return await d.delete(`${P}/${e}`,{headers:{"Monime-Space-Id":s,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(t){return d.isAxiosError(t)?{error:t,success:!1}:{error:new Error("unknown error"),success:!1}}}function D(r){return{create:(e,o,s,n,t,i,u,m,p)=>v(r,e,o,s,n,t,i,u,m,p),get:()=>G(r),getOne:e=>V(r,e),delete:e=>F(r,e)}}import{randomBytes as $e}from"crypto";import h from"axios";var O="https://api.monime.io/v1/financial-accounts",ve=$e(20).toString("hex");async function B(r,e,o){if(r.trim()==="")return{success:!1,error:new Error("accountName is required")};let s={name:r,currency:e,description:"",metadata:{}},{accessToken:n,monimeSpaceId:t,monimeVersion:i}=o._getConfig();try{return{success:!0,data:(await h.post(O,s,{headers:{"Idempotency-Key":`${ve}`,"Monime-Space-Id":`${t}`,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...i?{"Monime-Version":i}:{}}})).data}}catch(u){return h.isAxiosError(u)?{error:u,success:!1}:{error:new Error("unknown error"),success:!1}}}async function U(r,e){if(r.trim()==="")return{success:!1,error:new Error("financialAccountId is required")};let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await h.get(`${O}/${r}`,{headers:{"Monime-Space-Id":`${o}`,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(t){return h.isAxiosError(t)?{error:t,success:!1}:{error:new Error("unknown error"),success:!1}}}async function W(r){let{monimeSpaceId:e,accessToken:o,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await h.get(O,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${o}`}})).data}}catch(n){return h.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}function z(r){return{create:(e,o)=>B(e,o,r),get:e=>U(e,r),getAll:()=>W(r)}}import w from"axios";var _="https://api.monime.io/v1/financial-transactions";async function K(r){let{monimeSpaceId:e,accessToken:o,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await w.get(_,{headers:{Authorization:`Bearer ${o}`,"Monime-Space-Id":`${e}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return w.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}async function L(r,e){let{accessToken:o,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 w.get(`${_}/${e}`,{headers:{Authorization:`Bearer ${o}`,"Monime-Space-Id":`${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(t){return w.isAxiosError(t)?{error:t,success:!1}:{error:new Error("unknown error"),success:!1}}}function q(r){return{get:e=>L(r,e),getAll:()=>K(r)}}import{randomBytes as Ge}from"crypto";import g from"axios";var T="https://api.monime.io/v1/internal-transfers",Ve=Ge(20).toString("hex");async function N(r,e,o,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:t,monimeSpaceId:i,monimeVersion:u}=o._getConfig();try{return{success:!0,data:(await g.post(T,n,{headers:{"Idempotency-Key":`${Ve}`,"Monime-Space-Id":`${i}`,Authorization:`Bearer ${t}`,"Content-Type":"application/json",...u?{"Monime-Version":u}:{}}})).data}}catch(m){return g.isAxiosError(m)?{error:m,success:!1}:{error:new Error("unkknown error"),success:!1}}}async function j(r){let{monimeSpaceId:e,accessToken:o,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await g.get(T,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${o}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return g.isAxiosError(n)?{success:!1,error:n}:{error:new Error("unkknown error"),success:!1}}}async function H(r,e){let{accessToken:o,monimeSpaceId:s,monimeVersion:n}=r._getConfig();try{return{success:!0,data:(await g.get(`${T}/${e}`,{headers:{"Monime-Space-Id":`${s}`,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data}}catch(t){return g.isAxiosError(t)?{success:!1,error:t}:{error:new Error("unkknown error"),success:!1}}}async function J(r,e){let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=r._getConfig();try{return await g.delete(`${T}/${e}`,{headers:{"Monime-Space-Id":`${o}`,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(t){return g.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("unknown error")}}}function Q(r){return{create:(e,o,s)=>N(e,o,r,s),get:e=>H(r,e),getAll:()=>j(r),delete:e=>J(r,e)}}import{randomBytes as Fe}from"crypto";import A from"axios";var $="https://api.monime.io/v1/payments";async function X(r,e){if(!r)return{success:!1,error:new Error("paymentId is required")};let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await A.get(`${$}/${r}`,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(t){return A.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("Unknown error")}}}async function Y(r,e){let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=r._getConfig();try{return{success:!0,data:(await A.get($,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}},params:e})).data}}catch(t){return A.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("Unknown error")}}}async function Z(r,e,o){if(!r)return{success:!1,error:new Error("paymentId is required")};let{monimeSpaceId:s,accessToken:n,monimeVersion:t}=o._getConfig(),i=Fe(20).toString("hex");try{return{success:!0,data:(await A.patch(`${$}/${r}`,e,{headers:{"Idempotency-Key":i,"Monime-Space-Id":s,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...t?{"Monime-Version":t}:{}}})).data}}catch(u){return A.isAxiosError(u)?{success:!1,error:u}:{success:!1,error:new Error("Unknown error")}}}function ee(r){return{get:e=>X(e,r),getAll:e=>Y(r,e),patch:(e,o)=>Z(e,o,r)}}import{randomBytes as De}from"crypto";import f from"axios";var re=De(20).toString("hex"),I="https://api.monime.io/v1/payment-codes";async function ne(r,e,o,s,n,t){let i=null;if(o!==""&&(i=o),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:u,monimeSpaceId:m,monimeVersion:p}=t._getConfig(),E={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 f.post(I,E,{headers:{"Idempotency-Key":`${re}`,"Monime-Space-Id":`${m}`,Authorization:`Bearer ${u}`,"Content-Type":"application/json",...p?{"Monime-Version":p}:{}}})).data,success:!0}}catch(b){return f.isAxiosError(b)?{error:b.response?.data,success:!1}:{error:new Error("unknown error"),success:!1}}}async function te(r,e){let{accessToken:o,monimeSpaceId:s,monimeVersion:n}=e._getConfig();if(r.trim()==="")return{success:!1,error:new Error("paymentCodeId is required")};try{return await f.delete(`${I}/${r}`,{headers:{"Idempotency-Key":`${re}`,"Monime-Space-Id":`${s}`,Authorization:`Bearer ${o}`,"Content-Type":"application/json",...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(t){return f.isAxiosError(t)?{error:t,success:!1}:{error:new Error("unknown error"),success:!1}}}async function oe(r){let{monimeSpaceId:e,accessToken:o,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await f.get(I,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${o}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return f.isAxiosError(n)?{error:n,success:!1}:{error:new Error("unknown error"),success:!1}}}async function se(r,e){let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await f.get(`${I}/${r}`,{headers:{"Monime-Space-Id":`${o}`,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(t){return f.isAxiosError(t)?{error:t,success:!1}:{error:new Error("unknown error"),success:!1}}}function ie(r){return{create:(e,o,s,n,t)=>ne(e,o,s,n,t,r),delete:e=>te(e,r),getAll:()=>oe(r),get:e=>se(e,r)}}import{randomBytes as Be}from"crypto";import y from"axios";var k="https://api.monime.io/v1/payouts",Ue=Be(20).toString("hex");async function ae(r,e,o,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:t,monimeVersion:i}=s._getConfig(),u={amount:{currency:"SLE",value:r},source:{financialAccountId:e},destination:o,metadata:{}};try{return{success:!0,data:(await y.post(k,u,{headers:{"Idempotency-Key":`${Ue}`,"Monime-Space-Id":`${t}`,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...i?{"Monime-Version":i}:{}}})).data}}catch(m){return y.isAxiosError(m)?{success:!1,error:m}:{success:!1,error:new Error("unknown error")}}}async function ce(r){let{accessToken:e,monimeSpaceId:o,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await y.get(k,{headers:{"Monime-Space-Id":`${o}`,Authorization:`Bearer ${e}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return y.isAxiosError(n)?{success:!1,error:n}:{success:!1,error:new Error("unknown error")}}}async function ue(r,e){let{accessToken:o,monimeSpaceId:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await y.get(`${k}/${r}`,{headers:{"Monime-Space-Id":`${s}`,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}})).data}}catch(t){return y.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("unknown error")}}}async function me(r,e){let{accessToken:o,monimeSpaceId:s,monimeVersion:n}=e._getConfig();try{return await y.delete(`${k}/${r}`,{headers:{"Monime-Space-Id":`${s}`,Authorization:`Bearer ${o}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(t){return y.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("unknown error")}}}function le(r){return{create:(e,o,s)=>ae(e,s,o,r),get:()=>ce(r),getOne:e=>ue(e,r),delete:e=>me(e,r)}}import pe from"axios";var We="https://api.monime.io/v1/provider-kyc";async function de(r,e){let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await pe.get(`${We}/${r}`,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(t){return pe.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("Unknown error")}}}function ge(r){return{get:e=>de(e,r)}}import{randomBytes as ze}from"crypto";import R from"axios";var fe="https://api.monime.io/v1/receipts";async function ye(r,e){let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await R.get(`${fe}/${r}`,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(t){return R.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("Unknown error")}}}async function he(r,e,o){let{monimeSpaceId:s,accessToken:n,monimeVersion:t}=o._getConfig(),i=ze(20).toString("hex");try{return{success:!0,data:(await R.post(`${fe}/${r}/redeem`,e,{headers:{"Idempotency-Key":i,"Monime-Space-Id":s,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...t?{"Monime-Version":t}:{}}})).data}}catch(u){return R.isAxiosError(u)?{success:!1,error:u}:{success:!1,error:new Error("Unknown error")}}}function Ae(r){return{get:e=>ye(e,r),redeem:(e,o={})=>he(e,o,r)}}import{randomBytes as _e}from"crypto";import be from"axios";var Ke="https://api.monime.io/v1/ussd-otps";async function Ce(r,e){let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=e._getConfig(),t=_e(20).toString("hex");try{return{success:!0,data:(await be.post(Ke,r,{headers:{"Idempotency-Key":t,"Monime-Space-Id":o,Authorization:`Bearer ${s}`,"Content-Type":"application/json",...n?{"Monime-Version":n}:{}}})).data}}catch(i){return be.isAxiosError(i)?{success:!1,error:i}:{success:!1,error:new Error("Unknown error")}}}function Pe(r){return{create:e=>Ce(e,r)}}import{randomBytes as we}from"crypto";import l from"axios";var C="https://api.monime.io/v1/webhooks";async function Te(r,e){let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=e._getConfig(),t=we(20).toString("hex");try{return{success:!0,data:(await l.post(C,r,{headers:{"Idempotency-Key":t,"Monime-Space-Id":o,Authorization:`Bearer ${s}`,"Content-Type":"application/json",...n?{"Monime-Version":n}:{}}})).data}}catch(i){return l.isAxiosError(i)?{success:!1,error:i}:{success:!1,error:new Error("Unknown error")}}}async function Ie(r,e){let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=e._getConfig();try{return{success:!0,data:(await l.get(`${C}/${r}`,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}})).data}}catch(t){return l.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("Unknown error")}}}async function ke(r){let{monimeSpaceId:e,accessToken:o,monimeVersion:s}=r._getConfig();try{return{success:!0,data:(await l.get(C,{headers:{"Monime-Space-Id":e,Authorization:`Bearer ${o}`,...s?{"Monime-Version":s}:{}}})).data}}catch(n){return l.isAxiosError(n)?{success:!1,error:n}:{success:!1,error:new Error("Unknown error")}}}async function Re(r,e,o){let{monimeSpaceId:s,accessToken:n,monimeVersion:t}=o._getConfig(),i=we(20).toString("hex");try{return{success:!0,data:(await l.patch(`${C}/${r}`,e,{headers:{"Idempotency-Key":i,"Monime-Space-Id":s,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...t?{"Monime-Version":t}:{}}})).data}}catch(u){return l.isAxiosError(u)?{success:!1,error:u}:{success:!1,error:new Error("Unknown error")}}}async function xe(r,e){let{monimeSpaceId:o,accessToken:s,monimeVersion:n}=e._getConfig();try{return await l.delete(`${C}/${r}`,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${s}`,...n?{"Monime-Version":n}:{}}}),{success:!0}}catch(t){return l.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("Unknown error")}}}function Ee(r){return{create:e=>Te(e,r),get:e=>Ie(e,r),getAll:()=>ke(r),update:(e,o)=>Re(e,o,r),delete:e=>xe(e,r)}}var x=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=z(this),this.internalTransfer=Q(this),this.paymentCode=ie(this),this.payment=ee(this),this.payout=le(this),this.providerKyc=ge(this),this.receipt=Ae(this),this.ussdOtp=Pe(this),this.webhook=Ee(this),this.financialTransaction=q(this),this.checkoutSession=D(this)}_getConfig(){return{monimeSpaceId:this.monimeSpaceId,accessToken:this.accessToken,monimeVersion:this.monimeVersion}}};function Nn(r){return new x(r)}export{x as MonimeClient,Nn as createClient};
|