Class: Killbill::Avatax::AvataxClient
- Inherits:
-
KillBillClient::Model::Resource
- Object
- KillBillClient::Model::Resource
- Killbill::Avatax::AvataxClient
- Defined in:
- lib/avatax/client.rb
Constant Summary collapse
- KILLBILL_AVATAX_PREFIX =
'/plugins/killbill-avatax'
Class Method Summary collapse
- .get_tax_code(product_name, options = {}) ⇒ Object
- .get_tax_codes(options = {}) ⇒ Object
- .remove_exemption(account_id, user, reason, comment, options = {}) ⇒ Object
- .remove_tax_code(product_name, _user, _reason, _comment, options = {}) ⇒ Object
- .set_exemption(account_id, customer_usage_type, user, reason, comment, options = {}) ⇒ Object
- .set_tax_code(product_name, tax_code, _user, _reason, _comment, options = {}) ⇒ Object
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, = {}) path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes/#{product_name}" response = KillBillClient::API.get path, {}, 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( = {}) path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes" response = KillBillClient::API.get path, {}, 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(account_id, user, reason, comment, = {}) set_exemption(account_id, nil, user, reason, comment, ) 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, = {}) path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes/#{product_name}" KillBillClient::API.delete path, nil, {}, 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(account_id, customer_usage_type, user, reason, comment, = {}) exemption_cf_name = 'customerUsageType' account = KillBillClient::Model::Account.find_by_id(account_id, false, false, ) # Remove existing exemption(s) first account.custom_fields('NONE', ).each do |custom_field| account.remove_custom_field(custom_field.custom_field_id, user, reason, comment, ) 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 account.add_custom_field(custom_field, user, reason, comment, ) 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, = {}) body = { productName: product_name, taxCode: tax_code }.to_json path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes" response = KillBillClient::API.post path, body, {}, response.body end |