Module: SuperGood::SolidusTaxjar::Reportable

Included in:
Spree::Admin::TaxjarTransactionsController, Spree::LegacyReportingSubscriber, Spree::ReportingSubscriber
Defined in:
lib/super_good/solidus_taxjar/reportable.rb

Constant Summary collapse

ORDER_TOO_OLD_MESSAGE =
"Order cannot be synced because it was completed before TaxJar reporting was enabled"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/super_good/solidus_taxjar/reportable.rb', line 6

def self.included(base)
  # Omnes subscribers are classes, whereas the legacy event system uses
  # modules for subscribers. The type check ensures this is forwards
  # compatible and can be removed when we drop support for the legacy
  # event system.
  base.extend(base) unless base.is_a?(Class)
end

Instance Method Details

#order_reportable?(order) ⇒ Boolean

Returns true if the TaxJar reporting is currently enabled and the order meets all the other requirements for reporting.

Returns:

  • (Boolean)

    true if the TaxJar reporting is currently enabled and the order meets all the other requirements for reporting.



34
35
36
37
38
39
# File 'lib/super_good/solidus_taxjar/reportable.rb', line 34

def order_reportable?(order)
  return SuperGood::SolidusTaxjar.configuration.preferred_reporting_enabled &&
    order.completed? &&
    order.shipped? &&
    order.payment_state == "paid"
end

#transaction_replaceable?(order) ⇒ Boolean

Returns true if the transaction has been previously reported to TaxJar, the order is currently in ‘paid` state and there is a difference between the total (before tax) on the order in Solidus and the transaction amount on TaxJar.

Returns:

  • (Boolean)

    true if the transaction has been previously reported to TaxJar, the order is currently in ‘paid` state and there is a difference between the total (before tax) on the order in Solidus and the transaction amount on TaxJar.



45
46
47
48
# File 'lib/super_good/solidus_taxjar/reportable.rb', line 45

def transaction_replaceable?(order)
  order.taxjar_order_transactions.present? &&
    amount_changed?(order)
end

#with_replaceable(order, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/super_good/solidus_taxjar/reportable.rb', line 24

def with_replaceable(order, &block)
  return unless order_reportable?(order)
  return if completed_before_reporting_enabled?(order)
  return unless transaction_replaceable?(order)

  yield
end

#with_reportable(order, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/super_good/solidus_taxjar/reportable.rb', line 14

def with_reportable(order, &block)
  raise "Please provide a block!" unless block_given?

  return unless order_reportable?(order)
  return if completed_before_reporting_enabled?(order)
  return unless order.taxjar_order_transactions.none?

  yield
end