mirror of
https://gh.wpcy.net/https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2026-04-25 01:02:18 +08:00
1 line
No EOL
16 KiB
JavaScript
1 line
No EOL
16 KiB
JavaScript
(()=>{"use strict";const e=window.wp.plugins,t=window.wp.element,n=window.wp.data;function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,i(r.key),r)}}function i(e){var t=function(e){if("object"!=r(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==r(t)?t:t+""}const a=function(){function e(){var t=arguments;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),window.paypalInsightDataLayer=window.paypalInsightDataLayer||[],document.paypalInsight=function(){paypalInsightDataLayer.push(t)}}return t=e,n=[{key:"init",value:function(){return e.instance||(e.instance=new e),e.instance}},{key:"track",value:function(t,n){e.init(),paypalInsight("event",t,n)}},{key:"config",value:function(t,n){e.init(),paypalInsight("config",t,n)}},{key:"setSessionId",value:function(t){e.init(),paypalInsight("set",{session_id:t})}},{key:"trackJsLoad",value:function(){e.track("js_load",{timestamp:Date.now()})}},{key:"trackBeginCheckout",value:function(t){e.track("begin_checkout",t)}},{key:"trackSubmitCheckoutEmail",value:function(t){e.track("submit_checkout_email",t)}},{key:"trackSelectPaymentMethod",value:function(t){e.track("select_payment_method",t)}},{key:"trackEndCheckout",value:function(t){e.track("end_checkout",t)}}],null&&o(t.prototype,null),n&&o(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n}();function u(e){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u(e)}function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function l(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach(function(t){s(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function s(e,t,n){return(t=function(e){var t=function(e){if("object"!=u(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=u(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==u(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var f="woocommerce-paypal-payments/axo-block",d={isPayPalLoaded:!1,isGuest:!0,isAxoActive:!1,isAxoScriptLoaded:!1,isEmailSubmitted:!1,isEmailLookupCompleted:!1,shippingAddress:null,cardDetails:null,phoneNumber:"",cardChangeHandler:null};if(!(0,n.select)(f)){var p=(0,n.createReduxStore)(f,{reducer:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:d,t=arguments.length>1?arguments[1]:void 0;switch(t.type){case"SET_IS_PAYPAL_LOADED":return l(l({},e),{},{isPayPalLoaded:t.payload});case"SET_IS_GUEST":return l(l({},e),{},{isGuest:t.payload});case"SET_IS_AXO_ACTIVE":return l(l({},e),{},{isAxoActive:t.payload});case"SET_IS_AXO_SCRIPT_LOADED":return l(l({},e),{},{isAxoScriptLoaded:t.payload});case"SET_IS_EMAIL_SUBMITTED":return l(l({},e),{},{isEmailSubmitted:t.payload});case"SET_IS_EMAIL_LOOKUP_COMPLETED":return l(l({},e),{},{isEmailLookupCompleted:t.payload});case"SET_SHIPPING_ADDRESS":return l(l({},e),{},{shippingAddress:t.payload});case"SET_CARD_DETAILS":return l(l({},e),{},{cardDetails:t.payload});case"SET_PHONE_NUMBER":return l(l({},e),{},{phoneNumber:t.payload});case"SET_CARD_CHANGE_HANDLER":return l(l({},e),{},{cardChangeHandler:t.payload});default:return e}},actions:{setIsPayPalLoaded:function(e){return{type:"SET_IS_PAYPAL_LOADED",payload:e}},setIsGuest:function(e){return{type:"SET_IS_GUEST",payload:e}},setIsAxoActive:function(e){return{type:"SET_IS_AXO_ACTIVE",payload:e}},setIsAxoScriptLoaded:function(e){return{type:"SET_IS_AXO_SCRIPT_LOADED",payload:e}},setIsEmailSubmitted:function(e){return{type:"SET_IS_EMAIL_SUBMITTED",payload:e}},setIsEmailLookupCompleted:function(e){return{type:"SET_IS_EMAIL_LOOKUP_COMPLETED",payload:e}},setShippingAddress:function(e){return{type:"SET_SHIPPING_ADDRESS",payload:e}},setCardDetails:function(e){return{type:"SET_CARD_DETAILS",payload:e}},setPhoneNumber:function(e){return{type:"SET_PHONE_NUMBER",payload:e}},setCardChangeHandler:function(e){return{type:"SET_CARD_CHANGE_HANDLER",payload:e}}},selectors:{getIsPayPalLoaded:function(e){return e.isPayPalLoaded},getIsGuest:function(e){return e.isGuest},getIsAxoActive:function(e){return e.isAxoActive},getIsAxoScriptLoaded:function(e){return e.isAxoScriptLoaded},getIsEmailSubmitted:function(e){return e.isEmailSubmitted},getIsEmailLookupCompleted:function(e){return e.isEmailLookupCompleted},getShippingAddress:function(e){return e.shippingAddress},getCardDetails:function(e){return e.cardDetails},getPhoneNumber:function(e){return e.phoneNumber},getCardChangeHandler:function(e){return e.cardChangeHandler}}});(0,n.register)(p)}function y(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,a,u=[],c=!0,l=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=i.call(n)).done)&&(u.push(r.value),u.length!==t);c=!0);}catch(e){l=!0,o=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(e,t)||function(e,t){if(e){if("string"==typeof e)return m(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?m(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function v(e){return v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},v(e)}function b(){var e,t,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",o=n.toStringTag||"@@toStringTag";function i(n,r,o,i){var c=r&&r.prototype instanceof u?r:u,l=Object.create(c.prototype);return g(l,"_invoke",function(n,r,o){var i,u,c,l=0,s=o||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,u=0,c=e,d.n=n,a}};function p(n,r){for(u=n,c=r,t=0;!f&&l&&!o&&t<s.length;t++){var o,i=s[t],p=d.p,y=i[2];n>3?(o=y===r)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=n<2&&p<i[1])?(u=0,d.v=r,d.n=i[1]):p<y&&(o=n<3||i[0]>r||r>y)&&(i[4]=n,i[5]=r,d.n=y,u=0))}if(o||n>1)return a;throw f=!0,r}return function(o,s,y){if(l>1)throw TypeError("Generator is already running");for(f&&1===s&&p(s,y),u=s,c=y;(t=u<2?e:c)||!f;){i||(u?u<3?(u>1&&(d.n=-1),p(u,c)):d.n=c:d.v=c);try{if(l=2,i){if(u||(o="next"),t=i[o]){if(!(t=t.call(i,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,u<2&&(u=0)}else 1===u&&(t=i.return)&&t.call(i),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=e}else if((t=(f=d.n<0)?c:n.call(r,d))!==a)break}catch(t){i=e,u=1,c=t}finally{l=1}}return{value:t,done:f}}}(n,o,i),!0),l}var a={};function u(){}function c(){}function l(){}t=Object.getPrototypeOf;var s=[][r]?t(t([][r]())):(g(t={},r,function(){return this}),t),f=l.prototype=u.prototype=Object.create(s);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,g(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return c.prototype=l,g(f,"constructor",l),g(l,"constructor",c),c.displayName="GeneratorFunction",g(l,o,"GeneratorFunction"),g(f),g(f,o,"Generator"),g(f,r,function(){return this}),g(f,"toString",function(){return"[object Generator]"}),(b=function(){return{w:i,m:d}})()}function g(e,t,n,r){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}g=function(e,t,n,r){function i(t,n){g(e,t,function(e){return this._invoke(t,n,e)})}t?o?o(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},g(e,t,n,r)}function h(e,t,n,r,o,i,a){try{var u=e[i](a),c=u.value}catch(e){return void n(e)}u.done?t(c):Promise.resolve(c).then(r,o)}function S(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){h(i,r,o,a,u,"next",e)}function u(e){h(i,r,o,a,u,"throw",e)}a(void 0)})}}function w(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?w(Object(n),!0).forEach(function(t){E(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):w(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function E(e,t,n){return(t=function(e){var t=function(e){if("object"!=v(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=v(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==v(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function P(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var O=function(){return new Promise(function(e,t){if(window.paypalInsight)e(window.paypalInsight);else{var n=setTimeout(function(){r.disconnect(),t(new Error("PayPal Insights script load timeout"))},1e4),r=new MutationObserver(function(){window.paypalInsight&&(r.disconnect(),clearTimeout(n),e(window.paypalInsight))});r.observe(document,{childList:!0,subtree:!0})}})};(0,e.registerPlugin)("wc-ppcp-paypal-insights",{render:function(){var e,r,o=function(){var e,n,r=(e=(0,t.useState)({initialized:!1,jsLoaded:!1,beginCheckout:!1,emailSubmitted:!1}),n=2,function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,a,u=[],c=!0,l=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=i.call(n)).done)&&(u.push(r.value),u.length!==t);c=!0);}catch(e){l=!0,o=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(e,n)||function(e,t){if(e){if("string"==typeof e)return P(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?P(e,t):void 0}}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),o=r[0],i=r[1],a=(0,t.useRef)(null),u=(0,t.useCallback)(function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];i(function(n){return _(_({},n),{},E({},e,t))})},[]);return{setEventTriggered:u,isEventTriggered:(0,t.useCallback)(function(e){return o[e]},[o]),setCurrentPaymentMethod:(0,t.useCallback)(function(e){a.current=e},[]),getCurrentPaymentMethod:(0,t.useCallback)(function(){return a.current},[])}}(),i=o.setEventTriggered,u=o.isEventTriggered,c=function(e){var n=y((0,t.useState)(!1),2),r=n[0],o=n[1],i=y((0,t.useState)(e),2),a=i[0],u=i[1];return(0,t.useEffect)(function(){var e=function(){void 0!==window.PayPalCommerceGateway?(u(window.PayPalCommerceGateway),o(!0)):function(e){var t,n,r,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",i=null===(t=window.wc_ppcp_axo)||void 0===t?void 0:t.wp_debug,a=null===(n=window.wc_ppcp_axo)||void 0===n||null===(n=n.ajax)||void 0===n||null===(n=n.frontend_logger)||void 0===n?void 0:n.endpoint,u=null===(r=window.wc_ppcp_axo)||void 0===r?void 0:r.logging_enabled;if(i)switch(o){case"error":console.error("[AXO] ".concat(e));break;case"warn":console.warn("[AXO] ".concat(e));break;default:console.log("[AXO] ".concat(e))}a&&u&&fetch(a,{method:"POST",credentials:"same-origin",body:JSON.stringify({nonce:window.wc_ppcp_axo.ajax.frontend_logger.nonce,log:{message:e,level:o}})})}("PayPal Commerce Gateway config not loaded.","error")};return"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e(),function(){document.removeEventListener("DOMContentLoaded",e)}},[]),{isConfigLoaded:r,ppcpConfig:a}}((null===(e=window)||void 0===e||null===(e=e.wc)||void 0===e||null===(e=e.wcSettings)||void 0===e?void 0:e.getSetting("".concat("ppcp-axo-gateway","_data")))||{}).ppcpConfig,l=null===(r=window)||void 0===r?void 0:r.wc_ppcp_axo,s=(0,n.useSelect)(function(e){var t,n,r=e(f);return{isEmailSubmitted:null!==(t=null==r||null===(n=r.getIsEmailSubmitted)||void 0===n?void 0:n.call(r))&&void 0!==t&&t}},[]).isEmailSubmitted;return function(e,n,r){var o=r.setEventTriggered,i=r.isEventTriggered,u=(0,t.useRef)(!1);(0,t.useEffect)(function(){var t,n,r;if(null!=e&&null!==(t=e.insights)&&void 0!==t&&t.enabled&&null!=e&&null!==(n=e.insights)&&void 0!==n&&n.client_id&&null!=e&&null!==(r=e.insights)&&void 0!==r&&r.session_id&&!u.current&&!i("initialized")){var c=function(){var t=S(b().m(function t(){var n;return b().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,O();case 1:if(!u.current){t.n=2;break}return t.a(2);case 2:a.trackJsLoad(),o("jsLoaded"),a.config(e.insights.client_id,{debug:"1"===(null==e?void 0:e.wp_debug)}),a.setSessionId(e.insights.session_id),u.current=!0,o("initialized"),i("jsLoaded")&&!i("beginCheckout")&&(a.trackBeginCheckout({amount:e.insights.amount,page_type:"checkout",user_data:{country:"US",is_store_member:!1}}),o("beginCheckout")),t.n=4;break;case 3:t.p=3,n=t.v,console.error("PayPal Insights initialization failed:",n);case 4:return t.a(2)}},t,null,[[0,3]])}));return function(){return t.apply(this,arguments)}}();return c(),function(){u.current=!1}}},[e,n,o,i])}(l,c,o),function(e,r){var o,i=r.setCurrentPaymentMethod,u=(0,t.useRef)(null),c=(0,t.useRef)(!0),l=(0,n.useSelect)(function(e){var t;return null===(t=e(window.wc.wcBlocksData.PAYMENT_STORE_KEY))||void 0===t?void 0:t.getActivePaymentMethod()},[]),s=(0,t.useCallback)(function(){var t=S(b().m(function t(n){var r,o;return b().w(function(t){for(;;)switch(t.p=t.n){case 0:if(n&&n!==u.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,O();case 2:!c.current&&u.current&&a.trackSelectPaymentMethod({payment_method_selected:(null==e||null===(r=e.insights)||void 0===r?void 0:r.payment_method_selected_map[n])||"other",page_type:"checkout"}),u.current=n,i(n),t.n=4;break;case 3:t.p=3,o=t.v,console.error("Failed to track payment method:",o);case 4:return t.a(2)}},t,null,[[1,3]])}));return function(_x){return t.apply(this,arguments)}}(),[null==e||null===(o=e.insights)||void 0===o?void 0:o.payment_method_selected_map,i]);(0,t.useEffect)(function(){l&&(c.current?(u.current=l,i(l),c.current=!1):s(l))},[l,s,i]),(0,t.useEffect)(function(){return function(){u.current=null,c.current=!0}},[])}(l,o),(0,t.useEffect)(function(){var e=function(){var e=S(b().m(function e(){var t;return b().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!s||u("emailSubmitted")){e.n=4;break}return e.p=1,e.n=2,O();case 2:a.trackSubmitCheckoutEmail(),i("emailSubmitted"),e.n=4;break;case 3:e.p=3,t=e.v,console.error("Failed to track email submission:",t);case 4:return e.a(2)}},e,null,[[1,3]])}));return function(){return e.apply(this,arguments)}}();e()},[s,i,u]),null},scope:"woocommerce-checkout"})})(); |