@mainmoneyapp/js-checkout 0.1.1 → 0.2.0
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.ts +62 -2
- package/dist/index.js +470 -109
- package/dist/styles.css +158 -44
- package/package.json +13 -5
package/dist/index.js
CHANGED
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
ConfigurationException as ConfigurationException2,
|
|
4
4
|
CurrencyMismatchException,
|
|
5
5
|
Emitter,
|
|
6
|
+
MerchantBackendException,
|
|
6
7
|
createTranslator,
|
|
7
8
|
extractCustomerName,
|
|
9
|
+
isColorScheme,
|
|
8
10
|
isPhoneIdentifier,
|
|
9
11
|
isTerminalStatus as isTerminalStatus2
|
|
10
12
|
} from "@mainmoneyapp/js-core";
|
|
@@ -18,18 +20,36 @@ async function pollStatus(options) {
|
|
|
18
20
|
throw new ConfigurationException("pollUrl is required when polling is enabled");
|
|
19
21
|
}
|
|
20
22
|
let latest = { status: "PENDING" };
|
|
23
|
+
let failures = 0;
|
|
21
24
|
while (!options.signal?.aborted) {
|
|
22
25
|
const url = withQuery(options.pollUrl, { reference: options.reference, operation: options.operation });
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
let delay = options.intervalMs;
|
|
27
|
+
try {
|
|
28
|
+
const response = await options.fetchImpl(url, {
|
|
29
|
+
method: "GET",
|
|
30
|
+
headers: { ...options.pollHeaders },
|
|
31
|
+
signal: options.signal
|
|
32
|
+
});
|
|
33
|
+
latest = decodeJson(response.status, await response.text());
|
|
34
|
+
if (failures > 0) {
|
|
35
|
+
failures = 0;
|
|
36
|
+
options.onConnectionChange?.(false);
|
|
37
|
+
}
|
|
38
|
+
options.onResponse?.(latest);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (options.signal?.aborted) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
failures += 1;
|
|
44
|
+
if (failures === 1) {
|
|
45
|
+
options.onConnectionChange?.(true);
|
|
46
|
+
}
|
|
47
|
+
delay = Math.min(options.intervalMs * 2 ** Math.min(failures, 6), options.maxBackoffMs ?? 1e4);
|
|
48
|
+
}
|
|
49
|
+
if (failures === 0 && typeof latest.status === "string" && isTerminalStatus(latest.status)) {
|
|
30
50
|
return latest;
|
|
31
51
|
}
|
|
32
|
-
await sleep(
|
|
52
|
+
await sleep(delay, options.signal);
|
|
33
53
|
}
|
|
34
54
|
return latest;
|
|
35
55
|
}
|
|
@@ -103,8 +123,9 @@ function createCheckout(session, options) {
|
|
|
103
123
|
const theme = { ...session.theme, ...options.theme };
|
|
104
124
|
const emitter = new Emitter();
|
|
105
125
|
const pollAbort = new AbortController();
|
|
106
|
-
const explicitCurrency = options.currency?.trim() ?? "";
|
|
107
|
-
const
|
|
126
|
+
const explicitCurrency = (options.currency ?? session.currency)?.trim().toUpperCase() ?? "";
|
|
127
|
+
const fixedCurrency = explicitCurrency !== "";
|
|
128
|
+
const lockCurrency = (options.lockCurrency ?? session.lockCurrency) === true;
|
|
108
129
|
const state = {
|
|
109
130
|
step: "country",
|
|
110
131
|
operation: options.operation,
|
|
@@ -116,17 +137,38 @@ function createCheckout(session, options) {
|
|
|
116
137
|
lockAmount: options.lockAmount === true,
|
|
117
138
|
currency: explicitCurrency,
|
|
118
139
|
lockCurrency,
|
|
119
|
-
|
|
140
|
+
currencyFixed: fixedCurrency,
|
|
141
|
+
payCurrency: explicitCurrency,
|
|
142
|
+
availableCurrencies: fixedCurrency ? [explicitCurrency] : [],
|
|
143
|
+
quoteUnavailable: false,
|
|
120
144
|
partnerFee: null,
|
|
121
145
|
locale: options.locale ?? session.locale,
|
|
122
146
|
paymentMethods: ["mobile_money"],
|
|
123
147
|
activeMethod: "mobile_money",
|
|
124
148
|
feeBearer: "MERCHANT",
|
|
125
|
-
customerEmail: "",
|
|
149
|
+
customerEmail: options.customerEmail?.trim() ?? "",
|
|
126
150
|
canPay: false,
|
|
127
|
-
|
|
151
|
+
slow: false,
|
|
152
|
+
connectionLost: false,
|
|
153
|
+
pollConfirmed: false,
|
|
154
|
+
theme,
|
|
155
|
+
colorScheme: "auto",
|
|
156
|
+
resolvedColorScheme: "light"
|
|
128
157
|
};
|
|
129
158
|
let lastMatchedIdentifier = "";
|
|
159
|
+
let submissions = 0;
|
|
160
|
+
let baseReference;
|
|
161
|
+
const providerCache = /* @__PURE__ */ new Map();
|
|
162
|
+
const cachedProviders = (country) => {
|
|
163
|
+
const key = `${country}:${routingOperationType()}`;
|
|
164
|
+
let pending = providerCache.get(key);
|
|
165
|
+
if (pending === void 0) {
|
|
166
|
+
pending = http.get(session.paths.providers, { country, operation_type: routingOperationType() });
|
|
167
|
+
providerCache.set(key, pending);
|
|
168
|
+
pending.catch(() => providerCache.delete(key));
|
|
169
|
+
}
|
|
170
|
+
return pending;
|
|
171
|
+
};
|
|
130
172
|
let returnStep = "overview";
|
|
131
173
|
const notify = () => {
|
|
132
174
|
emitter.emit("change", getState());
|
|
@@ -134,13 +176,13 @@ function createCheckout(session, options) {
|
|
|
134
176
|
const getState = () => ({ ...structuredClone(state), canPay: computeCanPay() });
|
|
135
177
|
const hasValidLocalNumber = () => {
|
|
136
178
|
const digits = e164OrIdentifier().replace(/\D/g, "");
|
|
137
|
-
const dial = state.selectedCountry?.phone_code?.replace(/\D/g, "") ?? "";
|
|
179
|
+
const dial = dialPrefix() ? state.selectedCountry?.phone_code?.replace(/\D/g, "") ?? "" : "";
|
|
138
180
|
const national = digits.length - dial.length;
|
|
139
181
|
return national >= MIN_LOCAL_NUMBER_DIGITS && national <= MAX_LOCAL_NUMBER_DIGITS;
|
|
140
182
|
};
|
|
141
183
|
const computeCanPay = () => {
|
|
142
184
|
const amount = Number(state.amount);
|
|
143
|
-
return state.step === "details" && state.activeMethod === "mobile_money" && state.selectedCountry !== void 0 && state.providers.length > 0 && state.currency !== "" && Number.isFinite(amount) && amount > 0 && hasValidLocalNumber();
|
|
185
|
+
return state.step === "details" && state.activeMethod === "mobile_money" && state.selectedCountry !== void 0 && state.providers.length > 0 && state.currency !== "" && !state.quoteUnavailable && Number.isFinite(amount) && amount > 0 && hasValidLocalNumber();
|
|
144
186
|
};
|
|
145
187
|
const messageFromError = (error) => {
|
|
146
188
|
if (error instanceof Error && error.message !== "") {
|
|
@@ -164,17 +206,38 @@ function createCheckout(session, options) {
|
|
|
164
206
|
}
|
|
165
207
|
return [];
|
|
166
208
|
};
|
|
209
|
+
const defaultPayCurrency = (accepted) => {
|
|
210
|
+
if (accepted.length === 0 || accepted.includes(state.currency)) {
|
|
211
|
+
return state.currency;
|
|
212
|
+
}
|
|
213
|
+
return accepted[0];
|
|
214
|
+
};
|
|
167
215
|
const applyProviderCurrency = (provider) => {
|
|
168
216
|
if (state.lockCurrency) {
|
|
169
217
|
return;
|
|
170
218
|
}
|
|
171
219
|
const accepted = providerAcceptedCurrencies(provider);
|
|
172
220
|
state.availableCurrencies = accepted;
|
|
221
|
+
state.quoteUnavailable = false;
|
|
222
|
+
if (fixedCurrency) {
|
|
223
|
+
state.payCurrency = defaultPayCurrency(accepted);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
173
226
|
if (accepted.includes(provider.currency_code)) {
|
|
174
227
|
state.currency = provider.currency_code;
|
|
175
228
|
} else if (accepted.length > 0) {
|
|
176
229
|
state.currency = accepted[0];
|
|
177
230
|
}
|
|
231
|
+
state.payCurrency = state.currency;
|
|
232
|
+
};
|
|
233
|
+
const isNoQuote = (error) => {
|
|
234
|
+
if (!(error instanceof MerchantBackendException)) {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
if (error.errors.payment_currency !== void 0) {
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
return JSON.stringify(error.responseBody ?? "").includes("no_quote");
|
|
178
241
|
};
|
|
179
242
|
const PAYMENT_METHODS = ["mobile_money", "card", "mainmoney"];
|
|
180
243
|
const applyPaymentPreferences = (prefs) => {
|
|
@@ -189,17 +252,30 @@ function createCheckout(session, options) {
|
|
|
189
252
|
state.feeBearer = prefs.fee_bearer;
|
|
190
253
|
}
|
|
191
254
|
};
|
|
255
|
+
const allowedCountries = (countries) => {
|
|
256
|
+
const seen = /* @__PURE__ */ new Set();
|
|
257
|
+
return countries.filter((country) => {
|
|
258
|
+
if (typeof country.code !== "string" || country.code === "" || seen.has(country.code)) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
seen.add(country.code);
|
|
262
|
+
return true;
|
|
263
|
+
});
|
|
264
|
+
};
|
|
192
265
|
const loadCountries = async () => {
|
|
266
|
+
const countriesRequest = http.get(session.paths.countries);
|
|
267
|
+
const preferences = http.get(session.paths.checkoutPreferences).catch(() => void 0);
|
|
193
268
|
try {
|
|
194
|
-
const payload = await
|
|
195
|
-
state.countries = paginated(payload);
|
|
269
|
+
const payload = await countriesRequest;
|
|
270
|
+
state.countries = allowedCountries(paginated(payload));
|
|
196
271
|
state.error = void 0;
|
|
197
272
|
} catch (error) {
|
|
273
|
+
void preferences;
|
|
198
274
|
fail(error);
|
|
199
275
|
return;
|
|
200
276
|
}
|
|
201
|
-
|
|
202
|
-
|
|
277
|
+
const prefs = await preferences;
|
|
278
|
+
if (prefs !== void 0) {
|
|
203
279
|
applyPaymentPreferences(prefs);
|
|
204
280
|
if (prefs.primary_color !== void 0) {
|
|
205
281
|
state.theme = {
|
|
@@ -209,7 +285,6 @@ function createCheckout(session, options) {
|
|
|
209
285
|
background: String(prefs.background_color ?? state.theme.background)
|
|
210
286
|
};
|
|
211
287
|
}
|
|
212
|
-
} catch {
|
|
213
288
|
}
|
|
214
289
|
notify();
|
|
215
290
|
};
|
|
@@ -220,21 +295,22 @@ function createCheckout(session, options) {
|
|
|
220
295
|
return;
|
|
221
296
|
}
|
|
222
297
|
try {
|
|
223
|
-
const payload = await
|
|
224
|
-
country: code,
|
|
225
|
-
operation_type: routingOperationType()
|
|
226
|
-
});
|
|
298
|
+
const payload = await cachedProviders(code);
|
|
227
299
|
state.selectedCountry = country;
|
|
228
300
|
state.selectedProvider = void 0;
|
|
229
301
|
state.highlightedProviderCode = void 0;
|
|
230
302
|
state.customerName = null;
|
|
231
303
|
lastMatchedIdentifier = "";
|
|
304
|
+
lookupSeq += 1;
|
|
305
|
+
lookup = void 0;
|
|
232
306
|
state.providers = paginated(payload);
|
|
307
|
+
state.quoteUnavailable = false;
|
|
233
308
|
if (!state.lockCurrency) {
|
|
234
309
|
state.availableCurrencies = unionProviderCurrencies(state.providers);
|
|
235
310
|
if (state.currency === "" && state.availableCurrencies.length > 0) {
|
|
236
311
|
state.currency = state.availableCurrencies[0];
|
|
237
312
|
}
|
|
313
|
+
state.payCurrency = fixedCurrency ? defaultPayCurrency(state.availableCurrencies) : state.currency;
|
|
238
314
|
}
|
|
239
315
|
state.error = void 0;
|
|
240
316
|
state.step = "details";
|
|
@@ -244,6 +320,9 @@ function createCheckout(session, options) {
|
|
|
244
320
|
await refreshLimitsAndFees();
|
|
245
321
|
}
|
|
246
322
|
notify();
|
|
323
|
+
if (state.identifier.trim() !== "") {
|
|
324
|
+
await matchProvider();
|
|
325
|
+
}
|
|
247
326
|
} catch (error) {
|
|
248
327
|
fail(error);
|
|
249
328
|
}
|
|
@@ -285,37 +364,68 @@ function createCheckout(session, options) {
|
|
|
285
364
|
translate = createTranslator(locale, catalogOverrides);
|
|
286
365
|
notify();
|
|
287
366
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (trimmed === lastMatchedIdentifier) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
367
|
+
let lookup;
|
|
368
|
+
let lookupSeq = 0;
|
|
369
|
+
const runMatch = async (trimmed, key) => {
|
|
370
|
+
const seq = ++lookupSeq;
|
|
371
|
+
let payload;
|
|
296
372
|
try {
|
|
297
|
-
|
|
373
|
+
payload = await http.get(session.paths.matchProvider, {
|
|
298
374
|
account_number: e164OrIdentifier(),
|
|
299
375
|
get_lookup: true,
|
|
300
376
|
operation_type: routingOperationType()
|
|
301
377
|
});
|
|
302
|
-
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
378
|
+
} catch (error) {
|
|
379
|
+
if (seq === lookupSeq) {
|
|
380
|
+
fail(error);
|
|
381
|
+
}
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (seq !== lookupSeq || key !== lookupKey()) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const entity = typeof payload.entity === "string" ? payload.entity : void 0;
|
|
388
|
+
if (entity !== void 0) {
|
|
389
|
+
state.highlightedProviderCode = entity;
|
|
390
|
+
const matched = state.providers.find((item) => item.code === entity);
|
|
391
|
+
if (matched !== void 0) {
|
|
392
|
+
state.selectedProvider = matched;
|
|
393
|
+
applyProviderCurrency(matched);
|
|
310
394
|
}
|
|
311
|
-
|
|
312
|
-
|
|
395
|
+
}
|
|
396
|
+
state.customerName = extractCustomerName(payload);
|
|
397
|
+
lastMatchedIdentifier = trimmed;
|
|
398
|
+
notify();
|
|
399
|
+
try {
|
|
313
400
|
await refreshLimitsAndFees();
|
|
314
|
-
notify();
|
|
315
401
|
} catch (error) {
|
|
316
|
-
|
|
402
|
+
if (seq === lookupSeq) {
|
|
403
|
+
fail(error);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (seq === lookupSeq) {
|
|
408
|
+
notify();
|
|
317
409
|
}
|
|
318
410
|
};
|
|
411
|
+
const lookupKey = () => `${state.selectedCountry?.code ?? ""}:${e164OrIdentifier()}`;
|
|
412
|
+
const matchProvider = () => {
|
|
413
|
+
const trimmed = state.identifier.trim();
|
|
414
|
+
if (trimmed === "" || trimmed === lastMatchedIdentifier) {
|
|
415
|
+
return Promise.resolve();
|
|
416
|
+
}
|
|
417
|
+
const key = lookupKey();
|
|
418
|
+
if (lookup !== void 0 && lookup.key === key) {
|
|
419
|
+
return lookup.promise;
|
|
420
|
+
}
|
|
421
|
+
const promise = runMatch(trimmed, key).finally(() => {
|
|
422
|
+
if (lookup?.promise === promise) {
|
|
423
|
+
lookup = void 0;
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
lookup = { key, promise };
|
|
427
|
+
return promise;
|
|
428
|
+
};
|
|
319
429
|
const setCurrency = async (code) => {
|
|
320
430
|
if (state.lockCurrency) {
|
|
321
431
|
return;
|
|
@@ -326,7 +436,12 @@ function createCheckout(session, options) {
|
|
|
326
436
|
return;
|
|
327
437
|
}
|
|
328
438
|
try {
|
|
329
|
-
|
|
439
|
+
if (fixedCurrency) {
|
|
440
|
+
state.payCurrency = normalized;
|
|
441
|
+
} else {
|
|
442
|
+
state.currency = normalized;
|
|
443
|
+
state.payCurrency = normalized;
|
|
444
|
+
}
|
|
330
445
|
await refreshLimitsAndFees();
|
|
331
446
|
notify();
|
|
332
447
|
} catch (error) {
|
|
@@ -345,40 +460,67 @@ function createCheckout(session, options) {
|
|
|
345
460
|
fail(error);
|
|
346
461
|
}
|
|
347
462
|
};
|
|
348
|
-
const
|
|
349
|
-
if (state.selectedProvider === void 0 || state.amount.trim() === "" || state.currency === "") {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const operation = routingOperationType();
|
|
353
|
-
const limitsPayload = await http.get(session.paths.amountLimits, {
|
|
354
|
-
financial_entity_code: state.selectedProvider.code,
|
|
355
|
-
currency: state.currency,
|
|
356
|
-
operation_type: operation
|
|
357
|
-
});
|
|
358
|
-
const limits = paginated(limitsPayload);
|
|
359
|
-
state.limits = limits[0];
|
|
360
|
-
if (state.limits !== void 0) {
|
|
361
|
-
const amount = Number(state.amount);
|
|
362
|
-
const min = state.limits.amount_min === null ? void 0 : Number(state.limits.amount_min);
|
|
363
|
-
const max = state.limits.amount_max === null ? void 0 : Number(state.limits.amount_max);
|
|
364
|
-
if (min !== void 0 && amount < min || max !== void 0 && amount > max) {
|
|
365
|
-
state.error = t("limits", {
|
|
366
|
-
min: state.limits.amount_min ?? "",
|
|
367
|
-
max: state.limits.amount_max ?? ""
|
|
368
|
-
});
|
|
369
|
-
} else {
|
|
370
|
-
state.error = void 0;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
463
|
+
const feeSimulation = async (payCurrency) => {
|
|
373
464
|
const fees = merchantFees();
|
|
374
|
-
|
|
375
|
-
provider_code: state.selectedProvider
|
|
376
|
-
operation_type:
|
|
465
|
+
return http.post(session.paths.feesSimulate, {
|
|
466
|
+
provider_code: state.selectedProvider?.code ?? "",
|
|
467
|
+
operation_type: routingOperationType(),
|
|
377
468
|
amount: state.amount,
|
|
378
469
|
currency: state.currency,
|
|
470
|
+
...payCurrency !== state.currency ? { payment_currency: payCurrency } : {},
|
|
379
471
|
...fees !== "" ? { fees } : {}
|
|
380
472
|
});
|
|
381
473
|
};
|
|
474
|
+
const loadLimits = async (provider) => {
|
|
475
|
+
const payload = await http.get(session.paths.amountLimits, {
|
|
476
|
+
financial_entity_code: provider.code,
|
|
477
|
+
currency: state.payCurrency !== "" ? state.payCurrency : state.currency,
|
|
478
|
+
operation_type: routingOperationType()
|
|
479
|
+
});
|
|
480
|
+
state.limits = paginated(payload)[0];
|
|
481
|
+
};
|
|
482
|
+
const limitsError = (simulation) => {
|
|
483
|
+
if (state.limits === void 0) {
|
|
484
|
+
return void 0;
|
|
485
|
+
}
|
|
486
|
+
const amount = Number(simulation?.quote?.converted_amount ?? state.amount);
|
|
487
|
+
const min = state.limits.amount_min === null ? void 0 : Number(state.limits.amount_min);
|
|
488
|
+
const max = state.limits.amount_max === null ? void 0 : Number(state.limits.amount_max);
|
|
489
|
+
if (min !== void 0 && amount < min || max !== void 0 && amount > max) {
|
|
490
|
+
return t("limits", { min: state.limits.amount_min ?? "", max: state.limits.amount_max ?? "" });
|
|
491
|
+
}
|
|
492
|
+
return void 0;
|
|
493
|
+
};
|
|
494
|
+
const refreshLimitsAndFees = async () => {
|
|
495
|
+
const provider = state.selectedProvider;
|
|
496
|
+
if (provider === void 0 || state.amount.trim() === "" || state.currency === "") {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const payCurrency = state.payCurrency !== "" ? state.payCurrency : state.currency;
|
|
500
|
+
state.quoteUnavailable = false;
|
|
501
|
+
await loadLimits(provider);
|
|
502
|
+
let notice;
|
|
503
|
+
let simulation;
|
|
504
|
+
try {
|
|
505
|
+
simulation = await feeSimulation(payCurrency);
|
|
506
|
+
} catch (error) {
|
|
507
|
+
if (!isNoQuote(error) || payCurrency === state.currency) {
|
|
508
|
+
throw error;
|
|
509
|
+
}
|
|
510
|
+
notice = t("noQuote", { from: payCurrency, to: state.currency });
|
|
511
|
+
state.fees = void 0;
|
|
512
|
+
if (!providerAcceptedCurrencies(provider).includes(state.currency)) {
|
|
513
|
+
state.quoteUnavailable = true;
|
|
514
|
+
state.error = notice;
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
state.payCurrency = state.currency;
|
|
518
|
+
await loadLimits(provider);
|
|
519
|
+
simulation = await feeSimulation(state.currency);
|
|
520
|
+
}
|
|
521
|
+
state.fees = simulation;
|
|
522
|
+
state.error = limitsError(simulation) ?? notice;
|
|
523
|
+
};
|
|
382
524
|
const prepare = async () => {
|
|
383
525
|
if (state.selectedCountry === void 0 || state.selectedProvider === void 0) {
|
|
384
526
|
state.error = t("required");
|
|
@@ -454,7 +596,9 @@ function createCheckout(session, options) {
|
|
|
454
596
|
state.error = void 0;
|
|
455
597
|
notify();
|
|
456
598
|
try {
|
|
457
|
-
|
|
599
|
+
baseReference ??= options.reference ?? crypto.randomUUID();
|
|
600
|
+
const reference = submissions === 0 ? baseReference : `${baseReference}-r${submissions}`;
|
|
601
|
+
submissions += 1;
|
|
458
602
|
let created;
|
|
459
603
|
if (state.operation === "deposit") {
|
|
460
604
|
const payload = {
|
|
@@ -464,6 +608,9 @@ function createCheckout(session, options) {
|
|
|
464
608
|
currency: state.currency,
|
|
465
609
|
customer_phone: e164OrIdentifier()
|
|
466
610
|
};
|
|
611
|
+
if (state.payCurrency !== "" && state.payCurrency !== state.currency) {
|
|
612
|
+
payload.payment_currency = state.payCurrency;
|
|
613
|
+
}
|
|
467
614
|
if (state.customerName !== null) {
|
|
468
615
|
payload.customer_name = state.customerName;
|
|
469
616
|
}
|
|
@@ -474,9 +621,7 @@ function createCheckout(session, options) {
|
|
|
474
621
|
if (fees !== "") {
|
|
475
622
|
payload.fees = fees;
|
|
476
623
|
}
|
|
477
|
-
created = await http.post(session.paths.deposits, payload,
|
|
478
|
-
"Idempotency-Key": reference
|
|
479
|
-
});
|
|
624
|
+
created = await http.post(session.paths.deposits, payload, idempotencyHeaders(reference));
|
|
480
625
|
} else {
|
|
481
626
|
created = await http.post(session.paths.payouts, {
|
|
482
627
|
provider_code: state.selectedProvider.code,
|
|
@@ -484,7 +629,7 @@ function createCheckout(session, options) {
|
|
|
484
629
|
amount: state.amount,
|
|
485
630
|
currency: state.currency,
|
|
486
631
|
destination_account: e164OrIdentifier()
|
|
487
|
-
},
|
|
632
|
+
}, idempotencyHeaders(reference));
|
|
488
633
|
}
|
|
489
634
|
state.status = created;
|
|
490
635
|
if (typeof created.status === "string" && isTerminalStatus2(created.status)) {
|
|
@@ -500,16 +645,41 @@ function createCheckout(session, options) {
|
|
|
500
645
|
return;
|
|
501
646
|
}
|
|
502
647
|
state.step = "polling";
|
|
648
|
+
state.slow = false;
|
|
649
|
+
state.connectionLost = false;
|
|
650
|
+
state.pollConfirmed = false;
|
|
503
651
|
notify();
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
652
|
+
const slowTimer = setTimeout(() => {
|
|
653
|
+
state.slow = true;
|
|
654
|
+
notify();
|
|
655
|
+
}, options.slowNoticeAfterMs ?? 3e4);
|
|
656
|
+
pollAbort.signal.addEventListener("abort", () => clearTimeout(slowTimer), { once: true });
|
|
657
|
+
let status;
|
|
658
|
+
try {
|
|
659
|
+
status = await pollStatus({
|
|
660
|
+
pollUrl: options.pollUrl ?? "",
|
|
661
|
+
pollHeaders: options.pollHeaders ?? {},
|
|
662
|
+
fetchImpl: session.fetch,
|
|
663
|
+
reference,
|
|
664
|
+
operation: state.operation,
|
|
665
|
+
intervalMs: options.pollIntervalMs ?? 1e3,
|
|
666
|
+
signal: pollAbort.signal,
|
|
667
|
+
onConnectionChange: (lost) => {
|
|
668
|
+
state.connectionLost = lost;
|
|
669
|
+
notify();
|
|
670
|
+
},
|
|
671
|
+
onResponse: () => {
|
|
672
|
+
if (!state.pollConfirmed) {
|
|
673
|
+
state.pollConfirmed = true;
|
|
674
|
+
notify();
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
} finally {
|
|
679
|
+
clearTimeout(slowTimer);
|
|
680
|
+
}
|
|
681
|
+
state.slow = false;
|
|
682
|
+
state.connectionLost = false;
|
|
513
683
|
state.status = status;
|
|
514
684
|
state.step = "terminal";
|
|
515
685
|
notify();
|
|
@@ -518,25 +688,75 @@ function createCheckout(session, options) {
|
|
|
518
688
|
emitter.emit("status", status);
|
|
519
689
|
}
|
|
520
690
|
} catch (error) {
|
|
521
|
-
state.step = returnStep;
|
|
691
|
+
state.step = options.onRetry !== void 0 ? "error" : returnStep;
|
|
522
692
|
fail(error);
|
|
523
693
|
}
|
|
524
694
|
};
|
|
695
|
+
const idempotencyHeaders = (reference) => options.idempotencyHeader === true ? { "Idempotency-Key": reference } : {};
|
|
696
|
+
const retry = async () => {
|
|
697
|
+
if (options.onRetry !== void 0) {
|
|
698
|
+
await options.onRetry();
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
state.error = void 0;
|
|
702
|
+
state.status = void 0;
|
|
703
|
+
state.step = returnStep;
|
|
704
|
+
notify();
|
|
705
|
+
};
|
|
525
706
|
const merchantFees = () => {
|
|
526
707
|
if (state.operation !== "deposit") {
|
|
527
708
|
return "";
|
|
528
709
|
}
|
|
529
710
|
return state.partnerFee?.amount ?? options.fees ?? "";
|
|
530
711
|
};
|
|
712
|
+
const dialPrefix = () => {
|
|
713
|
+
if (state.activeMethod !== "mobile_money" || state.selectedCountry?.phone_code === void 0) {
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
return state.selectedProvider === void 0 || isPhoneIdentifier(state.selectedProvider);
|
|
717
|
+
};
|
|
531
718
|
const e164OrIdentifier = () => {
|
|
532
719
|
const raw = state.identifier.trim();
|
|
533
|
-
if (!
|
|
720
|
+
if (!dialPrefix() || state.selectedCountry?.phone_code === void 0) {
|
|
534
721
|
return raw;
|
|
535
722
|
}
|
|
536
723
|
return toE164Digits(raw, state.selectedCountry.phone_code);
|
|
537
724
|
};
|
|
725
|
+
const darkQuery = typeof globalThis.matchMedia === "function" ? globalThis.matchMedia("(prefers-color-scheme: dark)") : void 0;
|
|
726
|
+
const resolveColorScheme = () => state.colorScheme === "auto" ? darkQuery?.matches === true ? "dark" : "light" : state.colorScheme;
|
|
727
|
+
const setColorScheme = (scheme) => {
|
|
728
|
+
if (!isColorScheme(scheme) || state.colorScheme === scheme) {
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
state.colorScheme = scheme;
|
|
732
|
+
state.resolvedColorScheme = resolveColorScheme();
|
|
733
|
+
notify();
|
|
734
|
+
};
|
|
735
|
+
const onSystemSchemeChange = () => {
|
|
736
|
+
const resolved = resolveColorScheme();
|
|
737
|
+
if (state.colorScheme === "auto" && state.resolvedColorScheme !== resolved) {
|
|
738
|
+
state.resolvedColorScheme = resolved;
|
|
739
|
+
notify();
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
const releases = [];
|
|
743
|
+
const colorSource = options.colorScheme;
|
|
744
|
+
if (colorSource !== void 0 && typeof colorSource === "object") {
|
|
745
|
+
state.colorScheme = isColorScheme(colorSource.get()) ? colorSource.get() : "auto";
|
|
746
|
+
releases.push(colorSource.subscribe(setColorScheme));
|
|
747
|
+
} else if (isColorScheme(colorSource)) {
|
|
748
|
+
state.colorScheme = colorSource;
|
|
749
|
+
}
|
|
750
|
+
state.resolvedColorScheme = resolveColorScheme();
|
|
751
|
+
if (darkQuery !== void 0) {
|
|
752
|
+
darkQuery.addEventListener("change", onSystemSchemeChange);
|
|
753
|
+
releases.push(() => darkQuery.removeEventListener("change", onSystemSchemeChange));
|
|
754
|
+
}
|
|
538
755
|
const close = () => {
|
|
539
756
|
pollAbort.abort();
|
|
757
|
+
for (const release of releases.splice(0)) {
|
|
758
|
+
release();
|
|
759
|
+
}
|
|
540
760
|
};
|
|
541
761
|
return {
|
|
542
762
|
t,
|
|
@@ -549,8 +769,10 @@ function createCheckout(session, options) {
|
|
|
549
769
|
setCustomerEmail,
|
|
550
770
|
setMethod,
|
|
551
771
|
setLocale,
|
|
772
|
+
setColorScheme,
|
|
552
773
|
matchProvider,
|
|
553
774
|
setCurrency,
|
|
775
|
+
retry,
|
|
554
776
|
setAmount,
|
|
555
777
|
goOverview,
|
|
556
778
|
goBack,
|
|
@@ -561,7 +783,7 @@ function createCheckout(session, options) {
|
|
|
561
783
|
}
|
|
562
784
|
|
|
563
785
|
// src/mount.ts
|
|
564
|
-
import { applyTheme, isPhoneIdentifier as isPhoneIdentifier2 } from "@mainmoneyapp/js-core";
|
|
786
|
+
import { applyColorScheme, applyTheme, isPhoneIdentifier as isPhoneIdentifier2 } from "@mainmoneyapp/js-core";
|
|
565
787
|
|
|
566
788
|
// src/assets/logo.ts
|
|
567
789
|
var DEFAULT_LOGO_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAewAAAHsCAYAAAAQKp5gAAAguklEQVR4nO3dT2yUZ57g8V/vdEvzz1WjbbVmZaia0UozYeKYuTQJjsyFaHCvsBSkMURygrSkycE+pBeQBqNGC0hEmJECSR/sAyQcSCy14wORsBQYNXvAwpnxnOI4TbSH2a7CaFarltb2zLZGPTO9B1w0SWgCrreq3qfq85FarRDq9dt0d771PO/zPs83uos9vwoAINf+Q6tvAAD4eoINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAd9s9Q2QX/uG98TmcvcXfm1tZS1WVtYiIqJaWY6IiNWVtVhdWY1q5W7T7xGgUwh2B3tYkB/00tf8/YdZXVmLamX5/r9XK3fjTuVuVCvLcWf9r6HTFIqFKBZ/PwrFQhSKXVE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ve974h8/i2tr//uxfm/1l7+Ivf9rPlb//ZcNvquNq3dKvMvCM3hs32z1DcDXqdY5wi6VN8V81H+gSBZW/+2X8Wr172PfH2yOI9/509j8kNe1Vv/9X+PCz/8hLv78H3Id64h7R6IeGj3e6tuAjvCN7mLPr1p9E9Cp+n7v2/HMbxei6z/c23p06V9WY/6ffp77UAPNJ9gAkADPsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAYINAAkQbABIgGADQAIEGwASINgAkADBBoAECDYAJECwASABgg0ACRBsAEiAYANAAgQbABIg2ACQAMEGgAQINgAkQLABIAGCDQAJEGwASIBgA0ACBBsAEiDYAJAAwQaABAg2ACRAsAEgAf8f3StgqrS6+EwAAAAASUVORK5CYII=";
|
|
@@ -692,6 +914,9 @@ function mobileMoneyPane(checkout, state) {
|
|
|
692
914
|
if (!state.lockAmount || state.amount === "") {
|
|
693
915
|
pane.append(amountField(checkout, state));
|
|
694
916
|
}
|
|
917
|
+
if (payCurrencyOptions(state).length > 1) {
|
|
918
|
+
pane.append(payCurrencyField(checkout, state));
|
|
919
|
+
}
|
|
695
920
|
pane.append(feeBox(checkout, state));
|
|
696
921
|
pane.append(providerLogos(checkout, state));
|
|
697
922
|
appendError(pane, state);
|
|
@@ -742,6 +967,8 @@ function emailField(checkout, state) {
|
|
|
742
967
|
input.addEventListener("input", () => checkout.setCustomerEmail(input.value));
|
|
743
968
|
return floatingField(checkout.t("emailLabel"), input, checkout.t("emailHint"));
|
|
744
969
|
}
|
|
970
|
+
var LOOKUP_DEBOUNCE_MS = 600;
|
|
971
|
+
var LOOKUP_MIN_DIGITS = 7;
|
|
745
972
|
function phoneField(checkout, state) {
|
|
746
973
|
const row = document.createElement("div");
|
|
747
974
|
row.className = "mm-phone-row";
|
|
@@ -774,14 +1001,33 @@ function phoneField(checkout, state) {
|
|
|
774
1001
|
input.autocomplete = "tel-national";
|
|
775
1002
|
input.placeholder = "812345678";
|
|
776
1003
|
input.value = state.identifier;
|
|
1004
|
+
const lookup = document.createElement("span");
|
|
1005
|
+
lookup.className = "mm-spinner-sm";
|
|
1006
|
+
lookup.setAttribute("role", "status");
|
|
1007
|
+
lookup.setAttribute("aria-label", checkout.t("lookingUp"));
|
|
1008
|
+
lookup.hidden = true;
|
|
1009
|
+
const runLookup = () => {
|
|
1010
|
+
lookup.hidden = false;
|
|
1011
|
+
void checkout.matchProvider().catch(() => void 0).finally(() => {
|
|
1012
|
+
lookup.hidden = true;
|
|
1013
|
+
});
|
|
1014
|
+
};
|
|
1015
|
+
let timer;
|
|
777
1016
|
input.addEventListener("input", () => {
|
|
778
1017
|
checkout.setIdentifier(input.value);
|
|
779
1018
|
refreshPayButton(checkout, input);
|
|
1019
|
+
clearTimeout(timer);
|
|
1020
|
+
if (input.value.replace(/\D/g, "").length >= LOOKUP_MIN_DIGITS) {
|
|
1021
|
+
timer = setTimeout(runLookup, LOOKUP_DEBOUNCE_MS);
|
|
1022
|
+
}
|
|
780
1023
|
});
|
|
781
1024
|
input.addEventListener("blur", () => {
|
|
782
|
-
|
|
1025
|
+
clearTimeout(timer);
|
|
1026
|
+
if (input.isConnected && input.value.trim() !== "") {
|
|
1027
|
+
runLookup();
|
|
1028
|
+
}
|
|
783
1029
|
});
|
|
784
|
-
row.append(flag, dial, divider, input);
|
|
1030
|
+
row.append(flag, dial, divider, input, lookup);
|
|
785
1031
|
return floatingField(checkout.t("phone"), row, checkout.t("phoneHint"));
|
|
786
1032
|
}
|
|
787
1033
|
function amountField(checkout, state) {
|
|
@@ -797,7 +1043,7 @@ function amountField(checkout, state) {
|
|
|
797
1043
|
void checkout.setAmount(input.value).catch(() => void 0);
|
|
798
1044
|
});
|
|
799
1045
|
row.append(input);
|
|
800
|
-
if (state.lockCurrency || state.availableCurrencies.length <= 1) {
|
|
1046
|
+
if (state.lockCurrency || state.currencyFixed || state.availableCurrencies.length <= 1) {
|
|
801
1047
|
const badge = document.createElement("span");
|
|
802
1048
|
badge.className = "mm-currency-suffix";
|
|
803
1049
|
badge.textContent = state.currency;
|
|
@@ -819,15 +1065,43 @@ function amountField(checkout, state) {
|
|
|
819
1065
|
}
|
|
820
1066
|
return floatingField(checkout.t("amount"), row);
|
|
821
1067
|
}
|
|
1068
|
+
function payCurrencyOptions(state) {
|
|
1069
|
+
if (!state.currencyFixed || state.lockCurrency || state.selectedProvider === void 0) {
|
|
1070
|
+
return [];
|
|
1071
|
+
}
|
|
1072
|
+
return [...new Set(state.availableCurrencies)].sort();
|
|
1073
|
+
}
|
|
1074
|
+
function payCurrencyField(checkout, state) {
|
|
1075
|
+
const select = document.createElement("select");
|
|
1076
|
+
select.className = "mm-input mm-input-bare mm-select";
|
|
1077
|
+
for (const code of payCurrencyOptions(state)) {
|
|
1078
|
+
const option = document.createElement("option");
|
|
1079
|
+
option.value = code;
|
|
1080
|
+
option.textContent = code;
|
|
1081
|
+
option.selected = state.payCurrency === code;
|
|
1082
|
+
select.append(option);
|
|
1083
|
+
}
|
|
1084
|
+
select.addEventListener("change", () => {
|
|
1085
|
+
void checkout.setCurrency(select.value).catch(() => void 0);
|
|
1086
|
+
});
|
|
1087
|
+
return floatingField(checkout.t("payIn"), select);
|
|
1088
|
+
}
|
|
822
1089
|
function feeBox(checkout, state) {
|
|
823
1090
|
const box = document.createElement("div");
|
|
824
1091
|
box.className = "mm-fee-box";
|
|
825
1092
|
const q = quote(state);
|
|
826
|
-
|
|
827
|
-
box.append(feeRow(checkout.t("processingFee"), formatMoney(q.fee, state)));
|
|
828
|
-
const total = feeRow(checkout.t("youPay"), formatMoney(q.pay, state));
|
|
1093
|
+
const currency = state.fees?.quote?.to_currency ?? state.currency;
|
|
1094
|
+
box.append(feeRow(checkout.t("processingFee"), formatMoney(q.fee, state, currency)));
|
|
1095
|
+
const total = feeRow(checkout.t("youPay"), formatMoney(q.pay, state, currency));
|
|
829
1096
|
total.classList.add("mm-fee-total");
|
|
830
1097
|
box.append(total);
|
|
1098
|
+
const fx = state.fees?.quote;
|
|
1099
|
+
if (fx !== void 0) {
|
|
1100
|
+
const note = document.createElement("p");
|
|
1101
|
+
note.className = "mm-hint";
|
|
1102
|
+
note.textContent = checkout.t("exchangeRate", { from: fx.from_currency, to: fx.to_currency, rate: fx.rate });
|
|
1103
|
+
box.append(note);
|
|
1104
|
+
}
|
|
831
1105
|
return box;
|
|
832
1106
|
}
|
|
833
1107
|
function feeRow(labelText, value) {
|
|
@@ -892,7 +1166,7 @@ function payButton(checkout, state) {
|
|
|
892
1166
|
function applyPayState(button, checkout, state) {
|
|
893
1167
|
const ready = state.canPay;
|
|
894
1168
|
button.disabled = !ready;
|
|
895
|
-
const total = ready ? formatMoney(quote(state).pay, state) : "\u2014";
|
|
1169
|
+
const total = ready ? formatMoney(quote(state).pay, state, state.fees?.quote?.to_currency ?? state.currency) : "\u2014";
|
|
896
1170
|
button.textContent = `${checkout.t("pay")} ${total}`;
|
|
897
1171
|
}
|
|
898
1172
|
function refreshPayButton(checkout, from) {
|
|
@@ -910,8 +1184,8 @@ function quote(state) {
|
|
|
910
1184
|
pay: fees?.total_to_pay ?? amount
|
|
911
1185
|
};
|
|
912
1186
|
}
|
|
913
|
-
function formatMoney(value, state) {
|
|
914
|
-
if (value === null || value === "" ||
|
|
1187
|
+
function formatMoney(value, state, currency = state.currency) {
|
|
1188
|
+
if (value === null || value === "" || currency === "") {
|
|
915
1189
|
return "\u2014";
|
|
916
1190
|
}
|
|
917
1191
|
const number = Number(value);
|
|
@@ -919,9 +1193,9 @@ function formatMoney(value, state) {
|
|
|
919
1193
|
return "\u2014";
|
|
920
1194
|
}
|
|
921
1195
|
try {
|
|
922
|
-
return new Intl.NumberFormat(state.locale, { style: "currency", currency
|
|
1196
|
+
return new Intl.NumberFormat(state.locale, { style: "currency", currency }).format(number);
|
|
923
1197
|
} catch {
|
|
924
|
-
return `${number.toFixed(2)} ${
|
|
1198
|
+
return `${number.toFixed(2)} ${currency}`;
|
|
925
1199
|
}
|
|
926
1200
|
}
|
|
927
1201
|
function flagNode(country) {
|
|
@@ -952,6 +1226,21 @@ function appendError(parent, state) {
|
|
|
952
1226
|
}
|
|
953
1227
|
|
|
954
1228
|
// src/mount.ts
|
|
1229
|
+
function layoutKey(state) {
|
|
1230
|
+
return JSON.stringify({
|
|
1231
|
+
...state,
|
|
1232
|
+
colorScheme: void 0,
|
|
1233
|
+
resolvedColorScheme: void 0,
|
|
1234
|
+
identifier: void 0,
|
|
1235
|
+
customerEmail: void 0,
|
|
1236
|
+
amount: void 0,
|
|
1237
|
+
canPay: void 0
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
function applyPalette(element, state) {
|
|
1241
|
+
applyColorScheme(element, state.colorScheme);
|
|
1242
|
+
element.setAttribute("data-mm-resolved-theme", state.resolvedColorScheme);
|
|
1243
|
+
}
|
|
955
1244
|
function mountCheckout(element, checkout, options = {}) {
|
|
956
1245
|
const logoUrl = options.logoUrl ?? DEFAULT_LOGO_URL;
|
|
957
1246
|
const useForm = (state) => (options.layout ?? (state.operation === "deposit" ? "form" : "wizard")) === "form";
|
|
@@ -969,15 +1258,48 @@ function mountCheckout(element, checkout, options = {}) {
|
|
|
969
1258
|
body = confirmingStep(checkout, state, logoUrl);
|
|
970
1259
|
} else if (state.step === "ongoing") {
|
|
971
1260
|
body = messageStep(checkout.t("ongoing"));
|
|
1261
|
+
} else if (state.step === "error") {
|
|
1262
|
+
body = retryStep(checkout, state.error ?? checkout.t("failed"));
|
|
972
1263
|
} else if (state.step === "terminal") {
|
|
973
1264
|
const status = state.status?.status ?? "";
|
|
974
|
-
body =
|
|
1265
|
+
body = status.toUpperCase() === "SUCCESS" ? messageStep(checkout.t("success")) : retryStep(checkout, checkout.t("failed"));
|
|
975
1266
|
} else {
|
|
976
1267
|
body = formBody(checkout, state);
|
|
977
1268
|
}
|
|
978
1269
|
element.append(formChrome(checkout, state, logoUrl, options.links ?? {}, body));
|
|
979
1270
|
};
|
|
1271
|
+
let renderedKey;
|
|
1272
|
+
let renderedScheme = "";
|
|
980
1273
|
const render = (state) => {
|
|
1274
|
+
element.setAttribute("data-mm-variant", options.variant ?? "default");
|
|
1275
|
+
const key = layoutKey(state);
|
|
1276
|
+
const scheme = `${state.colorScheme}/${state.resolvedColorScheme}`;
|
|
1277
|
+
if (key === renderedKey) {
|
|
1278
|
+
if (scheme !== renderedScheme) {
|
|
1279
|
+
applyPalette(element, state);
|
|
1280
|
+
renderedScheme = scheme;
|
|
1281
|
+
}
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
renderedKey = key;
|
|
1285
|
+
renderedScheme = scheme;
|
|
1286
|
+
const fields = Array.from(element.querySelectorAll("input"));
|
|
1287
|
+
const focused = fields.findIndex((field) => field === document.activeElement);
|
|
1288
|
+
const caret = focused >= 0 ? fields[focused].selectionStart : null;
|
|
1289
|
+
renderBody(state);
|
|
1290
|
+
applyPalette(element, state);
|
|
1291
|
+
if (focused >= 0) {
|
|
1292
|
+
const next = element.querySelectorAll("input")[focused];
|
|
1293
|
+
next?.focus();
|
|
1294
|
+
if (caret !== null && caret !== void 0) {
|
|
1295
|
+
try {
|
|
1296
|
+
next?.setSelectionRange(caret, caret);
|
|
1297
|
+
} catch {
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
const renderBody = (state) => {
|
|
981
1303
|
applyTheme(element, state.theme);
|
|
982
1304
|
element.classList.add("mm-checkout");
|
|
983
1305
|
element.innerHTML = "";
|
|
@@ -997,9 +1319,14 @@ function mountCheckout(element, checkout, options = {}) {
|
|
|
997
1319
|
element.append(confirmingStep(checkout, state, logoUrl));
|
|
998
1320
|
} else if (state.step === "ongoing") {
|
|
999
1321
|
element.append(messageStep(checkout.t("ongoing")));
|
|
1322
|
+
} else if (state.step === "error") {
|
|
1323
|
+
element.append(retryStep(checkout, state.error ?? checkout.t("failed")));
|
|
1324
|
+
return;
|
|
1000
1325
|
} else {
|
|
1001
1326
|
const status = state.status?.status ?? "";
|
|
1002
|
-
element.append(
|
|
1327
|
+
element.append(
|
|
1328
|
+
status.toUpperCase() === "SUCCESS" ? messageStep(checkout.t("success")) : retryStep(checkout, checkout.t("failed"))
|
|
1329
|
+
);
|
|
1003
1330
|
}
|
|
1004
1331
|
appendError2(element, state);
|
|
1005
1332
|
};
|
|
@@ -1054,10 +1381,6 @@ function overviewStep(checkout, state) {
|
|
|
1054
1381
|
wrap.append(overviewRow(checkout.t("customerName"), state.customerName));
|
|
1055
1382
|
}
|
|
1056
1383
|
wrap.append(overviewRow(checkout.t("amount"), `${state.amount} ${state.currency}`));
|
|
1057
|
-
if (state.fees !== void 0) {
|
|
1058
|
-
wrap.append(overviewRow(checkout.t("fees"), `${state.fees.total_merchant_fee} ${state.currency}`));
|
|
1059
|
-
wrap.append(overviewRow(checkout.t("netAmount"), `${state.fees.net_amount} ${state.currency}`));
|
|
1060
|
-
}
|
|
1061
1384
|
if (state.partnerFee !== null) {
|
|
1062
1385
|
wrap.append(
|
|
1063
1386
|
overviewRow(state.partnerFee.label ?? checkout.t("partnerFee"), `${state.partnerFee.amount} ${state.partnerFee.currency}`)
|
|
@@ -1083,6 +1406,42 @@ function confirmingStep(checkout, state, logoUrl) {
|
|
|
1083
1406
|
const caption = document.createElement("div");
|
|
1084
1407
|
caption.textContent = state.step === "polling" ? checkout.t("polling") : checkout.t("confirming");
|
|
1085
1408
|
wrap.append(spinner, caption);
|
|
1409
|
+
if (state.step === "polling" && state.connectionLost) {
|
|
1410
|
+
const lost = document.createElement("div");
|
|
1411
|
+
lost.className = "mm-confirm-slow mm-confirm-offline";
|
|
1412
|
+
lost.setAttribute("role", "status");
|
|
1413
|
+
lost.textContent = checkout.t("connectionLost");
|
|
1414
|
+
wrap.append(lost);
|
|
1415
|
+
}
|
|
1416
|
+
if (state.step === "polling" && state.slow) {
|
|
1417
|
+
const notice = document.createElement("div");
|
|
1418
|
+
notice.className = "mm-confirm-slow";
|
|
1419
|
+
notice.textContent = checkout.t("slow");
|
|
1420
|
+
wrap.append(notice);
|
|
1421
|
+
}
|
|
1422
|
+
return wrap;
|
|
1423
|
+
}
|
|
1424
|
+
function retryStep(checkout, message) {
|
|
1425
|
+
const wrap = document.createElement("div");
|
|
1426
|
+
wrap.className = "mm-confirm mm-retry";
|
|
1427
|
+
const error = document.createElement("div");
|
|
1428
|
+
error.className = "mm-error";
|
|
1429
|
+
error.setAttribute("role", "alert");
|
|
1430
|
+
error.textContent = message;
|
|
1431
|
+
const hint = document.createElement("p");
|
|
1432
|
+
hint.className = "mm-hint";
|
|
1433
|
+
hint.textContent = checkout.t("retryHint");
|
|
1434
|
+
const button = document.createElement("button");
|
|
1435
|
+
button.type = "button";
|
|
1436
|
+
button.className = "mm-pay";
|
|
1437
|
+
button.textContent = checkout.t("retry");
|
|
1438
|
+
button.addEventListener("click", () => {
|
|
1439
|
+
button.disabled = true;
|
|
1440
|
+
void checkout.retry().catch(() => {
|
|
1441
|
+
button.disabled = false;
|
|
1442
|
+
});
|
|
1443
|
+
});
|
|
1444
|
+
wrap.append(error, hint, button);
|
|
1086
1445
|
return wrap;
|
|
1087
1446
|
}
|
|
1088
1447
|
function messageStep(text) {
|
|
@@ -1127,7 +1486,9 @@ function identifierField(checkout, state, phone) {
|
|
|
1127
1486
|
input.value = state.identifier;
|
|
1128
1487
|
input.addEventListener("input", () => checkout.setIdentifier(input.value));
|
|
1129
1488
|
input.addEventListener("blur", () => {
|
|
1130
|
-
|
|
1489
|
+
if (input.isConnected) {
|
|
1490
|
+
run(() => checkout.matchProvider());
|
|
1491
|
+
}
|
|
1131
1492
|
});
|
|
1132
1493
|
if (phone && state.selectedCountry?.phone_code) {
|
|
1133
1494
|
const row = document.createElement("div");
|