File "shortcode-checkout.min.js"
Full Path: /home/siazco/grocery.siazco.se/wp-content/plugins/swedbank-pay-checkout/assets/js/shortcode-checkout.min.js
File size: 13.54 KB
MIME-type: text/plain
Charset: utf-8
jQuery((function(e){"use strict";window.wc_sb_shortcode_checkout={customer_identified:null,customer_reference:null,billing_address:null,shipping_address:null,js_url:null,payment_url:WC_Shortcode_Checkout.payment_url,paymentMenu:null,is_payment_menu_loaded:!1,xhr:!1,updateTimer:null,init:function(o){console.log("init");var n=this;this.isTermsAndConditionsEnabled()||setInterval((function(){e("#place_order").prop("disabled",!0)}),1e3),this.isCheckinEnabled()&&(this.loadCheckIn(),this.isCheckinRequired()&&this.hidePlaceOrder(),e(document.body).on("click","#change-address-info",(function(e){e.preventDefault(),n.showAddressFields()})),this.hideAddressFields()),this.form=o,e(this.form).on("click","#place_order",{obj:n},this.onSubmit).on("submit checkout_place_order_payex_checkout"),e(document.body).on("updated_checkout",null,{obj:n},this.onInitOrUpdateCheckout),this.checkPaymentUrl((function(e){}))},isCheckinEnabled:()=>"yes"===WC_Shortcode_Checkout.checkin_enabled,isCheckinRequired(){return this.isCheckinEnabled()&&"yes"===WC_Shortcode_Checkout.checkin_required},isCustomerIdentified(){return!0===this.customer_identified},isRedirectMethodEnabled:()=>"redirect"===WC_Shortcode_Checkout.redirect_method,isTermsAndConditionsEnabled:()=>WC_Shortcode_Checkout.tos_enabled,loadCheckIn:function(){var o=this;return e.ajax({type:"POST",url:WC_Shortcode_Checkout.ajax_url,data:{action:"swedbank_pay_checkin",nonce:WC_Shortcode_Checkout.nonce},dataType:"json"}).done((function(e){if(!e.success)return o.logError("sb-checkin-loader",e),void alert(e.details);window.hasOwnProperty("payex")&&window.payex.hasOwnProperty("hostedView"),wc_sb_common.loadJs(e.data,(function(){o.initCheckIn()}))}))},initCheckIn:function(){if("undefined"!=typeof payex){var e=this;wc_sb_common.waitForLoading("payex.hostedView.consumer",(function(o){o?console.warn(o):window.payex.hostedView.consumer({container:"swedbank-pay-checkin",culture:WC_Shortcode_Checkout.culture,style:WC_Shortcode_Checkout.checkInStyle?JSON.parse(WC_Shortcode_Checkout.checkInStyle):null,onConsumerIdentified:function(o){console.log("hostedView: onConsumerIdentified"),e.onConsumerIdentified(o)},onNewConsumer:function(o){console.log("hostedView: onNewConsumer"),e.onConsumerIdentified(o)},onConsumerRemoved:function(e){console.log("hostedView: onConsumerRemoved"),console.log(e)},onBillingDetailsAvailable:function(o){e.onAddressDetailsAvailable("billing",o)},onShippingDetailsAvailable:function(o){e.onAddressDetailsAvailable("shipping",o)},onError:function(o){e.logError("sb-checkin",o),alert(o.details)}}).open()}))}},onConsumerIdentified:function(o){console.log("onConsumerIdentified",o);var n=this;async.parallel({save_customer_ref:function(e){n.saveCustomerRef(o,(function(o,n){o&&alert(o),e(null,n)}))},init_checkout:function(t){let r=e("#terms");r.length>0&&!r.prop("checked")&&r.prop("checked",!0),n.showPlaceOrder(),n.customer_identified=!0,n.form.find(".swedbank_pay_customer_reference").remove(),n.form.append("<input type='hidden' class='swedbank_pay_customer_reference' name='swedbank_pay_customer_reference' value='"+o.consumerProfileRef+"'/>"),t(null,[])}},(function(e,t){console.log("onConsumerIdentified: loaded",t),n.customer_identified=!0,n.customer_reference=o.consumerProfileRef}))},saveCustomerRef:function(o,n){e.ajax({type:"POST",url:WC_Shortcode_Checkout.ajax_url,data:{action:"swedbank_pay_checkout_customer_profile",nonce:WC_Shortcode_Checkout.nonce,consumerProfileRef:o.consumerProfileRef},dataType:"json"}).always((function(e){})).done((function(e){e.success?n(null,e):n(e.data.message,e)}))},fetchAddress:function(o,n,t){return e.ajax({type:"POST",url:WC_Shortcode_Checkout.ajax_url,data:{action:"swedbank_pay_checkout_get_address",nonce:WC_Shortcode_Checkout.nonce,type:o,url:n},dataType:"json"}).always((function(){})).done((function(n){if(console.log(n),!n.success)return void t(n.data.message);let r=n.data;e.each(r,(function(n,t){[o].forEach((function(o){let r=e('input[name="'+o+"_"+n+'"]');if(0!==r.length&&(r.prop("readonly",!1),r.closest(".form-row").removeClass("swedbank-pay-locked"),r.val(t).change(),"country"===n||"state"===n)){let r=e("#"+o+"_"+n);void 0!==window.Select2?r.select2("val",t):void 0!==e.fn.chosen?r.val(t).trigger("chosen:updated"):r.change()}}))})),t(null,r)}))},onAddressDetailsAvailable:function(o,n){console.log("onAddressDetailsAvailable",o,n);var t=this;t.fetchAddress(o,n.url,(function(r){r?t.onError(r):(t[o+"_address"]=n,e("#swedbank-pay-checkin-edit").show(),t.enqueueCheckoutUpdate())}))},hideAddressFields:function(){e("#address-fields").hide()},showAddressFields:function(){e("#address-fields").show()},initInstantCheckout:function(){console.log("Initialization of Shortcode Checkout...")},initCheckout:function(e){console.log("initCheckout"),e&&(this.form.find(".swedbank_pay_customer_reference").remove(),this.form.append("<input type='hidden' class='swedbank_pay_customer_reference' name='swedbank_pay_customer_reference' value='"+e+"'/>"));var o=this;o.block(),this.loadCheckout((function(e){o.unblock(),e&&o.submit_error('<div class="woocommerce-error">'+e+"</div>")}))},isPaymentMethodChosen:function(){return!0},onSubmit:function(e){void 0!==e&&e.preventDefault();var o=e.data.obj;o.loadCheckout((function(e){e&&o.submit_error('<div class="woocommerce-error">'+e+"</div>")}))},onUpdatedCheckout:function(o){console.log("onUpdatedCheckout");var n=o.data.obj;return!n.form.is(".processing")&&(wc_sb_common.validateForm()?(e(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),void n.updateOrder((function(){console.log("Order has been updated")}))):(console.log("onUpdatedCheckout: Validation is failed"),!1))},onUpdatedShippingMethod:function(e){console.log("onUpdatedShippingMethod");var o=e.data.obj;if(o.form.is(".processing"))return!1;o.updateOrder((function(){console.log("Order has been updated")}))},loadCheckout:function(o){console.log("loadCheckout");var n=this;let t=e("#terms");if(t.length>0&&!t.prop("checked"))o(WC_Shortcode_Checkout.terms_error);else{if(!n.isCheckinEnabled()||!n.isCheckinRequired()||n.isCustomerIdentified())return wc_sb_common.validateForm()?n.isPaymentMethodChosen()?(e(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),n.form.addClass("processing"),n.block(),n.xhr&&n.xhr.abort(),n.xhr=n.placeOrder().always((function(e){n.form.removeClass("processing"),n.unblock()})).fail((function(e,n){o(n)})).done((function(t){if(console.log(t),!t.hasOwnProperty("reload")||!0!==t.reload)return!0===t.result.refresh?(e(document.body).trigger("update_checkout"),void o(null,t)):void("success"===t.result?n.isRedirectMethodEnabled()?(console.log("Redirecting to "+t.redirect_url),window.location.href=t.redirect_url,o(null,t)):(n.js_url=t.js_url,n.initPaymentJS(n.js_url,(function(){n.hidePlaceOrder(),o(null,t)}))):o(t.messages));window.location.reload()})),!1):(console.log("payex_checkout must be chosen."),void o("Please select payment method.")):(console.log("The checkout form validation is failed."),void o(null));o(WC_Shortcode_Checkout.needs_checkin)}},resetCheckout:function(){},initPaymentJS:function(o,n){var t=this;void 0===n&&(n=function(){}),window.hasOwnProperty("payex")&&window.payex.hasOwnProperty("hostedView")&&(void 0!==window.payex.hostedView.paymentMenu&&window.payex.hostedView.paymentMenu().close(),e("#payment-swedbank-pay-checkout iframe").remove()),e("script[src*='px.paymentmenu.client']").remove(),wc_sb_common.loadJs(o,(function(){e("#payment-swedbank-pay-checkout iframe").remove(),e("#payment").hide(),t.initPaymentMenu("payment-swedbank-pay-checkout",(function(){n()}))}))},initPaymentMenu:function(o,n){console.log("initPaymentMenu");var t=this;void 0===n&&(n=function(){}),e("#"+o).block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),this.paymentMenu=window.payex.hostedView.paymentMenu({container:o,culture:WC_Shortcode_Checkout.culture,style:WC_Shortcode_Checkout.paymentMenuStyle?JSON.parse(WC_Shortcode_Checkout.paymentMenuStyle):null,onApplicationConfigured:function(r){t.is_payment_menu_loaded||(console.log("onApplicationConfigured",r),e("#"+o).unblock(),n(null)),t.is_payment_menu_loaded=!0},onPaymentMenuInstrumentSelected:function(e){console.log("onPaymentMenuInstrumentSelected",e),t.onPaymentMenuInstrumentSelected(e.name,e.instrument)},onPaymentCreated:function(){console.log("onPaymentCreated")},onPaymentCompleted:function(e){console.log("onPaymentCompleted",e),window.location.href=e.redirectUrl},onPaymentCanceled:function(e){console.log("onPaymentCanceled",e),t.logError("payment-menu-cancel",e)},onPaymentFailed:function(e){console.log("onPaymentFailed",e),t.logError("payment-menu-failed",e)},onPaymentToS:function(e){console.log("onPaymentToS",e),window.open(e.openUrl,"_blank")},onExternalRedirect:function(e){console.log("onExternalRedirect",e),window.location.href=e.redirectUrl},onError:function(e){t.logError("payment-menu-error",e),n(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");var o=this;let n=e(".woocommerce-checkout").serialize();return e.ajax({type:"POST",url:WC_Shortcode_Checkout.ajax_url,data:{action:"sbp_submit_order",nonce:WC_Shortcode_Checkout.nonce,data:n},dataType:"json"}).done((function(e){e.hasOwnProperty("reload")&&!0===e.reload?window.location.reload():e.hasOwnProperty("result")&&"failure"===e.result&&(o.logError("sb-place-order",e),o.onError(e.messages))}))},onInitOrUpdateCheckout:function(e){console.log("onInitOrUpdateCheckout");var o=this;if(void 0!==e&&(o=e.data.obj),!wc_sb_common.validateForm())return console.log("onInitOrUpdateCheckout: Validation is failed"),!1;void 0!==o.paymentMenu&&o.paymentMenu?o.updateOrder((function(){console.log("Order has been updated")})):o.isCheckinRequired()&&!o.customer_reference?console.log("Checkin is required."):o.initCheckout(o.customer_reference)},updateOrder:function(o){console.log("updateOrder");var n=this;let t=e(".woocommerce-checkout").serialize();return n.form.addClass("processing"),n.block(),n.xhr&&n.xhr.abort(),n.xhr=e.ajax({type:"POST",url:WC_Shortcode_Checkout.ajax_url,data:{action:"sbp_update_order",nonce:WC_Shortcode_Checkout.nonce,data:t},dataType:"json"}).always((function(e){n.form.removeClass("processing"),n.unblock()})).fail((function(e,n){console.log("updateOrder error:"+n),o(n)})).done((function(t){if(console.log(t),o(null,t),t.hasOwnProperty("result")&&"success"===t.result)n.refreshPaymentMenu();else{if(t.hasOwnProperty("result")&&"failure"===t.result){if(""===t.messages)return void console.warn("Error message is empty.");if(t.messages.indexOf("Order update is not available.")>-1)return void alert("Order update is not available.")}t.hasOwnProperty("reload")&&!0===t.reload?window.location.reload():t.hasOwnProperty("result")&&!0===t.result.refresh&&e(document.body).trigger("update_checkout")}})),n.xhr},enqueueCheckoutUpdate:function(){var o=this;o.updateTimer&&window.clearTimeout(o.updateTimer),o.updateTimer=setTimeout((function(){console.log("Update checkout..."),e(document.body).trigger("update_checkout")}),1e3)},onPaymentMenuInstrumentSelected:function(e,o){var n=this;async.parallel({invoice_fee:function(e){"no"!==WC_Shortcode_Checkout.invoice_fee_enabled?(n.block(),("Invoice"===o?sb_invoice_fee.apply_fee(!1):sb_invoice_fee.remove_fee(!1)).done((function(){e(null,!0)}))):e(null,!1)},carpay_discount:function(o){"no"!==WC_Shortcode_Checkout.carpay_enabled?(n.block(),("CarPay"===e?sb_carpay.apply_discount(!1):sb_carpay.remove_discount(!1)).done((function(){o(null,!0)}))):o(null,!1)},additional:function(e){e(null,!0)}},(function(e,o){(o.invoice_fee||o.carpay_discount)&&n.updateOrder((function(){console.log("Order has been updated"),n.unblock()}))}))},onError:function(e){console.log("onError",e),this.submit_error('<div class="woocommerce-error">'+e+"</div>")},submit_error:function(o){e(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),this.form.prepend('<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">'+o+"</div>"),this.form.removeClass("processing").unblock(),this.form.find(".input-text, select, input:checkbox").trigger("validate").blur(),this.scroll_to_notices(),e(document.body).trigger("checkout_error")},scroll_to_notices:function(){let o=e(".woocommerce-NoticeGroup-updateOrderReview, .woocommerce-NoticeGroup-checkout");o.length||(o=e(".form.checkout")),e.scroll_to_notices(o)},logError:function(o,n){return console.warn(n),e.ajax({type:"POST",url:WC_Shortcode_Checkout.ajax_url,data:{action:"swedbank_pay_checkout_log_error",nonce:WC_Shortcode_Checkout.nonce,id:o,data:JSON.stringify(n)},dataType:"json"})},checkPaymentUrl:function(o){new URLSearchParams(document.location.search).get("payment_url")&&this.payment_url?(e(".woocommerce-checkout").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),this.initPaymentJS(this.payment_url,(function(){console.log("Payment url has been loaded."),o(!0)}))):o(!1)},block:function(){var e=this;if(e.form){1!==e.form.data()["blockUI.isBlocked"]&&e.form.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}},unblock:function(){this.form&&this.form.unblock()},hidePlaceOrder:function(){e("#place_order").hide(),e(".place-order").hide();let o=e("#terms");o.length>0&&!o.prop("checked")&&o.prop("checked",!0)},showPlaceOrder:function(){e("#place_order").show(),e(".place-order").show()}},e(document).ready((function(){wc_sb_shortcode_checkout.init(e("form.checkout, form#order_review, form#add_payment_method"))}))}));
//# sourceMappingURL=shortcode-checkout.min.js.map