@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.umd.js CHANGED
@@ -1,11 +1,153 @@
1
- (function(h,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(h=typeof globalThis<"u"?globalThis:h||self,g((h.Alma=h.Alma||{},h.Alma.InPage={})))})(this,function(h){"use strict";var Ie=Object.defineProperty;var Se=(h,g,$)=>g in h?Ie(h,g,{enumerable:!0,configurable:!0,writable:!0,value:$}):h[g]=$;var ee=(h,g,$)=>Se(h,typeof g!="symbol"?g+"":g,$);const g=(e="LIVE",t)=>{let n=null,a=null;return{setEmbeddedSelector:m=>{n=m},getEmbeddedSelector:()=>n,getEnvironment:()=>e,getCheckoutUrl:()=>t,setTranslations:m=>{a=m},getTranslations:()=>a}},$="v2.10.0",U=e=>{const t=document.getElementById(e.replace("#",""));if(t)return t;j()};function j(){throw new Error("Element not found, please add an id selector for the iframe")}function P(e,t){if(t)return t;switch(e){case"LOCAL":return"http://localhost:1350";case"TEST":case"SANDBOX":return"https://checkout.sandbox.getalma.eu";case"STAGING":return"https://checkout.staging.almapay.com";case"DEV":return"https://checkout.dev.almapay.com";case"LIVE":case"PROD":default:return"https://checkout.getalma.eu"}}function N(e){switch(e){case"LOCAL":return"http://localhost:1337";case"TEST":case"SANDBOX":return"https://api.sandbox.getalma.eu";case"STAGING":return"https://api.staging.almapay.com";case"DEV":return"https://api.dev.almapay.com";case"LIVE":case"PROD":default:return"https://api.getalma.eu"}}function _(e,t){const n=`[Alma InPage] ${e}`;return console.error(n),t!=="PROD"&&t!=="LIVE"&&alert(n),n}function te(e,t){const n=N(t);return fetch(`${n}/v1/checkout/payments/${e}/return-urls`,{headers:{"X-Alma-Agent":`Alma Checkout - InPage/${S()}`}}).then(a=>a.json()).then(a=>{if(a.error_code){let o="";a.error_code==="not_found"&&(o=`
1
+ (function(g,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(g=typeof globalThis<"u"?globalThis:g||self,y((g.Alma=g.Alma||{},g.Alma.InPage={})))})(this,function(g){"use strict";var Ae=Object.defineProperty;var Pe=(g,y,r)=>y in g?Ae(g,y,{enumerable:!0,configurable:!0,writable:!0,value:r}):g[y]=r;var ee=(g,y,r)=>Pe(g,typeof y!="symbol"?y+"":y,r);const y=(e="LIVE",t)=>{let n=null,a=null;return{setPaymentModal:s=>{n=s},getPaymentModal:()=>n,getEnvironment:()=>e,getCheckoutUrl:()=>t,setTranslations:s=>{a=s},getTranslations:()=>a}},r="alma-in-page-modal",W={embedded:"/in-page/embedded/",modal:"/in-page/modal/"},B={orange:"#FA5022",backdrop:"#6C6C6C",white:"#FEFEFE"},te=`
2
+ #${r}-element {
3
+ position: fixed;
4
+ z-index: 10337;
5
+ top: 0;
6
+ left: 0;
7
+ bottom: 0;
8
+ right: 0;
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: center;
12
+ z-index: 9999;
13
+ }
14
+
15
+ #${r}-background {
16
+ background: ${B.backdrop};
17
+ position: absolute;
18
+ width: 100vw;
19
+ height: 100vh;
20
+ opacity: 0.8;
21
+ }
22
+
23
+ #${r}-body {
24
+ background: ${B.white};
25
+ width: 100%;
26
+ max-width: 700px;
27
+ height: calc(100% - 32px);
28
+ bottom: 0;
29
+ position: absolute;
30
+ border-radius: 0;
31
+ box-shadow: 0px 0px 12px 4px rgba(41, 15, 8, 0.04);
32
+ border-radius: 20px 20px 0 0;
33
+ overflow: hidden;
34
+ }
35
+
36
+ #${r}-close {
37
+ position: absolute;
38
+ right: 0;
39
+ top: 0;
40
+ cursor: pointer;
41
+ width: 72px;
42
+ height: 72px;
43
+ }
44
+
45
+ #${r}-close:hover, #${r}-close:focus-visible {
46
+ border-radius: 50%;
47
+ outline: 1px solid ${B.orange};
48
+ outline-offset: -16px;
49
+ }
50
+
51
+ #${r}-logo {
52
+ position: absolute;
53
+ left: 24px;
54
+ top: 16px;
55
+ }
56
+
57
+ #${r}-iframe {
58
+ width: 100%;
59
+ height: 100%;
60
+ border: 0;
61
+ }
62
+
63
+ .alma-fixed-body {
64
+ position: fixed;
65
+ width: 100%;
66
+ overflow: auto;
67
+ height: 100%;
68
+ }
69
+
70
+ .${r}-slideIn {
71
+ animation: ${r}-slideIn 300ms ease-out;
72
+ animation-iteration-count: 1;
73
+ }
74
+
75
+ .${r}-fadeIn {
76
+ animation: ${r}-fadeIn 300ms;
77
+ animation-iteration-count: 1;
78
+ }
79
+
80
+ .${r}-slideOut {
81
+ animation: ${r}-slideOut 300ms ease-in;
82
+ animation-iteration-count: 1;
83
+ }
84
+
85
+ .${r}-fadeOut {
86
+ animation: ${r}-fadeOut 300ms;
87
+ animation-iteration-count: 1;
88
+ }
89
+
90
+ @media (min-width: 600px) {
91
+ #${r}-body {
92
+ width: 80%;
93
+ height: 80%;
94
+ max-height: 700px;
95
+ bottom: initial;
96
+ border-radius: 20px;
97
+ }
98
+ }
99
+
100
+ @keyframes ${r}-slideIn {
101
+ from {
102
+ transform: translateY(300px);
103
+ }
104
+
105
+ to {
106
+ transform: translateY(0px);
107
+ }
108
+ }
109
+
110
+ @keyframes ${r}-fadeIn {
111
+ from {
112
+ opacity: 0;
113
+ visibility: hidden;
114
+ }
115
+
116
+ to {
117
+ opacity: 1;
118
+ visibility: visible;
119
+ }
120
+ }
121
+
122
+ @keyframes ${r}-slideOut {
123
+ from {
124
+ transform: translateY(0px);
125
+ }
126
+
127
+ to {
128
+ transform: translateY(300px);
129
+ }
130
+ }
131
+
132
+ @keyframes ${r}-fadeOut {
133
+ from {
134
+ opacity: 1;
135
+ visibility: visible;
136
+ }
137
+
138
+ to {
139
+ opacity: 0;
140
+ visibility: hidden;
141
+ }
142
+ }
143
+ `,ne="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",ae="v2.12.0",oe=e=>{const t=document.getElementById(e.replace("#",""));if(t)return t;j()};function j(){throw new Error("Element not found, please add an id selector for the iframe")}function F(e,t){if(t)return t;switch(e){case"LOCAL":return"http://localhost:1350";case"TEST":case"SANDBOX":return"https://checkout.sandbox.getalma.eu";case"STAGING":return"https://checkout.staging.almapay.com";case"DEV":return"https://checkout.dev.almapay.com";case"LIVE":case"PROD":default:return"https://checkout.getalma.eu"}}function N(e){switch(e){case"LOCAL":return"http://localhost:1337";case"TEST":case"SANDBOX":return"https://api.sandbox.getalma.eu";case"STAGING":return"https://api.staging.almapay.com";case"DEV":return"https://api.dev.almapay.com";case"LIVE":case"PROD":default:return"https://api.getalma.eu"}}function L(e,t){const n=`[Alma InPage] ${e}`;return console.error(n),t!=="PROD"&&t!=="LIVE"&&alert(n),n}function re(e,t){const n=N(t);return fetch(`${n}/v1/checkout/payments/${e}/return-urls`,{headers:{"X-Alma-Agent":`Alma Checkout - InPage/${P()}`}}).then(a=>a.json()).then(a=>{if(a.error_code){let o="";a.error_code==="not_found"&&(o=`
2
144
 
3
- Please check that payment "${e}" has been created on the ${t} environment (${n}).`),_(`Error: ${a.error_code}
145
+ Please check that payment "${e}" has been created on the ${t} environment (${n}).`),L(`Error: ${a.error_code}
4
146
 
5
- ${a.message}${o}`,t)}else a.origin&&a.origin!=="online_in_page"&&_(`Your payment does not have the proper origin for an in-page payment, you should use "online_in_page".
147
+ ${a.message}${o}`,t)}else a.origin&&a.origin!=="online_in_page"&&L(`Your payment does not have the proper origin for an in-page payment, you should use "online_in_page".
6
148
 
7
149
  Please, check the documentation:
8
- https://docs.almapay.com/docs/integration-in-page`,t);return{success:a.return_url,failure:a.failure_return_url}}).catch(a=>(console.error("[Alma InPage] Failed to fetch payment return URLs:",a),{success:void 0,failure:void 0}))}function ne(e,t,n,a){return P(t,a)+"/"+e+n}function S(){const e=$.match(/\d+\.\d+\.\d+/);return e?e[0]:"2.0.0"}function ae(e,t){const n=[],a=s=>{if(s.origin!==P(e,t)||s.data.from!=="checkout")return!1;s.data.type==="in_page_status"?n.filter(l=>l&&l.eventName===s.data.payload).forEach(l=>{l&&l.callback()}):s.data.type!=="embedded_height"&&s.data.type!=="translations"&&console.warn("Unknown message type:",s.data.type)};window.addEventListener("message",a,!1);function o(){window.removeEventListener("message",a,!1)}function i(s,l,d){const u=n.findIndex(m=>m&&m.eventName===s&&m.callerName===l);u!==-1&&(n[u]=null),n.push({eventName:s,callerName:l,callback:d})}return{onInPageStatusChanged:i,unsubscribe:o}}class V extends Error{constructor(){super(...arguments);ee(this,"name","BlockedRequestError")}}async function oe(e,t){const n=await fetch(`${N(t)}/v2/payments/eligibility`,{method:"POST",headers:{Authorization:`Alma-Merchant-Auth ${e.merchantId}`,"Content-Type":"application/json","X-Alma-Agent":`Alma Checkout - InPage/${S()}`},body:JSON.stringify({purchase_amount:e.amountInCents,queries:[{installments_count:e.installmentsCount,deferred_days:e.deferredDays,deferred_months:e.deferredMonths}],capture_method:e.captureMethod,locale:e.locale})}).catch(o=>{throw new V(String(o))});if(!n.ok)throw new Error(`Eligibility request failed with status ${n.status}`);return(await n.json()).find(o=>o.eligible&&o.deferred_days===e.deferredDays&&o.deferred_months===e.deferredMonths)??null}const r="alma-in-page-modal",G={embedded:"/in-page/embedded/",modal:"/in-page/modal/"};function re(e,t){if(!e.isConnected)return;const{environment:n,merchantId:a,selector:o,amountInCents:i,installmentsCount:s,deferredDays:l,deferredMonths:d,locale:u,captureMethod:m,style:x,onIntegratedPayButtonClicked:b,checkoutUrl:y}=t,c=new URL(P(n??"PROD",y)+G.embedded);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(x||null)),c.searchParams.append("inPageVersion",S()),b&&c.searchParams.append("showPayButton","true"),c.searchParams.append("fallback","true");const f=document.createElement("iframe");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 v(w){if(!f.isConnected){window.removeEventListener("message",v);return}w.origin!==c.origin||w.source!==f.contentWindow||(w.data.type==="embedded_height"?f.style.height=`${Math.ceil(w.data.payload)}px`:w.data.type==="in_page_status"&&w.data.payload==="ready_for_payment"&&(b==null||b()))})}const H="Alma Inter",se="https://cdn.almapay.com/fonts/Inter/InterVariable-latin.woff2",ie=300;let B=null;function le(){if(B||typeof FontFace>"u"||!document.fonts)return;const e=new FontFace(H,`url(${se}) format("woff2")`,{weight:"400 700",display:"swap"});document.fonts.add(e),B=e.load().catch(t=>{console.error("[Alma InPage] Failed to load the font:",t)})}function de(){return Promise.race([B,new Promise(e=>setTimeout(e,ie))])}const W={fr:{modal:{closeModalMessage:"Voulez-vous vraiment quitter la page de paiement ?",closeModalButtonHover:"Abandonner le paiement avec Alma"},embedded:{total:"Total",fees:e=>`Dont ${e} de frais à payer aujourd'hui.`,offeredFees:"Les frais de paiement sont offerts",payButton:e=>`Payer ${e}`,noPlanError:"Une erreur est survenue, aucun échéancier n'est disponible, merci de réessayer.",deferredCaptureExplanation:"Vos prélèvements commenceront lorsque nous aurons validé votre commande.",deferredFirstInstallment:"Au traitement de la commande",deferredMonth:e=>`${e} mois après`}},en:{modal:{closeModalMessage:"Do you really want to leave the checkout page?",closeModalButtonHover:"Cancel the payment with Alma"},embedded:{total:"Total",fees:e=>`Including ${e} of fees to be paid today.`,offeredFees:"Payment fees are free",payButton:e=>`Pay ${e}`,noPlanError:"An error has occurred, no payment schedule is available, please try again.",deferredCaptureExplanation:"Your direct debits will start as soon as we have validated your order.",deferredFirstInstallment:"When processing the order",deferredMonth:e=>`${e} month after`}},de:{modal:{closeModalMessage:"Möchten Sie die Zahlungsseite wirklich verlassen?",closeModalButtonHover:"Zahlung mit Alma abbrechen"},embedded:{total:"Gesamtbetrag",fees:e=>`Davon ${e} Gebühren, die heute bezahlt werden müssen.`,offeredFees:"Die Zahlungsgebühren sind erlassen",payButton:e=>`${e} zahlen`,noPlanError:"Es ist ein Fehler aufgetreten, es ist kein Zahlungsplan verfügbar. Bitte versuchen Sie es erneut.",deferredCaptureExplanation:"Ihre Abbuchungen beginnen, sobald wir Ihre Bestellung freigegeben haben.",deferredFirstInstallment:"Bei der Bearbeitung der Bestellung",deferredMonth:e=>e===1?`${e} Monat später`:`${e} Monate später`}},it:{modal:{closeModalMessage:"Vuoi davvero lasciare la pagina di pagamento?",closeModalButtonHover:"Annullare il pagamento con Alma"},embedded:{total:"Totale",fees:e=>`Inclusa la commissione di ${e} per il pagamento rateale.`,offeredFees:"Nessuna commissione di pagamento",payButton:e=>`Paga ${e}`,noPlanError:"Si è verificato un errore, non è disponibile nessun piano di pagamento, riprovare.",deferredCaptureExplanation:"Gli addebiti diretti inizieranno non appena avremo convalidato l'ordine.",deferredFirstInstallment:"Elaborazione dell'ordine",deferredMonth:e=>e===1?`${e} mese dopo`:`${e} mesi dopo`}},es:{modal:{closeModalMessage:"¿De verdad quieres salir de la página de pago?",closeModalButtonHover:"Cancelar el pago con Alma"},embedded:{total:"Total",fees:e=>`De los cuales ${e} son gastos administrativos.`,offeredFees:"Las comisiones de pago son gratuitas",payButton:e=>`Pagar ${e}`,noPlanError:"Se ha producido un error, inténtelo de nuevo.",deferredCaptureExplanation:"La domiciliación bancaria se iniciará en cuanto hayamos validado tu pedido.",deferredFirstInstallment:"Al procesarse el pedido",deferredMonth:e=>e===1?`${e} mes después`:`${e} meses después`}},nl:{modal:{closeModalMessage:"Weet je zeker dat je de betaalpagina wilt verlaten?",closeModalButtonHover:"Annuleer betaling met Alma"},embedded:{total:"Totaal",fees:e=>`Waarvan ${e} kosten die vandaag moeten worden betaald.`,offeredFees:"Geen extra kosten",payButton:e=>`Betaal ${e}`,noPlanError:"Er is een fout opgetreden, er is geen betaalschema beschikbaar, probeer het opnieuw.",deferredCaptureExplanation:"Uw automatische incasso's beginnen zodra we uw bestelling hebben gevalideerd.",deferredFirstInstallment:"Op het moment dat de bestelling wordt verwerkt",deferredMonth:e=>`${e} maand na`}},pt:{modal:{closeModalMessage:"Quer mesmo sair da página de pagamento?",closeModalButtonHover:"Cancelar o pagamento com a Alma"},embedded:{total:"Total",fees:e=>`Do qual ${e} deve ser pago hoje.`,offeredFees:"As despesas de pagamento são gratuitas",payButton:e=>`Pagar ${e}`,noPlanError:"Ocorreu um erro, não existe nenhum plano de pagamento disponível, tente novamente.",deferredCaptureExplanation:"Os seus débitos diretos começarão assim que tivermos validado a sua encomenda.",deferredFirstInstallment:"Processamento de encomendas",deferredMonth:e=>e===1?`${e} mês seguinte`:`${e} meses seguintes`}}};function Y(e){return Object.keys(W).includes(e)}function L(e){const t=String(e??"FR").toLowerCase();if(Y(t))return t;const n=navigator.language.split("-")[0];return Y(n)?n:"en"}function k(e){return W[L(e)]}const X=`
150
+ https://docs.almapay.com/docs/integration-in-page`,t);return{success:a.return_url,failure:a.failure_return_url}}).catch(a=>(console.error("[Alma InPage] Failed to fetch payment return URLs:",a),{success:void 0,failure:void 0}))}function ie(e,t,n,a){return F(t,a)+"/"+e+n}function P(){const e=ae.match(/\d+\.\d+\.\d+/);return e?e[0]:"2.0.0"}let T=0,x=null;function se(e,t,n,a,o){x=n,document.getElementById(`${r}-wrapper`)&&I(!1),T=window.scrollY,document.body.classList.add("alma-fixed-body"),document.body.scroll(0,T);const l=de(),m=ce(),p=ue(),i=me(),f=V(a),s=pe(e,t,o);return document.body.appendChild(l),l.appendChild(m),m.appendChild(p),m.appendChild(i),i.appendChild(f),i.appendChild(s),l.classList.add(`${r}-fadeIn`),i.classList.add(`${r}-slideIn`),s.focus(),s}function le(e){x=e;const t=document.getElementById(`${r}-close`);t&&(t.title=e.closeModalButtonHover)}function I(e=!0,t){const n=document.getElementById(`${r}-wrapper`);if(n&&(!e||confirm((x==null?void 0:x.closeModalMessage)??"Are you sure you want to leave the payment page?"))){const a=document.getElementById(`${r}-wrapper`),o=document.getElementById(`${r}-body`);a==null||a.classList.add(`${r}-fadeOut`),o==null||o.classList.add(`${r}-slideOut`),window.setTimeout(()=>{document.body.classList.remove("alma-fixed-body"),document.body.scroll(0,T),n.remove(),t&&t()},300)}}function de(){const e=document.createElement("style");e.innerHTML=te;const t=document.createElement("div");return t.id=`${r}-wrapper`,t.role="dialog",t.ariaModal="true",t.appendChild(e),t}function ce(){const e=document.createElement("div");return e.id=`${r}-element`,e}function ue(){const e=document.createElement("div");return e.id=`${r}-background`,e}function me(){const e=document.createElement("div");return e.id=`${r}-body`,e}function pe(e,t,n){const a=new URL(ie(e,t,W.modal,n));a.searchParams.append("inPageVersion",P());const o=document.createElement("iframe");return o.id=`${r}-iframe`,o.setAttribute("allow","camera *; microphone *; geolocation *; clipboard-read *; clipboard-write *; gyroscope *; accelerometer *; magnetometer *; ch-ua-platform-version *; ch-ua-model *; ch-ua-full-version *; payment"),o.src=a.toString(),o.title="Alma",o}function V(e){const t=document.createElement("img");return t.id=`${r}-close`,t.title=(x==null?void 0:x.closeModalButtonHover)||"Close the alma modal (you'll lose your data)",t.onclick=()=>I(!0,e),t.onkeyup=n=>{n.key==="Enter"&&I(!1,e)},t.src=ne,t.tabIndex=0,t}function fe(){const e=document.getElementById(`${r}-close`);e==null||e.remove()}function he(e,t,n,a){const o=[],l=i=>{var f;if(i.origin!==F(e,t)||i.data.from!=="checkout"||!i.source||i.source!==((f=n())==null?void 0:f.contentWindow))return!1;i.data.type==="in_page_status"?o.filter(s=>s&&s.eventName===i.data.payload).forEach(s=>{s&&s.callback()}):i.data.type==="locale"?typeof i.data.payload=="string"&&a(i.data.payload):i.data.type!=="embedded_height"&&i.data.type!=="translations"&&console.warn("Unknown message type:",i.data.type)};window.addEventListener("message",l,!1);function m(){window.removeEventListener("message",l,!1)}function p(i,f,s){const b=o.findIndex(w=>w&&w.eventName===i&&w.callerName===f);b!==-1&&(o[b]=null),o.push({eventName:i,callerName:f,callback:s})}return{onInPageStatusChanged:p,unsubscribe:m}}class G extends Error{constructor(){super(...arguments);ee(this,"name","BlockedRequestError")}}async function ge(e,t){const n=await fetch(`${N(t)}/v2/payments/eligibility`,{method:"POST",headers:{Authorization:`Alma-Merchant-Auth ${e.merchantId}`,"Content-Type":"application/json","X-Alma-Agent":`Alma Checkout - InPage/${P()}`},body:JSON.stringify({purchase_amount:e.amountInCents,queries:[{installments_count:e.installmentsCount,deferred_days:e.deferredDays,deferred_months:e.deferredMonths}],capture_method:e.captureMethod,locale:e.locale,...e.billingCountry&&{billing_address:{country:e.billingCountry}}})}).catch(o=>{throw new G(String(o))});if(!n.ok)throw new Error(`Eligibility request failed with status ${n.status}`);return(await n.json()).find(o=>o.eligible&&o.deferred_days===e.deferredDays&&o.deferred_months===e.deferredMonths)??null}const H={fr:{modal:{closeModalMessage:"Voulez-vous vraiment quitter la page de paiement ?",closeModalButtonHover:"Abandonner le paiement avec Alma"},embedded:{total:"Total",customerFees:"Dont frais",feesWithTaeg:(e,t)=>`${e} (TAEG ${t})`,payButton:e=>`Payer ${e}`,noPlanError:"Une erreur est survenue, aucun échéancier n'est disponible, merci de réessayer.",deferredCaptureExplanation:"Vos prélèvements commenceront lorsque nous aurons validé votre commande.",deferredFirstInstallment:"Au traitement de la commande",deferredMonth:e=>`${e} mois après`}},en:{modal:{closeModalMessage:"Do you really want to leave the checkout page?",closeModalButtonHover:"Cancel the payment with Alma"},embedded:{total:"Total",customerFees:"Including fees",feesWithTaeg:(e,t)=>`${e} (APR ${t})`,payButton:e=>`Pay ${e}`,noPlanError:"An error has occurred, no payment schedule is available, please try again.",deferredCaptureExplanation:"Your direct debits will start as soon as we have validated your order.",deferredFirstInstallment:"When processing the order",deferredMonth:e=>`${e} month after`}},de:{modal:{closeModalMessage:"Möchten Sie die Zahlungsseite wirklich verlassen?",closeModalButtonHover:"Zahlung mit Alma abbrechen"},embedded:{total:"Gesamtbetrag",customerFees:"Davon Kosten",feesWithTaeg:(e,t)=>`${e} (effektiver Jahreszins ${t})`,payButton:e=>`${e} zahlen`,noPlanError:"Es ist ein Fehler aufgetreten, es ist kein Zahlungsplan verfügbar. Bitte versuchen Sie es erneut.",deferredCaptureExplanation:"Ihre Abbuchungen beginnen, sobald wir Ihre Bestellung freigegeben haben.",deferredFirstInstallment:"Bei der Bearbeitung der Bestellung",deferredMonth:e=>e===1?`${e} Monat später`:`${e} Monate später`}},it:{modal:{closeModalMessage:"Vuoi davvero lasciare la pagina di pagamento?",closeModalButtonHover:"Annullare il pagamento con Alma"},embedded:{total:"Totale",customerFees:"Di cui commissioni",feesWithTaeg:(e,t)=>`${e} (TAEG ${t})`,payButton:e=>`Paga ${e}`,noPlanError:"Si è verificato un errore, non è disponibile nessun piano di pagamento, riprovare.",deferredCaptureExplanation:"Gli addebiti diretti inizieranno non appena avremo convalidato l'ordine.",deferredFirstInstallment:"Elaborazione dell'ordine",deferredMonth:e=>e===1?`${e} mese dopo`:`${e} mesi dopo`}},es:{modal:{closeModalMessage:"¿De verdad quieres salir de la página de pago?",closeModalButtonHover:"Cancelar el pago con Alma"},embedded:{total:"Total",customerFees:"De los cuales, los costes administrativos",feesWithTaeg:(e,t)=>`${e} (TAE ${t})`,payButton:e=>`Pagar ${e}`,noPlanError:"Se ha producido un error, inténtelo de nuevo.",deferredCaptureExplanation:"La domiciliación bancaria se iniciará en cuanto hayamos validado tu pedido.",deferredFirstInstallment:"Al procesarse el pedido",deferredMonth:e=>e===1?`${e} mes después`:`${e} meses después`}},nl:{modal:{closeModalMessage:"Weet je zeker dat je de betaalpagina wilt verlaten?",closeModalButtonHover:"Annuleer betaling met Alma"},embedded:{total:"Totaal",customerFees:"Waarvan kosten",feesWithTaeg:(e,t)=>`${e} (JKP ${t})`,payButton:e=>`Betaal ${e}`,noPlanError:"Er is een fout opgetreden, er is geen betaalschema beschikbaar, probeer het opnieuw.",deferredCaptureExplanation:"Uw automatische incasso's beginnen zodra we uw bestelling hebben gevalideerd.",deferredFirstInstallment:"Op het moment dat de bestelling wordt verwerkt",deferredMonth:e=>`${e} maand na`}},pt:{modal:{closeModalMessage:"Quer mesmo sair da página de pagamento?",closeModalButtonHover:"Cancelar o pagamento com a Alma"},embedded:{total:"Total",customerFees:"Incluindo encargos",feesWithTaeg:(e,t)=>`${e} (TAEG ${t})`,payButton:e=>`Pagar ${e}`,noPlanError:"Ocorreu um erro, não existe nenhum plano de pagamento disponível, tente novamente.",deferredCaptureExplanation:"Os seus débitos diretos começarão assim que tivermos validado a sua encomenda.",deferredFirstInstallment:"Processamento de encomendas",deferredMonth:e=>e===1?`${e} mês seguinte`:`${e} meses seguintes`}}};function Y(e){return Object.keys(H).includes(e)}function k(e){const t=String(e??"").toLowerCase();if(Y(t))return t;const n=navigator.language.split("-")[0].toLowerCase();return Y(n)?n:"en"}function A(e){return H[k(e)]}function ye(e,t){if(!e.isConnected)return;const{environment:n,merchantId:a,selector:o,amountInCents:l,installmentsCount:m,deferredDays:p,deferredMonths:i,locale:f,captureMethod:s,billingCountry:b,style:w,onIntegratedPayButtonClicked:v,checkoutUrl:$}=t,d=new URL(F(n??"PROD",$)+W.embedded);d.searchParams.append("merchantId",a),d.searchParams.append("amountInCents",l.toString()),d.searchParams.append("installmentsCount",m.toString()),p&&d.searchParams.append("deferredDays",p.toString()),i&&d.searchParams.append("deferredMonths",i.toString()),d.searchParams.append("locale",k(f).toUpperCase()),d.searchParams.append("captureMethod",s??"automatic"),b!==void 0&&d.searchParams.append("billingCountry",b),d.searchParams.append("domElement",o),d.searchParams.append("style",JSON.stringify(w||null)),d.searchParams.append("inPageVersion",P()),v&&d.searchParams.append("showPayButton","true"),d.searchParams.append("fallback","true");const c=document.createElement("iframe");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 C(h){if(!c.isConnected){window.removeEventListener("message",C);return}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"&&(v==null||v()))}),c}const X="Alma Inter",be="https://cdn.almapay.com/fonts/Inter/InterVariable-latin.woff2",ve=300;let O=null;function we(){if(O||typeof FontFace>"u"||!document.fonts)return;const e=new FontFace(X,`url(${be}) format("woff2")`,{weight:"400 700",display:"swap"});document.fonts.add(e),O=e.load().catch(t=>{console.error("[Alma InPage] Failed to load the font:",t)})}function Ce(){return Promise.race([O,new Promise(e=>setTimeout(e,ve))])}const J=`
9
151
  /* The merchant's rules matching the host win over :host, unless :host is !important */
10
152
  :host {
11
153
  padding: 0 !important;
@@ -26,7 +168,7 @@ https://docs.almapay.com/docs/integration-in-page`,t);return{success:a.return_ur
26
168
  flex-direction: column;
27
169
  gap: 10px;
28
170
  margin: 8px 16px;
29
- font-family: "${H}", sans-serif;
171
+ font-family: "${X}", sans-serif;
30
172
  font-size: 14px;
31
173
  line-height: 19px;
32
174
  letter-spacing: -0.6px;
@@ -149,147 +291,5 @@ https://docs.almapay.com/docs/integration-in-page`,t);return{success:a.return_ur
149
291
  animation: none;
150
292
  }
151
293
  }
152
- `;function p(e,t,n){const a=document.createElement(e);return t&&(a.className=t),n!==void 0&&(a.textContent=n),a}function M(e,t){const n=p("span","skeleton");n.style.width=`${e}px`;const a=p("span",t);return a.append(n),a}function F(e,t){t&&typeof t=="object"&&Object.assign(e.style,t)}function O(e){const t=p("div","container fadeIn");return F(t,e.containerStyle),t}let A=null;function T(e,t){"adoptedStyleSheets"in e&&"replaceSync"in CSSStyleSheet.prototype?(A||(A=new CSSStyleSheet,A.replaceSync(X)),e.adoptedStyleSheets=[A],e.replaceChildren(t)):e.replaceChildren(p("style",void 0,X),t)}function D(e,t){var o;const n=e.host.clientWidth;(o=e.querySelector(".button"))==null||o.classList.toggle("fitContent",n>=769);const a=new Intl.DateTimeFormat(L(t),{day:"numeric",month:n>400?"long":"short"}).format;e.querySelectorAll(".date").forEach(i=>{i.textContent=a(Number(i.dataset.dueDate))})}function Z(e){return e>4}function ce(e,t){const n=O(t);n.classList.add("delayed"),T(e,n);const a=k(t.locale).embedded;if(t.isDeferredCapture&&n.append(p("div","bold",a.deferredCaptureExplanation)),!Z(t.installmentsCount)){const o=p("div","installments");for(let d=0;d<t.installmentsCount;d++){const u=p("div","installment");u.append(M(90,"label"),M(60)),o.append(u)}const i=p("div","total"),s=p("div","totalAmount"),l=p("div","bold");l.append(M(60)),s.append(l,p("div","fees"," ")),i.append(M(40),s),o.append(i),n.append(o)}if(t.onPayButtonClicked){const o=p("button","button skeletonButton"," ");o.disabled=!0,F(o,t.buttonStyle),n.append(o)}D(e,t.locale)}function ue(e,t,n){const a=O(n),o=L(n.locale),i=k(n.locale).embedded,s=u=>new Intl.NumberFormat(o,{style:"currency",currency:"EUR"}).format(u/100);n.isDeferredCapture&&a.append(p("div","bold",i.deferredCaptureExplanation));const l=t.customer_fee+t.customer_interest,d=t.purchase_amount+l;if(!Z(n.installmentsCount)){const u=p("div","installments");u.dataset.testid="installments",t.payment_plan.forEach((y,c)=>{const f=p("div","installment");f.dataset.testid=`installment-${c}`;const v=p("span","label");n.isDeferredCapture?v.textContent=c===0?i.deferredFirstInstallment:i.deferredMonth(c):(v.classList.add("date"),v.dataset.dueDate=String(y.due_date*1e3)),f.append(v,p("span",void 0,s(y.purchase_amount+y.customer_fee+y.customer_interest))),u.append(f)});const m=p("div","total"),x=p("div","fees");if(l===0){const y=p("span",void 0,"🎁");y.setAttribute("aria-hidden","true"),x.append(`${i.offeredFees} `,y)}else x.textContent=i.fees(s(l));const b=p("div","totalAmount");b.append(p("div","bold",s(d)),x),m.append(p("span","bold",i.total),b),u.append(m),a.append(u)}if(n.onPayButtonClicked){const u=p("button","button",i.payButton(s(d)));u.type="button",F(u,n.buttonStyle),u.onclick=()=>{var m;return(m=n.onPayButtonClicked)==null?void 0:m.call(n)},a.append(u)}T(e,a),D(e,n.locale)}function q(e,t){const n=O(t);n.classList.add("error"),n.textContent=k(t.locale).embedded.noPlanError,T(e,n)}function me(e){var K;const{environment:t,merchantId:n,selector:a,amountInCents:o,installmentsCount:i,deferredDays:s,deferredMonths:l,locale:d,captureMethod:u,style:m,onIntegratedPayButtonClicked:x}=e;if(!a)return j(),!1;const b=C=>parseInt(String(C),10),y=b(i),c=document.createElement("div");c.id=`alma-embedded-${a.replace("#","")}`,c.style.width="100%",c.style.display=y>4&&!x?"none":"flow-root";const f=c.attachShadow({mode:"open"});(K=U(a))==null||K.replaceChildren(c);const v={locale:d,installmentsCount:y,isDeferredCapture:u==="manual",onPayButtonClicked:x,containerStyle:m==null?void 0:m.embedded,buttonStyle:m==null?void 0:m.embeddedButton};le(),ce(f,v);const w=new ResizeObserver(()=>{c.isConnected?D(f,d):w.disconnect()});return w.observe(c),oe({merchantId:n,amountInCents:b(o),installmentsCount:y,deferredDays:b(s)||0,deferredMonths:b(l)||0,captureMethod:u??"automatic",locale:d??"FR"},t??"PROD").then(async C=>{await de(),C?ue(f,C,v):q(f,v)}).catch(C=>{console.error("[Alma InPage] Failed to display the payment plan:",C),C instanceof V?re(c,e):q(f,v)}),!0}const R={orange:"#FA5022",backdrop:"#6C6C6C",white:"#FEFEFE"},pe=`
153
- #${r}-element {
154
- position: fixed;
155
- z-index: 10337;
156
- top: 0;
157
- left: 0;
158
- bottom: 0;
159
- right: 0;
160
- display: flex;
161
- align-items: center;
162
- justify-content: center;
163
- z-index: 9999;
164
- }
165
-
166
- #${r}-background {
167
- background: ${R.backdrop};
168
- position: absolute;
169
- width: 100vw;
170
- height: 100vh;
171
- opacity: 0.8;
172
- }
173
-
174
- #${r}-body {
175
- background: ${R.white};
176
- width: 100%;
177
- max-width: 700px;
178
- height: calc(100% - 32px);
179
- bottom: 0;
180
- position: absolute;
181
- border-radius: 0;
182
- box-shadow: 0px 0px 12px 4px rgba(41, 15, 8, 0.04);
183
- border-radius: 20px 20px 0 0;
184
- overflow: hidden;
185
- }
186
-
187
- #${r}-close {
188
- position: absolute;
189
- right: 0;
190
- top: 0;
191
- cursor: pointer;
192
- width: 72px;
193
- height: 72px;
194
- }
195
-
196
- #${r}-close:hover, #${r}-close:focus-visible {
197
- border-radius: 50%;
198
- outline: 1px solid ${R.orange};
199
- outline-offset: -16px;
200
- }
201
-
202
- #${r}-logo {
203
- position: absolute;
204
- left: 24px;
205
- top: 16px;
206
- }
207
-
208
- #${r}-iframe {
209
- width: 100%;
210
- height: 100%;
211
- border: 0;
212
- }
213
-
214
- .alma-fixed-body {
215
- position: fixed;
216
- width: 100%;
217
- overflow: auto;
218
- height: 100%;
219
- }
220
-
221
- .${r}-slideIn {
222
- animation: ${r}-slideIn 300ms ease-out;
223
- animation-iteration-count: 1;
224
- }
225
-
226
- .${r}-fadeIn {
227
- animation: ${r}-fadeIn 300ms;
228
- animation-iteration-count: 1;
229
- }
230
-
231
- .${r}-slideOut {
232
- animation: ${r}-slideOut 300ms ease-in;
233
- animation-iteration-count: 1;
234
- }
235
-
236
- .${r}-fadeOut {
237
- animation: ${r}-fadeOut 300ms;
238
- animation-iteration-count: 1;
239
- }
240
-
241
- @media (min-width: 600px) {
242
- #${r}-body {
243
- width: 80%;
244
- height: 80%;
245
- max-height: 700px;
246
- bottom: initial;
247
- border-radius: 20px;
248
- }
249
- }
250
-
251
- @keyframes ${r}-slideIn {
252
- from {
253
- transform: translateY(300px);
254
- }
255
-
256
- to {
257
- transform: translateY(0px);
258
- }
259
- }
260
-
261
- @keyframes ${r}-fadeIn {
262
- from {
263
- opacity: 0;
264
- visibility: hidden;
265
- }
266
-
267
- to {
268
- opacity: 1;
269
- visibility: visible;
270
- }
271
- }
272
-
273
- @keyframes ${r}-slideOut {
274
- from {
275
- transform: translateY(0px);
276
- }
277
-
278
- to {
279
- transform: translateY(300px);
280
- }
281
- }
282
-
283
- @keyframes ${r}-fadeOut {
284
- from {
285
- opacity: 1;
286
- visibility: visible;
287
- }
288
-
289
- to {
290
- opacity: 0;
291
- visibility: hidden;
292
- }
293
- }
294
- `,fe="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";let z=0,E=null;function he(e,t,n,a,o){E=n,document.getElementById(`${r}-wrapper`)&&I(!1),z=window.scrollY,document.body.classList.add("alma-fixed-body"),document.body.scroll(0,z);const i=ge(),s=ye(),l=be(),d=ve(),u=J(a),m=we(e,t,o);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()}function I(e=!0,t){const n=document.getElementById(`${r}-wrapper`);if(n&&(!e||confirm((E==null?void 0:E.closeModalMessage)??"Are you sure you want to leave the payment page?"))){const a=document.getElementById(`${r}-wrapper`),o=document.getElementById(`${r}-body`);a==null||a.classList.add(`${r}-fadeOut`),o==null||o.classList.add(`${r}-slideOut`),window.setTimeout(()=>{document.body.classList.remove("alma-fixed-body"),document.body.scroll(0,z),n.remove(),t&&t()},300)}}function ge(){const e=document.createElement("style");e.innerHTML=pe;const t=document.createElement("div");return t.id=`${r}-wrapper`,t.role="dialog",t.ariaModal="true",t.appendChild(e),t}function ye(){const e=document.createElement("div");return e.id=`${r}-element`,e}function be(){const e=document.createElement("div");return e.id=`${r}-background`,e}function ve(){const e=document.createElement("div");return e.id=`${r}-body`,e}function we(e,t,n){const a=new URL(ne(e,t,G.modal,n));a.searchParams.append("inPageVersion",S());const o=document.createElement("iframe");return o.id=`${r}-iframe`,o.setAttribute("allow","camera *; microphone *; geolocation *; clipboard-read *; clipboard-write *; gyroscope *; accelerometer *; magnetometer *; ch-ua-platform-version *; ch-ua-model *; ch-ua-full-version *; payment"),o.src=a.toString(),o.title="Alma",o}function J(e){const t=document.createElement("img");return t.id=`${r}-close`,t.title=(E==null?void 0:E.closeModalButtonHover)||"Close the alma modal (you'll lose your data)",t.onclick=()=>I(!0,e),t.onkeyup=n=>{n.key==="Enter"&&I(!1,e)},t.src=fe,t.tabIndex=0,t}function xe(){const e=document.getElementById(`${r}-close`);e==null||e.remove()}function Ee(e,t,n){const{paymentId:a,onPaymentRejected:o,onPaymentSucceeded:i,onUserCloseModal:s}=e;if(typeof a!="string"||a.trim()===""){const d=_(`startPayment() requires a non-empty "paymentId" (received: ${JSON.stringify(a)}). Make sure the payment has been created and its id retrieved before calling startPayment().`,t.getEnvironment());throw new Error(d)}const l={success:null,failure:null};te(a,t.getEnvironment()).then(d=>{l.success=d.success,l.failure=d.failure}),he(a,t.getEnvironment(),t.getTranslations(),s,t.getCheckoutUrl()),n("3ds_started","start-payment",xe),n("3ds_failed","start-payment",()=>{const d=document.getElementById(`${r}-body`);d&&d.appendChild(J(s))}),n("trigger_success_callback","start-payment",()=>{Q(i,l.success)}),n("trigger_reject_callback","start-payment",()=>{Q(o,l.failure)})}function Q(e,t){I(!1),e?e():t&&window.location.assign(t)}function Ce(e,t){const n=e.getEmbeddedSelector();if(I(!1),t(),!n)return;const a=U(n);e.setEmbeddedSelector(null),a&&a.firstChild&&a.removeChild(a.firstChild)}function $e(e){const t=g(e.environment,e.checkoutUrl);t.setTranslations(k(e.locale).modal);const{onInPageStatusChanged:n,unsubscribe:a}=ae(t.getEnvironment(),e.checkoutUrl);return me(e)&&t.setEmbeddedSelector(e.selector),{startPayment:i=>Ee(i,t,n),unmount:()=>Ce(t,a)}}h.initialize=$e,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
294
+ `;function u(e,t,n){const a=document.createElement(e);return t&&(a.className=t),n!==void 0&&(a.textContent=n),a}function _(e,t){const n=u("span","skeleton");n.style.width=`${e}px`;const a=u("span",t);return a.append(n),a}function D(e,t){t&&typeof t=="object"&&Object.assign(e.style,t)}function z(e){const t=u("div","container fadeIn");return D(t,e.containerStyle),t}let S=null;function R(e,t){"adoptedStyleSheets"in e&&"replaceSync"in CSSStyleSheet.prototype?(S||(S=new CSSStyleSheet,S.replaceSync(J)),e.adoptedStyleSheets=[S],e.replaceChildren(t)):e.replaceChildren(u("style",void 0,J),t)}function U(e,t){var o;const n=e.host.clientWidth;(o=e.querySelector(".button"))==null||o.classList.toggle("fitContent",n>=769);const a=new Intl.DateTimeFormat(k(t),{day:"numeric",month:n>400?"long":"short"}).format;e.querySelectorAll(".date").forEach(l=>{l.textContent=a(Number(l.dataset.dueDate))})}function Z(e){return e>4}function xe(e,t){const n=z(t);n.classList.add("delayed"),R(e,n);const a=A(t.locale).embedded;if(t.isDeferredCapture&&n.append(u("div","bold",a.deferredCaptureExplanation)),!Z(t.installmentsCount)){const o=u("div","installments");for(let i=0;i<t.installmentsCount;i++){const f=u("div","installment");f.append(_(90,"label"),_(60)),o.append(f)}const l=u("div","total"),m=u("div","totalAmount"),p=u("div","bold");p.append(_(60)),m.append(p,u("div","fees"," ")),l.append(_(40),m),o.append(l),n.append(o)}if(t.onPayButtonClicked){const o=u("button","button skeletonButton"," ");o.disabled=!0,D(o,t.buttonStyle),n.append(o)}U(e,t.locale)}function $e(e,t,n){const a=z(n),o=k(n.locale),l=A(n.locale).embedded,m=s=>new Intl.NumberFormat(o,{style:"currency",currency:"EUR"}).format(s/100),p=s=>new Intl.NumberFormat(o,{style:"percent",minimumFractionDigits:2,maximumFractionDigits:2}).format(s/1e4);n.isDeferredCapture&&a.append(u("div","bold",l.deferredCaptureExplanation));const i=t.customer_fee+t.customer_interest,f=t.purchase_amount+i;if(!Z(n.installmentsCount)){const s=u("div","installments");s.dataset.testid="installments",t.payment_plan.forEach((c,C)=>{const h=u("div","installment");h.dataset.testid=`installment-${C}`;const E=u("span","label");n.isDeferredCapture?E.textContent=C===0?l.deferredFirstInstallment:l.deferredMonth(C):(E.classList.add("date"),E.dataset.dueDate=String(c.due_date*1e3)),h.append(E,u("span",void 0,m(c.purchase_amount+c.customer_fee+c.customer_interest))),s.append(h)});const b=u("div","total"),w=u("div","fees"),v=m(i),$=typeof t.annual_interest_rate=="number"?p(t.annual_interest_rate):null;w.textContent=`${l.customerFees} ${$===null?v:l.feesWithTaeg(v,$)}`;const d=u("div","totalAmount");d.append(u("div","bold",m(f)),w),b.append(u("span","bold",l.total),d),s.append(b),a.append(s)}if(n.onPayButtonClicked){const s=u("button","button",l.payButton(m(f)));s.type="button",D(s,n.buttonStyle),s.onclick=()=>{var b;return(b=n.onPayButtonClicked)==null?void 0:b.call(n)},a.append(s)}R(e,a),U(e,n.locale)}function K(e,t){const n=z(t);n.classList.add("error"),n.textContent=A(t.locale).embedded.noPlanError,R(e,n)}function Ee(e){var Q;const{environment:t,merchantId:n,selector:a,amountInCents:o,installmentsCount:l,deferredDays:m,deferredMonths:p,locale:i,captureMethod:f,style:s,billingCountry:b,onIntegratedPayButtonClicked:w}=e;if(!a){j();return}const v=M=>parseInt(String(M),10),$=v(l),d=document.createElement("div");d.id=`alma-embedded-${a.replace("#","")}`,d.style.width="100%",d.style.display=$>4&&!w?"none":"flow-root";const c=d.attachShadow({mode:"open"});(Q=oe(a))==null||Q.replaceChildren(d);let C=d;const h={locale:i,installmentsCount:$,isDeferredCapture:f==="manual",onPayButtonClicked:w,containerStyle:s==null?void 0:s.embedded,buttonStyle:s==null?void 0:s.embeddedButton};we(),xe(c,h);const E=new ResizeObserver(()=>{d.isConnected?U(c,i):E.disconnect()});return E.observe(d),ge({merchantId:n,amountInCents:v(o),installmentsCount:$,deferredDays:v(m)||0,deferredMonths:v(p)||0,captureMethod:f??"automatic",locale:k(i).toUpperCase(),billingCountry:b},t??"PROD").then(async M=>{await Ce(),M?$e(c,M,h):K(c,h)}).catch(M=>{console.error("[Alma InPage] Failed to display the payment plan:",M),M instanceof G?C=ye(d,e)??C:K(c,h)}),()=>C.remove()}function Me(e,t,n){const{paymentId:a,onPaymentRejected:o,onPaymentSucceeded:l,onUserCloseModal:m}=e;if(typeof a!="string"||a.trim()===""){const i=L(`startPayment() requires a non-empty "paymentId" (received: ${JSON.stringify(a)}). Make sure the payment has been created and its id retrieved before calling startPayment().`,t.getEnvironment());throw new Error(i)}const p={success:null,failure:null};re(a,t.getEnvironment()).then(i=>{p.success=i.success,p.failure=i.failure}),t.setPaymentModal(se(a,t.getEnvironment(),t.getTranslations(),m,t.getCheckoutUrl())),n("3ds_started","start-payment",fe),n("3ds_failed","start-payment",()=>{const i=document.getElementById(`${r}-body`);i&&i.appendChild(V(m))}),n("trigger_success_callback","start-payment",()=>{q(l,p.success)}),n("trigger_reject_callback","start-payment",()=>{q(o,p.failure)})}function q(e,t){I(!1),e?e():t&&window.location.assign(t)}function Ie(e,t,n){var a;(a=e.getPaymentModal())!=null&&a.isConnected&&I(!1),t(),n==null||n()}function ke(e){const t=y(e.environment,e.checkoutUrl);t.setTranslations(A(e.locale).modal);const{onInPageStatusChanged:n,unsubscribe:a}=he(t.getEnvironment(),e.checkoutUrl,t.getPaymentModal,l=>le(A(l).modal)),o=Ee(e);return{startPayment:l=>Me(l,t,n),unmount:()=>Ie(t,a,o)}}g.initialize=ke,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
295
295
  //# sourceMappingURL=index.umd.js.map