JezK
Edit File: woopay.js
(()=>{var e,o,t={1609(e){"use strict";e.exports=window.React},790(e){"use strict";e.exports=window.ReactJSXRuntime},7723(e){"use strict";e.exports=window.wp.i18n}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var c=n[e]={exports:{}};return t[e](c,c.exports,r),c.exports}r.m=t,r.n=e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return r.d(o,{a:o}),o},r.d=(e,o)=>{for(var t in o)r.o(o,t)&&!r.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},r.f={},r.e=e=>Promise.all(Object.keys(r.f).reduce((o,t)=>(r.f[t](e,o),o),[])),r.u=e=>"chunks/"+(4701===e?"wcpay-phone-input":e)+".js?ver="+{4701:"f2f1d9501fe2d2329ad9",7189:"6e66f730143ed421da7b"}[e],r.miniCssF=e=>{},r.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),e={},o="woocommerce-payments:",r.l=(t,n,c,a)=>{if(e[t])e[t].push(n);else{var s,i;if(void 0!==c)for(var l=document.getElementsByTagName("script"),u=0;u<l.length;u++){var p=l[u];if(p.getAttribute("src")==t||p.getAttribute("data-webpack")==o+c){s=p;break}}s||(i=!0,(s=document.createElement("script")).charset="utf-8",r.nc&&s.setAttribute("nonce",r.nc),s.setAttribute("data-webpack",o+c),s.src=t),e[t]=[n];var m=(o,n)=>{s.onerror=s.onload=null,clearTimeout(d);var r=e[t];if(delete e[t],s.parentNode&&s.parentNode.removeChild(s),r&&r.forEach(e=>e(n)),o)return o(n)},d=setTimeout(m.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=m.bind(null,s.onerror),s.onload=m.bind(null,s.onload),i&&document.head.appendChild(s)}},r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;globalThis.importScripts&&(e=globalThis.location+"");var o=globalThis.document;if(!e&&o&&(o.currentScript&&"SCRIPT"===o.currentScript.tagName.toUpperCase()&&(e=o.currentScript.src),!e)){var t=o.getElementsByTagName("script");if(t.length)for(var n=t.length-1;n>-1&&(!e||!/^http(s?):/.test(e));)e=t[n--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=e})(),(()=>{var e={214:0};r.f.j=(o,t)=>{var n=r.o(e,o)?e[o]:void 0;if(0!==n)if(n)t.push(n[2]);else{var c=new Promise((t,r)=>n=e[o]=[t,r]);t.push(n[2]=c);var a=r.p+r.u(o),s=new Error;r.l(a,t=>{if(r.o(e,o)&&(0!==(n=e[o])&&(e[o]=void 0),n)){var c=t&&("load"===t.type?"missing":t.type),a=t&&t.target&&t.target.src;s.message="Loading chunk "+o+" failed.\n("+c+": "+a+")",s.name="ChunkLoadError",s.type=c,s.request=a,n[1](s)}},"chunk-"+o,o)}};var o=(o,t)=>{var n,c,[a,s,i]=t,l=0;if(a.some(o=>0!==e[o])){for(n in s)r.o(s,n)&&(r.m[n]=s[n]);i&&i(r)}for(o&&o(t);l<a.length;l++)c=a[l],r.o(e,c)&&e[c]&&e[c][0](),e[c]=0},t=globalThis.webpackChunkwoocommerce_payments=globalThis.webpackChunkwoocommerce_payments||[];t.forEach(o.bind(null,0)),t.push=o.bind(null,t.push.bind(t))})(),r.p=window.wcpayAssets.url,(()=>{"use strict";const e=window.ReactDOM;var o=r(1609),t=r(7723);const n=window.wp.data,c=window.wc.blocksCheckout,a=window.wc.wcBlocksData;var s=r(790);const i=(0,o.lazy)(()=>Promise.all([r.e(7189),r.e(4701)]).then(r.bind(r,3119))),l=({id:e,inputProps:o={},isBlocksCheckout:n})=>(0,s.jsx)("div",{className:n?"wc-block-components-text-input":"",children:(0,s.jsx)("div",{className:"iti",children:(0,s.jsx)("input",{type:"tel",id:e,className:"phone-input input-text",placeholder:(0,t.__)("Mobile number","woocommerce-payments"),"aria-label":o.ariaLabel||(0,t.__)("Mobile phone number","woocommerce-payments"),name:o.name,disabled:!0})})}),u=({value:e="",id:n,onValueChange:r=()=>{},onValidationChange:c=()=>{},onCountryDropdownClick:a,inputProps:i={},isBlocksCheckout:l,...u})=>((0,o.useEffect)(()=>{e&&c(e.replace(/\D/g,"").length>=6)},[e,c]),(0,s.jsx)("div",{className:l?"wc-block-components-text-input":"",children:(0,s.jsx)("input",{type:"tel",id:n,value:e,className:"phone-input input-text",placeholder:(0,t.__)("Mobile number","woocommerce-payments"),"aria-label":i.ariaLabel||(0,t.__)("Mobile phone number","woocommerce-payments"),name:i.name,onChange:e=>r(e.target.value),...u})}));class p extends o.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback:this.props.children}}const m=e=>(0,s.jsx)(p,{fallback:(0,s.jsx)(u,{...e}),children:(0,s.jsx)(o.Suspense,{fallback:(0,s.jsx)(l,{...e}),children:(0,s.jsx)(i,{...e})})}),d=e=>"undefined"!=typeof wcpayConfig&&void 0!==wcpayConfig[e]?wcpayConfig[e]:h(e),h=e=>{let o=null;if("undefined"!=typeof wcpay_upe_config)o=wcpay_upe_config;else{if("object"!=typeof wc||void 0===wc.wcSettings)return null;o=wc.wcSettings.getSetting("woocommerce_payments_data")||{}}return o[e]||null},y=e=>"object"==typeof wcpayExpressCheckoutParams&&wcpayExpressCheckoutParams.hasOwnProperty(e)?wcpayExpressCheckoutParams[e]:null,w=()=>(0,s.jsx)("div",{className:"additional-information",children:(0,t.__)("Next time you buy here and on other Woo-powered stores, we'll send you a code to securely purchase with WooPay.","woocommerce-payments")});function f(e){return e.startsWith("{{/")?{type:"componentClose",value:e.replace(/\W/g,"")}:e.endsWith("/}}")?{type:"componentSelfClosing",value:e.replace(/\W/g,"")}:e.startsWith("{{")?{type:"componentOpen",value:e.replace(/\W/g,"")}:{type:"string",value:e}}function v(e,t){let n,r,c=[];for(let o=0;o<e.length;o++){const a=e[o];if("string"!==a.type){if(void 0===t[a.value])throw new Error(`Invalid interpolation, missing component node: \`${a.value}\``);if("object"!=typeof t[a.value])throw new Error(`Invalid interpolation, component node must be a ReactElement or null: \`${a.value}\``);if("componentClose"===a.type)throw new Error(`Missing opening component token: \`${a.value}\``);if("componentOpen"===a.type){n=t[a.value],r=o;break}c.push(t[a.value])}else c.push(a.value)}if(n){const a=function(e,o){const t=o[e];let n=0;for(let r=e+1;r<o.length;r++){const e=o[r];if(e.value===t.value){if("componentOpen"===e.type){n++;continue}if("componentClose"===e.type){if(0===n)return r;n--}}}throw new Error("Missing closing component token `"+t.value+"`")}(r,e),s=v(e.slice(r+1,a),t),i=(0,o.cloneElement)(n,{},s);if(c.push(i),a<e.length-1){const o=v(e.slice(a+1),t);c=c.concat(o)}}return c=c.filter(Boolean),0===c.length?null:1===c.length?c[0]:(0,o.createElement)(o.Fragment,null,...c)}function _(e){const{mixedString:o,components:t,throwErrors:n}=e;if(!t)return o;if("object"!=typeof t){if(n)throw new Error(`Interpolation Error: unable to process \`${o}\` because components is not an object`);return o}const r=function(e){return e.split(/(\{\{\/?\s*\w+\s*\/?\}\})/g).map(f)}(o);try{return v(r,t)}catch(e){if(n)throw new Error(`Interpolation Error: unable to process \`${o}\` because of error \`${e.message}\``);return o}}window.wp.domReady;const b=(e,o={})=>{if(!1===(d("isShopperTrackingEnabled")??y("is_shopper_tracking_enabled")))return;const t=d("platformTrackerNonce")??y("nonce")?.platform_tracker,n=d("ajaxUrl")??y("ajax_url"),r=new FormData;r.append("tracksNonce",t),r.append("action","platform_tracks"),r.append("tracksEventName",e),r.append("tracksEventProp",JSON.stringify(o)),fetch(n,{method:"post",body:r}).then(e=>e.json())},k=()=>(0,s.jsx)("div",{className:"tos",children:_({mixedString:(0,t.__)("By continuing, you agree to WooPay's {{termsOfService/}} and {{privacyPolicy/}}.","woocommerce-payments"),components:{termsOfService:(0,s.jsx)("a",{target:"_blank",href:"https://wordpress.com/tos/",rel:"noopener noreferrer",onClick:()=>{b("checkout_save_my_info_tos_click")},children:(0,t.__)("Terms of Service","woocommerce-payments")}),privacyPolicy:(0,s.jsx)("a",{target:"_blank",href:"https://automattic.com/privacy/",rel:"noopener noreferrer",onClick:()=>{b("checkout_save_my_info_privacy_policy_click")},children:(0,t.__)("Privacy Policy","woocommerce-payments")})}})}),g=({children:e,isBlocksCheckout:o})=>o?(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("div",{className:"woopay-save-new-user-container",children:[(0,s.jsx)("div",{className:"wc-block-components-checkout-step__heading-container",children:(0,s.jsx)("div",{className:"wc-block-components-checkout-step__heading",children:(0,s.jsx)("h2",{className:"wc-block-components-title wc-block-components-checkout-step__title",children:(0,t.__)("Save my info","woocommerce-payments")})})}),e]})}):e;function E(e,o="",t){for(const n in e){const r=e[n],c=o?o+"["+n+"]":n;"string"==typeof r||"number"==typeof r?t.append(c,r):"object"==typeof r&&E(r,c,t)}return t}async function x(e,o,t){const n=E(o,"",new FormData),r=await fetch(e,{method:"POST",body:n,...t});return await r.json()}const C=()=>document.querySelector("#payment_method_woocommerce_payments")?.checked,S=()=>document.querySelector("#wc-woocommerce_payments-payment-token-new")?.checked||!document.querySelector('[type=radio][name="wc-woocommerce_payments-payment-token"]'),j=({isBlocksCheckout:e})=>{const r="invalid-woopay-phone-number",{setValidationErrors:i,clearValidationError:l}=(0,n.useDispatch)(a.VALIDATION_STORE_KEY),[u,p]=(0,o.useState)(window.woopayCheckout?.PRE_CHECK_SAVE_MY_INFO||!1),[h,y]=(0,o.useState)(""),[f,v]=(0,o.useState)(null),[_,E]=(0,o.useState)(!1),j=(0,o.useRef)(!1),N=(0,n.useSelect)(e=>e(a.CHECKOUT_STORE_KEY).isProcessing()),P=(0,n.useSelect)(e=>e(a.CHECKOUT_STORE_KEY).getUseShippingAsBilling()),B=(()=>{const[e,t]=(0,o.useState)(!1),n=(0,o.useRef)(window);return(0,o.useEffect)(()=>{const e=e=>{t(e.detail.isRegisteredUser)},o=n.current;return o.addEventListener("woopayUserCheck",e),()=>{o.removeEventListener("woopayUserCheck",e)}},[]),e})(),{isWCPayChosen:T,isNewPaymentTokenChosen:O}=(e=>{const{isWCPayChosenOnBlocksCheckout:t}=(0,n.useSelect)(e=>({isWCPayChosenOnBlocksCheckout:"woocommerce_payments"===e(a.PAYMENT_STORE_KEY).getActivePaymentMethod()})),[r,c]=(0,o.useState)(!e&&C()),[s,i]=(0,o.useState)(!e&&S());return(0,o.useEffect)(()=>{if(e)return;const o=()=>{const o=C();c(o),e&&o&&(()=>{const e=document.querySelector(".wc-block-components-payment-methods__save-card-info");e&&(e.style.display="none")})()},t=()=>{i(S())},n=document.querySelectorAll('[type=radio][name="payment_method"]');n.forEach(e=>{e.addEventListener("change",o)});const r=(e=>e?document.querySelectorAll('[type=radio][name="radio-control-wc-payment-method-saved-tokens"]'):document.querySelectorAll('[type=radio][name="wc-woocommerce_payments-payment-token"]'))(e);return r.forEach(e=>{e.addEventListener("change",t)}),()=>{n.forEach(e=>{e.removeEventListener("change",o)}),r.forEach(e=>{e.removeEventListener("change",t)})}},[e]),{isWCPayChosen:e?t:r,isNewPaymentTokenChosen:e?t:s}})(e),L=e?T:T&&O,A=window.document.documentElement.clientWidth,R=window.document.documentElement.clientHeight;(0,o.useEffect)(()=>{if(!e)return;const o=document.querySelector("#remember-me");if(o){if(N)return o.classList.add("wc-block-components-checkout-step--disabled"),void o.setAttribute("disabled","disabled");o.classList.remove("wc-block-components-checkout-step--disabled"),o.removeAttribute("disabled","disabled")}},[N,e]);const q=(0,o.useCallback)(()=>{let o="";return o=e?document.getElementById("phone")?.value||document.getElementById("billing-phone")?.value||document.getElementById("shipping-phone")?.value||"":document.getElementById("billing_phone")?.value||"",o=o.replace(/[^\d+]*/g,""),o.startsWith("+")||(o="+1"+o),o},[e]),W=(0,o.useCallback)((e=!1)=>{const o=e?{empty:1}:{save_user_in_woopay:u?1:0,woopay_source_url:wcSettings?.storePages?.checkout?.permalink,woopay_is_blocks:1,woopay_viewport:`${A}x${R}`,woopay_user_phone_field:{full:h}};x(((e,o,t="wcpay_")=>e.toString().replace("%%endpoint%%",t+o))(d("wcAjaxUrl"),"set_woopay_phone_number"),{_ajax_nonce:d("woopaySessionNonce"),...o}).then(()=>{E(!e)})},[u,h,A,R]),I=(0,o.useCallback)(()=>{b("checkout_woopay_save_my_info_country_click")},[]);(0,o.useEffect)(()=>{f&&b("checkout_woopay_save_my_info_mobile_enter")},[f]),(0,o.useEffect)(()=>{jQuery("form.woocommerce-checkout").on("checkout_place_order",function(){jQuery("#validate-error-invalid-woopay-phone-number").show()})},[]),(0,o.useEffect)(()=>{if(u)return u&&f?(l(r),void(e&&W(!1))):void(u&&!f&&L&&i({[r]:{message:(0,t.__)("Please enter a valid mobile phone number.","woocommerce-payments"),hidden:null===f}}))},[l,e,f,u,W,i,L]);const M=(0,o.useCallback)(()=>{j.current||y(q())},[y,q,j]);return(0,o.useEffect)(()=>{M()},[M]),(0,o.useEffect)(()=>{if(e){if(M(),P)return document.querySelector("#billing-phone")?.removeEventListener("blur",M),void document.querySelector("#shipping-phone")?.addEventListener("blur",M);document.querySelector("#shipping-phone")?.removeEventListener("blur",M),document.querySelector("#billing-phone")?.addEventListener("blur",M)}else document.querySelector("#billing_phone")?.addEventListener("blur",M)},[P,M,j,q,e]),(0,o.useEffect)(()=>{d("forceNetworkSavedCards")&&L&&!B||(e&&_&&W(!0),l(r))},[l,r,e,B,L,W,_]),d("forceNetworkSavedCards")&&L&&!B?(0,s.jsx)(g,{isBlocksCheckout:e,children:(0,s.jsxs)("div",{className:"save-details",children:[(0,s.jsx)("div",{className:"save-details-header",children:(0,s.jsx)("div",{className:e?"wc-block-components-checkbox":"",children:(0,s.jsxs)("label",{htmlFor:"save_user_in_woopay",children:[(0,s.jsx)("input",{type:"checkbox",checked:u,onChange:o=>{const t=o.target.checked;t?y(q()):(y(""),v(null),l(r),e&&W(!0)),p(t),b("checkout_save_my_info_click",{status:t?"checked":"unchecked"})},name:"save_user_in_woopay",id:"save_user_in_woopay",value:"true",className:"save-details-checkbox "+(e?"wc-block-components-checkbox__input":""),"aria-checked":u}),e&&(0,s.jsx)("svg",{className:"wc-block-components-checkbox__mark","aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 20",children:(0,s.jsx)("path",{d:"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z"})}),(0,s.jsx)("span",{className:"wc-block-components-checkbox__label",children:(0,t.__)("Securely save my information for 1-click checkout","woocommerce-payments")})]})})}),u&&(0,s.jsxs)("div",{className:"save-details-form form-row","data-testid":"save-user-form",children:[(0,s.jsx)("input",{type:"hidden",name:"woopay_source_url",value:wcSettings?.storePages?.checkout?.permalink}),(0,s.jsx)("input",{type:"hidden",name:"woopay_viewport",value:`${A}x${R}`}),(0,s.jsxs)("div",{className:f?"":"has-error",children:[(0,s.jsx)(m,{value:h,onValueChange:y,onValidationChange:v,onCountryDropdownClick:I,onClick:()=>j.current=!0,inputProps:{name:"woopay_user_phone_field[no-country-code]"},isBlocksCheckout:e}),e&&(0,s.jsx)(c.ValidationInputError,{elementId:r,propertyName:r}),!e&&!f&&(0,s.jsx)("p",{id:"validate-error-invalid-woopay-phone-number",hidden:!1!==f,children:(0,t.__)("Please enter a valid mobile phone number.","woocommerce-payments")})]}),(0,s.jsx)(w,{}),(0,s.jsx)(k,{})]})]})}):null};let N=null;const P=()=>{const o=document.getElementsByClassName("woopay-save-new-user-container")?.[0];if(!o)if(document.getElementsByClassName("wc-block-checkout").length){let o=document.querySelector("#remember-me");if(!o){const e=document.getElementsByClassName("wp-block-woocommerce-checkout-payment-block")?.[0];if(!e)return;o=document.createElement("fieldset"),o.className="wc-block-checkout__payment-method wp-block-woocommerce-checkout-remember-block wc-block-components-checkout-step ",o.id="remember-me",e.parentNode.insertBefore(o,e.nextSibling),N?.unmount(),N=null}N||(N=(0,e.createRoot)(o)),N.render((0,s.jsx)(j,{isBlocksCheckout:!0}))}else{const o=document.createElement("div");o.className="woopay-save-new-user-container";const t=document.getElementsByClassName("form-row place-order")?.[0],n=t?.parentNode;t&&n&&(n.insertBefore(o,t),(0,e.createRoot)(o).render((0,s.jsx)(j,{isBlocksCheckout:!1})))}};window.addEventListener("load",()=>{P()}),jQuery(function(e){e(document).ajaxComplete(function(){P()})})})()})();