jQuery(function(i){"use strict";try{var n=Stripe(wc_stripe_params.key,{locale:wc_stripe_params.stripe_locale||"auto"})}catch(e){return void console.log(e)}var t,o,a,e=Object.keys(wc_stripe_params.elements_options).length?wc_stripe_params.elements_options:{},r=Object.keys(wc_stripe_params.sepa_elements_options).length?wc_stripe_params.sepa_elements_options:{},s=n.elements(e),c=s.create("iban",r),m={getAjaxURL:function(e){return wc_stripe_params.ajaxurl.toString().replace("%%endpoint%%","wc_stripe_"+e)},unmountElements:function(){"yes"===wc_stripe_params.inline_cc_form?t.unmount("#stripe-card-element"):(t.unmount("#stripe-card-element"),o.unmount("#stripe-exp-element"),a.unmount("#stripe-cvc-element"))},mountElements:function(){i("#stripe-card-element").length&&("yes"!==wc_stripe_params.inline_cc_form?(t.mount("#stripe-card-element"),o.mount("#stripe-exp-element"),a.mount("#stripe-cvc-element")):t.mount("#stripe-card-element"))},createElements:function(){var e={base:{iconColor:"#666EE8",color:"#31325F",fontSize:"15px","::placeholder":{color:"#CFD7E0"}}},r={focus:"focused",empty:"empty",invalid:"invalid"},e=wc_stripe_params.elements_styling||e,r=wc_stripe_params.elements_classes||r;"yes"===wc_stripe_params.inline_cc_form?(t=s.create("card",{style:e,hidePostalCode:!0})).addEventListener("change",function(e){m.onCCFormChange(),e.error&&i(document.body).trigger("stripeError",e)}):(t=s.create("cardNumber",{style:e,classes:r}),o=s.create("cardExpiry",{style:e,classes:r}),a=s.create("cardCvc",{style:e,classes:r}),t.addEventListener("change",function(e){m.onCCFormChange(),m.updateCardBrand(e.brand),e.error&&i(document.body).trigger("stripeError",e)}),o.addEventListener("change",function(e){m.onCCFormChange(),e.error&&i(document.body).trigger("stripeError",e)}),a.addEventListener("change",function(e){m.onCCFormChange(),e.error&&i(document.body).trigger("stripeError",e)})),"yes"===wc_stripe_params.is_checkout?i(document.body).on("updated_checkout",function(){i("#stripe-card-element").children().length||(t&&m.unmountElements(),m.mountElements(),i("#stripe-iban-element").length&&c.mount("#stripe-iban-element"))}):(i("form#add_payment_method").length||i("form#order_review").length)&&(m.mountElements(),i("#stripe-iban-element").length&&c.mount("#stripe-iban-element"))},updateCardBrand:function(e){var r={visa:"stripe-visa-brand",mastercard:"stripe-mastercard-brand",amex:"stripe-amex-brand",discover:"stripe-discover-brand",diners:"stripe-diners-brand",jcb:"stripe-jcb-brand",unknown:"stripe-credit-card-brand"},t=i(".stripe-card-brand"),e=e in r?r[e]:"stripe-credit-card-brand";i.each(r,function(e,r){t.removeClass(r)}),t.addClass(e)},init:function(){"yes"!==wc_stripe_params.is_change_payment_page&&"yes"!==wc_stripe_params.is_pay_for_order_page||i(document.body).trigger("wc-credit-card-form-init"),i("form.woocommerce-checkout").length&&(this.form=i("form.woocommerce-checkout")),i("form.woocommerce-checkout").on("checkout_place_order_stripe checkout_place_order_stripe_bancontact checkout_place_order_stripe_sofort checkout_place_order_stripe_giropay checkout_place_order_stripe_ideal checkout_place_order_stripe_alipay checkout_place_order_stripe_sepa checkout_place_order_stripe_boleto checkout_place_order_stripe_oxxo",this.onSubmit),i("form#order_review").length&&(this.form=i("form#order_review")),i("form#order_review, form#add_payment_method").on("submit",this.onSubmit),i("form#add_payment_method").length&&(this.form=i("form#add_payment_method")),i("form.woocommerce-checkout").on("change",this.reset),i(document).on("stripeError",this.onError).on("checkout_error",this.reset),c.on("change",this.onSepaError),(i("#early_renewal_modal_submit[data-payment-method]").length?i("#early_renewal_modal_submit[data-payment-method=stripe]"):i("#early_renewal_modal_submit")).on("click",this.onEarlyRenewalSubmit),m.createElements(),window.addEventListener("hashchange",m.onHashChange),m.maybeConfirmIntent(),i(document).on("change",".wc_payment_methods",function(){var n,e;i("#stripe_boleto_tax_id").length&&(n=function(e){return 12<=e.replace(/\D/g,"").length?"00.000.000/0000-00":"000.000.000-009999"},e={onKeyPress:function(e,r,t,o){t.mask(n.apply({},arguments),o)}},i("#stripe_boleto_tax_id").mask(n,e))})},isStripeChosen:function(){return i("#payment_method_stripe, #payment_method_stripe_bancontact, #payment_method_stripe_sofort, #payment_method_stripe_giropay, #payment_method_stripe_ideal, #payment_method_stripe_alipay, #payment_method_stripe_sepa, #payment_method_stripe_eps, #payment_method_stripe_multibanco, #payment_method_stripe_boleto, #payment_method_stripe_oxxo").is(":checked")||i("#payment_method_stripe").is(":checked")&&"new"===i('input[name="wc-stripe-payment-token"]:checked').val()||i("#payment_method_stripe_sepa").is(":checked")&&"new"===i('input[name="wc-stripe-payment-token"]:checked').val()},isStripeSaveCardChosen:function(){return i("#payment_method_stripe").is(":checked")&&i('input[name="wc-stripe-payment-token"]').is(":checked")&&"new"!==i('input[name="wc-stripe-payment-token"]:checked').val()||i("#payment_method_stripe_sepa").is(":checked")&&i('input[name="wc-stripe_sepa-payment-token"]').is(":checked")&&"new"!==i('input[name="wc-stripe_sepa-payment-token"]:checked').val()},isStripeCardChosen:function(){return i("#payment_method_stripe").is(":checked")},isBancontactChosen:function(){return i("#payment_method_stripe_bancontact").is(":checked")},isGiropayChosen:function(){return i("#payment_method_stripe_giropay").is(":checked")},isIdealChosen:function(){return i("#payment_method_stripe_ideal").is(":checked")},isSofortChosen:function(){return i("#payment_method_stripe_sofort").is(":checked")},isAlipayChosen:function(){return i("#payment_method_stripe_alipay").is(":checked")},isSepaChosen:function(){return i("#payment_method_stripe_sepa").is(":checked")},isP24Chosen:function(){return i("#payment_method_stripe_p24").is(":checked")},isEpsChosen:function(){return i("#payment_method_stripe_eps").is(":checked")},isMultibancoChosen:function(){return i("#payment_method_stripe_multibanco").is(":checked")},isBoletoChosen:function(){return i("#payment_method_stripe_boleto").is(":checked")},isOxxoChosen:function(){return i("#payment_method_stripe_oxxo").is(":checked")},hasSource:function(){return 0').addClass("stripe-source").attr("name","stripe_source").val(r)),i("form#add_payment_method").length||i("#wc-stripe-change-payment-method").length?m.sourceSetup(e):m.form.trigger("submit"))},sourceSetup:function(e){var r={error:{type:"api_connection_error"}};const t=e?.paymentMethod?.id??e?.source?.id;i.post({url:m.getAjaxURL("create_setup_intent"),dataType:"json",data:{stripe_source_id:t,nonce:wc_stripe_params.add_card_nonce},error:function(){i(document.body).trigger("stripeError",r)}}).done(function(e){return"success"===e.status?(i("form#add_payment_method").length&&i(m.form).off("submit",m.form.onSubmit),void m.form.trigger("submit")):void("requires_action"===e.status?n.confirmCardSetup(e.client_secret,{payment_method:t}).then(function(e){e.error?i(document.body).trigger("stripeError",e):(i("form#add_payment_method").length&&i(m.form).off("submit",m.form.onSubmit),m.form.trigger("submit"))}).catch(function(e){console.log(e),i(document.body).trigger("stripeError",{error:e})}):i(document.body).trigger("stripeError",e))})},onSubmit:function(){if(!m.isStripeChosen())return!0;if(m.isStripeSaveCardChosen()||m.hasSource())return!0;if(m.isBancontactChosen()||m.isGiropayChosen()||m.isIdealChosen()||m.isAlipayChosen()||m.isSofortChosen()||m.isP24Chosen()||m.isEpsChosen()||m.isMultibancoChosen())return!0;if(m.block(),m.isBoletoChosen()){if(!i("#stripe_boleto_tax_id").val())return m.submitError(wc_stripe_params.cpf_cnpj_required_msg),m.unblock(),!1;m.handleBoleto()}else m.isOxxoChosen()?m.handleOxxo():m.createSource();return!1},handleBoleto:function(){m.executeCheckout("boleto",function(r){n.confirmBoletoPayment(r.client_secret,r.confirm_payment_data).then(function(e){m.handleConfirmResponse(r,e)})})},executeCheckout:function(e,r){const t=m.form.serializeArray().reduce((e,r)=>(e[r.name]=r.value,e),{});"order_review"===m.form.attr("id")?(t._ajax_nonce=wc_stripe_params.updatePaymentIntentNonce,t.order_id=wc_stripe_params.orderId,i.ajax({url:m.getAjaxURL(e+"_update_payment_intent"),type:"POST",data:t,success:function(e){if("success"!==e.result)return m.submitError(e.messages),void m.unblock();r(e)}})):i.ajax({url:wc_stripe_params.checkout_url,type:"POST",data:t,success:function(e){if("success"!==e.result)return m.submitError(e.messages,!0),void m.unblock();r(e)}})},handleConfirmResponse:function(e,r){r.error?i(document.body).trigger("stripeError",r):-1===e.redirect.indexOf("https://")||-1===e.redirect.indexOf("http://")?window.location=e.redirect:window.location=decodeURI(e.redirect)},handleOxxo:function(){m.executeCheckout("oxxo",function(r){n.confirmOxxoPayment(r.client_secret,r.confirm_payment_data).then(function(e){m.handleConfirmResponse(r,e)})})},onCCFormChange:function(){m.reset()},reset:function(){i(".wc-stripe-error, .stripe-source").remove()},onSepaError:function(e){var r=m.getSelectedPaymentElement().parents("li").eq(0).find(".stripe-source-errors");e.error?(console.log(e.error.message),i(r).html(''),i(r).find("li").text(e.error.message)):i(r).html("")},onError:function(e,r){var t=r.error.message,o=m.getSelectedPaymentElement().closest("li"),n=o.find(".woocommerce-SavedPaymentMethods-tokenInput");o=i("body").hasClass("woocommerce-stripe-prb-clicked")?(i("body").removeClass("woocommerce-stripe-prb-clicked"),i("div.woocommerce-notices-wrapper").first()):n.length?(n=n.filter(":checked")).closest(".woocommerce-SavedPaymentMethods-new").length?i("#wc-stripe-cc-form .stripe-source-errors"):n.closest("li").find(".stripe-source-errors"):o.find(".stripe-source-errors"),m.isSepaChosen()&&"invalid_owner_name"===r.error.code&&wc_stripe_params.hasOwnProperty(r.error.code)?m.submitError(wc_stripe_params[r.error.code]):("email_invalid"===r.error.code?t=wc_stripe_params.email_invalid:"invalid_request_error"!==r.error.type&&"api_connection_error"!==r.error.type&&"api_error"!==r.error.type&&"authentication_error"!==r.error.type&&"rate_limit_error"!==r.error.type||(t=wc_stripe_params.invalid_request_error),wc_stripe_params.hasOwnProperty(r.error.code)&&(t=wc_stripe_params[r.error.code]),m.reset(),i(".woocommerce-NoticeGroup-checkout").remove(),console.log(r.error.message),i(o).html(''),i(o).find("li").text(t),i(".wc-stripe-error").length&&i("html, body").animate({scrollTop:i(".wc-stripe-error").offset().top-200},200),m.unblock(),i.unblockUI())},submitError:function(e,r=!1){r||((r=i('
')).find("li").text(e),e=r.html()),i(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),m.form.prepend('
'+e+"
"),m.form.removeClass("processing").unblock(),m.form.find(".input-text, select, input:checkbox").trigger("blur");e="";i("#add_payment_method").length&&(e=i("#add_payment_method")),i("#order_review").length&&(e=i("#order_review")),(e=i("form.checkout").length?i("form.checkout"):e).length&&i("html, body").animate({scrollTop:e.offset().top-100},500),i(document.body).trigger("checkout_error"),m.unblock()},onHashChange:function(){var e,r,t=window.location.hash.match(/^#?confirm-(pi|si)-([^:]+):(.+)$/);!t||t.length<4||(e=t[1],r=t[2],t=decodeURIComponent(t[3]),window.location.hash="",m.openIntentModal(r,t,!1,"si"===e))},maybeConfirmIntent:function(){var e,r;i("#stripe-intent-id").length&&i("#stripe-intent-return").length&&(e=i("#stripe-intent-id").val(),r=i("#stripe-intent-return").val(),m.openIntentModal(e,r,!0,!1))},openIntentModal:function(e,r,t,o){n[o?"handleCardSetup":"handleCardPayment"](e).then(function(e){if(e.error)throw e.error;e=e[o?"setupIntent":"paymentIntent"];"requires_capture"!==e.status&&"succeeded"!==e.status||(window.location=r)}).catch(function(e){t?window.location=r:(i(document.body).trigger("stripeError",{error:e}),m.form&&m.form.removeClass("processing"),i.get(r+"&is_ajax"))})},onEarlyRenewalSubmit:function(e){return e.preventDefault(),i.ajax({url:i("#early_renewal_modal_submit").attr("href"),method:"get",success:function(e){e=JSON.parse(e);e.stripe_sca_required?m.openIntentModal(e.intent_secret,e.redirect_url,!0,!1):window.location=e.redirect_url}}),!1}};m.init()});