({459:function(){(function(){var t=function(t,e){return function(){return t.apply(e,arguments)}},e=function(t,e){for(const o in e)n.call(e,o)&&(t[o]=e[o]);function o(){this.constructor=t}return o.prototype=e.prototype,t.prototype=new o,t.__super__=e.prototype,t},n={}.hasOwnProperty;jQuery(document).ready((function(n){"use strict";return window.SV_WC_Apple_Pay_Handler=function(){function e(e){this.get_payment_request=t(this.get_payment_request,this),this.reset_payment_request=t(this.reset_payment_request,this),this.attach_update_events=t(this.attach_update_events,this),this.on_cancel_payment=t(this.on_cancel_payment,this),this.process_authorization=t(this.process_authorization,this),this.on_payment_authorized=t(this.on_payment_authorized,this),this.on_shipping_method_selected=t(this.on_shipping_method_selected,this),this.on_shipping_contact_selected=t(this.on_shipping_contact_selected,this),this.on_payment_method_selected=t(this.on_payment_method_selected,this),this.validate_merchant=t(this.validate_merchant,this),this.on_validate_merchant=t(this.on_validate_merchant,this),this.params=sv_wc_apple_pay_params,this.payment_request=e.payment_request,this.buttons=".sv-wc-apple-pay-button",this.is_available()&&(this.payment_request&&n(this.buttons).show(),this.init(),this.attach_update_events())}return e.prototype.is_available=function(){return!!window.ApplePaySession&&ApplePaySession.canMakePaymentsWithActiveCard(this.params.merchant_id).then((function(t){return t}))},e.prototype.init=function(){return n(document.body).on("click",".sv-wc-apple-pay-button",(t=this,function(e){let n;e.preventDefault(),t.block_ui();try{return t.session=new ApplePaySession(1,t.payment_request),t.session.onvalidatemerchant=function(e){return t.on_validate_merchant(e)},t.session.onpaymentmethodselected=function(e){return t.on_payment_method_selected(e)},t.session.onshippingcontactselected=function(e){return t.on_shipping_contact_selected(e)},t.session.onshippingmethodselected=function(e){return t.on_shipping_method_selected(e)},t.session.onpaymentauthorized=function(e){return t.on_payment_authorized(e)},t.session.oncancel=function(e){return t.on_cancel_payment(e)},t.session.begin()}catch(e){return n=e,t.fail_payment(n)}}));var t},e.prototype.on_validate_merchant=function(t){return this.validate_merchant(t.validationURL).then((e=this,function(t){return t=n.parseJSON(t),e.session.completeMerchantValidation(t)}),function(t){return function(e){return t.session.abort(),t.fail_payment("Merchant could no be validated. "+e.message)}}(this));var e},e.prototype.validate_merchant=function(t){return new Promise((e=this,function(o,s){let a;return a={action:"sv_wc_apple_pay_validate_merchant",nonce:e.params.validate_nonce,merchant_id:e.params.merchant_id,url:t},n.post(e.params.ajax_url,a,(function(t){return t.success?o(t.data):s(t.data)}))}));var e},e.prototype.on_payment_method_selected=function(t){return new Promise((e=this,function(t,o){let s;return s={action:"sv_wc_apple_pay_recalculate_totals",nonce:e.params.recalculate_totals_nonce},n.post(e.params.ajax_url,s,(function(n){return n.success?(s=n.data,t(e.session.completePaymentMethodSelection(s.total,s.line_items))):(console.error("[Apple Pay] Error selecting a shipping contact. "+n.data.message),o(e.session.completePaymentMethodSelection(e.payment_request.total,e.payment_request.lineItems)))}))}));var e},e.prototype.on_shipping_contact_selected=function(t){return new Promise((e=this,function(o,s){let a;return a={action:"sv_wc_apple_pay_recalculate_totals",nonce:e.params.recalculate_totals_nonce,contact:t.shippingContact},n.post(e.params.ajax_url,a,(function(t){return t.success?(a=t.data,o(e.session.completeShippingContactSelection(ApplePaySession.STATUS_SUCCESS,a.shipping_methods,a.total,a.line_items))):(console.error("[Apple Pay] Error selecting a shipping contact. "+t.data.message),s(e.session.completeShippingContactSelection(ApplePaySession.STATUS_FAILURE,[],e.payment_request.total,e.payment_request.lineItems)))}))}));var e},e.prototype.on_shipping_method_selected=function(t){return new Promise((e=this,function(o,s){let a;return a={action:"sv_wc_apple_pay_recalculate_totals",nonce:e.params.recalculate_totals_nonce,method:t.shippingMethod.identifier},n.post(e.params.ajax_url,a,(function(t){return t.success?(a=t.data,o(e.session.completeShippingMethodSelection(ApplePaySession.STATUS_SUCCESS,a.total,a.line_items))):(console.error("[Apple Pay] Error selecting a shipping method. "+t.data.message),s(e.session.completeShippingMethodSelection(ApplePaySession.STATUS_FAILURE,e.payment_request.total,e.payment_request.lineItems)))}))}));var e},e.prototype.on_payment_authorized=function(t){return this.process_authorization(t.payment).then((e=this,function(t){return e.set_payment_status(!0),e.complete_purchase(t)}),function(t){return function(e){return t.set_payment_status(!1),t.fail_payment("Payment could no be processed. "+e.message)}}(this));var e},e.prototype.process_authorization=function(t){return new Promise((e=this,function(o,s){let a;return a={action:"sv_wc_apple_pay_process_payment",nonce:e.params.process_nonce,type:e.type,payment:JSON.stringify(t)},n.post(e.params.ajax_url,a,(function(t){return t.success?o(t.data):s(t.data)}))}));var e},e.prototype.on_cancel_payment=function(t){return this.unblock_ui()},e.prototype.complete_purchase=function(t){return window.location=t.redirect},e.prototype.fail_payment=function(t){return console.error("[Apple Pay] "+t),this.unblock_ui(),this.render_errors([this.params.generic_error])},e.prototype.set_payment_status=function(t){let e;return e=t?ApplePaySession.STATUS_SUCCESS:ApplePaySession.STATUS_FAILURE,this.session.completePayment(e)},e.prototype.attach_update_events=function(){},e.prototype.reset_payment_request=function(t){return null==t&&(t={}),this.block_ui(),this.get_payment_request(t).then((e=this,function(t){return n(e.buttons).show(),e.payment_request=n.parseJSON(t),e.unblock_ui()}),function(t){return function(e){return console.error("[Apple Pay] Could not build payment request. "+e.message),n(t.buttons).hide(),t.unblock_ui()}}(this));var e},e.prototype.get_payment_request=function(t){return new Promise((e=this,function(o,s){let a;return a={action:"sv_wc_apple_pay_get_payment_request",type:e.type},n.extend(t,a),n.post(e.params.ajax_url,t,(function(t){return t.success?o(t.data):s(t.data)}))}));var e},e.prototype.render_errors=function(t){return n(".woocommerce-error, .woocommerce-message").remove(),this.ui_element.prepend('"),this.ui_element.removeClass("processing").unblock(),n("html, body").animate({scrollTop:this.ui_element.offset().top-100},1e3)},e.prototype.block_ui=function(){return this.ui_element.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},e.prototype.unblock_ui=function(){return this.ui_element.unblock()},e}(),window.Square_Apple_Pay_Cart_Handler=function(o){function s(e){this.attach_update_events=t(this.attach_update_events,this),this.type="cart",this.ui_element=n("form.woocommerce-cart-form").parents("div.woocommerce"),s.__super__.constructor.call(this,e)}return e(s,o),s.prototype.attach_update_events=function(){return n(document.body).on("updated_cart_totals",(t=this,function(){return t.reset_payment_request()}));var t},s}(SV_WC_Apple_Pay_Handler),window.Square_Apple_Pay_Checkout_Handler=function(o){function s(e){this.attach_update_events=t(this.attach_update_events,this),this.type="checkout",this.ui_element=n("form.woocommerce-checkout"),s.__super__.constructor.call(this,e),this.buttons=".sv-wc-apply-pay-checkout"}return e(s,o),s.prototype.attach_update_events=function(){return n(document.body).on("updated_checkout",(t=this,function(){return t.reset_payment_request()}));var t},s}(SV_WC_Apple_Pay_Handler),window.Square_Apple_Pay_Product_Handler=function(t){function o(t){this.type="product",this.ui_element=n("form.cart"),o.__super__.constructor.call(this,t)}return e(o,t),o}(SV_WC_Apple_Pay_Handler)}))}).call(this)}})[459]();