@applite/duticotac-react 0.0.4 → 0.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/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +321 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +370 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { TransactionModel, DuticotacSDK, PaymentProvider, CoreApp, PlatformType } from '@applite/duticotac';
|
|
4
|
+
export * from '@applite/duticotac';
|
|
4
5
|
import { ClassValue } from 'clsx';
|
|
5
6
|
|
|
6
7
|
interface DuticotacPaymentModalProps {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { TransactionModel, DuticotacSDK, PaymentProvider, CoreApp, PlatformType } from '@applite/duticotac';
|
|
4
|
+
export * from '@applite/duticotac';
|
|
4
5
|
import { ClassValue } from 'clsx';
|
|
5
6
|
|
|
6
7
|
interface DuticotacPaymentModalProps {
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
};
|
|
9
12
|
var __export = (target, all) => {
|
|
10
13
|
for (var name in all)
|
|
11
14
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -18,6 +21,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
21
|
}
|
|
19
22
|
return to;
|
|
20
23
|
};
|
|
24
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
25
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
26
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
27
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -28,6 +32,318 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
32
|
));
|
|
29
33
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
34
|
|
|
35
|
+
// ../../node_modules/.pnpm/@applite+duticotac@0.0.3/node_modules/@applite/duticotac/dist/index.js
|
|
36
|
+
var require_dist = __commonJS({
|
|
37
|
+
"../../node_modules/.pnpm/@applite+duticotac@0.0.3/node_modules/@applite/duticotac/dist/index.js"(exports2, module2) {
|
|
38
|
+
"use strict";
|
|
39
|
+
var __defProp2 = Object.defineProperty;
|
|
40
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
41
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
42
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
43
|
+
var __export2 = (target, all) => {
|
|
44
|
+
for (var name in all)
|
|
45
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
46
|
+
};
|
|
47
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
48
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
49
|
+
for (let key of __getOwnPropNames2(from))
|
|
50
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
51
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
52
|
+
}
|
|
53
|
+
return to;
|
|
54
|
+
};
|
|
55
|
+
var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
56
|
+
var index_exports2 = {};
|
|
57
|
+
__export2(index_exports2, {
|
|
58
|
+
BalanceModule: () => BalanceModule,
|
|
59
|
+
DuticotacError: () => DuticotacError2,
|
|
60
|
+
DuticotacSDK: () => DuticotacSDK2,
|
|
61
|
+
ERROR_MESSAGES: () => ERROR_MESSAGES,
|
|
62
|
+
HttpClient: () => HttpClient,
|
|
63
|
+
MobileMoneyModule: () => MobileMoneyModule,
|
|
64
|
+
OfferModule: () => OfferModule,
|
|
65
|
+
PaymentMethodModule: () => PaymentMethodModule,
|
|
66
|
+
TransactionModule: () => TransactionModule,
|
|
67
|
+
WebhookModule: () => WebhookModule,
|
|
68
|
+
getErrorMessage: () => getErrorMessage2,
|
|
69
|
+
getProviderLogo: () => getProviderLogo2,
|
|
70
|
+
getProviderName: () => getProviderName2
|
|
71
|
+
});
|
|
72
|
+
module2.exports = __toCommonJS2(index_exports2);
|
|
73
|
+
var ERROR_MESSAGES = {
|
|
74
|
+
"payment-failed": "\xC9chec du paiement",
|
|
75
|
+
"ref-or-idFromClient-required": "R\xE9f\xE9rence ou IDFromClient requis",
|
|
76
|
+
"product-not-found": "Produit non trouv\xE9",
|
|
77
|
+
"no-api-key": "Cl\xE9 API non fournie",
|
|
78
|
+
"phone-required": "Num\xE9ro de t\xE9l\xE9phone requis",
|
|
79
|
+
"iap-not-available": "Les achats in-app ne sont pas disponibles.",
|
|
80
|
+
"iap-purchase-failed": "Echec de l'achat",
|
|
81
|
+
"otp-required": "Code OTP requis pour les paiements Orange Money",
|
|
82
|
+
"app-not-found": "Application non trouv\xE9e dans AppLite UI",
|
|
83
|
+
"duticotac-setting-not-found": "Configuration Duticotac non trouv\xE9e",
|
|
84
|
+
"payment-method-not-activated": "M\xE9thode de paiement non activ\xE9e",
|
|
85
|
+
"no-provider-found": "M\xE9thode de paiement non activ\xE9e",
|
|
86
|
+
"customer-not-found": "Client non trouv\xE9",
|
|
87
|
+
"invalid-plateform": "Plateforme invalide",
|
|
88
|
+
"unknown-error": "Une erreur inconnue est survenue",
|
|
89
|
+
"reference-required": "R\xE9f\xE9rence requise",
|
|
90
|
+
"polling-timeout": "Temps d'attente de la transaction expir\xE9",
|
|
91
|
+
"payment-cancelled": "Paiement annul\xE9",
|
|
92
|
+
"wait-before-retry": "Veuillez attendre avant de r\xE9essayer",
|
|
93
|
+
"context-not-mounted": "Contexte non mont\xE9",
|
|
94
|
+
"show-modal-bottom-sheet-error": "Erreur lors de l'affichage de la fen\xEAtre modale"
|
|
95
|
+
};
|
|
96
|
+
function getErrorMessage2(code) {
|
|
97
|
+
return ERROR_MESSAGES[code] ?? ERROR_MESSAGES["unknown-error"];
|
|
98
|
+
}
|
|
99
|
+
var DuticotacError2 = class extends Error {
|
|
100
|
+
constructor(code, message) {
|
|
101
|
+
super(message ?? getErrorMessage2(code));
|
|
102
|
+
this.code = code;
|
|
103
|
+
this.name = "DuticotacError";
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var DEFAULT_BASE_URL = "https://api.applite.freddydro.dev";
|
|
107
|
+
var HttpClient = class {
|
|
108
|
+
constructor(config = {}) {
|
|
109
|
+
this.baseUrl = config.baseUrl?.replace(/\/$/, "") ?? DEFAULT_BASE_URL;
|
|
110
|
+
this.headers = config.headers ?? {};
|
|
111
|
+
this.fetchImpl = config.fetchFn ?? fetch;
|
|
112
|
+
this.apiKey = config.apiKey;
|
|
113
|
+
this.appId = config.appId;
|
|
114
|
+
}
|
|
115
|
+
async post(path, body) {
|
|
116
|
+
const mergedBody = {
|
|
117
|
+
...this.apiKey ? { apiKey: this.apiKey } : {},
|
|
118
|
+
...this.appId !== void 0 ? { appId: this.appId } : {},
|
|
119
|
+
...body
|
|
120
|
+
};
|
|
121
|
+
const url = `${this.baseUrl}${path}`;
|
|
122
|
+
const response = await this.fetchImpl(url, {
|
|
123
|
+
method: "POST",
|
|
124
|
+
headers: {
|
|
125
|
+
"Content-Type": "application/json",
|
|
126
|
+
...this.headers
|
|
127
|
+
},
|
|
128
|
+
body: JSON.stringify(mergedBody)
|
|
129
|
+
});
|
|
130
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
131
|
+
const isJson = contentType.includes("application/json");
|
|
132
|
+
const payload = isJson ? await response.json() : null;
|
|
133
|
+
if (!response.ok) {
|
|
134
|
+
const errorCode = typeof payload?.error === "string" ? payload.error : "unknown-error";
|
|
135
|
+
throw new DuticotacError2(
|
|
136
|
+
errorCode,
|
|
137
|
+
`Request failed with status ${response.status}: ${payload?.error ?? response.statusText}`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
if (!payload || payload.success !== true) {
|
|
141
|
+
const errorCode = typeof payload?.error === "string" ? payload.error : "unknown-error";
|
|
142
|
+
throw new DuticotacError2(errorCode);
|
|
143
|
+
}
|
|
144
|
+
return payload;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var BalanceModule = class {
|
|
148
|
+
constructor(http) {
|
|
149
|
+
this.http = http;
|
|
150
|
+
}
|
|
151
|
+
balance(params = {}) {
|
|
152
|
+
return this.http.post("/duticotac/balance", params);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var OfferModule = class {
|
|
156
|
+
constructor(http) {
|
|
157
|
+
this.http = http;
|
|
158
|
+
}
|
|
159
|
+
create(params) {
|
|
160
|
+
return this.http.post("/duticotac/offer/create", params);
|
|
161
|
+
}
|
|
162
|
+
list(params = {}) {
|
|
163
|
+
return this.http.post("/duticotac/offer/list", params);
|
|
164
|
+
}
|
|
165
|
+
get(params) {
|
|
166
|
+
const { ref, ...body } = params;
|
|
167
|
+
return this.http.post(`/duticotac/offer/${ref}`, body);
|
|
168
|
+
}
|
|
169
|
+
update(params) {
|
|
170
|
+
const { ref, ...body } = params;
|
|
171
|
+
return this.http.post(`/duticotac/offer/${ref}/edit`, body);
|
|
172
|
+
}
|
|
173
|
+
delete(params) {
|
|
174
|
+
const { ref, ...body } = params;
|
|
175
|
+
return this.http.post(`/duticotac/offer/${ref}/delete`, body);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var MobileMoneyModule = class {
|
|
179
|
+
constructor(http) {
|
|
180
|
+
this.http = http;
|
|
181
|
+
}
|
|
182
|
+
cashin(params) {
|
|
183
|
+
return this.http.post(
|
|
184
|
+
"/duticotac/pay/mobile-money/cashin",
|
|
185
|
+
params
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
cashout(params) {
|
|
189
|
+
if (params.paymentMethod === "OM_CI" && !params.otp) {
|
|
190
|
+
throw new DuticotacError2("otp-required");
|
|
191
|
+
}
|
|
192
|
+
if (!params.ref && !params.idFromClient) {
|
|
193
|
+
throw new DuticotacError2("ref-or-idFromClient-required");
|
|
194
|
+
}
|
|
195
|
+
return this.http.post(
|
|
196
|
+
"/duticotac/pay/mobile-money/cashout",
|
|
197
|
+
params
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
handleCashinWebhook(params) {
|
|
201
|
+
return this.http.post("/duticotac/pay/mobile-money/cashin/webhook", params);
|
|
202
|
+
}
|
|
203
|
+
handleCashoutWebhook(params) {
|
|
204
|
+
return this.http.post(
|
|
205
|
+
"/duticotac/pay/mobile-money/cashout/webhook",
|
|
206
|
+
params
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var PaymentMethodModule = class {
|
|
211
|
+
constructor(http) {
|
|
212
|
+
this.http = http;
|
|
213
|
+
}
|
|
214
|
+
get(params = {}) {
|
|
215
|
+
return this.http.post(
|
|
216
|
+
"/duticotac/payment-method",
|
|
217
|
+
params
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
set(params) {
|
|
221
|
+
return this.http.post(
|
|
222
|
+
"/duticotac/payment-method/set",
|
|
223
|
+
params
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
var WebhookModule = class {
|
|
228
|
+
constructor(http) {
|
|
229
|
+
this.http = http;
|
|
230
|
+
}
|
|
231
|
+
get(params = {}) {
|
|
232
|
+
return this.http.post("/duticotac/webhook", params);
|
|
233
|
+
}
|
|
234
|
+
set(params) {
|
|
235
|
+
return this.http.post("/duticotac/webhook/set", params);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
function backoff(attempt) {
|
|
239
|
+
switch (attempt) {
|
|
240
|
+
case 1:
|
|
241
|
+
return 1e3;
|
|
242
|
+
case 2:
|
|
243
|
+
return 2e3;
|
|
244
|
+
case 3:
|
|
245
|
+
return 3e3;
|
|
246
|
+
case 4:
|
|
247
|
+
return 5e3;
|
|
248
|
+
default:
|
|
249
|
+
return 8e3;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function delay(ms) {
|
|
253
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
254
|
+
}
|
|
255
|
+
var TransactionModule = class {
|
|
256
|
+
constructor(http) {
|
|
257
|
+
this.http = http;
|
|
258
|
+
}
|
|
259
|
+
get(params) {
|
|
260
|
+
return this.http.post(
|
|
261
|
+
"/duticotac/transaction/get",
|
|
262
|
+
params
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
async poll(id, options) {
|
|
266
|
+
const intervalMs = options?.intervalMs ?? 2e3;
|
|
267
|
+
const timeoutMs = options?.timeoutMs ?? 9e4;
|
|
268
|
+
const start = Date.now();
|
|
269
|
+
let attempt = 0;
|
|
270
|
+
while (true) {
|
|
271
|
+
attempt++;
|
|
272
|
+
const elapsed = Date.now() - start;
|
|
273
|
+
if (elapsed > timeoutMs) {
|
|
274
|
+
throw new DuticotacError2("polling-timeout");
|
|
275
|
+
}
|
|
276
|
+
if (options?.signal?.aborted) {
|
|
277
|
+
throw new DuticotacError2("payment-cancelled");
|
|
278
|
+
}
|
|
279
|
+
options?.onPoll?.(attempt, elapsed);
|
|
280
|
+
try {
|
|
281
|
+
const result = await this.get({ id });
|
|
282
|
+
const status = result.data?.status;
|
|
283
|
+
if (status === "CONFIRMED") return result;
|
|
284
|
+
if (status === "CANCELLED") throw new DuticotacError2("payment-cancelled");
|
|
285
|
+
if (status === "FAILED")
|
|
286
|
+
throw new DuticotacError2("payment-failed");
|
|
287
|
+
const wait = Math.max(backoff(attempt), intervalMs);
|
|
288
|
+
await delay(wait);
|
|
289
|
+
} catch (e) {
|
|
290
|
+
if (e instanceof DuticotacError2) throw e;
|
|
291
|
+
const wait = Math.max(backoff(attempt), intervalMs);
|
|
292
|
+
await delay(wait);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
function getProviderName2(provider) {
|
|
298
|
+
switch (provider) {
|
|
299
|
+
case "OM_CI":
|
|
300
|
+
return "Orange Money";
|
|
301
|
+
case "MTN_CI":
|
|
302
|
+
return "MTN Momo";
|
|
303
|
+
case "MOOV_CI":
|
|
304
|
+
return "Moov (Flooz)";
|
|
305
|
+
case "WAVE_CI":
|
|
306
|
+
return "Wave";
|
|
307
|
+
case "CREDIT_CARD":
|
|
308
|
+
return "Carte de cr\xE9dit";
|
|
309
|
+
case "CASH":
|
|
310
|
+
return "Esp\xE8ces";
|
|
311
|
+
case "IAP":
|
|
312
|
+
return "Achat Int\xE9gr\xE9";
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function getProviderLogo2(provider) {
|
|
316
|
+
switch (provider) {
|
|
317
|
+
case "OM_CI":
|
|
318
|
+
return "https://payto.freddydro.dev/images/OM.png";
|
|
319
|
+
case "MTN_CI":
|
|
320
|
+
return "https://payto.freddydro.dev/images/MTN.png";
|
|
321
|
+
case "MOOV_CI":
|
|
322
|
+
return "https://payto.freddydro.dev/images/MOOV.png";
|
|
323
|
+
case "WAVE_CI":
|
|
324
|
+
return "https://payto.freddydro.dev/images/WAVE.png";
|
|
325
|
+
case "CREDIT_CARD":
|
|
326
|
+
return "https://payto.freddydro.dev/images/CREDIT_CARD.png";
|
|
327
|
+
case "CASH":
|
|
328
|
+
return "https://payto.freddydro.dev/images/CASH.png";
|
|
329
|
+
case "IAP":
|
|
330
|
+
return "https://payto.freddydro.dev/images/IAP.png";
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
var DuticotacSDK2 = class {
|
|
334
|
+
constructor(config = {}) {
|
|
335
|
+
this.http = new HttpClient(config);
|
|
336
|
+
this.balance = new BalanceModule(this.http);
|
|
337
|
+
this.offer = new OfferModule(this.http);
|
|
338
|
+
this.mobileMoney = new MobileMoneyModule(this.http);
|
|
339
|
+
this.paymentMethod = new PaymentMethodModule(this.http);
|
|
340
|
+
this.webhook = new WebhookModule(this.http);
|
|
341
|
+
this.transaction = new TransactionModule(this.http);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
|
|
31
347
|
// src/index.ts
|
|
32
348
|
var index_exports = {};
|
|
33
349
|
__export(index_exports, {
|
|
@@ -49,10 +365,10 @@ module.exports = __toCommonJS(index_exports);
|
|
|
49
365
|
|
|
50
366
|
// src/components/payment-modal.tsx
|
|
51
367
|
var React2 = __toESM(require("react"));
|
|
52
|
-
var import_duticotac2 =
|
|
368
|
+
var import_duticotac2 = __toESM(require_dist());
|
|
53
369
|
|
|
54
370
|
// src/components/provider-selector.tsx
|
|
55
|
-
var import_duticotac =
|
|
371
|
+
var import_duticotac = __toESM(require_dist());
|
|
56
372
|
|
|
57
373
|
// src/utils/cn.ts
|
|
58
374
|
var import_clsx = require("clsx");
|
|
@@ -961,6 +1277,9 @@ function useDuticotac(config) {
|
|
|
961
1277
|
Dialog: DialogElement
|
|
962
1278
|
};
|
|
963
1279
|
}
|
|
1280
|
+
|
|
1281
|
+
// src/index.ts
|
|
1282
|
+
__reExport(index_exports, __toESM(require_dist()), module.exports);
|
|
964
1283
|
// Annotate the CommonJS export names for ESM import in node:
|
|
965
1284
|
0 && (module.exports = {
|
|
966
1285
|
DuticotacPaymentModal,
|