PAYONE-GmbH / magento-2

PAYONE Payment Extension for Magento 2
28 stars 56 forks source link

variable Klarna is not defined #443

Closed aws-ecommerce closed 2 years ago

aws-ecommerce commented 2 years ago

Hi there,

in the file Payone/Core/view/frontend/web/js/view/payment/method-renderer/klarna-method.js at line 211

there is

Klarna.Payments.authorize({

we are seeing hundreds of customers entering error Klarna is not defined

probably something wrong in a sequence of files loaded or you need to wait until variable is present.

This might cause a negative impact on the conversion rate.

image

janteuber commented 2 years ago

Hello @aws-ecommerce ,

Thank you very much for your message.

I will forward this to our agency and discuss the issue.

FatchipRobert commented 2 years ago

The error is indeed thrown when the Klarna.Payments.autorize() function is called before the Klarna Javascript is loaded.

BUT - this should not be possible if everything works as designed.

The Klarna.Payments.autorize() function is triggered inside the "validate()" function of the payment method and this validate function is triggered when the Place Order button has been clicked by the customer, but the Place Order button is hidden until the customer selected one of the 3 Klarna payment types.

The Klarna Javascript is loaded when the customer selects one of the 3 Klarna payment types, which also enables the Place Order button. Therefore the Klarna.Payments.autorize() function will be available once the Place Order button is clickable.

The only way I was able to reproduce this error was when I opened the browsers debug console and forcibly removed the "display:none;" flag from the Place Order button and then clicked it before choosing a Klarna payment type.

So I suppose for this error to happen the Place Order button in your shop is always shown or your shop executes the validate() function of the payment method in other places too.

Nevertheless - I added another check for if the Klarna payment type was selected and therefore the Klarna javascript is present, before the Klarna.Payments.autorize() function can be executed.

aws-ecommerce commented 2 years ago

@FatchipRobert thank you, it makes sense. indeed, we need to check if there is no validate() function being called. but your PR & code change should take care of it perfectly. thanks.