jQuery((function(o){"use strict";window.wc_sb_checkout={js_url:null,payment_url:WC_Gateway_Swedbank_Pay_Checkout.payment_url,paymentMenu:null,isPaymentMenuLoaded:!1,xhr:!1,isLocked:!1,init:function(e){this.form=e,this.form_submit=!1,o(this.form).on("click","#place_order",{obj:window.wc_sb_checkout},this.onSubmit).on("submit checkout_place_order_payex_checkout"),o(document.body).bind("update_checkout",this.onUpdateCheckout),o(document.body).on("checkout_error",this.resetCheckout),o(document.body).on("updated_checkout",this.onUpdatedCheckout),o(document.body).on("blur",this.onUpdatedCheckout),this.checkPaymentUrl((function(e){e||wc_sb_common.isInstantCheckout()&&wc_sb_checkout.initInstantCheckout()}))},initInstantCheckout:function(){console.log("Initialization of Instant Checkout...")},initCheckout:function(e){wc_sb_checkout.form.find(".swedbank_pay_customer_reference").remove(),wc_sb_checkout.form.append("<input type='hidden' class='swedbank_pay_customer_reference' name='swedbank_pay_customer_reference' value='"+e+"'/>"),wc_sb_checkout.onSubmit({data:{obj:window.wc_sb_checkout}})},isPaymentMethodChosen:function(){return o("#payment_method_payex_checkout").is(":checked")},onClose:function(){wc_sb_common.unblock()},onReady:function(){console.log("Ready")},onUpdateCheckout:function(){if(console.log("onUpdateCheckout"),!wc_sb_common.isInstantCheckout())return!1},onUpdatedCheckout:function(){return console.log("onUpdatedCheckout"),!!wc_sb_common.isInstantCheckout()&&(!wc_sb_checkout.form.is(".processing")&&(wc_sb_common.validateForm()?(o(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),void wc_sb_checkout.updateOrder()):(console.log("onUpdatedCheckout: Validation is failed"),!1)))},onSubmit:function(n){var c=n.data.obj;let t=o("#terms");return t.length>0&&!t.prop("checked")?(c.submit_error('<div class="woocommerce-error">'+WC_Gateway_Swedbank_Pay_Checkout.terms_error+"</div>"),!1):window.hasOwnProperty("wc_sb_checkin")&&window.wc_sb_checkin.isCheckinEnabled()&&window.wc_sb_checkin.isCheckinRequired()&&!window.wc_sb_checkin.isCustomerIdentified()?(c.submit_error('<div class="woocommerce-error">'+WC_Gateway_Swedbank_Pay_Checkin.needs_checkin+"</div>"),!1):!!c.form_submit||(!c.isPaymentMethodChosen()||("undefined"!=typeof e&&e.preventDefault(),wc_sb_common.validateForm()?(console.log("onSubmit"),c.form.is(".processing")||(o(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),c.form.addClass("processing"),wc_sb_common.block(),c.placeOrder().always((function(e){c.form.removeClass("processing"),wc_sb_common.unblock()})).fail((function(e,o){c.onError(o)})).done((function(e){if(console.log(e),"success"!==e.result)return e.hasOwnProperty("reload")&&!0===e.reload?void window.location.reload():(!0===e.result.refresh&&o(document.body).trigger("update_checkout"),void c.onError(e.messages));wc_sb_common.isRedirectMethodEnabled()?(console.log("Redirecting to "+e.redirect_url),window.location.href=e.redirect_url):(c.js_url=e.js_url,c.initPaymentJS(c.js_url))}))),!1):(console.log("The checkout form validation is failed."),c.isCheckinEnabled()&&c.submit_error('<div class="woocommerce-error">'+WC_Gateway_Swedbank_Pay_Checkout.checkin_error+"</div>"),!1)))},resetCheckout:function(){wc_sb_checkout.form_submit=!1},isCheckinEnabled:function(){return!!window.hasOwnProperty("wc_sb_checkin")&&window.wc_sb_checkin.isCheckinEnabled()},initPaymentJS:function(e,n){void 0===n&&(n=function(){}),window.hasOwnProperty("payex")&&window.payex.hasOwnProperty("hostedView")&&(void 0!==window.payex.hostedView.paymentMenu&&window.payex.hostedView.paymentMenu().close(),o("#payment-swedbank-pay-checkout iframe").remove()),o("script[src*='px.paymentmenu.client']").remove(),wc_sb_common.loadJs(e,(function(){o("#payment-swedbank-pay-checkout iframe").remove(),wc_sb_common.isInstantCheckout()?(o("#payment").hide(),wc_sb_checkout.initPaymentMenu("payment-swedbank-pay-checkout")):(console.log("non-instant checkout"),o.featherlight('<div id="swedbank-pay-paymentmenu">&nbsp;</div>',{variant:"featherlight-swedbank-seamless",persist:!0,closeOnClick:!1,closeOnEsc:!1,afterOpen:function(){wc_sb_checkout.initPaymentMenu("swedbank-pay-paymentmenu")},afterClose:function(){wc_sb_checkout.form.removeClass("processing").unblock()}})),n()}))},initPaymentMenu:function(e,o){console.log("initPaymentMenu"),void 0===o&&(o=function(){}),this.paymentMenu=window.payex.hostedView.paymentMenu({container:e,culture:WC_Gateway_Swedbank_Pay_Checkout.culture,style:WC_Gateway_Swedbank_Pay_Checkout.paymentMenuStyle?JSON.parse(WC_Gateway_Swedbank_Pay_Checkout.paymentMenuStyle):null,onApplicationConfigured:function(e){console.log("onApplicationConfigured"),console.log(e),wc_sb_checkout.isPaymentMenuLoaded=!0,o(null)},onPaymentMenuInstrumentSelected:function(e){console.log("onPaymentMenuInstrumentSelected"),console.log(e),wc_sb_checkout.onPaymentMenuInstrumentSelected(e.name,e.instrument)},onPaymentCreated:function(){console.log("onPaymentCreated")},onPaymentCompleted:function(e){console.log("onPaymentCompleted"),console.log(e),self.location.href=e.redirectUrl},onPaymentCanceled:function(e){console.log("onPaymentCanceled"),console.log(e),wc_sb_common.logError("payment-menu-cancel",e)},onPaymentFailed:function(e){console.log("onPaymentFailed"),console.log(e),wc_sb_common.logError("payment-menu-failed",e)},onError:function(e){wc_sb_common.logError("payment-menu-error",e),o(e)}}),this.paymentMenu.open()},refreshPaymentMenu:function(){console.log("refreshPaymentMenu"),void 0!==this.paymentMenu&&this.paymentMenu&&(this.paymentMenu.hasOwnProperty("refresh")&&"function"==typeof this.paymentMenu.refresh?this.paymentMenu.refresh():console.warn("refreshPaymentMenu: paymentMenu doesn't support refresh"))},placeOrder:function(){console.log("placeOrder");let e=o(".woocommerce-checkout").serialize();return o.ajax({type:"POST",url:WC_Gateway_Swedbank_Pay_Checkout.ajax_url,data:{action:"swedbank_pay_place_order",nonce:WC_Gateway_Swedbank_Pay_Checkout.nonce,data:e},dataType:"json"}).done((function(e){e.hasOwnProperty("reload")&&!0===e.reload?window.location.reload():e.hasOwnProperty("result")&&"failure"===e.result&&(wc_sb_common.logError("sb-place-order",e),wc_sb_checkout.onError(e.messages))}))},updateOrder:function(e){if(this.isLocked)return wc_sb_checkout.xhr;console.log("updateOrder");let n=o(".woocommerce-checkout").serialize();return e&&alert("Order update is not available."),wc_sb_checkout.form.addClass("processing"),wc_sb_common.block(),wc_sb_checkout.xhr&&wc_sb_checkout.xhr.abort(),wc_sb_checkout.xhr=o.ajax({type:"POST",url:WC_Gateway_Swedbank_Pay_Checkout.ajax_url,data:{action:"swedbank_pay_update_order",nonce:WC_Gateway_Swedbank_Pay_Checkout.nonce,data:n},dataType:"json"}).always((function(e){wc_sb_checkout.xhr=!1,wc_sb_checkout.form.removeClass("processing"),wc_sb_common.unblock()})).fail((function(e,o){console.log("updateOrder error:"+o)})).done((function(n){if(console.log(n),n.hasOwnProperty("result")&&"success"===n.result)return wc_sb_checkout.js_url=n.js_url,void wc_sb_checkout.refreshPaymentMenu();if(n.hasOwnProperty("result")&&"failure"===n.result){if(""===n.messages)return void console.warn("Error message is empty.");if(n.messages.indexOf("Order update is not available.")>-1&&!e)return console.warn("refreshPaymentMenu: refresh workaround. Force reload."),void wc_sb_checkout.updateOrder(!0).done((function(e){e.hasOwnProperty("js_url")&&wc_sb_checkout.initPaymentJS(e.js_url)}))}n.hasOwnProperty("reload")&&!0===n.reload?window.location.reload():(n.hasOwnProperty("result")&&!0===n.result.refresh&&o(document.body).trigger("update_checkout"),wc_sb_common.logError("sb-update-order",n))})),wc_sb_checkout.xhr},onPaymentMenuInstrumentSelected:function(e,n){console.log("onPaymentMenuInstrumentSelected",e,n),o(document.body).trigger("sb_payment_menu_instrument_selected",[e,n])},onError:function(e){console.log("onError",e),wc_sb_checkout.submit_error('<div class="woocommerce-error">'+e+"</div>")},submit_error:function(e){o(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),wc_sb_checkout.form.prepend('<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">'+e+"</div>"),wc_sb_checkout.form.removeClass("processing").unblock(),wc_sb_checkout.form.find(".input-text, select, input:checkbox").trigger("validate").blur(),wc_sb_checkout.scroll_to_notices(),o(document.body).trigger("checkout_error")},scroll_to_notices:function(){let e=o(".woocommerce-NoticeGroup-updateOrderReview, .woocommerce-NoticeGroup-checkout");e.length||(e=o(".form.checkout")),o.scroll_to_notices(e)},checkPaymentUrl:function(e){if(new URLSearchParams(document.location.search).get("payment_url")&&this.payment_url){var o=this;this.lockCheckout(),this.initPaymentJS(this.payment_url,(function(){console.log("Payment url has been loaded."),o.unlockCheckout(),e(!0)}))}else e(!1)},lockCheckout:function(){this.isLocked=!0,o(".woocommerce-checkout").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unlockCheckout:function(){this.isLocked=!1,o(".woocommerce-checkout").unblock()}},o(document).ready((function(){wc_sb_checkout.init(o("form.checkout, form#order_review, form#add_payment_method"))}))})); //# sourceMappingURL=instant-checkout.min.js.map