News:

Looking for documentation? Take a look on our wiki

Main Menu

AvaTax Fails with Authorize.net

Started by jessedyck, November 10, 2018, 00:40:51 AM

Previous topic - Next topic

jessedyck

Hello -

I'm building a new website that uses AxaTax for tax calculations and Authorize.net for it's payment processor. I had previously submitted many successful test transactions, but after a period of not paying attention to the store, my configuration has stopped working.

Tax calculation works perfectly fine in the cart, then on checkout it gives the error:
AvaTax Error Lines is expected to be between 1 and 15000.

I've been able to identify that this is indeed correct; there are 0 items being submitted to AvaTax. In avalara.php line 461 getCartProducts() returns nothing. Callstack at this point is:

#0 C:\MAMP\htdocs\plugins\vmcalculation\avalara\avalara.php(462): plgVmCalculationAvalara->getAvaTax(Object(stdClass), false, '1811091SAI07', 'TIGD09')
#1 C:\MAMP\htdocs\libraries\joomla\event\event.php(70): plgVmCalculationAvalara->plgVmConfirmedOrder(Object(VirtueMartCart), Array)
#2 C:\MAMP\htdocs\libraries\joomla\event\dispatcher.php(160): JEvent->update(Array)
#3 C:\MAMP\htdocs\components\com_virtuemart\helpers\cart.php(1231): JEventDispatcher->trigger('plgvmconfirmedo...', Array)
#4 C:\MAMP\htdocs\components\com_virtuemart\helpers\cart.php(941): VirtueMartCart->confirmedOrder()
#5 C:\MAMP\htdocs\components\com_virtuemart\controllers\cart.php(115): VirtueMartCart->confirmDone()
#6 C:\MAMP\htdocs\components\com_virtuemart\controllers\cart.php(228): VirtueMartControllerCart->display()
#7 C:\MAMP\htdocs\libraries\src\MVC\Controller\BaseController.php(710): VirtueMartControllerCart->updatecart()
#8 C:\MAMP\htdocs\components\com_virtuemart\virtuemart.php(120): Joomla\CMS\MVC\Controller\BaseController->execute('updatecart')
#9 C:\MAMP\htdocs\libraries\src\Component\ComponentHelper.php(402): require_once('C:\\MAMP\\htdocs\\...')
#10 C:\MAMP\htdocs\libraries\src\Component\ComponentHelper.php(377): Joomla\CMS\Component\ComponentHelper::executeComponent('C:\\MAMP\\htdocs/...')
#11 C:\MAMP\htdocs\libraries\src\Application\SiteApplication.php(194): Joomla\CMS\Component\ComponentHelper::renderComponent('com_virtuemart')
#12 C:\MAMP\htdocs\libraries\src\Application\SiteApplication.php(233): Joomla\CMS\Application\SiteApplication->dispatch()
#13 C:\MAMP\htdocs\libraries\src\Application\CMSApplication.php(196): Joomla\CMS\Application\SiteApplication->doExecute()
#14 C:\MAMP\htdocs\index.php(49): Joomla\CMS\Application\CMSApplication->execute()
#15 {main}


But prior to that, I can see that $products is set and sent to Avalara multiple times. So it seems like at some point in the checkout, the cart gets cleared.

Sure enough, in authorizenet.php on line 590, in plgVmConfirmedOrder(), the cart is cleared. AvaTax also runs plgVmConfirmedOrder(), which is where the failure occurs. So it seems to me that AvaTax is running after Authorize.net has cleared the cart, and is of course expecting to still have items in the cart. If I comment out that line, AvaTax works as expected; transaction is sent and logged on their end.

I've set up a few test sites to confirm this is not just happening on my 'production' website, but a base install of latest Joomla+VM, plus my last known good setup. I don't entirely know why this started happening just yet.

Hoping someone here with more knowledge of the workings of these systems can track down the source of the bug and/or proper solutions.  Thanks!

Milbo

Hello,

I wonder, maybe it is a joomla thing. The code there is


JPluginHelper::importPlugin('vmcalculation');
JPluginHelper::importPlugin('vmcustom');
JPluginHelper::importPlugin('vmshipment');
JPluginHelper::importPlugin('vmpayment');

$this->orderDetails = $orderDetails;

$returnValues = $dispatcher->trigger('plgVmConfirmedOrder', array($this, $orderDetails));


So the payment plugins should be executed as last. Maybe the order changed somehow.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

My investigations give the following idea.

We do a correct import of the plugins before we use the trigger. But when I check the function, it looks cached. So we do not change the order of the plugin calls, when we call the import stuff again.

So it could be possible, that for example some modules loads first and imports in a different ordering.

I added now the imports to the constructor of the cart


public function __construct() {
$this->useSSL = vmURI::useSSL();
$this->useXHTML = false;
$this->cartProductsData = array();
$this->layout = VmConfig::get('cartlayout','default');

if(empty($this->layout)){
$this->layout = 'default';
}
JPluginHelper::importPlugin('vmextended');
JPluginHelper::importPlugin('vmcalculation');
JPluginHelper::importPlugin('vmcustom');
JPluginHelper::importPlugin('vmcoupon');
JPluginHelper::importPlugin('vmshipment');
JPluginHelper::importPlugin('vmpayment');
JPluginHelper::importPlugin('vmuserfield');
}


and removed all other imports in the carthelper. Seems to work well. I think about to add to the config constructor so it is always correctly loaded. But on the other hand, it is not sophisticated to load always all plugins.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

jessedyck

Thanks Milbo! This coming together now. Are you suggesting that it's because the plugins are being loaded as-needed throughout the cart, there's a chance they can be loaded out of order, depending on the code path taken?

Assuming the file you are talking about is /components/com_virtuemart/helpers/cart.php, I've tested this out on my production and local server and it does get me closer (no more error message and the checkout is completed) but the transaction isn't registered with AvaTax. I've updated the constructor as you've shown. It also doesn't seem to matter if I remove or leave the other calls to JPluginHelper::importPlugin() in the cart, I get the same result: Successful transaction, but nothing registered with AvaTax. Am I perhaps looking at the wrong file?

Milbo

No, it is the correct file. But I decided now to add it to loadConfig.

Quotethere's a chance they can be loaded out of order, depending on the code path taken?
Exactly and so I think it should be directly loaded correctly, when VM is the first time loaded. Else we never know, if not a for example a product module, showing the shipment prices rendered before mixes up or odering.

Please open the config helper in the /helper directory of your backend folder. There is around line 488 if($exeTrig and $app->isSite()){

just make it like that

if($exeTrig and $app->isSite()){
// try plugins
JPluginHelper::importPlugin('vmextended');
JPluginHelper::importPlugin('vmcalculation');
JPluginHelper::importPlugin('vmcustom');
JPluginHelper::importPlugin('vmcoupon');
JPluginHelper::importPlugin('vmshipment');
JPluginHelper::importPlugin('vmpayment');
JPluginHelper::importPlugin('vmuserfield');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('plgVmInitialise', array());
$execTrigger = false;
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

jessedyck

Thanks for the continued help!

Quote from: Milbo on November 16, 2018, 09:27:11 AM
Please open the config helper in the /helper directory of your backend folder. There is around line 488 if($exeTrig and $app->isSite()){

I don't see that conditional around line 488 in `/administrator/components/com_virtuemart/helpers/config.php`. I do see it on line 860 (using VM3.4.2). If I make the change as described, and after reinstalling 3.4.2 to reset all my previous changes, I'm back receiving the error message `AvaTax Error Lines is expected to be between 1 and 15000.`

Milbo

That cant work, because you reinstalled it. You must add it now, but I also just uploaded a new version, just use that package. Of course j3.9
http://dev.virtuemart.net/attachments/download/1149/com_virtuemart.3.4.3.9989_package_or_extract.zip
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

jessedyck

I've upgraded now to J!3.9 and installed the new package, but it's again reverted to that same error message.

Here's the full list of errors I'm getting, with debugging turned on:


AvaTax Error Lines is expected to be between 1 and 15000.

Notice: Undefined index: subTotal in C:\MAMP\htdocs\administrator\components\com_virtuemart\helpers\calculationh.php on line 833

Notice: Undefined index: percentage in C:\MAMP\htdocs\administrator\components\com_virtuemart\helpers\calculationh.php on line 916

Warning: Invalid argument supplied for foreach() in C:\MAMP\htdocs\plugins\vmcalculation\avalara\avalara.php on line 895

Warning: Invalid argument supplied for foreach() in C:\MAMP\htdocs\administrator\components\com_virtuemart\helpers\calculationh.php on line 194


This is with PHP7.1, J3.9 and VM3.4.3.9989

Note those last two, that's where the foreach gets $products as a boolean (false) rather than the array of items in the cart.