Class: Vatsense::Resources::Rates

Inherits:
Object
  • Object
show all
Defined in:
lib/vatsense/resources/rates.rb

Overview

VAT/GST rate lookups for countries worldwide

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Rates

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Rates.

Parameters:



185
186
187
# File 'lib/vatsense/resources/rates.rb', line 185

def initialize(client:)
  @client = client
end

Instance Method Details

#calculate_price(price:, tax_type:, country_code: nil, eu: nil, ip_address: nil, province_code: nil, type: nil, request_options: {}) ⇒ Vatsense::Models::RateCalculatePriceResponse

Some parameter documentations has been truncated, see Models::RateCalculatePriceParams for more details.

Combines the functionality of the “Find a tax rate” and “VAT price calculation” endpoints to return the particular VAT price for an applicable VAT rate. Requires both a location (country_code or ip_address) and a price to calculate.

Parameters:

  • price (String)

    The price to calculate on. Must be a string with exactly 2 decimal places (e.g.

  • tax_type (Symbol, Vatsense::Models::RateCalculatePriceParams::TaxType)

    Whether the provided price is inclusive or exclusive of VAT.

  • country_code (String)

    A 2-character ISO 3166-1 alpha-2 country code (e.g. “GB”, “FR”).

  • eu (Boolean)

    Filter results by EU membership. Use 1 for EU countries only, 0 for non-EU only.

  • ip_address (String)

    An IPv4 or IPv6 address. If provided, the country will be determined from the IP

  • province_code (String)

    A 2-character province code (e.g. “NU”, “NT”). If providing a province

  • type (String)

    The product type to find the applicable rate for. See the /rates/types

  • request_options (Vatsense::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vatsense/resources/rates.rb', line 71

def calculate_price(params)
  parsed, options = Vatsense::RateCalculatePriceParams.dump_request(params)
  query = Vatsense::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "rates/price",
    query: query,
    model: Vatsense::Models::RateCalculatePriceResponse,
    options: options
  )
end

#details(country_code: nil, eu: nil, ip_address: nil, period: nil, province_code: nil, type: nil, request_options: {}) ⇒ Vatsense::Models::FindRate

Some parameter documentations has been truncated, see Models::RateDetailsParams for more details.

Get detailed tax rate information for a location, including all applicable rate classes (standard, reduced, zero, etc.).

Parameters:

  • country_code (String)

    A 2-character ISO 3166-1 alpha-2 country code (e.g. “GB”, “FR”).

  • eu (Boolean)

    Filter results by EU membership. Use 1 for EU countries only, 0 for non-EU only.

  • ip_address (String)

    An IPv4 or IPv6 address. If provided, the country will be determined from the IP

  • period (Time)

    A historical date to retrieve rates for (format “YYYY-MM-DD HH:MM:SS”). Must be

  • province_code (String)

    A 2-character province code (e.g. “NU”, “NT”). If providing a province

  • type (String)

    The product type to find the applicable rate for. See the /rates/types

  • request_options (Vatsense::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/vatsense/resources/rates.rb', line 108

def details(params = {})
  parsed, options = Vatsense::RateDetailsParams.dump_request(params)
  query = Vatsense::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "rates/tax_rate",
    query: query,
    model: Vatsense::FindRate,
    options: options
  )
end

#find(country_code: nil, eu: nil, ip_address: nil, period: nil, province_code: nil, type: nil, request_options: {}) ⇒ Vatsense::Models::FindRate

Some parameter documentations has been truncated, see Models::RateFindParams for more details.

A handy endpoint for finding a rate that applies to a particular country and optional product type, based on country code or IP address.

If no type is provided, or no specific rate is applied to the given type, then the standard rate will be returned if the country is subject to tax.

If the country is not subject to VAT/GST then an error response will be returned, indicating no tax applies.

Parameters:

  • country_code (String)

    A 2-character ISO 3166-1 alpha-2 country code (e.g. “GB”, “FR”).

  • eu (Boolean)

    Filter results by EU membership. Use 1 for EU countries only, 0 for non-EU only.

  • ip_address (String)

    An IPv4 or IPv6 address. If provided, the country will be determined from the IP

  • period (Time)

    A historical date to retrieve rates for (format “YYYY-MM-DD HH:MM:SS”). Must be

  • province_code (String)

    A 2-character province code (e.g. “NU”, “NT”). If providing a province

  • type (String)

    The product type to find the applicable rate for. See the /rates/types

  • request_options (Vatsense::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/vatsense/resources/rates.rb', line 151

def find(params = {})
  parsed, options = Vatsense::RateFindParams.dump_request(params)
  query = Vatsense::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "rates/rate",
    query: query,
    model: Vatsense::FindRate,
    options: options
  )
end

#list(country_code: nil, eu: nil, ip_address: nil, period: nil, request_options: {}) ⇒ Vatsense::Models::RateListResponse

Some parameter documentations has been truncated, see Models::RateListParams for more details.

Returns a list of VAT/GST rates for all countries, sorted alphabetically by country code. Each rate is returned as a rate object containing the standard rate and any other applicable rates.

You can optionally filter by country code, IP address, or EU membership.

Parameters:

  • country_code (String)

    A 2-character ISO 3166-1 alpha-2 country code (e.g. “GB”, “FR”).

  • eu (Boolean)

    Filter results by EU membership. Use 1 for EU countries only, 0 for non-EU only.

  • ip_address (String)

    An IPv4 or IPv6 address. If provided, the country will be determined from the IP

  • period (Time)

    A historical date to retrieve rates for (format “YYYY-MM-DD HH:MM:SS”). Must be

  • request_options (Vatsense::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vatsense/resources/rates.rb', line 31

def list(params = {})
  parsed, options = Vatsense::RateListParams.dump_request(params)
  query = Vatsense::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "rates",
    query: query,
    model: Vatsense::Models::RateListResponse,
    options: options
  )
end

#list_types(request_options: {}) ⇒ Vatsense::Models::RateListTypesResponse

Returns a list of all available product types that can be used to filter tax rates.

Parameters:

Returns:

See Also:



173
174
175
176
177
178
179
180
# File 'lib/vatsense/resources/rates.rb', line 173

def list_types(params = {})
  @client.request(
    method: :get,
    path: "rates/types",
    model: Vatsense::Models::RateListTypesResponse,
    options: params[:request_options]
  )
end