Copied to clipboard

Flag this post as spam?

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


  • Tobbe 74 posts 376 karma points c-trib
    Jul 13, 2017 @ 11:08
    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 2533 posts 8125 karma points
    Jul 13, 2017 @ 11:25
    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 74 posts 376 karma points c-trib
    Jul 13, 2017 @ 11:29
    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 2533 posts 8125 karma points
    Jul 13, 2017 @ 11:32
    Anders Burla Johansen
    0

    What Tea Commerce version do you use?

  • Tobbe 74 posts 376 karma points c-trib
    Jul 13, 2017 @ 11:38
    Tobbe
    0

    How can I see that? :)

    It is one of the newest, 3+

  • Anders Burla Johansen 2533 posts 8125 karma points
    Jul 13, 2017 @ 11:40
    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 74 posts 376 karma points c-trib
    Jul 13, 2017 @ 11:44
    Tobbe
    0

    3.2.0

  • Anders Burla Johansen 2533 posts 8125 karma points
    Jul 13, 2017 @ 11:48
    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 74 posts 376 karma points c-trib
    Jul 13, 2017 @ 12:20
    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 2533 posts 8125 karma points
    Jul 13, 2017 @ 12:42
    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 15 posts 37 karma points
    Jul 17, 2017 @ 11:34
    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 74 posts 376 karma points c-trib
    Jul 13, 2017 @ 13:14
    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 15 posts 37 karma points
    Jul 17, 2017 @ 17:20
    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

  • Anders Burla Johansen 2533 posts 8125 karma points
    Aug 08, 2017 @ 08:23
    Anders Burla Johansen
    0

    Hi Peter

    The problem with ignoring the TotalDiscount is that you can also have discount on the total price. Its not just a sum of the subtotal, shipping and payment discount - it can have its own discount. That is why we just parse one amount with all the discounts deduced as its pretty hard to make some nice UI that takes ALL the discount possibilities into account :)

    Kind regards

    Anders

  • Peter Josefson 15 posts 37 karma points
    Aug 08, 2017 @ 14:18
    Peter Josefson
    0

    Hi Anders,

    OK, I'll hold my horses regarding the pull request, then. This customer has very specific opinions about this, they may not be very widespread.

    But if I get the time I will look deeper into the various ways to calculate discounts. I will also add a comparison between your sums and mine - if they don't match, I fall back to the simplified version..

    Sounds like a plan?

  • Anders Burla Johansen 2533 posts 8125 karma points
    Aug 09, 2017 @ 07:20
    Anders Burla Johansen
    0

    Its always better to find a solution that works 100% of the times and not does a fallback for some cases and works in other cases in a different way. So dont think the fallback is a good idea :)

    Kind regards

    Anders

  • Peter Josefson 15 posts 37 karma points
    Aug 09, 2017 @ 08:39
    Peter Josefson
    0

    Yeah, of course it is so. But a fail-safe is always good, as this is something that would blow up in a customer's face otherwise. :)

    The goal is of course that the provider should work for all discount cases possible today, but degrade gracefully if TeaCommerce introduces new cases.

Please Sign in or register to post replies

Write your reply to:

Draft