Change VAT at checkout

Is there any way to change the VAT for an order at checkout and then re-calculate?

I’ve tested many ways all from CartContextSession, TransitionService and more.

We have a special case where we dont want to use the coutries VAT (a bug with filters required to update the litium version, witch is not a alternative to the customer) and have created a VAT as a field on channels. It seems that the Accellerator VAT tied to the country is deeply nested in the order creationflow and no obvious way to manipulate it at checkout.

Litium version: 8.7.1

The only way I directly have in mind is that you implement your own vat rule, see US sales tax and Litium - Questions - Litium Forum there you have some info about how that can be implemented.

May I ask why the VAT on the delivery country cant be used?

Yes, I found that yesterday ad I’m implementing and testing it today. Thanks!

I can’t explain in detail why we have a seperate VAT on the channel, but I have heard that we had issues getting correct prices when we set the countries VAT rate other than 0.

Ok so I tested the IVatFactory and tried to manipulate the prices to out channels VAT, but the orderrows themselves are not changed:

{
  "action": "Litium.Connect.Erp.Events.OrderConfirmed",
  "properties": {
    "RemoteIpAddress": "::1",
    "Device": "PostmanRuntime/7.32.3"
  },
  "resource": {
    "systemId": "870181aa-7620-4b50-96ec-a6b4fd4b73f3",
    "item": {
      "id": "LS10550",
      "currencyCode": "SEK",
      "grandTotal": 350,
      "orderCreatedAt": "2023-09-14T11:54:41.2259485Z",
      "channelId": "test",
      "webSiteId": "test",
      "countryCode": "SE",
      "type": "salesOrder",
      "clientIp": "127.0.0.1",
      "comments": "||",
      "additionalInfo": {},
      "rows": [
        {
          "id": "1",
          "type": "product",
          "articleNumber": "1046263",
          "descriptions": "USB-A - USB-C",
          "unitPriceIncludingVat": 280,
          "unitPriceExcludingVat": 280,
          "quantity": 1,
          "unitOfMeasurement": "st",
          "vatRate": 25,
          "totalIncludingVat": 280,
          "totalExcludingVat": 280,
          "additionalInfo": {}
        }
      ],
      "vatSummary": {
        "0": 0
      },
      "promotions": [],
      "payments": [
        {
          "id": "LSP11179",
          "paymentProviderName": "DirectPayment",
          "paymentMethodName": "DirectPay",
          "paymentAccountId": "",
          "totalAuthorizedAmount": 350,
          "transactions": [
            {
              "id": "----------",
              "type": "authorize",
              "totalIncludingVat": 350,
              "totalExcludingVat": 280,
              "rows": [
                {
                  "orderRowId": "1",
                  "type": "product",
                  "descriptions": "USB-A - USB-C",
                  "unitPriceIncludingVat": 350,
                  "unitPriceExcludingVat": 280,
                  "quantity": 1,
                  "vatRate": 25,
                  "totalIncludingVat": 350,
                  "totalExcludingVat": 280,
                  "additionalInfo": {}
                }
              ]
            },
            {
              "id": "LSP11179T1",
              "totalIncludingVat": 350,
              "totalExcludingVat": 280,
              "rows": [
                {
                  "orderRowId": "1",
                  "type": "product",
                  "descriptions": "USB-A - USB-C",
                  "unitPriceIncludingVat": 350,
                  "unitPriceExcludingVat": 280,
                  "quantity": 1,
                  "vatRate": 25,
                  "totalIncludingVat": 350,
                  "totalExcludingVat": 280,
                  "additionalInfo": {}
                }
              ]
            }
          ]
        }
      ],
      "shipments": [],
      "customerInfo": {
        "customerNumber": "K1129186",
        "firstName": "Lucas",
        "lastName": "Wiseby",
        "email": "---------",
        "organizationCustomerNumber": "K1129186",
        "additionalInfo": {}
      },
      "billingAddress": {
        "address1": "Testvägen 11",
        "city": "Saltsjö Boo",
        "country": "SE",
        "zip": "13249",
        "organizationName": "Test Litiumintegration AB"
      },
      "shippingInfo": [
        {
          "shippingMethod": "standardPackage",
          "additionalInfo": {
            "IsFreeShipping": true
          },
          "address": {
            "careOf": "företag",
            "address1": "hej",
            "address2": "då",
            "city": "Borås",
            "country": "SE",
            "phone": "123123123",
            "zip": "123123",
            "organizationName": "Test Litiumintegration AB"
          }
        }
      ],
      "rmas": []
    }
  },
  "metadata": {
    "attempt": 1,
    "eventSystemId": "fec6bb6b-ea55-4dc4-9d6b-6a19719e242a",
    "registrationId": "orderconfirmedtest1"
  }
}

As you can see, the transactions are correct but the “rows” stay the same.

This is my factory for testing:

using System.Linq;
using JetBrains.Annotations;
using Litium.Runtime.DependencyInjection;
using Litium.Sales;
using Litium.Sales.Calculator;

namespace Litium.Accelerator.Services;

[UsedImplicitly]
[ServiceDecorator(typeof(IVatRuleFactory))]
internal class CustomVatRuleFactory : IVatRuleFactory
{
    private readonly IVatRuleFactory _parent;
    private readonly BaseSalesVat _baseSalesVatRule;

    public CustomVatRuleFactory(IVatRuleFactory _parent, BaseSalesVat baseSalesVatRule)
    {
        this._parent = _parent;
        _baseSalesVatRule = baseSalesVatRule;
    }
    
    public IVatRule Create<T>(Order<T> order) where T : OrderRow
    {
        return _baseSalesVatRule;
    }
}

[Service(ServiceType = typeof(BaseSalesVat))]
public class BaseSalesVat : IVatRule
{
    public void CalculateVat<T>(Order<T> order) where T : OrderRow
    {
        CalculateVat(order, 25.0m);
    }
    
    private void CalculateVat<T>(Order<T> order, decimal vat) where T : OrderRow
    {
        foreach (var row in order.Rows)
        {
            row.VatRate = vat;
            var rowVat = vat / 100 * row.TotalExcludingVat;
            var rowUnitVat = vat / 100 * row.UnitPriceExcludingVat;
                
            row.UnitPriceIncludingVat = row.UnitPriceExcludingVat + rowUnitVat;
            row.TotalIncludingVat = row.TotalExcludingVat + rowVat;
            
            row.VatDetails.Clear();
            row.VatDetails.Add(new VatDetail
            {
                Vat = rowVat, VatRate = vat,
                AmountIncludingVat = row.TotalIncludingVat
            });
        }
    }
}

I think this question is more important to get the answer on then starting to implement own logic for this. The reason is that the inbuilt VAT logic handle the tax for the EU regulations.

Yes I understand. We have som technical debt on this one and we thought that we could work our way around this a little while longer.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.