class SuperGood::SolidusTaxjar::Api

Attributes

taxjar_client[R]

Public Class Methods

default_taxjar_client() click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 4
def self.default_taxjar_client
  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
  )
  client.set_api_config('headers', {
    'x-api-version' => '2020-08-07',
    'plugin' => 'supergoodsolidustaxjar'
  })
  client
end
new(taxjar_client: self.class.default_taxjar_client) click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 16
def initialize(taxjar_client: self.class.default_taxjar_client)
  @taxjar_client = taxjar_client
end

Public Instance Methods

create_refund_for(reimbursement) click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 50
def create_refund_for(reimbursement)
  taxjar_client.create_refund ApiParams.refund_params(reimbursement)
end
create_transaction_for(order) click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 38
def create_transaction_for(order)
  taxjar_client.create_order ApiParams.transaction_params(order)
end
delete_transaction_for(order) click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 46
def delete_transaction_for(order)
  taxjar_client.delete_order order.number
end
nexus_regions() click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 58
def nexus_regions
  taxjar_client.nexus_regions
end
tax_for(order) click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 20
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) click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 30
def tax_rate_for(address)
  taxjar_client.tax_for_order(ApiParams.tax_rate_address_params(address)).rate
end
tax_rates_for(address) click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 34
def tax_rates_for(address)
  taxjar_client.rates_for_location(*ApiParams.address_params(address))
end
update_transaction_for(order) click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 42
def update_transaction_for(order)
  taxjar_client.update_order ApiParams.transaction_params(order)
end
validate_spree_address(spree_address) click to toggle source
# File lib/super_good/solidus_taxjar/api.rb, line 54
def validate_spree_address(spree_address)
  taxjar_client.validate_address ApiParams.validate_address_params(spree_address)
end