Class: Vatsense::Resources::Currency

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

Overview

Currency exchange rates and conversion

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Currency

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 Currency.

Parameters:



106
107
108
# File 'lib/vatsense/resources/currency.rb', line 106

def initialize(client:)
  @client = client
end

Instance Method Details

#calculate_vat_price(price:, tax_type:, vat_rate:, request_options: {}) ⇒ Vatsense::Models::CurrencyCalculateVatPriceResponse

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

Calculate the inclusive and exclusive VAT price on a given amount and VAT rate. This is a standalone calculation that does not look up rates by country.

Parameters:

Returns:

See Also:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vatsense/resources/currency.rb', line 57

def calculate_vat_price(params)
  parsed, options = Vatsense::CurrencyCalculateVatPriceParams.dump_request(params)
  query = Vatsense::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "currency/price",
    query: query,
    model: Vatsense::Models::CurrencyCalculateVatPriceResponse,
    options: options
  )
end

#convert(amount:, from:, to:, request_options: {}) ⇒ Vatsense::Models::CurrencyConvertResponse

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

Convert a foreign currency amount to either GBP or EUR using official exchange rates.

GBP rates are from HMRC (updated on the 1st of every month). EUR rates are from the European Central Bank (updated around 16:00 CET on working days).

Parameters:

  • amount (String)

    The amount to convert. Must be a string with exactly 2 decimal places (e.g. “39.

  • from (String)

    The 3-character source currency code (e.g. “USD”, “CAD”).

  • to (Symbol, Vatsense::Models::CurrencyConvertParams::To)

    The 3-character target currency code. Must be either “GBP” or “EUR”.

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

Returns:

See Also:



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/vatsense/resources/currency.rb', line 91

def convert(params)
  parsed, options = Vatsense::CurrencyConvertParams.dump_request(params)
  query = Vatsense::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "currency/convert",
    query: query,
    model: Vatsense::Models::CurrencyConvertResponse,
    options: options
  )
end

#list(from: nil, to: nil, request_options: {}) ⇒ Vatsense::Models::CurrencyListResponse

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

Returns a list of all currency conversion rates sourced from HMRC (GBP) and the European Central Bank (EUR).

You can optionally filter by source and target currency.

Parameters:

Returns:

See Also:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vatsense/resources/currency.rb', line 26

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