@alma/in-page 2.10.0 → 2.12.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,32 +1,181 @@
1
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) => {
2
+ var ee = (e, t, n) => t in e ? Q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var z = (e, t, n) => ee(e, typeof t != "symbol" ? t + "" : t, n);
4
+ const te = (e = "LIVE", t) => {
5
5
  let n = null, a = null;
6
6
  return {
7
- setEmbeddedSelector: (m) => {
8
- n = m;
7
+ setPaymentModal: (s) => {
8
+ n = s;
9
9
  },
10
- getEmbeddedSelector: () => n,
10
+ getPaymentModal: () => n,
11
11
  getEnvironment: () => e,
12
12
  getCheckoutUrl: () => t,
13
- setTranslations: (m) => {
14
- a = m;
13
+ setTranslations: (s) => {
14
+ a = s;
15
15
  },
16
16
  getTranslations: () => a
17
17
  };
18
- }, te = "v2.10.0", V = (e) => {
18
+ }, i = "alma-in-page-modal", G = {
19
+ embedded: "/in-page/embedded/",
20
+ modal: "/in-page/modal/"
21
+ }, P = {
22
+ orange: "#FA5022",
23
+ backdrop: "#6C6C6C",
24
+ white: "#FEFEFE"
25
+ }, ne = `
26
+ #${i}-element {
27
+ position: fixed;
28
+ z-index: 10337;
29
+ top: 0;
30
+ left: 0;
31
+ bottom: 0;
32
+ right: 0;
33
+ display: flex;
34
+ align-items: center;
35
+ justify-content: center;
36
+ z-index: 9999;
37
+ }
38
+
39
+ #${i}-background {
40
+ background: ${P.backdrop};
41
+ position: absolute;
42
+ width: 100vw;
43
+ height: 100vh;
44
+ opacity: 0.8;
45
+ }
46
+
47
+ #${i}-body {
48
+ background: ${P.white};
49
+ width: 100%;
50
+ max-width: 700px;
51
+ height: calc(100% - 32px);
52
+ bottom: 0;
53
+ position: absolute;
54
+ border-radius: 0;
55
+ box-shadow: 0px 0px 12px 4px rgba(41, 15, 8, 0.04);
56
+ border-radius: 20px 20px 0 0;
57
+ overflow: hidden;
58
+ }
59
+
60
+ #${i}-close {
61
+ position: absolute;
62
+ right: 0;
63
+ top: 0;
64
+ cursor: pointer;
65
+ width: 72px;
66
+ height: 72px;
67
+ }
68
+
69
+ #${i}-close:hover, #${i}-close:focus-visible {
70
+ border-radius: 50%;
71
+ outline: 1px solid ${P.orange};
72
+ outline-offset: -16px;
73
+ }
74
+
75
+ #${i}-logo {
76
+ position: absolute;
77
+ left: 24px;
78
+ top: 16px;
79
+ }
80
+
81
+ #${i}-iframe {
82
+ width: 100%;
83
+ height: 100%;
84
+ border: 0;
85
+ }
86
+
87
+ .alma-fixed-body {
88
+ position: fixed;
89
+ width: 100%;
90
+ overflow: auto;
91
+ height: 100%;
92
+ }
93
+
94
+ .${i}-slideIn {
95
+ animation: ${i}-slideIn 300ms ease-out;
96
+ animation-iteration-count: 1;
97
+ }
98
+
99
+ .${i}-fadeIn {
100
+ animation: ${i}-fadeIn 300ms;
101
+ animation-iteration-count: 1;
102
+ }
103
+
104
+ .${i}-slideOut {
105
+ animation: ${i}-slideOut 300ms ease-in;
106
+ animation-iteration-count: 1;
107
+ }
108
+
109
+ .${i}-fadeOut {
110
+ animation: ${i}-fadeOut 300ms;
111
+ animation-iteration-count: 1;
112
+ }
113
+
114
+ @media (min-width: 600px) {
115
+ #${i}-body {
116
+ width: 80%;
117
+ height: 80%;
118
+ max-height: 700px;
119
+ bottom: initial;
120
+ border-radius: 20px;
121
+ }
122
+ }
123
+
124
+ @keyframes ${i}-slideIn {
125
+ from {
126
+ transform: translateY(300px);
127
+ }
128
+
129
+ to {
130
+ transform: translateY(0px);
131
+ }
132
+ }
133
+
134
+ @keyframes ${i}-fadeIn {
135
+ from {
136
+ opacity: 0;
137
+ visibility: hidden;
138
+ }
139
+
140
+ to {
141
+ opacity: 1;
142
+ visibility: visible;
143
+ }
144
+ }
145
+
146
+ @keyframes ${i}-slideOut {
147
+ from {
148
+ transform: translateY(0px);
149
+ }
150
+
151
+ to {
152
+ transform: translateY(300px);
153
+ }
154
+ }
155
+
156
+ @keyframes ${i}-fadeOut {
157
+ from {
158
+ opacity: 1;
159
+ visibility: visible;
160
+ }
161
+
162
+ to {
163
+ opacity: 0;
164
+ visibility: hidden;
165
+ }
166
+ }
167
+ `, ae = "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", oe = "v2.12.0", re = (e) => {
19
168
  const t = document.getElementById(e.replace("#", ""));
20
169
  if (t)
21
170
  return t;
22
- G();
171
+ H();
23
172
  };
24
- function G() {
173
+ function H() {
25
174
  throw new Error(
26
175
  "Element not found, please add an id selector for the iframe"
27
176
  );
28
177
  }
29
- function _(e, t) {
178
+ function L(e, t) {
30
179
  if (t)
31
180
  return t;
32
181
  switch (e) {
@@ -45,7 +194,7 @@ function _(e, t) {
45
194
  return "https://checkout.getalma.eu";
46
195
  }
47
196
  }
48
- function H(e) {
197
+ function Y(e) {
49
198
  switch (e) {
50
199
  case "LOCAL":
51
200
  return "http://localhost:1337";
@@ -62,28 +211,28 @@ function H(e) {
62
211
  return "https://api.getalma.eu";
63
212
  }
64
213
  }
65
- function M(e, t) {
214
+ function S(e, t) {
66
215
  const n = `[Alma InPage] ${e}`;
67
216
  return console.error(n), t !== "PROD" && t !== "LIVE" && alert(n), n;
68
217
  }
69
- function ne(e, t) {
70
- const n = H(t);
218
+ function se(e, t) {
219
+ const n = Y(t);
71
220
  return fetch(`${n}/v1/checkout/payments/${e}/return-urls`, {
72
221
  headers: {
73
- "X-Alma-Agent": `Alma Checkout - InPage/${I()}`
222
+ "X-Alma-Agent": `Alma Checkout - InPage/${_()}`
74
223
  }
75
224
  }).then((a) => a.json()).then((a) => {
76
225
  if (a.error_code) {
77
226
  let o = "";
78
227
  a.error_code === "not_found" && (o = `
79
228
 
80
- Please check that payment "${e}" has been created on the ${t} environment (${n}).`), M(
229
+ Please check that payment "${e}" has been created on the ${t} environment (${n}).`), S(
81
230
  `Error: ${a.error_code}
82
231
 
83
232
  ${a.message}${o}`,
84
233
  t
85
234
  );
86
- } else a.origin && a.origin !== "online_in_page" && M(
235
+ } else a.origin && a.origin !== "online_in_page" && S(
87
236
  `Your payment does not have the proper origin for an in-page payment, you should use "online_in_page".
88
237
 
89
238
  Please, check the documentation:
@@ -93,56 +242,120 @@ https://docs.almapay.com/docs/integration-in-page`,
93
242
  return { success: a.return_url, failure: a.failure_return_url };
94
243
  }).catch((a) => (console.error("[Alma InPage] Failed to fetch payment return URLs:", a), { success: void 0, failure: void 0 }));
95
244
  }
96
- function ae(e, t, n, a) {
97
- return _(t, a) + "/" + e + n;
245
+ function ie(e, t, n, a) {
246
+ return L(t, a) + "/" + e + n;
98
247
  }
99
- function I() {
100
- const e = te.match(/\d+\.\d+\.\d+/);
248
+ function _() {
249
+ const e = oe.match(/\d+\.\d+\.\d+/);
101
250
  return e ? e[0] : "2.0.0";
102
251
  }
103
- function oe(e, t) {
104
- const n = [], a = (s) => {
105
- if (s.origin !== _(e, t) || s.data.from !== "checkout")
252
+ let B = 0, C = null;
253
+ function le(e, t, n, a, o) {
254
+ C = n, document.getElementById(`${i}-wrapper`) && E(!1), B = window.scrollY, document.body.classList.add("alma-fixed-body"), document.body.scroll(0, B);
255
+ const l = ce(), m = ue(), p = me(), r = pe(), f = X(a), s = fe(e, t, o);
256
+ return document.body.appendChild(l), l.appendChild(m), m.appendChild(p), m.appendChild(r), r.appendChild(f), r.appendChild(s), l.classList.add(`${i}-fadeIn`), r.classList.add(`${i}-slideIn`), s.focus(), s;
257
+ }
258
+ function de(e) {
259
+ C = e;
260
+ const t = document.getElementById(`${i}-close`);
261
+ t && (t.title = e.closeModalButtonHover);
262
+ }
263
+ function E(e = !0, t) {
264
+ const n = document.getElementById(`${i}-wrapper`);
265
+ if (n && (!e || confirm(
266
+ (C == null ? void 0 : C.closeModalMessage) ?? "Are you sure you want to leave the payment page?"
267
+ ))) {
268
+ const a = document.getElementById(
269
+ `${i}-wrapper`
270
+ ), o = document.getElementById(`${i}-body`);
271
+ a == null || a.classList.add(`${i}-fadeOut`), o == null || o.classList.add(`${i}-slideOut`), window.setTimeout(() => {
272
+ document.body.classList.remove("alma-fixed-body"), document.body.scroll(0, B), n.remove(), t && t();
273
+ }, 300);
274
+ }
275
+ }
276
+ function ce() {
277
+ const e = document.createElement("style");
278
+ e.innerHTML = ne;
279
+ const t = document.createElement("div");
280
+ return t.id = `${i}-wrapper`, t.role = "dialog", t.ariaModal = "true", t.appendChild(e), t;
281
+ }
282
+ function ue() {
283
+ const e = document.createElement("div");
284
+ return e.id = `${i}-element`, e;
285
+ }
286
+ function me() {
287
+ const e = document.createElement("div");
288
+ return e.id = `${i}-background`, e;
289
+ }
290
+ function pe() {
291
+ const e = document.createElement("div");
292
+ return e.id = `${i}-body`, e;
293
+ }
294
+ function fe(e, t, n) {
295
+ const a = new URL(
296
+ ie(e, t, G.modal, n)
297
+ );
298
+ a.searchParams.append("inPageVersion", _());
299
+ const o = document.createElement("iframe");
300
+ return o.id = `${i}-iframe`, o.setAttribute(
301
+ "allow",
302
+ "camera *; microphone *; geolocation *; clipboard-read *; clipboard-write *; gyroscope *; accelerometer *; magnetometer *; ch-ua-platform-version *; ch-ua-model *; ch-ua-full-version *; payment"
303
+ ), o.src = a.toString(), o.title = "Alma", o;
304
+ }
305
+ function X(e) {
306
+ const t = document.createElement("img");
307
+ return t.id = `${i}-close`, t.title = (C == null ? void 0 : C.closeModalButtonHover) || "Close the alma modal (you'll lose your data)", t.onclick = () => E(!0, e), t.onkeyup = (n) => {
308
+ n.key === "Enter" && E(!1, e);
309
+ }, t.src = ae, t.tabIndex = 0, t;
310
+ }
311
+ function he() {
312
+ const e = document.getElementById(`${i}-close`);
313
+ e == null || e.remove();
314
+ }
315
+ function ge(e, t, n, a) {
316
+ const o = [], l = (r) => {
317
+ var f;
318
+ if (r.origin !== L(e, t) || r.data.from !== "checkout" || !r.source || r.source !== ((f = n()) == null ? void 0 : f.contentWindow))
106
319
  return !1;
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
- }) : (
320
+ r.data.type === "in_page_status" ? o.filter(
321
+ (s) => s && s.eventName === r.data.payload
322
+ ).forEach((s) => {
323
+ s && s.callback();
324
+ }) : r.data.type === "locale" ? typeof r.data.payload == "string" && a(r.data.payload) : (
112
325
  // 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)
326
+ r.data.type !== "embedded_height" && r.data.type !== "translations" && console.warn("Unknown message type:", r.data.type)
114
327
  );
115
328
  };
116
- window.addEventListener("message", a, !1);
117
- function o() {
118
- window.removeEventListener("message", a, !1);
329
+ window.addEventListener("message", l, !1);
330
+ function m() {
331
+ window.removeEventListener("message", l, !1);
119
332
  }
120
- function i(s, l, d) {
121
- const u = n.findIndex(
122
- (m) => m && m.eventName === s && m.callerName === l
333
+ function p(r, f, s) {
334
+ const g = o.findIndex(
335
+ (b) => b && b.eventName === r && b.callerName === f
123
336
  );
124
- u !== -1 && (n[u] = null), n.push({ eventName: s, callerName: l, callback: d });
337
+ g !== -1 && (o[g] = null), o.push({ eventName: r, callerName: f, callback: s });
125
338
  }
126
339
  return {
127
- onInPageStatusChanged: i,
128
- unsubscribe: o
340
+ onInPageStatusChanged: p,
341
+ unsubscribe: m
129
342
  };
130
343
  }
131
- class W extends Error {
344
+ class J extends Error {
132
345
  constructor() {
133
346
  super(...arguments);
134
- R(this, "name", "BlockedRequestError");
347
+ z(this, "name", "BlockedRequestError");
135
348
  }
136
349
  }
137
- async function re(e, t) {
350
+ async function ye(e, t) {
138
351
  const n = await fetch(
139
- `${H(t)}/v2/payments/eligibility`,
352
+ `${Y(t)}/v2/payments/eligibility`,
140
353
  {
141
354
  method: "POST",
142
355
  headers: {
143
356
  Authorization: `Alma-Merchant-Auth ${e.merchantId}`,
144
357
  "Content-Type": "application/json",
145
- "X-Alma-Agent": `Alma Checkout - InPage/${I()}`
358
+ "X-Alma-Agent": `Alma Checkout - InPage/${_()}`
146
359
  },
147
360
  body: JSON.stringify({
148
361
  purchase_amount: e.amountInCents,
@@ -154,11 +367,12 @@ async function re(e, t) {
154
367
  }
155
368
  ],
156
369
  capture_method: e.captureMethod,
157
- locale: e.locale
370
+ locale: e.locale,
371
+ ...e.billingCountry && { billing_address: { country: e.billingCountry } }
158
372
  })
159
373
  }
160
374
  ).catch((o) => {
161
- throw new W(String(o));
375
+ throw new J(String(o));
162
376
  });
163
377
  if (!n.ok)
164
378
  throw new Error(`Eligibility request failed with status ${n.status}`);
@@ -166,56 +380,6 @@ async function re(e, t) {
166
380
  (o) => o.eligible && o.deferred_days === e.deferredDays && o.deferred_months === e.deferredMonths
167
381
  ) ?? null;
168
382
  }
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
190
- );
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
383
  const Z = {
220
384
  fr: {
221
385
  modal: {
@@ -224,8 +388,8 @@ const Z = {
224
388
  },
225
389
  embedded: {
226
390
  total: "Total",
227
- fees: (e) => `Dont ${e} de frais à payer aujourd'hui.`,
228
- offeredFees: "Les frais de paiement sont offerts",
391
+ customerFees: "Dont frais",
392
+ feesWithTaeg: (e, t) => `${e} (TAEG ${t})`,
229
393
  payButton: (e) => `Payer ${e}`,
230
394
  noPlanError: "Une erreur est survenue, aucun échéancier n'est disponible, merci de réessayer.",
231
395
  deferredCaptureExplanation: "Vos prélèvements commenceront lorsque nous aurons validé votre commande.",
@@ -240,8 +404,8 @@ const Z = {
240
404
  },
241
405
  embedded: {
242
406
  total: "Total",
243
- fees: (e) => `Including ${e} of fees to be paid today.`,
244
- offeredFees: "Payment fees are free",
407
+ customerFees: "Including fees",
408
+ feesWithTaeg: (e, t) => `${e} (APR ${t})`,
245
409
  payButton: (e) => `Pay ${e}`,
246
410
  noPlanError: "An error has occurred, no payment schedule is available, please try again.",
247
411
  deferredCaptureExplanation: "Your direct debits will start as soon as we have validated your order.",
@@ -256,8 +420,8 @@ const Z = {
256
420
  },
257
421
  embedded: {
258
422
  total: "Gesamtbetrag",
259
- fees: (e) => `Davon ${e} Gebühren, die heute bezahlt werden müssen.`,
260
- offeredFees: "Die Zahlungsgebühren sind erlassen",
423
+ customerFees: "Davon Kosten",
424
+ feesWithTaeg: (e, t) => `${e} (effektiver Jahreszins ${t})`,
261
425
  payButton: (e) => `${e} zahlen`,
262
426
  noPlanError: "Es ist ein Fehler aufgetreten, es ist kein Zahlungsplan verfügbar. Bitte versuchen Sie es erneut.",
263
427
  deferredCaptureExplanation: "Ihre Abbuchungen beginnen, sobald wir Ihre Bestellung freigegeben haben.",
@@ -272,8 +436,8 @@ const Z = {
272
436
  },
273
437
  embedded: {
274
438
  total: "Totale",
275
- fees: (e) => `Inclusa la commissione di ${e} per il pagamento rateale.`,
276
- offeredFees: "Nessuna commissione di pagamento",
439
+ customerFees: "Di cui commissioni",
440
+ feesWithTaeg: (e, t) => `${e} (TAEG ${t})`,
277
441
  payButton: (e) => `Paga ${e}`,
278
442
  noPlanError: "Si è verificato un errore, non è disponibile nessun piano di pagamento, riprovare.",
279
443
  deferredCaptureExplanation: "Gli addebiti diretti inizieranno non appena avremo convalidato l'ordine.",
@@ -288,8 +452,8 @@ const Z = {
288
452
  },
289
453
  embedded: {
290
454
  total: "Total",
291
- fees: (e) => `De los cuales ${e} son gastos administrativos.`,
292
- offeredFees: "Las comisiones de pago son gratuitas",
455
+ customerFees: "De los cuales, los costes administrativos",
456
+ feesWithTaeg: (e, t) => `${e} (TAE ${t})`,
293
457
  payButton: (e) => `Pagar ${e}`,
294
458
  noPlanError: "Se ha producido un error, inténtelo de nuevo.",
295
459
  deferredCaptureExplanation: "La domiciliación bancaria se iniciará en cuanto hayamos validado tu pedido.",
@@ -304,8 +468,8 @@ const Z = {
304
468
  },
305
469
  embedded: {
306
470
  total: "Totaal",
307
- fees: (e) => `Waarvan ${e} kosten die vandaag moeten worden betaald.`,
308
- offeredFees: "Geen extra kosten",
471
+ customerFees: "Waarvan kosten",
472
+ feesWithTaeg: (e, t) => `${e} (JKP ${t})`,
309
473
  payButton: (e) => `Betaal ${e}`,
310
474
  noPlanError: "Er is een fout opgetreden, er is geen betaalschema beschikbaar, probeer het opnieuw.",
311
475
  deferredCaptureExplanation: "Uw automatische incasso's beginnen zodra we uw bestelling hebben gevalideerd.",
@@ -320,8 +484,8 @@ const Z = {
320
484
  },
321
485
  embedded: {
322
486
  total: "Total",
323
- fees: (e) => `Do qual ${e} deve ser pago hoje.`,
324
- offeredFees: "As despesas de pagamento são gratuitas",
487
+ customerFees: "Incluindo encargos",
488
+ feesWithTaeg: (e, t) => `${e} (TAEG ${t})`,
325
489
  payButton: (e) => `Pagar ${e}`,
326
490
  noPlanError: "Ocorreu um erro, não existe nenhum plano de pagamento disponível, tente novamente.",
327
491
  deferredCaptureExplanation: "Os seus débitos diretos começarão assim que tivermos validado a sua encomenda.",
@@ -330,19 +494,66 @@ const Z = {
330
494
  }
331
495
  }
332
496
  };
333
- function z(e) {
497
+ function W(e) {
334
498
  return Object.keys(Z).includes(e);
335
499
  }
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";
500
+ function I(e) {
501
+ const t = String(e ?? "").toLowerCase();
502
+ if (W(t)) return t;
503
+ const n = navigator.language.split("-")[0].toLowerCase();
504
+ return W(n) ? n : "en";
341
505
  }
342
- function k(e) {
343
- return Z[B(e)];
506
+ function M(e) {
507
+ return Z[I(e)];
344
508
  }
345
- const U = `
509
+ function be(e, t) {
510
+ if (!e.isConnected) return;
511
+ const {
512
+ environment: n,
513
+ merchantId: a,
514
+ selector: o,
515
+ amountInCents: l,
516
+ installmentsCount: m,
517
+ deferredDays: p,
518
+ deferredMonths: r,
519
+ locale: f,
520
+ captureMethod: s,
521
+ billingCountry: g,
522
+ style: b,
523
+ onIntegratedPayButtonClicked: y,
524
+ checkoutUrl: v
525
+ } = t, d = new URL(
526
+ L(n ?? "PROD", v) + G.embedded
527
+ );
528
+ d.searchParams.append("merchantId", a), d.searchParams.append("amountInCents", l.toString()), d.searchParams.append("installmentsCount", m.toString()), p && d.searchParams.append("deferredDays", p.toString()), r && d.searchParams.append("deferredMonths", r.toString()), d.searchParams.append("locale", I(f).toUpperCase()), d.searchParams.append("captureMethod", s ?? "automatic"), g !== void 0 && d.searchParams.append("billingCountry", g), d.searchParams.append("domElement", o), d.searchParams.append("style", JSON.stringify(b || null)), d.searchParams.append("inPageVersion", _()), y && d.searchParams.append("showPayButton", "true"), d.searchParams.append("fallback", "true");
529
+ const c = document.createElement("iframe");
530
+ return c.src = d.toString(), c.id = `alma-embedded-iframe-${o}`, c.style.width = "100%", c.style.height = "150px", c.style.transition = "height 0.5s", c.style.border = "none", c.style.display = e.style.display === "none" ? "none" : "block", c.setAttribute("allow", "payment"), e.replaceWith(c), window.addEventListener("message", function w(h) {
531
+ if (!c.isConnected) {
532
+ window.removeEventListener("message", w);
533
+ return;
534
+ }
535
+ h.origin !== d.origin || h.source !== c.contentWindow || (h.data.type === "embedded_height" ? c.style.height = `${Math.ceil(h.data.payload)}px` : h.data.type === "in_page_status" && h.data.payload === "ready_for_payment" && (y == null || y()));
536
+ }), c;
537
+ }
538
+ const K = "Alma Inter", we = "https://cdn.almapay.com/fonts/Inter/InterVariable-latin.woff2", ve = 300;
539
+ let F = null;
540
+ function Ce() {
541
+ if (F || typeof FontFace > "u" || !document.fonts) return;
542
+ const e = new FontFace(K, `url(${we}) format("woff2")`, {
543
+ weight: "400 700",
544
+ display: "swap"
545
+ });
546
+ document.fonts.add(e), F = e.load().catch((t) => {
547
+ console.error("[Alma InPage] Failed to load the font:", t);
548
+ });
549
+ }
550
+ function $e() {
551
+ return Promise.race([
552
+ F,
553
+ new Promise((e) => setTimeout(e, ve))
554
+ ]);
555
+ }
556
+ const N = `
346
557
  /* The merchant's rules matching the host win over :host, unless :host is !important */
347
558
  :host {
348
559
  padding: 0 !important;
@@ -363,7 +574,7 @@ const U = `
363
574
  flex-direction: column;
364
575
  gap: 10px;
365
576
  margin: 8px 16px;
366
- font-family: "${X}", sans-serif;
577
+ font-family: "${K}", sans-serif;
367
578
  font-size: 14px;
368
579
  line-height: 19px;
369
580
  letter-spacing: -0.6px;
@@ -487,425 +698,226 @@ const U = `
487
698
  }
488
699
  }
489
700
  `;
490
- function p(e, t, n) {
701
+ function u(e, t, n) {
491
702
  const a = document.createElement(e);
492
703
  return t && (a.className = t), n !== void 0 && (a.textContent = n), a;
493
704
  }
494
- function C(e, t) {
495
- const n = p("span", "skeleton");
705
+ function k(e, t) {
706
+ const n = u("span", "skeleton");
496
707
  n.style.width = `${e}px`;
497
- const a = p("span", t);
708
+ const a = u("span", t);
498
709
  return a.append(n), a;
499
710
  }
500
- function L(e, t) {
711
+ function T(e, t) {
501
712
  t && typeof t == "object" && Object.assign(e.style, t);
502
713
  }
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);
714
+ function O(e) {
715
+ const t = u("div", "container fadeIn");
716
+ return T(t, e.containerStyle), t;
510
717
  }
718
+ let A = null;
511
719
  function D(e, t) {
720
+ "adoptedStyleSheets" in e && "replaceSync" in CSSStyleSheet.prototype ? (A || (A = new CSSStyleSheet(), A.replaceSync(N)), e.adoptedStyleSheets = [A], e.replaceChildren(t)) : e.replaceChildren(u("style", void 0, N), t);
721
+ }
722
+ function R(e, t) {
512
723
  var o;
513
724
  const n = e.host.clientWidth;
514
725
  (o = e.querySelector(".button")) == null || o.classList.toggle("fitContent", n >= 769);
515
- const a = new Intl.DateTimeFormat(B(t), {
726
+ const a = new Intl.DateTimeFormat(I(t), {
516
727
  day: "numeric",
517
728
  month: n > 400 ? "long" : "short"
518
729
  }).format;
519
- e.querySelectorAll(".date").forEach((i) => {
520
- i.textContent = a(Number(i.dataset.dueDate));
730
+ e.querySelectorAll(".date").forEach((l) => {
731
+ l.textContent = a(Number(l.dataset.dueDate));
521
732
  });
522
733
  }
523
734
  function q(e) {
524
735
  return e > 4;
525
736
  }
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);
737
+ function xe(e, t) {
738
+ const n = O(t);
739
+ n.classList.add("delayed"), D(e, n);
740
+ const a = M(t.locale).embedded;
741
+ if (t.isDeferredCapture && n.append(u("div", "bold", a.deferredCaptureExplanation)), !q(t.installmentsCount)) {
742
+ const o = u("div", "installments");
743
+ for (let r = 0; r < t.installmentsCount; r++) {
744
+ const f = u("div", "installment");
745
+ f.append(k(90, "label"), k(60)), o.append(f);
535
746
  }
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);
747
+ const l = u("div", "total"), m = u("div", "totalAmount"), p = u("div", "bold");
748
+ p.append(k(60)), m.append(p, u("div", "fees", " ")), l.append(k(40), m), o.append(l), n.append(o);
538
749
  }
539
750
  if (t.onPayButtonClicked) {
540
- const o = p("button", "button skeletonButton", " ");
541
- o.disabled = !0, L(o, t.buttonStyle), n.append(o);
751
+ const o = u("button", "button skeletonButton", " ");
752
+ o.disabled = !0, T(o, t.buttonStyle), n.append(o);
542
753
  }
543
- D(e, t.locale);
754
+ R(e, t.locale);
544
755
  }
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, {
756
+ function Ee(e, t, n) {
757
+ const a = O(n), o = I(n.locale), l = M(n.locale).embedded, m = (s) => new Intl.NumberFormat(o, {
547
758
  style: "currency",
548
759
  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;
760
+ }).format(s / 100), p = (s) => new Intl.NumberFormat(o, {
761
+ style: "percent",
762
+ minimumFractionDigits: 2,
763
+ maximumFractionDigits: 2
764
+ }).format(s / 1e4);
765
+ n.isDeferredCapture && a.append(u("div", "bold", l.deferredCaptureExplanation));
766
+ const r = t.customer_fee + t.customer_interest, f = t.purchase_amount + r;
552
767
  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(
768
+ const s = u("div", "installments");
769
+ s.dataset.testid = "installments", t.payment_plan.forEach((c, w) => {
770
+ const h = u("div", "installment");
771
+ h.dataset.testid = `installment-${w}`;
772
+ const $ = u("span", "label");
773
+ n.isDeferredCapture ? $.textContent = w === 0 ? l.deferredFirstInstallment : l.deferredMonth(w) : ($.classList.add("date"), $.dataset.dueDate = String(c.due_date * 1e3)), h.append(
774
+ $,
775
+ u(
561
776
  "span",
562
777
  void 0,
563
- s(
564
- h.purchase_amount + h.customer_fee + h.customer_interest
778
+ m(
779
+ c.purchase_amount + c.customer_fee + c.customer_interest
565
780
  )
566
781
  )
567
- ), u.append(f);
782
+ ), s.append(h);
568
783
  });
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);
784
+ const g = u("div", "total"), b = u("div", "fees"), y = m(r), v = typeof t.annual_interest_rate == "number" ? p(t.annual_interest_rate) : null;
785
+ b.textContent = `${l.customerFees} ${v === null ? y : l.feesWithTaeg(y, v)}`;
786
+ const d = u("div", "totalAmount");
787
+ d.append(u("div", "bold", m(f)), b), g.append(u("span", "bold", l.total), d), s.append(g), a.append(s);
577
788
  }
578
789
  if (n.onPayButtonClicked) {
579
- const u = p(
790
+ const s = u(
580
791
  "button",
581
792
  "button",
582
- i.payButton(s(d))
793
+ l.payButton(m(f))
583
794
  );
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);
795
+ s.type = "button", T(s, n.buttonStyle), s.onclick = () => {
796
+ var g;
797
+ return (g = n.onPayButtonClicked) == null ? void 0 : g.call(n);
798
+ }, a.append(s);
588
799
  }
589
- O(e, a), D(e, n.locale);
800
+ D(e, a), R(e, n.locale);
590
801
  }
591
802
  function j(e, t) {
592
- const n = F(t);
593
- n.classList.add("error"), n.textContent = k(t.locale).embedded.noPlanError, O(e, n);
803
+ const n = O(t);
804
+ n.classList.add("error"), n.textContent = M(t.locale).embedded.noPlanError, D(e, n);
594
805
  }
595
- function pe(e) {
596
- var T;
806
+ function Me(e) {
807
+ var U;
597
808
  const {
598
809
  environment: t,
599
810
  merchantId: n,
600
811
  selector: a,
601
812
  amountInCents: o,
602
- installmentsCount: i,
603
- deferredDays: s,
604
- deferredMonths: l,
605
- locale: d,
606
- captureMethod: u,
607
- style: m,
608
- onIntegratedPayButtonClicked: v
813
+ installmentsCount: l,
814
+ deferredDays: m,
815
+ deferredMonths: p,
816
+ locale: r,
817
+ captureMethod: f,
818
+ style: s,
819
+ billingCountry: g,
820
+ onIntegratedPayButtonClicked: b
609
821
  } = e;
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
822
+ if (!a) {
823
+ H();
824
+ return;
825
+ }
826
+ const y = (x) => parseInt(String(x), 10), v = y(l), d = document.createElement("div");
827
+ d.id = `alma-embedded-${a.replace("#", "")}`, d.style.width = "100%", d.style.display = v > 4 && !b ? "none" : "flow-root";
828
+ const c = d.attachShadow({ mode: "open" });
829
+ (U = re(a)) == null || U.replaceChildren(d);
830
+ let w = d;
831
+ const h = {
832
+ locale: r,
833
+ installmentsCount: v,
834
+ isDeferredCapture: f === "manual",
835
+ onPayButtonClicked: b,
836
+ containerStyle: s == null ? void 0 : s.embedded,
837
+ buttonStyle: s == null ? void 0 : s.embeddedButton
623
838
  };
624
- de(), ue(f, y);
625
- const b = new ResizeObserver(() => {
626
- c.isConnected ? D(f, d) : b.disconnect();
839
+ Ce(), xe(c, h);
840
+ const $ = new ResizeObserver(() => {
841
+ d.isConnected ? R(c, r) : $.disconnect();
627
842
  });
628
- return b.observe(c), re(
843
+ return $.observe(d), ye(
629
844
  {
630
845
  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"
846
+ amountInCents: y(o),
847
+ installmentsCount: v,
848
+ deferredDays: y(m) || 0,
849
+ deferredMonths: y(p) || 0,
850
+ captureMethod: f ?? "automatic",
851
+ locale: I(r).toUpperCase(),
852
+ billingCountry: g
637
853
  },
638
854
  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);
643
- }), !0;
644
- }
645
- const S = {
646
- orange: "#FA5022",
647
- backdrop: "#6C6C6C",
648
- white: "#FEFEFE"
649
- }, fe = `
650
- #${r}-element {
651
- position: fixed;
652
- z-index: 10337;
653
- top: 0;
654
- left: 0;
655
- bottom: 0;
656
- right: 0;
657
- display: flex;
658
- align-items: center;
659
- justify-content: center;
660
- z-index: 9999;
661
- }
662
-
663
- #${r}-background {
664
- background: ${S.backdrop};
665
- position: absolute;
666
- width: 100vw;
667
- height: 100vh;
668
- opacity: 0.8;
669
- }
670
-
671
- #${r}-body {
672
- background: ${S.white};
673
- width: 100%;
674
- max-width: 700px;
675
- height: calc(100% - 32px);
676
- bottom: 0;
677
- position: absolute;
678
- border-radius: 0;
679
- box-shadow: 0px 0px 12px 4px rgba(41, 15, 8, 0.04);
680
- border-radius: 20px 20px 0 0;
681
- overflow: hidden;
682
- }
683
-
684
- #${r}-close {
685
- position: absolute;
686
- right: 0;
687
- top: 0;
688
- cursor: pointer;
689
- width: 72px;
690
- height: 72px;
691
- }
692
-
693
- #${r}-close:hover, #${r}-close:focus-visible {
694
- border-radius: 50%;
695
- outline: 1px solid ${S.orange};
696
- outline-offset: -16px;
697
- }
698
-
699
- #${r}-logo {
700
- position: absolute;
701
- left: 24px;
702
- top: 16px;
703
- }
704
-
705
- #${r}-iframe {
706
- width: 100%;
707
- height: 100%;
708
- border: 0;
709
- }
710
-
711
- .alma-fixed-body {
712
- position: fixed;
713
- width: 100%;
714
- overflow: auto;
715
- height: 100%;
716
- }
717
-
718
- .${r}-slideIn {
719
- animation: ${r}-slideIn 300ms ease-out;
720
- animation-iteration-count: 1;
721
- }
722
-
723
- .${r}-fadeIn {
724
- animation: ${r}-fadeIn 300ms;
725
- animation-iteration-count: 1;
726
- }
727
-
728
- .${r}-slideOut {
729
- animation: ${r}-slideOut 300ms ease-in;
730
- animation-iteration-count: 1;
731
- }
732
-
733
- .${r}-fadeOut {
734
- animation: ${r}-fadeOut 300ms;
735
- animation-iteration-count: 1;
736
- }
737
-
738
- @media (min-width: 600px) {
739
- #${r}-body {
740
- width: 80%;
741
- height: 80%;
742
- max-height: 700px;
743
- bottom: initial;
744
- border-radius: 20px;
745
- }
746
- }
747
-
748
- @keyframes ${r}-slideIn {
749
- from {
750
- transform: translateY(300px);
751
- }
752
-
753
- to {
754
- transform: translateY(0px);
755
- }
756
- }
757
-
758
- @keyframes ${r}-fadeIn {
759
- from {
760
- opacity: 0;
761
- visibility: hidden;
762
- }
763
-
764
- to {
765
- opacity: 1;
766
- visibility: visible;
767
- }
768
- }
769
-
770
- @keyframes ${r}-slideOut {
771
- from {
772
- transform: translateY(0px);
773
- }
774
-
775
- to {
776
- transform: translateY(300px);
777
- }
778
- }
779
-
780
- @keyframes ${r}-fadeOut {
781
- from {
782
- opacity: 1;
783
- visibility: visible;
784
- }
785
-
786
- to {
787
- opacity: 0;
788
- visibility: hidden;
789
- }
790
- }
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?"
802
- ))) {
803
- const a = document.getElementById(
804
- `${r}-wrapper`
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();
808
- }, 300);
809
- }
810
- }
811
- function ye() {
812
- const e = document.createElement("style");
813
- e.innerHTML = fe;
814
- const t = document.createElement("div");
815
- return t.id = `${r}-wrapper`, t.role = "dialog", t.ariaModal = "true", t.appendChild(e), t;
816
- }
817
- function be() {
818
- const e = document.createElement("div");
819
- return e.id = `${r}-element`, e;
820
- }
821
- function ve() {
822
- const e = document.createElement("div");
823
- return e.id = `${r}-background`, e;
824
- }
825
- function we() {
826
- const e = document.createElement("div");
827
- return e.id = `${r}-body`, e;
828
- }
829
- function xe(e, t, n) {
830
- const a = new URL(
831
- ae(e, t, Y.modal, n)
832
- );
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) {
841
- const t = document.createElement("img");
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;
845
- }
846
- function Ee() {
847
- const e = document.getElementById(`${r}-close`);
848
- e == null || e.remove();
849
- }
850
- function Ce(e, t, n) {
851
- const { paymentId: a, onPaymentRejected: o, onPaymentSucceeded: i, onUserCloseModal: s } = e;
855
+ ).then(async (x) => {
856
+ await $e(), x ? Ee(c, x, h) : j(c, h);
857
+ }).catch((x) => {
858
+ console.error("[Alma InPage] Failed to display the payment plan:", x), x instanceof J ? w = be(d, e) ?? w : j(c, h);
859
+ }), () => w.remove();
860
+ }
861
+ function Ie(e, t, n) {
862
+ const { paymentId: a, onPaymentRejected: o, onPaymentSucceeded: l, onUserCloseModal: m } = e;
852
863
  if (typeof a != "string" || a.trim() === "") {
853
- const d = M(
864
+ const r = S(
854
865
  `startPayment() requires a non-empty "paymentId" (received: ${JSON.stringify(
855
866
  a
856
867
  )}). Make sure the payment has been created and its id retrieved before calling startPayment().`,
857
868
  t.getEnvironment()
858
869
  );
859
- throw new Error(d);
870
+ throw new Error(r);
860
871
  }
861
- const l = {
872
+ const p = {
862
873
  success: null,
863
874
  failure: null
864
875
  };
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()
876
+ se(a, t.getEnvironment()).then((r) => {
877
+ p.success = r.success, p.failure = r.failure;
878
+ }), t.setPaymentModal(
879
+ le(
880
+ a,
881
+ t.getEnvironment(),
882
+ t.getTranslations(),
883
+ m,
884
+ t.getCheckoutUrl()
885
+ )
873
886
  ), n(
874
887
  "3ds_started",
875
888
  "start-payment",
876
- Ee
889
+ he
877
890
  ), n("3ds_failed", "start-payment", () => {
878
- const d = document.getElementById(`${r}-body`);
879
- d && d.appendChild(J(s));
891
+ const r = document.getElementById(`${i}-body`);
892
+ r && r.appendChild(X(m));
880
893
  }), n("trigger_success_callback", "start-payment", () => {
881
- N(i, l.success);
894
+ V(l, p.success);
882
895
  }), n("trigger_reject_callback", "start-payment", () => {
883
- N(o, l.failure);
896
+ V(o, p.failure);
884
897
  });
885
898
  }
886
- function N(e, t) {
899
+ function V(e, t) {
887
900
  E(!1), e ? e() : t && window.location.assign(t);
888
901
  }
889
- function $e(e, t) {
890
- const n = e.getEmbeddedSelector();
891
- if (E(!1), t(), !n)
892
- return;
893
- const a = V(n);
894
- e.setEmbeddedSelector(null), a && a.firstChild && a.removeChild(a.firstChild);
902
+ function ke(e, t, n) {
903
+ var a;
904
+ (a = e.getPaymentModal()) != null && a.isConnected && E(!1), t(), n == null || n();
895
905
  }
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(
906
+ function _e(e) {
907
+ const t = te(e.environment, e.checkoutUrl);
908
+ t.setTranslations(M(e.locale).modal);
909
+ const { onInPageStatusChanged: n, unsubscribe: a } = ge(
900
910
  t.getEnvironment(),
901
- e.checkoutUrl
902
- );
903
- return pe(e) && t.setEmbeddedSelector(e.selector), {
904
- startPayment: (i) => Ce(i, t, n),
905
- unmount: () => $e(t, a)
911
+ e.checkoutUrl,
912
+ t.getPaymentModal,
913
+ (l) => de(M(l).modal)
914
+ ), o = Me(e);
915
+ return {
916
+ startPayment: (l) => Ie(l, t, n),
917
+ unmount: () => ke(t, a, o)
906
918
  };
907
919
  }
908
920
  export {
909
- ke as initialize
921
+ _e as initialize
910
922
  };
911
923
  //# sourceMappingURL=index.es.js.map