escapeHtml(__('Your Unzer payment # is: %1.', $unzerPaymentId)) ?>
+ +getAdditionalPaymentInformation(); if (!empty($additionalInformation)): diff --git a/view/frontend/web/js/view/payment/method-renderer/applepayv2.js b/view/frontend/web/js/view/payment/method-renderer/applepayv2.js index 950f6d06..27eea32f 100644 --- a/view/frontend/web/js/view/payment/method-renderer/applepayv2.js +++ b/view/frontend/web/js/view/payment/method-renderer/applepayv2.js @@ -83,7 +83,7 @@ define( self = this; Promise.all([ - customElements.whenDefined(this.paymentCode) + customElements.whenDefined('unzer-payment') ]).then(() => { placeOrderAction(self.getData(), self.messageContainer) .done(function () { diff --git a/view/frontend/web/js/view/payment/method-renderer/basev2.js b/view/frontend/web/js/view/payment/method-renderer/basev2.js index 7c00f83a..8f3b3bf6 100644 --- a/view/frontend/web/js/view/payment/method-renderer/basev2.js +++ b/view/frontend/web/js/view/payment/method-renderer/basev2.js @@ -40,6 +40,7 @@ define( customerType: null, threatMetrixId: null, lastGrandTotal: null, + lastBillingAddressKey: null, defaults: { config: null, @@ -89,6 +90,34 @@ define( } }); + quote.billingAddress.subscribe(function (newAddress) { + if (!self.customerNeeded || !newAddress) { + return; + } + + if (!quote.paymentMethod() || quote.paymentMethod().method !== self.getCode()) { + return; + } + + let newKey = JSON.stringify({ + company: newAddress.company || '', + prefix: newAddress.prefix || '', + firstname: newAddress.firstname || '', + lastname: newAddress.lastname || '', + street: newAddress.street || '', + postcode: newAddress.postcode || '', + city: newAddress.city || '', + countryId: newAddress.countryId || '' + }); + + if (newKey === self.lastBillingAddressKey) { + return; + } + self.lastBillingAddressKey = newKey; + + self.waitForSetBasketData(); + }); + return this; }, @@ -100,6 +129,12 @@ define( const componentContainer = $('#unzer-component-' + this.getCode()); componentContainer.empty(); const unzerPayment = this.createUnzerPaymentElement(); + + const merchantConfig = this.getMerchantConfig(); + if (merchantConfig) { + unzerPayment.attr('skipFetchingMerchantConfig', 'true'); + } + const specificPaymentElement = this.createSpecificPaymentElement(); unzerPayment.append(specificPaymentElement); const unzerCheckout = this.createUnzerCheckoutPaymentElement(); @@ -107,6 +142,10 @@ define( componentContainer.append(unzerPayment); componentContainer.append(unzerCheckout); + if (merchantConfig) { + this.waitForSetMerchantConfigData(merchantConfig); + } + if (this.customerNeeded) { this.waitForSetBasketData(); } @@ -170,6 +209,30 @@ define( return window.checkoutConfig.payment.unzer.publicKey; }, + getMerchantConfig: function () { + return this._getMethodConfig('merchantConfig') + || window.checkoutConfig.payment.unzer.merchantConfig + || null; + }, + + waitForSetMerchantConfigData: function (config, maxRetries = 10, interval = 500) { + const unzerPayment = document.getElementById('unzer-payment-' + this.getCode()); + + if (!unzerPayment || typeof unzerPayment.setMerchantConfigData !== 'function') { + if (maxRetries > 0) { + setTimeout( + () => this.waitForSetMerchantConfigData(config, maxRetries - 1, interval), + interval + ); + } else { + console.error('setMerchantConfigData is not available after multiple retries.'); + } + return; + } + + unzerPayment.setMerchantConfigData(config); + }, + /** * Triggered when this payment method is unselected */ @@ -340,7 +403,7 @@ define( self = this; Promise.all([ - customElements.whenDefined(this.paymentCode) + customElements.whenDefined('unzer-payment') ]).then(() => { const unzerCheckoutElementId = 'unzer-checkout-' + this.getCode(); const unzerCheckout = document.getElementById(unzerCheckoutElementId); diff --git a/view/frontend/web/js/view/payment/method-renderer/cards.js b/view/frontend/web/js/view/payment/method-renderer/cards.js index 5412bb97..69e1ff2f 100644 --- a/view/frontend/web/js/view/payment/method-renderer/cards.js +++ b/view/frontend/web/js/view/payment/method-renderer/cards.js @@ -89,7 +89,7 @@ define( self = this; Promise.all([ - customElements.whenDefined('unzer-card') + customElements.whenDefined('unzer-payment') ]).then(() => { const unzerCheckout = document.getElementById('unzer-checkout-unzer_cards'); unzerCheckout.onPaymentSubmit = response => { diff --git a/view/frontend/web/js/view/payment/method-renderer/googlepay.js b/view/frontend/web/js/view/payment/method-renderer/googlepay.js index 357ded9e..8d800546 100644 --- a/view/frontend/web/js/view/payment/method-renderer/googlepay.js +++ b/view/frontend/web/js/view/payment/method-renderer/googlepay.js @@ -84,7 +84,7 @@ define( self = this; Promise.all([ - customElements.whenDefined(this.paymentCode) + customElements.whenDefined('unzer-payment') ]).then(() => { placeOrderAction(self.getData(), self.messageContainer) .done(function () {