rhyswynne / easy-digital-downloads-taxamo-integration

Integrate Taxamo into Easy Digital Downloads. Make yourself Compatible with the VATMOSS EU Legislation
2 stars 6 forks source link

Cache API calls to improve checkout page load speed #22

Closed NateWr closed 9 years ago

NateWr commented 9 years ago

This PR stores the results of the API calls in /includes/functions.php to prevent multiple calls in a single page load with the same data. It's not a persistent cache, just storing it into EDD_Taxamo_EDD_Integration::api_responses for retrieval.

The geoip lookup was the one that was really causing the delays. I went ahead and cached the vat details lookup as well, but I wasn't able to test that (I don't collect VAT details and Taxamo's API insists my VAT number is invalid -- though it validated the number in my account???).

Anyway, I recommend you test it before approving the PR.

NateWr commented 9 years ago

This address #1.

NateWr commented 9 years ago

4b9c40a caches the calls that are made to calculate the tax. In order to store the results within the class, I had to make a few methods non-static. I'm not always that clear on the use-case for static methods, so please take a look and make sure there's no potential fallout.

NateWr commented 9 years ago

I have found two more API calls. One that sends the transaction and one that creates a refund.

I haven't tested a refund, but the actual transaction seemed pretty snappy to me, so I don't think we have any issues with repeated calls to the api there. That would probably throw up red flags with multiple transactions appearing in Taxamo anyway.

I think this takes care of it, but would love some more testers! I'm going live with it on my production site now.

rhyswynne commented 9 years ago

Hi Nate,

Thanks for this :) - it does appear quicker.

I've tested a few times, and spotted a few issues though, which I'm not sure how they work but could be an issue going forward.

I'm assuming you're based in the UK, so this is from a UK IP.

If you are based in the UK, and put your billing address in the US, and confirm it, you will still get the UK cached tax rate. I guess we need to put a "If the submitted country code matches the cached country code, then use it, otherwise recollect it".

I'll see if I can take a look at it.