Adyen / adyen-salesforce-commerce-cloud

Salesforce Commerce Cloud (formerly Demandware)
MIT License
90 stars 75 forks source link

Orders/payments to fail on open invoice payment options as Klarna and AfterpayTouch - error in the SFCC/Adyen cartridge #343

Closed MaaGJ closed 3 years ago

MaaGJ commented 4 years ago

Describe the bug Issue with open invoice data for orders with order-level discounts.

There is an issue with the line item price values sent to adyen, via the SFCC-adyen cartridge, for open invoices when an order has order-level discounts. The issue results in adyen failing the auth request and the customer is not able to use the open invoice payment method. The problem is present in cartridge version 19.1 which is the version we are currently using. I have also looked at the code for the newest cartridge (19.2.2) and it looks like the problem is also present there, but I haven’t tested it. The issue is in the following script, where line item data is collected and added to the adyen request object: • /int_adyen_overlay/cartridge/scripts/adyenGetOpenInvoiceData.ds. The below is part of the JSON the script generates. To better illustrate what data is being sent to adyen I have inserted the commerce cloud functions that the script uses to fetch the required data: image

Below are two examples of data being fetched from commerce cloud and sent to adyen via the cartridge. Scenario 1 works fine, but scenario 2 is where the issue occurs.

  1. Data for a line item without order-level discount: image
  2. Data for the same line item, but with a 10% order level discount: image

As you can see in scenario 2, the amountExcludingTax (adjustedNetPrice) is higher than in scenario 1, which doesn't make sense since it includes 10% discount. One would assume that the adjustedNetPrice would be lower in case 2. The reason for this is that commerce cloud includes the 10% discount in the adjustedTax (taxAmount), but the gross price does not include the discount.

When commerce cloud calculates adjustedNetPrice, they take the adjustedGrossPrice 995 (not including 10% discount) and subtracts the adjustedTax 179,1 (including the 10% discount), resulting in an adjustedNetPrice of 815,9. When data in scenario 2 is sent to adyen, adyen fails the request because the calculation of the taxAmount does not add up. The calculation adyen uses is: 815,90 (amountExcludingTax) * 0,25 (taxPercentage) = 203,97.. this result does not match the taxAmount 179,1 and therefore the request fails.

The conclusion is that the adyen cartridge should handle situations where an order-level discount has been applied for open invoice orders. Currently the values collected from commerce cloud, does not go through the adyen validation because of the above-mentioned discrepancies.

maassenbas commented 4 years ago

Hi @MaaGJ ,

Thank you for the detailed description of the bug.

As I can see in the code is that we take the "adjustedNetPrice", which is the price after applying all product-level adjustments. Basically, to fix the issue, we will have to make sure that we take the price also after applying all order-level adjustments. Reading the documentation, there is a function called getAdjustedPrice(applyOrderLevelAdjustments : boolean) : Money, which might be applicable in this case. Could you verify this?

Meanwhile, I will test it on my side and see if I can reproduce/fix this issue.

Kind regards, Bas Maassen Adyen

MaaGJ commented 4 years ago

HI @maassenbas

Yes, I can verify that using getAdjustedPrice(applyOrderLevelAdjustments : boolean) would work in this case.

Although you should take into account that ajustedNetPrice always returns the NET price (excluding vat) and getAdjustedPrice returns the GROSS price (including vat) for gross-price based sites and net price for net-based sites, so you can't just switch out the two functions with each other.

Also worth mentioning is that getAdjustedPrice(applyOrderLevelAdjustments : boolean) is only a ProductLineItem function, and not available as a function on ShippingLineItems

Hope this helps :)

maassenbas commented 4 years ago

Hi @MaaGJ ,

I've been trying to reproduce the described issue, but I can't unfortunately. When applying a discount on order level, a separate lineItem will be created for the discount with a negative amount. In following example I included 4 products, 1 shipping item and 1 discount line.

 [{
        "amountExcludingTax": "31500",
        "taxAmount": "3465",
        "description": "Summer Bomber Jacket",
        "id": "883360541075M",
        "quantity": "3",
        "taxCategory": "None",
        "taxPercentage": "1100"
    },
    {
        "amountExcludingTax": "4900",
        "taxAmount": "539",
        "description": "Classic Bermuda Short",
        "id": "701643382088M",
        "quantity": "1",
        "taxCategory": "None",
        "taxPercentage": "1100"
    },
    {
        "amountExcludingTax": "2999",
        "taxAmount": "330",
        "description": "STANDARD_SHIPPING",
        "id": "8f1a0bf68f2cdecb904a796234",
        "quantity": "1",
        "taxCategory": "None",
        "taxPercentage": "1100"
    },
    {
        "amountExcludingTax": "-9940",
        "taxAmount": "-1093",
        "description": "Discount",
        "id": "00bf38ccdaa77e18ca712de94d",
        "quantity": "1",
        "taxCategory": "None",
        "taxPercentage": "1100"
    }
 ]

The total amount that is set in the request is: "amount": { "currency": "USD", "value": 102630 }

If you calculate all the line items, the sum of all the lineItems is equal to the total amount.

I noticed that you have a field in the lineItems called amountIncludingTax, however, this is not included in the default cartridge. Could you verify whether you have done some customisations there?

Kind regards, Bas Maassen Adyen

MaaGJ commented 4 years ago

Hi Bas,

You have to set the Discount Taxation to “Tax Products and Shipping Only Based on Adjusted Price” in the business manager under: Merchant Tools > Site Preferences > Promotions. I should of course have mentioned this in my initial document, sorry about that. Also make sure you are testing on a Gross price based site and not net based.

Although, I have also tested it with the default setting: “Tax Products, Shipping, and Discounts Based on Price (default)”, but now the issue seems to be with the discounted line item instead of the product line item. So no matter what option I choose between the two, the same issue occurs.

If I use the same (default setting) as you this is what my lineitems looks like:

"lineItems": [{ "amountExcludingTax": "79600", "taxAmount": "19900", "description": "MOONLIGHT GRAPES øreringe", "id": "10014406", "quantity": "1", "taxCategory": "None", "taxPercentage": "2500" }, { "amountExcludingTax": "0", "taxAmount": "0", "description": "Standard Levering", "id": "fe48d2deda24742906f207240b", "quantity": "1", "taxCategory": "None", "taxPercentage": "0" }, { "amountExcludingTax": "-9950", "taxAmount": "-1990", "description": "Discount", "id": "2cde1524e95925e3bc02110529", "quantity": "1", "taxCategory": "None", "taxPercentage": "2500" } ]

If you look at the discount line item the "taxAmount": "-1990" is not correct as -9950*0,25 equals -2487,5 and NOT -1990 as listed in the request and therefore Adyen will fail the request.

The property “amountIncludingTax” is something we added to support afterpay touch.. I have tried removing this property from the request, but the request still fails. So it seems it has nothing to do with the issue.

maassenbas commented 3 years ago

Hi @MaaGJ ,

I'm trying to setup a Gross site to reproduce this issue, but can't get it to work properly. I would advise you to use the default setting for “Tax Products, Shipping, and Discounts Based on Price (default)”. What is the exact error you get when you configured the setting above? Is it possible to setup a call so you can screenshare your issue?

Kind regards, Bas Maassen Adyen

MaaGJ commented 3 years ago

Hi @maassenbas Will get back to you shortly re. a call, I will need my developer to join to demo the issue

MaaGJ commented 3 years ago

Hi @maassenbas How does 24/9 12pm Copenhagen time sound? Which email can I send the invite to?

MaaGJ commented 3 years ago

Hi @maassenbas please let me know when you are available, we are currently having a lot of orders with payment error due to a campaign running, so we would really appreciate if this could be fixed asap.

maassenbas commented 3 years ago

Hi @MaaGJ , Apologies for my late reply, I was out of office. I see that your team already reached out via email to the account manager, so let's setup a call and look into it.

Kind regards, Bas Maassen Adyen

MaaGJ commented 3 years ago

Hi Bas,

What is your availability for a call on Octh 14+16th? Alternatively in week 43?

Med venlig hilsen / Best Regards,

[cid:image001.png@01D69BD3.DE1214E0]

Maja Neris Aagaard Digital Project Manager

Mob: +45 25 24 83 23 GEORG JENSEN A/S Sdr. Fasanvej 7 2000 Frederiksberg | Denmark

[cid:image004.png@01D69BD3.DE1214E0]https://www.georgjensen.com/global?utm_campaign=signature&utm_medium=email&utm_source=george_jensen_mails [cid:image005.png@01D69BD3.DE1214E0] https://www.linkedin.com/company/georg-jensen [cid:image006.png@01D69BD3.DE1214E0] https://www.facebook.com/georgjensen/ [cid:image007.png@01D69BD3.DE1214E0] https://www.instagram.com/georgjensen/ [cid:image008.png@01D69BD3.DE1214E0] https://www.pinterest.com/GeorgJensen/ [cid:image009.png@01D69BD3.DE1214E0] https://www.youtube.com/channel/UCcV_-oORDKOKcSuy3sz19_g

[cid:image010.png@01D69BD3.DE1214E0]https://www.georgjensen.com/ From: Bas Maassen notifications@github.com Sent: 05 October 2020 10:42 To: Adyen/adyen-salesforce-commerce-cloud adyen-salesforce-commerce-cloud@noreply.github.com Cc: Maja Neris Aagaard maa@georgjensen.com; Mention mention@noreply.github.com Subject: Re: [Adyen/adyen-salesforce-commerce-cloud] Orders/payments to fail on open invoice payment options as Klarna and AfterpayTouch - error in the SFCC/Adyen cartridge (#343)

Hi @MaaGJhttps://github.com/MaaGJ , Apologies for my late reply, I was out of office. I see that your team already reached out via email to the account manager, so let's setup a call and look into it.

Kind regards, Bas Maassen Adyen

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Adyen/adyen-salesforce-commerce-cloud/issues/343#issuecomment-703491055, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQTEWF2GUONMLX2DCWFM4SDSJGBF3ANCNFSM4P52P42Q.

MaaGJ commented 3 years ago

Hi @maassenbas I have invited you for a call on Oct 16th 11am

MaaGJ commented 3 years ago

Hi @maassenbas thanks for the call on Friday, please see the examples we discussed attached. Look forward to hearing how your tests are going

Details for replicating OpenInvoiceData issue.docx

maassenbas commented 3 years ago

Hi @MaaGJ , Thanks for the details. We were able to reproduce it on our end. We created an internal ticket for this and will pick this up next sprint.

We will keep you updated.

Kind regards, Bas Maassen Adyen

zaiddreakh commented 3 years ago

Hi @MaaGJ,

We created this PR https://github.com/Adyen/adyen-salesforce-commerce-cloud/pull/388 Can you please check if that change fixes your issue? I tried it for version 19.2.2 and it worked for me

Looking forward to hearing from you. Regards, Zaid Adyen

MaaGJ commented 3 years ago

Hi Zaid,

Sounds great. I will review with my tech team and revert as soon as possible.

Med venlig hilsen / Best Regards,

[cid:image010.png@01D6B383.1564E5F0]

Maja Neris Aagaard Digital Project Manager

Mob: +45 25 24 83 23 GEORG JENSEN A/S Sdr. Fasanvej 7 2000 Frederiksberg | Denmark

[cid:image012.png@01D6B383.1564E5F0]https://www.georgjensen.com/global?utm_campaign=signature&utm_medium=email&utm_source=george_jensen_mails [cid:image013.png@01D6B383.1564E5F0] https://www.linkedin.com/company/georg-jensen [cid:image014.png@01D6B383.1564E5F0] https://www.facebook.com/georgjensen/ [cid:image015.png@01D6B383.1564E5F0] https://www.instagram.com/georgjensen/ [cid:image016.png@01D6B383.1564E5F0] https://www.pinterest.com/GeorgJensen/ [cid:image017.png@01D6B383.1564E5F0] https://www.youtube.com/channel/UCcV_-oORDKOKcSuy3sz19_g

[cid:image018.png@01D6B383.1564E5F0]https://www.georgjensen.com/ From: Zaid Dreakh notifications@github.com Sent: 04 November 2020 16:39 To: Adyen/adyen-salesforce-commerce-cloud adyen-salesforce-commerce-cloud@noreply.github.com Cc: Maja Neris Aagaard maa@georgjensen.com; Mention mention@noreply.github.com Subject: Re: [Adyen/adyen-salesforce-commerce-cloud] Orders/payments to fail on open invoice payment options as Klarna and AfterpayTouch - error in the SFCC/Adyen cartridge (#343)

Hi @MaaGJhttps://github.com/MaaGJ,

We created this PR #388https://github.com/Adyen/adyen-salesforce-commerce-cloud/pull/388 Can you please check if that change fixes your issue? I tried it for version 19.2.2 and it worked for me

Looking forward to hearing from you. Regards, Zaid Adyen

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Adyen/adyen-salesforce-commerce-cloud/issues/343#issuecomment-721806001, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQTEWF7CIRVFH6XG722ELSTSOFYSRANCNFSM4P52P42Q.