@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.
@@ -6134,7 +6134,7 @@
6134
6134
  "payment-plan-strings.deferred": "{totalAmount} zu zahlen am {dueDate}",
6135
6135
  "payment-plan-strings.ineligible-greater-than-max": "Bis zu {maxAmount}",
6136
6136
  "payment-plan-strings.ineligible-lower-than-min": "Ab {minAmount}",
6137
- "payment-plan-strings.multiple-installments": "{firstInstallmentAmount} dann {numberOfRemainingInstallments} x {othersInstallmentAmount}",
6137
+ "payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} dann {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} dann {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
6138
6138
  "payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
6139
6139
  "payment-plan-strings.no-fee": "(gebührenfrei)"
6140
6140
  };
@@ -6156,7 +6156,7 @@
6156
6156
  "payment-plan-strings.deferred": "{totalAmount} to be paid on {dueDate}",
6157
6157
  "payment-plan-strings.ineligible-greater-than-max": "Until {maxAmount}",
6158
6158
  "payment-plan-strings.ineligible-lower-than-min": "From {minAmount}",
6159
- "payment-plan-strings.multiple-installments": "{firstInstallmentAmount} then {numberOfRemainingInstallments} x {othersInstallmentAmount}",
6159
+ "payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} then {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} then {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
6160
6160
  "payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
6161
6161
  "payment-plan-strings.no-fee": "(free of charge)"
6162
6162
  };
@@ -6178,7 +6178,7 @@
6178
6178
  "payment-plan-strings.deferred": "{totalAmount} a pagar el {dueDate}",
6179
6179
  "payment-plan-strings.ineligible-greater-than-max": "Hasta {maxAmount}",
6180
6180
  "payment-plan-strings.ineligible-lower-than-min": "Desde {minAmount}",
6181
- "payment-plan-strings.multiple-installments": "{firstInstallmentAmount} hoy, después {numberOfRemainingInstallments, plural, one {# mensualidad} other {# mensualidades}} de {othersInstallmentAmount}",
6181
+ "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}}}",
6182
6182
  "payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} plazos de {totalAmount}",
6183
6183
  "payment-plan-strings.no-fee": "(sin intereses)"
6184
6184
  };
@@ -6200,7 +6200,7 @@
6200
6200
  "payment-plan-strings.deferred": "{totalAmount} à payer le {dueDate}",
6201
6201
  "payment-plan-strings.ineligible-greater-than-max": "Jusqu'à {maxAmount}",
6202
6202
  "payment-plan-strings.ineligible-lower-than-min": "À partir de {minAmount}",
6203
- "payment-plan-strings.multiple-installments": "{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}",
6203
+ "payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
6204
6204
  "payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
6205
6205
  "payment-plan-strings.no-fee": "(sans frais)"
6206
6206
  };
@@ -6222,7 +6222,7 @@
6222
6222
  "payment-plan-strings.deferred": "{totalAmount} da pagare il {dueDate}",
6223
6223
  "payment-plan-strings.ineligible-greater-than-max": "Disponibile fino a {maxAmount}",
6224
6224
  "payment-plan-strings.ineligible-lower-than-min": "Pagamento rateale disponibile a partire da {minAmount}",
6225
- "payment-plan-strings.multiple-installments": "Oggi paghi {firstInstallmentAmount} poi {numberOfRemainingInstallments} rate mensili di {othersInstallmentAmount}",
6225
+ "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}}}",
6226
6226
  "payment-plan-strings.multiple-installments-same-amount": "In {installmentsCount} rate mensili di {totalAmount}",
6227
6227
  "payment-plan-strings.no-fee": "(senza interessi)"
6228
6228
  };
@@ -6230,7 +6230,7 @@
6230
6230
  var messagesNL = {
6231
6231
  "eligibility-modal.bullet-1": "Kies <strong>Alma</strong> bij het afrekenen.",
6232
6232
  "eligibility-modal.bullet-2": "Vul de <strong>gevraagde informatie</strong> in.",
6233
- "eligibility-modal.bullet-3": "Validatie van uw betaling <strong>onmiddellijk</strong>!",
6233
+ "eligibility-modal.bullet-3": "Onmiddelijke validatie van uw betaling ",
6234
6234
  "eligibility-modal.cost": "Waarvan kosten",
6235
6235
  "eligibility-modal.credit-commitment": "Een lening bindt je en moet worden terugbetaald. Ga na of u kunt terugbetalen voordat u zich vastlegt.",
6236
6236
  "eligibility-modal.credit-cost": "Waarvan kosten van krediet",
@@ -6244,7 +6244,7 @@
6244
6244
  "payment-plan-strings.deferred": "{totalAmount} te betalen op {dueDate}",
6245
6245
  "payment-plan-strings.ineligible-greater-than-max": "Tot {maxAmount}",
6246
6246
  "payment-plan-strings.ineligible-lower-than-min": "Van {minAmount}",
6247
- "payment-plan-strings.multiple-installments": "{firstInstallmentAmount} dan {numberOfRemainingInstallments} x {othersInstallmentAmount}",
6247
+ "payment-plan-strings.multiple-installments": "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} dan {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} dan {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
6248
6248
  "payment-plan-strings.multiple-installments-same-amount": "{installmentsCount} x {totalAmount}",
6249
6249
  "payment-plan-strings.no-fee": "(gratis)"
6250
6250
  };
@@ -14310,6 +14310,12 @@
14310
14310
  // Remove p1x
14311
14311
  var filteredEligibilityPlans = eligibilities.filter(function (plan) {
14312
14312
  return !(plan.installments_count === 1 && plan.deferred_days === 0 && plan.deferred_months === 0);
14313
+ }) // Keeps the plans that have a payment_plan property
14314
+ .filter(function (plan) {
14315
+ return plan.payment_plan;
14316
+ }) // Remove plans that have a reasons property
14317
+ .filter(function (plan) {
14318
+ return !plan.reasons;
14313
14319
  }); // If no configPlans was provided, return eligibility response
14314
14320
 
14315
14321
  if (!configPlans) {
@@ -14359,8 +14365,8 @@
14359
14365
  }, {
14360
14366
  Authorization: "Alma-Merchant-Auth " + merchantId
14361
14367
  }).then(function (res) {
14362
- setStatus(apiStatus.SUCCESS);
14363
14368
  setEligibility(res);
14369
+ setStatus(apiStatus.SUCCESS);
14364
14370
  })["catch"](function () {
14365
14371
  setStatus(apiStatus.FAILED);
14366
14372
  });
@@ -17846,7 +17852,7 @@
17846
17852
 
17847
17853
  return /*#__PURE__*/react.createElement(react.Fragment, null, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
17848
17854
  id: "payment-plan-strings.multiple-installments",
17849
- defaultMessage: "{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}",
17855
+ defaultMessage: "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
17850
17856
  values: {
17851
17857
  firstInstallmentAmount: /*#__PURE__*/react.createElement(FormattedNumber, {
17852
17858
  value: priceFromCents(payment.payment_plan[0].total_amount),
@@ -18212,16 +18218,54 @@
18212
18218
  };
18213
18219
  };
18214
18220
 
18215
- 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"};
18221
+ /**
18222
+ * It returns the **index** of the **first eligible plan** that matches the default installments count
18223
+ *
18224
+ * @param {number | number[]} suggestedPaymentPlan
18225
+ * @param {EligibilityPlan[]} eligibilityPlans
18226
+ * @returns number (index of the first eligible plan that matches the default installments count)
18227
+ */
18228
+ var getIndexOfActivePlan = function getIndexOfActivePlan(_ref) {
18229
+ var suggestedPaymentPlan = _ref.suggestedPaymentPlan,
18230
+ eligibilityPlans = _ref.eligibilityPlans;
18231
+ var suggestedPaymentPlanArray = Array.isArray(suggestedPaymentPlan) ? suggestedPaymentPlan : [suggestedPaymentPlan];
18232
+
18233
+ var _loop = function _loop(index) {
18234
+ var installmentsCount = suggestedPaymentPlanArray[index];
18235
+ var planFound = eligibilityPlans.findIndex(function (plan) {
18236
+ return plan.installments_count === installmentsCount && plan.eligible;
18237
+ });
18238
+
18239
+ if (planFound !== -1) {
18240
+ return {
18241
+ v: planFound
18242
+ };
18243
+ }
18244
+ };
18245
+
18246
+ for (var index in suggestedPaymentPlanArray) {
18247
+ var _ret = _loop(index);
18248
+
18249
+ if (typeof _ret === "object") return _ret.v;
18250
+ }
18251
+
18252
+ return 0;
18253
+ };
18254
+
18255
+ 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"};
18256
+
18257
+ var VERY_LONG_TIME_IN_MS = 1000 * 3600 * 24 * 365;
18258
+ var DEFAULT_TRANSITION_TIME = 5500;
18216
18259
 
18217
18260
  var PaymentPlanWidget = function PaymentPlanWidget(_ref) {
18218
- var _cx2;
18261
+ var _cx, _cx3;
18219
18262
 
18220
18263
  var purchaseAmount = _ref.purchaseAmount,
18221
18264
  apiData = _ref.apiData,
18222
18265
  configPlans = _ref.configPlans,
18223
18266
  transitionDelay = _ref.transitionDelay,
18224
- hideIfNotEligible = _ref.hideIfNotEligible;
18267
+ hideIfNotEligible = _ref.hideIfNotEligible,
18268
+ suggestedPaymentPlan = _ref.suggestedPaymentPlan;
18225
18269
 
18226
18270
  var _useFetchEligibility = useFetchEligibility(purchaseAmount, apiData, configPlans),
18227
18271
  eligibilityPlans = _useFetchEligibility[0],
@@ -18230,15 +18274,18 @@
18230
18274
  var eligiblePlans = eligibilityPlans.filter(function (plan) {
18231
18275
  return plan.eligible;
18232
18276
  });
18277
+ var activePlanIndex = getIndexOfActivePlan({
18278
+ eligibilityPlans: eligibilityPlans,
18279
+ suggestedPaymentPlan: suggestedPaymentPlan != null ? suggestedPaymentPlan : 0
18280
+ });
18281
+ var isSuggestedPaymentPlanSpecified = suggestedPaymentPlan !== undefined; // 👈 The merchant decided to focus a tab and remove animated transition.
18282
+
18283
+ var isTransitionSpecified = transitionDelay !== undefined; // 👈 The merchant has specified a transition time
18233
18284
 
18234
18285
  var _useState = react.useState(false),
18235
18286
  isOpen = _useState[0],
18236
18287
  setIsOpen = _useState[1];
18237
18288
 
18238
- var _useState2 = react.useState(0),
18239
- initialPlanIndex = _useState2[0],
18240
- setInitialPlanIndex = _useState2[1];
18241
-
18242
18289
  var openModal = function openModal() {
18243
18290
  return setIsOpen(true);
18244
18291
  };
@@ -18250,19 +18297,51 @@
18250
18297
  var eligiblePlanKeys = eligibilityPlans.reduce(function (acc, plan, index) {
18251
18298
  return plan.eligible ? [].concat(acc, [index]) : acc;
18252
18299
  }, []);
18300
+ /**
18301
+ * If merchand specify a suggestedPaymentPlan and no transition, we set a very long transition delay.
18302
+ * Otherwise, we set the transition delay specified by the merchant.
18303
+ * If none of those properties are specified, we set a default transition delay.
18304
+ * @returns
18305
+ */
18306
+
18307
+ var realTransitionTime = function realTransitionTime() {
18308
+ if (isTransitionSpecified) {
18309
+ return transitionDelay != null ? transitionDelay : DEFAULT_TRANSITION_TIME;
18310
+ }
18253
18311
 
18254
- var _useButtonAnimation = useButtonAnimation(eligiblePlanKeys, transitionDelay ? transitionDelay : 5500),
18312
+ if (isSuggestedPaymentPlanSpecified) {
18313
+ return VERY_LONG_TIME_IN_MS;
18314
+ }
18315
+
18316
+ return DEFAULT_TRANSITION_TIME;
18317
+ };
18318
+
18319
+ var _useButtonAnimation = useButtonAnimation(eligiblePlanKeys, realTransitionTime()),
18255
18320
  current = _useButtonAnimation.current,
18256
18321
  onHover = _useButtonAnimation.onHover,
18257
- onLeave = _useButtonAnimation.onLeave; // This hook is needed to update the initial plan index when useButtonAnimation
18258
- // updates the `current` value (i.e. without any hover / click callback).
18259
-
18322
+ onLeave = _useButtonAnimation.onLeave;
18260
18323
 
18261
18324
  react.useEffect(function () {
18262
- if (current !== initialPlanIndex) {
18263
- setInitialPlanIndex(current);
18325
+ // When API has given a response AND the marchand set an active plan by default.
18326
+ if (status === apiStatus.SUCCESS && isSuggestedPaymentPlanSpecified) {
18327
+ onHover(activePlanIndex); // We select the first active plan possible
18328
+
18329
+ onLeave(); // We need to call onLeave to reset the animation
18264
18330
  }
18265
- }, [current, initialPlanIndex]);
18331
+ }, [status]);
18332
+ /**
18333
+ * It takes a plan index and returns the index of that plan within the eligible plans
18334
+ *
18335
+ * @param {number} planIndex - The index of the plan that the user has selected.
18336
+ * @returns The index of the planKey in the eligiblePlanKeys array.
18337
+ */
18338
+
18339
+ var getIndexWithinEligiblePlans = function getIndexWithinEligiblePlans(planIndex) {
18340
+ var index = eligiblePlanKeys.findIndex(function (planKey) {
18341
+ return planKey === planIndex;
18342
+ });
18343
+ return index === -1 ? 0 : index;
18344
+ };
18266
18345
 
18267
18346
  if (status === apiStatus.PENDING) {
18268
18347
  return /*#__PURE__*/react.createElement("div", {
@@ -18270,11 +18349,7 @@
18270
18349
  }, /*#__PURE__*/react.createElement(Loader, null));
18271
18350
  }
18272
18351
 
18273
- if (hideIfNotEligible && eligiblePlans.length == 0 || eligibilityPlans.length === 0) {
18274
- return null;
18275
- }
18276
-
18277
- if (status === apiStatus.FAILED) {
18352
+ if (hideIfNotEligible && eligiblePlans.length === 0 || eligibilityPlans.length === 0 || status === apiStatus.FAILED) {
18278
18353
  return null;
18279
18354
  }
18280
18355
 
@@ -18286,19 +18361,9 @@
18286
18361
  }
18287
18362
  };
18288
18363
 
18289
- var handleHoverAndClick = function handleHoverAndClick(key, newInitialPlanIndex) {
18290
- // This is needed to update the initial plan index and button style when hovering (desktop) or clicking (mobile).
18291
- // The actual modal opening is triggered by a click on the highest parent div in `handleOpenModal`.
18292
- onHover(key);
18293
- setInitialPlanIndex(newInitialPlanIndex);
18294
- };
18295
-
18296
18364
  return /*#__PURE__*/react.createElement(react.Fragment, null, /*#__PURE__*/react.createElement("div", {
18297
18365
  onClick: handleOpenModal,
18298
- className: s$b.widgetButton,
18299
- style: {
18300
- cursor: eligiblePlans.length > 0 ? 'pointer' : 'initial'
18301
- },
18366
+ className: classnames(s$b.widgetButton, (_cx = {}, _cx[s$b.clickable] = eligiblePlans.length > 0, _cx[s$b.unClickable] = eligiblePlans.length === 0, _cx)),
18302
18367
  "data-testid": "widget-button"
18303
18368
  }, /*#__PURE__*/react.createElement("div", {
18304
18369
  className: s$b.primaryContainer
@@ -18307,28 +18372,20 @@
18307
18372
  }), /*#__PURE__*/react.createElement("div", {
18308
18373
  className: s$b.paymentPlans
18309
18374
  }, eligibilityPlans.map(function (eligibilityPlan, key) {
18310
- var _cx;
18375
+ var _cx2;
18311
18376
 
18312
- var newInitialPlanIndex = eligiblePlanKeys.includes(key) ? eligiblePlanKeys.findIndex(function (planKey) {
18313
- return planKey === key;
18314
- }) : 0;
18315
18377
  return /*#__PURE__*/react.createElement("div", {
18378
+ key: key,
18316
18379
  onMouseEnter: function onMouseEnter() {
18317
- handleHoverAndClick(key, newInitialPlanIndex);
18318
- },
18319
- onMouseOut: function onMouseOut() {
18320
- onLeave();
18380
+ return onHover(key);
18321
18381
  },
18322
- onClick: function onClick() {
18323
- handleHoverAndClick(key, newInitialPlanIndex);
18324
- },
18325
- key: key,
18326
- className: classnames(s$b.plan, (_cx = {}, _cx[s$b.active] = current === key, _cx[s$b.notEligible] = !eligibilityPlan.eligible, _cx))
18382
+ onMouseOut: onLeave,
18383
+ className: classnames(s$b.plan, (_cx2 = {}, _cx2[s$b.active] = current === key, _cx2[s$b.notEligible] = !eligibilityPlan.eligible, _cx2))
18327
18384
  }, paymentPlanShorthandName(eligibilityPlan));
18328
18385
  }))), /*#__PURE__*/react.createElement("div", {
18329
- className: classnames(s$b.info, (_cx2 = {}, _cx2[s$b.notEligible] = eligibilityPlans[current] && !eligibilityPlans[current].eligible, _cx2))
18386
+ className: classnames(s$b.info, (_cx3 = {}, _cx3[s$b.notEligible] = eligibilityPlans[current] && !eligibilityPlans[current].eligible, _cx3))
18330
18387
  }, eligibilityPlans.length !== 0 && paymentPlanInfoText(eligibilityPlans[current]))), isOpen && /*#__PURE__*/react.createElement(EligibilityModal, {
18331
- initialPlanIndex: initialPlanIndex,
18388
+ initialPlanIndex: getIndexWithinEligiblePlans(current),
18332
18389
  onClose: closeModal,
18333
18390
  eligibilityPlans: eligiblePlans,
18334
18391
  status: status
@@ -18357,6 +18414,7 @@
18357
18414
  plans = options.plans,
18358
18415
  transitionDelay = options.transitionDelay,
18359
18416
  hideIfNotEligible = options.hideIfNotEligible,
18417
+ suggestedPaymentPlan = options.suggestedPaymentPlan,
18360
18418
  _options$locale = options.locale,
18361
18419
  locale = _options$locale === void 0 ? Locale.en : _options$locale;
18362
18420
 
@@ -18368,7 +18426,8 @@
18368
18426
  apiData: this.apiData,
18369
18427
  configPlans: plans,
18370
18428
  transitionDelay: transitionDelay,
18371
- hideIfNotEligible: hideIfNotEligible
18429
+ hideIfNotEligible: hideIfNotEligible,
18430
+ suggestedPaymentPlan: suggestedPaymentPlan
18372
18431
  })), document.querySelector(container));
18373
18432
  }
18374
18433
  }