Module: Apilayer::Vat

Extended by:
ConnectionHelper
Defined in:
lib/apilayer/vat.rb

Constant Summary collapse

CRITERIA_MISSING_MSG =
'You must provide either :country_code or :ip_address'.freeze

Class Method Summary collapse

Class Method Details

.price(price, criteria, value) ⇒ Object

Api-Method: Calls the /price endpoint to get price including and excluding VAT for a given price and country. It also returns the VAT rate for that country Example:

Apilayer::Vat.price(100, :country, "NL")
Apilayer::Vat.price(100, :ip_address, "176.249.153.36")


56
57
58
59
60
# File 'lib/apilayer/vat.rb', line 56

def self.price(price, criteria, value)
  validate_country_criteria(criteria)
  params = { amount: price, criteria.to_sym => value }
  get_and_parse('price', params)
end

.rate(criteria, value) ⇒ Object

Api-Method: Calls the /rate endpoint to get the VAT-rate of a given country, based on country-code or ip-address. Example:

Apilayer::Vat.rate(:country_code, "NL")
Apilayer::Vat.rate(:ip_address, "176.249.153.36")


35
36
37
38
39
# File 'lib/apilayer/vat.rb', line 35

def self.rate(criteria, value)
  validate_country_criteria(criteria)
  params = { criteria.to_sym => value }
  get_and_parse('rate', params)
end

.rate_listObject

Api-Method: Calls the /rate_list endpoint to get the standard and reduced VAT-rates for all EU countries. Example:

Apilayer::Vat.rate_list


46
47
48
# File 'lib/apilayer/vat.rb', line 46

def self.rate_list
  get_and_parse('rate_list')
end

.validate(vat_number) ⇒ Object

Api-Method: Calls the /validate endpoint to validate a given VAT-number. Example:

Apilayer::Vat.validate("LU26375245")


24
25
26
27
# File 'lib/apilayer/vat.rb', line 24

def self.validate(vat_number)
  params = { vat_number: vat_number }
  get_and_parse('validate', params)
end

.validate_country_criteria(criteria) ⇒ Object

Validates whether a supported criteria has been provided to .rate and .price



11
12
13
14
15
# File 'lib/apilayer/vat.rb', line 11

def self.validate_country_criteria(criteria)
  unless [:country_code, :ip_address].include? criteria
    fail Apilayer::Error.new CRITERIA_MISSING_MSG
  end
end