Connecting to Taxamo from Ruby

Taxamo provides free, Swagger-codegen generated bindings to the RESTful API.

Source code is available as a github repo:

The project is also used to report Taxamo Ruby API-related issues:

Please also consult the regression tests on example usage of the API.


To install it, just fetch this repository and issue the following command:

$ gem build taxamo.gemspec
$ gem install taxamo-1.1.0.gem

Alternatively, add the following line to your project’s Gemfile file:

gem "taxamo", github: "taxamo/taxamo-ruby"


First of all, a merchant needs to set their private test or live token:

require 'taxamo'

Swagger.configure do |config|
  config.api_key = 'YOUR_TOKEN_HERE'

Next, merchants can invoke the API as functions in Taxamo module:

resp = Taxamo.get_transaction('SOME_TRANSACTION_ID')

It is possible to use hashes and arrays as input:

resp = Taxamo.calculate_tax(
        {'transaction' => {
            'currency_code' => 'USD',
            'buyer_ip' => '',
            'billing_country_code' => 'IE',
            'buyer_credit_card_prefix' => '516622',
            'transaction_lines' => [{'amount' => 200,
                                     'custom_id' => 'line1'},
                                    {'amount' => 100,
                                     'product_type' => 'e-book',
                                     'custom_id' => 'line2'}]}})

But also regular classes:

taxIn =
taxIn.transaction =
taxIn.transaction.currency_code = 'USD'
taxIn.transaction.buyer_ip = ''
taxIn.transaction.billing_country_code = 'IE'
taxIn.transaction.force_country_code = 'FR'
taxIn.transaction.transaction_lines = [,]
taxIn.transaction.transaction_lines[0].amount = 200
taxIn.transaction.transaction_lines[0].custom_id = 'line1'
taxIn.transaction.transaction_lines[1].amount = 100
taxIn.transaction.transaction_lines[1].custom_id = 'line2'
taxIn.transaction.transaction_lines[1].product_type = 'e-book'

resp = Taxamo.calculate_tax(taxIn)

The output is always coerced to appropriate classes:

assert_equal resp.transaction.countries.detected.code, 'IE'
assert_equal resp.transaction.amount, 300
assert_equal resp.transaction.tax_amount, 45.5
assert_equal resp.transaction.total_amount, 345.5

See the regression tests for more examples.