Avalara Developer Network Developer avaTax

Getting our PHP Samples Running on Windows

Zend Certified Engineer Logo As I said in my introduction, I’m a Zend Certified PHP Engineer. I may not have mentioned that, like many developers, I tend to trust my abilities probably more than I should, jump into projects head first, and only start to read the fine manual when something doesn’t work as expected.

Setting up my Avalara laptop, one of the first things I did was install a basic WAMP stack (like LAMP but with Windows). That may be sacrilege to some, but it works.

When I had to write my first bit of code with the PHP sample libraries, I thought “I got this,” pulled the PHP REST for AvaTax samples down from GitHub, and ran the PingTest sample in the browser.

It failed.

Warning: require(vendor/autoload.php): failed to open stream: No such file or directory...

Yup, there’s no vendor folder in there. Where did that come from? What had I missed?

Step 1: You have to install our PHP samples

I’d missed that this set of samples uses Composer for dependency management. If you haven’t already, go to the Composer download page, download the Windows installer, then run it.

It will set up Composer and make sure it’s in your Windows path. If you had any command windows open, they will not know about the changes to the Windows path. You’ll need to open a new one in the directory you downloaded our samples to. I recommend this handy shortcut:

shift + right click on a directory In the File manager, hold down SHIFT while right-clicking the directory where your copy of the Avalara code is. You’ll see an option to “Open a command window here.” Choose it.

You can then run “composer install” in the command window.

After that, you should be able to run the sample code… as long as you’ve set up your PHP installation with the proper root certificates so you can negotiate secure connections with HTTPS hosts. We provide a recommendation on where to get and how to install the proper SSL root certificate to communicate with our servers.

But I am a certified PHP developer and I know what I’m doing, right? So I installed the Mozilla root certificate bundle, saved it as cacert.pem in my PHP installation directory, and linked it up in my PHP installation by adding the following to the end of my php.ini file.

curl.cainfo="C:\[path to php dir]\cacert.pem"

I downloaded a copy of Google’s homepage via a cURL call in PHP to test it. Boom. Ready to go.

I ran the PingTest sample again and it failed with multiple warnings like this:

Warning: First parameter must either be an object or the name of an existing class in \Samples\src\AvaTax\EstimateTaxResult.php on line 41

Step 2: Make sure you install our recommended root certificate

A little debugging showed that despite having the root certificate bundle, I didn’t have the root certificate Avalara recommends. D’oh! I was getting that error because the HTTPS negotiation failed and there was no JSON response being returned.

So I went back to our instructions, added the recommended certificate to the bundle (cut and pasted the text into the end of the cacert.pem file), and tried again.

PingTest Result: Error The user or account could not be authenticated.


Step 3: Put your data in configuration.php

The configuration.php file is in the Samples directory like the PingTest sample. You should have received an email with your account number and license key. If you didn’t or lost it, you can get a new key from the settings tab of your Developer Console.

Once you’ve put that information into configuration.php and run the PingTest, you should get the following message:

PingTest Result: Success

And you’re on your way.

Subscribe via RSS!

Back to posts