Class: SuperGood::SolidusTaxJar::API

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(taxjar_client: self.class.default_taxjar_client) ⇒ API

Returns a new instance of API.



11
12
13
# File 'lib/super_good/solidus_taxjar/api.rb', line 11

def initialize(taxjar_client: self.class.default_taxjar_client)
  @taxjar_client = taxjar_client
end

Class Method Details

.default_taxjar_clientObject



4
5
6
7
8
9
# File 'lib/super_good/solidus_taxjar/api.rb', line 4

def self.default_taxjar_client
  ::Taxjar::Client.new(
    api_key: ENV.fetch("TAXJAR_API_KEY"),
    api_url: ENV.fetch("TAXJAR_API_URL") { 'https://api.taxjar.com' } # Sandbox URL: https://api.sandbox.taxjar.com
  )
end

Instance Method Details

#create_refund_for(reimbursement) ⇒ Object



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

def create_refund_for(reimbursement)
  taxjar_client.create_refund APIParams.refund_params(reimbursement)
end

#create_transaction_for(order) ⇒ Object



33
34
35
# File 'lib/super_good/solidus_taxjar/api.rb', line 33

def create_transaction_for(order)
  taxjar_client.create_order APIParams.transaction_params(order)
end

#delete_transaction_for(order) ⇒ Object



41
42
43
# File 'lib/super_good/solidus_taxjar/api.rb', line 41

def delete_transaction_for(order)
  taxjar_client.delete_order order.number
end

#tax_for(order) ⇒ Object



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

def tax_for(order)
  taxjar_client.tax_for_order(APIParams.order_params(order)).tap do |taxes|
    next unless SuperGood::SolidusTaxJar.logging_enabled

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

#tax_rate_for(address) ⇒ Object



25
26
27
# File 'lib/super_good/solidus_taxjar/api.rb', line 25

def tax_rate_for(address)
  taxjar_client.tax_for_order(APIParams.tax_rate_address_params(address)).rate
end

#tax_rates_for(address) ⇒ Object



29
30
31
# File 'lib/super_good/solidus_taxjar/api.rb', line 29

def tax_rates_for(address)
  taxjar_client.rates_for_location(*APIParams.address_params(address))
end

#update_transaction_for(order) ⇒ Object



37
38
39
# File 'lib/super_good/solidus_taxjar/api.rb', line 37

def update_transaction_for(order)
  taxjar_client.update_order APIParams.transaction_params(order)
end