Module: SuperGood::SolidusTaxJar::APIParams

Defined in:
lib/super_good/solidus_taxjar/api_params.rb

Class Method Summary collapse

Class Method Details

.address_params(address) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/super_good/solidus_taxjar/api_params.rb', line 21

def address_params(address)
  [
    address.zipcode,
    {
      street: address.address1,
      city: address.city,
      state: address&.state&.abbr || address.state_name,
      country: address.country.iso
    }
  ]
end

.order_params(order) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/super_good/solidus_taxjar/api_params.rb', line 5

def order_params(order)
  {}
    .merge(customer_params(order))
    .merge(order_address_params(order.tax_address))
    .merge(line_items_params(order.line_items))
    .merge(shipping: shipping(order))
    .merge(SuperGood::SolidusTaxJar.custom_order_params.(order))
    .tap do |params|
      next unless SuperGood::SolidusTaxJar.logging_enabled

      Rails.logger.info(
        "TaxJar params for #{order.number}: #{params.inspect}"
      )
    end
end

.refund_params(reimbursement) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/super_good/solidus_taxjar/api_params.rb', line 54

def refund_params(reimbursement)
  additional_taxes = reimbursement.return_items.sum(&:additional_tax_total)

  {}
    .merge(order_address_params(reimbursement.order.tax_address))
    .merge(
      transaction_id: reimbursement.number,
      transaction_reference_id: reimbursement.order.number,
      transaction_date: reimbursement.order.completed_at.to_formatted_s(:iso8601),
      amount: reimbursement.total - additional_taxes,
      shipping: 0,
      sales_tax: additional_taxes
    )
end

.tax_rate_address_params(address) ⇒ Object



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

def tax_rate_address_params(address)
  {
    amount: 100,
    shipping: 0,
  }.merge(order_address_params(address))
end

.transaction_params(order) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/super_good/solidus_taxjar/api_params.rb', line 40

def transaction_params(order)
  {}
    .merge(customer_params(order))
    .merge(order_address_params(order.tax_address))
    .merge(transaction_line_items_params(order.line_items))
    .merge(
      transaction_id: order.number,
      transaction_date: order.completed_at.to_formatted_s(:iso8601),
      amount: [order.total - order.additional_tax_total, 0].max,
      shipping: shipping(order),
      sales_tax: sales_tax(order)
    )
end