woocommerce-eu-vat-number/build/frontend.js
2026-03-18 10:49:43 +00:00

3 lines
No EOL
15 KiB
JavaScript

(()=>{var e,t={275:(e,t,r)=>{"use strict";const n=window.React,o=window.wc.blocksCheckout,c=window.wp.i18n,a=JSON.parse('{"apiVersion":2,"name":"woocommerce/eu-vat-number","version":"1.0.0","title":"EU VAT Number","parent":["woocommerce/checkout-fields-block"],"category":"woocommerce","icon":"cart","description":"The EU VAT Number extension lets you collect and validate EU VAT numbers during checkout to identify B2B transactions verses B2C. IP Addresses can also be validated to ensure they match the billing address. EU businesses with a valid VAT number can have their VAT removed prior to payment.","supports":{"html":false},"textdomain":"woocommerce-eu-vat-number","attributes":{"lock":{"type":"object","default":{"remove":true,"move":false}}}}'),i=window.wp.element,s=window.wp.compose,u=window.wp.data;function l(e,t){return e===t}function d(e,t){return t}const m=window.wp.components,p=window.wc.wcSettings;var v=r(485),f=r.n(v);const h="wc/store/validation",b=({shouldValidateIp:e,billingCountry:t,ipAddress:r,ipCountry:a,validation:s,checkoutExtensionData:l})=>{const d=(0,p.getSetting)("allowedCountries",{}),{setExtensionData:m}=l;let v=t;d[t]&&(v=d[t]);const{extensions:f}=(0,u.useSelect)((e=>e("wc/store/cart").getCartData())),b=f["woocommerce-eu-vat-number"]||{},{cart_has_digital_goods:_}=b?.vat_data||{},{setValidationErrors:g,clearValidationError:w,showAllValidationErrors:y}=(0,u.useDispatch)(h),{getValidationError:E}=(0,u.useSelect)((e=>e(h))),[k,S]=(0,i.useState)(!1),[x,A]=(0,i.useState)(!1),C="billing_vat_number_ip_address_notice",N=(0,c.sprintf)(/* translators: %1$s is the user's IP address, %2$s is the billing country name */ /* translators: %1$s is the user's IP address, %2$s is the billing country name */
(0,c.__)("Your IP Address (%1$s) does not match your billing country (%2$s). European VAT laws require your IP address to match your billing country when purchasing digital goods in the EU. Please confirm you are located within your billing country using the checkbox above.","woocommerce-eu-vat-number"),r,v),O=e&&_&&t!==a,T=(0,u.useSelect)((e=>e("wc/store/checkout").isProcessing()));if((0,i.useEffect)((()=>(!k&&O&&g({[C]:{message:N,hidden:!x}}),k&&w(C),()=>{w(C)})),[g,k,x]),(0,i.useEffect)((()=>{T&&y()}),[T]),!O)return null;const V=E(C);return(0,n.createElement)("div",{className:"wc-eu-vat-checkout-ip-notice"},(0,n.createElement)("div",{className:"wc-eu-vat-checkout-ip-notice__checkbox-container"},(0,n.createElement)(o.CheckboxControl,{name:"location_confirmation",className:!1===V?.hidden?"has-error":"",label:(0,i.createInterpolateElement)((0,c.sprintf)(/* translators: %s is the billing country full name, e.g. Finland, France, or Spain. */ /* translators: %s is the billing country full name, e.g. Finland, France, or Spain. */
(0,c.__)("I am established, have my permanent address, or usually reside within <strong>%s</strong>.","woocommerce-eu-vat-number"),v),{strong:(0,n.createElement)("strong",null)}),checked:k,onChange:e=>{x||A(!0),S(e),m("woocommerce-eu-vat-number","location_confirmation",e)}})),V?.message&&!V?.hidden?(0,n.createElement)("div",{className:"wc-eu-vat-checkout-ip-notice__error wc-block-components-validation-error"},V.message):null)},_=({defaultTitle:e=(0,c.__)("Step","woocommerce-eu-vat-number"),defaultDescription:t=(0,c.__)("Step description text.","woocommerce-eu-vat-number"),defaultShowStepNumber:r=!0})=>({title:{type:"string",default:e},description:{type:"string",default:t},showStepNumber:{type:"boolean",default:r}}),g=({title:e,stepHeadingContent:t})=>(0,n.createElement)("div",{className:"wc-block-components-checkout-step__heading"},(0,n.createElement)("h2",{"aria-hidden":"true",className:"wc-block-components-checkout-step__title wc-block-components-title"},e),!!t&&(0,n.createElement)("span",{className:"wc-block-components-checkout-step__heading-content"},t)),w=(y=_({}),e=>t=>{const r=((e,t)=>{const r=[];return Object.keys(e).forEach((n=>{if(void 0!==t[n])switch(e[n].type){case"boolean":r[n]="false"!==t[n]&&!1!==t[n];break;case"number":r[n]=parseInt(t[n],10);break;case"array":case"object":r[n]=JSON.parse(t[n]);break;default:r[n]=t[n]}else r[n]=e[n].default})),r})(y,t);return(0,n.createElement)(e,{...t,...r})})((({id:e,className:t,title:r,legend:o,description:c,children:a,disabled:i=!1,showStepNumber:s=!0,stepHeadingContent:u=(()=>{})})=>{const l=o||r?"fieldset":"div";return(0,n.createElement)(l,{className:f()(t,"wc-block-components-checkout-step",{"wc-block-components-checkout-step--with-step-number":s,"wc-block-components-checkout-step--disabled":i}),id:e,disabled:i},!(!o&&!r)&&(0,n.createElement)("legend",{className:"screen-reader-text"},o||r),!!r&&(0,n.createElement)(g,{title:r,stepHeadingContent:u()}),(0,n.createElement)("div",{className:"wc-block-components-checkout-step__container"},!!c&&(0,n.createElement)("p",{className:"wc-block-components-checkout-step__description"},c),(0,n.createElement)("div",null,a)))}));var y;const E="woocommerce-eu-vat-number",k="wc/store/validation",S="vat_input_error",x="vat_required_error",A="vat_freeze_checkout",C=(0,s.withInstanceId)((e=>{const{checkoutExtensionData:t,extensions:r,validation:a}=e,{setExtensionData:s}=t,{billingAddress:v,shippingAddress:h,needsShipping:_}=(0,u.useSelect)((e=>{const t=e("wc/store/cart").getCartData();return{cartItems:t.items,billingAddress:t.billingAddress,shippingAddress:t.shippingAddress,extensions:t.extensions,needsShipping:t.needsShipping}})),{eu_countries:g,input_label:y,input_description:C,use_shipping_country:N,saved_vat_number:O,b2b_required:T}=window.wc_eu_vat_params,{title:V=(0,c.__)("VAT Details","woocommerce-eu-vat-number"),description:I="",showStepNumber:D=!0}=e,{woocommerce_eu_vat_number_validate_ip:P,ip_address:R,ip_country:j}=(0,p.getSetting)("woocommerce-eu-vat-number_data"),q="yes"===P,U=j&&-1!==g.indexOf(j),B=r[E]||{},L=N&&_?h.country:v.country,{cart_has_digital_goods:M}=B?.vat_data||{},z=q&&M&&v.country!==j&&U,F=(0,i.useRef)(!0),$=(0,i.useRef)(!0),[H,J]=(0,i.useState)(O),[W,Y]=(0,i.useState)(!1),[G,K]=(0,i.useState)(-1!==g.indexOf(L)),[Q]=(se=H,le=l,de=(0,n.useReducer)(d,se),me=de[0],pe=de[1],ve=function(e,t,r){var o=this,c=(0,n.useRef)(null),a=(0,n.useRef)(0),i=(0,n.useRef)(null),s=(0,n.useRef)([]),u=(0,n.useRef)(),l=(0,n.useRef)(),d=(0,n.useRef)(e),m=(0,n.useRef)(!0);d.current=e;var p="undefined"!=typeof window,v=!t&&0!==t&&p;if("function"!=typeof e)throw new TypeError("Expected a function");t=+t||0;var f=!!(r=r||{}).leading,h=!("trailing"in r)||!!r.trailing,b="maxWait"in r,_="debounceOnServer"in r&&!!r.debounceOnServer,g=b?Math.max(+r.maxWait||0,t):null;(0,n.useEffect)((function(){return m.current=!0,function(){m.current=!1}}),[]);var w=(0,n.useMemo)((function(){var e=function(e){var t=s.current,r=u.current;return s.current=u.current=null,a.current=e,l.current=d.current.apply(r,t)},r=function(e,t){v&&cancelAnimationFrame(i.current),i.current=v?requestAnimationFrame(e):setTimeout(e,t)},n=function(e){if(!m.current)return!1;var r=e-c.current;return!c.current||r>=t||r<0||b&&e-a.current>=g},w=function(t){return i.current=null,h&&s.current?e(t):(s.current=u.current=null,l.current)},y=function e(){var o=Date.now();if(n(o))return w(o);if(m.current){var i=t-(o-c.current),s=b?Math.min(i,g-(o-a.current)):i;r(e,s)}},E=function(){if(p||_){var d=Date.now(),v=n(d);if(s.current=[].slice.call(arguments),u.current=o,c.current=d,v){if(!i.current&&m.current)return a.current=c.current,r(y,t),f?e(c.current):l.current;if(b)return r(y,t),e(c.current)}return i.current||r(y,t),l.current}};return E.cancel=function(){i.current&&(v?cancelAnimationFrame(i.current):clearTimeout(i.current)),a.current=0,s.current=c.current=u.current=i.current=null},E.isPending=function(){return!!i.current},E.flush=function(){return i.current?w(Date.now()):l.current},E}),[f,b,t,g,h,v,p,_]);return w}((0,n.useCallback)((function(e){return pe(e)}),[pe]),800,ue),fe=(0,n.useRef)(se),le(fe.current,se)||(ve(se),fe.current=se),[me,ve]),X=(0,i.useRef)(!0),{setValidationErrors:Z,clearValidationError:ee,showAllValidationErrors:te}=(0,u.useDispatch)(k),re="yes"===T,{getValidationError:ne}=(0,u.useSelect)((e=>e(k))),oe=B?.vat_data?.is_valid,ce=ne(S),ae=ne(x),ie=(0,u.useSelect)((e=>e("wc/store/checkout").isProcessing()));var se,ue,le,de,me,pe,ve,fe;if((0,i.useEffect)((()=>{if($.current&&!Q)return(0,o.extensionCartUpdate)({namespace:E,data:{vat_number:"",billing_country:v.country,shipping_country:h.country,use_shipping_country:N&&_}}),void($.current=!1);Y(!0),Z({vat_verification_in_progress:{message:"",hidden:!1}}),(0,o.extensionCartUpdate)({namespace:E,data:{vat_number:Q,billing_country:v.country,shipping_country:h.country,needs_shipping:_}}).then((()=>{Y(!1),ee("vat_verification_in_progress")}))}),[Q,L]),(0,i.useEffect)((()=>{Z({[A]:{message:"",hidden:!1}})}),[H]),(0,i.useEffect)((()=>{s(E,"vat_number",Q),ee(A)}),[Q]),(0,i.useEffect)((()=>{s("woocommerce-eu-vat-number","location_confirmation",!1)}),[s]),(0,i.useEffect)((()=>{Q?ee(x):re&&G?Z({[x]:{message:(0,c.__)("VAT number is required.","woocommerce-eu-vat-number"),hidden:X.current}}):ee(x)}),[Q,re,G]),(0,i.useEffect)((()=>{if(F.current)return void(F.current=!1);const e=-1!==g.indexOf(L);ee(S),e||""===L||(ee(x),ee(A),ee("vat_verification_in_progress"),J("")),K(e)}),[L,g]),(0,i.useEffect)((()=>{oe?ee(S):Q&&B?.vat_data?.error?Z({[S]:{message:B?.vat_data?.error,hidden:!1}}):ee(S)}),[oe,L,Q,B?.vat_data?.error]),(0,i.useEffect)((()=>{X.current=!1,H||ee(S)}),[H]),(0,i.useEffect)((()=>{ie&&te()}),[ie]),!G&&!z)return;const he=[ce?.hidden,ae?.hidden].some((e=>!1===e));let be=!1;return re&&G||Q&&oe?be=!1:(!Q||Q&&!oe)&&(be=!0),(0,n.createElement)(w,{id:"shipping-fields",className:f()("wc-block-checkout__shipping-fields","eu-vat-extra-css"),title:V,description:I,showStepNumber:D},G&&(0,n.createElement)(n.Fragment,null,(0,n.createElement)(o.TextInput,{label:`${y}${re?"":" ("+(0,c.__)("optional","woocommerce-eu-vat-number")+")"}`,value:H,onChange:J,className:he&&"has-error",style:{marginBottom:0},id:"billing_vat_number","aria-describedby":C?"billing_vat_number_description":null}),ce&&!ce.hidden&&(0,n.createElement)("div",{className:"wc-block-components-validation-error"},(0,n.createElement)("p",{role:"alert"},ce.message)),ae&&!ae.hidden&&(0,n.createElement)("div",{className:"wc-block-components-validation-error"},(0,n.createElement)("p",{role:"alert"},ae.message)),C&&(0,n.createElement)("div",{className:"wc-block-components-checkout-step__description",id:"billing_vat_number_description",style:{marginTop:"0.5rem"}},C),W&&(0,n.createElement)("div",{className:"wc-block-components-checkout-step__description",style:{marginTop:"0.5rem",marginBottom:"0",display:"flex",alignItems:"end"}},(0,n.createElement)(m.Spinner,{style:{overflow:"visible"}}),(0,c.__)("Applying VAT...","woocommerce-eu-vat-number"))),be&&(0,n.createElement)(b,{validation:a,ipAddress:R,ipCountry:j,billingCountry:v.country,shouldValidateIp:q,checkoutExtensionData:t}))})),N=".wc-block-components-address-card",O="{vat_id}",T=(()=>{const e={vatNumber:null,replacementsCount:0,initialized:!1};return{get:t=>{try{return e[t]}catch(e){return null}},set:(t,r)=>{try{e[t]=r}catch(e){}}}})(),V=e=>{let t=0;return Promise.race([new Promise((r=>{const n=setInterval((()=>{if(t++>=50)return clearInterval(n),void r(null);const o=e();o&&(clearInterval(n),r(o))}),10);window.addEventListener("pagehide",(()=>clearInterval(n))),window.addEventListener("unload",(()=>clearInterval(n)))})),new Promise((e=>{setTimeout((()=>e(null)),5e3)}))])},I=async()=>{try{var e;const t=await V((()=>{try{const e=(0,u.select)("wc/store/cart");if(!e)return null;const t=e.getCartData();return void 0!==t?.extensions?.["woocommerce-eu-vat-number"]?.vat_data?.number?t:null}catch(e){return null}}));return null!==(e=t?.extensions["woocommerce-eu-vat-number"]?.vat_data?.number)&&void 0!==e?e:""}catch(e){return""}},D=e=>{try{var t;if(T.get("replacementsCount")>=2)return!1;const r=null!==(t=T.get("vatNumber"))&&void 0!==t?t:"";if(!e)return!1;let n=e.querySelectorAll(".wc-block-components-address-card__address-section span");n?.length||(n=e.querySelectorAll(".wc-block-components-address-card__address-section"));let o=!1;return n?.forEach((e=>{if(e?.textContent?.includes(O)){let t=e.textContent.replace(O,r);!r&&t&&(t=t.replace(/,\s*,/g,",")),e.textContent=t,o=!0}})),o}catch(e){return!1}},P=async()=>{if(!T.get("initialized")){T.set("initialized",!0);try{const[e,t]=await Promise.all([I(),V((()=>document.querySelector(".wc-block-checkout__form")))]);if(!t)return;T.set("vatNumber",e);const r=document.querySelectorAll(N);if(r.length>0&&r.forEach(D),T.get("replacementsCount")<2){const e=new MutationObserver((()=>{T.get("replacementsCount")>=2?e.disconnect():(document.querySelectorAll(N).forEach(D),T.get("replacementsCount")>=2&&e.disconnect())}));e.observe(t,{childList:!0,subtree:!0})}}catch(e){}}},R=()=>{try{if("loading"===document.readyState)return void document.addEventListener("DOMContentLoaded",P);if("interactive"===document.readyState||"complete"===document.readyState)return void P();document.addEventListener("readystatechange",(()=>{T.get("initialized")||"interactive"!==document.readyState&&"complete"!==document.readyState||P()}))}catch(e){}},j={metadata:{...a,attributes:{...a.attributes,..._({defaultTitle:(0,c.__)("VAT Number","woocommerce-eu-vat-number"),defaultDescription:"",defaultShowStepNumber:!0})}},component:e=>(0,n.createElement)(C,{isEditing:!1,...e})};R(),(0,o.registerCheckoutBlock)(j)},485:(e,t)=>{var r;!function(){"use strict";var n={}.hasOwnProperty;function o(){for(var e=[],t=0;t<arguments.length;t++){var r=arguments[t];if(r){var c=typeof r;if("string"===c||"number"===c)e.push(r);else if(Array.isArray(r)){if(r.length){var a=o.apply(null,r);a&&e.push(a)}}else if("object"===c)if(r.toString===Object.prototype.toString)for(var i in r)n.call(r,i)&&r[i]&&e.push(i);else e.push(r.toString())}}return e.join(" ")}e.exports?(o.default=o,e.exports=o):void 0===(r=function(){return o}.apply(t,[]))||(e.exports=r)}()}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var c=r[e]={exports:{}};return t[e](c,c.exports,n),c.exports}n.m=t,e=[],n.O=(t,r,o,c)=>{if(!r){var a=1/0;for(l=0;l<e.length;l++){for(var[r,o,c]=e[l],i=!0,s=0;s<r.length;s++)(!1&c||a>=c)&&Object.keys(n.O).every((e=>n.O[e](r[s])))?r.splice(s--,1):(i=!1,c<a&&(a=c));if(i){e.splice(l--,1);var u=o();void 0!==u&&(t=u)}}return t}c=c||0;for(var l=e.length;l>0&&e[l-1][2]>c;l--)e[l]=e[l-1];e[l]=[r,o,c]},n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={343:0,834:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var o,c,[a,i,s]=r,u=0;if(a.some((t=>0!==e[t]))){for(o in i)n.o(i,o)&&(n.m[o]=i[o]);if(s)var l=s(n)}for(t&&t(r);u<a.length;u++)c=a[u],n.o(e,c)&&e[c]&&e[c][0](),e[c]=0;return n.O(l)},r=globalThis.webpackChunkwoocommerce_eu_vat_number=globalThis.webpackChunkwoocommerce_eu_vat_number||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var o=n.O(void 0,[834],(()=>n(275)));o=n.O(o)})();