@alma/in-page 2.8.0 → 2.10.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.
package/dist/index.es.js CHANGED
@@ -1,43 +1,32 @@
1
- const M = (e = "LIVE", t) => {
2
- let o = null, n = !1, a = /* @__PURE__ */ new Set(), i = null;
1
+ var Q = Object.defineProperty;
2
+ var K = (e, t, n) => t in e ? Q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var R = (e, t, n) => K(e, typeof t != "symbol" ? t + "" : t, n);
4
+ const ee = (e = "LIVE", t) => {
5
+ let n = null, a = null;
3
6
  return {
4
- setEmbeddedSelector: (p) => {
5
- o = p;
7
+ setEmbeddedSelector: (m) => {
8
+ n = m;
6
9
  },
7
- getEmbeddedSelector: () => o,
8
- setIsCheckoutLoaded: (p) => {
9
- n = p;
10
- },
11
- getIsCheckoutLoaded: () => n,
10
+ getEmbeddedSelector: () => n,
12
11
  getEnvironment: () => e,
13
12
  getCheckoutUrl: () => t,
14
- addMessageToSendLater: (p) => {
15
- a.add(p);
16
- },
17
- getAndResetMessagesToSendLater: () => {
18
- const p = Array.from(a);
19
- return a = /* @__PURE__ */ new Set(), p;
13
+ setTranslations: (m) => {
14
+ a = m;
20
15
  },
21
- setTranslations: (p) => {
22
- i = p;
23
- },
24
- getTranslations: () => i
16
+ getTranslations: () => a
25
17
  };
26
- }, r = "alma-in-page-modal", L = {
27
- embedded: "/in-page/embedded/",
28
- modal: "/in-page/modal/"
29
- }, P = "v2.8.0", C = (e) => {
18
+ }, te = "v2.10.0", V = (e) => {
30
19
  const t = document.getElementById(e.replace("#", ""));
31
20
  if (t)
32
21
  return t;
33
- k();
22
+ G();
34
23
  };
35
- function k() {
24
+ function G() {
36
25
  throw new Error(
37
26
  "Element not found, please add an id selector for the iframe"
38
27
  );
39
28
  }
40
- function b(e, t) {
29
+ function _(e, t) {
41
30
  if (t)
42
31
  return t;
43
32
  switch (e) {
@@ -56,7 +45,7 @@ function b(e, t) {
56
45
  return "https://checkout.getalma.eu";
57
46
  }
58
47
  }
59
- function $(e) {
48
+ function H(e) {
60
49
  switch (e) {
61
50
  case "LOCAL":
62
51
  return "http://localhost:1337";
@@ -73,140 +62,591 @@ function $(e) {
73
62
  return "https://api.getalma.eu";
74
63
  }
75
64
  }
76
- function A(e, t) {
77
- const o = $(t);
78
- return fetch(`${o}/v1/checkout/payments/${e}/return-urls`, {
65
+ function M(e, t) {
66
+ const n = `[Alma InPage] ${e}`;
67
+ return console.error(n), t !== "PROD" && t !== "LIVE" && alert(n), n;
68
+ }
69
+ function ne(e, t) {
70
+ const n = H(t);
71
+ return fetch(`${n}/v1/checkout/payments/${e}/return-urls`, {
79
72
  headers: {
80
- "X-Alma-Agent": `Alma Checkout - InPage/${v()}`
73
+ "X-Alma-Agent": `Alma Checkout - InPage/${I()}`
81
74
  }
82
- }).then((n) => n.json()).then((n) => {
83
- if (t !== "PROD" && t !== "LIVE")
84
- if (n.error_code) {
85
- let a = "";
86
- if (n.error_code === "not_found") {
87
- const i = $(t);
88
- a = `
89
-
90
- Please check your payment has been created on the ${t} environment (${i}).`;
91
- }
92
- alert(`Error: ${n.error_code}
93
-
94
- ${n.message}${a}`);
95
- } else n.origin && n.origin !== "online_in_page" && alert(
96
- `Your payment does not have the proper origin for an in-page payment, you should use "online_in_page".
75
+ }).then((a) => a.json()).then((a) => {
76
+ if (a.error_code) {
77
+ let o = "";
78
+ a.error_code === "not_found" && (o = `
97
79
 
98
- Please, check the documentation:
99
- https://docs.almapay.com/docs/integration-in-page`
80
+ Please check that payment "${e}" has been created on the ${t} environment (${n}).`), M(
81
+ `Error: ${a.error_code}
82
+
83
+ ${a.message}${o}`,
84
+ t
100
85
  );
101
- return { success: n.return_url, failure: n.failure_return_url };
102
- });
103
- }
104
- function O(e, t, o, n) {
105
- return b(t, n) + "/" + e + o;
86
+ } else a.origin && a.origin !== "online_in_page" && M(
87
+ `Your payment does not have the proper origin for an in-page payment, you should use "online_in_page".
88
+
89
+ Please, check the documentation:
90
+ https://docs.almapay.com/docs/integration-in-page`,
91
+ t
92
+ );
93
+ return { success: a.return_url, failure: a.failure_return_url };
94
+ }).catch((a) => (console.error("[Alma InPage] Failed to fetch payment return URLs:", a), { success: void 0, failure: void 0 }));
106
95
  }
107
- function B(e, t) {
108
- return b(e, t) + L.embedded;
96
+ function ae(e, t, n, a) {
97
+ return _(t, a) + "/" + e + n;
109
98
  }
110
- function v() {
111
- const e = P.match(/\d+\.\d+\.\d+/);
99
+ function I() {
100
+ const e = te.match(/\d+\.\d+\.\d+/);
112
101
  return e ? e[0] : "2.0.0";
113
102
  }
114
- function T(e, t, o, n) {
115
- const a = [], i = (s) => {
116
- if (s.origin !== b(e, n) || s.data.from !== "checkout")
103
+ function oe(e, t) {
104
+ const n = [], a = (s) => {
105
+ if (s.origin !== _(e, t) || s.data.from !== "checkout")
117
106
  return !1;
118
- const c = s.data.payload, f = s.data.domElement;
119
- if (s.data.type === "in_page_status") {
120
- if ((c === "ready_for_payment" || c === "can_open_modal") && t !== f)
121
- return;
122
- a.filter((l) => l && l.eventName === c).forEach((l) => {
123
- l && l.callback();
124
- });
125
- } else if (s.data.type === "embedded_height") {
126
- if (t !== f)
127
- return;
128
- const l = document.getElementById(
129
- `alma-embedded-iframe-${t}`
130
- );
131
- l && (l.style.height = `${Math.ceil(c)}px`);
132
- } else s.data.type === "translations" ? o(c) : console.warn("Unknown message type:", s.data.type);
107
+ s.data.type === "in_page_status" ? n.filter(
108
+ (l) => l && l.eventName === s.data.payload
109
+ ).forEach((l) => {
110
+ l && l.callback();
111
+ }) : (
112
+ // Sent by the iframe fallback, see Embedded/fallback.ts
113
+ s.data.type !== "embedded_height" && s.data.type !== "translations" && console.warn("Unknown message type:", s.data.type)
114
+ );
133
115
  };
134
- window.addEventListener("message", i, !1);
135
- function d() {
136
- window.removeEventListener("message", i, !1);
116
+ window.addEventListener("message", a, !1);
117
+ function o() {
118
+ window.removeEventListener("message", a, !1);
137
119
  }
138
- function m(s, c, f) {
139
- const l = a.findIndex(
140
- (g) => g && g.eventName === s && g.callerName === c
120
+ function i(s, l, d) {
121
+ const u = n.findIndex(
122
+ (m) => m && m.eventName === s && m.callerName === l
141
123
  );
142
- l && (a[l] = null), a.push({ eventName: s, callerName: c, callback: f });
124
+ u !== -1 && (n[u] = null), n.push({ eventName: s, callerName: l, callback: d });
143
125
  }
144
126
  return {
145
- onInPageStatusChanged: m,
146
- unsubscribe: d
127
+ onInPageStatusChanged: i,
128
+ unsubscribe: o
147
129
  };
148
130
  }
149
- function I(e, t) {
150
- var d;
151
- if (e.getIsCheckoutLoaded() === !1)
152
- return e.addMessageToSendLater(t), !1;
153
- const o = e.getEmbeddedSelector();
154
- if (!o)
155
- return console.error("Can not send message yet, mount() has not been called."), !1;
156
- const n = C(o), a = n == null ? void 0 : n.firstChild, i = b(
157
- e.getEnvironment(),
158
- e.getCheckoutUrl()
131
+ class W extends Error {
132
+ constructor() {
133
+ super(...arguments);
134
+ R(this, "name", "BlockedRequestError");
135
+ }
136
+ }
137
+ async function re(e, t) {
138
+ const n = await fetch(
139
+ `${H(t)}/v2/payments/eligibility`,
140
+ {
141
+ method: "POST",
142
+ headers: {
143
+ Authorization: `Alma-Merchant-Auth ${e.merchantId}`,
144
+ "Content-Type": "application/json",
145
+ "X-Alma-Agent": `Alma Checkout - InPage/${I()}`
146
+ },
147
+ body: JSON.stringify({
148
+ purchase_amount: e.amountInCents,
149
+ queries: [
150
+ {
151
+ installments_count: e.installmentsCount,
152
+ deferred_days: e.deferredDays,
153
+ deferred_months: e.deferredMonths
154
+ }
155
+ ],
156
+ capture_method: e.captureMethod,
157
+ locale: e.locale
158
+ })
159
+ }
160
+ ).catch((o) => {
161
+ throw new W(String(o));
162
+ });
163
+ if (!n.ok)
164
+ throw new Error(`Eligibility request failed with status ${n.status}`);
165
+ return (await n.json()).find(
166
+ (o) => o.eligible && o.deferred_days === e.deferredDays && o.deferred_months === e.deferredMonths
167
+ ) ?? null;
168
+ }
169
+ const r = "alma-in-page-modal", Y = {
170
+ embedded: "/in-page/embedded/",
171
+ modal: "/in-page/modal/"
172
+ };
173
+ function se(e, t) {
174
+ if (!e.isConnected) return;
175
+ const {
176
+ environment: n,
177
+ merchantId: a,
178
+ selector: o,
179
+ amountInCents: i,
180
+ installmentsCount: s,
181
+ deferredDays: l,
182
+ deferredMonths: d,
183
+ locale: u,
184
+ captureMethod: m,
185
+ style: v,
186
+ onIntegratedPayButtonClicked: g,
187
+ checkoutUrl: h
188
+ } = t, c = new URL(
189
+ _(n ?? "PROD", h) + Y.embedded
159
190
  );
160
- return (d = a.contentWindow) == null || d.postMessage(t, i), !0;
191
+ c.searchParams.append("merchantId", a), c.searchParams.append("amountInCents", i.toString()), c.searchParams.append("installmentsCount", s.toString()), l && c.searchParams.append("deferredDays", l.toString()), d && c.searchParams.append("deferredMonths", d.toString()), c.searchParams.append("locale", u ?? "FR"), c.searchParams.append("captureMethod", m ?? "automatic"), c.searchParams.append("domElement", o), c.searchParams.append("style", JSON.stringify(v || null)), c.searchParams.append("inPageVersion", I()), g && c.searchParams.append("showPayButton", "true"), c.searchParams.append("fallback", "true");
192
+ const f = document.createElement("iframe");
193
+ f.src = c.toString(), f.id = `alma-embedded-iframe-${o}`, f.style.width = "100%", f.style.height = "150px", f.style.transition = "height 0.5s", f.style.border = "none", f.style.display = e.style.display === "none" ? "none" : "block", f.setAttribute("allow", "payment"), e.replaceWith(f), window.addEventListener("message", function y(b) {
194
+ if (!f.isConnected) {
195
+ window.removeEventListener("message", y);
196
+ return;
197
+ }
198
+ b.origin !== c.origin || b.source !== f.contentWindow || (b.data.type === "embedded_height" ? f.style.height = `${Math.ceil(b.data.payload)}px` : b.data.type === "in_page_status" && b.data.payload === "ready_for_payment" && (g == null || g()));
199
+ });
200
+ }
201
+ const X = "Alma Inter", ie = "https://cdn.almapay.com/fonts/Inter/InterVariable-latin.woff2", le = 300;
202
+ let A = null;
203
+ function de() {
204
+ if (A || typeof FontFace > "u" || !document.fonts) return;
205
+ const e = new FontFace(X, `url(${ie}) format("woff2")`, {
206
+ weight: "400 700",
207
+ display: "swap"
208
+ });
209
+ document.fonts.add(e), A = e.load().catch((t) => {
210
+ console.error("[Alma InPage] Failed to load the font:", t);
211
+ });
212
+ }
213
+ function ce() {
214
+ return Promise.race([
215
+ A,
216
+ new Promise((e) => setTimeout(e, le))
217
+ ]);
218
+ }
219
+ const Z = {
220
+ fr: {
221
+ modal: {
222
+ closeModalMessage: "Voulez-vous vraiment quitter la page de paiement ?",
223
+ closeModalButtonHover: "Abandonner le paiement avec Alma"
224
+ },
225
+ embedded: {
226
+ total: "Total",
227
+ fees: (e) => `Dont ${e} de frais à payer aujourd'hui.`,
228
+ offeredFees: "Les frais de paiement sont offerts",
229
+ payButton: (e) => `Payer ${e}`,
230
+ noPlanError: "Une erreur est survenue, aucun échéancier n'est disponible, merci de réessayer.",
231
+ deferredCaptureExplanation: "Vos prélèvements commenceront lorsque nous aurons validé votre commande.",
232
+ deferredFirstInstallment: "Au traitement de la commande",
233
+ deferredMonth: (e) => `${e} mois après`
234
+ }
235
+ },
236
+ en: {
237
+ modal: {
238
+ closeModalMessage: "Do you really want to leave the checkout page?",
239
+ closeModalButtonHover: "Cancel the payment with Alma"
240
+ },
241
+ embedded: {
242
+ total: "Total",
243
+ fees: (e) => `Including ${e} of fees to be paid today.`,
244
+ offeredFees: "Payment fees are free",
245
+ payButton: (e) => `Pay ${e}`,
246
+ noPlanError: "An error has occurred, no payment schedule is available, please try again.",
247
+ deferredCaptureExplanation: "Your direct debits will start as soon as we have validated your order.",
248
+ deferredFirstInstallment: "When processing the order",
249
+ deferredMonth: (e) => `${e} month after`
250
+ }
251
+ },
252
+ de: {
253
+ modal: {
254
+ closeModalMessage: "Möchten Sie die Zahlungsseite wirklich verlassen?",
255
+ closeModalButtonHover: "Zahlung mit Alma abbrechen"
256
+ },
257
+ embedded: {
258
+ total: "Gesamtbetrag",
259
+ fees: (e) => `Davon ${e} Gebühren, die heute bezahlt werden müssen.`,
260
+ offeredFees: "Die Zahlungsgebühren sind erlassen",
261
+ payButton: (e) => `${e} zahlen`,
262
+ noPlanError: "Es ist ein Fehler aufgetreten, es ist kein Zahlungsplan verfügbar. Bitte versuchen Sie es erneut.",
263
+ deferredCaptureExplanation: "Ihre Abbuchungen beginnen, sobald wir Ihre Bestellung freigegeben haben.",
264
+ deferredFirstInstallment: "Bei der Bearbeitung der Bestellung",
265
+ deferredMonth: (e) => e === 1 ? `${e} Monat später` : `${e} Monate später`
266
+ }
267
+ },
268
+ it: {
269
+ modal: {
270
+ closeModalMessage: "Vuoi davvero lasciare la pagina di pagamento?",
271
+ closeModalButtonHover: "Annullare il pagamento con Alma"
272
+ },
273
+ embedded: {
274
+ total: "Totale",
275
+ fees: (e) => `Inclusa la commissione di ${e} per il pagamento rateale.`,
276
+ offeredFees: "Nessuna commissione di pagamento",
277
+ payButton: (e) => `Paga ${e}`,
278
+ noPlanError: "Si è verificato un errore, non è disponibile nessun piano di pagamento, riprovare.",
279
+ deferredCaptureExplanation: "Gli addebiti diretti inizieranno non appena avremo convalidato l'ordine.",
280
+ deferredFirstInstallment: "Elaborazione dell'ordine",
281
+ deferredMonth: (e) => e === 1 ? `${e} mese dopo` : `${e} mesi dopo`
282
+ }
283
+ },
284
+ es: {
285
+ modal: {
286
+ closeModalMessage: "¿De verdad quieres salir de la página de pago?",
287
+ closeModalButtonHover: "Cancelar el pago con Alma"
288
+ },
289
+ embedded: {
290
+ total: "Total",
291
+ fees: (e) => `De los cuales ${e} son gastos administrativos.`,
292
+ offeredFees: "Las comisiones de pago son gratuitas",
293
+ payButton: (e) => `Pagar ${e}`,
294
+ noPlanError: "Se ha producido un error, inténtelo de nuevo.",
295
+ deferredCaptureExplanation: "La domiciliación bancaria se iniciará en cuanto hayamos validado tu pedido.",
296
+ deferredFirstInstallment: "Al procesarse el pedido",
297
+ deferredMonth: (e) => e === 1 ? `${e} mes después` : `${e} meses después`
298
+ }
299
+ },
300
+ nl: {
301
+ modal: {
302
+ closeModalMessage: "Weet je zeker dat je de betaalpagina wilt verlaten?",
303
+ closeModalButtonHover: "Annuleer betaling met Alma"
304
+ },
305
+ embedded: {
306
+ total: "Totaal",
307
+ fees: (e) => `Waarvan ${e} kosten die vandaag moeten worden betaald.`,
308
+ offeredFees: "Geen extra kosten",
309
+ payButton: (e) => `Betaal ${e}`,
310
+ noPlanError: "Er is een fout opgetreden, er is geen betaalschema beschikbaar, probeer het opnieuw.",
311
+ deferredCaptureExplanation: "Uw automatische incasso's beginnen zodra we uw bestelling hebben gevalideerd.",
312
+ deferredFirstInstallment: "Op het moment dat de bestelling wordt verwerkt",
313
+ deferredMonth: (e) => `${e} maand na`
314
+ }
315
+ },
316
+ pt: {
317
+ modal: {
318
+ closeModalMessage: "Quer mesmo sair da página de pagamento?",
319
+ closeModalButtonHover: "Cancelar o pagamento com a Alma"
320
+ },
321
+ embedded: {
322
+ total: "Total",
323
+ fees: (e) => `Do qual ${e} deve ser pago hoje.`,
324
+ offeredFees: "As despesas de pagamento são gratuitas",
325
+ payButton: (e) => `Pagar ${e}`,
326
+ noPlanError: "Ocorreu um erro, não existe nenhum plano de pagamento disponível, tente novamente.",
327
+ deferredCaptureExplanation: "Os seus débitos diretos começarão assim que tivermos validado a sua encomenda.",
328
+ deferredFirstInstallment: "Processamento de encomendas",
329
+ deferredMonth: (e) => e === 1 ? `${e} mês seguinte` : `${e} meses seguintes`
330
+ }
331
+ }
332
+ };
333
+ function z(e) {
334
+ return Object.keys(Z).includes(e);
335
+ }
336
+ function B(e) {
337
+ const t = String(e ?? "FR").toLowerCase();
338
+ if (z(t)) return t;
339
+ const n = navigator.language.split("-")[0];
340
+ return z(n) ? n : "en";
341
+ }
342
+ function k(e) {
343
+ return Z[B(e)];
344
+ }
345
+ const U = `
346
+ /* The merchant's rules matching the host win over :host, unless :host is !important */
347
+ :host {
348
+ padding: 0 !important;
349
+ border: none !important;
350
+ background-color: #fefefe !important;
351
+ }
352
+
353
+ .container {
354
+ /* Resets what is inherited from the merchant's page, except what hides the payment plan */
355
+ all: initial;
356
+ visibility: inherit;
357
+ pointer-events: inherit;
358
+ direction: ltr;
359
+ color: #130a07;
360
+ -webkit-font-smoothing: antialiased;
361
+ -moz-osx-font-smoothing: grayscale;
362
+ display: flex;
363
+ flex-direction: column;
364
+ gap: 10px;
365
+ margin: 8px 16px;
366
+ font-family: "${X}", sans-serif;
367
+ font-size: 14px;
368
+ line-height: 19px;
369
+ letter-spacing: -0.6px;
370
+ }
371
+
372
+ .fadeIn {
373
+ animation: fadeIn 0.4s ease-out backwards;
374
+ }
375
+
376
+ /* A fast response never shows the skeleton, which would only flash */
377
+ .delayed {
378
+ animation-delay: 0.2s;
379
+ }
380
+
381
+ @keyframes fadeIn {
382
+ from {
383
+ opacity: 0;
384
+ }
385
+ to {
386
+ opacity: 1;
387
+ }
388
+ }
389
+
390
+ .bold {
391
+ font-weight: 700;
392
+ }
393
+
394
+ .installments {
395
+ display: flex;
396
+ flex-direction: column;
397
+ gap: 2px;
398
+ }
399
+
400
+ .installment,
401
+ .total {
402
+ display: flex;
403
+ justify-content: space-between;
404
+ gap: 8px;
405
+ }
406
+
407
+ .total {
408
+ align-items: center;
409
+ }
410
+
411
+ .label {
412
+ font-size: 16px;
413
+ line-height: 135%;
414
+ letter-spacing: normal;
161
415
  }
162
- function U(e) {
163
- e.getAndResetMessagesToSendLater().forEach((o) => {
164
- I(e, o);
416
+
417
+ .date {
418
+ text-transform: capitalize;
419
+ }
420
+
421
+ .totalAmount {
422
+ text-align: right;
423
+ }
424
+
425
+ .error {
426
+ margin-block: 16px;
427
+ }
428
+
429
+ .fees {
430
+ margin-top: 4px;
431
+ font-size: 12px;
432
+ line-height: 16px;
433
+ opacity: 0.5;
434
+ }
435
+
436
+ .skeleton {
437
+ display: inline-block;
438
+ height: 12px;
439
+ vertical-align: middle;
440
+ border-radius: 6px;
441
+ background-color: currentColor;
442
+ opacity: 0.1;
443
+ }
444
+
445
+ .button {
446
+ font: inherit;
447
+ font-size: 16px;
448
+ line-height: 22px;
449
+ font-weight: 700;
450
+ color: #fff;
451
+ background-color: #130a07;
452
+ border: 3px solid transparent;
453
+ border-radius: 100px;
454
+ box-sizing: border-box;
455
+ height: 50px;
456
+ padding: 0 24px;
457
+ cursor: pointer;
458
+ transition: all 0.2s ease;
459
+ }
460
+
461
+ .fitContent {
462
+ width: -moz-fit-content;
463
+ width: fit-content;
464
+ }
465
+
466
+ .button:hover:not(:disabled) {
467
+ background-color: #3e1509;
468
+ }
469
+
470
+ .button:focus-visible {
471
+ outline: 3px solid #53d9e8;
472
+ outline-offset: -3px;
473
+ }
474
+
475
+ .skeletonButton {
476
+ opacity: 0.1;
477
+ cursor: default;
478
+ }
479
+
480
+ .skeletonButton.fitContent {
481
+ width: 160px;
482
+ }
483
+
484
+ @media (prefers-reduced-motion: reduce) {
485
+ .fadeIn {
486
+ animation: none;
487
+ }
488
+ }
489
+ `;
490
+ function p(e, t, n) {
491
+ const a = document.createElement(e);
492
+ return t && (a.className = t), n !== void 0 && (a.textContent = n), a;
493
+ }
494
+ function C(e, t) {
495
+ const n = p("span", "skeleton");
496
+ n.style.width = `${e}px`;
497
+ const a = p("span", t);
498
+ return a.append(n), a;
499
+ }
500
+ function L(e, t) {
501
+ t && typeof t == "object" && Object.assign(e.style, t);
502
+ }
503
+ function F(e) {
504
+ const t = p("div", "container fadeIn");
505
+ return L(t, e.containerStyle), t;
506
+ }
507
+ let $ = null;
508
+ function O(e, t) {
509
+ "adoptedStyleSheets" in e && "replaceSync" in CSSStyleSheet.prototype ? ($ || ($ = new CSSStyleSheet(), $.replaceSync(U)), e.adoptedStyleSheets = [$], e.replaceChildren(t)) : e.replaceChildren(p("style", void 0, U), t);
510
+ }
511
+ function D(e, t) {
512
+ var o;
513
+ const n = e.host.clientWidth;
514
+ (o = e.querySelector(".button")) == null || o.classList.toggle("fitContent", n >= 769);
515
+ const a = new Intl.DateTimeFormat(B(t), {
516
+ day: "numeric",
517
+ month: n > 400 ? "long" : "short"
518
+ }).format;
519
+ e.querySelectorAll(".date").forEach((i) => {
520
+ i.textContent = a(Number(i.dataset.dueDate));
165
521
  });
166
522
  }
167
- function R(e) {
523
+ function q(e) {
524
+ return e > 4;
525
+ }
526
+ function ue(e, t) {
527
+ const n = F(t);
528
+ n.classList.add("delayed"), O(e, n);
529
+ const a = k(t.locale).embedded;
530
+ if (t.isDeferredCapture && n.append(p("div", "bold", a.deferredCaptureExplanation)), !q(t.installmentsCount)) {
531
+ const o = p("div", "installments");
532
+ for (let d = 0; d < t.installmentsCount; d++) {
533
+ const u = p("div", "installment");
534
+ u.append(C(90, "label"), C(60)), o.append(u);
535
+ }
536
+ const i = p("div", "total"), s = p("div", "totalAmount"), l = p("div", "bold");
537
+ l.append(C(60)), s.append(l, p("div", "fees", " ")), i.append(C(40), s), o.append(i), n.append(o);
538
+ }
539
+ if (t.onPayButtonClicked) {
540
+ const o = p("button", "button skeletonButton", " ");
541
+ o.disabled = !0, L(o, t.buttonStyle), n.append(o);
542
+ }
543
+ D(e, t.locale);
544
+ }
545
+ function me(e, t, n) {
546
+ const a = F(n), o = B(n.locale), i = k(n.locale).embedded, s = (u) => new Intl.NumberFormat(o, {
547
+ style: "currency",
548
+ currency: "EUR"
549
+ }).format(u / 100);
550
+ n.isDeferredCapture && a.append(p("div", "bold", i.deferredCaptureExplanation));
551
+ const l = t.customer_fee + t.customer_interest, d = t.purchase_amount + l;
552
+ if (!q(n.installmentsCount)) {
553
+ const u = p("div", "installments");
554
+ u.dataset.testid = "installments", t.payment_plan.forEach((h, c) => {
555
+ const f = p("div", "installment");
556
+ f.dataset.testid = `installment-${c}`;
557
+ const y = p("span", "label");
558
+ n.isDeferredCapture ? y.textContent = c === 0 ? i.deferredFirstInstallment : i.deferredMonth(c) : (y.classList.add("date"), y.dataset.dueDate = String(h.due_date * 1e3)), f.append(
559
+ y,
560
+ p(
561
+ "span",
562
+ void 0,
563
+ s(
564
+ h.purchase_amount + h.customer_fee + h.customer_interest
565
+ )
566
+ )
567
+ ), u.append(f);
568
+ });
569
+ const m = p("div", "total"), v = p("div", "fees");
570
+ if (l === 0) {
571
+ const h = p("span", void 0, "🎁");
572
+ h.setAttribute("aria-hidden", "true"), v.append(`${i.offeredFees} `, h);
573
+ } else
574
+ v.textContent = i.fees(s(l));
575
+ const g = p("div", "totalAmount");
576
+ g.append(p("div", "bold", s(d)), v), m.append(p("span", "bold", i.total), g), u.append(m), a.append(u);
577
+ }
578
+ if (n.onPayButtonClicked) {
579
+ const u = p(
580
+ "button",
581
+ "button",
582
+ i.payButton(s(d))
583
+ );
584
+ u.type = "button", L(u, n.buttonStyle), u.onclick = () => {
585
+ var m;
586
+ return (m = n.onPayButtonClicked) == null ? void 0 : m.call(n);
587
+ }, a.append(u);
588
+ }
589
+ O(e, a), D(e, n.locale);
590
+ }
591
+ function j(e, t) {
592
+ const n = F(t);
593
+ n.classList.add("error"), n.textContent = k(t.locale).embedded.noPlanError, O(e, n);
594
+ }
595
+ function pe(e) {
596
+ var T;
168
597
  const {
169
598
  environment: t,
170
- merchantId: o,
171
- selector: n,
172
- amountInCents: a,
599
+ merchantId: n,
600
+ selector: a,
601
+ amountInCents: o,
173
602
  installmentsCount: i,
174
- deferredDays: d,
175
- deferredMonths: m,
176
- locale: s,
177
- captureMethod: c,
178
- style: f,
179
- onIntegratedPayButtonClicked: l,
180
- checkoutUrl: g
603
+ deferredDays: s,
604
+ deferredMonths: l,
605
+ locale: d,
606
+ captureMethod: u,
607
+ style: m,
608
+ onIntegratedPayButtonClicked: v
181
609
  } = e;
182
- if (!n)
183
- return k(), !1;
184
- const x = B(
185
- t ?? "PROD",
186
- g
187
- ), u = new URL(x);
188
- return u.searchParams.append("merchantId", o), u.searchParams.append("amountInCents", a.toString()), u.searchParams.append(
189
- "installmentsCount",
190
- i.toString()
191
- ), d && u.searchParams.append("deferredDays", d.toString()), m && u.searchParams.append("deferredMonths", m.toString()), u.searchParams.append("locale", s ?? "FR"), u.searchParams.append("captureMethod", c ?? "automatic"), u.searchParams.append("domElement", n), u.searchParams.append("style", JSON.stringify(f || null)), u.searchParams.append("inPageVersion", v()), l && u.searchParams.append("showPayButton", "true"), D({
192
- selector: n,
193
- url: u.toString(),
194
- shouldBeHidden: i > 4 && !l
610
+ if (!a)
611
+ return G(), !1;
612
+ const g = (w) => parseInt(String(w), 10), h = g(i), c = document.createElement("div");
613
+ c.id = `alma-embedded-${a.replace("#", "")}`, c.style.width = "100%", c.style.display = h > 4 && !v ? "none" : "flow-root";
614
+ const f = c.attachShadow({ mode: "open" });
615
+ (T = V(a)) == null || T.replaceChildren(c);
616
+ const y = {
617
+ locale: d,
618
+ installmentsCount: h,
619
+ isDeferredCapture: u === "manual",
620
+ onPayButtonClicked: v,
621
+ containerStyle: m == null ? void 0 : m.embedded,
622
+ buttonStyle: m == null ? void 0 : m.embeddedButton
623
+ };
624
+ de(), ue(f, y);
625
+ const b = new ResizeObserver(() => {
626
+ c.isConnected ? D(f, d) : b.disconnect();
627
+ });
628
+ return b.observe(c), re(
629
+ {
630
+ merchantId: n,
631
+ amountInCents: g(o),
632
+ installmentsCount: h,
633
+ deferredDays: g(s) || 0,
634
+ deferredMonths: g(l) || 0,
635
+ captureMethod: u ?? "automatic",
636
+ locale: d ?? "FR"
637
+ },
638
+ t ?? "PROD"
639
+ ).then(async (w) => {
640
+ await ce(), w ? me(f, w, y) : j(f, y);
641
+ }).catch((w) => {
642
+ console.error("[Alma InPage] Failed to display the payment plan:", w), w instanceof W ? se(c, e) : j(f, y);
195
643
  }), !0;
196
644
  }
197
- function D({
198
- selector: e,
199
- url: t,
200
- shouldBeHidden: o
201
- }) {
202
- const n = C(e), a = document.createElement("iframe");
203
- a.src = t, a.id = `alma-embedded-iframe-${e}`, a.style.width = "100%", a.style.height = "150px", a.style.transition = "height 0.5s", a.style.border = "none", a.style.display = o ? "none" : "block", a.setAttribute("allow", "payment"), n == null || n.replaceChildren(a);
204
- }
205
- const E = {
645
+ const S = {
206
646
  orange: "#FA5022",
207
647
  backdrop: "#6C6C6C",
208
648
  white: "#FEFEFE"
209
- }, F = `
649
+ }, fe = `
210
650
  #${r}-element {
211
651
  position: fixed;
212
652
  z-index: 10337;
@@ -221,7 +661,7 @@ const E = {
221
661
  }
222
662
 
223
663
  #${r}-background {
224
- background: ${E.backdrop};
664
+ background: ${S.backdrop};
225
665
  position: absolute;
226
666
  width: 100vw;
227
667
  height: 100vh;
@@ -229,7 +669,7 @@ const E = {
229
669
  }
230
670
 
231
671
  #${r}-body {
232
- background: ${E.white};
672
+ background: ${S.white};
233
673
  width: 100%;
234
674
  max-width: 700px;
235
675
  height: calc(100% - 32px);
@@ -252,7 +692,7 @@ const E = {
252
692
 
253
693
  #${r}-close:hover, #${r}-close:focus-visible {
254
694
  border-radius: 50%;
255
- outline: 1px solid ${E.orange};
695
+ outline: 1px solid ${S.orange};
256
696
  outline-offset: -16px;
257
697
  }
258
698
 
@@ -348,120 +788,124 @@ const E = {
348
788
  visibility: hidden;
349
789
  }
350
790
  }
351
- `, V = "data:image/svg+xml,%3csvg%20width='72'%20height='72'%20viewBox='0%200%2072%2072'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20filter='url(%23filter0_d_12596_6540)'%3e%3ccircle%20cx='36'%20cy='36'%20r='20'%20fill='white'/%3e%3c/g%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M29.4697%2029.4697C29.7626%2029.1768%2030.2374%2029.1768%2030.5303%2029.4697L36%2034.9393L41.4697%2029.4697C41.7626%2029.1768%2042.2374%2029.1768%2042.5303%2029.4697C42.8232%2029.7626%2042.8232%2030.2374%2042.5303%2030.5303L37.0607%2036L42.5303%2041.4697C42.8232%2041.7626%2042.8232%2042.2374%2042.5303%2042.5303C42.2374%2042.8232%2041.7626%2042.8232%2041.4697%2042.5303L36%2037.0607L30.5303%2042.5303C30.2374%2042.8232%2029.7626%2042.8232%2029.4697%2042.5303C29.1768%2042.2374%2029.1768%2041.7626%2029.4697%2041.4697L34.9393%2036L29.4697%2030.5303C29.1768%2030.2374%2029.1768%2029.7626%2029.4697%2029.4697Z'%20fill='%231A1A1A'/%3e%3cdefs%3e%3cfilter%20id='filter0_d_12596_6540'%20x='0'%20y='0'%20width='72'%20height='72'%20filterUnits='userSpaceOnUse'%20color-interpolation-filters='sRGB'%3e%3cfeFlood%20flood-opacity='0'%20result='BackgroundImageFix'/%3e%3cfeColorMatrix%20in='SourceAlpha'%20type='matrix'%20values='0%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%20127%200'%20result='hardAlpha'/%3e%3cfeMorphology%20radius='4'%20operator='dilate'%20in='SourceAlpha'%20result='effect1_dropShadow_12596_6540'/%3e%3cfeOffset/%3e%3cfeGaussianBlur%20stdDeviation='6'/%3e%3cfeComposite%20in2='hardAlpha'%20operator='out'/%3e%3cfeColorMatrix%20type='matrix'%20values='0%200%200%200%200.160784%200%200%200%200%200.0588235%200%200%200%200%200.0313726%200%200%200%200.04%200'/%3e%3cfeBlend%20mode='normal'%20in2='BackgroundImageFix'%20result='effect1_dropShadow_12596_6540'/%3e%3cfeBlend%20mode='normal'%20in='SourceGraphic'%20in2='effect1_dropShadow_12596_6540'%20result='shape'/%3e%3c/filter%3e%3c/defs%3e%3c/svg%3e";
352
- let w = 0, h = null;
353
- function j(e, t, o, n, a) {
354
- h = o, document.getElementById(`${r}-wrapper`) && y(!1), w = window.scrollY, document.body.classList.add("alma-fixed-body"), document.body.scroll(0, w);
355
- const i = G(), d = N(), m = Y(), s = z(), c = S(n), f = X(e, t, a);
356
- document.body.appendChild(i), i.appendChild(d), d.appendChild(m), d.appendChild(s), s.appendChild(c), s.appendChild(f), i.classList.add(`${r}-fadeIn`), s.classList.add(`${r}-slideIn`), f.focus();
357
- }
358
- function y(e = !0, t) {
359
- const o = document.getElementById(`${r}-wrapper`);
360
- if (o && (!e || confirm(
361
- (h == null ? void 0 : h.closeModalMessage) ?? "Are you sure you want to leave the payment page?"
791
+ `, he = "data:image/svg+xml,%3csvg%20width='72'%20height='72'%20viewBox='0%200%2072%2072'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20filter='url(%23filter0_d_12596_6540)'%3e%3ccircle%20cx='36'%20cy='36'%20r='20'%20fill='white'/%3e%3c/g%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M29.4697%2029.4697C29.7626%2029.1768%2030.2374%2029.1768%2030.5303%2029.4697L36%2034.9393L41.4697%2029.4697C41.7626%2029.1768%2042.2374%2029.1768%2042.5303%2029.4697C42.8232%2029.7626%2042.8232%2030.2374%2042.5303%2030.5303L37.0607%2036L42.5303%2041.4697C42.8232%2041.7626%2042.8232%2042.2374%2042.5303%2042.5303C42.2374%2042.8232%2041.7626%2042.8232%2041.4697%2042.5303L36%2037.0607L30.5303%2042.5303C30.2374%2042.8232%2029.7626%2042.8232%2029.4697%2042.5303C29.1768%2042.2374%2029.1768%2041.7626%2029.4697%2041.4697L34.9393%2036L29.4697%2030.5303C29.1768%2030.2374%2029.1768%2029.7626%2029.4697%2029.4697Z'%20fill='%231A1A1A'/%3e%3cdefs%3e%3cfilter%20id='filter0_d_12596_6540'%20x='0'%20y='0'%20width='72'%20height='72'%20filterUnits='userSpaceOnUse'%20color-interpolation-filters='sRGB'%3e%3cfeFlood%20flood-opacity='0'%20result='BackgroundImageFix'/%3e%3cfeColorMatrix%20in='SourceAlpha'%20type='matrix'%20values='0%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%20127%200'%20result='hardAlpha'/%3e%3cfeMorphology%20radius='4'%20operator='dilate'%20in='SourceAlpha'%20result='effect1_dropShadow_12596_6540'/%3e%3cfeOffset/%3e%3cfeGaussianBlur%20stdDeviation='6'/%3e%3cfeComposite%20in2='hardAlpha'%20operator='out'/%3e%3cfeColorMatrix%20type='matrix'%20values='0%200%200%200%200.160784%200%200%200%200%200.0588235%200%200%200%200%200.0313726%200%200%200%200.04%200'/%3e%3cfeBlend%20mode='normal'%20in2='BackgroundImageFix'%20result='effect1_dropShadow_12596_6540'/%3e%3cfeBlend%20mode='normal'%20in='SourceGraphic'%20in2='effect1_dropShadow_12596_6540'%20result='shape'/%3e%3c/filter%3e%3c/defs%3e%3c/svg%3e";
792
+ let P = 0, x = null;
793
+ function ge(e, t, n, a, o) {
794
+ x = n, document.getElementById(`${r}-wrapper`) && E(!1), P = window.scrollY, document.body.classList.add("alma-fixed-body"), document.body.scroll(0, P);
795
+ const i = ye(), s = be(), l = ve(), d = we(), u = J(a), m = xe(e, t, o);
796
+ document.body.appendChild(i), i.appendChild(s), s.appendChild(l), s.appendChild(d), d.appendChild(u), d.appendChild(m), i.classList.add(`${r}-fadeIn`), d.classList.add(`${r}-slideIn`), m.focus();
797
+ }
798
+ function E(e = !0, t) {
799
+ const n = document.getElementById(`${r}-wrapper`);
800
+ if (n && (!e || confirm(
801
+ (x == null ? void 0 : x.closeModalMessage) ?? "Are you sure you want to leave the payment page?"
362
802
  ))) {
363
- const n = document.getElementById(
803
+ const a = document.getElementById(
364
804
  `${r}-wrapper`
365
- ), a = document.getElementById(`${r}-body`);
366
- n == null || n.classList.add(`${r}-fadeOut`), a == null || a.classList.add(`${r}-slideOut`), window.setTimeout(() => {
367
- document.body.classList.remove("alma-fixed-body"), document.body.scroll(0, w), o.remove(), t && t();
805
+ ), o = document.getElementById(`${r}-body`);
806
+ a == null || a.classList.add(`${r}-fadeOut`), o == null || o.classList.add(`${r}-slideOut`), window.setTimeout(() => {
807
+ document.body.classList.remove("alma-fixed-body"), document.body.scroll(0, P), n.remove(), t && t();
368
808
  }, 300);
369
809
  }
370
810
  }
371
- function G() {
811
+ function ye() {
372
812
  const e = document.createElement("style");
373
- e.innerHTML = F;
813
+ e.innerHTML = fe;
374
814
  const t = document.createElement("div");
375
815
  return t.id = `${r}-wrapper`, t.role = "dialog", t.ariaModal = "true", t.appendChild(e), t;
376
816
  }
377
- function N() {
817
+ function be() {
378
818
  const e = document.createElement("div");
379
819
  return e.id = `${r}-element`, e;
380
820
  }
381
- function Y() {
821
+ function ve() {
382
822
  const e = document.createElement("div");
383
823
  return e.id = `${r}-background`, e;
384
824
  }
385
- function z() {
825
+ function we() {
386
826
  const e = document.createElement("div");
387
827
  return e.id = `${r}-body`, e;
388
828
  }
389
- function X(e, t, o) {
390
- const n = new URL(
391
- O(e, t, L.modal, o)
829
+ function xe(e, t, n) {
830
+ const a = new URL(
831
+ ae(e, t, Y.modal, n)
392
832
  );
393
- n.searchParams.append("inPageVersion", v());
394
- const a = document.createElement("iframe");
395
- return a.id = `${r}-iframe`, a.setAttribute("allow", "camera *; payment"), a.src = n.toString(), a.title = "Alma", a;
396
- }
397
- function S(e) {
833
+ a.searchParams.append("inPageVersion", I());
834
+ const o = document.createElement("iframe");
835
+ return o.id = `${r}-iframe`, o.setAttribute(
836
+ "allow",
837
+ "camera *; microphone *; geolocation *; clipboard-read *; clipboard-write *; gyroscope *; accelerometer *; magnetometer *; ch-ua-platform-version *; ch-ua-model *; ch-ua-full-version *; payment"
838
+ ), o.src = a.toString(), o.title = "Alma", o;
839
+ }
840
+ function J(e) {
398
841
  const t = document.createElement("img");
399
- return t.id = `${r}-close`, t.title = (h == null ? void 0 : h.closeModalButtonHover) || "Close the alma modal (you'll lose your data)", t.onclick = () => y(!0, e), t.onkeyup = (o) => {
400
- o.key === "Enter" && y(!1, e);
401
- }, t.src = V, t.tabIndex = 0, t;
842
+ return t.id = `${r}-close`, t.title = (x == null ? void 0 : x.closeModalButtonHover) || "Close the alma modal (you'll lose your data)", t.onclick = () => E(!0, e), t.onkeyup = (n) => {
843
+ n.key === "Enter" && E(!1, e);
844
+ }, t.src = he, t.tabIndex = 0, t;
402
845
  }
403
- function H() {
846
+ function Ee() {
404
847
  const e = document.getElementById(`${r}-close`);
405
848
  e == null || e.remove();
406
849
  }
407
- function W(e, t, o) {
408
- const { paymentId: n, onPaymentRejected: a, onPaymentSucceeded: i, onUserCloseModal: d } = e;
409
- I(t, { from: "in-page", type: "user_wants_to_pay" });
410
- const m = {
850
+ function Ce(e, t, n) {
851
+ const { paymentId: a, onPaymentRejected: o, onPaymentSucceeded: i, onUserCloseModal: s } = e;
852
+ if (typeof a != "string" || a.trim() === "") {
853
+ const d = M(
854
+ `startPayment() requires a non-empty "paymentId" (received: ${JSON.stringify(
855
+ a
856
+ )}). Make sure the payment has been created and its id retrieved before calling startPayment().`,
857
+ t.getEnvironment()
858
+ );
859
+ throw new Error(d);
860
+ }
861
+ const l = {
411
862
  success: null,
412
863
  failure: null
413
864
  };
414
- A(n, t.getEnvironment()).then((s) => {
415
- m.success = s.success, m.failure = s.failure;
416
- }), o("can_open_modal", "start-payment", () => {
417
- j(
418
- n,
419
- t.getEnvironment(),
420
- t.getTranslations(),
421
- d,
422
- t.getCheckoutUrl()
423
- );
424
- }), o(
865
+ ne(a, t.getEnvironment()).then((d) => {
866
+ l.success = d.success, l.failure = d.failure;
867
+ }), ge(
868
+ a,
869
+ t.getEnvironment(),
870
+ t.getTranslations(),
871
+ s,
872
+ t.getCheckoutUrl()
873
+ ), n(
425
874
  "3ds_started",
426
875
  "start-payment",
427
- H
428
- ), o("3ds_failed", "start-payment", () => {
429
- const s = document.getElementById(`${r}-body`);
430
- s && s.appendChild(S(d));
431
- }), o("trigger_success_callback", "start-payment", () => {
432
- _(i, m.success);
433
- }), o("trigger_reject_callback", "start-payment", () => {
434
- _(a, m.failure);
876
+ Ee
877
+ ), n("3ds_failed", "start-payment", () => {
878
+ const d = document.getElementById(`${r}-body`);
879
+ d && d.appendChild(J(s));
880
+ }), n("trigger_success_callback", "start-payment", () => {
881
+ N(i, l.success);
882
+ }), n("trigger_reject_callback", "start-payment", () => {
883
+ N(o, l.failure);
435
884
  });
436
885
  }
437
- function _(e, t) {
438
- y(!1), e ? e() : t && window.location.assign(t);
886
+ function N(e, t) {
887
+ E(!1), e ? e() : t && window.location.assign(t);
439
888
  }
440
- function J(e, t) {
441
- const o = e.getEmbeddedSelector();
442
- if (y(!1), t(), !o)
889
+ function $e(e, t) {
890
+ const n = e.getEmbeddedSelector();
891
+ if (E(!1), t(), !n)
443
892
  return;
444
- const n = C(o);
445
- e.setEmbeddedSelector(null), n && n.firstChild && n.removeChild(n.firstChild);
893
+ const a = V(n);
894
+ e.setEmbeddedSelector(null), a && a.firstChild && a.removeChild(a.firstChild);
446
895
  }
447
- function q(e) {
448
- const t = M(e.environment, e.checkoutUrl), { onInPageStatusChanged: o, unsubscribe: n } = T(
896
+ function ke(e) {
897
+ const t = ee(e.environment, e.checkoutUrl);
898
+ t.setTranslations(k(e.locale).modal);
899
+ const { onInPageStatusChanged: n, unsubscribe: a } = oe(
449
900
  t.getEnvironment(),
450
- e.selector,
451
- t.setTranslations,
452
901
  e.checkoutUrl
453
902
  );
454
- return o("embedded_loaded", "initialize", () => {
455
- t.setIsCheckoutLoaded(!0), U(t);
456
- }), o("ready_for_payment", "initialize", () => {
457
- var i;
458
- (i = e.onIntegratedPayButtonClicked) == null || i.call(e);
459
- }), R(e) && t.setEmbeddedSelector(e.selector), {
460
- startPayment: (i) => W(i, t, o),
461
- unmount: () => J(t, n)
903
+ return pe(e) && t.setEmbeddedSelector(e.selector), {
904
+ startPayment: (i) => Ce(i, t, n),
905
+ unmount: () => $e(t, a)
462
906
  };
463
907
  }
464
908
  export {
465
- q as initialize
909
+ ke as initialize
466
910
  };
467
911
  //# sourceMappingURL=index.es.js.map