@mainmoneyapp/js-checkout 0.1.5 → 0.2.1
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/README.md +5 -4
- package/dist/index.d.ts +7 -0
- package/dist/index.js +61 -27
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @mainmoneyapp/js-checkout
|
|
2
2
|
|
|
3
3
|
Headless checkout and vanilla `mountCheckout`. Import
|
|
4
|
-
`@mainmoneyapp/js-checkout/styles.css`. See the [root README](../../README.md).
|
|
4
|
+
`@mainmoneyapp/js-checkout/styles.css`. See the [root README](../../README.md) and the [full documentation](../../docs/README.md).
|
|
5
5
|
|
|
6
6
|
## Layouts
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@ Headless checkout and vanilla `mountCheckout`. Import
|
|
|
9
9
|
|
|
10
10
|
- **`form`** (default for `operation: "deposit"`): one page with Card / Mobile money /
|
|
11
11
|
MainMoney tabs, optional receipt email, dial-code dropdown plus local phone number,
|
|
12
|
-
fee box (
|
|
12
|
+
fee box (Processing fee / You pay), provider logos for the selected
|
|
13
13
|
country, a Pay button, an EN/FR toggle and footer links.
|
|
14
14
|
- **`wizard`** (default for payouts): the step-by-step flow. Force either with `layout`.
|
|
15
15
|
|
|
@@ -27,8 +27,9 @@ Headless checkout and vanilla `mountCheckout`. Import
|
|
|
27
27
|
backends are integrated.
|
|
28
28
|
- Countries, flags and provider logos: `/countries` and `/providers`, already limited to
|
|
29
29
|
what the merchant may use.
|
|
30
|
-
- Fee box: `
|
|
31
|
-
|
|
30
|
+
- Fee box: `processing_fee` and `total_to_pay` from `/fees/simulate` (what the merchant receives is never shown).
|
|
31
|
+
`fee_bearer` is exposed as `feeBearer` on the snapshot but does not change the deposit request; the deposit is
|
|
32
|
+
always created with the order `amount` (a merchant fee goes in `fees`).
|
|
32
33
|
- The phone number is sent once as `<dial code><local number>`; typing `+243...` or `0...`
|
|
33
34
|
is handled.
|
|
34
35
|
|
package/dist/index.d.ts
CHANGED
|
@@ -43,6 +43,13 @@ type CreateCheckoutOptions = {
|
|
|
43
43
|
* reference and Idempotency-Key suffix.
|
|
44
44
|
*/
|
|
45
45
|
onRetry?: () => void | Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Also send the reference as an `Idempotency-Key` header on deposits and payouts. Off by default: a custom header
|
|
48
|
+
* makes the browser preflight list it in `Access-Control-Allow-Headers`, and a merchant backend that does not
|
|
49
|
+
* allow it fails every payment with a CORS error. The `reference` in the body already makes the call idempotent;
|
|
50
|
+
* turn this on only when your backend allows the header (or forwards it to the aggregator).
|
|
51
|
+
*/
|
|
52
|
+
idempotencyHeader?: boolean;
|
|
46
53
|
/** Polling interval; defaults to 1000 ms. */
|
|
47
54
|
pollIntervalMs?: number;
|
|
48
55
|
/** After this long without a terminal status the widget flags `slow` (default 30000 ms) but keeps polling. */
|
package/dist/index.js
CHANGED
|
@@ -301,6 +301,8 @@ function createCheckout(session, options) {
|
|
|
301
301
|
state.highlightedProviderCode = void 0;
|
|
302
302
|
state.customerName = null;
|
|
303
303
|
lastMatchedIdentifier = "";
|
|
304
|
+
lookupSeq += 1;
|
|
305
|
+
lookup = void 0;
|
|
304
306
|
state.providers = paginated(payload);
|
|
305
307
|
state.quoteUnavailable = false;
|
|
306
308
|
if (!state.lockCurrency) {
|
|
@@ -362,36 +364,67 @@ function createCheckout(session, options) {
|
|
|
362
364
|
translate = createTranslator(locale, catalogOverrides);
|
|
363
365
|
notify();
|
|
364
366
|
};
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
if (trimmed === lastMatchedIdentifier) {
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
367
|
+
let lookup;
|
|
368
|
+
let lookupSeq = 0;
|
|
369
|
+
const runMatch = async (trimmed, key) => {
|
|
370
|
+
const seq = ++lookupSeq;
|
|
371
|
+
let payload;
|
|
373
372
|
try {
|
|
374
|
-
|
|
373
|
+
payload = await http.get(session.paths.matchProvider, {
|
|
375
374
|
account_number: e164OrIdentifier(),
|
|
376
375
|
get_lookup: true,
|
|
377
376
|
operation_type: routingOperationType()
|
|
378
377
|
});
|
|
379
|
-
|
|
380
|
-
if (
|
|
381
|
-
|
|
382
|
-
const matched = state.providers.find((item) => item.code === entity);
|
|
383
|
-
if (matched !== void 0) {
|
|
384
|
-
state.selectedProvider = matched;
|
|
385
|
-
applyProviderCurrency(matched);
|
|
386
|
-
}
|
|
378
|
+
} catch (error) {
|
|
379
|
+
if (seq === lookupSeq) {
|
|
380
|
+
fail(error);
|
|
387
381
|
}
|
|
388
|
-
|
|
389
|
-
|
|
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);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
state.customerName = extractCustomerName(payload);
|
|
397
|
+
lastMatchedIdentifier = trimmed;
|
|
398
|
+
notify();
|
|
399
|
+
try {
|
|
390
400
|
await refreshLimitsAndFees();
|
|
391
|
-
notify();
|
|
392
401
|
} catch (error) {
|
|
393
|
-
|
|
402
|
+
if (seq === lookupSeq) {
|
|
403
|
+
fail(error);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (seq === lookupSeq) {
|
|
408
|
+
notify();
|
|
409
|
+
}
|
|
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();
|
|
394
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;
|
|
395
428
|
};
|
|
396
429
|
const setCurrency = async (code) => {
|
|
397
430
|
if (state.lockCurrency) {
|
|
@@ -588,9 +621,7 @@ function createCheckout(session, options) {
|
|
|
588
621
|
if (fees !== "") {
|
|
589
622
|
payload.fees = fees;
|
|
590
623
|
}
|
|
591
|
-
created = await http.post(session.paths.deposits, payload,
|
|
592
|
-
"Idempotency-Key": reference
|
|
593
|
-
});
|
|
624
|
+
created = await http.post(session.paths.deposits, payload, idempotencyHeaders(reference));
|
|
594
625
|
} else {
|
|
595
626
|
created = await http.post(session.paths.payouts, {
|
|
596
627
|
provider_code: state.selectedProvider.code,
|
|
@@ -598,7 +629,7 @@ function createCheckout(session, options) {
|
|
|
598
629
|
amount: state.amount,
|
|
599
630
|
currency: state.currency,
|
|
600
631
|
destination_account: e164OrIdentifier()
|
|
601
|
-
},
|
|
632
|
+
}, idempotencyHeaders(reference));
|
|
602
633
|
}
|
|
603
634
|
state.status = created;
|
|
604
635
|
if (typeof created.status === "string" && isTerminalStatus2(created.status)) {
|
|
@@ -661,6 +692,7 @@ function createCheckout(session, options) {
|
|
|
661
692
|
fail(error);
|
|
662
693
|
}
|
|
663
694
|
};
|
|
695
|
+
const idempotencyHeaders = (reference) => options.idempotencyHeader === true ? { "Idempotency-Key": reference } : {};
|
|
664
696
|
const retry = async () => {
|
|
665
697
|
if (options.onRetry !== void 0) {
|
|
666
698
|
await options.onRetry();
|
|
@@ -991,7 +1023,7 @@ function phoneField(checkout, state) {
|
|
|
991
1023
|
});
|
|
992
1024
|
input.addEventListener("blur", () => {
|
|
993
1025
|
clearTimeout(timer);
|
|
994
|
-
if (input.value.trim() !== "") {
|
|
1026
|
+
if (input.isConnected && input.value.trim() !== "") {
|
|
995
1027
|
runLookup();
|
|
996
1028
|
}
|
|
997
1029
|
});
|
|
@@ -1454,7 +1486,9 @@ function identifierField(checkout, state, phone) {
|
|
|
1454
1486
|
input.value = state.identifier;
|
|
1455
1487
|
input.addEventListener("input", () => checkout.setIdentifier(input.value));
|
|
1456
1488
|
input.addEventListener("blur", () => {
|
|
1457
|
-
|
|
1489
|
+
if (input.isConnected) {
|
|
1490
|
+
run(() => checkout.matchProvider());
|
|
1491
|
+
}
|
|
1458
1492
|
});
|
|
1459
1493
|
if (phone && state.selectedCountry?.phone_code) {
|
|
1460
1494
|
const row = document.createElement("div");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mainmoneyapp/js-checkout",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Checkout wizard for the MainMoney JS/TS frontend SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@mainmoneyapp/js-core": "0.1
|
|
45
|
-
"@mainmoneyapp/js-http": "0.1
|
|
44
|
+
"@mainmoneyapp/js-core": "0.2.1",
|
|
45
|
+
"@mainmoneyapp/js-http": "0.2.1"
|
|
46
46
|
}
|
|
47
47
|
}
|