diff --git a/.gitignore b/.gitignore index 1cb06a589..024717eb3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ src/Resources/public/administration/swag-pay-pal.*.hot-update.js phpstan.neon var/ composer.lock +node_modules diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 034df874b..c28e49b18 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -45,6 +45,7 @@ Check built JS files: - php bin/console plugin:install --activate SwagPayPal - ./psh.phar storefront:install-dependencies - ./psh.phar administration:build + - npm --prefix custom/plugins/SwagPayPal/src/Resources/app/storefront/ clean-install - ./psh.phar storefront:build - cd $CI_PROJECT_DIR/development/custom/plugins/SwagPayPal - > @@ -88,6 +89,7 @@ Static validation: cd $CI_PROJECT_DIR/development ./psh.phar administration:init --APP_ENV="dev" cd $CI_PROJECT_DIR/development/custom/plugins/SwagPayPal + npm --prefix src/Resources/app/storefront/ clean-install make administration-lint make storefront-lint fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 41cfa5b94..bb68f3ca3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # REPLACE_GLOBALLY_WITH_NEXT_VERSION - PPI-5 - Implement Set PayPal as default pamyent method in First Run Wizard - PPI-77 - Replaced snippets in administration by `global.defaults` +- PPI-293 - Improved PayPal script loading in Storefront - PPI-330 - Improve Zettle decimal precision behavior # 3.4.0 diff --git a/CHANGELOG_de-DE.md b/CHANGELOG_de-DE.md index 8bbd36b9b..cab8ffc97 100644 --- a/CHANGELOG_de-DE.md +++ b/CHANGELOG_de-DE.md @@ -1,6 +1,7 @@ # REPLACE_GLOBALLY_WITH_NEXT_VERSION - PPI-5 - Setzen von PayPal als Standardzahlungsart im Ersteinrichtungs-Assistent implementiert - PPI-77 - Ersetzt Snippets in der Administration durch `global.defaults` +- PPI-293 - Skript-Ladevorgang in der Storefront verbessert - PPI-330 - Verbessert Nachkommastellen-Verhalten der Zettle-Synchronisation # 3.4.0 diff --git a/src/Resources/app/storefront/build/webpack.config.js b/src/Resources/app/storefront/build/webpack.config.js new file mode 100644 index 000000000..e0df20c10 --- /dev/null +++ b/src/Resources/app/storefront/build/webpack.config.js @@ -0,0 +1,13 @@ +const { join, resolve } = require('path'); + +module.exports = () => { + return { + resolve: { + alias: { + '@paypal': resolve( + join(__dirname, '..', 'node_modules', '@paypal'), + ), + }, + }, + }; +}; diff --git a/src/Resources/app/storefront/dist/storefront/js/swag-pay-pal.js b/src/Resources/app/storefront/dist/storefront/js/swag-pay-pal.js index 91a0138ab..c33e2e5bd 100644 --- a/src/Resources/app/storefront/dist/storefront/js/swag-pay-pal.js +++ b/src/Resources/app/storefront/dist/storefront/js/swag-pay-pal.js @@ -1 +1,2 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([["swag-pay-pal"],{"5eYc":function(t,e,n){"use strict";(function(t){n.d(e,"a",(function(){return y}));var o=n("gHbT");function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var n=0;n0&&(t+="&disable-funding=".concat(this.options.disabledAlternativePaymentMethods.join(","))):t+="&disable-funding=".concat(h.join(",")),t}},{key:"createError",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",o=this.options.addErrorUrl,i={_csrf_token:r.a.getDataAttribute(this.el,"data-swag-pay-pal-add-error-token"),error:t,cancel:e};this._client.post(o,JSON.stringify(i),(function(){n?window.location=n:(window.onbeforeunload=function(){window.scrollTo(0,0)},window.location.reload())}))}}])&&u(n.prototype,o),i&&u(n,i),e}(o.a);f=b,y="scriptLoading",d=new i.a,y in f?Object.defineProperty(f,y,{value:d,enumerable:!0,configurable:!0,writable:!0}):f[y]=d},dkCy:function(t,e,n){"use strict";n.r(e);var o=n("p4AR"),r=n("gHbT"),i=n("u0Tz"),a=n("LkB+"),c=n("CiWO");function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function l(t,e){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:{attributes:!0},i=function(t){var r=!0,i=!1,a=void 0;try{for(var c,u=t[Symbol.iterator]();!(r=(c=u.next()).done);r=!0)if("disabled"===c.value.attributeName){if(o.getBuyButtonState().disabled)return void n();e()}}catch(t){i=!0,a=t}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}},a=new MutationObserver(i);return a.observe(t,r),a}},{key:"getButtonConfig",value:function(){var t=this,e=this.el,n=this.getBuyButtonState(),o=n.element,r=n.disabled;return{onInit:function(n,i){if(t.options.addProductToCart){var a=function(){i.enable(),e.classList.remove(t.options.disabledClass)},c=function(){i.disable(),e.classList.add(t.options.disabledClass)};t.observeBuyButton(o,a,c),r?c():a()}},style:{size:this.options.buttonSize,shape:this.options.buttonShape,color:this.options.buttonColor,tagline:this.options.tagline,layout:"horizontal",label:"checkout",height:40},createOrder:this.createOrder.bind(this),onApprove:this.onApprove.bind(this),onCancel:this.onCancel.bind(this),onError:this.onError.bind(this)}}},{key:"createOrder",value:function(){var t=this,e={paymentMethodId:this.options.payPaLPaymentMethodId};return new Promise((function(n,o){t._client.patch(t.options.contextSwitchUrl,JSON.stringify(e),(function(e,r){return r.status>=400&&o(e),Promise.resolve().then((function(){return t.options.addProductToCart?t.addProductToCart():Promise.resolve()})).then((function(){return t._createOrder()})).then((function(t){n(t)})).catch((function(t){o(t)}))}))}))}},{key:"_createOrder",value:function(){var t=this;return new Promise((function(e,n){t._client.post(t.options.createOrderUrl,new FormData,(function(t,o){o.status>=400&&n(t);try{var r=JSON.parse(t);e(r.token)}catch(t){n(t)}}))}))}},{key:"addProductToCart",value:function(){var t=this,e=this.el.closest("form"),n=r.a.querySelector(e,this.options.buyButtonSelector),o=window.PluginManager.getPluginInstanceFromElement(e,"AddToCart");return new Promise((function(e){t._client.delete(t.options.deleteCartUrl,null,(function(){o.$emitter.subscribe("openOffCanvasCart",(function(){e()})),n.click()}))}))}},{key:"onApprove",value:function(t,e){var n=this,o={token:t.orderID};i.a.create(document.body),this._client.post(this.options.prepareCheckoutUrl,JSON.stringify(o),(function(t,o){return o.status<400?e.redirect(n.options.checkoutConfirmUrl):n.createError(t,!1,n.options.cancelRedirectUrl)}))}},{key:"onError",value:function(t){this.createError(t)}},{key:"onCancel",value:function(t){this.createError(t,!0,this.options.cancelRedirectUrl)}}])&&l(n.prototype,a),c&&l(n,c),e}(a.a);d(h,"scriptLoading",new c.a),d(h,"options",{disabledClass:"is-disabled",buyButtonSelector:".btn-buy",buttonColor:"gold",buttonShape:"rect",buttonSize:"small",languageIso:"en_GB",clientId:"",currency:"EUR",intent:"capture",commit:!1,tagline:!1,addProductToCart:!1,contextSwitchUrl:"",payPaLPaymentMethodId:"",createOrderUrl:"",deleteCartUrl:"",prepareCheckoutUrl:"",checkoutConfirmUrl:"",addErrorUrl:"",cancelRedirectUrl:""});var b=n("2Y4b"),m=n("3xtq");function v(t){return(v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function g(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function w(t,e){for(var n=0;n=400&&o(t);try{var r=JSON.parse(t);n(r.token)}catch(t){o(t)}}))}))}},{key:"onApprove",value:function(t){m.a.create();var e=document.createElement("input");e.setAttribute("type","hidden"),e.setAttribute("name","paypalOrderId"),e.setAttribute("value",t.orderID),this.confirmOrderForm.appendChild(e),this.confirmOrderForm.submit()}},{key:"onCancel",value:function(){this.createError(null,!0)}},{key:"onClick",value:function(t,e){return this.confirmOrderForm.checkValidity()?e.resolve():e.reject()}},{key:"onError",value:function(t){this.createError(t)}}])&&w(n.prototype,i),a&&w(n,a),e}(a.a);function E(t){return(E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function B(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function I(t,e){for(var n=0;n1?(n="*",o=t.toString()):n=t.toString():"string"==typeof t&&t.length>0?n=t:"string"==typeof e&&e.length>0&&(n="*",o=e);return{"merchant-id":n,"data-merchant-id":o}}(t["merchant-id"],t["data-merchant-id"]),o=Object.assign({},t,n),r=Object.keys(o).filter((function(t){return void 0!==o[t]&&null!==o[t]&&""!==o[t]})).reduce((function(t,e){var n=o[e].toString();return"data-"===e.substring(0,5)?t.dataAttributes[e]=n:t.queryParams[e]=n,t}),{queryParams:{},dataAttributes:{}}),i=r.queryParams,c=r.dataAttributes;return{url:e+"?"+a(i),dataAttributes:c}}function a(t){var e="";return Object.keys(t).forEach((function(n){0!==e.length&&(e+="&"),e+=n+"="+t[n]})),e}function c(t,e){void 0===e&&(e={});var n=document.createElement("script");return n.src=t,Object.keys(e).forEach((function(t){n.setAttribute(t,e[t]),"data-csp-nonce"===t&&n.setAttribute("nonce",e["data-csp-nonce"])})),n}function u(t,e){if(void 0===e&&(e=s()),p(t,e),"undefined"==typeof window)return e.resolve(null);var n=i(t),o=n.url,r=n.dataAttributes,a=r["data-namespace"]||"paypal",u=l(a);return function(t,e){var n=document.querySelector('script[src="'+t+'"]');if(null===n)return null;var o=c(t,e),r=Object.assign({},n.dataset);if(delete r.uidAuto,Object.keys(r).length!==Object.keys(o.dataset).length)return null;var i=!0;return Object.keys(r).forEach((function(t){r[t]!==o.dataset[t]&&(i=!1)})),i?n:null}(o,r)&&u?e.resolve(u):function(t,e){void 0===e&&(e=s());p(t,e);var n=t.url,o=t.attributes;if("string"!=typeof n||0===n.length)throw new Error("Invalid url.");if(void 0!==o&&"object"!=typeof o)throw new Error("Expected attributes to be an object.");return new e((function(t,e){if("undefined"==typeof window)return t();!function(t){var e=t.url,n=t.attributes,o=t.onSuccess,r=t.onError,i=c(e,n);i.onerror=r,i.onload=o,document.head.insertBefore(i,document.head.firstElementChild)}({url:n,attributes:o,onSuccess:function(){return t()},onError:function(){return e(new Error('The script "'+n+'" failed to load.'))}})}))}({url:o,attributes:r},e).then((function(){var t=l(a);if(t)return t;throw new Error("The window."+a+" global variable is not available.")}))}function s(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function l(t){return window[t]}function p(t,e){if("object"!=typeof t||null===t)throw new Error("Expected an options object.");if(void 0!==e&&"function"!=typeof e)throw new Error("Expected PromisePonyfill to be a function.")}var f=n("CiWO");function d(t){return(d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function y(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function h(t,e){for(var n=0;n0&&(t+="&disable-funding=".concat(this.options.disabledAlternativePaymentMethods.join(","))):t+="&disable-funding=".concat(P.join(",")),t}},{key:"createError",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",o=this.options.addErrorUrl,i={_csrf_token:r.a.getDataAttribute(this.el,"data-swag-pay-pal-add-error-token"),error:t,cancel:e};this._client.post(o,JSON.stringify(i),(function(){n?window.location=n:(window.onbeforeunload=function(){window.scrollTo(0,0)},window.location.reload())}))}}])&&h(n.prototype,o),i&&h(n,i),e}(o.a);g=S,w="scriptLoading",O=new f.a,w in g?Object.defineProperty(g,w,{value:O,enumerable:!0,configurable:!0,writable:!0}):g[w]=O},dkCy:function(t,e,n){"use strict";n.r(e);var o=n("p4AR"),r=n("gHbT"),i=n("u0Tz"),a=n("LkB+"),c=n("CiWO");function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function l(t,e){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:{attributes:!0},i=function(t){var r=!0,i=!1,a=void 0;try{for(var c,u=t[Symbol.iterator]();!(r=(c=u.next()).done);r=!0)if("disabled"===c.value.attributeName){if(o.getBuyButtonState().disabled)return void n();e()}}catch(t){i=!0,a=t}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}},a=new MutationObserver(i);return a.observe(t,r),a}},{key:"getButtonConfig",value:function(){var t=this,e=this.el,n=this.getBuyButtonState(),o=n.element,r=n.disabled;return{onInit:function(n,i){if(t.options.addProductToCart){var a=function(){i.enable(),e.classList.remove(t.options.disabledClass)},c=function(){i.disable(),e.classList.add(t.options.disabledClass)};t.observeBuyButton(o,a,c),r?c():a()}},style:{size:this.options.buttonSize,shape:this.options.buttonShape,color:this.options.buttonColor,tagline:this.options.tagline,layout:"horizontal",label:"checkout",height:40},createOrder:this.createOrder.bind(this),onApprove:this.onApprove.bind(this),onCancel:this.onCancel.bind(this),onError:this.onError.bind(this)}}},{key:"createOrder",value:function(){var t=this,e={paymentMethodId:this.options.payPaLPaymentMethodId};return new Promise((function(n,o){t._client.patch(t.options.contextSwitchUrl,JSON.stringify(e),(function(e,r){return r.status>=400&&o(e),Promise.resolve().then((function(){return t.options.addProductToCart?t.addProductToCart():Promise.resolve()})).then((function(){return t._createOrder()})).then((function(t){n(t)})).catch((function(t){o(t)}))}))}))}},{key:"_createOrder",value:function(){var t=this;return new Promise((function(e,n){t._client.post(t.options.createOrderUrl,new FormData,(function(t,o){o.status>=400&&n(t);try{var r=JSON.parse(t);e(r.token)}catch(t){n(t)}}))}))}},{key:"addProductToCart",value:function(){var t=this,e=this.el.closest("form"),n=r.a.querySelector(e,this.options.buyButtonSelector),o=window.PluginManager.getPluginInstanceFromElement(e,"AddToCart");return new Promise((function(e){t._client.delete(t.options.deleteCartUrl,null,(function(){o.$emitter.subscribe("openOffCanvasCart",(function(){e()})),n.click()}))}))}},{key:"onApprove",value:function(t,e){var n=this,o={token:t.orderID};i.a.create(document.body),this._client.post(this.options.prepareCheckoutUrl,JSON.stringify(o),(function(t,o){return o.status<400?e.redirect(n.options.checkoutConfirmUrl):n.createError(t,!1,n.options.cancelRedirectUrl)}))}},{key:"onError",value:function(t){this.createError(t)}},{key:"onCancel",value:function(t){this.createError(t,!0,this.options.cancelRedirectUrl)}}])&&l(n.prototype,a),c&&l(n,c),e}(a.a);y(h,"scriptLoading",new c.a),y(h,"options",{disabledClass:"is-disabled",buyButtonSelector:".btn-buy",buttonColor:"gold",buttonShape:"rect",buttonSize:"small",languageIso:"en_GB",clientId:"",currency:"EUR",intent:"capture",commit:!1,tagline:!1,addProductToCart:!1,contextSwitchUrl:"",payPaLPaymentMethodId:"",createOrderUrl:"",deleteCartUrl:"",prepareCheckoutUrl:"",checkoutConfirmUrl:"",addErrorUrl:"",cancelRedirectUrl:""});var b=n("2Y4b"),m=n("3xtq");function v(t){return(v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function g(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function w(t,e){for(var n=0;n=400&&o(t);try{var r=JSON.parse(t);n(r.token)}catch(t){o(t)}}))}))}},{key:"onApprove",value:function(t){m.a.create();var e=document.createElement("input");e.setAttribute("type","hidden"),e.setAttribute("name","paypalOrderId"),e.setAttribute("value",t.orderID),this.confirmOrderForm.appendChild(e),this.confirmOrderForm.submit()}},{key:"onCancel",value:function(){this.createError(null,!0)}},{key:"onClick",value:function(t,e){return this.confirmOrderForm.checkValidity()?e.resolve():e.reject()}},{key:"onError",value:function(t){this.createError(t)}}])&&w(n.prototype,i),a&&w(n,a),e}(a.a);function E(t){return(E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function B(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function I(t,e){for(var n=0;n