Class: Strikeiron::TaxValue

Inherits:
Object
  • Object
show all
Defined in:
lib/strikeiron/tax_value.rb

Overview

Total sales tax rate based on the dollar amount and category from TaxValueRequest. TaxValueRecord should only be rendered from a SOAP response.

Attributes

  • category - The corresponding category name. A category name and/or ID must be supplied.

  • category_id - The corresponding category ID. A category name and/or ID must be supplied.

  • amount - The amount to calculate the tax for.

  • tax_amount - The combined sales tax rate based on the address and tax category provided

Notes

See Strikeiron.tax_categories for information on obtaining category information.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_values = {}) ⇒ TaxValue

Creates a TaxValueRecord with the supplied attributes.



17
18
19
20
21
22
23
# File 'lib/strikeiron/tax_value.rb', line 17

def initialize(default_values = {})
  safe_keys = %w(category category_id amount tax_amount jurisdictions)
  # Only permit the keys defined in safe_keys
  default_values.reject! { |key, value| !safe_keys.include?(key.to_s) }

  default_values.each { |key, value| self.send "#{key}=", value }
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



14
15
16
# File 'lib/strikeiron/tax_value.rb', line 14

def amount
  @amount
end

#categoryObject

Returns the value of attribute category.



14
15
16
# File 'lib/strikeiron/tax_value.rb', line 14

def category
  @category
end

#category_idObject

Returns the value of attribute category_id.



14
15
16
# File 'lib/strikeiron/tax_value.rb', line 14

def category_id
  @category_id
end

#jurisdictionsObject

Returns the value of attribute jurisdictions.



14
15
16
# File 'lib/strikeiron/tax_value.rb', line 14

def jurisdictions
  @jurisdictions
end

#tax_amountObject

Returns the value of attribute tax_amount.



14
15
16
# File 'lib/strikeiron/tax_value.rb', line 14

def tax_amount
  @tax_amount
end

Class Method Details

.from_soap(hash = {}) ⇒ Object

Convert the SOAP response object to a TaxValueRecord



35
36
37
38
39
40
41
42
43
# File 'lib/strikeiron/tax_value.rb', line 35

def from_soap(hash = {})
  default_values = {
    :category    => hash['Category'],
    :category_id => hash['CategoryID'],
    :tax_amount  => hash['SalesTaxAmount']
  }

  new(default_values)
end

Instance Method Details

#to_soapObject

Convert the object to be valid for the SOAP request



26
27
28
29
30
31
# File 'lib/strikeiron/tax_value.rb', line 26

def to_soap
  {
    'SalesTaxCategoryOrCategoryID' => category || category_id,
    'Amount'                       => amount
  }
end