@cimplify/sdk 0.6.5 → 0.6.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/ads-t3FBTU8p.d.mts +20 -0
- package/dist/ads-t3FBTU8p.d.ts +20 -0
- package/dist/advanced.d.mts +25 -0
- package/dist/advanced.d.ts +25 -0
- package/dist/advanced.js +2639 -0
- package/dist/advanced.mjs +2617 -0
- package/dist/{ads-CmO7VVPP.d.mts → client-CUFdFugo.d.mts} +21 -193
- package/dist/{ads-CmO7VVPP.d.ts → client-CjqNbEM6.d.ts} +21 -193
- package/dist/index-B5Bj-Ikg.d.ts +325 -0
- package/dist/index-CJ9GkIXf.d.mts +325 -0
- package/dist/index.d.mts +7 -346
- package/dist/index.d.ts +7 -346
- package/dist/index.js +81 -6
- package/dist/index.mjs +81 -6
- package/dist/payment-D-u3asA8.d.mts +170 -0
- package/dist/payment-D-u3asA8.d.ts +170 -0
- package/dist/react.d.mts +29 -7
- package/dist/react.d.ts +29 -7
- package/dist/react.js +3421 -44
- package/dist/react.mjs +3420 -45
- package/dist/utils.d.mts +2 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +457 -0
- package/dist/utils.mjs +433 -0
- package/package.json +11 -1
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
// src/utils/price.ts
|
|
2
|
+
var CURRENCY_SYMBOLS = {
|
|
3
|
+
// Major world currencies
|
|
4
|
+
USD: "$",
|
|
5
|
+
EUR: "\u20AC",
|
|
6
|
+
GBP: "\xA3",
|
|
7
|
+
JPY: "\xA5",
|
|
8
|
+
CNY: "\xA5",
|
|
9
|
+
CHF: "CHF",
|
|
10
|
+
CAD: "C$",
|
|
11
|
+
AUD: "A$",
|
|
12
|
+
NZD: "NZ$",
|
|
13
|
+
HKD: "HK$",
|
|
14
|
+
SGD: "S$",
|
|
15
|
+
INR: "\u20B9",
|
|
16
|
+
BRL: "R$",
|
|
17
|
+
MXN: "MX$",
|
|
18
|
+
KRW: "\u20A9",
|
|
19
|
+
RUB: "\u20BD",
|
|
20
|
+
TRY: "\u20BA",
|
|
21
|
+
THB: "\u0E3F",
|
|
22
|
+
PLN: "z\u0142",
|
|
23
|
+
SEK: "kr",
|
|
24
|
+
NOK: "kr",
|
|
25
|
+
DKK: "kr",
|
|
26
|
+
CZK: "K\u010D",
|
|
27
|
+
HUF: "Ft",
|
|
28
|
+
ILS: "\u20AA",
|
|
29
|
+
AED: "\u062F.\u0625",
|
|
30
|
+
SAR: "\uFDFC",
|
|
31
|
+
MYR: "RM",
|
|
32
|
+
PHP: "\u20B1",
|
|
33
|
+
IDR: "Rp",
|
|
34
|
+
VND: "\u20AB",
|
|
35
|
+
TWD: "NT$",
|
|
36
|
+
// African currencies
|
|
37
|
+
GHS: "GH\u20B5",
|
|
38
|
+
NGN: "\u20A6",
|
|
39
|
+
KES: "KSh",
|
|
40
|
+
ZAR: "R",
|
|
41
|
+
XOF: "CFA",
|
|
42
|
+
XAF: "FCFA",
|
|
43
|
+
EGP: "E\xA3",
|
|
44
|
+
MAD: "MAD",
|
|
45
|
+
TZS: "TSh",
|
|
46
|
+
UGX: "USh",
|
|
47
|
+
RWF: "FRw",
|
|
48
|
+
ETB: "Br",
|
|
49
|
+
ZMW: "ZK",
|
|
50
|
+
BWP: "P",
|
|
51
|
+
MUR: "\u20A8",
|
|
52
|
+
SCR: "\u20A8",
|
|
53
|
+
NAD: "N$",
|
|
54
|
+
SZL: "E",
|
|
55
|
+
LSL: "L",
|
|
56
|
+
MWK: "MK",
|
|
57
|
+
AOA: "Kz",
|
|
58
|
+
CDF: "FC",
|
|
59
|
+
GMD: "D",
|
|
60
|
+
GNF: "FG",
|
|
61
|
+
LRD: "L$",
|
|
62
|
+
SLL: "Le",
|
|
63
|
+
MZN: "MT",
|
|
64
|
+
SDG: "SDG",
|
|
65
|
+
SSP: "SSP",
|
|
66
|
+
SOS: "Sh.So.",
|
|
67
|
+
DJF: "Fdj",
|
|
68
|
+
ERN: "Nfk",
|
|
69
|
+
CVE: "$",
|
|
70
|
+
STN: "Db",
|
|
71
|
+
KMF: "CF",
|
|
72
|
+
BIF: "FBu"
|
|
73
|
+
};
|
|
74
|
+
function getCurrencySymbol(currencyCode) {
|
|
75
|
+
return CURRENCY_SYMBOLS[currencyCode.toUpperCase()] || currencyCode;
|
|
76
|
+
}
|
|
77
|
+
function formatNumberCompact(value, decimals = 1) {
|
|
78
|
+
const absValue = Math.abs(value);
|
|
79
|
+
const sign = value < 0 ? "-" : "";
|
|
80
|
+
if (absValue >= 1e9) {
|
|
81
|
+
return `${sign}${(absValue / 1e9).toFixed(decimals)}B`;
|
|
82
|
+
}
|
|
83
|
+
if (absValue >= 1e6) {
|
|
84
|
+
return `${sign}${(absValue / 1e6).toFixed(decimals)}M`;
|
|
85
|
+
}
|
|
86
|
+
if (absValue >= 1e3) {
|
|
87
|
+
return `${sign}${(absValue / 1e3).toFixed(decimals)}K`;
|
|
88
|
+
}
|
|
89
|
+
return `${sign}${absValue.toFixed(decimals)}`;
|
|
90
|
+
}
|
|
91
|
+
function formatPrice(amount, currency = "GHS", locale = "en-US") {
|
|
92
|
+
const numAmount = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
93
|
+
if (isNaN(numAmount)) {
|
|
94
|
+
return `${getCurrencySymbol(currency)}0.00`;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
return new Intl.NumberFormat(locale, {
|
|
98
|
+
style: "currency",
|
|
99
|
+
currency: currency.toUpperCase(),
|
|
100
|
+
minimumFractionDigits: 2,
|
|
101
|
+
maximumFractionDigits: 2
|
|
102
|
+
}).format(numAmount);
|
|
103
|
+
} catch {
|
|
104
|
+
return `${getCurrencySymbol(currency)}${numAmount.toFixed(2)}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function formatPriceAdjustment(amount, currency = "GHS", locale = "en-US") {
|
|
108
|
+
const formatted = formatPrice(Math.abs(amount), currency, locale);
|
|
109
|
+
if (amount > 0) {
|
|
110
|
+
return `+${formatted}`;
|
|
111
|
+
} else if (amount < 0) {
|
|
112
|
+
return `-${formatted}`;
|
|
113
|
+
}
|
|
114
|
+
return formatted;
|
|
115
|
+
}
|
|
116
|
+
function formatPriceCompact(amount, currency = "GHS", decimals = 1) {
|
|
117
|
+
const numAmount = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
118
|
+
if (isNaN(numAmount)) {
|
|
119
|
+
return `${getCurrencySymbol(currency)}0`;
|
|
120
|
+
}
|
|
121
|
+
const symbol = getCurrencySymbol(currency);
|
|
122
|
+
if (Math.abs(numAmount) < 1e3) {
|
|
123
|
+
return `${symbol}${numAmount.toFixed(2)}`;
|
|
124
|
+
}
|
|
125
|
+
return `${symbol}${formatNumberCompact(numAmount, decimals)}`;
|
|
126
|
+
}
|
|
127
|
+
function formatMoney(amount, currency = "GHS") {
|
|
128
|
+
const symbol = getCurrencySymbol(currency);
|
|
129
|
+
const numAmount = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
130
|
+
if (isNaN(numAmount)) {
|
|
131
|
+
return `${symbol}0.00`;
|
|
132
|
+
}
|
|
133
|
+
return `${symbol}${numAmount.toFixed(2)}`;
|
|
134
|
+
}
|
|
135
|
+
function parsePrice(value) {
|
|
136
|
+
if (value === void 0 || value === null) {
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
if (typeof value === "number") {
|
|
140
|
+
return isNaN(value) ? 0 : value;
|
|
141
|
+
}
|
|
142
|
+
const cleaned = value.replace(/[^\d.-]/g, "");
|
|
143
|
+
const parsed = parseFloat(cleaned);
|
|
144
|
+
return isNaN(parsed) ? 0 : parsed;
|
|
145
|
+
}
|
|
146
|
+
function getDisplayPrice(product) {
|
|
147
|
+
if (product.price_info) {
|
|
148
|
+
return parsePrice(product.price_info.final_price);
|
|
149
|
+
}
|
|
150
|
+
if (product.final_price !== void 0 && product.final_price !== null) {
|
|
151
|
+
return parsePrice(product.final_price);
|
|
152
|
+
}
|
|
153
|
+
if (product.default_price !== void 0 && product.default_price !== null) {
|
|
154
|
+
return parsePrice(product.default_price);
|
|
155
|
+
}
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
function getBasePrice(product) {
|
|
159
|
+
if (product.price_info) {
|
|
160
|
+
return parsePrice(product.price_info.base_price);
|
|
161
|
+
}
|
|
162
|
+
if (product.base_price !== void 0 && product.base_price !== null) {
|
|
163
|
+
return parsePrice(product.base_price);
|
|
164
|
+
}
|
|
165
|
+
if (product.default_price !== void 0 && product.default_price !== null) {
|
|
166
|
+
return parsePrice(product.default_price);
|
|
167
|
+
}
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
170
|
+
function isOnSale(product) {
|
|
171
|
+
const basePrice = getBasePrice(product);
|
|
172
|
+
const finalPrice = getDisplayPrice(product);
|
|
173
|
+
return basePrice > finalPrice && basePrice > 0;
|
|
174
|
+
}
|
|
175
|
+
function getDiscountPercentage(product) {
|
|
176
|
+
const basePrice = getBasePrice(product);
|
|
177
|
+
const finalPrice = getDisplayPrice(product);
|
|
178
|
+
if (basePrice > finalPrice && basePrice > 0) {
|
|
179
|
+
return Math.round((basePrice - finalPrice) / basePrice * 100);
|
|
180
|
+
}
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
function getMarkupPercentage(product) {
|
|
184
|
+
const basePrice = getBasePrice(product);
|
|
185
|
+
const finalPrice = getDisplayPrice(product);
|
|
186
|
+
if (finalPrice > basePrice && basePrice > 0) {
|
|
187
|
+
return Math.round((finalPrice - basePrice) / basePrice * 100);
|
|
188
|
+
}
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
function getProductCurrency(product) {
|
|
192
|
+
if (product.price_info?.currency) {
|
|
193
|
+
return product.price_info.currency;
|
|
194
|
+
}
|
|
195
|
+
if (product.currency) {
|
|
196
|
+
return product.currency;
|
|
197
|
+
}
|
|
198
|
+
return "GHS";
|
|
199
|
+
}
|
|
200
|
+
function formatProductPrice(product, locale = "en-US") {
|
|
201
|
+
const price = getDisplayPrice(product);
|
|
202
|
+
const currency = getProductCurrency(product);
|
|
203
|
+
return formatPrice(price, currency, locale);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/utils/payment.ts
|
|
207
|
+
function categorizePaymentError(error, errorCode) {
|
|
208
|
+
let message = "An unexpected error occurred during payment processing. Please try again or contact support.";
|
|
209
|
+
let recoverable = true;
|
|
210
|
+
let code = errorCode || "PAYMENT_ERROR";
|
|
211
|
+
const technical = error.stack;
|
|
212
|
+
const errorMessage = error.message?.toLowerCase() || "";
|
|
213
|
+
if (errorCode === "INSUFFICIENT_FUNDS" || errorMessage.includes("insufficient") || errorMessage.includes("funds")) {
|
|
214
|
+
code = "INSUFFICIENT_FUNDS";
|
|
215
|
+
message = "Your payment method has insufficient funds. Please try another payment method.";
|
|
216
|
+
} else if (errorCode === "CARD_DECLINED" || errorMessage.includes("declined")) {
|
|
217
|
+
code = "CARD_DECLINED";
|
|
218
|
+
message = "Your card was declined. Please try another card or payment method.";
|
|
219
|
+
} else if (errorMessage.includes("cancelled") || errorMessage.includes("canceled") || errorCode === "PAYMENT_CANCELLED") {
|
|
220
|
+
code = "PAYMENT_CANCELLED";
|
|
221
|
+
message = "Payment was cancelled. You can try again when ready.";
|
|
222
|
+
} else if (errorMessage.includes("network") || errorMessage.includes("connection") || errorCode === "NETWORK_ERROR") {
|
|
223
|
+
code = "NETWORK_ERROR";
|
|
224
|
+
message = "Network connection issue. Please check your internet connection and try again.";
|
|
225
|
+
} else if (errorMessage.includes("timeout") || errorCode === "TIMEOUT") {
|
|
226
|
+
code = "TIMEOUT";
|
|
227
|
+
message = "Payment processing timed out. Please try again.";
|
|
228
|
+
} else if (errorCode === "PAYMENT_ACTION_NOT_COMPLETED") {
|
|
229
|
+
code = "PAYMENT_ACTION_NOT_COMPLETED";
|
|
230
|
+
message = "Payment action was not completed. Please try again.";
|
|
231
|
+
} else if (errorCode === "AUTHORIZATION_FAILED") {
|
|
232
|
+
code = "AUTHORIZATION_FAILED";
|
|
233
|
+
message = "Authorization failed. Please check your code and try again.";
|
|
234
|
+
} else if (errorCode === "INVALID_OTP") {
|
|
235
|
+
code = "INVALID_OTP";
|
|
236
|
+
message = "Invalid verification code. Please check and try again.";
|
|
237
|
+
}
|
|
238
|
+
return { code, message, recoverable, technical };
|
|
239
|
+
}
|
|
240
|
+
function isQuickPaymentResponse(response) {
|
|
241
|
+
return response !== null && typeof response === "object" && "payment" in response && typeof response.payment === "object";
|
|
242
|
+
}
|
|
243
|
+
function isWebPaymentResponse(response) {
|
|
244
|
+
return response !== null && typeof response === "object" && "transaction" in response && typeof response.transaction === "object";
|
|
245
|
+
}
|
|
246
|
+
function normalizePaymentResponse(response) {
|
|
247
|
+
if (!response) {
|
|
248
|
+
return {
|
|
249
|
+
method: "unknown",
|
|
250
|
+
provider: "unknown",
|
|
251
|
+
requires_action: false,
|
|
252
|
+
metadata: {}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
if (isQuickPaymentResponse(response)) {
|
|
256
|
+
return {
|
|
257
|
+
method: response.payment.type?.toLowerCase() || "unknown",
|
|
258
|
+
provider: response.payment.provider?.toLowerCase() || "unknown",
|
|
259
|
+
requires_action: !!response.payment.redirect_url || !!response.payment.access_code,
|
|
260
|
+
public_key: response.payment.public_key,
|
|
261
|
+
client_secret: response.payment.access_code,
|
|
262
|
+
access_code: response.payment.access_code,
|
|
263
|
+
redirect_url: response.payment.redirect_url,
|
|
264
|
+
transaction_id: response.payment.reference,
|
|
265
|
+
order_id: response.order_id,
|
|
266
|
+
reference: response.payment.reference,
|
|
267
|
+
instructions: response.payment.instructions,
|
|
268
|
+
metadata: response.payment.metadata
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
if (isWebPaymentResponse(response)) {
|
|
272
|
+
const authType = response.authorization_type?.toLowerCase();
|
|
273
|
+
const validAuthTypes = ["otp", "pin", "phone", "birthday", "address"];
|
|
274
|
+
const safeAuthType = authType && validAuthTypes.includes(authType) ? authType : void 0;
|
|
275
|
+
return {
|
|
276
|
+
provider: response.transaction.provider_type?.toLowerCase() || "unknown",
|
|
277
|
+
requires_action: response.requires_action || false,
|
|
278
|
+
public_key: response.public_key,
|
|
279
|
+
client_secret: response.client_secret,
|
|
280
|
+
redirect_url: response.authorization_url,
|
|
281
|
+
transaction_id: response.transaction.id,
|
|
282
|
+
order_id: response.transaction.order_id,
|
|
283
|
+
reference: response.transaction.provider_reference,
|
|
284
|
+
metadata: response.transaction.metadata,
|
|
285
|
+
method: response.transaction.payment_method?.toLowerCase() || "unknown",
|
|
286
|
+
instructions: response.display_text,
|
|
287
|
+
display_text: response.display_text,
|
|
288
|
+
requires_authorization: response.requires_authorization,
|
|
289
|
+
authorization_type: safeAuthType,
|
|
290
|
+
provider_payment_id: response.provider_payment_id || response.transaction.provider_reference
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
method: "unknown",
|
|
295
|
+
provider: "unknown",
|
|
296
|
+
requires_action: false,
|
|
297
|
+
metadata: {}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
var PAYMENT_SUCCESS_STATUSES = /* @__PURE__ */ new Set([
|
|
301
|
+
"success",
|
|
302
|
+
"succeeded",
|
|
303
|
+
"paid",
|
|
304
|
+
"captured",
|
|
305
|
+
"completed",
|
|
306
|
+
"authorized"
|
|
307
|
+
]);
|
|
308
|
+
var PAYMENT_FAILURE_STATUSES = /* @__PURE__ */ new Set([
|
|
309
|
+
"failed",
|
|
310
|
+
"declined",
|
|
311
|
+
"cancelled",
|
|
312
|
+
"voided",
|
|
313
|
+
"error"
|
|
314
|
+
]);
|
|
315
|
+
var PAYMENT_REQUIRES_ACTION_STATUSES = /* @__PURE__ */ new Set([
|
|
316
|
+
"requires_action",
|
|
317
|
+
"requires_payment_method",
|
|
318
|
+
"requires_capture"
|
|
319
|
+
]);
|
|
320
|
+
var PAYMENT_STATUS_ALIAS_MAP = {
|
|
321
|
+
ok: "success",
|
|
322
|
+
done: "success",
|
|
323
|
+
paid: "paid",
|
|
324
|
+
paid_in_full: "paid",
|
|
325
|
+
paid_successfully: "paid",
|
|
326
|
+
succeeded: "success",
|
|
327
|
+
captured: "captured",
|
|
328
|
+
completed: "completed",
|
|
329
|
+
pending_confirmation: "pending_confirmation",
|
|
330
|
+
requires_authorization: "requires_action",
|
|
331
|
+
requires_action: "requires_action",
|
|
332
|
+
requires_payment_method: "requires_payment_method",
|
|
333
|
+
requires_capture: "requires_capture",
|
|
334
|
+
partially_paid: "partially_paid",
|
|
335
|
+
partially_refunded: "partially_refunded",
|
|
336
|
+
card_declined: "declined",
|
|
337
|
+
canceled: "cancelled",
|
|
338
|
+
authorized: "authorized",
|
|
339
|
+
cancelled: "cancelled",
|
|
340
|
+
unresolved: "pending"
|
|
341
|
+
};
|
|
342
|
+
var KNOWN_PAYMENT_STATUSES = /* @__PURE__ */ new Set([
|
|
343
|
+
"pending",
|
|
344
|
+
"processing",
|
|
345
|
+
"created",
|
|
346
|
+
"pending_confirmation",
|
|
347
|
+
"success",
|
|
348
|
+
"succeeded",
|
|
349
|
+
"failed",
|
|
350
|
+
"declined",
|
|
351
|
+
"authorized",
|
|
352
|
+
"refunded",
|
|
353
|
+
"partially_refunded",
|
|
354
|
+
"partially_paid",
|
|
355
|
+
"paid",
|
|
356
|
+
"unpaid",
|
|
357
|
+
"requires_action",
|
|
358
|
+
"requires_payment_method",
|
|
359
|
+
"requires_capture",
|
|
360
|
+
"captured",
|
|
361
|
+
"cancelled",
|
|
362
|
+
"completed",
|
|
363
|
+
"voided",
|
|
364
|
+
"error",
|
|
365
|
+
"unknown"
|
|
366
|
+
]);
|
|
367
|
+
function normalizeStatusToken(status) {
|
|
368
|
+
return status?.trim().toLowerCase().replace(/[\s-]+/g, "_") ?? "";
|
|
369
|
+
}
|
|
370
|
+
function normalizePaymentStatusValue(status) {
|
|
371
|
+
const normalized = normalizeStatusToken(status);
|
|
372
|
+
if (Object.prototype.hasOwnProperty.call(PAYMENT_STATUS_ALIAS_MAP, normalized)) {
|
|
373
|
+
return PAYMENT_STATUS_ALIAS_MAP[normalized];
|
|
374
|
+
}
|
|
375
|
+
return KNOWN_PAYMENT_STATUSES.has(normalized) ? normalized : "unknown";
|
|
376
|
+
}
|
|
377
|
+
function isPaymentStatusSuccess(status) {
|
|
378
|
+
const normalizedStatus = normalizePaymentStatusValue(status);
|
|
379
|
+
return PAYMENT_SUCCESS_STATUSES.has(normalizedStatus);
|
|
380
|
+
}
|
|
381
|
+
function isPaymentStatusFailure(status) {
|
|
382
|
+
const normalizedStatus = normalizePaymentStatusValue(status);
|
|
383
|
+
return PAYMENT_FAILURE_STATUSES.has(normalizedStatus);
|
|
384
|
+
}
|
|
385
|
+
function isPaymentStatusRequiresAction(status) {
|
|
386
|
+
const normalizedStatus = normalizePaymentStatusValue(status);
|
|
387
|
+
return PAYMENT_REQUIRES_ACTION_STATUSES.has(normalizedStatus);
|
|
388
|
+
}
|
|
389
|
+
function normalizeStatusResponse(response) {
|
|
390
|
+
if (!response || typeof response !== "object") {
|
|
391
|
+
return {
|
|
392
|
+
status: "pending",
|
|
393
|
+
paid: false,
|
|
394
|
+
message: "No status available"
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
const res = response;
|
|
398
|
+
const normalizedStatus = normalizePaymentStatusValue(res.status ?? void 0);
|
|
399
|
+
const paidValue = res.paid === true;
|
|
400
|
+
const derivedPaid = paidValue || [
|
|
401
|
+
"success",
|
|
402
|
+
"succeeded",
|
|
403
|
+
"paid",
|
|
404
|
+
"captured",
|
|
405
|
+
"authorized",
|
|
406
|
+
"completed"
|
|
407
|
+
].includes(normalizedStatus);
|
|
408
|
+
return {
|
|
409
|
+
status: normalizedStatus,
|
|
410
|
+
paid: derivedPaid,
|
|
411
|
+
amount: res.amount,
|
|
412
|
+
currency: res.currency,
|
|
413
|
+
reference: res.reference,
|
|
414
|
+
message: res.message || ""
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
var MOBILE_MONEY_PROVIDERS = {
|
|
418
|
+
mtn: { name: "MTN Mobile Money", prefix: ["024", "054", "055", "059"] },
|
|
419
|
+
vodafone: { name: "Vodafone Cash", prefix: ["020", "050"] },
|
|
420
|
+
airtel: { name: "AirtelTigo Money", prefix: ["027", "057", "026", "056"] }
|
|
421
|
+
};
|
|
422
|
+
function detectMobileMoneyProvider(phoneNumber) {
|
|
423
|
+
const cleaned = phoneNumber.replace(/\D/g, "");
|
|
424
|
+
const prefix = cleaned.slice(-9, -6);
|
|
425
|
+
for (const [provider, info] of Object.entries(MOBILE_MONEY_PROVIDERS)) {
|
|
426
|
+
if (info.prefix.some((p) => prefix.startsWith(p.slice(1)))) {
|
|
427
|
+
return provider;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export { CURRENCY_SYMBOLS, MOBILE_MONEY_PROVIDERS, categorizePaymentError, detectMobileMoneyProvider, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getProductCurrency, isOnSale, isPaymentStatusFailure, isPaymentStatusRequiresAction, isPaymentStatusSuccess, normalizePaymentResponse, normalizeStatusResponse, parsePrice };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cimplify/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "Cimplify Commerce SDK for storefronts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cimplify",
|
|
@@ -25,6 +25,16 @@
|
|
|
25
25
|
"types": "./dist/react.d.ts",
|
|
26
26
|
"import": "./dist/react.mjs",
|
|
27
27
|
"require": "./dist/react.js"
|
|
28
|
+
},
|
|
29
|
+
"./utils": {
|
|
30
|
+
"types": "./dist/utils.d.ts",
|
|
31
|
+
"import": "./dist/utils.mjs",
|
|
32
|
+
"require": "./dist/utils.js"
|
|
33
|
+
},
|
|
34
|
+
"./advanced": {
|
|
35
|
+
"types": "./dist/advanced.d.ts",
|
|
36
|
+
"import": "./dist/advanced.mjs",
|
|
37
|
+
"require": "./dist/advanced.js"
|
|
28
38
|
}
|
|
29
39
|
},
|
|
30
40
|
"scripts": {
|