Class: Strikeiron::TaxValue

Inherits:
Object
  • Object
show all
Defined in:
lib/strikeiron2/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
24
# File 'lib/strikeiron2/tax_value.rb', line 17

def initialize(default_values = {})
  safe_keys = %w(category category_id amount tax_amount jurisdictions)
  
  default_values.each do |key, value|
    next unless safe_keys.include? key.to_s # Only permit the keys defined in safe_keys
    self.send "#{key}=", value
  end
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



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

def amount
  @amount
end

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#category_idObject

Returns the value of attribute category_id.



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

def category_id
  @category_id
end

#jurisdictionsObject

Returns the value of attribute jurisdictions.



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

def jurisdictions
  @jurisdictions
end

#tax_amountObject

Returns the value of attribute tax_amount.



14
15
16
# File 'lib/strikeiron2/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/strikeiron2/tax_value.rb', line 35

def self.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



27
28
29
30
31
32
# File 'lib/strikeiron2/tax_value.rb', line 27

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