Class: LittleFinger::Avatax
- Inherits:
-
Object
- Object
- LittleFinger::Avatax
- Defined in:
- lib/little_finger/avatax.rb
Instance Attribute Summary collapse
-
#account_number ⇒ Object
Returns the value of attribute account_number.
-
#address_service_url ⇒ Object
Returns the value of attribute address_service_url.
-
#company_code ⇒ Object
Returns the value of attribute company_code.
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#license_key ⇒ Object
Returns the value of attribute license_key.
-
#tax_service_url ⇒ Object
Returns the value of attribute tax_service_url.
Instance Method Summary collapse
-
#cancel(cancel_code, lookup_opts = {}) ⇒ Hash
Voids or deletes and existing transaction record from the AvaTax system.
-
#estimate(coordinates, sale_amount = 0) ⇒ Hash
Retrieves tax rate details for the supplied geographic coordinates and sale amount.
-
#get(payload) ⇒ Object
Calculates taxes on a document such as a sales order, sales invoice, purchase order, purchase invoice, or credit memo.
-
#initialize ⇒ Avatax
constructor
A new instance of Avatax.
-
#status ⇒ Fixnum
Since the REST API does not provide an explicit ping function, the estimate method can also be used to test connectivity to the service.
-
#validate(address) ⇒ Hash
Normalizes a single US or Canadian address, providing a non-ambiguous address match.
Constructor Details
#initialize ⇒ Avatax
Returns a new instance of Avatax.
9 10 11 12 13 14 15 16 17 |
# File 'lib/little_finger/avatax.rb', line 9 def initialize() @company_code = LittleFinger::Configuration.configuration[:avatax][:company_code] @account_number = LittleFinger::Configuration.configuration[:avatax][:account_number] @license_key = LittleFinger::Configuration.configuration[:avatax][:license_key] @api_timeout = LittleFinger::Configuration.configuration[:avatax][:timeout] || 5 @credentials = ["Basic ",Base64.encode64(@account_number + ":"+ @license_key)].join @tax_service_url = [LittleFinger::Configuration.configuration[:avatax][:service_url], LittleFinger::Configuration.configuration[:avatax][:tax_service_path]].join @address_service_url = [LittleFinger::Configuration.configuration[:avatax][:service_url], LittleFinger::Configuration.configuration[:avatax][:address_service_path]].join end |
Instance Attribute Details
#account_number ⇒ Object
Returns the value of attribute account_number.
7 8 9 |
# File 'lib/little_finger/avatax.rb', line 7 def account_number @account_number end |
#address_service_url ⇒ Object
Returns the value of attribute address_service_url.
7 8 9 |
# File 'lib/little_finger/avatax.rb', line 7 def address_service_url @address_service_url end |
#company_code ⇒ Object
Returns the value of attribute company_code.
7 8 9 |
# File 'lib/little_finger/avatax.rb', line 7 def company_code @company_code end |
#credentials ⇒ Object
Returns the value of attribute credentials.
7 8 9 |
# File 'lib/little_finger/avatax.rb', line 7 def credentials @credentials end |
#license_key ⇒ Object
Returns the value of attribute license_key.
7 8 9 |
# File 'lib/little_finger/avatax.rb', line 7 def license_key @license_key end |
#tax_service_url ⇒ Object
Returns the value of attribute tax_service_url.
7 8 9 |
# File 'lib/little_finger/avatax.rb', line 7 def tax_service_url @tax_service_url end |
Instance Method Details
#cancel(cancel_code, lookup_opts = {}) ⇒ Hash
Voids or deletes and existing transaction record from the AvaTax system. developer.avalara.com/api-docs/api-reference/rest-curl/canceltax developer.avalara.com/api-docs/rest/tax/cancel
47 48 49 50 51 52 |
# File 'lib/little_finger/avatax.rb', line 47 def cancel(cancel_code, lookup_opts = {}) payload = lookup_opts.merge({CancelCode: cancel_code}) uri = [@tax_service_url, "cancel"].join response = send_request(:post, uri, payload) JSON.parse(response.body).try(:[],"CancelTaxResult") end |
#estimate(coordinates, sale_amount = 0) ⇒ Hash
Retrieves tax rate details for the supplied geographic coordinates and sale amount. developer.avalara.com/api-docs/api-reference/rest-curl/estimatetax
61 62 63 64 65 66 |
# File 'lib/little_finger/avatax.rb', line 61 def estimate(coordinates, sale_amount = 0) return unless coordinates.present? && coordinates.has_key?(:latitude) && coordinates.has_key?(:longitude) uri = [@tax_service_url,coordinates[:latitude].to_s,",",coordinates[:longitude].to_s,"/get?saleamount=",sale_amount.to_s].join response = send_request(:get, uri) JSON.parse(response.body) end |
#get(payload) ⇒ Object
Calculates taxes on a document such as a sales order, sales invoice, purchase order, purchase invoice, or credit memo. developer.avalara.com/api-docs/api-reference/rest-curl/gettax
31 32 33 34 35 |
# File 'lib/little_finger/avatax.rb', line 31 def get(payload) uri = [@tax_service_url,"get"].join response = send_request(:post, uri, payload) JSON.parse(response.body) end |
#status ⇒ Fixnum
Since the REST API does not provide an explicit ping function, the estimate method can also be used to test connectivity to the service.
21 22 23 24 25 26 |
# File 'lib/little_finger/avatax.rb', line 21 def status coordinates = { latitude: "34.030291", longitude: "-118.468925"} uri = [@tax_service_url,coordinates[:latitude].to_s,",",coordinates[:longitude].to_s,"/get?saleamount=",0].join response = send_request(:get, uri) response.code end |
#validate(address) ⇒ Hash
Normalizes a single US or Canadian address, providing a non-ambiguous address match. developer.avalara.com/api-docs/api-reference/rest-curl/validate
79 80 81 82 83 |
# File 'lib/little_finger/avatax.rb', line 79 def validate(address) uri = [@address_service_url, "validate?", address.to_query].join response = send_request(:get, uri) JSON.parse(response.body) end |