Class: Avatax::ConfigurationController

Inherits:
EngineController show all
Defined in:
app/controllers/avatax/configuration_controller.rb

Instance Method Summary collapse

Methods inherited from EngineController

#current_tenant_user, #get_layout

Instance Method Details

#do_set_exemptionObject



50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/avatax/configuration_controller.rb', line 50

def do_set_exemption
  ::Killbill::Avatax::AvataxClient.set_exemption(params.require(:account_id),
                                                 params.require(:customer_usage_type),
                                                 options_for_klient[:username],
                                                 params[:reason],
                                                 params[:comment],
                                                 options_for_klient)

  flash[:notice] = 'Exemption successfully saved'
  redirect_to action: :index
end

#do_set_tax_codeObject



21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/avatax/configuration_controller.rb', line 21

def do_set_tax_code
  ::Killbill::Avatax::AvataxClient.set_tax_code(params.require(:product_name),
                                                params.require(:tax_code),
                                                options_for_klient[:username],
                                                params[:reason],
                                                params[:comment],
                                                options_for_klient)

  flash[:notice] = 'Tax code successfully saved'
  redirect_to action: :index
end

#indexObject



7
8
9
10
# File 'app/controllers/avatax/configuration_controller.rb', line 7

def index
  @tax_codes = ::Killbill::Avatax::AvataxClient.get_tax_codes(options_for_klient)
  @exemptions = exempt_accounts
end

#plugin_configurationObject

Settings



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/avatax/configuration_controller.rb', line 77

def plugin_configuration
  @configuration = {}

  config = KillBillClient::Model::Tenant.get_tenant_plugin_config('killbill-avatax', options_for_klient)
  return if config.values.empty?

  config.values.first.split.each do |property|
    k, v = property.split('=')
    case k
    when 'org.killbill.billing.plugin.avatax.accountId'
      @configuration[:account_id] = v
    when 'org.killbill.billing.plugin.avatax.licenseKey'
      @configuration[:license_key] = v
    when 'org.killbill.billing.plugin.avatax.companyCode'
      @configuration[:company_code] = v
    when 'org.killbill.billing.plugin.avatax.commitDocuments'
      @configuration[:commit_documents] = v == 'true'
    end
  end
end

#remove_exemptionObject



62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/avatax/configuration_controller.rb', line 62

def remove_exemption
  ::Killbill::Avatax::AvataxClient.remove_exemption(params.require(:account_id),
                                                    options_for_klient[:username],
                                                    params[:reason],
                                                    params[:comment],
                                                    options_for_klient)

  flash[:notice] = 'Exemption successfully removed'
  redirect_to action: :index
end

#remove_tax_codeObject



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/avatax/configuration_controller.rb', line 33

def remove_tax_code
  ::Killbill::Avatax::AvataxClient.remove_tax_code(params.require(:product_name),
                                                   options_for_klient[:username],
                                                   params[:reason],
                                                   params[:comment],
                                                   options_for_klient)

  flash[:notice] = 'Tax code successfully removed'
  redirect_to action: :index
end

#set_exemptionObject

Exemptions



48
# File 'app/controllers/avatax/configuration_controller.rb', line 48

def set_exemption; end

#set_tax_codeObject

Tax Codes



16
17
18
19
# File 'app/controllers/avatax/configuration_controller.rb', line 16

def set_tax_code
  simple_catalog = KillBillClient::Model::Catalog.simple_catalog(nil, options_for_klient).last
  @products = simple_catalog ? simple_catalog.products.map(&:name) : []
end

#update_plugin_configurationObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/controllers/avatax/configuration_controller.rb', line 98

def update_plugin_configuration
  plugin_config = "org.killbill.billing.plugin.avatax.accountId=#{params.require(:account_id)}
org.killbill.billing.plugin.avatax.licenseKey=#{params.require(:license_key)}\n"
  plugin_config << "org.killbill.billing.plugin.avatax.commitDocuments=#{params[:commit_documents] == '1'}\n"
  plugin_config << "org.killbill.billing.plugin.avatax.companyCode=#{params[:company_code]}\n" unless params[:company_code].blank?

  # Merge the new values with the current config. The config will likely contain additional fields that we don't want to clobber.
  # The user should really use the more powerful /admin_tenants screen - this plugin screen was just created
  # to be able to pass the initial AvaTax certification.
  current_config = KillBillClient::Model::Tenant.get_tenant_plugin_config('killbill-avatax', options_for_klient)
  config_values = current_config.values
  config_values.present? && config_values.first.split.each do |property|
    k, v = property.split('=')
    plugin_config << case k
                     when 'org.killbill.billing.plugin.avatax.accountId', 'org.killbill.billing.plugin.avatax.licenseKey', 'org.killbill.billing.plugin.avatax.companyCode', 'org.killbill.billing.plugin.avatax.commitDocuments'
                       next
                     else
                       "#{k}=#{v}\n"
                     end
  end

  KillBillClient::Model::Tenant.upload_tenant_plugin_config('killbill-avatax',
                                                            plugin_config,
                                                            options_for_klient[:username],
                                                            params[:reason],
                                                            params[:comment],
                                                            options_for_klient)

  flash[:notice] = 'Configuration successfully saved'
  redirect_to action: :index
end