Class: Killbill::Avatax::AvataxClient

Inherits:
KillBillClient::Model::Resource
  • Object
show all
Defined in:
lib/avatax/client.rb

Constant Summary collapse

KILLBILL_AVATAX_PREFIX =
'/plugins/killbill-avatax'

Class Method Summary collapse

Class Method Details

.get_tax_code(product_name, options = {}) ⇒ Object



38
39
40
41
42
# File 'lib/avatax/client.rb', line 38

def get_tax_code(product_name, options = {})
  path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes/#{product_name}"
  response = KillBillClient::API.get path, {}, options
  JSON.parse(response.body).symbolize_keys
end

.get_tax_codes(options = {}) ⇒ Object



32
33
34
35
36
# File 'lib/avatax/client.rb', line 32

def get_tax_codes(options = {})
  path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes"
  response = KillBillClient::API.get path, {}, options
  JSON.parse(response.body).map(&:symbolize_keys)
end

.remove_exemption(account_id, user, reason, comment, options = {}) ⇒ Object



28
29
30
# File 'lib/avatax/client.rb', line 28

def remove_exemption(, user, reason, comment, options = {})
  set_exemption(, nil, user, reason, comment, options)
end

.remove_tax_code(product_name, _user, _reason, _comment, options = {}) ⇒ Object



52
53
54
55
# File 'lib/avatax/client.rb', line 52

def remove_tax_code(product_name, _user, _reason, _comment, options = {})
  path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes/#{product_name}"
  KillBillClient::API.delete path, nil, {}, options
end

.set_exemption(account_id, customer_usage_type, user, reason, comment, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/avatax/client.rb', line 9

def set_exemption(, customer_usage_type, user, reason, comment, options = {})
  exemption_cf_name = 'customerUsageType'

   = KillBillClient::Model::Account.find_by_id(, false, false, options)

  # Remove existing exemption(s) first
  .custom_fields('NONE', options).each do |custom_field|
    .remove_custom_field(custom_field.custom_field_id, user, reason, comment, options) if custom_field.name == exemption_cf_name
  end

  return if customer_usage_type.nil?

  # Set the exemption
  custom_field = KillBillClient::Model::CustomField.new
  custom_field.name = exemption_cf_name
  custom_field.value = customer_usage_type
  .add_custom_field(custom_field, user, reason, comment, options)
end

.set_tax_code(product_name, tax_code, _user, _reason, _comment, options = {}) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/avatax/client.rb', line 44

def set_tax_code(product_name, tax_code, _user, _reason, _comment, options = {})
  body = { productName: product_name, taxCode: tax_code }.to_json

  path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes"
  response = KillBillClient::API.post path, body, {}, options
  response.body
end