Reduce API calls to TaxCloud

  • Posts: 176
  • Thank you received: 5
  • Hikashop Business
2 years 8 months ago #335058

-- HikaShop version -- : 4.4.3
-- Joomla version -- : 3.9.28
-- PHP version -- : 7.4.22

We are using the HikaShop TaxCloud Plugin to calculate tax. Recently Taxcloud changed its billing structure and now charges per API call (an extra $10 for every 1000 calls over the first 1000). This has resulted in a $30 - $50 increase in our monthly bill. Is there any way the number of API calls can be reduced? It seems that each time a customer adds a product to the cart and then views the cart it results in API calls. For some transactions, customers are naturally moving between the cart and product pages, but this results in 10-20 API calls for that one purchase. Is there any way this can be reduced? For example, the tax is not calculated until a step after the cart? Looking for the minimal amount of API calls to TaxCloud per transaction.

Thank you,
Dustin

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
2 years 8 months ago #335060

Hi,

Cache is already implemented in the TaxCloud plugin.
When a cart is loaded, three functions of the plugin are called:
- verifyAddress which get the USPS address from the address entered by the user to make sure that we're dealing with a valid address
- lookup which load the taxes for the products
- onAfterProcessShippings which load the taxes for the shipping methods
In each function, you'll see that the code uses getUserState and setUserState to store and load data to / from the user session so that if a request is the same as one already done, it is skipped and the data in the user session is used instead.
So these functions are called each time a product will be added to the cart, and then when the user enters his address, when he changes his cart content, or modify his address, and then another 2 functions will be called again when the order is created (and maybe one when the order is confirmed).
So that can quickly add up.

While the taxes might not be needed on your website before the customer access the cart, that might be different for someone else. If the customer is already logged in with a user with an address and he adds something in the cart, if the cart module is displayed on the page where the customer adds a product in the cart, and the cart module is configured to display taxes, it needs the taxes to be calculated. Or if the merchant is using the "shipping estimation" plugin so that the customer can get the shipping price on the product page while the shipping methods are taxed and he wants to display the shipping prices with taxes.

Thinking about it, I suppose some code could be added to the plugin to skip when the user didn't login or fill in the guest form yet.
Try adding the code:

if(!hikashop_loadUser(false))
			return false;
just after the lines:
protected function lookup(&$cart) {
and:
protected function verifyAddress() {
If that helps, we could add an option to skip the calls before the user login or fill in the guest form

Please Log in or Create an account to join the conversation.

  • Posts: 176
  • Thank you received: 5
  • Hikashop Business
2 years 7 months ago #335177

Thank you, Nicolas. This is great information. For our particular situation, our store is only accessible after the user has an account (no public-facing store or guest checkout). We do use the cart module in our store, but the Taxes option is set to "No". With this, is it safe to say that all the Taxcloud API calls are coming from when the user changes their shipping address or when they view the cart step in checkout after adding/removing a product?

The way we use our store is primarily for company-branded merchandise in which products are shipped to a set number of our company locations. I'm wondering if we had a set number of global addresses for the user to select from if this might help with the API calls. We currently use a custom field for them to select the warehouse to transfer their products, but it seems that part of this problem might be that they can enter in their own address. Would it be possible to have a global set of addresses to choose from with one pre-selected for all members of a user group?

Any other suggestions for reducing API calls would be welcome. Thank you again for your help!

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
2 years 7 months ago #335183

Hi,

In that case, the code modification I proposed won't help you at all.
Where you can save on TaxCloud API calls:
- make sure that every user that has access to the non public store already has at least one billing and one shipping address and that the one that will be most used is their default billing/shipping address (that will reduce the address switching needed).
- prevent the customers from changing the products in their cart on the cart module / checkout.
- allow customers to add products to the cart in bulk. If your products don't have variants/options/custom item fields, you can set the "Add to cart on listings" setting to "global on listings" in the HikaShop configuration and make sure that the "add to cart button" setting is activated in your products listings. That way, on the listings, you'll get a quantity field for each product and a main add to cart button at the bottom of the listing so that customers can add several products of the same listing at once.

Please Log in or Create an account to join the conversation.

  • Posts: 176
  • Thank you received: 5
  • Hikashop Business
2 years 7 months ago #335220

Thank you for the suggestions.

I've tried disabling the ability to delete products from the Shopping Cart module. I'm hesitant to remove that in either the cart or module as customers need an easy way to remove their products. We'll try it this month to see how much it impact the API calls.

Bulk is enabled where possible. Several items have variants.

Is there a way we could set up global addresses for our users and have one set for each user by default? (i.e. each user would have their own default address from this list). Each employee is associated with a warehouse, so this setup would be ideal.

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
2 years 7 months ago #335229

Hi,

When you have the cart in "mini" mode and you activate the corresponding setting in the cart module, you have an icon to delete the whole cart at once. So you could activate this while disabling the ability for them to delete the products one by one.
But as you said, I think it will make the life of your users harder.

The addresses are per user. So if you wanted to have a custom system to automatically add all the global addresses to your users when they are created / logged in, that would be possible with a custom plugin development. But that will cost a few hundred euros and I'm not sure it will reduce the API calls that much.
The way TaxCloud API is made, it requires many API calls :/

One other idea would be to only call the TaxCloud API when the order is being created. The drawback is that the customer doesn't see the tax amount before he already went through the checkout and discovers the total amount with taxes on the payment gateway page. But that would allow you to reduce drastically the amount of API calls while the modifications are not too complex to add to the plugin.

Please Log in or Create an account to join the conversation.

  • Posts: 176
  • Thank you received: 5
  • Hikashop Business
2 years 7 months ago #335488

I would like to proceed with having a custom plugin developed for having global addresses. As you mentioned, it might not decrease API calls, but right now we are having some issues with zip codes lining up. Please let me know how to proceed in having this developed.

I am also open to funding improvements to the Taxcloud plugin to include the ability to implement the options you mentioned for reducing API calls.

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
2 years 7 months ago #335497

Hi,

I think it could be done by overriding the whole hikashopAddressClass of administrator/components/com_hikashop/classes/address.php with a system plugin to be able to override the functions getByUser, loadUserAddresses and getCurrentUserAddress so they always return the same list of addresses.
We actually have documentation on how to do that here:
www.hikashop.com/support/documentation/6...ntation.html#classes
The question will then be how that list of addresses is provided to the plugin ? With options in the plugin ? Directly hard coded in the code of the plugin ? With some kind of interface in the backend ? Should the provided addresses be different for billing and shipping ?

Regarding the TaxCloud plugin, the only solution I see is to not calculate the tax at all until the order is created. That's possible but it has huge implications for customers since they won't know the amount of taxes they'll be charged until the order is created. We can't add that, even as an option to the plugin.
Another possibility would be to calculate the taxes in the cart based on the current URL. That's possible, but again, it's more of a custom thing than a standard thing we should add in the plugin I think.

Please Log in or Create an account to join the conversation.

  • Posts: 176
  • Thank you received: 5
  • Hikashop Business
2 years 7 months ago #335563

We would want all users still to be able to have the ability to have their own addresses. What we are looking for is the ability to have additional global addresses that would be available to each user assigned by user group.

I'm thinking on the admin side a component or plugin in which you can create addresses (there will be about 50+) that allows you to assign each address individually to a user group. Then when those users are in checkout they can enter/select their own or select an address from ones available to them. I can write a more detailed scope of what we are looking for if it helps. Let me know how you would like to proceed.

For the Taxcloud plugin, calculating on the current URL sounds like a better solution.

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
2 years 7 months ago #335574

Hi,

So all that is possible. However, it requires quite a bit of work.
We can talk about costs via our contact form:
www.hikashop.com/support/contact-us.html

I would personally recommend to first work on a custom TaxCloud plugin, with a check to skip it based on either a whitelist or a blacklist of URLs. I suppose that it's something which could be done in a matter of several hours of work.
Having a component to manage addresses and inject them to the address list of the customers is possible, but we're talking about a bigger project with at least several days of work.

Please Log in or Create an account to join the conversation.

Time to create page: 0.073 seconds
Powered by Kunena Forum