killbill-avatax 0.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -6
  3. data/Rakefile +3 -5
  4. data/app/assets/javascripts/application.js +0 -6
  5. data/app/assets/stylesheets/application.css +1 -1
  6. data/app/assets/stylesheets/bootstrap_and_overrides.css +0 -4
  7. data/app/controllers/avatax/configuration_controller.rb +49 -35
  8. data/app/controllers/avatax/engine_controller.rb +2 -2
  9. data/app/helpers/avatax/application_helper.rb +2 -0
  10. data/app/views/avatax/configuration/_plugin_form.html.erb +2 -11
  11. data/config/routes.rb +3 -3
  12. data/lib/avatax.rb +10 -10
  13. data/lib/avatax/client.rb +14 -18
  14. data/lib/avatax/engine.rb +4 -4
  15. data/lib/avatax/version.rb +3 -1
  16. data/lib/tasks/avatax_tasks.rake +1 -0
  17. data/test/avatax_test.rb +3 -1
  18. data/test/dummy/app/assets/config/manifest.js +1 -0
  19. data/test/dummy/bin/rails +1 -1
  20. data/test/dummy/bin/setup +21 -12
  21. data/test/dummy/bin/update +29 -0
  22. data/test/dummy/bin/yarn +11 -0
  23. data/test/dummy/config/application.rb +14 -20
  24. data/test/dummy/config/boot.rb +2 -4
  25. data/test/dummy/config/environment.rb +1 -1
  26. data/test/dummy/config/environments/development.rb +26 -13
  27. data/test/dummy/config/environments/production.rb +29 -17
  28. data/test/dummy/config/environments/test.rb +7 -7
  29. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  30. data/test/dummy/config/initializers/assets.rb +6 -3
  31. data/test/dummy/config/initializers/cookies_serializer.rb +2 -0
  32. data/test/dummy/config/initializers/new_framework_defaults_5_1.rb +14 -0
  33. data/test/dummy/config/initializers/wrap_parameters.rb +2 -2
  34. data/test/dummy/config/locales/en.yml +10 -0
  35. data/test/dummy/config/secrets.yml +15 -5
  36. data/test/integration/navigation_test.rb +13 -4
  37. data/test/test_helper.rb +7 -7
  38. metadata +151 -269
  39. data/test/dummy/config/database.yml +0 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29a3897328ca491b74d95b73e0b88646f384d6e3
4
- data.tar.gz: 358aabaeb09c912fc676b1a20e224cff8b8b573d
3
+ metadata.gz: 649bcd5e1b0d3b47a658a12d5b66ec84b005ea46
4
+ data.tar.gz: 901a135544d1d1908b55c01afb77a4177aa1cb30
5
5
  SHA512:
6
- metadata.gz: 668451206aa3d018f6456cc401dca2d561e693735673af0054dea975510298162417d063df1a8cbb9b6e2e7b62fd24885b035f93b13e285435a07e1c144afff9
7
- data.tar.gz: 243ba53ded70ca620c3c5eb071df161669536344ac9391a68a418676963c37016e2c98a46d320a41314d60ddd16503ea8959630187ac57170bee6f52f60f992d
6
+ metadata.gz: eecf8bef864704fe7972936dfd53b1aac91a41dace7ecffeb26437f993d3ffb7da152ec5098f042fd6f1e84cb4794f1de4511d8c073fb5d88e2ee88847366ce4
7
+ data.tar.gz: 0d4f6ad68dd2933b2257017c63d2c5f8b317bf21ed49ddeedc52a4626d2ca4866d724df779f8425adccad7a6ec4962050aa0e7ed345cab4fcb00216ac4b5c01d
data/README.md CHANGED
@@ -4,8 +4,19 @@ Overview
4
4
 
5
5
  This Rails mountable engine allows you to manage your Avatax integration in Kill Bill.
6
6
 
7
- * See [killbill/killbill-avatax-plugin](https://github.com/killbill/killbill-avatax-plugin) to get started with the Avatax plugin.
8
- * See [killbill-admin-ui-standalone](https://github.com/killbill/killbill-admin-ui-standalone) to get start with the Kill Bill Admin UI.
7
+ * See [killbill-avatax-plugin](https://github.com/killbill/killbill-avatax-plugin) to get started with the Avatax plugin.
8
+ * See [killbill-admin-ui-standalone](https://github.com/killbill/killbill-admin-ui-standalone) to get started with the Kill Bill Admin UI.
9
+
10
+ Kill Bill compatibility
11
+ -----------------------
12
+
13
+ | Avatax UI version | Kill Bill version |
14
+ | ----------------: | ----------------: |
15
+ | 0.0.y | 0.16.z |
16
+ | 0.1.y | 0.18.z (Rails 4) |
17
+ | 0.2.y | 0.18.z (Rails 5) |
18
+ | 1.x.y | 0.20.z |
19
+ | 2.x.y | 0.22.z |
9
20
 
10
21
  Functionality
11
22
  -------------
@@ -32,8 +43,12 @@ KillBillClient.api_secret = 'lazar'
32
43
  Then, simply run:
33
44
 
34
45
  ```
35
- bundle install
36
- export RAILS_ENV=development
37
- cd test/dummy
38
- rails server
46
+ rails s
47
+ ```
48
+
49
+
50
+ To run tests:
51
+
52
+ ```
53
+ rails t
39
54
  ```
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'bundler/setup'
3
5
  rescue LoadError
@@ -14,14 +16,11 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
16
  rdoc.rdoc_files.include('lib/**/*.rb')
15
17
  end
16
18
 
17
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
19
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
18
20
  load 'rails/tasks/engine.rake'
19
21
 
20
-
21
22
  load 'rails/tasks/statistics.rake'
22
23
 
23
-
24
-
25
24
  Bundler::GemHelper.install_tasks
26
25
 
27
26
  require 'rake/testtask'
@@ -33,5 +32,4 @@ Rake::TestTask.new(:test) do |t|
33
32
  t.verbose = false
34
33
  end
35
34
 
36
-
37
35
  task default: :test
@@ -10,15 +10,9 @@
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require js-routes
14
- //= require moment
15
- //= require spin
16
13
  //= require jquery
17
14
  //= require jquery_ujs
18
15
  //= require twitter/bootstrap
19
16
  //= require dataTables/jquery.dataTables
20
17
  //= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
21
- //= require d3
22
- //= require bootstrap-datepicker
23
- //= require jquery.spin
24
18
  //= require avatax/avatax
@@ -11,9 +11,9 @@
11
11
  * file per style scope.
12
12
  *
13
13
  *= require_self
14
- *= require bootstrap-datepicker3
15
14
  *= require dataTables/jquery.dataTables
16
15
  *= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
16
+ *= require font-awesome
17
17
  *= require bootstrap_and_overrides
18
18
  *= require avatax/avatax
19
19
  */
@@ -1,9 +1,5 @@
1
1
  /*
2
2
  *= require twitter-bootstrap-static/bootstrap
3
- *
4
- * Use Font Awesome icons (default)
5
- * To use Glyphicons sprites instead of Font Awesome, replace with "require twitter-bootstrap-static/sprites"
6
- *= require twitter-bootstrap-static/fontawesome
7
3
  */
8
4
 
9
5
  /* Override Bootstrap 3 font locations */
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'avatax/client'
2
4
 
3
5
  module Avatax
4
6
  class ConfigurationController < EngineController
5
-
6
7
  def index
7
8
  @tax_codes = ::Killbill::Avatax::AvataxClient.get_tax_codes(options_for_klient)
8
9
  @exemptions = exempt_accounts
@@ -13,7 +14,7 @@ module Avatax
13
14
  #
14
15
 
15
16
  def set_tax_code
16
- @products = KillBillClient::Model::Catalog.simple_catalog(options_for_klient).products.map(&:name)
17
+ @products = KillBillClient::Model::Catalog.simple_catalog(options_for_klient).last.products.map(&:name)
17
18
  end
18
19
 
19
20
  def do_set_tax_code
@@ -25,7 +26,7 @@ module Avatax
25
26
  options_for_klient)
26
27
 
27
28
  flash[:notice] = 'Tax code successfully saved'
28
- redirect_to :action => :index
29
+ redirect_to action: :index
29
30
  end
30
31
 
31
32
  def remove_tax_code
@@ -36,15 +37,14 @@ module Avatax
36
37
  options_for_klient)
37
38
 
38
39
  flash[:notice] = 'Tax code successfully removed'
39
- redirect_to :action => :index
40
+ redirect_to action: :index
40
41
  end
41
42
 
42
43
  #
43
44
  # Exemptions
44
45
  #
45
46
 
46
- def set_exemption
47
- end
47
+ def set_exemption; end
48
48
 
49
49
  def do_set_exemption
50
50
  ::Killbill::Avatax::AvataxClient.set_exemption(params.require(:account_id),
@@ -55,7 +55,7 @@ module Avatax
55
55
  options_for_klient)
56
56
 
57
57
  flash[:notice] = 'Exemption successfully saved'
58
- redirect_to :action => :index
58
+ redirect_to action: :index
59
59
  end
60
60
 
61
61
  def remove_exemption
@@ -66,7 +66,7 @@ module Avatax
66
66
  options_for_klient)
67
67
 
68
68
  flash[:notice] = 'Exemption successfully removed'
69
- redirect_to :action => :index
69
+ redirect_to action: :index
70
70
  end
71
71
 
72
72
  #
@@ -82,26 +82,44 @@ module Avatax
82
82
  config.values.first.split.each do |property|
83
83
  k, v = property.split('=')
84
84
  case k
85
- when 'org.killbill.billing.plugin.avatax.url'
86
- @configuration[:test] = avatax_url(true) == v
87
- when 'org.killbill.billing.plugin.avatax.accountNumber'
88
- @configuration[:account_number] = v
89
- when 'org.killbill.billing.plugin.avatax.licenseKey'
90
- @configuration[:license_key] = v
91
- when 'org.killbill.billing.plugin.avatax.companyCode'
92
- @configuration[:company_code] = v
93
- when 'org.killbill.billing.plugin.avatax.commitDocuments'
94
- @configuration[:commit_documents] = v == 'true'
85
+ when 'org.killbill.billing.plugin.avatax.accountId'
86
+ @configuration[:account_id] = v
87
+ when 'org.killbill.billing.plugin.avatax.licenseKey'
88
+ @configuration[:license_key] = v
89
+ when 'org.killbill.billing.plugin.avatax.companyCode'
90
+ @configuration[:company_code] = v
91
+ when 'org.killbill.billing.plugin.avatax.commitDocuments'
92
+ @configuration[:commit_documents] = v == 'true'
95
93
  end
96
94
  end
97
95
  end
98
96
 
99
97
  def update_plugin_configuration
100
- plugin_config = "org.killbill.billing.plugin.avatax.url=#{avatax_url(params[:test] == '1')}
101
- org.killbill.billing.plugin.avatax.accountNumber=#{params.require(:account_number)}
102
- org.killbill.billing.plugin.avatax.licenseKey=#{params.require(:license_key)}
103
- org.killbill.billing.plugin.avatax.companyCode=#{params[:company_code]}
104
- org.killbill.billing.plugin.avatax.commitDocuments=#{params[:commit_documents] == '1'}"
98
+ plugin_config = "org.killbill.billing.plugin.avatax.accountId=#{params.require(:account_id)}
99
+ org.killbill.billing.plugin.avatax.licenseKey=#{params.require(:license_key)}\n"
100
+ plugin_config << "org.killbill.billing.plugin.avatax.commitDocuments=#{params[:commit_documents] == '1'}\n"
101
+ plugin_config << "org.killbill.billing.plugin.avatax.companyCode=#{params[:company_code]}\n" unless params[:company_code].blank?
102
+
103
+ # Merge the new values with the current config. The config will likely contain additional fields that we don't want to clobber.
104
+ # The user should really use the more powerful /admin_tenants screen - this plugin screen was just created
105
+ # to be able to pass the initial AvaTax certification.
106
+ current_config = KillBillClient::Model::Tenant.get_tenant_plugin_config('killbill-avatax', options_for_klient)
107
+
108
+ (current_config.values || ['']).first.split.each do |property|
109
+ k, v = property.split('=')
110
+ plugin_config << case k
111
+ when 'org.killbill.billing.plugin.avatax.accountId'
112
+ next
113
+ when 'org.killbill.billing.plugin.avatax.licenseKey'
114
+ next
115
+ when 'org.killbill.billing.plugin.avatax.companyCode'
116
+ next
117
+ when 'org.killbill.billing.plugin.avatax.commitDocuments'
118
+ next
119
+ else
120
+ "#{k}=#{v}\n"
121
+ end
122
+ end
105
123
 
106
124
  KillBillClient::Model::Tenant.upload_tenant_plugin_config('killbill-avatax',
107
125
  plugin_config,
@@ -111,31 +129,27 @@ org.killbill.billing.plugin.avatax.commitDocuments=#{params[:commit_documents] =
111
129
  options_for_klient)
112
130
 
113
131
  flash[:notice] = 'Configuration successfully saved'
114
- redirect_to :action => :index
132
+ redirect_to action: :index
115
133
  end
116
134
 
117
135
  private
118
136
 
119
- def avatax_url(test)
120
- "https://#{test ? 'development' : 'avatax'}.avalara.net"
121
- end
122
-
123
137
  def exempt_accounts(offset = 0, limit = 100)
124
138
  custom_field_value = 'customerUsageType'
125
139
 
126
140
  KillBillClient::Model::CustomField.find_in_batches_by_search_key(custom_field_value, offset, limit, options_for_klient)
127
- .select { |cf| cf.name == custom_field_value && cf.object_type == 'ACCOUNT' }
128
- .map { |cf| {:account_id => cf.object_id, :customer_usage_type => cf.value} }
141
+ .select { |cf| cf.name == custom_field_value && cf.object_type == 'ACCOUNT' }
142
+ .map { |cf| { account_id: cf.object_id, customer_usage_type: cf.value } }
129
143
  end
130
144
 
131
145
  def options_for_klient
132
146
  user = current_tenant_user
133
147
  {
134
- :username => user[:username],
135
- :password => user[:password],
136
- :session_id => user[:session_id],
137
- :api_key => user[:api_key],
138
- :api_secret => user[:api_secret]
148
+ username: user[:username],
149
+ password: user[:password],
150
+ session_id: user[:session_id],
151
+ api_key: user[:api_key],
152
+ api_secret: user[:api_secret]
139
153
  }
140
154
  end
141
155
  end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avatax
2
4
  class EngineController < ApplicationController
3
-
4
5
  layout :get_layout
5
6
 
6
7
  def get_layout
@@ -13,6 +14,5 @@ module Avatax
13
14
  user = current_user if respond_to?(:current_user)
14
15
  Avatax.current_tenant_user.call(session, user)
15
16
  end
16
-
17
17
  end
18
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avatax
2
4
  module ApplicationHelper
3
5
  end
@@ -1,8 +1,8 @@
1
1
  <%= form_tag update_plugin_configuration_path, :class => 'form-horizontal' do %>
2
2
  <div class="form-group">
3
- <%= label_tag :account_number, 'Account number', :class => 'col-sm-2 control-label' %>
3
+ <%= label_tag :account_id, 'Account ID', :class => 'col-sm-2 control-label' %>
4
4
  <div class="col-sm-10">
5
- <%= text_field_tag :account_number, @configuration[:account_number], :class => 'form-control' %>
5
+ <%= text_field_tag :account_id, @configuration[:account_id], :class => 'form-control' %>
6
6
  </div>
7
7
  </div>
8
8
  <div class="form-group">
@@ -26,15 +26,6 @@
26
26
  </div>
27
27
  </div>
28
28
  </div>
29
- <div class="form-group">
30
- <div class="col-sm-offset-2 col-sm-10">
31
- <div class="checkbox">
32
- <%= label_tag :test, 'Test mode', :class => 'control-label' do %>
33
- <%= check_box_tag :test, '1', @configuration[:test] %>Test mode?
34
- <% end %>
35
- </div>
36
- </div>
37
- </div>
38
29
  <div class="form-group">
39
30
  <div class="col-sm-offset-2 col-sm-10">
40
31
  <%= submit_tag 'Save', :class => 'btn btn-default' %>
data/config/routes.rb CHANGED
@@ -1,8 +1,9 @@
1
- Avatax::Engine.routes.draw do
1
+ # frozen_string_literal: true
2
2
 
3
+ Avatax::Engine.routes.draw do
3
4
  root to: 'configuration#index'
4
5
 
5
- resources :configuration, :only => [:index]
6
+ resources :configuration, only: [:index]
6
7
 
7
8
  scope '/configuration' do
8
9
  match '/tax_code' => 'configuration#set_tax_code', :via => :get, :as => 'set_tax_code_configuration'
@@ -16,5 +17,4 @@ Avatax::Engine.routes.draw do
16
17
  match '/plugin' => 'configuration#plugin_configuration', :via => :get, :as => 'plugin_configuration'
17
18
  match '/plugin' => 'configuration#update_plugin_configuration', :via => :post, :as => 'update_plugin_configuration'
18
19
  end
19
-
20
20
  end
data/lib/avatax.rb CHANGED
@@ -1,22 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'avatax/engine'
2
4
 
3
5
  module Avatax
4
-
5
6
  mattr_accessor :current_tenant_user
6
7
  mattr_accessor :layout
7
8
 
8
- self.current_tenant_user = lambda { |session, user|
9
- {:username => 'admin',
10
- :password => 'password',
11
- :session_id => nil,
12
- :api_key => KillBillClient.api_key,
13
- :api_secret => KillBillClient.api_secret}
9
+ self.current_tenant_user = lambda { |_session, _user|
10
+ { username: 'admin',
11
+ password: 'password',
12
+ session_id: nil,
13
+ api_key: KillBillClient.api_key,
14
+ api_secret: KillBillClient.api_secret }
14
15
  }
15
16
 
16
- def self.config(&block)
17
+ def self.config
17
18
  {
18
- :layout => layout || 'avatax/layouts/avatax_application',
19
+ layout: layout || 'avatax/layouts/avatax_application'
19
20
  }
20
21
  end
21
-
22
22
  end
data/lib/avatax/client.rb CHANGED
@@ -1,29 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Killbill
2
4
  module Avatax
3
-
4
5
  class AvataxClient < KillBillClient::Model::Resource
5
-
6
6
  KILLBILL_AVATAX_PREFIX = '/plugins/killbill-avatax'
7
7
 
8
8
  class << self
9
-
10
9
  def set_exemption(account_id, customer_usage_type, user, reason, comment, options = {})
11
- exemptionCustomFieldName = 'customerUsageType'
10
+ exemption_cf_name = 'customerUsageType'
12
11
 
13
12
  account = KillBillClient::Model::Account.find_by_id(account_id, false, false, options)
14
13
 
15
14
  # Remove existing exemption(s) first
16
15
  account.custom_fields('NONE', options).each do |custom_field|
17
- account.remove_custom_field(custom_field.custom_field_id, user, reason, comment, options) if custom_field.name == exemptionCustomFieldName
16
+ account.remove_custom_field(custom_field.custom_field_id, user, reason, comment, options) if custom_field.name == exemption_cf_name
18
17
  end
19
18
 
20
- unless customer_usage_type.nil?
21
- # Set the exemption
22
- custom_field = KillBillClient::Model::CustomField.new
23
- custom_field.name = exemptionCustomFieldName
24
- custom_field.value = customer_usage_type
25
- account.add_custom_field(custom_field, user, reason, comment, options)
26
- end
19
+ return if customer_usage_type.nil?
20
+
21
+ # Set the exemption
22
+ custom_field = KillBillClient::Model::CustomField.new
23
+ custom_field.name = exemption_cf_name
24
+ custom_field.value = customer_usage_type
25
+ account.add_custom_field(custom_field, user, reason, comment, options)
27
26
  end
28
27
 
29
28
  def remove_exemption(account_id, user, reason, comment, options = {})
@@ -42,22 +41,19 @@ module Killbill
42
41
  JSON.parse(response.body).symbolize_keys
43
42
  end
44
43
 
45
- def set_tax_code(product_name, tax_code, user, reason, comment, options = {})
46
- body = {:productName => product_name, :taxCode => tax_code}.to_json
44
+ def set_tax_code(product_name, tax_code, _user, _reason, _comment, options = {})
45
+ body = { productName: product_name, taxCode: tax_code }.to_json
47
46
 
48
47
  path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes"
49
48
  response = KillBillClient::API.post path, body, {}, options
50
49
  response.body
51
50
  end
52
51
 
53
- def remove_tax_code(product_name, user, reason, comment, options= {})
52
+ def remove_tax_code(product_name, _user, _reason, _comment, options = {})
54
53
  path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes/#{product_name}"
55
54
  KillBillClient::API.delete path, nil, {}, options
56
55
  end
57
-
58
56
  end
59
-
60
57
  end
61
-
62
58
  end
63
59
  end