@applite/duticotac-react 0.0.3 → 0.0.5

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