Class: SuperGood::SolidusTaxjar::Reporting

Inherits:
Object
  • Object
show all
Defined in:
lib/super_good/solidus_taxjar/reporting.rb

Instance Method Summary collapse

Constructor Details

#initialize(api: SuperGood::SolidusTaxjar.api) ⇒ Reporting

Returns a new instance of Reporting.



4
5
6
# File 'lib/super_good/solidus_taxjar/reporting.rb', line 4

def initialize(api: SuperGood::SolidusTaxjar.api)
  @api = api
end

Instance Method Details

#refund_and_create_new_transaction(order) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/super_good/solidus_taxjar/reporting.rb', line 8

def refund_and_create_new_transaction(order)
  latest_order_transaction = OrderTransaction.latest_for(order)

  unless latest_order_transaction.refund_transaction
    transaction_response = @api.create_refund_transaction_for(order)
    latest_order_transaction.create_refund_transaction!(
      transaction_id: transaction_response.transaction_id,
      transaction_date: transaction_response.transaction_date
    )
  end

  return if order.total.zero?

  if transaction_response = @api.create_transaction_for(order)
    order.taxjar_order_transactions.create!(
      transaction_id: transaction_response.transaction_id,
      transaction_date: transaction_response.transaction_date
    )
  end
end

#show_or_create_transaction(order) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/super_good/solidus_taxjar/reporting.rb', line 29

def show_or_create_transaction(order)
  if transaction_response = @api.show_latest_transaction_for(order)
    SuperGood::SolidusTaxjar::OrderTransaction.find_by!(
      transaction_id: transaction_response.transaction_id
    )
  else
    transaction_response = @api.create_transaction_for(order)
    order.taxjar_order_transactions.create!(
      transaction_id: transaction_response.transaction_id,
      transaction_date: transaction_response.transaction_date
    )
  end
end