From 976ef33e97a90c0f3a401a2b226d303dcc665b0f Mon Sep 17 00:00:00 2001 From: paeddl Date: Wed, 15 Apr 2026 17:06:47 +0200 Subject: [PATCH] v6.5.6 --- CHANGELOG_de-DE.md | 7 +++ CHANGELOG_en-GB.md | 7 +++ composer.json | 2 +- .../UnzerGooglePayPaymentHandler.php | 2 +- .../PaymentResourceHydrator.php | 2 +- .../Storefront/ExtensionFactory.php | 18 +++++-- .../Confirm/UnzerDataPageExtension.php | 1 + .../UnzerPaymentDeviceController.php | 3 -- .../Checkout/ConfirmPageEventListener.php | 8 --- src/Installer/PaymentInstaller.php | 4 +- .../unzer-payment-settings.scss | 10 ++-- .../unzer-payment-tab.html.twig | 14 ++--- .../js/unzer-payment6/unzer-payment6.js | 2 +- src/Resources/app/storefront/package.json | 20 +++---- .../unzer-payment.express-buttons.plugin.js | 19 ------- .../src/unzer/unzer-payment.base.plugin.js | 38 +++++++++---- .../unzer/unzer-payment.google-pay.plugin.js | 2 +- .../config/dependencies/services.xml | 1 + .../snippet/de_DE/unzer-payment.de-DE.json | 2 + .../snippet/en_GB/unzer-payment.en-GB.json | 2 + .../unzer/base/unzer-library.html.twig | 2 +- .../views/storefront/layout/meta.html.twig | 8 +++ .../page/checkout/confirm/index.html.twig | 4 +- .../page/checkout/summary.html.twig | 53 ------------------- .../checkout/summary/summary-total.html.twig | 53 ------------------- 25 files changed, 102 insertions(+), 182 deletions(-) create mode 100644 src/Resources/views/storefront/layout/meta.html.twig delete mode 100644 src/Resources/views/storefront/page/checkout/summary.html.twig delete mode 100644 src/Resources/views/storefront/page/checkout/summary/summary-total.html.twig diff --git a/CHANGELOG_de-DE.md b/CHANGELOG_de-DE.md index ecd10144..22285244 100644 --- a/CHANGELOG_de-DE.md +++ b/CHANGELOG_de-DE.md @@ -1,3 +1,10 @@ +# 6.5.6 +* Fix: Fehlende Übersetzungen neuer Zahlungsarten konnten nach einem Update im Frontend zu einer Fehlermeldung führen +* Fix: Dateien veralteter Zahlungsarten wurden nicht korrekt entfernt und konnten in einigen Fällen Probleme verursachen +* Optimierung: Umstellung auf Preloading der Zahlungskomponenten für ein besseres Checkout-Erlebnis +* Fix: Korrekte Fehlerbehandlung, wenn Kunden auf „Bezahlen“ klickten, bevor die Zahlungskomponente vollständig geladen war +* Optimierung: Caching von Schlüsselpaaren für ein schnelleres Laden der Zahlungskomponenten + # 6.5.5 * Verbesserung: Shopware-Bestellnummer wird nun in den Zahlungsdetails gespeichert, um das Tracking von Unzer Paylater-Zahlungen zu verbessern * Fehlerbehebung: Zahlungsarten für Rechnung und Ratenzahlung wurden auf die neuen offiziellen Bezeichnungen aktualisiert (nur Deutsch). Betrifft nur Neuinstallationen diff --git a/CHANGELOG_en-GB.md b/CHANGELOG_en-GB.md index a84ec46c..a26d0cbd 100644 --- a/CHANGELOG_en-GB.md +++ b/CHANGELOG_en-GB.md @@ -1,3 +1,10 @@ +# 6.5.6 +* Fix: Missing translation of new payment methods could display an error in Frontend after updating +* Fix: Files from deprecated payment methods was not properly removed and could in some cases create issues +* Optimizing: Switch to preloading of payment components for better checkout experience +* Fix: Correct error handling if customer clicked pay before payment component was fully loaded +* Optimizing: Cache of key pairs for faster loading payment components + # 6.5.5 * Improvement: Save Shopware Order Number in payment details for Unzer Paylater payment tracking * Fix: Changed payment method names for Invoice and Installment to the new official brands (German only). This will only affect new installs diff --git a/composer.json b/composer.json index 1da52155..532f37e9 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "unzerdev/shopware6", "description": "Unzer payment integration for Shopware 6", - "version": "6.5.5", + "version": "6.5.6", "type": "shopware-platform-plugin", "license": "Apache-2.0", "minimum-stability": "dev", diff --git a/src/Components/PaymentHandler/UnzerGooglePayPaymentHandler.php b/src/Components/PaymentHandler/UnzerGooglePayPaymentHandler.php index 6db299d1..753b2558 100755 --- a/src/Components/PaymentHandler/UnzerGooglePayPaymentHandler.php +++ b/src/Components/PaymentHandler/UnzerGooglePayPaymentHandler.php @@ -87,7 +87,7 @@ public function pay( } } - public static function fetchChannelId(Unzer $client): string + public static function fetchChannelId(Unzer $client, bool $cached = true): string { try { $keyPair = $client->fetchKeyPair(true); diff --git a/src/Components/ResourceHydrator/PaymentResourceHydrator/PaymentResourceHydrator.php b/src/Components/ResourceHydrator/PaymentResourceHydrator/PaymentResourceHydrator.php index 36778c24..90626071 100644 --- a/src/Components/ResourceHydrator/PaymentResourceHydrator/PaymentResourceHydrator.php +++ b/src/Components/ResourceHydrator/PaymentResourceHydrator/PaymentResourceHydrator.php @@ -370,7 +370,7 @@ protected function hydrateTransactionItem(AbstractTransactionType $item, string return [ 'id' => $item->getId(), 'shortId' => $item->getShortId(), - 'reference'=>method_exists($item, 'getPaymentReference')?$item->getPaymentReference():'', + 'reference' => method_exists($item, 'getPaymentReference') ? $item->getPaymentReference() : '', 'state' => $state, 'date' => $item->getDate(), 'type' => $type, diff --git a/src/Components/Storefront/ExtensionFactory.php b/src/Components/Storefront/ExtensionFactory.php index a3b6eae8..41c9f663 100644 --- a/src/Components/Storefront/ExtensionFactory.php +++ b/src/Components/Storefront/ExtensionFactory.php @@ -5,6 +5,8 @@ namespace UnzerPayment6\Components\Storefront; use Shopware\Core\System\SystemConfig\SystemConfigService; +use Symfony\Contracts\Cache\CacheInterface; +use Symfony\Contracts\Cache\ItemInterface; use UnzerPayment6\Components\ClientFactory\ClientFactoryInterface; use UnzerPayment6\Components\ConfigReader\ConfigReader; use UnzerPayment6\Components\ConfigReader\ConfigReaderInterface; @@ -20,7 +22,8 @@ class ExtensionFactory public function __construct( private readonly ConfigReaderInterface $configReader, private readonly ClientFactoryInterface $clientFactory, - private readonly SystemConfigService $systemConfigService + private readonly SystemConfigService $systemConfigService, + private readonly CacheInterface $cache, ) { } @@ -62,11 +65,16 @@ private function readConfig(?string $salesChannelId = null): void $this->configData = $this->configReader->read($salesChannelId); } - private function fetchGooglePayChannelId($salesChannelId = null) + private function fetchGooglePayChannelId($salesChannelId = null, int $cacheTtl = 7200): string { - $publicKey = $this->configData->get(ConfigReader::CONFIG_KEY_PUBLIC_KEY); - $client = $this->clientFactory->createClientFromPublicKey($publicKey, (string) $salesChannelId); + $cacheKey = 'UnzerGooglePayChannelId_' . ($salesChannelId ?? 'main'); - return UnzerGooglePayPaymentHandler::fetchChannelId($client); + return $this->cache->get($cacheKey, function (ItemInterface $item) use ($salesChannelId, $cacheTtl) { + $item->expiresAfter($cacheTtl); + $publicKey = $this->configData->get(ConfigReader::CONFIG_KEY_PUBLIC_KEY); + $client = $this->clientFactory->createClientFromPublicKey($publicKey, (string) $salesChannelId); + + return UnzerGooglePayPaymentHandler::fetchChannelId($client); + }); } } diff --git a/src/Components/Struct/PageExtension/Checkout/Confirm/UnzerDataPageExtension.php b/src/Components/Struct/PageExtension/Checkout/Confirm/UnzerDataPageExtension.php index 8cdf9118..bf59f3ec 100644 --- a/src/Components/Struct/PageExtension/Checkout/Confirm/UnzerDataPageExtension.php +++ b/src/Components/Struct/PageExtension/Checkout/Confirm/UnzerDataPageExtension.php @@ -11,6 +11,7 @@ class UnzerDataPageExtension extends Struct { public const EXTENSION_NAME = 'unzerPaymentData'; + public const JS_LIBRARY_URL = 'https://static-v2.unzer.com/v2/ui-components/index.js'; private string $publicKey; diff --git a/src/Controllers/Storefront/UnzerPaymentDeviceController.php b/src/Controllers/Storefront/UnzerPaymentDeviceController.php index c1fe5b2b..502357f4 100644 --- a/src/Controllers/Storefront/UnzerPaymentDeviceController.php +++ b/src/Controllers/Storefront/UnzerPaymentDeviceController.php @@ -21,9 +21,6 @@ public function __construct( // TODO: evaluate if GET is the correct method for this route #[Route(path: '/unzer/deleteDevice', name: 'frontend.unzer.device.delete', methods: ['GET'])] - /** - * @Route("/unzer/deleteDevice", name="frontend.unzer.device.delete", methods={"GET"}) - */ public function deleteDevice(Request $request, SalesChannelContext $salesChannelContext): RedirectResponse { if (!$salesChannelContext->getCustomer()) { diff --git a/src/EventListeners/Checkout/ConfirmPageEventListener.php b/src/EventListeners/Checkout/ConfirmPageEventListener.php index 6d1c10e0..724a45d6 100644 --- a/src/EventListeners/Checkout/ConfirmPageEventListener.php +++ b/src/EventListeners/Checkout/ConfirmPageEventListener.php @@ -21,7 +21,6 @@ use UnzerPayment6\Components\ConfigReader\KeyPairConfigReader; use UnzerPayment6\Components\ExpressCheckout\ExpressCheckoutService; use UnzerPayment6\Components\PaymentFrame\PaymentFrameFactoryInterface; -use UnzerPayment6\Components\PaymentHandler\UnzerGooglePayPaymentHandler; use UnzerPayment6\Components\ResourceHydrator\CustomerResourceHydrator\CustomerResourceHydratorInterface; use UnzerPayment6\Components\Storefront\ExtensionFactory; use UnzerPayment6\Components\Struct\Configuration; @@ -312,13 +311,6 @@ private function addGooglePayExtension(PageLoadedEvent $event): void $event->getPage()->addExtension(GooglePayPageExtension::EXTENSION_NAME, $extension); } - private function fetchGooglePayChannelId(PageLoadedEvent $event): string - { - $client = $this->clientFactory->createClientFromSalesChannelContext($event->getSalesChannelContext(), $event->getRequest()); - - return UnzerGooglePayPaymentHandler::fetchChannelId($client); - } - private function addPaylaterInstallmentExtension(PageLoadedEvent $event): void { $extension = new PaylaterInstallmentPageExtension(); diff --git a/src/Installer/PaymentInstaller.php b/src/Installer/PaymentInstaller.php index b164bf60..8d8aba73 100755 --- a/src/Installer/PaymentInstaller.php +++ b/src/Installer/PaymentInstaller.php @@ -529,10 +529,10 @@ private function renameIdeal(Context $context): void foreach ($existingPaymentMethod->getTranslations()->getElements() as $uniqueId => $translation) { $newName = null; $newDescription = null; - if (stripos($translation->getName(), 'wero') === false) { + if ($translation->getName() !== null && stripos($translation->getName(), 'wero') === false) { $newName = str_replace('iDEAL', 'iDEAL | Wero', $translation->getName()); } - if (stripos($translation->getDescription(), 'wero') === false) { + if ($translation->getDescription() !== null && stripos($translation->getDescription(), 'wero') === false) { $newDescription = str_replace('iDEAL', 'iDEAL | Wero', $translation->getDescription()); } diff --git a/src/Resources/app/administration/src/module/unzer-payment-configuration/page/unzer-payment-settings/unzer-payment-settings.scss b/src/Resources/app/administration/src/module/unzer-payment-configuration/page/unzer-payment-settings/unzer-payment-settings.scss index 196e661b..ad672c5f 100644 --- a/src/Resources/app/administration/src/module/unzer-payment-configuration/page/unzer-payment-settings/unzer-payment-settings.scss +++ b/src/Resources/app/administration/src/module/unzer-payment-configuration/page/unzer-payment-settings/unzer-payment-settings.scss @@ -160,11 +160,11 @@ } } -.unzer-additional-keys__title{ - .unzer-additional-keys__title-content{ - flex-basis:100%; +.unzer-additional-keys__title { + .unzer-additional-keys__title-content { + flex-basis: 100%; } - .unzer-additional-keys__title-icon{ + .unzer-additional-keys__title-icon { flex-basis: 32px; } -} \ No newline at end of file +} diff --git a/src/Resources/app/administration/src/module/unzer-payment/page/unzer-payment-tab/unzer-payment-tab.html.twig b/src/Resources/app/administration/src/module/unzer-payment/page/unzer-payment-tab/unzer-payment-tab.html.twig index 9cbffbc3..9c861cae 100644 --- a/src/Resources/app/administration/src/module/unzer-payment/page/unzer-payment-tab/unzer-payment-tab.html.twig +++ b/src/Resources/app/administration/src/module/unzer-payment/page/unzer-payment-tab/unzer-payment-tab.html.twig @@ -11,13 +11,13 @@ @reloadOrderDetails="reloadOrderDetails" > - + {% endblock %} {% block unzer_payment_payment_details_content_payment_history %} diff --git a/src/Resources/app/storefront/dist/storefront/js/unzer-payment6/unzer-payment6.js b/src/Resources/app/storefront/dist/storefront/js/unzer-payment6/unzer-payment6.js index d149e7c3..11a27b8c 100644 --- a/src/Resources/app/storefront/dist/storefront/js/unzer-payment6/unzer-payment6.js +++ b/src/Resources/app/storefront/dist/storefront/js/unzer-payment6/unzer-payment6.js @@ -1 +1 @@ -(()=>{"use strict";let e=window.PluginBaseClass;class t extends e{init(){this._registerElements(),this._registerEvents()}_registerElements(){this.submitButton=this.getSubmitButton()}getSubmitButton(){let e=document.getElementById(this.options.submitButtonId);return e||(e=document.getElementById(this.options.confirmFormId).getElementsByTagName("button")[0]),e||null}_registerEvents(){this.submitButton.addEventListener("click",this._onSubmitButtonClick.bind(this)),this.options.unzerCustomer&&Promise.all([customElements.whenDefined("unzer-payment")]).then(()=>{let e=document.getElementById("unzer-payment-component");e&&(console.log("set customer data",this.options.unzerCustomer),e.setCustomerData(this.options.unzerCustomer))})}setSubmitButtonActive(e){e?(this.submitButton.classList.remove(this.options.disabledClass),this.submitButton.disabled=!1):(this.submitButton.classList.add(this.options.disabledClass),this.submitButton.disabled=!0)}submitTypeId(e,t){if(document.getElementById(this.options.resourceIdElementId).value=e,t){let e=document.getElementById(this.options.threatMetrixIdElementId);e&&(e.value=t)}this.setSubmitButtonActive(!0),this.submitButton.click(),this.setSubmitButtonActive(!1)}showError(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=document.getElementsByClassName(this.options.errorWrapperClass).item(0),s=document.querySelectorAll(this.options.errorContentSelector)[0];t&&""!==s.innerText?s.innerText="".concat(s.innerText,"\n").concat(e.message):s.innerText=e.message,n.hidden=!1,n.scrollIntoView({block:"end",behavior:"smooth"}),this.setSubmitButtonActive(!0),this.submitting=!1}renderErrorToElement(e,t){let n=document.getElementsByClassName(this.options.errorWrapperClass).item(0),s=document.querySelectorAll(this.options.errorContentSelector)[0];n.hidden=!1,s.innerText=e.message,t.appendChild(n)}async _onSubmitButtonClick(e){if(!0===this.submitting)return;if(this.submitting=!0,e.preventDefault(),!this._validateForm()){this.submitting=!1,this.setSubmitButtonActive(!0);return}this.setSubmitButtonActive(!1);let t=document.querySelector(this.options.savedDeviceSelectedRadioButtonSelector);if(t&&t.id!==this.options.savedDeviceRadioButtonNewAccountId)this.submitTypeId(t.value,null);else{let e=document.getElementById("unzer-payment-component");if(e)try{let t=await e.submit();t.submitResponse?!0===t.submitResponse.success?(console.log("submit response: ",t.submitResponse),this.submitTypeId(t.submitResponse.data.id,t.threatMetrixId||null)):this.showError({message:"GENERAL ERROR"}):this.showError({message:"EXCEPTIONAL ERROR"})}catch(t){e.scrollIntoView({block:"end",behavior:"smooth"}),this.submitting=!1,this.setSubmitButtonActive(!0)}else this.setSubmitButtonActive(!0),this.submitButton.click(),this.setSubmitButtonActive(!1)}}_validateForm(){let e=!0,t=document.forms[this.options.confirmFormId].elements;this._clearErrorMessage();for(let n=0;n0&&this.showError({message:this.options.errorShouldNotBeEmpty.replace(/%field%/,s.labels[0].innerText)},!0),e=!1):s.classList.remove("is-invalid")}return e}_clearErrorMessage(){let e=document.getElementsByClassName(this.options.errorWrapperClass).item(0),t=document.querySelectorAll(this.options.errorContentSelector)[0];e.hidden=!0,t.innerText=""}getB2bCustomerObject(e){let t="".concat(e.firstName," ").concat(e.lastName),n=e.birthday?new Date(e.birthday):null,s={firstname:e.firstName,lastname:e.lastName,email:e.email,company:e.activeBillingAddress.company,salutation:e.salutation.salutationKey,billingAddress:{name:t,street:e.activeBillingAddress.street,zip:e.activeBillingAddress.zipcode,city:e.activeBillingAddress.city,country:e.activeBillingAddress.country.iso},shippingAddress:{name:t,street:e.activeShippingAddress.street,zip:e.activeShippingAddress.zipcode,city:e.activeShippingAddress.city,country:e.activeShippingAddress.country.iso}};return n&&(s.birthDate=n.getFullYear()+"-"+(n.getMonth()+1).toString().padStart(2,"0")+"-"+n.getDay().toString().padStart(2,"0")),s}}t.options={publicKey:null,shopLocale:null,unzerCustomer:null,submitButtonId:"confirmFormSubmit",disabledClass:"disabled",resourceIdElementId:"unzerResourceId",threatMetrixIdElementId:"unzerThreatMetrixId",confirmFormId:"confirmOrderForm",errorWrapperClass:"unzer-payment--error-wrapper",errorContentSelector:".unzer-payment--error-wrapper .alert-content",errorShouldNotBeEmpty:"%field% should not be empty",isOrderEdit:!1,savedDeviceRadioButtonSelector:'*[name="savedPaymentDevice"]',savedDeviceRadioButtonNewAccountId:"device-new",savedDeviceSelectedRadioButtonSelector:'*[name="savedPaymentDevice"]:checked'},t.submitting=!1;let n=window.PluginBaseClass;class s extends n{init(){this._unzerPaymentPlugin=window.PluginManager.getPluginInstances("UnzerPaymentBase")[0]}_handleError(e){this._unzerPaymentPlugin.showError(e)}_setSubmitButtonActive(e){this._unzerPaymentPlugin.setSubmitButtonActive(e)}_getSubmitButton(){return this._unzerPaymentPlugin.getSubmitButton()}}s._unzerPaymentPlugin=null,window.PluginBaseClass;class o extends s{init(){super.init(),this._registerEvents()}_registerEvents(){if(this.options.hasSavedDevices){let e=this.el.querySelectorAll(this.options.radioButtonSelector);for(let t=0;tthis._onRadioButtonChange(e));document.querySelector(this.options.selectedRadioButtonSelector).dispatchEvent(new Event("change"))}}_onRadioButtonChange(e){let t=e.target;this.el.querySelector(this.options.elementWrapperSelector).hidden=t.id!==this.options.radioButtonNewAccountId}}o.options={elementWrapperSelector:".unzer-payment-create-component-container",radioButtonSelector:'*[name="savedPaymentDevice"]',radioButtonNewAccountId:"device-new",selectedRadioButtonSelector:'*[name="savedPaymentDevice"]:checked',hasSavedDevices:!1},window.PluginBaseClass;class i extends s{init(){super.init(),this._createForm(),this._hideBuyButton()}_disableApplePay(){document.querySelector(this.options.applePayMethodSelector).remove(),document.querySelectorAll("[data-unzer-payment-apple-pay-v2]").forEach(e=>e.remove()),this._handleError({message:this.options.noApplePayMessage}),this._unzerPaymentPlugin.setSubmitButtonActive(!1)}_createForm(){Promise.all([customElements.whenDefined("unzer-payment")]).then(()=>{let e=document.getElementById("unzer-payment-component");e&&(e.setApplePayData(this._getApplePayPaymentRequest()),document.getElementById("unzer-checkout-component").onPaymentSubmit=t=>{t.submitResponse&&t.submitResponse.success&&this._unzerPaymentPlugin._validateForm()&&(e.style.display="none",this._unzerPaymentPlugin.submitting=!0,this._unzerPaymentPlugin.submitTypeId(t.submitResponse.data.id))})})}_getApplePayPaymentRequest(){return{countryCode:this.options.countryCode,currencyCode:this.options.currency,supportedNetworks:this.options.supportedNetworks,merchantCapabilities:this.options.merchantCapabilities,total:{label:this.options.shopName,amount:this.options.amount}}}_hideBuyButton(){document.querySelector(this.options.checkoutConfirmButtonSelector).style.display="none"}}i.options={countryCode:"DE",currency:"EUR",shopName:"Unzer GmbH",amount:"0.0",applePayButtonSelector:".apple-pay-button",checkoutConfirmButtonSelector:"#confirmFormSubmit",applePayMethodSelector:".unzer-payment-apple-pay-v2-method-wrapper",authorizePaymentUrl:"",merchantValidationUrl:"",noApplePayMessage:"",supportedNetworks:["masterCard","visa"]};class a extends s{init(){super.init(),Promise.all([customElements.whenDefined("unzer-payment")]).then(()=>{let e=document.getElementById("unzer-payment-component");e&&e.setBasketData({amount:this.options.paylaterInstallmentAmount,currencyType:this.options.paylaterInstallmentCurrency,country:this.options.countryIso})})}}a.options={countryIso:"",paylaterInstallmentAmount:"",paylaterInstallmentCurrency:""};class r extends s{init(){super.init(),this._registerGooglePayButton(),this._hideBuyButton()}_registerGooglePayButton(){Promise.all([customElements.whenDefined("unzer-payment")]).then(()=>{let e=document.getElementById("unzer-payment-component");e&&(e.setGooglePayData({gatewayMerchantId:this.options.gatewayMerchantId,merchantInfo:{merchantName:this.options.merchantName,merchantId:this.options.merchantId},transactionInfo:{currencyCode:this.options.currency,countryCode:this.options.countryCode,totalPriceStatus:"ESTIMATED",totalPrice:String(this.options.amount)},buttonOptions:{buttonColor:this.options.buttonColor,buttonSizeMode:this.options.buttonSizeMode},allowedCardNetworks:this.options.allowedCardNetworks,allowCreditCards:this.options.allowCreditCards,allowPrepaidCards:this.options.allowPrepaidCards}),document.getElementById("unzer-checkout-component").onPaymentSubmit=t=>{t.submitResponse&&t.submitResponse.success?!this._unzerPaymentPlugin._validateForm()||(e.style.display="none",this._unzerPaymentPlugin.submitting=!0,this._unzerPaymentPlugin.submitTypeId(t.submitResponse.data.id)):console.log("ERROR",t)})})}_hideBuyButton(){this._getSubmitButton().style.display="none"}}r.options={googlePayButtonId:"unzer-google-pay-button",merchantName:"",merchantId:"",gatewayMerchantId:"",currency:"EUR",amount:"0.0",countryCode:"DE",allowedCardNetworks:[],allowCreditCards:!0,allowPrepaidCards:!0,buttonColor:"default",buttonSizeMode:"fill"},r.submitting=!1;let l=window.PluginBaseClass;class u extends l{init(){this.includeJs(),this.registerActions()}includeJs(){if(!document.querySelector('script[src*="static-v2.unzer.com/v2/ui-components/index.js"]')){let e=document.createElement("script");e.type="module",e.src="https://static-v2.unzer.com/v2/ui-components/index.js",document.head.appendChild(e)}}registerActions(){Promise.all([customElements.whenDefined("unzer-payment"),customElements.whenDefined("unzer-google-pay"),customElements.whenDefined("unzer-paypal-express"),customElements.whenDefined("unzer-apple-pay")]).then(()=>{let e=this.el.querySelector(".unzer-express-payment"),t=this.el.querySelector(".unzer-paypal-express"),n=this.el.querySelector(".unzer-google-pay"),s=this.el.querySelector(".unzer-apple-pay");e&&(t&&this.registerPaypalExpress(t,e),n&&this.registerGooglePay(n,e),s&&this.registerApplePay(s,e))})}registerPaypalExpress(e,t){e.id="unzer-paypal-button-"+Math.floor(1e4*Math.random()),e.addEventListener("click",async e=>{e.stopPropagation();let n=await t.submit();if(n.submitResponse&&n.submitResponse.success){let e=n.submitResponse.data.id;fetch("/unzer/paypal-express",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paymentTypeId:e})}).then(e=>e.json()).then(e=>{location.href=e.redirectUrl})}})}registerGooglePay(e,t){t.setGooglePayData({gatewayMerchantId:this.options.googlePay.gatewayMerchantId,merchantInfo:{merchantName:this.options.googlePay.merchantName,merchantId:this.options.googlePay.merchantId},transactionInfo:{currencyCode:this.options.googlePay.currency,countryCode:this.options.googlePay.countryCode,totalPriceStatus:"ESTIMATED",checkoutOption:"DEFAULT",totalPrice:String(this.options.googlePay.amount)},buttonOptions:{buttonColor:this.options.googlePay.buttonColor,buttonSizeMode:this.options.googlePay.buttonSizeMode},allowedCardNetworks:this.options.googlePay.allowedCardNetworks,allowCreditCards:this.options.googlePay.allowCreditCards,allowPrepaidCards:this.options.googlePay.allowPrepaidCards,billingAddressParameters:{format:"MIN"},billingAddressRequired:!0,emailRequired:!0,onPaymentDataChangedCallback:()=>({}),shippingOptionParameters:{},onPaymentAuthorizedCallback:async(e,n,s)=>{console.log("paymentData:",e);let o=await t.submit(),i=o.submitResponse.data.id;console.log(o,"--- success paymentTypeId",i),console.log("submit response: ",o),fetch("/unzer/google-pay-express",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paymentTypeId:i,paymentData:e})}).then(e=>e.json()).then(e=>{console.log(JSON.stringify(e)),location.href=e.redirectUrl})},shippingAddressRequired:!0,shippingOptionRequired:!1})}registerApplePay(e,t){let n={countryCode:this.options.applePay.countryCode,currencyCode:this.options.applePay.currency,supportedNetworks:this.options.applePay.supportedNetworks,merchantCapabilities:this.options.applePay.merchantCapabilities,total:{label:this.options.applePay.shopName,amount:String(this.options.applePay.amount)},requiredShippingContactFields:["postalAddress","name","email","phone"],requiredBillingContactFields:["postalAddress","name","email","phone"],onPaymentAuthorizedCallback:async(e,n,s,o)=>{console.log("paymentData:",e);let i=o.payment.shippingContact,a=o.payment.billingContact;console.log(i),console.log(a);let r=await t.submit();r.submitResponse.success?n():s();let l=r.submitResponse.data.id;console.log(r,"--- success paymentTypeId",l),console.log("submit response: ",r),fetch("/unzer/applepay-express",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paymentTypeId:l,paymentData:e,shippingContact:i,billingContact:a})}).then(e=>e.json()).then(e=>{console.log(JSON.stringify(e)),location.href=e.redirectUrl})}};n.initApplePaySession=e=>{},null==t||t.setApplePayData(n)}}u.options={googlePay:{},applePay:{}},window.PluginManager.register("UnzerPaymentBase",t,"[data-unzer-payment-base]"),window.PluginManager.register("UnzerPaymentCreditCard",class extends o{},"[data-unzer-payment-credit-card]"),window.PluginManager.register("UnzerPaymentPayPal",class extends o{},"[data-unzer-payment-paypal]"),window.PluginManager.register("UnzerPaymentSepaDirectDebit",class extends o{},"[data-unzer-payment-sepa-direct-debit]"),window.PluginManager.register("UnzerPaymentApplePayV2",i,"[data-unzer-payment-apple-pay-v2]"),window.PluginManager.register("UnzerPaymentPaylaterInvoice",class extends s{},"[data-unzer-payment-paylater-invoice]"),window.PluginManager.register("UnzerPaymentPaylaterInstallment",a,"[data-unzer-payment-paylater-installment]"),window.PluginManager.register("UnzerPaymentPaylaterDirectDebitSecured",class extends s{},"[data-unzer-payment-paylater-direct-debit-secured]"),window.PluginManager.register("UnzerPaymentGooglePay",r,"[data-unzer-payment-google-pay]"),window.PluginManager.register("UnzerPaymentExpressButtons",u,"[data-unzer-payment-express-buttons]")})(); \ No newline at end of file +(()=>{"use strict";let e=window.PluginBaseClass;class t extends e{init(){this._registerElements(),this._registerEvents()}_registerElements(){this.submitButton=this.getSubmitButton()}getSubmitButton(){let e=document.getElementById(this.options.submitButtonId);return e||(e=document.getElementById(this.options.confirmFormId).getElementsByTagName("button")[0]),e||null}_registerEvents(){this.submitButton.addEventListener("click",this._onSubmitButtonClick.bind(this)),this.options.unzerCustomer&&Promise.all([customElements.whenDefined("unzer-payment")]).then(()=>{let e=document.getElementById("unzer-payment-component");e&&e.setCustomerData(this.options.unzerCustomer)})}setSubmitButtonActive(e){e?(this.submitButton.classList.remove(this.options.disabledClass),this.submitButton.disabled=!1):(this.submitButton.classList.add(this.options.disabledClass),this.submitButton.disabled=!0)}submitTypeId(e,t){if(document.getElementById(this.options.resourceIdElementId).value=e,t){let e=document.getElementById(this.options.threatMetrixIdElementId);e&&(e.value=t)}this.setSubmitButtonActive(!0),this.submitButton.click(),this.setSubmitButtonActive(!1)}showNotLoadedError(){this.showError({message:this.options.errorNotReady})}showError(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=document.getElementsByClassName(this.options.errorWrapperClass).item(0),s=document.querySelectorAll(this.options.errorContentSelector)[0];t&&""!==s.innerText?s.innerText="".concat(s.innerText,"\n").concat(e.message):s.innerText=e.message,n.hidden=!1,n.scrollIntoView({block:"end",behavior:"smooth"}),this.setSubmitButtonActive(!0),this.submitting=!1}renderErrorToElement(e,t){let n=document.getElementsByClassName(this.options.errorWrapperClass).item(0),s=document.querySelectorAll(this.options.errorContentSelector)[0];n.hidden=!1,s.innerText=e.message,t.appendChild(n)}async _onSubmitButtonClick(e){if(!0===this.submitting)return;if(this.submitting=!0,e.preventDefault(),!this._validateForm()){this.submitting=!1,this.setSubmitButtonActive(!0);return}this.setSubmitButtonActive(!1);let t=document.querySelector(this.options.savedDeviceSelectedRadioButtonSelector);if(t&&t.id!==this.options.savedDeviceRadioButtonNewAccountId)this.submitTypeId(t.value,null);else{let e=document.getElementById("unzer-payment-component");if(e){if(void 0===e.submit){this.showNotLoadedError();return}try{let t=await e.submit();if(t.submitResponse){if(!0===t.submitResponse.success){if("object"==typeof e.currentPaymentMethod&&e.currentPaymentMethod.tagName.toLowerCase().includes("-paylater")&&!t.threatMetrixId){this.showNotLoadedError();return}this.submitTypeId(t.submitResponse.data.id,t.threatMetrixId||null)}else this.showError({message:this.options.generalError})}else this.showError({message:this.options.generalError})}catch(t){e.scrollIntoView({block:"end",behavior:"smooth"}),this.submitting=!1,this.setSubmitButtonActive(!0)}}else this.setSubmitButtonActive(!0),this.submitButton.click(),this.setSubmitButtonActive(!1)}}_validateForm(){let e=!0,t=document.forms[this.options.confirmFormId].elements;this._clearErrorMessage();for(let n=0;n0&&this.showError({message:this.options.errorShouldNotBeEmpty.replace(/%field%/,s.labels[0].innerText)},!0),e=!1):s.classList.remove("is-invalid")}return e}_clearErrorMessage(){let e=document.getElementsByClassName(this.options.errorWrapperClass).item(0),t=document.querySelectorAll(this.options.errorContentSelector)[0];e.hidden=!0,t.innerText=""}getB2bCustomerObject(e){let t="".concat(e.firstName," ").concat(e.lastName),n=e.birthday?new Date(e.birthday):null,s={firstname:e.firstName,lastname:e.lastName,email:e.email,company:e.activeBillingAddress.company,salutation:e.salutation.salutationKey,billingAddress:{name:t,street:e.activeBillingAddress.street,zip:e.activeBillingAddress.zipcode,city:e.activeBillingAddress.city,country:e.activeBillingAddress.country.iso},shippingAddress:{name:t,street:e.activeShippingAddress.street,zip:e.activeShippingAddress.zipcode,city:e.activeShippingAddress.city,country:e.activeShippingAddress.country.iso}};return n&&(s.birthDate=n.getFullYear()+"-"+(n.getMonth()+1).toString().padStart(2,"0")+"-"+n.getDay().toString().padStart(2,"0")),s}}t.options={publicKey:null,shopLocale:null,unzerCustomer:null,submitButtonId:"confirmFormSubmit",disabledClass:"disabled",resourceIdElementId:"unzerResourceId",threatMetrixIdElementId:"unzerThreatMetrixId",confirmFormId:"confirmOrderForm",errorWrapperClass:"unzer-payment--error-wrapper",errorContentSelector:".unzer-payment--error-wrapper .alert-content",errorShouldNotBeEmpty:"%field% should not be empty",errorNotReady:"Payment method is not loaded yet. Please wait.",generalError:"Error! Please try again.",isOrderEdit:!1,savedDeviceRadioButtonSelector:'*[name="savedPaymentDevice"]',savedDeviceRadioButtonNewAccountId:"device-new",savedDeviceSelectedRadioButtonSelector:'*[name="savedPaymentDevice"]:checked'},t.submitting=!1;let n=window.PluginBaseClass;class s extends n{init(){this._unzerPaymentPlugin=window.PluginManager.getPluginInstances("UnzerPaymentBase")[0]}_handleError(e){this._unzerPaymentPlugin.showError(e)}_setSubmitButtonActive(e){this._unzerPaymentPlugin.setSubmitButtonActive(e)}_getSubmitButton(){return this._unzerPaymentPlugin.getSubmitButton()}}s._unzerPaymentPlugin=null,window.PluginBaseClass;class o extends s{init(){super.init(),this._registerEvents()}_registerEvents(){if(this.options.hasSavedDevices){let e=this.el.querySelectorAll(this.options.radioButtonSelector);for(let t=0;tthis._onRadioButtonChange(e));document.querySelector(this.options.selectedRadioButtonSelector).dispatchEvent(new Event("change"))}}_onRadioButtonChange(e){let t=e.target;this.el.querySelector(this.options.elementWrapperSelector).hidden=t.id!==this.options.radioButtonNewAccountId}}o.options={elementWrapperSelector:".unzer-payment-create-component-container",radioButtonSelector:'*[name="savedPaymentDevice"]',radioButtonNewAccountId:"device-new",selectedRadioButtonSelector:'*[name="savedPaymentDevice"]:checked',hasSavedDevices:!1},window.PluginBaseClass;class i extends s{init(){super.init(),this._createForm(),this._hideBuyButton()}_disableApplePay(){document.querySelector(this.options.applePayMethodSelector).remove(),document.querySelectorAll("[data-unzer-payment-apple-pay-v2]").forEach(e=>e.remove()),this._handleError({message:this.options.noApplePayMessage}),this._unzerPaymentPlugin.setSubmitButtonActive(!1)}_createForm(){Promise.all([customElements.whenDefined("unzer-payment")]).then(()=>{let e=document.getElementById("unzer-payment-component");e&&(e.setApplePayData(this._getApplePayPaymentRequest()),document.getElementById("unzer-checkout-component").onPaymentSubmit=t=>{t.submitResponse&&t.submitResponse.success&&this._unzerPaymentPlugin._validateForm()&&(e.style.display="none",this._unzerPaymentPlugin.submitting=!0,this._unzerPaymentPlugin.submitTypeId(t.submitResponse.data.id))})})}_getApplePayPaymentRequest(){return{countryCode:this.options.countryCode,currencyCode:this.options.currency,supportedNetworks:this.options.supportedNetworks,merchantCapabilities:this.options.merchantCapabilities,total:{label:this.options.shopName,amount:this.options.amount}}}_hideBuyButton(){document.querySelector(this.options.checkoutConfirmButtonSelector).style.display="none"}}i.options={countryCode:"DE",currency:"EUR",shopName:"Unzer GmbH",amount:"0.0",applePayButtonSelector:".apple-pay-button",checkoutConfirmButtonSelector:"#confirmFormSubmit",applePayMethodSelector:".unzer-payment-apple-pay-v2-method-wrapper",authorizePaymentUrl:"",merchantValidationUrl:"",noApplePayMessage:"",supportedNetworks:["masterCard","visa"]};class r extends s{init(){super.init(),Promise.all([customElements.whenDefined("unzer-payment")]).then(()=>{let e=document.getElementById("unzer-payment-component");e&&e.setBasketData({amount:this.options.paylaterInstallmentAmount,currencyType:this.options.paylaterInstallmentCurrency,country:this.options.countryIso})})}}r.options={countryIso:"",paylaterInstallmentAmount:"",paylaterInstallmentCurrency:""};class a extends s{init(){super.init(),this._registerGooglePayButton(),this._hideBuyButton()}_registerGooglePayButton(){Promise.all([customElements.whenDefined("unzer-payment")]).then(()=>{let e=document.getElementById("unzer-payment-component");e&&(e.setGooglePayData({gatewayMerchantId:this.options.gatewayMerchantId,merchantInfo:{merchantName:this.options.merchantName,merchantId:this.options.merchantId},transactionInfo:{currencyCode:this.options.currency,countryCode:this.options.countryCode,totalPriceStatus:"ESTIMATED",totalPrice:String(this.options.amount)},buttonOptions:{buttonColor:this.options.buttonColor,buttonSizeMode:this.options.buttonSizeMode},allowedCardNetworks:this.options.allowedCardNetworks,allowCreditCards:this.options.allowCreditCards,allowPrepaidCards:this.options.allowPrepaidCards}),document.getElementById("unzer-checkout-component").onPaymentSubmit=t=>{t.submitResponse&&t.submitResponse.success?!this._unzerPaymentPlugin._validateForm()||(e.style.display="none",this._unzerPaymentPlugin.submitting=!0,this._unzerPaymentPlugin.submitTypeId(t.submitResponse.data.id)):console.error(t)})})}_hideBuyButton(){this._getSubmitButton().style.display="none"}}a.options={googlePayButtonId:"unzer-google-pay-button",merchantName:"",merchantId:"",gatewayMerchantId:"",currency:"EUR",amount:"0.0",countryCode:"DE",allowedCardNetworks:[],allowCreditCards:!0,allowPrepaidCards:!0,buttonColor:"default",buttonSizeMode:"fill"},a.submitting=!1;let l=window.PluginBaseClass;class u extends l{init(){this.includeJs(),this.registerActions()}includeJs(){if(!document.querySelector('script[src*="static-v2.unzer.com/v2/ui-components/index.js"]')){let e=document.createElement("script");e.type="module",e.src="https://static-v2.unzer.com/v2/ui-components/index.js",document.head.appendChild(e)}}registerActions(){Promise.all([customElements.whenDefined("unzer-payment"),customElements.whenDefined("unzer-google-pay"),customElements.whenDefined("unzer-paypal-express"),customElements.whenDefined("unzer-apple-pay")]).then(()=>{let e=this.el.querySelector(".unzer-express-payment"),t=this.el.querySelector(".unzer-paypal-express"),n=this.el.querySelector(".unzer-google-pay"),s=this.el.querySelector(".unzer-apple-pay");e&&(t&&this.registerPaypalExpress(t,e),n&&this.registerGooglePay(n,e),s&&this.registerApplePay(s,e))})}registerPaypalExpress(e,t){e.id="unzer-paypal-button-"+Math.floor(1e4*Math.random()),e.addEventListener("click",async e=>{e.stopPropagation();let n=await t.submit();if(n.submitResponse&&n.submitResponse.success){let e=n.submitResponse.data.id;fetch("/unzer/paypal-express",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paymentTypeId:e})}).then(e=>e.json()).then(e=>{location.href=e.redirectUrl})}})}registerGooglePay(e,t){t.setGooglePayData({gatewayMerchantId:this.options.googlePay.gatewayMerchantId,merchantInfo:{merchantName:this.options.googlePay.merchantName,merchantId:this.options.googlePay.merchantId},transactionInfo:{currencyCode:this.options.googlePay.currency,countryCode:this.options.googlePay.countryCode,totalPriceStatus:"ESTIMATED",checkoutOption:"DEFAULT",totalPrice:String(this.options.googlePay.amount)},buttonOptions:{buttonColor:this.options.googlePay.buttonColor,buttonSizeMode:this.options.googlePay.buttonSizeMode},allowedCardNetworks:this.options.googlePay.allowedCardNetworks,allowCreditCards:this.options.googlePay.allowCreditCards,allowPrepaidCards:this.options.googlePay.allowPrepaidCards,billingAddressParameters:{format:"MIN"},billingAddressRequired:!0,emailRequired:!0,onPaymentDataChangedCallback:()=>({}),shippingOptionParameters:{},onPaymentAuthorizedCallback:async(e,n,s)=>{let o=(await t.submit()).submitResponse.data.id;fetch("/unzer/google-pay-express",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paymentTypeId:o,paymentData:e})}).then(e=>e.json()).then(e=>{location.href=e.redirectUrl})},shippingAddressRequired:!0,shippingOptionRequired:!1})}registerApplePay(e,t){let n={countryCode:this.options.applePay.countryCode,currencyCode:this.options.applePay.currency,supportedNetworks:this.options.applePay.supportedNetworks,merchantCapabilities:this.options.applePay.merchantCapabilities,total:{label:this.options.applePay.shopName,amount:String(this.options.applePay.amount)},requiredShippingContactFields:["postalAddress","name","email","phone"],requiredBillingContactFields:["postalAddress","name","email","phone"],onPaymentAuthorizedCallback:async(e,n,s,o)=>{let i=o.payment.shippingContact,r=o.payment.billingContact,a=await t.submit();a.submitResponse.success?n():s();let l=a.submitResponse.data.id;fetch("/unzer/applepay-express",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paymentTypeId:l,paymentData:e,shippingContact:i,billingContact:r})}).then(e=>e.json()).then(e=>{location.href=e.redirectUrl})}};n.initApplePaySession=e=>{},null==t||t.setApplePayData(n)}}u.options={googlePay:{},applePay:{}},window.PluginManager.register("UnzerPaymentBase",t,"[data-unzer-payment-base]"),window.PluginManager.register("UnzerPaymentCreditCard",class extends o{},"[data-unzer-payment-credit-card]"),window.PluginManager.register("UnzerPaymentPayPal",class extends o{},"[data-unzer-payment-paypal]"),window.PluginManager.register("UnzerPaymentSepaDirectDebit",class extends o{},"[data-unzer-payment-sepa-direct-debit]"),window.PluginManager.register("UnzerPaymentApplePayV2",i,"[data-unzer-payment-apple-pay-v2]"),window.PluginManager.register("UnzerPaymentPaylaterInvoice",class extends s{},"[data-unzer-payment-paylater-invoice]"),window.PluginManager.register("UnzerPaymentPaylaterInstallment",r,"[data-unzer-payment-paylater-installment]"),window.PluginManager.register("UnzerPaymentPaylaterDirectDebitSecured",class extends s{},"[data-unzer-payment-paylater-direct-debit-secured]"),window.PluginManager.register("UnzerPaymentGooglePay",a,"[data-unzer-payment-google-pay]"),window.PluginManager.register("UnzerPaymentExpressButtons",u,"[data-unzer-payment-express-buttons]")})(); \ No newline at end of file diff --git a/src/Resources/app/storefront/package.json b/src/Resources/app/storefront/package.json index f9efb227..f684102b 100644 --- a/src/Resources/app/storefront/package.json +++ b/src/Resources/app/storefront/package.json @@ -1,12 +1,12 @@ { - "name": "unzer-shopware6-storefront", - "version": "1.0.0", - "description": "", - "author": "Kellerkinder", - "devDependencies": { - "webpack-cli": "^5.1.4" - }, - "dependencies": { - "shopware-storefront-sdk": "^0.0.2" - } + "name": "unzer-shopware6-storefront", + "version": "1.0.0", + "description": "", + "author": "Kellerkinder", + "devDependencies": { + "webpack-cli": "^5.1.4" + }, + "dependencies": { + "shopware-storefront-sdk": "^0.0.2" + } } diff --git a/src/Resources/app/storefront/src/unzer/express/unzer-payment.express-buttons.plugin.js b/src/Resources/app/storefront/src/unzer/express/unzer-payment.express-buttons.plugin.js index 411ced75..7147755e 100644 --- a/src/Resources/app/storefront/src/unzer/express/unzer-payment.express-buttons.plugin.js +++ b/src/Resources/app/storefront/src/unzer/express/unzer-payment.express-buttons.plugin.js @@ -126,16 +126,9 @@ export default class UnzerPaymentExpressButtonsPlugin extends Plugin { approve, reject ) => { - console.log('paymentData:', paymentData); // You can create customer here based on paymentData const response = await unzerExpressPayment.submit(); const paymentTypeId = response.submitResponse.data.id; - console.log( - response, - '--- success paymentTypeId', - paymentTypeId - ); - console.log('submit response: ', response); fetch('/unzer/google-pay-express', { method: 'POST', @@ -149,7 +142,6 @@ export default class UnzerPaymentExpressButtonsPlugin extends Plugin { }) .then((response) => response.json()) .then((json) => { - console.log(JSON.stringify(json)); location.href = json.redirectUrl; }); }, @@ -187,13 +179,9 @@ export default class UnzerPaymentExpressButtonsPlugin extends Plugin { reject, event ) => { - console.log('paymentData:', paymentData); let shippingContact = event.payment.shippingContact; // Store the shipping contact data for express checkout let billingContact = event.payment.billingContact; // Store the billing contact data for express checkout - console.log(shippingContact); - console.log(billingContact); - // You can create customer here based on paymentData const response = await unzerExpressPayment.submit(); if (response.submitResponse.success) { @@ -202,12 +190,6 @@ export default class UnzerPaymentExpressButtonsPlugin extends Plugin { reject(); } const paymentTypeId = response.submitResponse.data.id; - console.log( - response, - '--- success paymentTypeId', - paymentTypeId - ); - console.log('submit response: ', response); fetch('/unzer/applepay-express', { method: 'POST', @@ -223,7 +205,6 @@ export default class UnzerPaymentExpressButtonsPlugin extends Plugin { }) .then((response) => response.json()) .then((json) => { - console.log(JSON.stringify(json)); location.href = json.redirectUrl; }); }, diff --git a/src/Resources/app/storefront/src/unzer/unzer-payment.base.plugin.js b/src/Resources/app/storefront/src/unzer/unzer-payment.base.plugin.js index 38b8304d..13844ba3 100755 --- a/src/Resources/app/storefront/src/unzer/unzer-payment.base.plugin.js +++ b/src/Resources/app/storefront/src/unzer/unzer-payment.base.plugin.js @@ -13,6 +13,8 @@ export default class UnzerPaymentBasePlugin extends Plugin { errorWrapperClass: 'unzer-payment--error-wrapper', errorContentSelector: '.unzer-payment--error-wrapper .alert-content', errorShouldNotBeEmpty: '%field% should not be empty', + errorNotReady: 'Payment method is not loaded yet. Please wait.', + generalError: 'Error! Please try again.', isOrderEdit: false, savedDeviceRadioButtonSelector: '*[name="savedPaymentDevice"]', savedDeviceRadioButtonNewAccountId: 'device-new', @@ -62,10 +64,6 @@ export default class UnzerPaymentBasePlugin extends Plugin { 'unzer-payment-component' ); if (unzerPaymentElement) { - console.log( - 'set customer data', - this.options.unzerCustomer - ); unzerPaymentElement.setCustomerData( this.options.unzerCustomer ); @@ -114,6 +112,12 @@ export default class UnzerPaymentBasePlugin extends Plugin { this.setSubmitButtonActive(false); } + showNotLoadedError() { + this.showError({ + message: this.options.errorNotReady, + }); + } + /** * @param {Object} error * @param {Boolean} append @@ -199,27 +203,41 @@ export default class UnzerPaymentBasePlugin extends Plugin { this.submitButton.click(); this.setSubmitButtonActive(false); } else { + if (typeof unzerPaymentComponent.submit === 'undefined') { + this.showNotLoadedError(); + return; + } + try { const response = await unzerPaymentComponent.submit(); if (response.submitResponse) { if (response.submitResponse.success === true) { - console.log( - 'submit response: ', - response.submitResponse - ); + // in some cases it can happen that threatmetrix was not yet ready when submitting + if ( + typeof unzerPaymentComponent.currentPaymentMethod === + 'object' && + unzerPaymentComponent.currentPaymentMethod.tagName + .toLowerCase() + .includes('-paylater') && + !response.threatMetrixId + ) { + this.showNotLoadedError(); + return; + } + this.submitTypeId( response.submitResponse.data.id, response.threatMetrixId || null ); } else { this.showError({ - message: 'GENERAL ERROR', + message: this.options.generalError, }); } } else { this.showError({ - message: 'EXCEPTIONAL ERROR', + message: this.options.generalError, }); } } catch (err) { diff --git a/src/Resources/app/storefront/src/unzer/unzer-payment.google-pay.plugin.js b/src/Resources/app/storefront/src/unzer/unzer-payment.google-pay.plugin.js index 00e7e027..782ceb8e 100755 --- a/src/Resources/app/storefront/src/unzer/unzer-payment.google-pay.plugin.js +++ b/src/Resources/app/storefront/src/unzer/unzer-payment.google-pay.plugin.js @@ -87,7 +87,7 @@ export default class UnzerPaymentGooglePayPlugin extends UnzerPaymentBaseParent response.submitResponse.data.id ); } else { - console.log('ERROR', response); + console.error(response); } }; } diff --git a/src/Resources/config/dependencies/services.xml b/src/Resources/config/dependencies/services.xml index e307205c..4a7e0435 100644 --- a/src/Resources/config/dependencies/services.xml +++ b/src/Resources/config/dependencies/services.xml @@ -102,6 +102,7 @@ + diff --git a/src/Resources/snippet/de_DE/unzer-payment.de-DE.json b/src/Resources/snippet/de_DE/unzer-payment.de-DE.json index 8d4549a1..2e104e8c 100644 --- a/src/Resources/snippet/de_DE/unzer-payment.de-DE.json +++ b/src/Resources/snippet/de_DE/unzer-payment.de-DE.json @@ -87,6 +87,8 @@ }, "finishPaymentFailed": "Zahlung ändern", "birthdayInvalid": "Sie müssen mindestens 18 Jahre alt sein.", + "errorNotReady": "Die Zahlungsart ist noch nicht vollständig geladen. Bitte warten Sie einen Moment.", + "generalError": "Es gab einen Fehler. Bitte versuchen Sie es erneut.", "companyType": { "label": "Art des Unternehmens", "placeholder": "Bitte auswählen", diff --git a/src/Resources/snippet/en_GB/unzer-payment.en-GB.json b/src/Resources/snippet/en_GB/unzer-payment.en-GB.json index db9f79b1..ad398de8 100644 --- a/src/Resources/snippet/en_GB/unzer-payment.en-GB.json +++ b/src/Resources/snippet/en_GB/unzer-payment.en-GB.json @@ -87,6 +87,8 @@ }, "finishPaymentFailed": "Change payment method", "birthdayInvalid": "You need to be at least 18 years old.", + "errorNotReady": "Payment method is not loaded yet. Please wait.", + "generalError": "Error! Please try again.", "companyType": { "label": "Type of company", "placeholder": "Please select", diff --git a/src/Resources/views/storefront/component/unzer/base/unzer-library.html.twig b/src/Resources/views/storefront/component/unzer/base/unzer-library.html.twig index e48c4027..faadc8d5 100644 --- a/src/Resources/views/storefront/component/unzer/base/unzer-library.html.twig +++ b/src/Resources/views/storefront/component/unzer/base/unzer-library.html.twig @@ -1,3 +1,3 @@ {% block unzer_paymentbase_js_library %} - + {% endblock %} diff --git a/src/Resources/views/storefront/layout/meta.html.twig b/src/Resources/views/storefront/layout/meta.html.twig new file mode 100644 index 00000000..a68d3899 --- /dev/null +++ b/src/Resources/views/storefront/layout/meta.html.twig @@ -0,0 +1,8 @@ +{% sw_extends '@Storefront/storefront/layout/meta.html.twig' %} + +{% block layout_head_stylesheet %} + {{ parent() }} + {% if app.request.attributes.get('_route') == 'frontend.checkout.confirm.page' %} + + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/src/Resources/views/storefront/page/checkout/confirm/index.html.twig b/src/Resources/views/storefront/page/checkout/confirm/index.html.twig index 29f3880b..54f9f1fb 100755 --- a/src/Resources/views/storefront/page/checkout/confirm/index.html.twig +++ b/src/Resources/views/storefront/page/checkout/confirm/index.html.twig @@ -32,7 +32,9 @@ "publicKey": "{{ page.extensions.unzerPaymentData.publicKey }}", "shopLocale": "{{ page.extensions.unzerPaymentData.locale }}", "unzerCustomer": {% if page.extensions.unzerPaymentData.getUnzerCustomer() is not empty %}{{ page.extensions.unzerPaymentData.getUnzerCustomer().expose()|json_encode }}{% else %}null{% endif %}, - "errorShouldNotBeEmpty": "{{ "error.VIOLATION::IS_BLANK_ERROR" | trans }}" + "errorShouldNotBeEmpty": "{{ "error.VIOLATION::IS_BLANK_ERROR" | trans }}", + "errorNotReady": "{{ "UnzerPayment.errorNotReady" | trans }}", + "generalError": "{{ "UnzerPayment.generalError" | trans }}" }'>
{% block unzer_payment_checkout_confirm_frame_card_body %} diff --git a/src/Resources/views/storefront/page/checkout/summary.html.twig b/src/Resources/views/storefront/page/checkout/summary.html.twig deleted file mode 100644 index 031d8c0b..00000000 --- a/src/Resources/views/storefront/page/checkout/summary.html.twig +++ /dev/null @@ -1,53 +0,0 @@ -{% sw_extends '@Storefront/storefront/page/checkout/summary.html.twig' %} - -{# Extension for the cart summary should only apply to InstallmentSecured since it modifies the prices accordingly to the selected rate! #} -{% block page_checkout_summary_total %} - {% if context.paymentMethod.id is constant("UnzerPayment6\\Installer\\PaymentInstaller::PAYMENT_ID_INSTALLMENT_SECURED") %} - {% block page_checkout_summary_unzer_paymentinstallment_interest_label %} -
- {{ "UnzerPayment.frame.installmentSecured.totalInterest"|trans|sw_sanitize }} -
- {% endblock %} - - {% block page_checkout_summary_unzer_paymentinstallment_interest_value %} -
- {% if page.extensions.unzerFinishPage and (page.extensions.unzerFinishPage.installmentInformation|length > 0) %} - {{ page.extensions.unzerFinishPage.installmentInformation[0].totalInterestAmount|currency }}{{ "general.star"|trans|sw_sanitize }} - {% else %} - {{ 0|currency }}{{ "general.star"|trans|sw_sanitize }} - {% endif %} -
- {% endblock %} - - {% block page_checkout_summary_total_label %} -
- {{ "checkout.summaryTotalPrice"|trans|sw_sanitize }} -
- {% endblock %} - - {% block page_checkout_summary_total_value %} -
- {{ summary.price.totalPrice|currency }}{% if page.cart.price.taxStatus == "gross" %}{{ "general.star"|trans|sw_sanitize|trim }}{% endif %} -
- {% endblock %} - - {% block page_checkout_summary_unzer_paymentinstallment_total_label %} -
- {{ "UnzerPayment.frame.installmentSecured.totalAmount"|trans }} -
- {% endblock %} - - {% block page_checkout_summary_unzer_paymentinstallment_total_value %} -
- {% if page.extensions.unzerFinishPage and (page.extensions.unzerFinishPage.installmentInformation|length > 0) %} - {{ page.extensions.unzerFinishPage.installmentInformation[0].totalAmount|currency }}{{ "general.star"|trans|sw_sanitize }} - {% else %} - {{ summary.price.totalPrice|currency }}{{ "general.star"|trans|sw_sanitize }} - {% endif %} -
- {% endblock %} - {% else %} - {{ parent() }} - {% endif %} -{% endblock %} diff --git a/src/Resources/views/storefront/page/checkout/summary/summary-total.html.twig b/src/Resources/views/storefront/page/checkout/summary/summary-total.html.twig deleted file mode 100644 index 6550ba51..00000000 --- a/src/Resources/views/storefront/page/checkout/summary/summary-total.html.twig +++ /dev/null @@ -1,53 +0,0 @@ -{% sw_extends '@Storefront/storefront/page/checkout/summary/summary-total.html.twig' %} - -{# Extension for the cart summary should only apply to InstallmentSecured since it modifies the prices accordingly to the selected rate! #} -{% block page_checkout_summary_total %} - {% if context.paymentMethod.id is constant("UnzerPayment6\\Installer\\PaymentInstaller::PAYMENT_ID_INSTALLMENT_SECURED") %} - {% block page_checkout_summary_unzer_paymentinstallment_interest_label %} -
- {{ "UnzerPayment.frame.installmentSecured.totalInterest"|trans|sw_sanitize }} -
- {% endblock %} - - {% block page_checkout_summary_unzer_paymentinstallment_interest_value %} -
- {% if page.extensions.unzerFinishPage and (page.extensions.unzerFinishPage.installmentInformation|length > 0) %} - {{ page.extensions.unzerFinishPage.installmentInformation[0].totalInterestAmount|currency }}{{ "general.star"|trans|sw_sanitize }} - {% else %} - {{ 0|currency }}{{ "general.star"|trans|sw_sanitize }} - {% endif %} -
- {% endblock %} - - {% block page_checkout_summary_total_label %} -
- {{ "checkout.summaryTotalPrice"|trans|sw_sanitize }} -
- {% endblock %} - - {% block page_checkout_summary_total_value %} -
- {{ summary.price.totalPrice|currency }}{% if page.cart.price.taxStatus == "gross" %}{{ "general.star"|trans|sw_sanitize|trim }}{% endif %} -
- {% endblock %} - - {% block page_checkout_summary_unzer_paymentinstallment_total_label %} -
- {{ "UnzerPayment.frame.installmentSecured.totalAmount"|trans }} -
- {% endblock %} - - {% block page_checkout_summary_unzer_paymentinstallment_total_value %} -
- {% if page.extensions.unzerFinishPage and (page.extensions.unzerFinishPage.installmentInformation|length > 0) %} - {{ page.extensions.unzerFinishPage.installmentInformation[0].totalAmount|currency }}{{ "general.star"|trans|sw_sanitize }} - {% else %} - {{ summary.price.totalPrice|currency }}{{ "general.star"|trans|sw_sanitize }} - {% endif %} -
- {% endblock %} - {% else %} - {{ parent() }} - {% endif %} -{% endblock %}