A Ruby interface to the TaxJar Sales Tax API. TaxJar makes sales tax filing easier for online sellers and merchants. See local jurisdictional tax reports, get payment reminders, and more. You can use our API to access TaxJar API endpoints, which can get information on sales tax rates, categories or upload transactions.
- This wrapper supports 100% of the TaxJar API
- Data returned from API calls are mapped to Ruby objects
Supported Ruby Versions
Gem Dependencies
Installation
Authentication
Usage
Custom Options
Sandbox Environment
Error Handling
Tests
More Information
License
Support
Contributing
Ruby 2.3 or greater
Installing this gem also bundles the following dependencies:
- http - Fast Ruby HTTP client with a chainable API and full streaming support.
- addressable - Replacement for the URI implementation that is part of Ruby's standard library. It more closely conforms to the relevant RFCs and adds support for IRIs and URI templates.
- memoizable - Memoize method return values.
- model_attribute - Type casted attributes for non-ActiveRecord models.
Add this line to your application's Gemfile:
gem 'taxjar-ruby', require: 'taxjar'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install taxjar-ruby
Generate an API token from TaxJar. Copy and paste your API token when instantiating a new client:
require 'taxjar'
client = Taxjar::Client.new(api_key: 'YOUR_API_TOKEN')
You're now ready to use TaxJar! Check out our quickstart guide to get up and running quickly.
categories
- List all tax categories
tax_for_order
- Calculate sales tax for an order
list_orders
- List order transactions
show_order
- Show order transaction
create_order
- Create order transaction
update_order
- Update order transaction
delete_order
- Delete order transaction
list_refunds
- List refund transactions
show_refund
- Show refund transaction
create_refund
- Create refund transaction
update_refund
- Update refund transaction
delete_refund
- Delete refund transaction
list_customers
- List customers
show_customer
- Show customer
create_customer
- Create customer
update_customer
- Update customer
delete_customer
- Delete customer
rates_for_location
- List tax rates for a location (by zip/postal code)
nexus_regions
- List nexus regions
validate_address
- Validate an address
validate
- Validate a VAT number
summary_rates
- Summarize tax rates for all regions
List all tax categories (API docs)
The TaxJar API provides product-level tax rules for a subset of product categories. These categories are to be used for products that are either exempt from sales tax in some jurisdictions or are taxed at reduced rates. You need not pass in a product tax code for sales tax calculations on product that is fully taxable. Simply leave that parameter out.
client.categories
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.categories
[
#<Taxjar::Category:0x00000a @attrs={
:name => 'Digital Goods',
:product_tax_code => 31000,
:description => 'Digital products transferred electronically.'
}>,
#<Taxjar::Category:0x00000a @attrs={
:name => 'Clothing',
:product_tax_code => 20010,
:description => 'All human wearing apparel suitable for general use'
}>,
#<Taxjar::Category:0x00000a @attrs={
:name => 'Non-Prescription',
:product_tax_code => 51010,
:description => 'Drugs for human use without a prescription'
}>
]
Calculate sales tax for an order (API docs)
Shows the sales tax that should be collected for a given order.
client.tax_for_order
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.tax_for_order({
:from_country => 'US',
:from_zip => '94025',
:from_state => 'CA',
:from_city => 'Menlo Park',
:from_street => '2825 Sand Hill Rd',
:to_country => 'US',
:to_zip => '94303',
:to_state => 'CA',
:to_city => 'Palo Alto',
:to_street => '5230 Newell Road',
:amount => 267.9,
:shipping => 0,
:nexus_addresses => [{:country => 'US',
:state => 'CA'}],
:line_items => [{:id => '1',
:quantity => 1,
:product_tax_code => '19005',
:unit_price => 535.8,
:discount => 267.9}]
})
#<Taxjar::Tax:0x00000a @attrs={
:taxable_amount => 0,
:tax_source => 'destination',
:shipping => 0,
:rate => 0,
:order_total_amount => 267.9
:jurisdictions => #<Taxjar::Jurisdictions:0x00000a @attrs={
:state => 'CA',
:county => 'SAN MATEO',
:country => 'US',
:city => 'EAST PALO ALTO'
}>,
:has_nexus => true,
:freight_taxable => false,
:breakdown => #<Taxjar::Breakdown:0x00000a @attrs={
:taxable_amount => 0,
:tax_collectable => 0,
:state_taxable_amount => 0,
:state_tax_rate => 0,
:state_tax_collectable => 0,
:special_tax_rate => 0,
:special_district_taxable_amount => 0,
:special_district_tax_collectable => 0,
:line_items => [
#<Taxjar::BreakdownLineItem:0x00000a @attrs={
:taxable_amount => 0,
:tax_collectable => 0,
:state_taxable_amount => 0,
:state_sales_tax_rate => 0,
:state_amount => 0,
:special_tax_rate => 0,
:special_district_taxable_amount => 0,
:special_district_amount => 0,
:id => '1',
:county_taxable_amount => 0,
:county_tax_rate => 0,
:county_amount => 0,
:combined_tax_rate => 0,
:city_taxable_amount => 0,
:city_tax_rate => 0,
:city_amount => 0,
}>
],
:county_taxable_amount => 0,
:county_tax_rate => 0,
:county_tax_collectable => 0,
:combined_tax_rate => 0,
:city_taxable_amount => 0,
:city_tax_rate => 0,
:city_tax_collectable => 0
}>
:amount_to_collect => 0
}>
List order transactions (API docs)
Lists existing order transactions created through the API.
client.list_orders
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.list_orders({:from_transaction_date => '2015/05/01',
:to_transaction_date => '2015/05/31'})
['20', '21', '22']
Show order transaction (API docs)
Shows an existing order transaction created through the API.
client.show_order
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.show_order('123')
#<Taxjar::Order:0x00000a @attrs={
:transaction_id => '123',
:user_id => 11836,
:transaction_date => '2015-05-14T00:00:00Z',
:transaction_reference_id => nil,
:from_country => 'US',
:from_zip => '93107',
:from_state => 'CA',
:from_city => 'SANTA BARBARA',
:from_street => '1281 State St',
:to_country => 'US',
:to_zip => '90002',
:to_state => 'CA',
:to_city => 'LOS ANGELES',
:to_street => '123 Palm Grove Ln',
:amount => 17,
:shipping => 2,
:sales_tax => 0.95,
:line_items => [
{
:id => '1',
:quantity => 1,
:product_identifier => '12-34243-0',
:product_tax_code => nil,
:description => 'Heavy Widget',
:unit_price => 15,
:discount => 0,
:sales_tax => 0.95
}
]
}>
Create order transaction (API docs)
Creates a new order transaction.
client.create_order
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
order = client.create_order({
:transaction_id => '123',
:transaction_date => '2015/05/15',
:from_country => 'US',
:from_zip => '94025',
:from_state => 'CA',
:from_city => 'Menlo Park',
:from_street => '2825 Sand Hill Rd',
:to_country => 'US',
:to_zip => '94303',
:to_state => 'CA',
:to_city => 'Palo Alto',
:to_street => '5230 Newell Road',
:amount => 267.9,
:shipping => 0,
:sales_tax => 0,
:line_items => [{:id => '1',
:quantity => 1,
:description => 'Legal Services',
:product_tax_code => '19005',
:unit_price => 535.8,
:discount => 267.9,
:sales_tax => 0}]
})
#<Taxjar::Order:0x00000a @attrs={
:transaction_id => '123',
:user_id => 11836,
:provider => 'api',
:transaction_date => '2015-05-15T00:00:00Z',
:transaction_reference_id => nil,
:customer_id => nil,
:exemption_type => nil,
:from_country => 'US',
:from_zip => '94025',
:from_state => 'CA',
:from_city => 'MENLO PARK',
:from_street => '2825 Sand Hill Rd',
:to_country => 'US',
:to_zip => '94303',
:to_state => 'CA',
:to_city => 'PALO ALTO',
:to_street => '5230 Newell Rd',
:amount => 267.9,
:shipping => 0,
:sales_tax => 0,
:line_items => [
{
:id => '1',
:quantity => 1,
:product_identifier => nil,
:product_tax_code => '19005',
:description => 'Legal Services',
:unit_price => 535.8,
:discount => 267.9,
:sales_tax => 0
}
]
}>
Update order transaction (API docs)
Updates an existing order transaction created through the API.
client.update_order
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
order = client.update_order({
:transaction_id => '123',
:amount => 283.6,
:shipping => 5,
:sales_tax => 1.04,
:line_items => [
{
:id => '1',
:quantity => 1,
:description => 'Legal Services',
:product_tax_code => '19005',
:unit_price => 535.8,
:discount => 267.9,
:sales_tax => 0
},
{
:id => '2',
:quantity => 2,
:description => 'Hoberman Switch Pitch',
:unit_price => 10.7,
:discount => 10.7,
:sales_tax => 1.04
}
]
})
#<Taxjar::Order:0x00000a @attrs={
:transaction_id => '123',
:user_id => 11836,
:provider => 'api',
:transaction_date => '2015-05-15T00:00:00Z',
:transaction_reference_id => nil,
:customer_id => nil,
:exemption_type => nil,
:from_country => 'US',
:from_zip => '94025',
:from_state => 'CA',
:from_city => 'MENLO PARK',
:from_street => '2825 Sand Hill Rd',
:to_country => 'US',
:to_zip => '94303',
:to_state => 'CA',
:to_city => 'PALO ALTO',
:to_street => '5230 Newell Road',
:amount => 283.6,
:shipping => 5,
:sales_tax => 1.04,
:line_items => [
{
:id => '1',
:quantity => 1,
:product_identifier => nil,
:product_tax_code => '19005',
:description => 'Legal Services',
:unit_price => 535.8,
:discount => 267.9,
:sales_tax => 0
},
{
:id => '2',
:quantity => 2,
:product_identifier => nil,
:product_tax_code => nil,
:description => 'Hoberman Switch Pitch',
:unit_price => 10.7,
:discount => 10.7,
:sales_tax => 1.04
}
]
}>
Delete order transaction (API docs)
Deletes an existing order transaction created through the API.
client.delete_order
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.delete_order('123')
#<Taxjar::Order:0x00000a @attrs={
:transaction_id => '123',
:user_id => 11836,
:provider => 'api',
:transaction_date => nil,
:transaction_reference_id => nil,
:customer_id => nil,
:exemption_type => nil,
:from_country => nil,
:from_zip => nil,
:from_state => nil,
:from_city => nil,
:from_street => nil,
:to_country => nil,
:to_zip => nil,
:to_state => nil,
:to_city => nil,
:to_street => nil,
:amount => nil,
:shipping => nil,
:sales_tax => nil,
:line_items => []
}>
List refund transactions (API docs)
Lists existing refund transactions created through the API.
client.list_refunds
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.list_refunds({:from_transaction_date => '2015/05/01',
:to_transaction_date => '2015/05/31'})
['20-refund', '21-refund', '22-refund']
Show refund transaction (API docs)
Shows an existing refund transaction created through the API.
client.show_refund
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.show_refund('20-refund')
#<Taxjar::Refund:0x00000a @attrs={
:transaction_id => '20-refund',
:user_id => 11836,
:provider => 'api',
:transaction_date => '2015-05-15T00:00:00Z',
:transaction_reference_id => '20',
:customer_id => nil,
:exemption_type => nil,
:from_country => 'US',
:from_zip => '93107',
:from_state => 'CA',
:from_city => 'SANTA BARBARA',
:from_street => '1218 State St',
:to_country => 'US',
:to_zip => '90002',
:to_state => 'CA',
:to_city => 'LOS ANGELES',
:to_street => '123 Palm Grove Ln',
:amount => -17,
:shipping => -2,
:sales_tax => -0.95,
:line_items => [
{
:id => '1',
:quantity => 1,
:product_identifier => '12-34243-0',
:product_tax_code => nil,
:description => 'Heavy Widget',
:unit_price => -15,
:discount => 0,
:sales_tax => -0.95
}
]
}>
Create refund transaction (API docs)
Creates a new refund transaction.
client.create_refund
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
refund = client.create_refund({
:transaction_id => '123-refund',
:transaction_reference_id => '123',
:transaction_date => '2015/05/15',
:from_country => 'US',
:from_zip => '94025',
:from_state => 'CA',
:from_city => 'Menlo Park',
:from_street => '2825 Sand Hill Rd',
:to_country => 'US',
:to_zip => '94303',
:to_state => 'CA',
:to_city => 'Palo Alto',
:to_street => '5230 Newell Road',
:amount => -5.35,
:shipping => -0,
:sales_tax => -0.52,
:line_items => [
{
:id => '1',
:quantity => 1,
:description => 'Legal Services',
:product_tax_code => '19005',
:unit_price => -0,
:discount => -0,
:sales_tax => -0
},
{
:id => '2',
:quantity => 1,
:description => 'Hoberman Switch Pitch',
:unit_price => -0,
:discount => -5.35,
:sales_tax => -0.52
}
]
})
#<Taxjar::Refund:0x00000a @attrs={
:transaction_id => '123-refund',
:user_id => 11836,
:provider => 'api',
:transaction_date => '2015-05-15T00:00:00Z',
:transaction_reference_id => '123',
:customer_id => nil,
:exemption_type => nil,
:from_country => 'US',
:from_zip => '94025',
:from_state => 'CA',
:from_city => 'MENLO PARK',
:from_street => '2825 Sand Hill Rd',
:to_country => 'US',
:to_zip => '94303',
:to_state => 'CA',
:to_city => 'PALO ALTO',
:to_street => '5230 Newell Road',
:amount => -5.35,
:shipping => -0,
:sales_tax => -0.52,
:line_items => [
{
:id => '1',
:quantity => 1,
:product_identifier => nil,
:product_tax_code => '19005',
:description => 'Legal Services',
:unit_price => 0,
:discount => 0,
:sales_tax => 0
},
{
:id => '2',
:quantity => 1,
:product_identifier => nil,
:product_tax_code => nil,
:description => 'Hoberman Switch Pitch',
:unit_price => 0,
:discount => -5.35,
:sales_tax => -0.52
}
]
}>
Update refund transaction (API docs)
Updates an existing refund transaction created through the API.
client.update_refund
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
refund = client.update_refund({
:transaction_id => '123-refund',
:transaction_reference_id => '123',
:amount => -10.35,
:shipping => -5
})
#<Taxjar::Refund:0x00000a @attrs={
:transaction_id => '123-refund',
:user_id => 11836,
:provider => 'api',
:transaction_date => '2015-05-15T00:00:00Z',
:transaction_reference_id => '123',
:customer_id => nil,
:exemption_type => nil,
:from_country => 'US',
:from_zip => '94025',
:from_state => 'CA',
:from_city => 'MENLO PARK',
:from_street => '2825 Sand Hill Rd',
:to_country => 'US',
:to_zip => '94303',
:to_state => 'CA',
:to_city => 'PALO ALTO',
:to_street => '5230 Newell Road',
:amount => -10.35,
:shipping => -5,
:sales_tax => 0,
:line_items => [
{
:id => '1',
:quantity => 1,
:product_identifier => nil,
:product_tax_code => '19005',
:description => 'Legal Services',
:unit_price => 0,
:discount => 0,
:sales_tax => 0
},
{
:id => '2',
:quantity => 1,
:product_identifier => nil,
:product_tax_code => nil,
:description => 'Hoberman Switch Pitch',
:unit_price => 0,
:discount => -5.35,
:sales_tax => -0.52
}
]
}>
Delete refund transaction (API docs)
Deletes an existing refund transaction created through the API.
client.delete_refund
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.delete_refund('123-refund')
#<Taxjar::Refund:0x00000a @attrs={
:transaction_id => '123-refund',
:user_id => 11836,
:provider => 'api',
:transaction_date => nil,
:transaction_reference_id => nil,
:customer_id => nil,
:exemption_type => nil,
:from_country => nil,
:from_zip => nil,
:from_state => nil,
:from_city => nil,
:from_street => nil,
:to_country => nil,
:to_zip => nil,
:to_state => nil,
:to_city => nil,
:to_street => nil,
:amount => nil,
:shipping => nil,
:sales_tax => nil,
:line_items => []
}>
List customers (API docs)
Lists existing customers created through the API.
client.list_customers
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.list_customers
['123', '124', '125']
Show customer (API docs)
Shows an existing customer created through the API.
client.show_customer
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.show_customer('123')
#<Taxjar::Customer @attrs={
:customer_id => "123",
:exemption_type => "wholesale",
:exempt_regions => [
[0] {
:country => "US",
:state => "FL"
},
[1] {
:country => "US",
:state => "PA"
}
],
:name => "Dunder Mifflin Paper Company",
:country => "US",
:state => "PA",
:zip => "18504",
:city => "Scranton",
:street => "1725 Slough Avenue"
}>
Create customer (API docs)
Creates a new customer.
client.create_customer
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
customer = client.create_customer({
:customer_id => '123',
:exemption_type => 'wholesale',
:name => 'Dunder Mifflin Paper Company',
:exempt_regions => [
{
:country => 'US',
:state => 'FL'
},
{
:country => 'US',
:state => 'PA'
}
],
:country => 'US',
:state => 'PA',
:zip => '18504',
:city => 'Scranton',
:street => '1725 Slough Avenue'
})
#<Taxjar::Customer @attrs={
:customer_id => "123",
:exemption_type => "wholesale",
:exempt_regions => [
[0] {
:country => "US",
:state => "FL"
},
[1] {
:country => "US",
:state => "PA"
}
],
:name => "Dunder Mifflin Paper Company",
:country => "US",
:state => "PA",
:zip => "18504",
:city => "Scranton",
:street => "1725 Slough Avenue"
}>
Update customer (API docs)
Updates an existing customer created through the API.
client.update_customer
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
customer = client.update_customer({
:customer_id => '123',
:exemption_type => 'wholesale',
:name => 'Sterling Cooper',
:exempt_regions => [
{
:country => 'US',
:state => 'NY'
}
],
:country => 'US',
:state => 'NY',
:zip => '10010',
:city => 'New York',
:street => '405 Madison Ave'
})
#<Taxjar::Customer @attrs={
:customer_id => "123",
:exemption_type => "wholesale",
:exempt_regions => [
[0] {
:country => "US",
:state => "NY"
}
],
:name => "Sterling Cooper",
:country => "US",
:state => "NY",
:zip => "10010",
:city => "New York",
:street => "405 Madison Ave"
}>
Delete customer (API docs)
Deletes an existing customer created through the API.
client.delete_customer
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
client.delete_customer('123')
#<Taxjar::Customer @attrs={
:customer_id => "123",
:exemption_type => "wholesale",
:exempt_regions => [],
:name => "Dunder Mifflin Paper Company",
:country => "US",
:state => "PA",
:zip => "18504",
:city => "Scranton",
:street => "1725 Slough Avenue"
}>
List tax rates for a location (by zip/postal code) (API docs)
Shows the sales tax rates for a given location.
Please note this method only returns the full combined rate for a given location. It does not support nexus determination, sourcing based on a ship from and ship to address, shipping taxability, product exemptions, customer exemptions, or sales tax holidays. We recommend using
tax_for_order
to accurately calculate sales tax for an order.
client.rates_for_location
require 'taxjar'
client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78')
# United States (ZIP+4)
rates = client.rates_for_location('90404-3370')
# United States (ZIP w/ Optional Params)
rates = client.rates_for_location('90404', {
:city => 'SANTA MONICA',
:country => 'US'
})
# International Examples (Requires City and Country)
rates = client.rates_for_location('V5K0A1', {
:city => 'VANCOUVER',
:country => 'CA'
})
rates = client.rates_for_location('00150', {
:city => 'HELSINKI',
:country => 'FI'
})
#<Taxjar::Rate:0x00000a @attrs={
:zip => '90002',
:state => 'CA',
:state_rate => 0.065,
:county => 'LOS ANGELES',
:county_rate => 0.01,
:city => 'WATTS',
:city_rate => 0,
:combined_district_rate => 0.015,
:combined_rate => 0.09,
:freight_taxable => false
}>
#<Taxjar::Rate:0x00000a @attrs={
:zip => 'V5K0A1',
:city => 'Vancouver',
:state => 'BC',
:country => 'CA',
:combined_rate => 0.12,
:freight_taxable => true
}>
#<Taxjar::Rate:0x00000a @attrs={
:country => 'FI',
:name => 'Finland',
:standard_rate => 0.24,
:reduced_rate => nil,
:super_reduced_rate => nil,
:parking_rate => nil,
:distance_sale_threshold => nil,
:freight_taxable => true
}>
List nexus regions (API docs)
Lists existing nexus locations for a TaxJar account.
client.nexus_regions
require 'taxjar'
client = Taxjar::Client.new(api_key: '9e0cd62a22f451701f29c3bde214')
nexus_regions = client.nexus_regions
[
#<Taxjar::NexusRegion:0x00000a @attrs={
:country_code => 'US',
:country => 'United States',
:region_code => 'CA',
:region => 'California'
}>,
#<Taxjar::NexusRegion:0x00000a @attrs={
:country_code => 'US',
:country => 'United States',
:region_code => 'NY',
:region => 'New York'
}>,
#<Taxjar::NexusRegion:0x00000a @attrs={
:country_code => 'US',
:country => 'United States',
:region_code => 'WA',
:region => 'Washington'
}>
]
Validate an address (API docs)
Validates a customer address and returns back a collection of address matches. Address validation requires a TaxJar Professional subscription.
client.validate_address
require 'taxjar'
client = Taxjar::Client.new(api_key: '9e0cd62a22f451701f29c3bde214')
addresses = client.validate_address({
:country => 'US',
:state => 'AZ',
:zip => '85297',
:city => 'Gilbert',
:street => '3301 Greenfield Rd'
})
[
#<Taxjar::Address:0x00000a @attrs={
:zip => '85297-2176',
:street => '3301 S Greenfield Rd',
:state => 'AZ',
:country => 'US',
:city => 'Gilbert'
}>
]
Validate a VAT number (API docs)
Validates an existing VAT identification number against VIES.
client.validate
require 'taxjar'
client = Taxjar::Client.new(api_key: '9e0cd62a22f451701f29c3bde214')
validation = client.validate({
:vat => 'FR40303265045'
})
#<Taxjar::Validation:0x00000a @attrs={
:valid => true,
:exists => true,
:vies_available => true,
:vies_response => {
:country_code => 'FR',
:vat_number => '40303265045',
:request_date => '2016-02-10',
:valid => true,
:name => 'SA SODIMAS',
:address => "11 RUE AMPERE\n26600 PONT DE L ISERE"
}
}>
Summarize tax rates for all regions (API docs)
Retrieve minimum and average sales tax rates by region as a backup.
This method is useful for periodically pulling down rates to use if the TaxJar API is unavailable. However, it does not support nexus determination, sourcing based on a ship from and ship to address, shipping taxability, product exemptions, customer exemptions, or sales tax holidays. We recommend using
tax_for_order
to accurately calculate sales tax for an order.
client.summary_rates
require 'taxjar'
client = Taxjar::Client.new(api_key: '9e0cd62a22f451701f29c3bde214')
summarized_rates = client.summary_rates
[
#<Taxjar::SummaryRate:0x00000a @attrs={
:country_code => 'US',
:country => 'United States',
:region_code => 'CA',
:region => 'California',
:minimum_rate => {
:label => 'State Tax',
:rate => 0.065
},
:average_rate => {
:label => 'Tax',
:rate => 0.0827
}
}>,
#<Taxjar::SummaryRate:0x00000a @attrs={
:country_code => 'CA',
:country => 'Canada',
:region_code => 'BC',
:region => 'British Columbia',
:minimum_rate => {
:label => 'GST',
:rate => 0.05
},
:average_rate => {
:label => 'PST',
:rate => 0.12
}
}>,
#<Taxjar::SummaryRate:0x00000a @attrs={
:country_code => 'UK',
:country => 'United Kingdom',
:region_code => nil,
:region => nil,
:minimum_rate => {
:label => 'VAT',
:rate => 0.2
},
:average_rate => {
:label => 'VAT',
:rate => 0.2
}
}>
]
Pass a hash to any API method above for the following options:
Set request timeout in seconds:
client.tax_for_order({ timeout: 30 })
You can easily configure the client to use the TaxJar Sandbox:
require 'taxjar'
client = Taxjar::Client.new(api_key: 'YOUR_SANDBOX_API_TOKEN', api_url: 'https://api.sandbox.taxjar.com')
For testing specific error response codes, pass the custom X-TJ-Expected-Response
header:
client.set_api_config('headers', {
'X-TJ-Expected-Response' => 422
})
When invalid data is sent to TaxJar or we encounter an error, we’ll throw a Taxjar::Error
with the HTTP status code and error message. To catch these exceptions, refer to the example below. Click here for a list of common error response classes.
require 'taxjar'
client = Taxjar::Client.new(api_key: '9e0cd62a22f451701f29c3bde214')
begin
order = client.create_order({
:transaction_date => '2015/05/14',
:to_country => 'US',
:to_state => 'CA',
:to_zip => '90002',
:amount => 17.45,
:shipping => 1.5,
:sales_tax => 0.95
})
rescue Taxjar::Error => e
# <Taxjar::Error::NotAcceptable: transaction_id is missing>
puts e.class.name
puts e.message
end
An RSpec test suite is available to ensure API functionality:
$ git clone git://github.com/taxjar/taxjar-ruby.git
$ bundle install
$ rspec
More information can be found on TaxJar Developers.
TaxJar is released under the MIT License.
Bug reports and feature requests should be filed on the GitHub issue tracking page.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new pull request