Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tobbe 72 posts 354 karma points c-trib
    1 week ago
    Tobbe
    0

    Discount not applied on payment provider (Klarna)

    Hello

    We have a problem with "Order amount award"-discount code. Everything seems to work on the site, but when clicking on "Continue to payment", Klarna shows the total amout WITHOUT discounts. So I suspect that discounts are applied on the site correctly (checking with the javascript API), but the wrong numbers are sent to the payment provider.

    Note: Discounts are working for specified products with the "Order line amount award"-discount code.

  • Anders Burla Johansen 2500 posts 7991 karma points
    1 week ago
    Anders Burla Johansen
    0

    Hi Tobbe

    The payment providers sent the value with all discounts subtracted. See line 192 of Klarna and line 69 of ePay. The use order.TotalPrice.Value.WithVat - so you can try and output that to your UI and see if that is the right amount.

    https://github.com/TeaCommerce/Payment-providers/blob/master/Source/TeaCommerce.PaymentProviders/Inline/Klarna.cs

    https://github.com/TeaCommerce/Payment-providers/blob/master/Source/TeaCommerce.PaymentProviders/Classic/ePay.cs

    Kind regards

    Anders

  • Tobbe 72 posts 354 karma points c-trib
    1 week ago
    Tobbe
    0

    Hi!

    Okey, I tried that and it shows the correct amount (with discounts). But Klarna still shows the amount wihtout discounts.

    Any ideas?

  • Anders Burla Johansen 2500 posts 7991 karma points
    1 week ago
    Anders Burla Johansen
    0

    What Tea Commerce version do you use?

  • Tobbe 72 posts 354 karma points c-trib
    1 week ago
    Tobbe
    0

    How can I see that? :)

    It is one of the newest, 3+

  • Anders Burla Johansen 2500 posts 7991 karma points
    1 week ago
    Anders Burla Johansen
    0

    In your installed packages look at the package there, or right click the dll file and choose properties and for newer Tea Commerce versions the version number is there. If it just says 2.0 or 1.0 then you need to look in the installed packages.

    If you are not running the latest version, then what you state could be a bug that was fixed.

    Kind regards

    Anders

  • Tobbe 72 posts 354 karma points c-trib
    1 week ago
    Tobbe
    0

    3.2.0

  • Anders Burla Johansen 2500 posts 7991 karma points
    1 week ago
    Anders Burla Johansen
    0

    Try and update to latest and then download the payment provider project from Github and attach the debugger and see what value is sent to Klarna. Sounds weird that if you print that out, that it's a wrong one that is sent to Klarna.

  • Tobbe 72 posts 354 karma points c-trib
    1 week ago
    Tobbe
    0

    Okay, Ill try that.

    If I use "Order line amount award" and choose "Unit price" everything works. If I use "Order line amount award" and choose "Total price" discounts are not applied.

  • Anders Burla Johansen 2500 posts 7991 karma points
    1 week ago
    Anders Burla Johansen
    0

    Ahh so it might be a bug in the marketing engine giving discounts on total order line amount but its working with unit price amount award. Please try and locate if that is the problem and not a problem with Klarna. Then it would be much easier to debug the right place :)

    Kind regards

    Anders

  • Peter Josefson 11 posts 33 karma points
    4 days ago
    Peter Josefson
    0

    Hi,

    Peter @ Toxic here, I've taken over the case from Tobbe. As you saw, we worked around the problem using the latest version - HOWEVER, the order lines are no longer specified to Klarna - only the total.

    So, I'll try to figure out where that changed, go back to the previous version and then check if the workaround is effective there, too.

    Any explanation for the Total-thing?

    EDIT: I found the culprit, it's the commit from 2014-12-04 that replaced the order lines with a total (intentionally, because of discount problems). Unfortunately, our customer needs the order lines to be on the order, so I'll try to tweak the version before that into working.

  • Tobbe 72 posts 354 karma points c-trib
    1 week ago
    Tobbe
    100

    Hi,

    After looking closer, we found something weird when the ProcessRequest method (communiation type "checkout") in Klarna.cs fetches the amount. In all other cases, order.TotalPrice.Value is equal to order.TotalPrice.WithDiscounts, but at this particular place, it's not.

    So after changing the line where it's set in Klarna's order to the following, it works:

              List<Dictionary<string, object>> cartItems = new List<Dictionary<string, object>> {
            new Dictionary<string, object> {
              {"reference", settings.ContainsKey( "totalSku" ) ? settings[ "totalSku" ] : "0001"},
              {"name", settings.ContainsKey( "totalName" ) ? settings[ "totalName" ] : "Total"},
              {"quantity", 1},
              // Changed:
              {"unit_price", (int) ( order.TotalPrice.WithDiscounts.WithVat * 100M )},
              {"tax_rate", 0}
            }
          };
    

    We're up and running now, but I think you should investigate it.

  • Peter Josefson 11 posts 33 karma points
    4 days ago
    Peter Josefson
    0

    Anders,

    I have now built a combined version of the current Klarna provider and the one which specifies all order lines. I've also modified it (the old part) so that the current discount options should work as designed (only a few tested, though).

    The only modification is the part where the cartItems list is built. I now add ordinary order lines (discounted, any discounts here don't seem to be specified elsewhere), subtotal discounts (one line for each, with campaign names), shipping (discounted, and only if it has an undiscounted price), payment fee (same logic), total discounts (TotalPrice.Discounts, one line for each, with campaign names - I ignore TotalDiscount as it includes subtotal discounts) and finally gift cards.

    So, slightly different logic than the old version, and it seems to result in a proper cart object for Klarna.

    I'll comment further when we have tested more. A pull request will be coming your way after that. :D

Please Sign in or register to post replies

Write your reply to:

Draft