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