!function(e,t){"use strict";var o,n=!0,r=!1,c=!1,i="",a="";function d(){var n=e(t).find(".yith-ppwc-button");"checkout"===(i=n.attr("data-location"))?o=n.closest('form[name="checkout"]'):"pay_order"===i?o=n.closest("#order_review"):"product"===i&&(o=n.closest(".product.type-product").find("form.cart"))}function l(e){var t=[];return e.push({name:"security",value:yith_ppwc_frontend.ajaxNonce},{name:"flow",value:a}),jQuery.each(e,(function(e,o){t.push(o.name+"="+o.value)})),t.join("&")}function u(n){if(n&&n.reload)window.location.reload();else if(n&&n.redirect)window.location.href=n.redirect;else{var r=n&&n.messages.length?n.messages:yith_ppwc_frontend.errorMessage;"checkout"===i?(e(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),e("form.checkout").prepend('<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">'+r+"</div>"),e(t.body).trigger("checkout_error",[r]),o.find(".input-text, select, input:checkbox").trigger("validate").blur()):e(".woocommerce-notices-wrapper").first().html(r),void 0!==e.scroll_to_notices&&e.scroll_to_notices("checkout"===i?e(".woocommerce-NoticeGroup-checkout"):e(".woocommerce-notices-wrapper").first()),p()}return!1}function s(){void 0===o||o.hasClass("processing")||o.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}function p(){void 0!==o&&o.hasClass("processing")&&o.removeClass("processing").unblock()}function h(t){var o=e("#payment_method_yith_paypal_payments").is(":checked"),n=e("#payment_method_yith_paypal_payments_custom_card").is(":checked"),r=e("#place_order"),c=e(".yith-ppwc-button-container");c.hide(),r.attr("disabled",!1).css({opacity:"1",cursor:"pointer"}).show(),t||!o&&!n||(r.attr("disabled",!0),o?(r.hide(),c.show()):r.css({opacity:"0.5",cursor:"default"}))}function f(){var c=e(t).find(".yith-ppwc-button");n?c.show():c.hide(),r||(r=!0,paypal.Buttons({style:{layout:yith_ppwc_frontend.layout,color:yith_ppwc_frontend.buttonColor,shape:yith_ppwc_frontend.buttonShape,disableMaxWidth:!0,label:c.data("label")},onClick:function(e,t){var n=[];return a=e&&e.fundingSource?e.fundingSource:"",d(),void 0!==o&&o.length?(n=function(){var e=o.serializeArray();if("product"===i){var t=o.find('button[name="add-to-cart"]');e.push({name:"is-yith-ppwc-action",value:"yes"}),t.length&&e.push({name:"add-to-cart",value:t.val()})}return e}(),"checkout"===i?(n.push({name:"request",value:"validate_checkout"}),s()):n.push({name:"request",value:"validate_product_cart"}),fetch(yith_ppwc_frontend.ajaxUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:l(n)}).then((function(e){return e.json()})).then((function(e){return e&&"failure"===e.result?(u(e),t.reject()):t.resolve()})).catch((function(e){return console.log("--- PayPal button onClick error: "+e+" ---"),u(null),t.reject()}))):t.resolve()},createOrder:function(e,t){return fetch(yith_ppwc_frontend.ajaxUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:l([{name:"request",value:"create_order"},{name:"checkoutRequest",value:i},{name:"orderID",value:c.data("order")}])}).then((function(e){return e.json()})).then((function(e){return p(),e.id}))},onError:function(e){"checkout"===i&&window.location.reload()},onApprove:function(e,t){e&&e.orderID&&("checkout"===i&&s(),fetch(yith_ppwc_frontend.ajaxUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:l([{name:"request",value:"approve_order"},{name:"orderID",value:e.orderID},{name:"checkoutRequest",value:i}])}).then((function(e){return e.json()})).then((function(e){e&&(e.redirect?window.location.href=e.redirect:e.result&&"failure"===e.result&&window.location.reload()),"checkout"!==i&&"pay_order"!==i||(p(),o.submit())})))}}).render(".yith-ppwc-button").catch((function(e){console.log(e)})))}if(e(t).find("#checkout_as_confirm_page").length)e(t.body).on("updated_checkout",(function(){e(t).find("ul.wc_payment_methods").hide()}));else if(e(t).find("#yith-ppwc-cc-form").length||e(t).find(".yith-ppwc-button").length){var m=function(){e(t).find(".yith-ppwc-button").html(""),r=!1,c=!1,f(),function(){if(void 0!==paypal.HostedFields&&!c)if(paypal.HostedFields.isEligible()){var n=e("#yith-ppwc-cc-form"),r=n.find(".error");d(),a="unbranded_card",c=!0,paypal.HostedFields.render({createOrder:function(t,o){return fetch(yith_ppwc_frontend.ajaxUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:l([{name:"request",value:"create_order"},{name:"checkoutRequest",value:i},{name:"orderID",value:e("#yith_paypal_cc_payments-order-id").data("order-id")}])}).then((function(e){return e.json()})).then((function(e){return e.id}))},styles:{input:{"font-size":"13px","font-family":"helvetica, tahoma, calibri, sans-serif",color:"#3a3a3a",padding:"0"},":focus":{color:"black"},"input.invalid":{color:"#e53a40"}},fields:{number:{selector:"#yith-ppwc-cc-card-number",placeholder:"1111 1111 1111 1111"},cvv:{selector:"#yith-ppwc-cc-cvv",placeholder:"123"},expirationDate:{selector:"#yith-ppwc-cc-expiration-date",placeholder:"10/24"}}}).then((function(c){var i=function(){var e=c.getState();r.html(""),h(Object.keys(e.fields).every((function(t){return e.fields[t].isValid})))};c.on("validityChange",i),i(),c.on("empty",(function(t){r.html(""),e("#card-image").removeClass()})),c.on("cardTypeChange",(function(t){r.html(""),1===t.cards.length?(e("#card-image").removeClass().addClass(t.cards[0].type),n.find('label[for="cvv"]').text(t.cards[0].code.name),4===t.cards[0].code.size&&c.setAttribute({field:"cvv",attribute:"placeholder",value:"1234"})):c.setAttribute({field:"cvv",attribute:"placeholder",value:"123"})})),e("#place_order").on("click",(function(n){if(yith_ppwc_frontend.customCardPaymentID==e('input[name="payment_method"]:checked').val()){n.preventDefault(),r.html("");var i={},a=e(t).find("#payments-sdk__contingency-lightbox").length>0;a&&(i={contingencies:["3D_SECURE"]}),s(),c.submit(i).then((function(n){try{var c=e("#yith_paypal_cc_payments-order-id");if(a){var i=e(t).find("#payments-sdk__contingency-lightbox").data("liability").split(",");if(console.log(n.liabilityShift),void 0!==n.liabilityShift&&!function(e,t){for(var o in t)if(t[o]===e)return!0;return!1}(n.liabilityShift.toLowerCase(),i)){if("unknown"===n.liabilityShift.toLowerCase())throw r.html(yith_ppwc_frontend.secure_3d_unknown),yith_ppwc_frontend.secure_3d_unknown;if("no"===n.liabilityShift.toLowerCase())throw r.html(yith_ppwc_frontend.secure_3d_no),yith_ppwc_frontend.secure_3d_no}}if(void 0===n.orderId||!n.orderId)throw"PayPal order ID missing";return c.val(n.orderId),p(),o.submit(),!0}catch(e){return p(),console.log(e),!1}})).catch((function(e){if(void 0!==e.details&&e.details.length>0){var t="";e.details.forEach((function(e){t+=e.description})),r.html(t),p()}}))}}))})).catch((function(e){console.log(e)}))}else e("#yith-ppwc-cc-form").hide()}()};e(t).ready((function(){d(),"checkout"!==i&&"pay_order"!==i||e(t.body).on("change",'input[name="payment_method"]',(function(){h(null)})),"checkout"===i?e(t.body).on("updated_checkout",(function(){h(null),m()})):m()})),e(t).on("yith_ppwc_initialize",m)}e("form.variations_form").on("show_variation",(function(e,t,o){n=o,f()})),e("form.variations_form").on("hide_variation",(function(e,t,o){n=!1,f()}))}(jQuery,document);