• Resolved tobbecokta

    (@tobbecokta)


    Hi,

    We have an issue with this plugin.

    We run WooCommerce with Klarna Checkout plugin. When we enable LiteSpeed Cache the button “Choose another payment method” in the Klarna checkout is not working.

    I have contacted Klarna Checkout who says this is because of issues in the Litespeed Cache plugin. I don’t know if that is correct, or if it is the Klarna plugin that is defect, I just want this issue fixed ??

    When a visitor presses the “Choose another payment method” the standard checkout page should be loaded, but instead nothing happens. The button is simply not working.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support qtwrk

    (@qtwrk)

    Hi,

    this looks like nonce issue

    please seach keyword “change_payment_method_nonce” through the Klarna plugin file and show me what you found

    Best regards,

    Thread Starter tobbecokta

    (@tobbecokta)

    Here is what I found:

    \klarna-checkout-for-woocommerce\assets\js\klarna-checkout-for-woocommerce.js  (2 hits)
    	Line 99: 					nonce: kco_params.change_payment_method_nonce
    	Line 133: 						nonce: kco_params.change_payment_method_nonc

    and

    \klarna-checkout-for-woocommerce\classes\class-kco-gateway.php  (1 hit)
    	Line 271: 				'change_payment_method_nonce'  => wp_create_nonce( 'kco_wc_change_payment_method' ),
    

    and

    \klarna-checkout-for-woocommerce\assets\js\klarna-checkout-for-woocommerce.min.js  (2 hits)
    	jQuery(function(a){if("undefined"==typeof kco_params)return!1;var r={bodyEl:a("body"),checkoutFormSelector:a("form.checkout"),paymentMethodEl:a('input[name="payment_method"]'),paymentMethod:"",selectAnotherSelector:"#klarna-checkout-select-other",shippingUpdated:!1,blocked:!1,preventPaymentMethodChange:!1,timeout:null,interval:null,klarnaUpdateNeeded:!1,documentReady:function(){r.log(kco_params),0<r.paymentMethodEl.length?r.paymentMethod=r.paymentMethodEl.filter(":checked").val():r.paymentMethod="kco","kco"===r.paymentMethod&&a("#ship-to-different-address-checkbox").prop("checked",!0),kco_params.pay_for_order||(r.moveExtraCheckoutFields(),r.updateShipping(!1))},kcoSuspend:function(o){window._klarnaCheckout&&window._klarnaCheckout(function(e){e.suspend({autoResume:{enabled:o}})})},kcoResume:function(){window._klarnaCheckout&&window._klarnaCheckout(function(e){!1===r.blocked&&e.resume()})},changeFromKco:function(e){e.preventDefault(),a(r.checkoutFormSelector).block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({type:"POST",dataType:"json",data:{kco:!1,nonce:kco_params.change_payment_method_nonce},url:kco_params.change_payment_method_url,success:function(e){},error:function(e){},complete:function(e){r.log(e.responseJSON),window.location.href=e.responseJSON.data.redirect}})},maybeChangeToKco:function(){r.preventPaymentMethodChange||(r.log(a(this).val()),"kco"===a(this).val()&&(a(".woocommerce-info").remove(),a(r.checkoutFormSelector).block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({type:"POST",data:{kco:!0,nonce:kco_params.change_payment_method_nonce},dataType:"json",url:kco_params.change_payment_method_url,success:function(e){},error:function(e){},complete:function(e){r.log(e.responseJSON),window.location.href=e.responseJSON.data.redirect}})))},moveExtraCheckoutFields:function(){a(".woocommerce-additional-fields").appendTo("#kco-extra-checkout-fields");var e=a('form[name="checkout"] input, form[name="checkout"] select, textarea'),o=!1;for(i=0;i<e.length;i++){var n=e[i].name.replace("[]","\\[\\]");a("table.woocommerce-checkout-review-order-table").find(e[i]).length||-1===a.inArray(n,kco_params.standard_woo_checkout_fields)&&("wc_checkout_add_ons"===a("p#"+n+"_field").parent().attr("id")?o||(o=!0,a("div#wc_checkout_add_ons").appendTo("#kco-extra-checkout-fields")):(0<a("p#"+n+"_field").length?a("p#"+n+"_field"):a('input[name="'+n+'"]').closest("p")).appendTo("#kco-extra-checkout-fields"))}},maybeDisplayShippingPrice:function(){var e;a(".kco-shipping").length||"kco"===r.paymentMethod&&"yes"===kco_params.shipping_methods_in_iframe&&"no"===kco_params.is_confirmation_page&&(a("#shipping_method input[type='radio']").length?a("#shipping_method input[type='radio']:checked").each(function(){var e=a(this).attr("id"),e=a("label[for='"+e+"']").text();a(".woocommerce-shipping-totals td").html(e),a(".woocommerce-shipping-totals td").addClass("kco-shipping")}):(e=a("#shipping_method input[name='shipping_method[0]']").attr("id"),e=a("label[for='"+e+"']").text(),a(".woocommerce-shipping-totals td").html(e),a(".woocommerce-shipping-totals td").addClass("kco-shipping")))},updateCart:function(){r.kcoSuspend(!0),a.ajax({type:"POST",url:kco_params.update_cart_url,data:{checkout:a("form.checkout").serialize(),nonce:kco_params.update_cart_nonce},dataType:"json",success:function(e){},error:function(e){},complete:function(e){a("body").trigger("update_checkout"),r.kcoResume()}})},getKlarnaOrder:function(){return console.log("getKlarnaOrder"),r.preventPaymentMethodChange=!0,a(".woocommerce-checkout-review-order-table").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({type:"POST",url:kco_params.get_klarna_order_url,data:{nonce:kco_params.get_klarna_order_nonce},dataType:"json",success:function(e){r.setCustomerData(e.data),0<a("form.checkout #terms").length&&a("form.checkout #terms").prop("checked",!0),console.log("success")},error:function(e){console.log("error")},complete:function(e){}})},setCustomerData:function(e){r.log(e),"billing_address"in e&&null!==e.billing_address&&(a("#billing_first_name").val("given_name"in e.billing_address?e.billing_address.given_name:""),a("#billing_last_name").val("family_name"in e.billing_address?e.billing_address.family_name:""),a("#billing_company").val("organization_name"in e.billing_address?e.billing_address.organization_name:""),a("#billing_address_1").val("street_address"in e.billing_address?e.billing_address.street_address:""),a("#billing_address_2").val("street_address2"in e.billing_address?e.billing_address.street_address2:""),a("#billing_city").val("city"in e.billing_address?e.billing_address.city:""),a("#billing_postcode").val("postal_code"in e.billing_address?e.billing_address.postal_code:""),a("#billing_phone").val("phone"in e.billing_address?e.billing_address.phone:""),a("#billing_email").val("email"in e.billing_address?e.billing_address.email:""),a("#billing_country").val("country"in e.billing_address?e.billing_address.country.toUpperCase():""),a("#billing_state").val("region"in e.billing_address?e.billing_address.region:""),a("#billing_email").change(),a("#billing_email").blur()),"shipping_address"in e&&null!==e.shipping_address&&(a("#ship-to-different-address-checkbox").prop("checked",!0),a("#shipping_first_name").val("given_name"in e.shipping_address?e.shipping_address.given_name:""),a("#shipping_last_name").val("family_name"in e.shipping_address?e.shipping_address.family_name:""),a("#shipping_company").val("organization_name"in e.shipping_address?e.shipping_address.organization_name:""),a("#shipping_address_1").val("street_address"in e.shipping_address?e.shipping_address.street_address:""),a("#shipping_address_2").val("street_address2"in e.shipping_address?e.shipping_address.street_address2:""),a("#shipping_city").val("city"in e.shipping_address?e.shipping_address.city:""),a("#shipping_postcode").val("postal_code"in e.shipping_address?e.shipping_address.postal_code:""),a("#shipping_country").val("country"in e.shipping_address?e.shipping_address.country.toUpperCase():""),a("#shipping_state").val("region"in e.shipping_address?e.shipping_address.region:""))},checkUrl:function(e){window.location.hash&&-1<window.location.hash.indexOf("#klarna-success")&&(r.logToFile("klarna-success hashtag detected in URL."),e({should_proceed:!0}),clearInterval(r.interval),clearTimeout(r.timeout),r.checkoutFormSelector.removeClass("processing"),a(".woocommerce-checkout-review-order-table").unblock(),a(r.checkoutFormSelector).unblock())},failOrder:function(e,o,n){n({should_proceed:!1}),r.blocked=!1;n=kco_params.pay_for_order?"div.woocommerce-notices-wrapper":"form.checkout";a("body").trigger("updated_checkout"),a(r.checkoutFormSelector).removeClass("processing"),a(r.checkoutFormSelector).unblock(),a(".woocommerce-checkout-review-order-table").unblock(),a(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),a(n).prepend('<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">'+o+"</div>"),a(n).removeClass("processing").unblock(),a(n).find(".input-text, select, input:checkbox").trigger("validate").blur(),a(document.body).trigger("checkout_error",[o]),a("html, body").animate({scrollTop:a(n).offset().top-100},1e3)},logToFile:function(e){a.ajax({url:kco_params.log_to_file_url,type:"POST",dataType:"json",data:{message:e,nonce:kco_params.log_to_file_nonce}})},log:function(e){kco_params.logging&&console.log(e)},updateShipping:function(e){r.kcoSuspend(!0),a("#kco_shipping_data").val(JSON.stringify(e)),a("body").trigger("kco_shipping_option_changed",[e]),a("body").trigger("update_checkout")},convertCountry:function(o){return Object.keys(kco_params.countries).find(e=>kco_params.countries[e]===o)},placeKlarnaOrder:function(o){r.blocked=!0,r.getKlarnaOrder().done(function(e){e.success?r.submitOrder(o):r.failOrder("get_order",'<div class="woocommerce-error">Failed to get the order from Klarna.</div>',o)})},submitOrder:function(n){a(".woocommerce-checkout-review-order-table").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({type:"POST",url:kco_params.submit_order,data:a("form.checkout").serialize(),dataType:"json",success:function(o){try{if("success"!==o.result)throw"Result failed";r.logToFile('Successfully placed order. Sending "should_proceed: true" to Klarna'),n({should_proceed:!0})}catch(e){o.messages?(r.logToFile("Checkout error | "+o.messages),r.failOrder("submission",o.messages,n)):(r.logToFile("Checkout error | No message"),r.failOrder("submission",'<div class="woocommerce-error">Checkout error</div>',n))}},error:function(e){try{r.logToFile("AJAX error | "+JSON.stringify(e))}catch(e){r.logToFile("AJAX error | Failed to parse error message.")}r.failOrder("ajax-error",'<div class="woocommerce-error">Internal Server Error</div>',n)}})},init:function(){a(document).ready(r.documentReady),r.bodyEl.on("update_checkout",function(){r.kcoSuspend(!0)}),r.bodyEl.on("updated_checkout",r.kcoResume),r.bodyEl.on("updated_checkout",r.maybeDisplayShippingPrice),r.bodyEl.on("change","input.qty",r.updateCart),r.bodyEl.on("change",'input[name="payment_method"]',r.maybeChangeToKco),r.bodyEl.on("click",r.selectAnotherSelector,r.changeFromKco),"function"==typeof window._klarnaCheckout&&window._klarnaCheckout(function(e){e.on({shipping_address_change:function(e){r.log("shipping_address_change"),r.log(e);var o=r.convertCountry(e.country.toUpperCase());0<=a("#shipping_first_name").length?(a("#ship-to-different-address-checkbox").prop("checked",!0),a("#ship-to-different-address-checkbox").change(),a("#ship-to-different-address-checkbox").blur(),a("#shipping_first_name").val("given_name"in e?e.given_name:""),a("#shipping_last_name").val("family_name"in e?e.family_name:""),a("#shipping_postcode").val("postal_code"in e?e.postal_code:""),a("#shipping_country").val("country"in e?o:""),a("#shipping_country").change()):(a("#billing_first_name").val("given_name"in e?e.given_name:""),a("#billing_last_name").val("family_name"in e?e.family_name:""),a("#billing_postcode").val("postal_code"in e?e.postal_code:""),a("#billing_country").val("country"in e?o:""),a("#billing_email").val("email"in e?e.email:""),a("#billing_country").change(),a("#billing_email").change(),a("#billing_email").blur()),a("form.checkout").trigger("update_checkout")},change:function(e){r.log("change",e)},order_total_change:function(e){r.log("order_total_change",e)},shipping_option_change:function(e){r.log("shipping_option_change",e),r.log(e),r.updateShipping(e)},can_not_complete_order:function(e){r.log("can_not_complete_order",e)},validation_callback:function(e,o){r.logToFile("validation_callback from Klarna triggered"),kco_params.pay_for_order?o({should_proceed:!0}):r.placeKlarnaOrder(o)}})})}};r.init()});
    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    okay , please use keyword kco_wc_change_payment_method

    add it into Cache -> ESI -> ESI nonce list , and also enable ESI

    after you have done it , please also provide the report number , you can get it in toolbox -> report -> click “send to LiteSpeed”

    Best regards,

    Thread Starter tobbecokta

    (@tobbecokta)

    Keyword added.

    Report generated, LGFZPZXU.

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    okay , from report it looks alright

    please let me know that goes

    Best regards,

    Thread Starter tobbecokta

    (@tobbecokta)

    Unfortunately we are still experiencing the same issue.
    When the “other payment method” button is clicked the page is reloaded but still it is only the Klarna Checkout showing.

    Plugin Support qtwrk

    (@qtwrk)

    now that makes no sense , I just notice the checkout is no-cache after all , so the nonce didn’t even gets cached

    I just tested and it seems working fine on me , how exactly do I need to do to reproduce it ?

    Thread Starter tobbecokta

    (@tobbecokta)

    I just checked again and the issue is still there.
    Can i share a screen video with you so you can see what I see?
    What email should I send to?

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    please upload it somewhere like Google driver or dropbox , then send the share link to support at litespeedtech.com with reference link to this topic

    Best regards,

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Causing error with Klarna Checkout’ is closed to new replies.