WebService::TaxJar - A simple client to TaxJar's REST API.
version 0.0002
use WebService::TaxJar; my $tj = WebService::TaxJar->new(api_key => 'XXXXXXXXXXxxxxxxxxxxxx', version => 'v2'); my $categories = $tj->get('categories');
A light-weight wrapper for TaxJar's RESTful API (an example of which can be found at: https://https://developers.taxjar.com/api/reference/). This wrapper basically hides the request cycle from you so that you can get down to the business of using the API. It doesn't attempt to manage the data structures or objects the web service interfaces with.
The module takes care of all of these things for you:
Based on the value of the sandbox flag, the module will either send requests to the production environment sandbox => 0 or the sandbox environment sandbox => 1.
sandbox
sandbox => 0
sandbox => 1
WebService::TaxJar adds an authentication header of the type "Authorization: Bearer $tj->api_key" to each request.
WebService::TaxJar
$tj->api_key
WebService::TaxJar prepends the $tj->version to each URL you submit.
$tj->version
When making a request like:
$tj->post('customers', { customer_id => '27', exemption_type => 'non_exempt', name => 'Andy Dufresne', });
The data in POST request will be translated to JSON using <JSON::to_json>.
All exceptions in WebService::TaxJar are handled by Ouch. A 500 exception "Server returned unparsable content." is returned if TaxJar's server returns something that isn't JSON. If the request isn't successful, then an exception with the code and response and string will be thrown.
Ouch
"Server returned unparsable content."
The following methods are available.
Constructor.
A hash of parameters.
Your key for accessing TaxJar's API. Required.
The version of the API that you are using, like 'v1', 'v2', etc. Optional, defaults to 'v2'.
Tax Jar decided to move away from a numbered scheme where the version is in the URL to a date based version in the HTTP headers. This flag is optional, and defaults to '2022-01-24', which is the default date as of May 2022. The date must be in the version of 'YYYY-MM-DD' to be accepted by TaxJar, but this module will not validate your date flag.
A boolean that, if true, will send all requests to TaxJar's sandbox environment for testing instead of to production. Defaults to 0.
Just a spare, writable flag so that users of the object should log debug information, since TaxJar will likely ask for request/response pairs when you're having problems.
my $sales_tax = $taxjar->get('taxes', $order_information); if ($taxjar->debug_flag) { $log->info($taxjar->last_response->request->as_string); $log->info($taxjar->last_response->content); }
A LWP::UserAgent compliant object used to keep a persistent cookie_jar across requests. By default this module uses HTTP::Thin, but you can supply another object when creating a WebService::TaxJar object.
The HTTP::Response object from the last request/reponse pair that was sent, for debugging purposes.
Performs a GET request, which is used for reading data from the service.
GET
The path to the REST interface you wish to call.
A hash reference of parameters you wish to pass to the web service. These parameters will be added as query parameters to the URL for you.
Performs a DELETE request, deleting data from the service.
DELETE
Performs a PUT request, which is used for updating data in the service.
PUT
A hash reference of parameters you wish to pass to Tax Jar. This will be translated to JSON.
Performs a POST request, which is used for creating data in the service.
POST
A hash reference of parameters you wish to pass to Tax Jar. They will be encoded as JSON.
The path you provide as arguments to the request methods get, post, put delete should not have a leading slash.
get, post, put delete
As of early 2019:
The current version of their API is 'v2'. There is no default value for the version parameter, so please provide this when creating a WebService::TaxJar object.
version
TaxJar does not provide a free sandbox for prototyping your code, it is part of their premium service level.
TaxJar's sandbox mode does not implement all API endpoints.
HTTP::Thin Ouch HTTP::Request::Common HTTP::CookieJar JSON URI Moo
https://github.com/perldreamer/WebService-TaxJar
https://github.com/perldreamer/WebService-TaxJar/issues
Colin Kuskie <colink_at_plainblack_dot_com>
This module is Copyright 2019 Plain Black Corporation. It is distributed under the same terms as Perl itself.
To install WebService::TaxJar, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WebService::TaxJar
CPAN shell
perl -MCPAN -e shell install WebService::TaxJar
For more information on module installation, please visit the detailed CPAN module installation guide.