Module: Strikeiron
- Defined in:
- lib/strikeiron.rb,
lib/strikeiron/address.rb,
lib/strikeiron/version.rb,
lib/strikeiron/tax_value.rb,
lib/strikeiron/tax_result.rb,
lib/strikeiron/jurisdiction.rb,
lib/strikeiron/configuration.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Address, Configuration, Jurisdiction, TaxResult, TaxValue
Constant Summary collapse
- WSDL =
The location of the Strikeiron Online Sales Tax WSDL
'https://wsparam.strikeiron.com/SpeedTaxSalesTax3?WSDL'
- VERSION =
"0.0.4"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
-
.client ⇒ Object
Singleton Savon client.
-
.configure {|configuration| ... } ⇒ Object
Configure Strikeiron for your account.
-
.remaining_hits ⇒ Object
The number of API hits remanining for the configured account.
-
.sales_tax(options = {}) ⇒ Object
Get the calculated online sales tax for a product or service.
-
.tax_categories ⇒ Object
Performs a request to obtain a list of all available category names and their corresponding ID number.
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
16 17 18 |
# File 'lib/strikeiron.rb', line 16 def configuration @configuration end |
Class Method Details
.client ⇒ Object
Singleton Savon client
25 26 27 |
# File 'lib/strikeiron.rb', line 25 def client @@client ||= Savon::Client.new(WSDL) end |
.configure {|configuration| ... } ⇒ Object
Configure Strikeiron for your account. See Configuration for more information.
19 20 21 22 |
# File 'lib/strikeiron.rb', line 19 def configure self.configuration ||= Configuration.new yield configuration end |
.remaining_hits ⇒ Object
The number of API hits remanining for the configured account
Example
Strikeiron.remaining_hits
# => 100
93 94 95 96 97 98 99 100 101 |
# File 'lib/strikeiron.rb', line 93 def remaining_hits response = client.request(:get_remaining_hits) do |soap| soap.body = { 'UserID' => configuration.user_id, 'Password' => configuration.password } end response[:si_subscription_info][:remaining_hits].to_i end |
.sales_tax(options = {}) ⇒ Object
Get the calculated online sales tax for a product or service
Options
-
from
- The origin Address (or your physical location). Required. -
to
- The destination Address of the customer. Required. -
tax_values
- An array of TaxValueRequest objects. Required.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/strikeiron.rb', line 35 def sales_tax( = {}) = .inject({}) { |memo,(k, v)| memo[k.to_sym] = v; memo } = %w(from to tax_values) # Raise an error if the required option is not defined .each { |val| raise ArgumentError, "Missing option :#{val}" if !.include?(val.to_sym) } response = client.request(:get_sales_tax_value) do |soap| soap.body = { 'UserID' => configuration.user_id, 'Password' => configuration.password, 'ShipFrom' => [:from].to_soap, 'ShipTo' => [:to].to_soap, 'TaxValueRequests' => { 'TaxValueRequest' => [:tax_values].map(&:to_soap) } } end response_code = response[:get_sales_tax_value_response][:get_sales_tax_value_result][:service_status][:status_nbr] # Raise exceptions if there was an error when calculating the tax case response_code.to_i when 401 raise RuntimeError, 'Invalid From address.' when 402 raise RuntimeError, 'Invalid To address.' when 403 raise RuntimeError, 'Invalid Taxability category.' when 500 raise RuntimeError, 'Internal Strikeiron server error.' end Strikeiron::TaxResult.from_soap(response[:get_sales_tax_value_response][:get_sales_tax_value_result][:service_result]) end |
.tax_categories ⇒ Object
Performs a request to obtain a list of all available category names and their corresponding ID number.
Example
Strikeiron.tax_categories
# => [{:category=>"Alcohol", :category_id=>"01051000"}, {:category=>"Alcoholic Beverages", :category_id=>"01050000"}, {:category=>"Beer", :category_id=>"01052000"}, {:category=>"Books", :category_id=>"01501500"}, {:category=>"Charges necessary to complete sale other than delivery and installation", :category_id=>"04800000"}]
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/strikeiron.rb', line 74 def tax_categories response = client.request(:get_sales_tax_categories) do |soap| soap.body = { 'UserID' => configuration.user_id, 'Password' => configuration.password } end # Return an empty array if the response was not successful return [] if response[:get_sales_tax_categories_response][:get_sales_tax_categories_result][:service_status][:status_nbr] != '200' response[:get_sales_tax_categories_response][:get_sales_tax_categories_result][:service_result][:sales_tax_category] end |