Module: SolidusTaxCloud::Spree::OrderDecorator
- Defined in:
- app/decorators/models/solidus_tax_cloud/spree/order_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #capture_tax_cloud ⇒ Object
-
#is_taxed_using_tax_cloud? ⇒ Boolean
Order.tax_zone.tax_rates is used here to check if the order is taxable by Tax Cloud.
- #log_tax_cloud(response) ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
6 7 8 9 10 |
# File 'app/decorators/models/solidus_tax_cloud/spree/order_decorator.rb', line 6 def self.prepended(base) base.class_eval do state_machine.after_transition to: :complete, do: :capture_tax_cloud end end |
Instance Method Details
#capture_tax_cloud ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'app/decorators/models/solidus_tax_cloud/spree/order_decorator.rb', line 12 def capture_tax_cloud return unless is_taxed_using_tax_cloud? response = ::Spree::TaxCloud.transaction_from_order(self). if response != 'OK' Rails.logger.error "ERROR: TaxCloud returned an order capture response of #{response}." end log_tax_cloud(response) end |
#is_taxed_using_tax_cloud? ⇒ Boolean
Order.tax_zone.tax_rates is used here to check if the order is taxable by Tax Cloud. It’s not possible check against the order’s tax adjustments because an adjustment is not created for 0% rates. However, US orders must be submitted to Tax Cloud even when the rate is 0%. Note that we explicitly use ship_address instead of tax_address, as per compliance with Tax Cloud instructions.
28 29 30 |
# File 'app/decorators/models/solidus_tax_cloud/spree/order_decorator.rb', line 28 def is_taxed_using_tax_cloud? ::Spree::TaxRate.for_address(ship_address).any? { |rate| rate.calculator_type == 'Spree::Calculator::TaxCloudCalculator' } end |
#log_tax_cloud(response) ⇒ Object
32 33 34 35 36 37 |
# File 'app/decorators/models/solidus_tax_cloud/spree/order_decorator.rb', line 32 def log_tax_cloud(response) # Implement into your own application. # You could create your own Log::TaxCloud model then use either HStore or # JSONB to store the response. # The response argument carries the response from an order transaction. end |