(()=>{/*!
 * Copyright 2024-2025 Simply.IN Sp. z o.o.
 *
 * NOTICE OF LICENSE
 * Licensed under the EUPL-1.2 or later.
 * You may not use this work except in compliance with the Licence.
 * Copy of the Licence is available at: https://joinup.ec.europa.eu/software/page/eupl
 * It is bundled with this package in the file LICENSE.txt
 *
 * @author    Simply.IN Sp. z o.o.
 * @copyright 2024-2025 Simply.IN Sp. z o.o.
 * @license   https://joinup.ec.europa.eu/software/page/eupl
 */var e=window.jQuery,s=window.simplyin,d=".simplyin-retry-form",u=".simplyin-retry-button",h="order-retry",f={PENDING:"Waiting for the bank to confirm your payment...",AWAITING_CONFIRMATION:"Confirm the payment in your banking app to finish."},p={BLIK_INVALID_CODE:"The BLIK code you entered was incorrect.",CARD_THREE_DS_FAILED:"Your bank did not confirm the card.",AMOUNT_LIMIT_EXCEEDED:"This payment exceeds an allowed transaction limit.",TRANSACTION_TIMEOUT:"The payment took too long and timed out."};e(function(){window.SimplyInPayment={errorMsgBlik:null,successMsgBlik:null,cc:null,successMsg:null,errorMsg:null,ott_corect:!1,blik_corect:!1,inputs:[],newImg:!1,card_interval:null,duplicated_card:null,confirmationSelector:"#payment-confirmation button",confirmationButton:function(){return document.querySelector(this.confirmationSelector)},ajaxToken:null,cartToken:null,_formInputsWired:!1,_retryRevealChecked:!1,wireFormInputs:function(){this._formInputsWired||(this._formInputsWired=!0,this.setupCardForm(),this.setupBlikInputs(),this.setupPaymentOptionChange(),this.setupBlikEvents())},init:function(){this.ajaxToken=s.ajax_token,this.cartToken=s.cart_token,this.inlinePaymentOptionLogo(),this.wireFormInputs(),this.bindPaymentMethodChecker(),this.autoSelectPayment()},initRetry:function(){document.querySelector(d)&&(this.ajaxToken=s.retry_ajax_token,this.cartToken=s.retry_cart_token,this.confirmationSelector=u,this.wireFormInputs(),this.bindGeneralConfirmationEvent())},initOrderConfirmation:function(){this.setupOrderStatusCheck(),this.initRetry()},inlinePaymentOptionLogo:function(){e('input[type="radio"][data-module-name^="simplyin"]').each(function(){let t=e(this).closest(".payment-option");if(!t.length)return;let n=t.find("label").first().css({display:"flex",alignItems:"center",gap:"8px"}),i=t.find('img[src*="/simplyin/views/img/"]').first();if(!i.length||(i.css({maxHeight:"20px",width:"auto"}),n.find("img").length))return;let a=i.closest("label");n.prepend(i),a.length&&!a.is(n)&&a.children().length===0&&a.text().trim()===""&&a.remove()})},bindGeneralConfirmationEvent:function(){let t=this,n=t.confirmationButton();if(!n)return;let i=a=>{let o=e(".simplyin-payment-option:checked"),r=e("#simplyin-payment-error");if(!o.length)return a.preventDefault(),a.stopPropagation(),a.stopImmediatePropagation(),r&&(r.html(t.l("Please select a payment method")),r.fadeIn(),e(".simplyin-payment-option-item").addClass("select-method")),!1;r&&r.fadeOut()};n._simplyinGeneralHandler&&n.removeEventListener("click",n._simplyinGeneralHandler,{capture:!0}),n.addEventListener("click",i,{capture:!0}),n._simplyinGeneralHandler=i},unbindGeneralConfirmationEvent:function(){let t=this.confirmationButton();t&&t._simplyinGeneralHandler&&(t.removeEventListener("click",t._simplyinGeneralHandler,{capture:!0}),delete t._simplyinGeneralHandler)},bindPaymentMethodChecker:function(){let t=this;e(document).on("change","input[name=payment-option]",function(){if(e(this).data("module-name")&&e(this).data("module-name").startsWith("simplyin")){if(e(".simplyin-payment-option:checked").length==0)return t.bindGeneralConfirmationEvent(),!0}else return t.unbindGeneralConfirmationEvent(),!0})},l:function(t){return typeof s.labels<"u"&&s.labels[t]?s.labels[t]:t},setupCardForm:function(){let t=this;t.duplicated_card&&clearTimeout(t.duplicated_card),t.duplicated_card=setTimeout(function(){if(e('#simplyin-add-card-payment-method input[name="simplyin-payment-option"]').length&&e("#card-number").find("div").length==0){let n=e('#simplyin-add-card-payment-method input[name="simplyin-payment-option"]').data("iframe-url"),a=e('#simplyin-add-card-payment-method input[name="simplyin-payment-option"]').data("integrator-id"),o=n,r=document.createElement("script");r.src=o,r.onload=()=>t.initCardForm(a),document.head.appendChild(r),t.watchCardFocus()}},150)},watchCardFocus:function(){var t=this;this._cardFocusObserver&&this._cardFocusObserver.disconnect();var n=document.querySelectorAll("#card-holder, #card-number, #expiry-date, #verification-code");if(n.length){this._cardFocusObserver=new MutationObserver(function(){t.hideCardErrors()});for(var i=0;i<n.length;i++)this._cardFocusObserver.observe(n[i],{attributes:!0,attributeFilter:["class"],subtree:!0})}},hideCardErrors:function(){e(".ccIframe-component.has-focus").length&&e(this.errorMsg).hide()},initCardForm:function(t){try{this.cc=CCIframe({integratorId:t});let n={fonts:[{family:"Inter",src:"url(https://fonts.gstatic.com/s/inter/v18/UcCo3FwrK3iLTcviYwYZ8UA3.woff2) format('woff2')",style:"normal",weight:"100 900"}],styles:{base:{color:"rgba(0, 0, 0, 0.8)",fontFamily:"Inter",fontSize:"14px"}}};this.cc.createComponent("cardHolder","#card-holder",n),this.cc.createComponent("cardNumber","#card-number",n),this.cc.createComponent("cardExp","#expiry-date",n),this.cc.createComponent("cardCvv","#verification-code",n),this.successMsg="#card-success-message-1",this.errorMsg="#form-error-1"}catch{}},setupBlikInputs:function(){this.successMsgBlik="#blik-success-message-1",this.errorMsgBlik="#blik-form-error-1",this.inputs=".simplyin-blik-digit-input";let t=this;e(document).on("click",this.inputs,function(){e('input[name="simplyin-payment-option"][data-payment-type="blik"]').is(":checked")||e('input[name="simplyin-payment-option"][data-payment-type="blik"]').prop("checked",!0).trigger("change")}),e(document).on("input",this.inputs,function(){let n=e(this),i=e(t.inputs),a=i.index(this),o=n.val().replace(/\D/g,"");n.val(o.substring(0,1)),o&&a<i.length-1&&e(i[a+1]).focus()}),e(document).on("keydown",this.inputs,function(n){if(n.key==="Backspace"){let i=e(this),a=e(t.inputs),o=a.index(this);!i.val()&&o>0&&e(a[o-1]).focus()}}),e(document).on("paste",this.inputs,function(n){n.preventDefault();let i=e(t.inputs),a=e(this),o=i.index(this),r=(n.originalEvent.clipboardData||window.clipboardData).getData("text").replace(/\D/g,"");if(!r)return;[...r].slice(0,i.length).forEach((c,m)=>{e(i[m]).val(c)});let l=Math.min(r.length,i.length)-1;e(i[l]).focus(),e(i[i.length-1]).trigger("change")})},getBlikCode:function(){return e(this.inputs).map(function(){return e(this).val()}).get().join("")},checkBlikCode:function(){let t=this;return this.getBlikCode().length===6},setPaymentsTerm:function(t){let n=this,i=t.data("regulationsurl"),a=t.data("gdprurl"),o=t.data("payment-provider-name"),r=n.l("By paying, I accept the terms and [conditions] and [privacy policy] of %s");r=r.replace(/\[(.*?)\]/,`<a class="simplyin-payment-provider-url" href="${i}" target="_blank">$1</a>`),r=r.replace(/\[(.*?)\]/,`<a class="simplyin-payment-provider-url" href="${a}" target="_blank">$1</a>`),r=r.replace("%s",o),e(".simplyin-payment-provider-footer").html(`<p>${r}</p>`)},setupPaymentOptionChange:function(){let t=this;e(document).on("change","#simplyin-save-card",function(){e(this).is(":checked")?e(".simplyin-card-name").fadeIn():e(".simplyin-card-name").fadeOut()}),e(document).on("change",'input[name="simplyin-payment-option"]',n=>{let i=e(n.currentTarget),a=i.data("payment-type"),o={action:"selectPaymentMethod",ajax:1,ajax_token:t.ajaxToken,cart_token:t.cartToken,payment_id:i.val(),payment_type:a,payment_provider:i.data("payment-provider-name"),provider_image:i.data("provider-image"),logo:i.data("logo")};t.setPaymentsTerm(i),a==="card"?(o.card_name=i.data("card-name"),o.last_digits=i.data("last-digits"),o.card_provider=i.data("card-provider"),this.unbindCardConfirmationEvents(),this.unbindBlikConfirmationEvents()):a==="blik"?(this.unbindCardConfirmationEvents(),this.bindBlikConfirmationEvents()):a==="add-card"&&(this.bindCardConfirmationEvents(),this.unbindBlikConfirmationEvents()),e.ajax({url:s.controllers.payment_ajax,method:"POST",data:o,dataType:"json"}),t.unbindGeneralConfirmationEvent(),e("#simplyin-payment-error").hide(),e(".simplyin-payment-option-item").removeClass("select-method")})},setupBlikEvents:function(){let t=this;e(document).on("focus",".simplyin-blik-digit-input",()=>{e(".simplyin-blik-digit-input").removeClass("valid error"),e(".simplyin-blik-error").hide()}),e(document).on("change",'input[name="simplyin-payment-option"]',function(){e(this).data("payment-type")!=="blik"?(e(".simplyin-blik-container").hide(),e(".simplyin-blik-digit-input").removeClass("valid error").val(""),e("#blik-form-error-1").hide()):e(".simplyin-blik-container").show()}),e(document).on("keyup",".simplyin-blik-digit-input",()=>{let n=this.getBlikCode();if(t.checkBlikCode(),n.length===6){let i={action:"enterBlikCode",ajax:1,ajax_token:t.ajaxToken,cart_token:t.cartToken,blik_code:n};e(".simplyin-blik-digit-input").addClass("valid"),e(".simplyin-blik-error").hide(),e.ajax({url:s.controllers.payment_ajax,method:"POST",data:i,dataType:"json"}).done(a=>{a.status==="success"&&e(".simplyin-blik-error").hide()})}}),e(document).on("focusout",".simplyin-blik-inputs-grid",n=>{e(n.relatedTarget).closest(".simplyin-blik-inputs-grid").length||(this.checkBlikCode()===!1?(e(".simplyin-blik-digit-input").removeClass("valid").addClass("error"),e(".simplyin-blik-error").show()):(e(".simplyin-blik-digit-input").removeClass("error").addClass("valid"),e(".simplyin-blik-error").hide()))})},bindCardConfirmationEvents:function(){let t=this,n=t.confirmationButton();if(!n)return;let i=a=>{if(this.ott_corect)return!0;a.preventDefault(),a.stopPropagation(),a.stopImmediatePropagation(),e(this.errorMsg).hide(),e(this.successMsg).hide(),this.cc.createToken().then(o=>{if(o&&o.oneTimeToken){e(this.successMsg).show();let r={action:"selectPaymentMethod",ajax:1,ajax_token:t.ajaxToken,cart_token:t.cartToken,payment_id:e('input[name="simplyin-payment-option"]:checked').val(),payment_type:"add-card",payment_provider:e('input[name="simplyin-payment-option"]:checked').data("payment-provider-name"),provider_image:e('input[name="simplyin-payment-option"]:checked').data("provider-image"),logo:e('input[name="simplyin-payment-option"]:checked').data("logo")};e("#simplyin-save-card").is(":checked")?(r.card_name=e("#card-name").val(),r.card_save="1"):(r.card_name="",r.card_save="0"),r.last_digits=o.last4digits,r.card_provider=o.organization,r.ott=o.oneTimeToken,this.unbindCardConfirmationEvents(),e.ajax({url:s.controllers.payment_ajax,method:"POST",data:r,dataType:"json"}).done(()=>{this.ott_corect=!0,setTimeout(()=>{let l=t.confirmationButton();l&&l.click()},300)})}else e(this.errorMsg).text(t.l("Invalid tokenization response")),e(this.errorMsg).show()}).catch(o=>{e(this.errorMsg).text(t.l("Problem processing card")),e(this.errorMsg).show()})};n.addEventListener("click",i,{capture:!0}),n._simplyinHandler=i},unbindCardConfirmationEvents:function(){let t=this.confirmationButton();t&&t._simplyinHandler&&(t.removeEventListener("click",t._simplyinHandler,{capture:!0}),delete t._simplyinHandler)},bindBlikConfirmationEvents:function(){let t=this,n=t.confirmationButton();if(!n)return;let i=a=>{if(this.blik_corect)return!0;if(a.preventDefault(),a.stopPropagation(),a.stopImmediatePropagation(),e(this.errorMsgBlik).hide(),e(this.successMsgBlik).hide(),!this.checkBlikCode()){e(this.errorMsgBlik).text(t.l("Invalid BLIK code")),e(this.errorMsgBlik).show();return}let o=this.getBlikCode(),r={action:"selectPaymentMethod",ajax:1,ajax_token:t.ajaxToken,cart_token:t.cartToken,payment_id:e('input[name="simplyin-payment-option"]:checked').val(),payment_type:"blik",blik_code:o,payment_provider:e('input[name="simplyin-payment-option"]:checked').data("payment-provider-name"),provider_image:e('input[name="simplyin-payment-option"]:checked').data("provider-image"),logo:e('input[name="simplyin-payment-option"]:checked').data("logo")};this.unbindBlikConfirmationEvents(),e.ajax({url:s.controllers.payment_ajax,method:"POST",data:r,dataType:"json"}).done(l=>{l.success===!0?(this.blik_corect=!0,setTimeout(()=>{let c=t.confirmationButton();c&&c.click()},300)):(e(this.errorMsgBlik).text(t.l("BLIK code rejected")),e(this.errorMsgBlik).show())}).fail(()=>{e(this.errorMsgBlik).text(t.l("Problem with BLIK processing")),e(this.errorMsgBlik).show()})};n.addEventListener("click",i,{capture:!0}),n._simplyinBlikHandler=i},unbindBlikConfirmationEvents:function(){let t=this.confirmationButton();t&&t._simplyinBlikHandler&&(t.removeEventListener("click",t._simplyinBlikHandler,{capture:!0}),delete t._simplyinBlikHandler)},setupOrderStatusCheck:function(){var t=this;if(typeof s.order_sended<"u"&&!s.order_status_paid){if(t.setupConfirmationHeading(),s.payment_status=="PAID"){e("#status-success").show().css("display","flex"),e("#status-pending").hide(),t.applyConfirmationHeading(!0);return}e("#status-pending").show().css("display","flex"),t.applyConfirmationHeading(!1);var n=0,i=100;let a=setInterval(()=>{if(n++,n>i){clearInterval(a),e("#status-error").show().css("display","flex"),e("#status-pending").hide();return}let o={id_cart:s.id_cart,ajax:1,ajax_token:s.ajax_token,cart_token:s.cart_token,action:"checkOrderStatus",id_module:s.id_module,payment_check_token:s.payment_check_token};e.ajax({url:s.controllers.payment_ajax,method:"POST",data:o,dataType:"json"}).done(r=>{r.status==="PAID"?(e("#status-success").show().css("display","flex"),e("#status-pending").hide(),t.applyConfirmationHeading(!0),clearInterval(a)):r.status=="REJECTED"||r.status=="FAILED"||r.status=="FAILD"?(e("#status-error").show().css("display","flex"),e("#status-pending").hide(),clearInterval(a),t.showRejectReason(r.reject_reason),t.checkRetryReveal()):t.showPendingMessage(r.status)})},3e3)}},setupConfirmationHeading:function(){if(this._headingIcon=null,this._headingTextNode=null,!!s.confirmation_heading_override)try{var t=document.getElementById("content-hook_order_confirmation");if(!t)return;var n=t.querySelectorAll(".card-title");if(n.length!==1)return;for(var i=n[0],a=null,o=0;o<i.childNodes.length;o++){var r=i.childNodes[o];if(r.nodeType===3&&r.textContent.trim()!==""){a=r;break}}if(!a)return;this._headingIcon=i.querySelector("i.material-icons")||null,this._headingTextNode=a}catch{this._headingIcon=null,this._headingTextNode=null}},applyConfirmationHeading:function(t){if(!(!s.confirmation_heading_override||!this._headingTextNode))try{this._headingIcon&&(this._headingIcon.style.display=t?"":"none"),this._headingTextNode.textContent=t?this.l("Order confirmed"):this.l("Order placed")}catch{}},showPendingMessage:function(t){var n=this,i=f[t];i&&e("#blik-status-message").text(n.l(i))},showRejectReason:function(t){var n=this,i=t&&p[t]?p[t]:"This order has not been paid.";e("#simplyin-status-error-message").text(n.l(i))},checkRetryReveal:function(){var t=this;if(!t._retryRevealChecked){t._retryRevealChecked=!0;try{var n=e(".simplyin-retry");if(!n.length||e(d).length)return;var i=n.data("order-id"),a=n.data("retry-token");if(!i||!a)return;e.ajax({url:s.controllers.payment_ajax,method:"POST",data:{action:"checkRetryDecision",ajax:1,ajax_token:s.retry_ajax_token,cart_token:s.retry_cart_token,id_order:i,retry_token:a},dataType:"json"}).done(function(o){try{o&&typeof o.html=="string"&&o.html!==""&&(n.replaceWith(o.html),t.initRetry())}catch{}})}catch{}}},autoSelectPayment:function(){let t=this;e('input[type="radio"][data-module-name^="simplyin"]').length&&e('input[type="radio"][data-module-name^="simplyin"]').prop("checked",!0).trigger("change")}},s&&(s.surface===h?window.SimplyInPayment.initRetry():s.controller==="orderconfirmation"?window.SimplyInPayment.initOrderConfirmation():(s.checkout=="classic"||s.checkout=="hummingbird")&&window.SimplyInPayment.init())});})();
