@alma/widgets 2.2.10 → 2.3.2
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/CHANGELOG.md +21 -0
- package/dist/raw/widgets.css +21 -14
- package/dist/raw/widgets.js +114 -55
- package/dist/raw/widgets.js.map +1 -1
- package/dist/raw/widgets.m.js +114 -55
- package/dist/raw/widgets.m.js.map +1 -1
- package/dist/raw/widgets.modern.js +101 -47
- package/dist/raw/widgets.modern.js.map +1 -1
- package/dist/raw/widgets.umd.js +114 -55
- package/dist/raw/widgets.umd.js.map +1 -1
- package/dist/types/Widgets/PaymentPlans/index.d.ts +3 -2
- package/dist/types/Widgets/PaymentPlans/tests/SuggestedPaymentPlan.d.ts +1 -0
- package/dist/types/types.d.ts +2 -0
- package/dist/types/utils/merchantOrderPreferences.d.ts +14 -0
- package/dist/widgets.css +6 -6
- package/dist/widgets.js +1 -1
- package/dist/widgets.js.map +1 -1
- package/dist/widgets.m.js +1 -1
- package/dist/widgets.m.js.map +1 -1
- package/dist/widgets.modern.js +1 -1
- package/dist/widgets.modern.js.map +1 -1
- package/dist/widgets.umd.js +1 -1
- package/dist/widgets.umd.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [2.3.2](https://github.com/alma/widgets/compare/v2.3.1...v2.3.2) (2022-05-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **eligibility:** filter plans that have no payment_plan and a reason ([#32](https://github.com/alma/widgets/issues/32)) ([7f8e3ac](https://github.com/alma/widgets/commit/7f8e3ac95f8c38f7a79d2058e2d072f7b5598fe7))
|
|
7
|
+
|
|
8
|
+
## [2.3.1](https://github.com/alma/widgets/compare/v2.3.0...v2.3.1) (2022-05-02)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update wrong translation ([#33](https://github.com/alma/widgets/issues/33)) ([578e6cd](https://github.com/alma/widgets/commit/578e6cd7550df6cc01fd7ad9968a4e8c9bb745e8))
|
|
14
|
+
|
|
15
|
+
# [2.3.0](https://github.com/alma/widgets/compare/v2.2.10...v2.3.0) (2022-04-21)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **payment-plan:** add firstDisplayedPaymentPlan option ([#26](https://github.com/alma/widgets/issues/26)) ([f16fa4a](https://github.com/alma/widgets/commit/f16fa4a068a9e06aec261489065bc1282acee666))
|
|
21
|
+
|
|
1
22
|
## [2.2.10](https://github.com/alma/widgets/compare/v2.2.9...v2.2.10) (2022-04-12)
|
|
2
23
|
|
|
3
24
|
|
package/dist/raw/widgets.css
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
--green-600: #1dcda3;
|
|
37
37
|
}
|
|
38
38
|
@font-face {
|
|
39
|
-
font-family: 'Eina04';
|
|
39
|
+
font-family: 'Eina04', sans-serif;
|
|
40
40
|
src: url('./assets/fonts/Eina04-Light.eot?#iefix') format('embedded-opentype'),
|
|
41
41
|
url('./assets/fonts/Eina04-Light.woff') format('woff'),
|
|
42
42
|
url('./assets/fonts/Eina04-Light.ttf') format('truetype'),
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
font-display: swap;
|
|
47
47
|
}
|
|
48
48
|
@font-face {
|
|
49
|
-
font-family: 'Eina04';
|
|
49
|
+
font-family: 'Eina04', sans-serif;
|
|
50
50
|
src: url('./assets/fonts/Eina04-Regular.eot?#iefix') format('embedded-opentype'),
|
|
51
51
|
url('./assets/fonts/Eina04-Regular.woff') format('woff'),
|
|
52
52
|
url('./assets/fonts/Eina04-Regular.ttf') format('truetype'),
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
font-display: swap;
|
|
57
57
|
}
|
|
58
58
|
@font-face {
|
|
59
|
-
font-family: 'Eina04';
|
|
59
|
+
font-family: 'Eina04', sans-serif;
|
|
60
60
|
src: url('./assets/fonts/Eina04-RegularItalic.eot?#iefix') format('embedded-opentype'),
|
|
61
61
|
url('./assets/fonts/Eina04-RegularItalic.woff') format('woff'),
|
|
62
62
|
url('./assets/fonts/Eina04-RegularItalic.ttf') format('truetype'),
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
font-display: swap;
|
|
67
67
|
}
|
|
68
68
|
@font-face {
|
|
69
|
-
font-family: 'Eina04';
|
|
69
|
+
font-family: 'Eina04', sans-serif;
|
|
70
70
|
src: url('./assets/fonts/Eina04-SemiBold.eot?#iefix') format('embedded-opentype'),
|
|
71
71
|
url('./assets/fonts/Eina04-SemiBold.woff') format('woff'),
|
|
72
72
|
url('./assets/fonts/Eina04-SemiBold.ttf') format('truetype'),
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
font-display: swap;
|
|
77
77
|
}
|
|
78
78
|
@font-face {
|
|
79
|
-
font-family: 'Eina04';
|
|
79
|
+
font-family: 'Eina04', sans-serif;
|
|
80
80
|
src: url('./assets/fonts/Eina04-SemiboldItalic.eot?#iefix') format('embedded-opentype'),
|
|
81
81
|
url('./assets/fonts/Eina04-SemiboldItalic.woff') format('woff'),
|
|
82
82
|
url('./assets/fonts/Eina04-SemiboldItalic.ttf') format('truetype'),
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
font-display: swap;
|
|
87
87
|
}
|
|
88
88
|
@font-face {
|
|
89
|
-
font-family: 'Eina04';
|
|
89
|
+
font-family: 'Eina04', sans-serif;
|
|
90
90
|
src: url('./assets/fonts/Eina04-Bold.eot?#iefix') format('embedded-opentype'),
|
|
91
91
|
url('./assets/fonts/Eina04-Bold.woff') format('woff'),
|
|
92
92
|
url('./assets/fonts/Eina04-Bold.ttf') format('truetype'),
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
._2p94X {
|
|
113
|
-
font-family: Eina04;
|
|
113
|
+
font-family: 'Eina04', sans-serif;
|
|
114
114
|
font-weight: bold;
|
|
115
115
|
line-height: 35px;
|
|
116
116
|
font-size: 64px;
|
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
margin: 0 4px 8px;
|
|
287
287
|
border: 1px solid var(--gray-300);
|
|
288
288
|
border-radius: 8px;
|
|
289
|
-
font-family: 'Eina04';
|
|
289
|
+
font-family: 'Eina04', sans-serif;
|
|
290
290
|
font-size: 18px;
|
|
291
291
|
line-height: 150%;
|
|
292
292
|
font-weight: 600;
|
|
@@ -322,7 +322,6 @@
|
|
|
322
322
|
margin-bottom: 40px;
|
|
323
323
|
border-top: 1px solid var(--gray-300);
|
|
324
324
|
border-bottom: 1px solid var(--gray-300);
|
|
325
|
-
|
|
326
325
|
}
|
|
327
326
|
|
|
328
327
|
._1A7Qv {
|
|
@@ -333,13 +332,13 @@
|
|
|
333
332
|
}
|
|
334
333
|
|
|
335
334
|
._14Ejo {
|
|
336
|
-
font-family: 'Eina04';
|
|
335
|
+
font-family: 'Eina04', sans-serif;
|
|
337
336
|
font-weight: 600;
|
|
338
337
|
font-size: 18px;
|
|
339
338
|
}
|
|
340
339
|
|
|
341
340
|
._1ZIgu {
|
|
342
|
-
font-family: 'Eina04';
|
|
341
|
+
font-family: 'Eina04', sans-serif;
|
|
343
342
|
font-weight: 600;
|
|
344
343
|
font-size: 14px;
|
|
345
344
|
margin-bottom: 24px;
|
|
@@ -408,7 +407,7 @@
|
|
|
408
407
|
}
|
|
409
408
|
|
|
410
409
|
._3ERx- {
|
|
411
|
-
font-family: 'Eina04';
|
|
410
|
+
font-family: 'Eina04', sans-serif;
|
|
412
411
|
font-weight: 600;
|
|
413
412
|
font-size: 18px;
|
|
414
413
|
line-height: 150%;
|
|
@@ -424,7 +423,7 @@
|
|
|
424
423
|
}
|
|
425
424
|
|
|
426
425
|
@media (min-width: 800px) {
|
|
427
|
-
._3ERx- {
|
|
426
|
+
._3ERx- {
|
|
428
427
|
font-size: 24px;
|
|
429
428
|
text-align: start;
|
|
430
429
|
margin: 0 0 24px 0;
|
|
@@ -526,7 +525,7 @@
|
|
|
526
525
|
}
|
|
527
526
|
._2Kqjn {
|
|
528
527
|
font-size: 12px;
|
|
529
|
-
font-family: 'Eina04';
|
|
528
|
+
font-family: 'Eina04', sans-serif;
|
|
530
529
|
font-weight: 600;
|
|
531
530
|
color: var(--blue-300);
|
|
532
531
|
line-height: 20px;
|
|
@@ -544,6 +543,7 @@
|
|
|
544
543
|
|
|
545
544
|
._2Kqjn._3dG_J._3O1bg {
|
|
546
545
|
border-bottom-color: var(--gray-600);
|
|
546
|
+
cursor: not-allowed;
|
|
547
547
|
}
|
|
548
548
|
|
|
549
549
|
._25GrF {
|
|
@@ -581,3 +581,10 @@
|
|
|
581
581
|
._1ZDMS {
|
|
582
582
|
align-items: center;
|
|
583
583
|
}
|
|
584
|
+
|
|
585
|
+
._UksZa {
|
|
586
|
+
cursor: pointer;
|
|
587
|
+
}
|
|
588
|
+
._1lr-q {
|
|
589
|
+
cursor: not-allowed;
|
|
590
|
+
}
|
package/dist/raw/widgets.js
CHANGED
|
@@ -1529,7 +1529,7 @@ var messagesDE = {
|
|
|
1529
1529
|
"payment-plan-strings.deferred": "{totalAmount} zu zahlen am {dueDate}",
|
|
1530
1530
|
"payment-plan-strings.ineligible-greater-than-max": "Bis zu {maxAmount}",
|
|
1531
1531
|
"payment-plan-strings.ineligible-lower-than-min": "Ab {minAmount}",
|
|
1532
|
-
"payment-plan-strings.multiple-installments": "{firstInstallmentAmount} dann {numberOfRemainingInstallments} x {othersInstallmentAmount}",
|
|
1532
|
+
"payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} dann {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} dann {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
|
|
1533
1533
|
"payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
|
|
1534
1534
|
"payment-plan-strings.no-fee": "(gebührenfrei)"
|
|
1535
1535
|
};
|
|
@@ -1551,7 +1551,7 @@ var messagesEN = {
|
|
|
1551
1551
|
"payment-plan-strings.deferred": "{totalAmount} to be paid on {dueDate}",
|
|
1552
1552
|
"payment-plan-strings.ineligible-greater-than-max": "Until {maxAmount}",
|
|
1553
1553
|
"payment-plan-strings.ineligible-lower-than-min": "From {minAmount}",
|
|
1554
|
-
"payment-plan-strings.multiple-installments": "{firstInstallmentAmount} then {numberOfRemainingInstallments} x {othersInstallmentAmount}",
|
|
1554
|
+
"payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} then {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} then {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
|
|
1555
1555
|
"payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
|
|
1556
1556
|
"payment-plan-strings.no-fee": "(free of charge)"
|
|
1557
1557
|
};
|
|
@@ -1573,7 +1573,7 @@ var messagesES = {
|
|
|
1573
1573
|
"payment-plan-strings.deferred": "{totalAmount} a pagar el {dueDate}",
|
|
1574
1574
|
"payment-plan-strings.ineligible-greater-than-max": "Hasta {maxAmount}",
|
|
1575
1575
|
"payment-plan-strings.ineligible-lower-than-min": "Desde {minAmount}",
|
|
1576
|
-
"payment-plan-strings.multiple-installments": "{firstInstallmentAmount} hoy, después {numberOfRemainingInstallments
|
|
1576
|
+
"payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} hoy, después {numberOfRemainingInstallments} mensualidad de {othersInstallmentAmount}} other {{firstInstallmentAmount} hoy, después {numberOfRemainingInstallments} mensualidades de {othersInstallmentAmount}}}",
|
|
1577
1577
|
"payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} plazos de {totalAmount}",
|
|
1578
1578
|
"payment-plan-strings.no-fee": "(sin intereses)"
|
|
1579
1579
|
};
|
|
@@ -1595,7 +1595,7 @@ var messagesFR = {
|
|
|
1595
1595
|
"payment-plan-strings.deferred": "{totalAmount} à payer le {dueDate}",
|
|
1596
1596
|
"payment-plan-strings.ineligible-greater-than-max": "Jusqu'à {maxAmount}",
|
|
1597
1597
|
"payment-plan-strings.ineligible-lower-than-min": "À partir de {minAmount}",
|
|
1598
|
-
"payment-plan-strings.multiple-installments": "{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}",
|
|
1598
|
+
"payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
|
|
1599
1599
|
"payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
|
|
1600
1600
|
"payment-plan-strings.no-fee": "(sans frais)"
|
|
1601
1601
|
};
|
|
@@ -1617,7 +1617,7 @@ var messagesIT = {
|
|
|
1617
1617
|
"payment-plan-strings.deferred": "{totalAmount} da pagare il {dueDate}",
|
|
1618
1618
|
"payment-plan-strings.ineligible-greater-than-max": "Disponibile fino a {maxAmount}",
|
|
1619
1619
|
"payment-plan-strings.ineligible-lower-than-min": "Pagamento rateale disponibile a partire da {minAmount}",
|
|
1620
|
-
"payment-plan-strings.multiple-installments": "Oggi paghi {firstInstallmentAmount} poi {numberOfRemainingInstallments} rate mensili di {othersInstallmentAmount}",
|
|
1620
|
+
"payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {Oggi paghi {firstInstallmentAmount} poi tra {numberOfRemainingInstallments} mese {othersInstallmentAmount}} other {Oggi paghi {firstInstallmentAmount} poi {numberOfRemainingInstallments} rate mensili di {othersInstallmentAmount}}}",
|
|
1621
1621
|
"payment-plan-strings.multiple-installments-same-amount": "In {installmentsCount} rate mensili di {totalAmount}",
|
|
1622
1622
|
"payment-plan-strings.no-fee": "(senza interessi)"
|
|
1623
1623
|
};
|
|
@@ -1625,7 +1625,7 @@ var messagesIT = {
|
|
|
1625
1625
|
var messagesNL = {
|
|
1626
1626
|
"eligibility-modal.bullet-1": "Kies <strong>Alma</strong> bij het afrekenen.",
|
|
1627
1627
|
"eligibility-modal.bullet-2": "Vul de <strong>gevraagde informatie</strong> in.",
|
|
1628
|
-
"eligibility-modal.bullet-3": "
|
|
1628
|
+
"eligibility-modal.bullet-3": "Onmiddelijke validatie van uw betaling ",
|
|
1629
1629
|
"eligibility-modal.cost": "Waarvan kosten",
|
|
1630
1630
|
"eligibility-modal.credit-commitment": "Een lening bindt je en moet worden terugbetaald. Ga na of u kunt terugbetalen voordat u zich vastlegt.",
|
|
1631
1631
|
"eligibility-modal.credit-cost": "Waarvan kosten van krediet",
|
|
@@ -1639,7 +1639,7 @@ var messagesNL = {
|
|
|
1639
1639
|
"payment-plan-strings.deferred": "{totalAmount} te betalen op {dueDate}",
|
|
1640
1640
|
"payment-plan-strings.ineligible-greater-than-max": "Tot {maxAmount}",
|
|
1641
1641
|
"payment-plan-strings.ineligible-lower-than-min": "Van {minAmount}",
|
|
1642
|
-
"payment-plan-strings.multiple-installments": "{firstInstallmentAmount} dan {numberOfRemainingInstallments} x {othersInstallmentAmount}",
|
|
1642
|
+
"payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} dan {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} dan {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
|
|
1643
1643
|
"payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
|
|
1644
1644
|
"payment-plan-strings.no-fee": "(gratis)"
|
|
1645
1645
|
};
|
|
@@ -1738,6 +1738,12 @@ var filterELigibility = function filterELigibility(eligibilities, configPlans) {
|
|
|
1738
1738
|
// Remove p1x
|
|
1739
1739
|
var filteredEligibilityPlans = eligibilities.filter(function (plan) {
|
|
1740
1740
|
return !(plan.installments_count === 1 && plan.deferred_days === 0 && plan.deferred_months === 0);
|
|
1741
|
+
}) // Keeps the plans that have a payment_plan property
|
|
1742
|
+
.filter(function (plan) {
|
|
1743
|
+
return plan.payment_plan;
|
|
1744
|
+
}) // Remove plans that have a reasons property
|
|
1745
|
+
.filter(function (plan) {
|
|
1746
|
+
return !plan.reasons;
|
|
1741
1747
|
}); // If no configPlans was provided, return eligibility response
|
|
1742
1748
|
|
|
1743
1749
|
if (!configPlans) {
|
|
@@ -1787,8 +1793,8 @@ var useFetchEligibility = function useFetchEligibility(purchaseAmount, _ref, pla
|
|
|
1787
1793
|
}, {
|
|
1788
1794
|
Authorization: "Alma-Merchant-Auth " + merchantId
|
|
1789
1795
|
}).then(function (res) {
|
|
1790
|
-
setStatus(apiStatus.SUCCESS);
|
|
1791
1796
|
setEligibility(res);
|
|
1797
|
+
setStatus(apiStatus.SUCCESS);
|
|
1792
1798
|
})["catch"](function () {
|
|
1793
1799
|
setStatus(apiStatus.FAILED);
|
|
1794
1800
|
});
|
|
@@ -1970,7 +1976,7 @@ var paymentPlanInfoText = function paymentPlanInfoText(payment) {
|
|
|
1970
1976
|
|
|
1971
1977
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(reactIntl.FormattedMessage, {
|
|
1972
1978
|
id: "payment-plan-strings.multiple-installments",
|
|
1973
|
-
defaultMessage: "{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}",
|
|
1979
|
+
defaultMessage: "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
|
|
1974
1980
|
values: {
|
|
1975
1981
|
firstInstallmentAmount: /*#__PURE__*/React__default.createElement(reactIntl.FormattedNumber, {
|
|
1976
1982
|
value: priceFromCents(payment.payment_plan[0].total_amount),
|
|
@@ -2336,16 +2342,54 @@ var useButtonAnimation = function useButtonAnimation(iterateValues, transitionDe
|
|
|
2336
2342
|
};
|
|
2337
2343
|
};
|
|
2338
2344
|
|
|
2339
|
-
|
|
2345
|
+
/**
|
|
2346
|
+
* It returns the **index** of the **first eligible plan** that matches the default installments count
|
|
2347
|
+
*
|
|
2348
|
+
* @param {number | number[]} suggestedPaymentPlan
|
|
2349
|
+
* @param {EligibilityPlan[]} eligibilityPlans
|
|
2350
|
+
* @returns number (index of the first eligible plan that matches the default installments count)
|
|
2351
|
+
*/
|
|
2352
|
+
var getIndexOfActivePlan = function getIndexOfActivePlan(_ref) {
|
|
2353
|
+
var suggestedPaymentPlan = _ref.suggestedPaymentPlan,
|
|
2354
|
+
eligibilityPlans = _ref.eligibilityPlans;
|
|
2355
|
+
var suggestedPaymentPlanArray = Array.isArray(suggestedPaymentPlan) ? suggestedPaymentPlan : [suggestedPaymentPlan];
|
|
2356
|
+
|
|
2357
|
+
var _loop = function _loop(index) {
|
|
2358
|
+
var installmentsCount = suggestedPaymentPlanArray[index];
|
|
2359
|
+
var planFound = eligibilityPlans.findIndex(function (plan) {
|
|
2360
|
+
return plan.installments_count === installmentsCount && plan.eligible;
|
|
2361
|
+
});
|
|
2362
|
+
|
|
2363
|
+
if (planFound !== -1) {
|
|
2364
|
+
return {
|
|
2365
|
+
v: planFound
|
|
2366
|
+
};
|
|
2367
|
+
}
|
|
2368
|
+
};
|
|
2369
|
+
|
|
2370
|
+
for (var index in suggestedPaymentPlanArray) {
|
|
2371
|
+
var _ret = _loop(index);
|
|
2372
|
+
|
|
2373
|
+
if (typeof _ret === "object") return _ret.v;
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
return 0;
|
|
2377
|
+
};
|
|
2378
|
+
|
|
2379
|
+
var s$b = {"widgetButton":"_TSkFv","logo":"_LJ4nZ","primaryContainer":"_bMClc","paymentPlans":"_17c_S","plan":"_2Kqjn","active":"_3dG_J","notEligible":"_3O1bg","info":"_25GrF","loader":"_30j1O","error":"_R0YlN","errorText":"_2kGhu","errorButton":"_73d_Y","pending":"_1ZDMS","clickable":"_UksZa","unClickable":"_1lr-q"};
|
|
2380
|
+
|
|
2381
|
+
var VERY_LONG_TIME_IN_MS = 1000 * 3600 * 24 * 365;
|
|
2382
|
+
var DEFAULT_TRANSITION_TIME = 5500;
|
|
2340
2383
|
|
|
2341
2384
|
var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
|
|
2342
|
-
var
|
|
2385
|
+
var _cx, _cx3;
|
|
2343
2386
|
|
|
2344
2387
|
var purchaseAmount = _ref.purchaseAmount,
|
|
2345
2388
|
apiData = _ref.apiData,
|
|
2346
2389
|
configPlans = _ref.configPlans,
|
|
2347
2390
|
transitionDelay = _ref.transitionDelay,
|
|
2348
|
-
hideIfNotEligible = _ref.hideIfNotEligible
|
|
2391
|
+
hideIfNotEligible = _ref.hideIfNotEligible,
|
|
2392
|
+
suggestedPaymentPlan = _ref.suggestedPaymentPlan;
|
|
2349
2393
|
|
|
2350
2394
|
var _useFetchEligibility = useFetchEligibility(purchaseAmount, apiData, configPlans),
|
|
2351
2395
|
eligibilityPlans = _useFetchEligibility[0],
|
|
@@ -2354,15 +2398,18 @@ var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
|
|
|
2354
2398
|
var eligiblePlans = eligibilityPlans.filter(function (plan) {
|
|
2355
2399
|
return plan.eligible;
|
|
2356
2400
|
});
|
|
2401
|
+
var activePlanIndex = getIndexOfActivePlan({
|
|
2402
|
+
eligibilityPlans: eligibilityPlans,
|
|
2403
|
+
suggestedPaymentPlan: suggestedPaymentPlan != null ? suggestedPaymentPlan : 0
|
|
2404
|
+
});
|
|
2405
|
+
var isSuggestedPaymentPlanSpecified = suggestedPaymentPlan !== undefined; // 👈 The merchant decided to focus a tab and remove animated transition.
|
|
2406
|
+
|
|
2407
|
+
var isTransitionSpecified = transitionDelay !== undefined; // 👈 The merchant has specified a transition time
|
|
2357
2408
|
|
|
2358
2409
|
var _useState = React.useState(false),
|
|
2359
2410
|
isOpen = _useState[0],
|
|
2360
2411
|
setIsOpen = _useState[1];
|
|
2361
2412
|
|
|
2362
|
-
var _useState2 = React.useState(0),
|
|
2363
|
-
initialPlanIndex = _useState2[0],
|
|
2364
|
-
setInitialPlanIndex = _useState2[1];
|
|
2365
|
-
|
|
2366
2413
|
var openModal = function openModal() {
|
|
2367
2414
|
return setIsOpen(true);
|
|
2368
2415
|
};
|
|
@@ -2374,19 +2421,51 @@ var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
|
|
|
2374
2421
|
var eligiblePlanKeys = eligibilityPlans.reduce(function (acc, plan, index) {
|
|
2375
2422
|
return plan.eligible ? [].concat(acc, [index]) : acc;
|
|
2376
2423
|
}, []);
|
|
2424
|
+
/**
|
|
2425
|
+
* If merchand specify a suggestedPaymentPlan and no transition, we set a very long transition delay.
|
|
2426
|
+
* Otherwise, we set the transition delay specified by the merchant.
|
|
2427
|
+
* If none of those properties are specified, we set a default transition delay.
|
|
2428
|
+
* @returns
|
|
2429
|
+
*/
|
|
2430
|
+
|
|
2431
|
+
var realTransitionTime = function realTransitionTime() {
|
|
2432
|
+
if (isTransitionSpecified) {
|
|
2433
|
+
return transitionDelay != null ? transitionDelay : DEFAULT_TRANSITION_TIME;
|
|
2434
|
+
}
|
|
2377
2435
|
|
|
2378
|
-
|
|
2436
|
+
if (isSuggestedPaymentPlanSpecified) {
|
|
2437
|
+
return VERY_LONG_TIME_IN_MS;
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
return DEFAULT_TRANSITION_TIME;
|
|
2441
|
+
};
|
|
2442
|
+
|
|
2443
|
+
var _useButtonAnimation = useButtonAnimation(eligiblePlanKeys, realTransitionTime()),
|
|
2379
2444
|
current = _useButtonAnimation.current,
|
|
2380
2445
|
onHover = _useButtonAnimation.onHover,
|
|
2381
|
-
onLeave = _useButtonAnimation.onLeave;
|
|
2382
|
-
// updates the `current` value (i.e. without any hover / click callback).
|
|
2383
|
-
|
|
2446
|
+
onLeave = _useButtonAnimation.onLeave;
|
|
2384
2447
|
|
|
2385
2448
|
React.useEffect(function () {
|
|
2386
|
-
|
|
2387
|
-
|
|
2449
|
+
// When API has given a response AND the marchand set an active plan by default.
|
|
2450
|
+
if (status === apiStatus.SUCCESS && isSuggestedPaymentPlanSpecified) {
|
|
2451
|
+
onHover(activePlanIndex); // We select the first active plan possible
|
|
2452
|
+
|
|
2453
|
+
onLeave(); // We need to call onLeave to reset the animation
|
|
2388
2454
|
}
|
|
2389
|
-
}, [
|
|
2455
|
+
}, [status]);
|
|
2456
|
+
/**
|
|
2457
|
+
* It takes a plan index and returns the index of that plan within the eligible plans
|
|
2458
|
+
*
|
|
2459
|
+
* @param {number} planIndex - The index of the plan that the user has selected.
|
|
2460
|
+
* @returns The index of the planKey in the eligiblePlanKeys array.
|
|
2461
|
+
*/
|
|
2462
|
+
|
|
2463
|
+
var getIndexWithinEligiblePlans = function getIndexWithinEligiblePlans(planIndex) {
|
|
2464
|
+
var index = eligiblePlanKeys.findIndex(function (planKey) {
|
|
2465
|
+
return planKey === planIndex;
|
|
2466
|
+
});
|
|
2467
|
+
return index === -1 ? 0 : index;
|
|
2468
|
+
};
|
|
2390
2469
|
|
|
2391
2470
|
if (status === apiStatus.PENDING) {
|
|
2392
2471
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
@@ -2394,11 +2473,7 @@ var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
|
|
|
2394
2473
|
}, /*#__PURE__*/React__default.createElement(Loader, null));
|
|
2395
2474
|
}
|
|
2396
2475
|
|
|
2397
|
-
if (hideIfNotEligible && eligiblePlans.length
|
|
2398
|
-
return null;
|
|
2399
|
-
}
|
|
2400
|
-
|
|
2401
|
-
if (status === apiStatus.FAILED) {
|
|
2476
|
+
if (hideIfNotEligible && eligiblePlans.length === 0 || eligibilityPlans.length === 0 || status === apiStatus.FAILED) {
|
|
2402
2477
|
return null;
|
|
2403
2478
|
}
|
|
2404
2479
|
|
|
@@ -2410,19 +2485,9 @@ var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
|
|
|
2410
2485
|
}
|
|
2411
2486
|
};
|
|
2412
2487
|
|
|
2413
|
-
var handleHoverAndClick = function handleHoverAndClick(key, newInitialPlanIndex) {
|
|
2414
|
-
// This is needed to update the initial plan index and button style when hovering (desktop) or clicking (mobile).
|
|
2415
|
-
// The actual modal opening is triggered by a click on the highest parent div in `handleOpenModal`.
|
|
2416
|
-
onHover(key);
|
|
2417
|
-
setInitialPlanIndex(newInitialPlanIndex);
|
|
2418
|
-
};
|
|
2419
|
-
|
|
2420
2488
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
|
|
2421
2489
|
onClick: handleOpenModal,
|
|
2422
|
-
className: s$b.widgetButton,
|
|
2423
|
-
style: {
|
|
2424
|
-
cursor: eligiblePlans.length > 0 ? 'pointer' : 'initial'
|
|
2425
|
-
},
|
|
2490
|
+
className: cx(s$b.widgetButton, (_cx = {}, _cx[s$b.clickable] = eligiblePlans.length > 0, _cx[s$b.unClickable] = eligiblePlans.length === 0, _cx)),
|
|
2426
2491
|
"data-testid": "widget-button"
|
|
2427
2492
|
}, /*#__PURE__*/React__default.createElement("div", {
|
|
2428
2493
|
className: s$b.primaryContainer
|
|
@@ -2431,28 +2496,20 @@ var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
|
|
|
2431
2496
|
}), /*#__PURE__*/React__default.createElement("div", {
|
|
2432
2497
|
className: s$b.paymentPlans
|
|
2433
2498
|
}, eligibilityPlans.map(function (eligibilityPlan, key) {
|
|
2434
|
-
var
|
|
2499
|
+
var _cx2;
|
|
2435
2500
|
|
|
2436
|
-
var newInitialPlanIndex = eligiblePlanKeys.includes(key) ? eligiblePlanKeys.findIndex(function (planKey) {
|
|
2437
|
-
return planKey === key;
|
|
2438
|
-
}) : 0;
|
|
2439
2501
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
2502
|
+
key: key,
|
|
2440
2503
|
onMouseEnter: function onMouseEnter() {
|
|
2441
|
-
|
|
2442
|
-
},
|
|
2443
|
-
onMouseOut: function onMouseOut() {
|
|
2444
|
-
onLeave();
|
|
2504
|
+
return onHover(key);
|
|
2445
2505
|
},
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
},
|
|
2449
|
-
key: key,
|
|
2450
|
-
className: cx(s$b.plan, (_cx = {}, _cx[s$b.active] = current === key, _cx[s$b.notEligible] = !eligibilityPlan.eligible, _cx))
|
|
2506
|
+
onMouseOut: onLeave,
|
|
2507
|
+
className: cx(s$b.plan, (_cx2 = {}, _cx2[s$b.active] = current === key, _cx2[s$b.notEligible] = !eligibilityPlan.eligible, _cx2))
|
|
2451
2508
|
}, paymentPlanShorthandName(eligibilityPlan));
|
|
2452
2509
|
}))), /*#__PURE__*/React__default.createElement("div", {
|
|
2453
|
-
className: cx(s$b.info, (
|
|
2510
|
+
className: cx(s$b.info, (_cx3 = {}, _cx3[s$b.notEligible] = eligibilityPlans[current] && !eligibilityPlans[current].eligible, _cx3))
|
|
2454
2511
|
}, eligibilityPlans.length !== 0 && paymentPlanInfoText(eligibilityPlans[current]))), isOpen && /*#__PURE__*/React__default.createElement(EligibilityModal, {
|
|
2455
|
-
initialPlanIndex:
|
|
2512
|
+
initialPlanIndex: getIndexWithinEligiblePlans(current),
|
|
2456
2513
|
onClose: closeModal,
|
|
2457
2514
|
eligibilityPlans: eligiblePlans,
|
|
2458
2515
|
status: status
|
|
@@ -2481,6 +2538,7 @@ var WidgetsController = /*#__PURE__*/function () {
|
|
|
2481
2538
|
plans = options.plans,
|
|
2482
2539
|
transitionDelay = options.transitionDelay,
|
|
2483
2540
|
hideIfNotEligible = options.hideIfNotEligible,
|
|
2541
|
+
suggestedPaymentPlan = options.suggestedPaymentPlan,
|
|
2484
2542
|
_options$locale = options.locale,
|
|
2485
2543
|
locale = _options$locale === void 0 ? Locale.en : _options$locale;
|
|
2486
2544
|
|
|
@@ -2492,7 +2550,8 @@ var WidgetsController = /*#__PURE__*/function () {
|
|
|
2492
2550
|
apiData: this.apiData,
|
|
2493
2551
|
configPlans: plans,
|
|
2494
2552
|
transitionDelay: transitionDelay,
|
|
2495
|
-
hideIfNotEligible: hideIfNotEligible
|
|
2553
|
+
hideIfNotEligible: hideIfNotEligible,
|
|
2554
|
+
suggestedPaymentPlan: suggestedPaymentPlan
|
|
2496
2555
|
})), document.querySelector(container));
|
|
2497
2556
|
}
|
|
2498
2557
|
}
|