@alma/widgets 2.3.4 → 2.4.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.
@@ -14473,16 +14473,34 @@
14473
14473
  }
14474
14474
  };
14475
14475
 
14476
+ var isPlanEligible = function isPlanEligible(plan, configPlan) {
14477
+ if (!plan.eligible) {
14478
+ return false;
14479
+ }
14480
+
14481
+ return configPlan ? plan.purchase_amount >= (configPlan == null ? void 0 : configPlan.minAmount) && plan.purchase_amount <= (configPlan == null ? void 0 : configPlan.maxAmount) : false;
14482
+ };
14483
+
14484
+ var getPaymentPlanBoundaries = function getPaymentPlanBoundaries(plan, configPlan) {
14485
+ var _plan$constraints;
14486
+
14487
+ // When the plan is not eligible, the purchase amount constraints is given from the merchant config
14488
+ var purchaseAmountConstraints = (_plan$constraints = plan.constraints) == null ? void 0 : _plan$constraints.purchase_amount;
14489
+
14490
+ if (purchaseAmountConstraints && configPlan) {
14491
+ return {
14492
+ minAmount: Math.max(configPlan.minAmount, purchaseAmountConstraints == null ? void 0 : purchaseAmountConstraints.minimum),
14493
+ maxAmount: Math.min(configPlan.maxAmount, purchaseAmountConstraints == null ? void 0 : purchaseAmountConstraints.maximum)
14494
+ };
14495
+ }
14496
+
14497
+ return configPlan != null ? configPlan : {};
14498
+ };
14499
+
14476
14500
  var filterELigibility = function filterELigibility(eligibilities, configPlans) {
14477
14501
  // Remove p1x
14478
14502
  var filteredEligibilityPlans = eligibilities.filter(function (plan) {
14479
14503
  return !(plan.installments_count === 1 && plan.deferred_days === 0 && plan.deferred_months === 0);
14480
- }) // Keeps the plans that have a payment_plan property
14481
- .filter(function (plan) {
14482
- return plan.payment_plan;
14483
- }) // Remove plans that have a reasons property
14484
- .filter(function (plan) {
14485
- return !plan.reasons;
14486
14504
  }); // If no configPlans was provided, return eligibility response
14487
14505
 
14488
14506
  if (!configPlans) {
@@ -14498,10 +14516,8 @@
14498
14516
  return plan.installments_count === configPlan.installmentsCount && eligibilityDeferredDays === configPlanDeferredDays;
14499
14517
  });
14500
14518
  return _extends({}, plan, {
14501
- eligible: relatedConfigPlan ? plan.purchase_amount >= (relatedConfigPlan == null ? void 0 : relatedConfigPlan.minAmount) && plan.purchase_amount <= (relatedConfigPlan == null ? void 0 : relatedConfigPlan.maxAmount) : false,
14502
- minAmount: relatedConfigPlan == null ? void 0 : relatedConfigPlan.minAmount,
14503
- maxAmount: relatedConfigPlan == null ? void 0 : relatedConfigPlan.maxAmount
14504
- });
14519
+ eligible: isPlanEligible(plan, relatedConfigPlan)
14520
+ }, getPaymentPlanBoundaries(plan, relatedConfigPlan));
14505
14521
  });
14506
14522
  };
14507
14523
 
@@ -16738,6 +16754,29 @@
16738
16754
  }));
16739
16755
  }
16740
16756
 
16757
+ /**
16758
+ * Prefix classes to avoid name collisions.
16759
+ */
16760
+ var prefix = 'alma-eligibility-modal';
16761
+ /**
16762
+ * Class names for the **eligibility modale** widget.
16763
+ * Those classes are intended to be used by the **merchant developer**.
16764
+ */
16765
+
16766
+ var STATIC_CUSTOMISATION_CLASSES = {
16767
+ leftSide: prefix + '-left-side',
16768
+ rightSide: prefix + '-right-side',
16769
+ title: prefix + '-title',
16770
+ info: prefix + '-info',
16771
+ infoMessage: prefix + '-info-message',
16772
+ eligibilityOptions: prefix + '-eligibility-options',
16773
+ activeOption: prefix + '-active-option',
16774
+ closeButton: prefix + '-close-button',
16775
+ scheduleDetails: prefix + '-schedule-details',
16776
+ scheduleTotal: prefix + '-schedule-total',
16777
+ scheduleCredit: prefix + '-schedule-credit'
16778
+ };
16779
+
16741
16780
  var _excluded = ["children", "isOpen", "onClose", "className", "contentClassName", "scrollable"];
16742
16781
 
16743
16782
  var ControlledModal = function ControlledModal(_ref) {
@@ -16770,7 +16809,7 @@
16770
16809
  className: s$1.header
16771
16810
  }, /*#__PURE__*/react.createElement("button", {
16772
16811
  onClick: onClose,
16773
- className: s$1.closeButton,
16812
+ className: classnames(s$1.closeButton, STATIC_CUSTOMISATION_CLASSES.closeButton),
16774
16813
  "data-testid": "modal-close-button"
16775
16814
  }, /*#__PURE__*/react.createElement(CrossIcon, null))), /*#__PURE__*/react.createElement("div", {
16776
16815
  className: classnames(s$1.content, contentClassName, (_cx = {}, _cx[s$1.contentScrollable] = scrollable, _cx))
@@ -18139,6 +18178,20 @@
18139
18178
  return installmentsCount + "x";
18140
18179
  }
18141
18180
  };
18181
+
18182
+ var withNoFee = function withNoFee(payment) {
18183
+ var _payment$payment_plan;
18184
+
18185
+ if ((_payment$payment_plan = payment.payment_plan) != null && _payment$payment_plan.every(function (plan) {
18186
+ return plan.customer_fee === 0 && plan.customer_interest === 0;
18187
+ })) {
18188
+ return /*#__PURE__*/react.createElement(react.Fragment, null, ' ', /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18189
+ id: "payment-plan-strings.no-fee",
18190
+ defaultMessage: '(sans frais)'
18191
+ }));
18192
+ }
18193
+ };
18194
+
18142
18195
  var paymentPlanInfoText = function paymentPlanInfoText(payment) {
18143
18196
  var deferred_days = payment.deferred_days,
18144
18197
  deferred_months = payment.deferred_months,
@@ -18148,20 +18201,10 @@
18148
18201
  _payment$minAmount = payment.minAmount,
18149
18202
  minAmount = _payment$minAmount === void 0 ? 0 : _payment$minAmount,
18150
18203
  _payment$maxAmount = payment.maxAmount,
18151
- maxAmount = _payment$maxAmount === void 0 ? 0 : _payment$maxAmount;
18204
+ maxAmount = _payment$maxAmount === void 0 ? 0 : _payment$maxAmount,
18205
+ payment_plan = payment.payment_plan;
18152
18206
  var deferredDaysCount = deferred_days + deferred_months * 30;
18153
18207
 
18154
- var withNoFee = function withNoFee() {
18155
- if (payment.payment_plan.every(function (plan) {
18156
- return plan.customer_fee === 0 && plan.customer_interest === 0;
18157
- })) {
18158
- return /*#__PURE__*/react.createElement(react.Fragment, null, ' ', /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18159
- id: "payment-plan-strings.no-fee",
18160
- defaultMessage: '(sans frais)'
18161
- }));
18162
- }
18163
- };
18164
-
18165
18208
  if (!eligible) {
18166
18209
  return purchaseAmount > maxAmount ? /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18167
18210
  id: "payment-plan-strings.ineligible-greater-than-max",
@@ -18184,27 +18227,32 @@
18184
18227
  })
18185
18228
  }
18186
18229
  });
18230
+ } else if (!payment_plan) {
18231
+ /* This error should never happen. We added this condition to avoid a typescript warning on
18232
+ payment_plan possibly undefined. As far as we know, it only happens when the plan is not
18233
+ eligible, which is checked above. */
18234
+ throw Error("No payment plan provided for payment in " + installmentsCount + " installments. Please contact us if you see this error.");
18187
18235
  } else if (deferredDaysCount !== 0 && installmentsCount === 1) {
18188
18236
  return /*#__PURE__*/react.createElement(react.Fragment, null, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18189
18237
  id: "payment-plan-strings.deferred",
18190
18238
  defaultMessage: "{totalAmount} \xE0 payer le {dueDate}",
18191
18239
  values: {
18192
18240
  totalAmount: /*#__PURE__*/react.createElement(FormattedNumber, {
18193
- value: priceFromCents(payment.payment_plan[0].total_amount),
18241
+ value: priceFromCents(payment_plan[0].total_amount),
18194
18242
  style: "currency",
18195
18243
  currency: "EUR"
18196
18244
  }),
18197
18245
  dueDate: /*#__PURE__*/react.createElement(FormattedDate, {
18198
- value: secondsToMilliseconds(payment.payment_plan[0].due_date),
18246
+ value: secondsToMilliseconds(payment_plan[0].due_date),
18199
18247
  day: "numeric",
18200
18248
  month: "long",
18201
18249
  year: "numeric"
18202
18250
  })
18203
18251
  }
18204
- }), withNoFee());
18252
+ }), withNoFee(payment));
18205
18253
  } else if (installmentsCount > 0) {
18206
- var areInstallmentsOfSameAmount = payment.payment_plan.every(function (installment, index) {
18207
- return index === 0 || installment.total_amount === payment.payment_plan[0].total_amount;
18254
+ var areInstallmentsOfSameAmount = payment_plan == null ? void 0 : payment_plan.every(function (installment, index) {
18255
+ return index === 0 || installment.total_amount === payment_plan[0].total_amount;
18208
18256
  });
18209
18257
 
18210
18258
  if (areInstallmentsOfSameAmount) {
@@ -18213,13 +18261,13 @@
18213
18261
  defaultMessage: "{installmentsCount} x {totalAmount}",
18214
18262
  values: {
18215
18263
  totalAmount: /*#__PURE__*/react.createElement(FormattedNumber, {
18216
- value: priceFromCents(payment.payment_plan[0].total_amount),
18264
+ value: priceFromCents(payment_plan[0].total_amount),
18217
18265
  style: "currency",
18218
18266
  currency: "EUR"
18219
18267
  }),
18220
18268
  installmentsCount: installmentsCount
18221
18269
  }
18222
- }), withNoFee());
18270
+ }), withNoFee(payment));
18223
18271
  }
18224
18272
 
18225
18273
  return /*#__PURE__*/react.createElement(react.Fragment, null, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
@@ -18227,18 +18275,18 @@
18227
18275
  defaultMessage: "{numberOfRemainingInstallments, plural, one {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}} other {{firstInstallmentAmount} puis {numberOfRemainingInstallments} x {othersInstallmentAmount}}}",
18228
18276
  values: {
18229
18277
  firstInstallmentAmount: /*#__PURE__*/react.createElement(FormattedNumber, {
18230
- value: priceFromCents(payment.payment_plan[0].total_amount),
18278
+ value: priceFromCents(payment_plan[0].total_amount),
18231
18279
  style: "currency",
18232
18280
  currency: "EUR"
18233
18281
  }),
18234
18282
  numberOfRemainingInstallments: installmentsCount - 1,
18235
18283
  othersInstallmentAmount: /*#__PURE__*/react.createElement(FormattedNumber, {
18236
- value: priceFromCents(payment.payment_plan[1].total_amount),
18284
+ value: priceFromCents(payment_plan[1].total_amount),
18237
18285
  style: "currency",
18238
18286
  currency: "EUR"
18239
18287
  })
18240
18288
  }
18241
- }), withNoFee());
18289
+ }), withNoFee(payment));
18242
18290
  }
18243
18291
 
18244
18292
  return /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
@@ -18254,13 +18302,13 @@
18254
18302
  currentPlanIndex = _ref.currentPlanIndex,
18255
18303
  setCurrentPlanIndex = _ref.setCurrentPlanIndex;
18256
18304
  return /*#__PURE__*/react.createElement("div", {
18257
- className: s$2.buttons
18305
+ className: classnames(s$2.buttons, STATIC_CUSTOMISATION_CLASSES.eligibilityOptions)
18258
18306
  }, eligibilityPlans.map(function (eligibilityPlan, index) {
18259
18307
  var _cx;
18260
18308
 
18261
18309
  return /*#__PURE__*/react.createElement("button", {
18262
18310
  key: index,
18263
- className: classnames((_cx = {}, _cx[s$2.active] = index === currentPlanIndex, _cx)),
18311
+ className: classnames((_cx = {}, _cx[classnames(s$2.active, STATIC_CUSTOMISATION_CLASSES.activeOption)] = index === currentPlanIndex, _cx)),
18264
18312
  onClick: function onClick() {
18265
18313
  return setCurrentPlanIndex(index);
18266
18314
  }
@@ -18279,10 +18327,10 @@
18279
18327
  var isCredit = currentPlan && currentPlan.installments_count > 4;
18280
18328
  var intl = useIntl();
18281
18329
  return /*#__PURE__*/react.createElement("div", {
18282
- className: s$3.schedule,
18330
+ className: classnames(s$3.schedule, STATIC_CUSTOMISATION_CLASSES.scheduleDetails),
18283
18331
  "data-testid": "modal-installments-element"
18284
18332
  }, /*#__PURE__*/react.createElement("div", {
18285
- className: classnames(s$3.scheduleLine, s$3.total)
18333
+ className: classnames(s$3.scheduleLine, s$3.total, STATIC_CUSTOMISATION_CLASSES.scheduleTotal)
18286
18334
  }, /*#__PURE__*/react.createElement("span", null, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18287
18335
  id: "eligibility-modal.total",
18288
18336
  defaultMessage: "Total"
@@ -18291,7 +18339,7 @@
18291
18339
  style: "currency",
18292
18340
  currency: "EUR"
18293
18341
  }))), /*#__PURE__*/react.createElement("div", {
18294
- className: classnames(s$3.scheduleLine, s$3.creditCost)
18342
+ className: classnames(s$3.scheduleLine, s$3.creditCost, STATIC_CUSTOMISATION_CLASSES.scheduleCredit)
18295
18343
  }, isCredit ? /*#__PURE__*/react.createElement("span", null, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18296
18344
  id: "eligibility-modal.credit-cost",
18297
18345
  defaultMessage: "Dont co\xFBt du cr\xE9dit"
@@ -18344,13 +18392,15 @@
18344
18392
 
18345
18393
  var Info = function Info() {
18346
18394
  return /*#__PURE__*/react.createElement("div", {
18347
- className: s$4.list,
18395
+ className: classnames(s$4.list, STATIC_CUSTOMISATION_CLASSES.info),
18348
18396
  "data-testid": "modal-info-element"
18349
18397
  }, /*#__PURE__*/react.createElement("div", {
18350
18398
  className: s$4.listItem
18351
18399
  }, /*#__PURE__*/react.createElement("div", {
18352
18400
  className: s$4.bullet
18353
- }, "1"), /*#__PURE__*/react.createElement("div", null, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18401
+ }, "1"), /*#__PURE__*/react.createElement("div", {
18402
+ className: STATIC_CUSTOMISATION_CLASSES.infoMessage
18403
+ }, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18354
18404
  id: "eligibility-modal.bullet-1",
18355
18405
  defaultMessage: "Choisissez <strong>Alma</strong> au moment du paiement.",
18356
18406
  values: {
@@ -18362,7 +18412,9 @@
18362
18412
  className: s$4.listItem
18363
18413
  }, /*#__PURE__*/react.createElement("div", {
18364
18414
  className: s$4.bullet
18365
- }, "2"), /*#__PURE__*/react.createElement("div", null, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18415
+ }, "2"), /*#__PURE__*/react.createElement("div", {
18416
+ className: STATIC_CUSTOMISATION_CLASSES.infoMessage
18417
+ }, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18366
18418
  id: "eligibility-modal.bullet-2",
18367
18419
  defaultMessage: "Renseignez les <strong>informations</strong> demand\xE9es.",
18368
18420
  values: {
@@ -18374,7 +18426,9 @@
18374
18426
  className: s$4.listItem
18375
18427
  }, /*#__PURE__*/react.createElement("div", {
18376
18428
  className: s$4.bullet
18377
- }, "3"), /*#__PURE__*/react.createElement("div", null, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18429
+ }, "3"), /*#__PURE__*/react.createElement("div", {
18430
+ className: STATIC_CUSTOMISATION_CLASSES.infoMessage
18431
+ }, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18378
18432
  id: "eligibility-modal.bullet-3",
18379
18433
  defaultMessage: "La validation de votre paiement <strong>instantan\xE9e</strong> !",
18380
18434
  values: {
@@ -18432,7 +18486,7 @@
18432
18486
 
18433
18487
  var Title = function Title() {
18434
18488
  return /*#__PURE__*/react.createElement("div", {
18435
- className: s$6.title,
18489
+ className: classnames(s$6.title, STATIC_CUSTOMISATION_CLASSES.title),
18436
18490
  "data-testid": "modal-title-element"
18437
18491
  }, /*#__PURE__*/react.createElement(MemoizedFormattedMessage, {
18438
18492
  id: "eligibility-modal.title",
@@ -18453,9 +18507,9 @@
18453
18507
  className: s$7.container,
18454
18508
  "data-testid": "modal-container"
18455
18509
  }, /*#__PURE__*/react.createElement("div", {
18456
- className: classnames([s$7.block, s$7.left])
18510
+ className: classnames([s$7.block, s$7.left, STATIC_CUSTOMISATION_CLASSES.leftSide])
18457
18511
  }, /*#__PURE__*/react.createElement(Title, null), /*#__PURE__*/react.createElement(Info, null), /*#__PURE__*/react.createElement(Logo, null)), /*#__PURE__*/react.createElement("div", {
18458
- className: s$7.block
18512
+ className: classnames(s$7.block, STATIC_CUSTOMISATION_CLASSES.rightSide)
18459
18513
  }, children));
18460
18514
  };
18461
18515
 
@@ -18624,6 +18678,24 @@
18624
18678
  return 0;
18625
18679
  };
18626
18680
 
18681
+ /**
18682
+ * Prefix classes to avoid name collisions.
18683
+ */
18684
+ var prefix$1 = 'alma-payment-plans';
18685
+ /**
18686
+ * Class names for the **payment plans** widget.
18687
+ * Those classes are intended to be used by the **merchant developer**.
18688
+ */
18689
+
18690
+ var STATIC_CUSTOMISATION_CLASSES$1 = {
18691
+ container: prefix$1 + '-container',
18692
+ eligibilityLine: prefix$1 + '-eligibility-line',
18693
+ eligibilityOptions: prefix$1 + '-eligibility-options',
18694
+ notEligibleOption: prefix$1 + '-not-eligible-option',
18695
+ paymentInfo: prefix$1 + '-payment-info',
18696
+ activeOption: prefix$1 + '-active-option'
18697
+ };
18698
+
18627
18699
  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"};
18628
18700
 
18629
18701
  var VERY_LONG_TIME_IN_MS = 1000 * 3600 * 24 * 365;
@@ -18650,7 +18722,7 @@
18650
18722
  eligibilityPlans: eligibilityPlans,
18651
18723
  suggestedPaymentPlan: suggestedPaymentPlan != null ? suggestedPaymentPlan : 0
18652
18724
  });
18653
- var isSuggestedPaymentPlanSpecified = suggestedPaymentPlan !== undefined; // 👈 The merchant decided to focus a tab and remove animated transition.
18725
+ var isSuggestedPaymentPlanSpecified = suggestedPaymentPlan !== undefined; // 👈 The merchant decided to focus a tab
18654
18726
 
18655
18727
  var isTransitionSpecified = transitionDelay !== undefined; // 👈 The merchant has specified a transition time
18656
18728
 
@@ -18735,14 +18807,14 @@
18735
18807
 
18736
18808
  return /*#__PURE__*/react.createElement(react.Fragment, null, /*#__PURE__*/react.createElement("div", {
18737
18809
  onClick: handleOpenModal,
18738
- className: classnames(s$b.widgetButton, (_cx = {}, _cx[s$b.clickable] = eligiblePlans.length > 0, _cx[s$b.unClickable] = eligiblePlans.length === 0, _cx)),
18810
+ className: classnames(s$b.widgetButton, (_cx = {}, _cx[s$b.clickable] = eligiblePlans.length > 0, _cx[s$b.unClickable] = eligiblePlans.length === 0, _cx), STATIC_CUSTOMISATION_CLASSES$1.container),
18739
18811
  "data-testid": "widget-button"
18740
18812
  }, /*#__PURE__*/react.createElement("div", {
18741
- className: s$b.primaryContainer
18813
+ className: classnames(s$b.primaryContainer, STATIC_CUSTOMISATION_CLASSES$1.eligibilityLine)
18742
18814
  }, /*#__PURE__*/react.createElement(LogoIcon, {
18743
18815
  className: s$b.logo
18744
18816
  }), /*#__PURE__*/react.createElement("div", {
18745
- className: s$b.paymentPlans
18817
+ className: classnames(s$b.paymentPlans, STATIC_CUSTOMISATION_CLASSES$1.eligibilityOptions)
18746
18818
  }, eligibilityPlans.map(function (eligibilityPlan, key) {
18747
18819
  var _cx2;
18748
18820
 
@@ -18752,10 +18824,10 @@
18752
18824
  return onHover(key);
18753
18825
  },
18754
18826
  onMouseOut: onLeave,
18755
- className: classnames(s$b.plan, (_cx2 = {}, _cx2[s$b.active] = current === key, _cx2[s$b.notEligible] = !eligibilityPlan.eligible, _cx2))
18827
+ className: classnames(s$b.plan, (_cx2 = {}, _cx2[classnames(s$b.active, STATIC_CUSTOMISATION_CLASSES$1.activeOption)] = current === key, _cx2[classnames(s$b.notEligible, STATIC_CUSTOMISATION_CLASSES$1.notEligibleOption)] = !eligibilityPlan.eligible, _cx2))
18756
18828
  }, paymentPlanShorthandName(eligibilityPlan));
18757
18829
  }))), /*#__PURE__*/react.createElement("div", {
18758
- className: classnames(s$b.info, (_cx3 = {}, _cx3[s$b.notEligible] = eligibilityPlans[current] && !eligibilityPlans[current].eligible, _cx3))
18830
+ className: classnames(s$b.info, (_cx3 = {}, _cx3[classnames(s$b.notEligible, STATIC_CUSTOMISATION_CLASSES$1.notEligibleOption)] = eligibilityPlans[current] && !eligibilityPlans[current].eligible, _cx3), STATIC_CUSTOMISATION_CLASSES$1.paymentInfo)
18759
18831
  }, eligibilityPlans.length !== 0 && paymentPlanInfoText(eligibilityPlans[current]))), isOpen && /*#__PURE__*/react.createElement(EligibilityModal, {
18760
18832
  initialPlanIndex: getIndexWithinEligiblePlans(current),
18761
18833
  onClose: closeModal,