@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.
@@ -1526,7 +1526,7 @@ var messagesDE = {
1526
1526
  "payment-plan-strings.deferred": "{totalAmount} zu zahlen am {dueDate}",
1527
1527
  "payment-plan-strings.ineligible-greater-than-max": "Bis zu {maxAmount}",
1528
1528
  "payment-plan-strings.ineligible-lower-than-min": "Ab {minAmount}",
1529
- "payment-plan-strings.multiple-installments": "{firstInstallmentAmount} dann {numberOfRemainingInstallments} x {othersInstallmentAmount}",
1529
+ "payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} dann {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} dann {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
1530
1530
  "payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
1531
1531
  "payment-plan-strings.no-fee": "(gebührenfrei)"
1532
1532
  };
@@ -1548,7 +1548,7 @@ var messagesEN = {
1548
1548
  "payment-plan-strings.deferred": "{totalAmount} to be paid on {dueDate}",
1549
1549
  "payment-plan-strings.ineligible-greater-than-max": "Until {maxAmount}",
1550
1550
  "payment-plan-strings.ineligible-lower-than-min": "From {minAmount}",
1551
- "payment-plan-strings.multiple-installments": "{firstInstallmentAmount} then {numberOfRemainingInstallments} x {othersInstallmentAmount}",
1551
+ "payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} then {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} then {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
1552
1552
  "payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
1553
1553
  "payment-plan-strings.no-fee": "(free of charge)"
1554
1554
  };
@@ -1570,7 +1570,7 @@ var messagesES = {
1570
1570
  "payment-plan-strings.deferred": "{totalAmount} a pagar el {dueDate}",
1571
1571
  "payment-plan-strings.ineligible-greater-than-max": "Hasta {maxAmount}",
1572
1572
  "payment-plan-strings.ineligible-lower-than-min": "Desde {minAmount}",
1573
- "payment-plan-strings.multiple-installments": "{firstInstallmentAmount} hoy, después {numberOfRemainingInstallments, plural, one {# mensualidad} other {# mensualidades}} de {othersInstallmentAmount}",
1573
+ "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}}}",
1574
1574
  "payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} plazos de {totalAmount}",
1575
1575
  "payment-plan-strings.no-fee": "(sin intereses)"
1576
1576
  };
@@ -1592,7 +1592,7 @@ var messagesFR = {
1592
1592
  "payment-plan-strings.deferred": "{totalAmount} à payer le {dueDate}",
1593
1593
  "payment-plan-strings.ineligible-greater-than-max": "Jusqu'à {maxAmount}",
1594
1594
  "payment-plan-strings.ineligible-lower-than-min": "À partir de {minAmount}",
1595
- "payment-plan-strings.multiple-installments": "{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}",
1595
+ "payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
1596
1596
  "payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
1597
1597
  "payment-plan-strings.no-fee": "(sans frais)"
1598
1598
  };
@@ -1614,7 +1614,7 @@ var messagesIT = {
1614
1614
  "payment-plan-strings.deferred": "{totalAmount} da pagare il {dueDate}",
1615
1615
  "payment-plan-strings.ineligible-greater-than-max": "Disponibile fino a {maxAmount}",
1616
1616
  "payment-plan-strings.ineligible-lower-than-min": "Pagamento rateale disponibile a partire da {minAmount}",
1617
- "payment-plan-strings.multiple-installments": "Oggi paghi {firstInstallmentAmount} poi {numberOfRemainingInstallments} rate mensili di {othersInstallmentAmount}",
1617
+ "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}}}",
1618
1618
  "payment-plan-strings.multiple-installments-same-amount": "In {installmentsCount} rate mensili di {totalAmount}",
1619
1619
  "payment-plan-strings.no-fee": "(senza interessi)"
1620
1620
  };
@@ -1622,7 +1622,7 @@ var messagesIT = {
1622
1622
  var messagesNL = {
1623
1623
  "eligibility-modal.bullet-1": "Kies <strong>Alma</strong> bij het afrekenen.",
1624
1624
  "eligibility-modal.bullet-2": "Vul de <strong>gevraagde informatie</strong> in.",
1625
- "eligibility-modal.bullet-3": "Validatie van uw betaling <strong>onmiddellijk</strong>!",
1625
+ "eligibility-modal.bullet-3": "Onmiddelijke validatie van uw betaling ",
1626
1626
  "eligibility-modal.cost": "Waarvan kosten",
1627
1627
  "eligibility-modal.credit-commitment": "Een lening bindt je en moet worden terugbetaald. Ga na of u kunt terugbetalen voordat u zich vastlegt.",
1628
1628
  "eligibility-modal.credit-cost": "Waarvan kosten van krediet",
@@ -1636,7 +1636,7 @@ var messagesNL = {
1636
1636
  "payment-plan-strings.deferred": "{totalAmount} te betalen op {dueDate}",
1637
1637
  "payment-plan-strings.ineligible-greater-than-max": "Tot {maxAmount}",
1638
1638
  "payment-plan-strings.ineligible-lower-than-min": "Van {minAmount}",
1639
- "payment-plan-strings.multiple-installments": "{firstInstallmentAmount} dan {numberOfRemainingInstallments} x {othersInstallmentAmount}",
1639
+ "payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} dan {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} dan {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
1640
1640
  "payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
1641
1641
  "payment-plan-strings.no-fee": "(gratis)"
1642
1642
  };
@@ -1735,6 +1735,12 @@ var filterELigibility = function filterELigibility(eligibilities, configPlans) {
1735
1735
  // Remove p1x
1736
1736
  var filteredEligibilityPlans = eligibilities.filter(function (plan) {
1737
1737
  return !(plan.installments_count === 1 && plan.deferred_days === 0 && plan.deferred_months === 0);
1738
+ }) // Keeps the plans that have a payment_plan property
1739
+ .filter(function (plan) {
1740
+ return plan.payment_plan;
1741
+ }) // Remove plans that have a reasons property
1742
+ .filter(function (plan) {
1743
+ return !plan.reasons;
1738
1744
  }); // If no configPlans was provided, return eligibility response
1739
1745
 
1740
1746
  if (!configPlans) {
@@ -1784,8 +1790,8 @@ var useFetchEligibility = function useFetchEligibility(purchaseAmount, _ref, pla
1784
1790
  }, {
1785
1791
  Authorization: "Alma-Merchant-Auth " + merchantId
1786
1792
  }).then(function (res) {
1787
- setStatus(apiStatus.SUCCESS);
1788
1793
  setEligibility(res);
1794
+ setStatus(apiStatus.SUCCESS);
1789
1795
  })["catch"](function () {
1790
1796
  setStatus(apiStatus.FAILED);
1791
1797
  });
@@ -1967,7 +1973,7 @@ var paymentPlanInfoText = function paymentPlanInfoText(payment) {
1967
1973
 
1968
1974
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormattedMessage, {
1969
1975
  id: "payment-plan-strings.multiple-installments",
1970
- defaultMessage: "{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}",
1976
+ defaultMessage: "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
1971
1977
  values: {
1972
1978
  firstInstallmentAmount: /*#__PURE__*/React.createElement(FormattedNumber, {
1973
1979
  value: priceFromCents(payment.payment_plan[0].total_amount),
@@ -2333,16 +2339,54 @@ var useButtonAnimation = function useButtonAnimation(iterateValues, transitionDe
2333
2339
  };
2334
2340
  };
2335
2341
 
2336
- 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"};
2342
+ /**
2343
+ * It returns the **index** of the **first eligible plan** that matches the default installments count
2344
+ *
2345
+ * @param {number | number[]} suggestedPaymentPlan
2346
+ * @param {EligibilityPlan[]} eligibilityPlans
2347
+ * @returns number (index of the first eligible plan that matches the default installments count)
2348
+ */
2349
+ var getIndexOfActivePlan = function getIndexOfActivePlan(_ref) {
2350
+ var suggestedPaymentPlan = _ref.suggestedPaymentPlan,
2351
+ eligibilityPlans = _ref.eligibilityPlans;
2352
+ var suggestedPaymentPlanArray = Array.isArray(suggestedPaymentPlan) ? suggestedPaymentPlan : [suggestedPaymentPlan];
2353
+
2354
+ var _loop = function _loop(index) {
2355
+ var installmentsCount = suggestedPaymentPlanArray[index];
2356
+ var planFound = eligibilityPlans.findIndex(function (plan) {
2357
+ return plan.installments_count === installmentsCount && plan.eligible;
2358
+ });
2359
+
2360
+ if (planFound !== -1) {
2361
+ return {
2362
+ v: planFound
2363
+ };
2364
+ }
2365
+ };
2366
+
2367
+ for (var index in suggestedPaymentPlanArray) {
2368
+ var _ret = _loop(index);
2369
+
2370
+ if (typeof _ret === "object") return _ret.v;
2371
+ }
2372
+
2373
+ return 0;
2374
+ };
2375
+
2376
+ 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"};
2377
+
2378
+ var VERY_LONG_TIME_IN_MS = 1000 * 3600 * 24 * 365;
2379
+ var DEFAULT_TRANSITION_TIME = 5500;
2337
2380
 
2338
2381
  var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
2339
- var _cx2;
2382
+ var _cx, _cx3;
2340
2383
 
2341
2384
  var purchaseAmount = _ref.purchaseAmount,
2342
2385
  apiData = _ref.apiData,
2343
2386
  configPlans = _ref.configPlans,
2344
2387
  transitionDelay = _ref.transitionDelay,
2345
- hideIfNotEligible = _ref.hideIfNotEligible;
2388
+ hideIfNotEligible = _ref.hideIfNotEligible,
2389
+ suggestedPaymentPlan = _ref.suggestedPaymentPlan;
2346
2390
 
2347
2391
  var _useFetchEligibility = useFetchEligibility(purchaseAmount, apiData, configPlans),
2348
2392
  eligibilityPlans = _useFetchEligibility[0],
@@ -2351,15 +2395,18 @@ var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
2351
2395
  var eligiblePlans = eligibilityPlans.filter(function (plan) {
2352
2396
  return plan.eligible;
2353
2397
  });
2398
+ var activePlanIndex = getIndexOfActivePlan({
2399
+ eligibilityPlans: eligibilityPlans,
2400
+ suggestedPaymentPlan: suggestedPaymentPlan != null ? suggestedPaymentPlan : 0
2401
+ });
2402
+ var isSuggestedPaymentPlanSpecified = suggestedPaymentPlan !== undefined; // 👈 The merchant decided to focus a tab and remove animated transition.
2403
+
2404
+ var isTransitionSpecified = transitionDelay !== undefined; // 👈 The merchant has specified a transition time
2354
2405
 
2355
2406
  var _useState = useState(false),
2356
2407
  isOpen = _useState[0],
2357
2408
  setIsOpen = _useState[1];
2358
2409
 
2359
- var _useState2 = useState(0),
2360
- initialPlanIndex = _useState2[0],
2361
- setInitialPlanIndex = _useState2[1];
2362
-
2363
2410
  var openModal = function openModal() {
2364
2411
  return setIsOpen(true);
2365
2412
  };
@@ -2371,19 +2418,51 @@ var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
2371
2418
  var eligiblePlanKeys = eligibilityPlans.reduce(function (acc, plan, index) {
2372
2419
  return plan.eligible ? [].concat(acc, [index]) : acc;
2373
2420
  }, []);
2421
+ /**
2422
+ * If merchand specify a suggestedPaymentPlan and no transition, we set a very long transition delay.
2423
+ * Otherwise, we set the transition delay specified by the merchant.
2424
+ * If none of those properties are specified, we set a default transition delay.
2425
+ * @returns
2426
+ */
2427
+
2428
+ var realTransitionTime = function realTransitionTime() {
2429
+ if (isTransitionSpecified) {
2430
+ return transitionDelay != null ? transitionDelay : DEFAULT_TRANSITION_TIME;
2431
+ }
2374
2432
 
2375
- var _useButtonAnimation = useButtonAnimation(eligiblePlanKeys, transitionDelay ? transitionDelay : 5500),
2433
+ if (isSuggestedPaymentPlanSpecified) {
2434
+ return VERY_LONG_TIME_IN_MS;
2435
+ }
2436
+
2437
+ return DEFAULT_TRANSITION_TIME;
2438
+ };
2439
+
2440
+ var _useButtonAnimation = useButtonAnimation(eligiblePlanKeys, realTransitionTime()),
2376
2441
  current = _useButtonAnimation.current,
2377
2442
  onHover = _useButtonAnimation.onHover,
2378
- onLeave = _useButtonAnimation.onLeave; // This hook is needed to update the initial plan index when useButtonAnimation
2379
- // updates the `current` value (i.e. without any hover / click callback).
2380
-
2443
+ onLeave = _useButtonAnimation.onLeave;
2381
2444
 
2382
2445
  useEffect(function () {
2383
- if (current !== initialPlanIndex) {
2384
- setInitialPlanIndex(current);
2446
+ // When API has given a response AND the marchand set an active plan by default.
2447
+ if (status === apiStatus.SUCCESS && isSuggestedPaymentPlanSpecified) {
2448
+ onHover(activePlanIndex); // We select the first active plan possible
2449
+
2450
+ onLeave(); // We need to call onLeave to reset the animation
2385
2451
  }
2386
- }, [current, initialPlanIndex]);
2452
+ }, [status]);
2453
+ /**
2454
+ * It takes a plan index and returns the index of that plan within the eligible plans
2455
+ *
2456
+ * @param {number} planIndex - The index of the plan that the user has selected.
2457
+ * @returns The index of the planKey in the eligiblePlanKeys array.
2458
+ */
2459
+
2460
+ var getIndexWithinEligiblePlans = function getIndexWithinEligiblePlans(planIndex) {
2461
+ var index = eligiblePlanKeys.findIndex(function (planKey) {
2462
+ return planKey === planIndex;
2463
+ });
2464
+ return index === -1 ? 0 : index;
2465
+ };
2387
2466
 
2388
2467
  if (status === apiStatus.PENDING) {
2389
2468
  return /*#__PURE__*/React.createElement("div", {
@@ -2391,11 +2470,7 @@ var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
2391
2470
  }, /*#__PURE__*/React.createElement(Loader, null));
2392
2471
  }
2393
2472
 
2394
- if (hideIfNotEligible && eligiblePlans.length == 0 || eligibilityPlans.length === 0) {
2395
- return null;
2396
- }
2397
-
2398
- if (status === apiStatus.FAILED) {
2473
+ if (hideIfNotEligible && eligiblePlans.length === 0 || eligibilityPlans.length === 0 || status === apiStatus.FAILED) {
2399
2474
  return null;
2400
2475
  }
2401
2476
 
@@ -2407,19 +2482,9 @@ var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
2407
2482
  }
2408
2483
  };
2409
2484
 
2410
- var handleHoverAndClick = function handleHoverAndClick(key, newInitialPlanIndex) {
2411
- // This is needed to update the initial plan index and button style when hovering (desktop) or clicking (mobile).
2412
- // The actual modal opening is triggered by a click on the highest parent div in `handleOpenModal`.
2413
- onHover(key);
2414
- setInitialPlanIndex(newInitialPlanIndex);
2415
- };
2416
-
2417
2485
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
2418
2486
  onClick: handleOpenModal,
2419
- className: s$b.widgetButton,
2420
- style: {
2421
- cursor: eligiblePlans.length > 0 ? 'pointer' : 'initial'
2422
- },
2487
+ className: cx(s$b.widgetButton, (_cx = {}, _cx[s$b.clickable] = eligiblePlans.length > 0, _cx[s$b.unClickable] = eligiblePlans.length === 0, _cx)),
2423
2488
  "data-testid": "widget-button"
2424
2489
  }, /*#__PURE__*/React.createElement("div", {
2425
2490
  className: s$b.primaryContainer
@@ -2428,28 +2493,20 @@ var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
2428
2493
  }), /*#__PURE__*/React.createElement("div", {
2429
2494
  className: s$b.paymentPlans
2430
2495
  }, eligibilityPlans.map(function (eligibilityPlan, key) {
2431
- var _cx;
2496
+ var _cx2;
2432
2497
 
2433
- var newInitialPlanIndex = eligiblePlanKeys.includes(key) ? eligiblePlanKeys.findIndex(function (planKey) {
2434
- return planKey === key;
2435
- }) : 0;
2436
2498
  return /*#__PURE__*/React.createElement("div", {
2499
+ key: key,
2437
2500
  onMouseEnter: function onMouseEnter() {
2438
- handleHoverAndClick(key, newInitialPlanIndex);
2439
- },
2440
- onMouseOut: function onMouseOut() {
2441
- onLeave();
2501
+ return onHover(key);
2442
2502
  },
2443
- onClick: function onClick() {
2444
- handleHoverAndClick(key, newInitialPlanIndex);
2445
- },
2446
- key: key,
2447
- className: cx(s$b.plan, (_cx = {}, _cx[s$b.active] = current === key, _cx[s$b.notEligible] = !eligibilityPlan.eligible, _cx))
2503
+ onMouseOut: onLeave,
2504
+ className: cx(s$b.plan, (_cx2 = {}, _cx2[s$b.active] = current === key, _cx2[s$b.notEligible] = !eligibilityPlan.eligible, _cx2))
2448
2505
  }, paymentPlanShorthandName(eligibilityPlan));
2449
2506
  }))), /*#__PURE__*/React.createElement("div", {
2450
- className: cx(s$b.info, (_cx2 = {}, _cx2[s$b.notEligible] = eligibilityPlans[current] && !eligibilityPlans[current].eligible, _cx2))
2507
+ className: cx(s$b.info, (_cx3 = {}, _cx3[s$b.notEligible] = eligibilityPlans[current] && !eligibilityPlans[current].eligible, _cx3))
2451
2508
  }, eligibilityPlans.length !== 0 && paymentPlanInfoText(eligibilityPlans[current]))), isOpen && /*#__PURE__*/React.createElement(EligibilityModal, {
2452
- initialPlanIndex: initialPlanIndex,
2509
+ initialPlanIndex: getIndexWithinEligiblePlans(current),
2453
2510
  onClose: closeModal,
2454
2511
  eligibilityPlans: eligiblePlans,
2455
2512
  status: status
@@ -2478,6 +2535,7 @@ var WidgetsController = /*#__PURE__*/function () {
2478
2535
  plans = options.plans,
2479
2536
  transitionDelay = options.transitionDelay,
2480
2537
  hideIfNotEligible = options.hideIfNotEligible,
2538
+ suggestedPaymentPlan = options.suggestedPaymentPlan,
2481
2539
  _options$locale = options.locale,
2482
2540
  locale = _options$locale === void 0 ? Locale.en : _options$locale;
2483
2541
 
@@ -2489,7 +2547,8 @@ var WidgetsController = /*#__PURE__*/function () {
2489
2547
  apiData: this.apiData,
2490
2548
  configPlans: plans,
2491
2549
  transitionDelay: transitionDelay,
2492
- hideIfNotEligible: hideIfNotEligible
2550
+ hideIfNotEligible: hideIfNotEligible,
2551
+ suggestedPaymentPlan: suggestedPaymentPlan
2493
2552
  })), document.querySelector(container));
2494
2553
  }
2495
2554
  }