How to calculate tax when manually creating OrderInfo

Al Burns asked on September 23, 2020 17:42

Hi. I am implementing a recurring payment method for my client and need to manually create an order for when the payment is due for renewal.

I am following the guidance in the documentation - https://docs.kentico.com/api11/e-commerce/orders which is pretty straight forward, but I need to set the OrderTotalTax value. Can anyone confirm what the best way to go about this is? Many thanks.

Recent Answers


Development Support answered on September 24, 2020 21:27 (last edited on September 24, 2020 21:27)

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 24, 2020 21:27

Kentico usually uses the ShoppingCartInfo to generate Orders, which during that conversion process (ShoppingCartInfoProvider.SetOrder(ShoppingCart)) it handles figuring out taxes and such.

var ShoppingCart = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(PreviousOrderID);
ShoppingCart.OrderId = 0; // Will make the system think it's a new order
ShoppingCartInfoProvider.SetOrder(ShoppingCart); // Create order

That should hook up automatically the tax services to find the proper taxes and such. Try that!

0 votesVote for this answer Mark as a Correct answer

Al Burns answered on September 25, 2020 09:21

Thanks Trevor. I had previously tried using the shopping cart but as my code is in a data handler called by a 3rd party payment provider (Stripe) ECommerceContext.CurrentShoppingCart returned null.

Your example looks different though so I will give that a try, thanks.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.