kaui 0.14.2 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Gemfile +1 -1
- data/README.md +23 -6
- data/app/assets/javascripts/application.js +1 -0
- data/app/assets/stylesheets/application.css +1 -0
- data/app/assets/stylesheets/kaui/header.less +11 -4
- data/app/controllers/kaui/accounts_controller.rb +1 -1
- data/app/controllers/kaui/admin_tenants_controller.rb +113 -18
- data/app/controllers/kaui/bundles_controller.rb +0 -2
- data/app/controllers/kaui/chargebacks_controller.rb +1 -1
- data/app/controllers/kaui/charges_controller.rb +1 -1
- data/app/controllers/kaui/engine_controller.rb +5 -2
- data/app/controllers/kaui/invoices_controller.rb +1 -1
- data/app/controllers/kaui/payment_methods_controller.rb +1 -1
- data/app/controllers/kaui/payments_controller.rb +20 -2
- data/app/controllers/kaui/refunds_controller.rb +1 -1
- data/app/controllers/kaui/subscriptions_controller.rb +8 -13
- data/app/helpers/kaui/account_helper.rb +9 -0
- data/app/helpers/kaui/subscription_helper.rb +47 -21
- data/app/models/kaui/admin_tenant.rb +96 -2
- data/app/models/kaui/bundle.rb +1 -1
- data/app/models/kaui/catalog.rb +138 -0
- data/app/models/kaui/invoice_payment.rb +39 -5
- data/app/models/kaui/overdue.rb +85 -0
- data/app/models/kaui/simple_plan.rb +4 -0
- data/app/models/kaui/transaction.rb +2 -0
- data/app/views/kaui/account_timelines/show.html.erb +2 -1
- data/app/views/kaui/accounts/_billing_info.html.erb +18 -20
- data/app/views/kaui/accounts/_payment_methods.html.erb +11 -16
- data/app/views/kaui/admin_tenants/_form_catalog_translation.erb +24 -0
- data/app/views/kaui/admin_tenants/_form_invoice_template.erb +28 -0
- data/app/views/kaui/admin_tenants/_form_invoice_translation.erb +24 -0
- data/app/views/kaui/admin_tenants/_form_plugin_config.erb +199 -0
- data/app/views/kaui/admin_tenants/_show_catalog.erb +25 -0
- data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +96 -0
- data/app/views/kaui/admin_tenants/_show_catalog_xml.erb +44 -0
- data/app/views/kaui/admin_tenants/_show_overdue.erb +89 -0
- data/app/views/kaui/admin_tenants/new_catalog.html.erb +176 -0
- data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +138 -0
- data/app/views/kaui/admin_tenants/new_plan_currency.html.erb +34 -0
- data/app/views/kaui/admin_tenants/show.html.erb +20 -127
- data/app/views/kaui/bundles/index.html.erb +1 -1
- data/app/views/kaui/invoice_items/_edit_form.html.erb +1 -0
- data/app/views/kaui/layouts/kaui_account_navbar.html.erb +2 -0
- data/app/views/kaui/payments/_payment_table.html.erb +16 -5
- data/app/views/kaui/refunds/_form.html.erb +4 -5
- data/app/views/kaui/subscriptions/_edit_form.html.erb +48 -1
- data/app/views/kaui/subscriptions/_form.html.erb +36 -0
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +12 -9
- data/config/routes.rb +8 -0
- data/db/ddl.sql +5 -2
- data/kaui.gemspec +3 -2
- data/lib/kaui/engine.rb +1 -0
- data/lib/kaui/version.rb +1 -1
- data/test/dummy/config/environments/development.rb +1 -1
- data/test/dummy/db/schema.rb +5 -5
- data/test/functional/kaui/account_emails_controller_test.rb +2 -2
- data/test/functional/kaui/accounts_controller_test.rb +4 -4
- data/test/functional/kaui/admin_tenants_controller_test.rb +5 -1
- data/test/functional/kaui/bundle_tags_controller_test.rb +1 -1
- data/test/functional/kaui/bundles_controller_test.rb +4 -4
- data/test/functional/kaui/chargebacks_controller_test.rb +2 -2
- data/test/functional/kaui/charges_controller_test.rb +2 -2
- data/test/functional/kaui/credits_controller_test.rb +2 -2
- data/test/functional/kaui/invoice_items_controller_test.rb +6 -4
- data/test/functional/kaui/invoices_controller_test.rb +2 -2
- data/test/functional/kaui/payments_controller_test.rb +4 -0
- data/test/functional/kaui/refunds_controller_test.rb +2 -2
- data/test/functional/kaui/subscriptions_controller_test.rb +6 -6
- data/test/killbill_test_helper.rb +7 -7
- metadata +47 -8
- data/db/migrate/20130812155313_devise_create_kaui_users.rb +0 -12
- data/db/migrate/20150109214021_create_kaui_tenants.rb +0 -12
- data/db/migrate/20150112232813_create_kaui_allowed_users.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf008611430663168c6e6f8ef1adca13ef8b0929
|
4
|
+
data.tar.gz: 55cd8e91ff9c1798881a5e8af70dfede6f9576de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90239db91f63b3eeff5170aa41f6e7b75b34c3b4f17eceabe1830f86134193c8a44f3e09c28450b4e6851fdec534e346cd599c97094dd28039f480dd38b690f0
|
7
|
+
data.tar.gz: 7ee1407b3378494668e50879f686c6c33809ad3a3a086572c4abe9572b5a10c460298a5a6058977fe39c1ddcfc62195fc0cf7d461f4c062c6ebdc58ac4f20e23
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,4 +3,4 @@ source 'http://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
#gem 'killbill-client', :path => '../killbill-client-ruby'
|
6
|
-
#gem 'killbill-client', :
|
6
|
+
#gem 'killbill-client', :git => 'https://github.com/killbill/killbill-client-ruby.git'
|
data/README.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
Getting started
|
2
2
|
===============
|
3
3
|
|
4
|
+
Kaui core mountable engine. For Kaui the UI, see [killbill-admin-ui-standalone](https://github.com/killbill/killbill-admin-ui-standalone).
|
5
|
+
|
6
|
+
Kill Bill compatibility
|
7
|
+
-----------------------
|
8
|
+
|
9
|
+
| API version | Kill Bill version |
|
10
|
+
| ----------: | ----------------: |
|
11
|
+
| 0.14.y | 0.16.z |
|
12
|
+
| 0.15.y | 0.18.z |
|
13
|
+
|
4
14
|
Running Kaui locally
|
5
15
|
---------------------
|
6
16
|
|
@@ -12,6 +22,7 @@ export RAILS_ENV=development
|
|
12
22
|
bundle install
|
13
23
|
rake kaui:install:migrations
|
14
24
|
rake db:migrate
|
25
|
+
bundle exec rake assets:precompile
|
15
26
|
rails server
|
16
27
|
```
|
17
28
|
|
@@ -46,17 +57,23 @@ Running tests
|
|
46
57
|
-------------
|
47
58
|
|
48
59
|
Go into 'test/dummy':
|
49
|
-
|
60
|
+
```
|
61
|
+
cd test/dummy/
|
62
|
+
```
|
50
63
|
|
51
64
|
Run migrations:
|
52
|
-
|
53
|
-
|
54
|
-
|
65
|
+
```
|
66
|
+
export RAILS_ENV=test
|
67
|
+
rake kaui:install:migrations
|
68
|
+
rake db:migrate
|
69
|
+
```
|
55
70
|
|
56
71
|
Run the tests:
|
57
72
|
(Move back to top level)
|
58
|
-
|
59
|
-
|
73
|
+
```
|
74
|
+
cd ../..
|
75
|
+
rake test
|
76
|
+
```
|
60
77
|
|
61
78
|
Note: functional and integration tests require an instance of Kill Bill to test against.
|
62
79
|
|
@@ -126,14 +126,11 @@ header {
|
|
126
126
|
}
|
127
127
|
}
|
128
128
|
|
129
|
-
a {
|
129
|
+
a,p {
|
130
130
|
display: inline-block;
|
131
131
|
padding: 12px 40px;
|
132
132
|
font-size: 12px;
|
133
|
-
text-transform: uppercase;
|
134
|
-
color: #666666;
|
135
133
|
margin: 0;
|
136
|
-
border-left: 1px solid #fff;
|
137
134
|
line-height: 12px;
|
138
135
|
background: transparent;
|
139
136
|
vertical-align: top;
|
@@ -173,6 +170,12 @@ header {
|
|
173
170
|
width: 100%;
|
174
171
|
}
|
175
172
|
}
|
173
|
+
}
|
174
|
+
|
175
|
+
a {
|
176
|
+
color: #666666;
|
177
|
+
text-transform: uppercase;
|
178
|
+
border-left: 1px solid #fff;
|
176
179
|
|
177
180
|
&:hover, &.current {
|
178
181
|
color: #fff;
|
@@ -183,4 +186,8 @@ header {
|
|
183
186
|
border-right: 1px solid #fff;
|
184
187
|
}
|
185
188
|
}
|
189
|
+
|
190
|
+
p {
|
191
|
+
font-weight: normal;
|
192
|
+
}
|
186
193
|
}
|
@@ -55,6 +55,7 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def show
|
58
|
+
# Re-fetch the account with balance and CBA
|
58
59
|
@account = Kaui::Account::find_by_id_or_key(params.require(:account_id), true, true, options_for_klient)
|
59
60
|
|
60
61
|
fetch_overdue_state = lambda { @overdue_state = @account.overdue(options_for_klient) }
|
@@ -72,7 +73,6 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
72
73
|
end
|
73
74
|
|
74
75
|
def edit
|
75
|
-
@account = Kaui::Account::find_by_id_or_key(params.require(:account_id), false, false, options_for_klient)
|
76
76
|
end
|
77
77
|
|
78
78
|
def update
|
@@ -14,18 +14,11 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
14
14
|
|
15
15
|
def create
|
16
16
|
param_tenant = params[:tenant]
|
17
|
-
old_tenant = Kaui::Tenant.find_by_name(param_tenant[:name])
|
18
|
-
if old_tenant
|
19
|
-
flash.now[:error] = "Tenant with name #{param_tenant[:name]} already exists!"
|
20
|
-
@tenant = Kaui::Tenant.new
|
21
|
-
render :new and return
|
22
|
-
end
|
23
17
|
|
24
|
-
old_tenant = Kaui::Tenant.find_by_api_key(param_tenant[:api_key])
|
18
|
+
old_tenant = Kaui::Tenant.find_by_name(param_tenant[:name]) || Kaui::Tenant.find_by_api_key(param_tenant[:api_key])
|
25
19
|
if old_tenant
|
26
|
-
|
27
|
-
|
28
|
-
render :new and return
|
20
|
+
old_tenant.kaui_allowed_users << Kaui::AllowedUser.where(:kb_username => current_user.kb_username).first_or_create
|
21
|
+
redirect_to admin_tenant_path(old_tenant[:id]), :notice => 'Tenant was successfully configured' and return
|
29
22
|
end
|
30
23
|
|
31
24
|
begin
|
@@ -37,24 +30,24 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
37
30
|
options[:api_secret] = param_tenant[:api_secret]
|
38
31
|
new_tenant = Kaui::AdminTenant.find_by_api_key(param_tenant[:api_key], options)
|
39
32
|
rescue KillBillClient::API::Unauthorized, KillBillClient::API::NotFound
|
33
|
+
|
40
34
|
# Create the tenant in Kill Bill
|
41
35
|
new_tenant = Kaui::AdminTenant.new
|
42
36
|
new_tenant.external_key = param_tenant[:name]
|
43
37
|
new_tenant.api_key = param_tenant[:api_key]
|
44
38
|
new_tenant.api_secret = param_tenant[:api_secret]
|
45
|
-
new_tenant = new_tenant.create(options[:username], nil, comment, options)
|
39
|
+
new_tenant = new_tenant.create(false, options[:username], nil, comment, options)
|
46
40
|
end
|
47
41
|
|
48
42
|
# Transform object to Kaui model
|
49
43
|
tenant_model = Kaui::Tenant.new
|
50
|
-
tenant_model.name =
|
51
|
-
tenant_model.
|
52
|
-
tenant_model.api_key = new_tenant.api_key
|
44
|
+
tenant_model.name = param_tenant[:name]
|
45
|
+
tenant_model.api_key = param_tenant[:api_key]
|
53
46
|
tenant_model.api_secret = param_tenant[:api_secret]
|
47
|
+
tenant_model.kb_tenant_id = new_tenant.tenant_id
|
54
48
|
|
55
49
|
# Save in KAUI tables
|
56
50
|
tenant_model.save!
|
57
|
-
|
58
51
|
# Make sure at least the current user can access the tenant
|
59
52
|
tenant_model.kaui_allowed_users << Kaui::AllowedUser.where(:kb_username => current_user.kb_username).first_or_create
|
60
53
|
rescue => e
|
@@ -72,6 +65,20 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
72
65
|
def show
|
73
66
|
@tenant = safely_find_tenant_by_id(params[:id])
|
74
67
|
@allowed_users = @tenant.kaui_allowed_users & retrieve_allowed_users_for_current_user
|
68
|
+
|
69
|
+
options = tenant_options_for_client
|
70
|
+
options[:api_key] = @tenant.api_key
|
71
|
+
options[:api_secret] = @tenant.api_secret
|
72
|
+
|
73
|
+
@catalogs = Kaui::Catalog::get_catalog_json(false, options) rescue @catalogs = []
|
74
|
+
@catalogs_xml = Kaui::Catalog::get_catalog_xml(options) rescue @catalogs_xml = []
|
75
|
+
@overdue = Kaui::Overdue::get_overdue_json(options) rescue @overdue = nil
|
76
|
+
@overdue_xml = Kaui::Overdue::get_tenant_overdue_config('xml', options) rescue @overdue_xml = nil
|
77
|
+
|
78
|
+
plugin_repository = Kaui::AdminTenant::get_plugin_repository
|
79
|
+
|
80
|
+
@plugin_config = Kaui::AdminTenant::get_oss_plugin_info(plugin_repository) rescue @plugin_config = ""
|
81
|
+
@tenant_plugin_config = Kaui::AdminTenant::get_tenant_plugin_config(plugin_repository, options) rescue @tenant_plugin_config = ""
|
75
82
|
end
|
76
83
|
|
77
84
|
def upload_catalog
|
@@ -89,6 +96,80 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
89
96
|
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Catalog was successfully uploaded'
|
90
97
|
end
|
91
98
|
|
99
|
+
def new_catalog
|
100
|
+
@tenant = safely_find_tenant_by_id(params[:id])
|
101
|
+
|
102
|
+
options = tenant_options_for_client
|
103
|
+
options[:api_key] = @tenant.api_key
|
104
|
+
options[:api_secret] = @tenant.api_secret
|
105
|
+
|
106
|
+
latest_catalog = Kaui::Catalog::get_catalog_json(true, options)
|
107
|
+
|
108
|
+
@ao_mapping = Kaui::Catalog::build_ao_mapping(latest_catalog)
|
109
|
+
|
110
|
+
@available_base_products = latest_catalog && latest_catalog.products ?
|
111
|
+
latest_catalog.products.select { |p| p.type == 'BASE' }.map { |p| p.name } : []
|
112
|
+
@available_ao_products = latest_catalog && latest_catalog.products ?
|
113
|
+
latest_catalog.products.select { |p| p.type == 'ADD_ON' }.map { |p| p.name } : []
|
114
|
+
@available_standalone_products = latest_catalog && latest_catalog.products ?
|
115
|
+
latest_catalog.products.select { |p| p.type == 'STANDALONE' }.map { |p| p.name } : []
|
116
|
+
@product_categories = [:BASE, :ADD_ON, :STANDALONE]
|
117
|
+
@billing_period = [:DAILY, :WEEKLY, :BIWEEKLY, :THIRTY_DAYS, :MONTHLY, :QUARTERLY, :BIANNUAL, :ANNUAL, :BIENNIAL]
|
118
|
+
@time_units = [:UNLIMITED, :DAYS, :MONTHS, :YEARS]
|
119
|
+
|
120
|
+
@simple_plan = Kaui::SimplePlan.new
|
121
|
+
end
|
122
|
+
|
123
|
+
def new_plan_currency
|
124
|
+
@tenant = safely_find_tenant_by_id(params[:id])
|
125
|
+
@simple_plan = Kaui::SimplePlan.new
|
126
|
+
@simple_plan.plan_id = params[:plan_id]
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
def create_simple_plan
|
131
|
+
|
132
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
133
|
+
|
134
|
+
options = tenant_options_for_client
|
135
|
+
options[:api_key] = current_tenant.api_key
|
136
|
+
options[:api_secret] = current_tenant.api_secret
|
137
|
+
|
138
|
+
simple_plan = params.require(:simple_plan).delete_if { |e, value| value.blank? }
|
139
|
+
# Fix issue in Rails where first entry in the multi-select array is an empty string
|
140
|
+
simple_plan["available_base_products"].reject!(&:blank?) if simple_plan["available_base_products"]
|
141
|
+
|
142
|
+
simple_plan = KillBillClient::Model::SimplePlanAttributes.new(simple_plan)
|
143
|
+
|
144
|
+
Kaui::Catalog.add_tenant_catalog_simple_plan(simple_plan, options[:username], nil, comment, options)
|
145
|
+
|
146
|
+
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Catalog plan was successfully added'
|
147
|
+
end
|
148
|
+
|
149
|
+
def new_overdue_config
|
150
|
+
@tenant = safely_find_tenant_by_id(params[:id])
|
151
|
+
|
152
|
+
options = tenant_options_for_client
|
153
|
+
options[:api_key] = @tenant.api_key
|
154
|
+
options[:api_secret] = @tenant.api_secret
|
155
|
+
@overdue = Kaui::Overdue::get_overdue_json(options)
|
156
|
+
end
|
157
|
+
|
158
|
+
def modify_overdue_config
|
159
|
+
|
160
|
+
current_tenant = safely_find_tenant_by_id(params[:id])
|
161
|
+
|
162
|
+
options = tenant_options_for_client
|
163
|
+
options[:api_key] = current_tenant.api_key
|
164
|
+
options[:api_secret] = current_tenant.api_secret
|
165
|
+
|
166
|
+
view_form_model = params.require(:kill_bill_client_model_overdue).delete_if { |e, value| value.blank? }
|
167
|
+
overdue = Kaui::Overdue::from_overdue_form_model(view_form_model)
|
168
|
+
overdue.upload_tenant_overdue_config_json(options[:username], nil, comment, options)
|
169
|
+
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Overdue config was successfully added '
|
170
|
+
end
|
171
|
+
|
172
|
+
|
92
173
|
def upload_overdue_config
|
93
174
|
current_tenant = safely_find_tenant_by_id(params[:id])
|
94
175
|
|
@@ -161,10 +242,13 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
161
242
|
options[:api_secret] = current_tenant.api_secret
|
162
243
|
|
163
244
|
plugin_name = params[:plugin_name]
|
164
|
-
|
165
|
-
|
245
|
+
plugin_properties = params[:plugin_properties]
|
246
|
+
plugin_type = params[:plugin_type]
|
166
247
|
|
167
|
-
Kaui::AdminTenant.
|
248
|
+
plugin_config = Kaui::AdminTenant.format_plugin_config(plugin_name, plugin_type, plugin_properties)
|
249
|
+
|
250
|
+
key = plugin_type.present? ? "killbill-#{plugin_name}" : plugin_name
|
251
|
+
Kaui::AdminTenant.upload_tenant_plugin_config(key, plugin_config, options[:username], nil, comment, options)
|
168
252
|
|
169
253
|
redirect_to admin_tenant_path(current_tenant.id), :notice => 'Config for plugin was successfully uploaded'
|
170
254
|
end
|
@@ -183,6 +267,17 @@ class Kaui::AdminTenantsController < Kaui::EngineController
|
|
183
267
|
render :json => '{}', :status => 200
|
184
268
|
end
|
185
269
|
|
270
|
+
def display_catalog_xml
|
271
|
+
@catalog_xml = params.require(:xml)
|
272
|
+
render xml: @catalog_xml
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
def display_overdue_xml
|
277
|
+
render xml: params.require(:xml)
|
278
|
+
end
|
279
|
+
|
280
|
+
|
186
281
|
private
|
187
282
|
|
188
283
|
def safely_find_tenant_by_id(tenant_id)
|
@@ -1,8 +1,6 @@
|
|
1
1
|
class Kaui::BundlesController < Kaui::EngineController
|
2
2
|
|
3
3
|
def index
|
4
|
-
@account = Kaui::Account::find_by_id_or_key(params.require(:account_id), false, false, options_for_klient)
|
5
|
-
|
6
4
|
fetch_bundles = lambda { @bundles = @account.bundles(options_for_klient) }
|
7
5
|
fetch_bundle_tags = lambda {
|
8
6
|
all_bundle_tags = @account.all_tags(:BUNDLE, false, 'NONE', options_for_klient)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Kaui::ChargebacksController < Kaui::EngineController
|
2
2
|
|
3
3
|
def new
|
4
|
-
payment = Kaui::Payment::find_by_id(params.require(:payment_id), options_for_klient)
|
4
|
+
payment = Kaui::Payment::find_by_id(params.require(:payment_id), false, false, options_for_klient)
|
5
5
|
@chargeback = Kaui::Chargeback.new(:payment_id => payment.payment_id,
|
6
6
|
:amount => payment.paid_amount_to_money.to_f,
|
7
7
|
:currency => payment.currency)
|
@@ -19,7 +19,7 @@ class Kaui::ChargesController < Kaui::EngineController
|
|
19
19
|
charge = Kaui::InvoiceItem.new(params.require(:invoice_item).delete_if { |key, value| value.blank? })
|
20
20
|
charge.account_id ||= params.require(:account_id)
|
21
21
|
|
22
|
-
charge = charge.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
22
|
+
charge = charge.create(true, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
23
23
|
redirect_to kaui_engine.account_invoice_path(charge.account_id, charge.invoice_id), :notice => 'Charge was successfully created'
|
24
24
|
end
|
25
25
|
end
|
@@ -2,7 +2,7 @@ class Kaui::EngineController < ApplicationController
|
|
2
2
|
|
3
3
|
include Kaui::EngineControllerUtil
|
4
4
|
|
5
|
-
before_filter :authenticate_user!, :check_for_redirect_to_tenant_screen
|
5
|
+
before_filter :authenticate_user!, :check_for_redirect_to_tenant_screen, :populate_account_details
|
6
6
|
|
7
7
|
layout :get_layout
|
8
8
|
|
@@ -18,7 +18,6 @@ class Kaui::EngineController < ApplicationController
|
|
18
18
|
super
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
21
|
def current_ability
|
23
22
|
# Redefined here to namespace Ability in the correct module
|
24
23
|
@current_ability ||= Kaui::Ability.new(current_user)
|
@@ -32,6 +31,10 @@ class Kaui::EngineController < ApplicationController
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
34
|
+
def populate_account_details
|
35
|
+
@account ||= params[:account_id].present? ? Kaui::Account.find_by_id(params[:account_id], false, false, options_for_klient) : Kaui::Account.new
|
36
|
+
end
|
37
|
+
|
35
38
|
def retrieve_tenants_for_current_user
|
36
39
|
if Kaui.root_username == current_user.kb_username
|
37
40
|
Kaui::Tenant.all.map(&:kb_tenant_id)
|
@@ -39,7 +39,7 @@ class Kaui::InvoicesController < Kaui::EngineController
|
|
39
39
|
@invoice = Kaui::Invoice.find_by_id_or_number(params.require(:id), true, 'FULL', options_for_klient)
|
40
40
|
|
41
41
|
fetch_payments_and_pms = lambda do
|
42
|
-
@payments = @invoice.payments(true, 'FULL', options_for_klient).map { |payment| Kaui::InvoicePayment.build_from_raw_payment(payment) }
|
42
|
+
@payments = @invoice.payments(true, true, 'FULL', options_for_klient).map { |payment| Kaui::InvoicePayment.build_from_raw_payment(payment) }
|
43
43
|
@payment_methods = Kaui::PaymentMethod.payment_methods_for_payments(@payments, options_for_klient)
|
44
44
|
end
|
45
45
|
fetch_account = lambda { @account = Kaui::Account.find_by_id(@invoice.account_id, false, false, options_for_klient) }
|
@@ -58,7 +58,7 @@ class Kaui::PaymentMethodsController < Kaui::EngineController
|
|
58
58
|
|
59
59
|
payment_method = Kaui::PaymentMethod.find_by_id(payment_method_id, false, options_for_klient)
|
60
60
|
begin
|
61
|
-
Kaui::PaymentMethod.destroy(payment_method_id, params[:set_auto_pay_off], current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
61
|
+
Kaui::PaymentMethod.destroy(payment_method_id, params[:set_auto_pay_off], false, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
62
62
|
redirect_to kaui_engine.account_path(payment_method.account_id), :notice => "Payment method #{payment_method_id} successfully deleted"
|
63
63
|
rescue => e
|
64
64
|
flash[:error] = "Error while deleting payment method #{payment_method_id}: #{as_string(e)}"
|
@@ -65,7 +65,7 @@ class Kaui::PaymentsController < Kaui::EngineController
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def show
|
68
|
-
@payment = Kaui::InvoicePayment.find_by_id(params.require(:id), true, options_for_klient)
|
68
|
+
@payment = Kaui::InvoicePayment.build_from_raw_payment(Kaui::InvoicePayment.find_by_id(params.require(:id), true, true, options_for_klient))
|
69
69
|
|
70
70
|
fetch_account = lambda { @account = Kaui::Account.find_by_id(@payment.account_id, false, false, options_for_klient) }
|
71
71
|
# The payment method may have been deleted
|
@@ -75,10 +75,28 @@ class Kaui::PaymentsController < Kaui::EngineController
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def restful_show
|
78
|
-
|
78
|
+
begin
|
79
|
+
payment = Kaui::InvoicePayment.find_by_id(params.require(:id), false, true, options_for_klient)
|
80
|
+
rescue KillBillClient::API::NotFound
|
81
|
+
payment = Kaui::Payment.find_by_external_key(params.require(:id), false, true, options_for_klient)
|
82
|
+
end
|
79
83
|
redirect_to account_payment_path(payment.account_id, payment.payment_id)
|
80
84
|
end
|
81
85
|
|
86
|
+
def cancel_scheduled_payment
|
87
|
+
begin
|
88
|
+
payment_transaction = Kaui::Transaction.new
|
89
|
+
payment_transaction.transaction_external_key = params.require(:transaction_external_key)
|
90
|
+
|
91
|
+
payment_transaction.cancel_scheduled_payment(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
92
|
+
|
93
|
+
redirect_to kaui_engine.account_payment_path(params.require(:account_id), params.require(:id)), :notice => "Payment attempt retry successfully deleted"
|
94
|
+
rescue => e
|
95
|
+
flash[:error] = "Error deleting payment attempt retry: #{as_string(e)}"
|
96
|
+
redirect_to kaui_engine.account_path(params.require(:account_id))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
82
100
|
private
|
83
101
|
|
84
102
|
def invoice_payment_params
|
@@ -2,7 +2,7 @@ class Kaui::RefundsController < Kaui::EngineController
|
|
2
2
|
|
3
3
|
def new
|
4
4
|
fetch_invoice = lambda { @invoice = Kaui::Invoice.find_by_id_or_number(params.require(:invoice_id), true, 'NONE', options_for_klient) }
|
5
|
-
fetch_payment = lambda { @payment = Kaui::InvoicePayment::find_by_id(params.require(:payment_id), false, options_for_klient) }
|
5
|
+
fetch_payment = lambda { @payment = Kaui::InvoicePayment::find_by_id(params.require(:payment_id), false, false, options_for_klient) }
|
6
6
|
|
7
7
|
run_in_parallel fetch_invoice, fetch_payment
|
8
8
|
|
@@ -30,11 +30,9 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
30
30
|
plan_details = plans_details.find { |p| p.plan == plan_name }
|
31
31
|
raise "Unable to find plan #{plan_name}" if plan_details.nil?
|
32
32
|
|
33
|
-
@subscription.
|
34
|
-
|
35
|
-
@subscription
|
36
|
-
|
37
|
-
@subscription = @subscription.create(current_user.kb_username, params[:reason], params[:comment], params[:requested_date], false, options_for_klient)
|
33
|
+
@subscription.plan_name = plan_name
|
34
|
+
requested_date = params[:type_change] == "DATE" ? params[:requested_date].presence : nil
|
35
|
+
@subscription = @subscription.create(current_user.kb_username, params[:reason], params[:comment], requested_date, false, options_for_klient)
|
38
36
|
redirect_to kaui_engine.account_bundles_path(@subscription.account_id), :notice => 'Subscription was successfully created'
|
39
37
|
rescue => e
|
40
38
|
@plans = plans_details.nil? ? [] : plans_details.map { |p| p.plan }
|
@@ -53,21 +51,18 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
53
51
|
end
|
54
52
|
|
55
53
|
def update
|
54
|
+
|
56
55
|
plan_name = params.require(:plan_name)
|
57
56
|
|
58
|
-
requested_date = params[:requested_date].presence
|
59
|
-
billing_policy = params[:policy].presence
|
57
|
+
requested_date = params[:type_change] == "DATE" ? params[:requested_date].presence : nil
|
58
|
+
billing_policy = params[:type_change] == "POLICY" ? params[:policy].presence : nil
|
59
|
+
|
60
60
|
wait_for_completion = params[:wait_for_completion] == '1'
|
61
61
|
|
62
62
|
subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
|
63
|
-
plans_details = Kaui::Catalog::available_base_plans(options_for_klient)
|
64
|
-
new_plan_details = plans_details.find { |p| p.plan == plan_name }
|
65
|
-
raise "Unable to find plan #{plan_name}" if new_plan_details.nil?
|
66
63
|
|
67
64
|
subscription.change_plan({
|
68
|
-
:
|
69
|
-
:billingPeriod => new_plan_details.final_phase_billing_period,
|
70
|
-
:priceList => new_plan_details.price_list
|
65
|
+
:planName => plan_name
|
71
66
|
},
|
72
67
|
current_user.kb_username,
|
73
68
|
params[:reason],
|
@@ -1,37 +1,53 @@
|
|
1
1
|
module Kaui
|
2
2
|
module SubscriptionHelper
|
3
3
|
|
4
|
-
def
|
4
|
+
def humanized_subscription_product_category(sub)
|
5
5
|
if !sub.present? or !sub.product_category.present?
|
6
6
|
nil
|
7
|
-
|
7
|
+
else
|
8
|
+
humanized_product_category(sub.product_category)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def humanized_product_category(product_category)
|
13
|
+
if product_category == 'BASE'
|
8
14
|
'Base'
|
9
|
-
elsif
|
15
|
+
elsif product_category == 'ADD_ON'
|
10
16
|
'Add-on'
|
11
17
|
else
|
12
|
-
|
18
|
+
product_category.downcase.capitalize
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
16
|
-
def
|
22
|
+
def humanized_subscription_product_name(sub)
|
17
23
|
if !sub.present? or !sub.product_name.present?
|
18
24
|
nil
|
19
25
|
else
|
20
|
-
sub.product_name
|
26
|
+
humanized_product_name(sub.product_name)
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
24
|
-
def
|
30
|
+
def humanized_product_name(product_name)
|
31
|
+
product_name.downcase.capitalize
|
32
|
+
end
|
33
|
+
|
34
|
+
def humanized_subscription_billing_period(sub)
|
25
35
|
if !sub.present? or !sub.billing_period.present?
|
26
36
|
nil
|
27
|
-
|
37
|
+
else
|
38
|
+
humanized_billing_period(sub.billing_period)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def humanized_billing_period(billing_period)
|
43
|
+
if billing_period == 'NO_BILLING_PERIOD'
|
28
44
|
'No billing period'
|
29
45
|
else
|
30
|
-
|
46
|
+
billing_period.downcase.capitalize
|
31
47
|
end
|
32
48
|
end
|
33
49
|
|
34
|
-
def
|
50
|
+
def humanized_subscription_price_list(sub, show_default=true)
|
35
51
|
if !sub.present? or !sub.price_list.present? or (!show_default and sub.price_list.upcase == 'DEFAULT')
|
36
52
|
nil
|
37
53
|
else
|
@@ -39,10 +55,10 @@ module Kaui
|
|
39
55
|
end
|
40
56
|
end
|
41
57
|
|
42
|
-
def
|
43
|
-
humanized_product_name =
|
44
|
-
humanized_billing_period =
|
45
|
-
humanized_price_list =
|
58
|
+
def humanized_subscription_full_product_name(sub)
|
59
|
+
humanized_product_name = humanized_subscription_product_name(sub)
|
60
|
+
humanized_billing_period = humanized_subscription_billing_period(sub)
|
61
|
+
humanized_price_list = humanized_subscription_price_list(sub, false)
|
46
62
|
|
47
63
|
if humanized_billing_period.nil?
|
48
64
|
if humanized_price_list.nil?
|
@@ -59,7 +75,11 @@ module Kaui
|
|
59
75
|
end
|
60
76
|
end
|
61
77
|
|
62
|
-
def
|
78
|
+
def humanized_subscription_phase_type(sub)
|
79
|
+
sub.phase_type
|
80
|
+
end
|
81
|
+
|
82
|
+
def humanized_subscription_start_date(sub, account)
|
63
83
|
if !sub.present? or !sub.start_date.present? or !account.present? or !account.time_zone.present?
|
64
84
|
nil
|
65
85
|
else
|
@@ -67,7 +87,7 @@ module Kaui
|
|
67
87
|
end
|
68
88
|
end
|
69
89
|
|
70
|
-
def
|
90
|
+
def humanized_subscription_charged_through_date(sub, account)
|
71
91
|
if !sub.present? or !sub.charged_through_date.present? or !account.present? or !account.time_zone.present?
|
72
92
|
nil
|
73
93
|
else
|
@@ -75,7 +95,7 @@ module Kaui
|
|
75
95
|
end
|
76
96
|
end
|
77
97
|
|
78
|
-
def
|
98
|
+
def humanized_subscription_cancelled_date(sub, account)
|
79
99
|
if !sub.present? or !sub.cancelled_date.present? or !account.present? or !account.time_zone.present?
|
80
100
|
nil
|
81
101
|
else
|
@@ -88,7 +108,7 @@ module Kaui
|
|
88
108
|
end
|
89
109
|
end
|
90
110
|
|
91
|
-
def
|
111
|
+
def humanized_subscription_billing_start_date(sub, account)
|
92
112
|
if !sub.present? or !sub.billing_start_date.present? or !account.present? or !account.time_zone.present?
|
93
113
|
nil
|
94
114
|
else
|
@@ -96,7 +116,7 @@ module Kaui
|
|
96
116
|
end
|
97
117
|
end
|
98
118
|
|
99
|
-
def
|
119
|
+
def humanized_subscription_billing_end_date(sub, account)
|
100
120
|
if !sub.present? or !sub.billing_end_date.present? or !account.present? or !account.time_zone.present?
|
101
121
|
nil
|
102
122
|
else
|
@@ -104,11 +124,17 @@ module Kaui
|
|
104
124
|
end
|
105
125
|
end
|
106
126
|
|
107
|
-
|
127
|
+
|
128
|
+
def humanized_time_unit(time_unit)
|
129
|
+
time_unit.downcase.capitalize
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
def is_subscription_future_cancelled?(sub)
|
108
134
|
sub.present? and sub.billing_end_date.present? and Time.parse(sub.billing_end_date) > Time.now
|
109
135
|
end
|
110
136
|
|
111
|
-
def
|
137
|
+
def is_subscription_cancelled?(sub)
|
112
138
|
sub.present? and sub.billing_end_date.present?
|
113
139
|
end
|
114
140
|
end
|