diff --git a/CHANGELOG.md b/CHANGELOG.md index b181501..9d0b853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 3.2.1 +- Shipping cost as separated parameter + # 3.2.0 - New payment methods: Bank Transfer, P24, Twint, Carte Bancaire, PostFinane diff --git a/composer.json b/composer.json index 56f05d9..b000446 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mediaopt/worldline", "description": "Worldline Online Payments", - "version": "3.2.0", + "version": "3.2.1", "type": "shopware-platform-plugin", "license": "proprietary", "config": { diff --git a/src/Adapter/WorldlineSDKAdapter.php b/src/Adapter/WorldlineSDKAdapter.php index 8b43bdd..29e4e5d 100644 --- a/src/Adapter/WorldlineSDKAdapter.php +++ b/src/Adapter/WorldlineSDKAdapter.php @@ -39,6 +39,7 @@ use OnlinePayments\Sdk\Domain\MerchantAction; use OnlinePayments\Sdk\Domain\Order; use OnlinePayments\Sdk\Domain\OrderLineDetails; +use OnlinePayments\Sdk\Domain\OrderReferences; use OnlinePayments\Sdk\Domain\PaymentDetailsResponse; use OnlinePayments\Sdk\Domain\PaymentProductFilter; use OnlinePayments\Sdk\Domain\PaymentProductFiltersHostedCheckout; @@ -52,6 +53,7 @@ use OnlinePayments\Sdk\Domain\RefundResponse; use OnlinePayments\Sdk\Domain\Shipping; use OnlinePayments\Sdk\Domain\ShoppingCart; +use OnlinePayments\Sdk\Domain\ShoppingCartExtension; use OnlinePayments\Sdk\Domain\ThreeDSecure; use OnlinePayments\Sdk\Merchant\MerchantClient; use Shopware\Core\Checkout\Cart\Price\Struct\CalculatedPrice; @@ -121,6 +123,13 @@ public function getMerchantClient(array $credentials = []): MerchantClient $credentials = $this->getCredentials(); } + $shoppingCartExtension = new ShoppingCartExtension( + MoptWorldline::PLUGIN_CREATOR, + MoptWorldline::PLUGIN_NAME, + MoptWorldline::PLUGIN_VERSION, + MoptWorldline::PLUGIN_ID + ); + $communicatorConfiguration = new CommunicatorConfiguration( $credentials['apiKey'], $credentials['apiSecret'], @@ -129,6 +138,8 @@ public function getMerchantClient(array $credentials = []): MerchantClient null ); + $communicatorConfiguration->setShoppingCartExtension($shoppingCartExtension); + $connection = new DefaultConnection(); $communicator = new Communicator($connection, $communicatorConfiguration); $client = new Client($communicator); @@ -192,6 +203,9 @@ public function createPayment( $order = new Order(); $order->setAmountOfMoney($amountOfMoney); + $orderRef = new OrderReferences(); + $orderRef->setMerchantReference($orderEntity->getOrderNumber()); + $order->setReferences($orderRef); $hostedCheckoutSpecificInput = new HostedCheckoutSpecificInput(); $ReturnUrlController = new ReturnUrlController($this->systemConfigService); @@ -376,7 +390,7 @@ public function createHostedTokenization(array $iframeData): GetHostedTokenizati * @param string $currencyISO * @param array $iframeData * @param GetHostedTokenizationResponse $hostedTokenization - * @param OrderEntity $orderEntity + * @param ?OrderEntity $orderEntity * @return CreatePaymentResponse * @throws \Exception */ @@ -385,7 +399,7 @@ public function createHostedTokenizationPayment( string $currencyISO, array $iframeData, GetHostedTokenizationResponse $hostedTokenization, - OrderEntity $orderEntity + ?OrderEntity $orderEntity ): CreatePaymentResponse { $token = $hostedTokenization->getToken()->getId(); @@ -702,6 +716,7 @@ private function addCartToRequest( $isNetPrice ) ); + $shipping->setShippingCost($orderEntity->getShippingCosts()->getTotalPrice() * 100); $order->setShoppingCart($shoppingCart); $order->setShipping($shipping); @@ -806,12 +821,6 @@ private function createRequestLineItems( if ($shippingPrice > 0) { $grandPrice += $shippingPrice; $grandCount++; - $shippingElementId = 'shipping_element'; - if ($maxPrices['unit']['price'] < $shippingPrice) { - $maxPrices['unit']['price'] = $shippingPrice; - $maxPrices['unit']['id'] = $shippingElementId; - } - $requestLineItems[$shippingElementId] = self::createLineItem(self::SHIPPING_LABEL, $currencyISO, $shippingPrice, $shippingPrice, 1); } if ($discount > 0) { diff --git a/src/MoptWorldline.php b/src/MoptWorldline.php index c53d357..d6776bb 100644 --- a/src/MoptWorldline.php +++ b/src/MoptWorldline.php @@ -22,7 +22,9 @@ class MoptWorldline extends Plugin { const PLUGIN_NAME = 'MoptWorldline'; - const PLUGIN_VERSION = '3.2.0'; + const PLUGIN_VERSION = '3.2.1'; + const PLUGIN_ID = 'MoptWorldline'; + const PLUGIN_CREATOR = 'Mediaopt GmbH'; /** * @param InstallContext $installContext diff --git a/src/Resources/app/storefront/dist/storefront/js/mopt-worldline/mopt-worldline.js b/src/Resources/app/storefront/dist/storefront/js/mopt-worldline/mopt-worldline.js index 7f41317..8ca3186 100644 --- a/src/Resources/app/storefront/dist/storefront/js/mopt-worldline/mopt-worldline.js +++ b/src/Resources/app/storefront/dist/storefront/js/mopt-worldline/mopt-worldline.js @@ -1 +1 @@ -(()=>{"use strict";var e={857:e=>{var t=function(e){var t;return!!e&&"object"==typeof e&&"[object RegExp]"!==(t=Object.prototype.toString.call(e))&&"[object Date]"!==t&&e.$$typeof!==r},r="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function n(e,t){return!1!==t.clone&&t.isMergeableObject(e)?a(Array.isArray(e)?[]:{},e,t):e}function i(e,t,r){return e.concat(t).map(function(e){return n(e,r)})}function o(e){return Object.keys(e).concat(Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(t){return Object.propertyIsEnumerable.call(e,t)}):[])}function s(e,t){try{return t in e}catch(e){return!1}}function a(e,r,l){(l=l||{}).arrayMerge=l.arrayMerge||i,l.isMergeableObject=l.isMergeableObject||t,l.cloneUnlessOtherwiseSpecified=n;var c,d,u=Array.isArray(r);return u!==Array.isArray(e)?n(r,l):u?l.arrayMerge(e,r,l):(d={},(c=l).isMergeableObject(e)&&o(e).forEach(function(t){d[t]=n(e[t],c)}),o(r).forEach(function(t){(!s(e,t)||Object.hasOwnProperty.call(e,t)&&Object.propertyIsEnumerable.call(e,t))&&(s(e,t)&&c.isMergeableObject(r[t])?d[t]=(function(e,t){if(!t.customMerge)return a;var r=t.customMerge(e);return"function"==typeof r?r:a})(t,c)(e[t],r[t],c):d[t]=n(r[t],c))}),d)}a.all=function(e,t){if(!Array.isArray(e))throw Error("first argument should be an array");return e.reduce(function(e,r){return a(e,r,t)},{})},e.exports=a}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}(()=>{r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t}})(),(()=>{r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})}})(),(()=>{r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{class e{get(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"application/json",n=this._createPreparedRequest("GET",e,r);return this._sendRequest(n,null,t)}post(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";n=this._getContentType(t,n);let i=this._createPreparedRequest("POST",e,n);return this._sendRequest(i,t,r)}delete(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";n=this._getContentType(t,n);let i=this._createPreparedRequest("DELETE",e,n);return this._sendRequest(i,t,r)}patch(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";n=this._getContentType(t,n);let i=this._createPreparedRequest("PATCH",e,n);return this._sendRequest(i,t,r)}abort(){if(this._request)return this._request.abort()}_registerOnLoaded(e,t){t&&e.addEventListener("loadend",()=>{t(e.responseText,e)})}_sendRequest(e,t,r){return this._registerOnLoaded(e,r),e.send(t),e}_getContentType(e,t){return e instanceof FormData&&(t=!1),t}_createPreparedRequest(e,t,r){return this._request=new XMLHttpRequest,this._request.open(e,t),this._request.setRequestHeader("X-Requested-With","XMLHttpRequest"),r&&this._request.setRequestHeader("Content-type",r),this._request}constructor(){this._request=null}}var t=r(857),n=r.n(t);class i{static ucFirst(e){return e.charAt(0).toUpperCase()+e.slice(1)}static lcFirst(e){return e.charAt(0).toLowerCase()+e.slice(1)}static toDashCase(e){return e.replace(/([A-Z])/g,"-$1").replace(/^-/,"").toLowerCase()}static toLowerCamelCase(e,t){let r=i.toUpperCamelCase(e,t);return i.lcFirst(r)}static toUpperCamelCase(e,t){return t?e.split(t).map(e=>i.ucFirst(e.toLowerCase())).join(""):i.ucFirst(e.toLowerCase())}static parsePrimitive(e){try{return/^\d+(.|,)\d+$/.test(e)&&(e=e.replace(",",".")),JSON.parse(e)}catch(t){return e.toString()}}}class o{static isNode(e){return"object"==typeof e&&null!==e&&(e===document||e===window||e instanceof Node)}static hasAttribute(e,t){if(!o.isNode(e))throw Error("The element must be a valid HTML Node!");return"function"==typeof e.hasAttribute&&e.hasAttribute(t)}static getAttribute(e,t){let r=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(r&&!1===o.hasAttribute(e,t))throw Error('The required property "'.concat(t,'" does not exist!'));if("function"!=typeof e.getAttribute){if(r)throw Error("This node doesn't support the getAttribute function!");return}return e.getAttribute(t)}static getDataAttribute(e,t){let r=!(arguments.length>2)||void 0===arguments[2]||arguments[2],n=t.replace(/^data(|-)/,""),s=i.toLowerCamelCase(n,"-");if(!o.isNode(e)){if(r)throw Error("The passed node is not a valid HTML Node!");return}if(void 0===e.dataset){if(r)throw Error("This node doesn't support the dataset attribute!");return}let a=e.dataset[s];if(void 0===a){if(r)throw Error('The required data attribute "'.concat(t,'" does not exist on ').concat(e,"!"));return a}return i.parsePrimitive(a)}static querySelector(e,t){let r=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(r&&!o.isNode(e))throw Error("The parent node is not a valid HTML Node!");let n=e.querySelector(t)||!1;if(r&&!1===n)throw Error('The required element "'.concat(t,'" does not exist in parent node!'));return n}static querySelectorAll(e,t){let r=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(r&&!o.isNode(e))throw Error("The parent node is not a valid HTML Node!");let n=e.querySelectorAll(t);if(0===n.length&&(n=!1),r&&!1===n)throw Error('At least one item of "'.concat(t,'" must exist in parent node!'));return n}}class s{publish(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=new CustomEvent(e,{detail:t,cancelable:r});return this.el.dispatchEvent(n),n}subscribe(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=this,i=e.split("."),o=r.scope?t.bind(r.scope):t;if(r.once&&!0===r.once){let t=o;o=function(r){n.unsubscribe(e),t(r)}}return this.el.addEventListener(i[0],o),this.listeners.push({splitEventName:i,opts:r,cb:o}),!0}unsubscribe(e){let t=e.split(".");return this.listeners=this.listeners.reduce((e,r)=>([...r.splitEventName].sort().toString()===t.sort().toString()?this.el.removeEventListener(r.splitEventName[0],r.cb):e.push(r),e),[]),!0}reset(){return this.listeners.forEach(e=>{this.el.removeEventListener(e.splitEventName[0],e.cb)}),this.listeners=[],!0}get el(){return this._el}set el(e){this._el=e}get listeners(){return this._listeners}set listeners(e){this._listeners=e}constructor(e=document){this._el=e,e.$emitter=this,this._listeners=[]}}class a{init(){throw Error('The "init" method for the plugin "'.concat(this._pluginName,'" is not defined.'))}update(){}_init(){this._initialized||(this.init(),this._initialized=!0)}_update(){this._initialized&&this.update()}_mergeOptions(e){let t=i.toDashCase(this._pluginName),r=o.getDataAttribute(this.el,"data-".concat(t,"-config"),!1),s=o.getAttribute(this.el,"data-".concat(t,"-options"),!1),a=[this.constructor.options,this.options,e];r&&a.push(window.PluginConfigManager.get(this._pluginName,r));try{s&&a.push(JSON.parse(s))}catch(e){throw console.error(this.el),Error('The data attribute "data-'.concat(t,'-options" could not be parsed to json: ').concat(e.message))}return n().all(a.filter(e=>e instanceof Object&&!(e instanceof Array)).map(e=>e||{}))}_registerInstance(){window.PluginManager.getPluginInstancesFromElement(this.el).set(this._pluginName,this),window.PluginManager.getPlugin(this._pluginName,!1).get("instances").push(this)}_getPluginName(e){return e||(e=this.constructor.name),e}constructor(e,t={},r=!1){if(!o.isNode(e))throw Error("There is no valid element given.");this.el=e,this.$emitter=new s(this.el),this._pluginName=this._getPluginName(r),this.options=this._mergeOptions(t),this._initialized=!1,this._registerInstance(),this._init()}}window.PluginManager.register("WorldlineIframePlugin",class extends a{init(){if(null!==document.getElementById("moptWorldlinePageId")){if(this.page=document.getElementById("moptWorldlinePageId").value,this._client=new e,"cartConfirm"===this.page){this.changePaymentForm=document.getElementById("changePaymentForm"),this.changePaymentForm.addEventListener("change",e=>{e.preventDefault(),this._changePaymentForm()}),this.moptWorldlineSalesChannel=document.getElementById("moptWorldlineSalesChannelId"),this.moptWorldlineLocaleId=document.getElementById("moptWorldlineLocaleId"),this._client.get("/worldline_serverUrl?serverUrl="+document.URL);var t=document.getElementById("moptWorldlineShowIframe");null!==t&&t.value&&("1"===this._isRedirectToken()?this._initRedirectTokenMethod():this._initIframe()),this._client.get("/worldline_cardToken?worldline_cardToken=")}"account"===this.page&&(this.changeAccountPaymentForm=document.getElementById("moptWorldlinePageId").form,this.changeAccountPaymentForm.addEventListener("submit",e=>{e.preventDefault(),this._changeAccountPaymentForm()}),this._client.get("/worldline_accountCardToken?worldline_accountCardToken="))}}_initIframe(){this.tokenizationDiv="div-hosted-tokenization",this.savePaymentCardCheckbox=document.getElementById("moptWorldlineSavePaymentCard"),this.salesChannelId=this.moptWorldlineSalesChannel.value,this.localeId=this.moptWorldlineLocaleId.value,this.confirmForm=document.getElementById("confirmOrderForm");var e=this._getCurrentToken();this._client.get("/worldline_iframe?salesChannelId="+this.salesChannelId+"&token="+e+"&localeId="+this.localeId,this._setContent.bind(this),"application/json",!0),this.confirmForm.addEventListener("submit",e=>{e.preventDefault(),this._confirmOrderForm()})}_setContent(e){this.tokenizer=new Tokenizer(JSON.parse(e).url,this.tokenizationDiv,{hideCardholderName:!1,hideTokenFields:!0},this._getCurrentToken()),this.tokenizer.initialize()}_confirmOrderForm(){var e=!!this.savePaymentCardCheckbox&&this.savePaymentCardCheckbox.checked;this.tokenizer.submitTokenization({storePermanently:e}).then(e=>{e.success&&(this._createHiddenInput(this.confirmForm,"moptWorldlineHostedTokenizationId",e.hostedTokenizationId),this._createHiddenInput(this.confirmForm,"moptWorldlineBrowserDataColorDepth",screen.colorDepth),this._createHiddenInput(this.confirmForm,"moptWorldlineBrowserDataScreenHeight",screen.height),this._createHiddenInput(this.confirmForm,"moptWorldlineBrowserDataScreenWidth",screen.width),this._createHiddenInput(this.confirmForm,"moptWorldlineBrowserDataJavaEnabled",navigator.javaEnabled()),this._createHiddenInput(this.confirmForm,"moptWorldlineLocale",this.moptWorldlineLocaleId.value),this._createHiddenInput(this.confirmForm,"moptWorldlineUserAgent",navigator.userAgent),this._createHiddenInput(this.confirmForm,"moptWorldlineTimezoneOffsetUtcMinutes",new Date().getTimezoneOffset()),this.confirmForm.submit())})}_initRedirectTokenMethod(){this.confirmForm=document.getElementById("confirmOrderForm"),this._createHiddenInput(this.confirmForm,"moptWorldlineRedirectToken",this._getCurrentToken())}_createHiddenInput(e,t,r){var n=document.createElement("input");n.setAttribute("type","hidden"),n.setAttribute("name",t),n.setAttribute("value",r),e.appendChild(n)}_changePaymentForm(){var e=this._getCurrentToken();this._client.get("/worldline_cardToken?worldline_cardToken="+e);var t=!0,r=document.getElementById("moptWorldlineShowIframe");null!==r&&r.value&&null!==this.savePaymentCardCheckbox&&(t=!this.savePaymentCardCheckbox.checked),t&&this.changePaymentForm.submit()}_getCurrentToken(){var e=document.querySelector("#changePaymentForm input:checked"),t=e?e.attributes.rel:"";return t?t.value:""}_isRedirectToken(){var e=document.querySelector("#changePaymentForm input:checked"),t=e?e.attributes.redirect:"";return t?t.value:""}_getPaymentProductId(){var e=document.querySelector("#changePaymentForm input:checked"),t=e?e.attributes.product:"";return t?t.value:""}_changeAccountPaymentForm(){var e=this._getCurrentAccountToken();this._client.get("/worldline_accountCardToken?worldline_accountCardToken="+e,this._submit.bind(this),"application/json",!0)}_submit(e){this.changeAccountPaymentForm.submit()}_getCurrentAccountToken(){var e=document.getElementById("moptWorldlinePageId").form.querySelector("input:checked"),t=e?e.attributes.rel:"";return t?t.value:""}})})()})(); \ No newline at end of file +(()=>{"use strict";var e={857:e=>{var t=function(e){var t;return!!e&&"object"==typeof e&&"[object RegExp]"!==(t=Object.prototype.toString.call(e))&&"[object Date]"!==t&&e.$$typeof!==r},r="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function n(e,t){return!1!==t.clone&&t.isMergeableObject(e)?a(Array.isArray(e)?[]:{},e,t):e}function i(e,t,r){return e.concat(t).map(function(e){return n(e,r)})}function o(e){return Object.keys(e).concat(Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(t){return Object.propertyIsEnumerable.call(e,t)}):[])}function s(e,t){try{return t in e}catch(e){return!1}}function a(e,r,l){(l=l||{}).arrayMerge=l.arrayMerge||i,l.isMergeableObject=l.isMergeableObject||t,l.cloneUnlessOtherwiseSpecified=n;var c,d,u=Array.isArray(r);return u!==Array.isArray(e)?n(r,l):u?l.arrayMerge(e,r,l):(d={},(c=l).isMergeableObject(e)&&o(e).forEach(function(t){d[t]=n(e[t],c)}),o(r).forEach(function(t){(!s(e,t)||Object.hasOwnProperty.call(e,t)&&Object.propertyIsEnumerable.call(e,t))&&(s(e,t)&&c.isMergeableObject(r[t])?d[t]=(function(e,t){if(!t.customMerge)return a;var r=t.customMerge(e);return"function"==typeof r?r:a})(t,c)(e[t],r[t],c):d[t]=n(r[t],c))}),d)}a.all=function(e,t){if(!Array.isArray(e))throw Error("first argument should be an array");return e.reduce(function(e,r){return a(e,r,t)},{})},e.exports=a}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}(()=>{r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t}})(),(()=>{r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})}})(),(()=>{r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{class e{get(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"application/json",n=this._createPreparedRequest("GET",e,r);return this._sendRequest(n,null,t)}post(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";n=this._getContentType(t,n);let i=this._createPreparedRequest("POST",e,n);return this._sendRequest(i,t,r)}delete(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";n=this._getContentType(t,n);let i=this._createPreparedRequest("DELETE",e,n);return this._sendRequest(i,t,r)}patch(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";n=this._getContentType(t,n);let i=this._createPreparedRequest("PATCH",e,n);return this._sendRequest(i,t,r)}abort(){if(this._request)return this._request.abort()}setErrorHandlingInternal(e){this._errorHandlingInternal=e}_registerOnLoaded(e,t){t&&(!0===this._errorHandlingInternal?(e.addEventListener("load",()=>{t(e.responseText,e)}),e.addEventListener("abort",()=>{console.warn("the request to ".concat(e.responseURL," was aborted"))}),e.addEventListener("error",()=>{console.warn("the request to ".concat(e.responseURL," failed with status ").concat(e.status))}),e.addEventListener("timeout",()=>{console.warn("the request to ".concat(e.responseURL," timed out"))})):e.addEventListener("loadend",()=>{t(e.responseText,e)}))}_sendRequest(e,t,r){return this._registerOnLoaded(e,r),e.send(t),e}_getContentType(e,t){return e instanceof FormData&&(t=!1),t}_createPreparedRequest(e,t,r){return this._request=new XMLHttpRequest,this._request.open(e,t),this._request.setRequestHeader("X-Requested-With","XMLHttpRequest"),r&&this._request.setRequestHeader("Content-type",r),this._request}constructor(){this._request=null,this._errorHandlingInternal=!1}}var t=r(857),n=r.n(t);class i{static ucFirst(e){return e.charAt(0).toUpperCase()+e.slice(1)}static lcFirst(e){return e.charAt(0).toLowerCase()+e.slice(1)}static toDashCase(e){return e.replace(/([A-Z])/g,"-$1").replace(/^-/,"").toLowerCase()}static toLowerCamelCase(e,t){let r=i.toUpperCamelCase(e,t);return i.lcFirst(r)}static toUpperCamelCase(e,t){return t?e.split(t).map(e=>i.ucFirst(e.toLowerCase())).join(""):i.ucFirst(e.toLowerCase())}static parsePrimitive(e){try{return/^\d+(.|,)\d+$/.test(e)&&(e=e.replace(",",".")),JSON.parse(e)}catch(t){return e.toString()}}}class o{static isNode(e){return"object"==typeof e&&null!==e&&(e===document||e===window||e instanceof Node)}static hasAttribute(e,t){if(!o.isNode(e))throw Error("The element must be a valid HTML Node!");return"function"==typeof e.hasAttribute&&e.hasAttribute(t)}static getAttribute(e,t){let r=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(r&&!1===o.hasAttribute(e,t))throw Error('The required property "'.concat(t,'" does not exist!'));if("function"!=typeof e.getAttribute){if(r)throw Error("This node doesn't support the getAttribute function!");return}return e.getAttribute(t)}static getDataAttribute(e,t){let r=!(arguments.length>2)||void 0===arguments[2]||arguments[2],n=t.replace(/^data(|-)/,""),s=i.toLowerCamelCase(n,"-");if(!o.isNode(e)){if(r)throw Error("The passed node is not a valid HTML Node!");return}if(void 0===e.dataset){if(r)throw Error("This node doesn't support the dataset attribute!");return}let a=e.dataset[s];if(void 0===a){if(r)throw Error('The required data attribute "'.concat(t,'" does not exist on ').concat(e,"!"));return a}return i.parsePrimitive(a)}static querySelector(e,t){let r=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(r&&!o.isNode(e))throw Error("The parent node is not a valid HTML Node!");let n=e.querySelector(t)||!1;if(r&&!1===n)throw Error('The required element "'.concat(t,'" does not exist in parent node!'));return n}static querySelectorAll(e,t){let r=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(r&&!o.isNode(e))throw Error("The parent node is not a valid HTML Node!");let n=e.querySelectorAll(t);if(0===n.length&&(n=!1),r&&!1===n)throw Error('At least one item of "'.concat(t,'" must exist in parent node!'));return n}static getFocusableElements(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.body;return e.querySelectorAll('\n input:not([tabindex^="-"]):not([disabled]):not([type="hidden"]),\n select:not([tabindex^="-"]):not([disabled]),\n textarea:not([tabindex^="-"]):not([disabled]),\n button:not([tabindex^="-"]):not([disabled]),\n a[href]:not([tabindex^="-"]):not([disabled]),\n [tabindex]:not([tabindex^="-"]):not([disabled])\n ')}static getFirstFocusableElement(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.body;return this.getFocusableElements(e)[0]}static getLastFocusableElement(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,t=this.getFocusableElements(e);return t[t.length-1]}}class s{publish(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=new CustomEvent(e,{detail:t,cancelable:r});return this.el.dispatchEvent(n),n}subscribe(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=this,i=e.split("."),o=r.scope?t.bind(r.scope):t;if(r.once&&!0===r.once){let t=o;o=function(r){n.unsubscribe(e),t(r)}}return this.el.addEventListener(i[0],o),this.listeners.push({splitEventName:i,opts:r,cb:o}),!0}unsubscribe(e){let t=e.split(".");return this.listeners=this.listeners.reduce((e,r)=>([...r.splitEventName].sort().toString()===t.sort().toString()?this.el.removeEventListener(r.splitEventName[0],r.cb):e.push(r),e),[]),!0}reset(){return this.listeners.forEach(e=>{this.el.removeEventListener(e.splitEventName[0],e.cb)}),this.listeners=[],!0}get el(){return this._el}set el(e){this._el=e}get listeners(){return this._listeners}set listeners(e){this._listeners=e}constructor(e=document){this._el=e,e.$emitter=this,this._listeners=[]}}class a{init(){throw Error('The "init" method for the plugin "'.concat(this._pluginName,'" is not defined.'))}update(){}_init(){this._initialized||(this.init(),this._initialized=!0)}_update(){this._initialized&&this.update()}_mergeOptions(e){let t=i.toDashCase(this._pluginName),r=o.getDataAttribute(this.el,"data-".concat(t,"-config"),!1),s=o.getAttribute(this.el,"data-".concat(t,"-options"),!1),a=[this.constructor.options,this.options,e];r&&a.push(window.PluginConfigManager.get(this._pluginName,r));try{s&&a.push(JSON.parse(s))}catch(e){throw console.error(this.el),Error('The data attribute "data-'.concat(t,'-options" could not be parsed to json: ').concat(e.message))}return n().all(a.filter(e=>e instanceof Object&&!(e instanceof Array)).map(e=>e||{}))}_registerInstance(){window.PluginManager.getPluginInstancesFromElement(this.el).set(this._pluginName,this),window.PluginManager.getPlugin(this._pluginName,!1).get("instances").push(this)}_getPluginName(e){return e||(e=this.constructor.name),e}constructor(e,t={},r=!1){if(!o.isNode(e))throw Error("There is no valid element given.");this.el=e,this.$emitter=new s(this.el),this._pluginName=this._getPluginName(r),this.options=this._mergeOptions(t),this._initialized=!1,this._registerInstance(),this._init()}}window.PluginManager.register("WorldlineIframePlugin",class extends a{init(){if(null!==document.getElementById("moptWorldlinePageId")){if(this.page=document.getElementById("moptWorldlinePageId").value,this._client=new e,"cartConfirm"===this.page){this.changePaymentForm=document.getElementById("changePaymentForm"),this.changePaymentForm.addEventListener("change",e=>{e.preventDefault(),this._changePaymentForm()}),this.moptWorldlineSalesChannel=document.getElementById("moptWorldlineSalesChannelId"),this.moptWorldlineLocaleId=document.getElementById("moptWorldlineLocaleId"),this._client.get("/worldline_serverUrl?serverUrl="+document.URL);var t=document.getElementById("moptWorldlineShowIframe");null!==t&&t.value&&("1"===this._isRedirectToken()?this._initRedirectTokenMethod():this._initIframe()),this._client.get("/worldline_cardToken?worldline_cardToken=")}"account"===this.page&&(this.changeAccountPaymentForm=document.getElementById("moptWorldlinePageId").form,this.changeAccountPaymentForm.addEventListener("submit",e=>{e.preventDefault(),this._changeAccountPaymentForm()}),this._client.get("/worldline_accountCardToken?worldline_accountCardToken="))}}_initIframe(){this.tokenizationDiv="div-hosted-tokenization",this.savePaymentCardCheckbox=document.getElementById("moptWorldlineSavePaymentCard"),this.salesChannelId=this.moptWorldlineSalesChannel.value,this.localeId=this.moptWorldlineLocaleId.value,this.confirmForm=document.getElementById("confirmOrderForm");var e=this._getCurrentToken();this._client.get("/worldline_iframe?salesChannelId="+this.salesChannelId+"&token="+e+"&localeId="+this.localeId,this._setContent.bind(this),"application/json",!0),this.confirmForm.addEventListener("submit",e=>{e.preventDefault(),this._confirmOrderForm()})}_setContent(e){this.tokenizer=new Tokenizer(JSON.parse(e).url,this.tokenizationDiv,{hideCardholderName:!1,hideTokenFields:!0},this._getCurrentToken()),this.tokenizer.initialize()}_confirmOrderForm(){var e=!!this.savePaymentCardCheckbox&&this.savePaymentCardCheckbox.checked;this.tokenizer.submitTokenization({storePermanently:e}).then(e=>{e.success&&(this._createHiddenInput(this.confirmForm,"moptWorldlineHostedTokenizationId",e.hostedTokenizationId),this._createHiddenInput(this.confirmForm,"moptWorldlineBrowserDataColorDepth",screen.colorDepth),this._createHiddenInput(this.confirmForm,"moptWorldlineBrowserDataScreenHeight",screen.height),this._createHiddenInput(this.confirmForm,"moptWorldlineBrowserDataScreenWidth",screen.width),this._createHiddenInput(this.confirmForm,"moptWorldlineBrowserDataJavaEnabled",navigator.javaEnabled()),this._createHiddenInput(this.confirmForm,"moptWorldlineLocale",this.moptWorldlineLocaleId.value),this._createHiddenInput(this.confirmForm,"moptWorldlineUserAgent",navigator.userAgent),this._createHiddenInput(this.confirmForm,"moptWorldlineTimezoneOffsetUtcMinutes",new Date().getTimezoneOffset()),this.confirmForm.submit())})}_initRedirectTokenMethod(){this.confirmForm=document.getElementById("confirmOrderForm"),this._createHiddenInput(this.confirmForm,"moptWorldlineRedirectToken",this._getCurrentToken())}_createHiddenInput(e,t,r){var n=document.createElement("input");n.setAttribute("type","hidden"),n.setAttribute("name",t),n.setAttribute("value",r),e.appendChild(n)}_changePaymentForm(){var e=this._getCurrentToken();this._client.get("/worldline_cardToken?worldline_cardToken="+e);var t=!0,r=document.getElementById("moptWorldlineShowIframe");null!==r&&r.value&&null!==this.savePaymentCardCheckbox&&(t=!this.savePaymentCardCheckbox.checked),t&&this.changePaymentForm.submit()}_getCurrentToken(){var e=document.querySelector("#changePaymentForm input:checked"),t=e?e.attributes.rel:"";return t?t.value:""}_isRedirectToken(){var e=document.querySelector("#changePaymentForm input:checked"),t=e?e.attributes.redirect:"";return t?t.value:""}_getPaymentProductId(){var e=document.querySelector("#changePaymentForm input:checked"),t=e?e.attributes.product:"";return t?t.value:""}_changeAccountPaymentForm(){var e=this._getCurrentAccountToken();this._client.get("/worldline_accountCardToken?worldline_accountCardToken="+e,this._submit.bind(this),"application/json",!0)}_submit(e){this.changeAccountPaymentForm.submit()}_getCurrentAccountToken(){var e=document.getElementById("moptWorldlinePageId").form.querySelector("input:checked"),t=e?e.attributes.rel:"";return t?t.value:""}})})()})(); \ No newline at end of file diff --git a/src/Service/PaymentHandler.php b/src/Service/PaymentHandler.php index 740d69c..b2eb145 100644 --- a/src/Service/PaymentHandler.php +++ b/src/Service/PaymentHandler.php @@ -245,7 +245,7 @@ public function capturePayment(string $hostedCheckoutId, int $amount, array $ite $amounts = []; $log = []; $isFinal = ($amount == $customFields[Form::CUSTOM_FIELD_WORLDLINE_PAYMENT_TRANSACTION_CAPTURE_AMOUNT]); - /* if ($amount != 0 && !OrderHelper::isOrderLocked($customFields)) { + if ($amount != 0 && !OrderHelper::isOrderLocked($customFields)) { $captureResponse = $this->adapter->capturePayment($hostedCheckoutId, $amount, $isFinal); $this->logger->paymentLog($this->order->getOrderNumber(), 'capturePayment', 0, $captureResponse->toJson()); $newStatus = $captureResponse->getStatusOutput()->getStatusCode(); @@ -264,14 +264,14 @@ public function capturePayment(string $hostedCheckoutId, int $amount, array $ite $log, $orderItemsStatus ); - $this->updateOrderTransactionState($newStatus, $hostedCheckoutId, $isFinal);*/ + $this->updateOrderTransactionState($newStatus, $hostedCheckoutId, $isFinal); $message = $this->getSuccessMessage($isFinal, $hostedCheckoutId, 'capturePayment'); - /*if ((!in_array($newStatus, Payment::STATUS_CAPTURE_REQUESTED) + if ((!in_array($newStatus, Payment::STATUS_CAPTURE_REQUESTED) && !in_array($newStatus, Payment::STATUS_CAPTURED)) && $amount > 0) { return [false, 'failed']; - }*/ + } return [true, $message]; } diff --git a/src/Subscriber/CheckoutSubscriber.php b/src/Subscriber/CheckoutSubscriber.php index 0e3b6d4..4dca701 100644 --- a/src/Subscriber/CheckoutSubscriber.php +++ b/src/Subscriber/CheckoutSubscriber.php @@ -59,7 +59,7 @@ public function storefrontRenderEvent(StorefrontRenderEvent $event): void private function isCheckoutPage($event): bool { $route = $event->getRequest()->attributes->get('_route'); - if (in_array($route, ['frontend.checkout.confirm.page', 'frontend.checkout.cart.page'])) { + if (in_array($route, ['frontend.checkout.confirm.page', 'frontend.checkout.cart.page', 'frontend.account.edit-order.page'])) { return true; } return false;