kaui 2.0.4 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +8 -23
- data/Rakefile +4 -2
- data/app/assets/config/kaui_manifest.js +45 -0
- data/app/assets/javascripts/jquery.spin.js +76 -0
- data/app/assets/javascripts/kaui/kaui.js +76 -0
- data/app/assets/javascripts/kaui_application.js +25 -0
- data/app/assets/javascripts/spin.js +76 -0
- data/app/assets/stylesheets/bootstrap_and_overrides.scss +240 -0
- data/app/assets/stylesheets/kaui/{account.less → account.scss} +13 -1
- data/app/assets/stylesheets/kaui/{audit.less → audit.scss} +5 -1
- data/app/assets/stylesheets/kaui/{common.less → common.scss} +19 -17
- data/app/assets/stylesheets/kaui/{datatable.less → datatable.scss} +6 -3
- data/app/assets/stylesheets/kaui/{header.less → header.scss} +16 -12
- data/app/assets/stylesheets/kaui/{home.less → home.scss} +7 -4
- data/app/assets/stylesheets/kaui/{invoice.less → invoice.scss} +7 -3
- data/app/assets/stylesheets/kaui/kaui.scss +265 -0
- data/app/assets/stylesheets/kaui/kaui_bootstrap.scss +3 -0
- data/app/assets/stylesheets/kaui/{overdue.less → overdue.scss} +3 -1
- data/app/assets/stylesheets/kaui/{payment.less → payment.scss} +3 -0
- data/app/assets/stylesheets/kaui/{subscription.less → subscription.scss} +4 -1
- data/app/assets/stylesheets/kaui/{tags.less → tags.scss} +9 -5
- data/app/assets/stylesheets/kaui/timeline.scss +7 -0
- data/app/assets/stylesheets/kaui/tooltip.scss +15 -0
- data/app/controllers/kaui/account_children_controller.rb +25 -28
- data/app/controllers/kaui/account_custom_fields_controller.rb +16 -15
- data/app/controllers/kaui/account_emails_controller.rb +28 -25
- data/app/controllers/kaui/account_tags_controller.rb +37 -34
- data/app/controllers/kaui/account_timelines_controller.rb +38 -33
- data/app/controllers/kaui/accounts_controller.rb +269 -255
- data/app/controllers/kaui/admin_allowed_users_controller.rb +105 -99
- data/app/controllers/kaui/admin_controller.rb +32 -31
- data/app/controllers/kaui/admin_tenants_controller.rb +434 -388
- data/app/controllers/kaui/audit_logs_controller.rb +87 -84
- data/app/controllers/kaui/bundle_tags_controller.rb +24 -20
- data/app/controllers/kaui/bundles_controller.rb +96 -82
- data/app/controllers/kaui/chargebacks_controller.rb +36 -33
- data/app/controllers/kaui/charges_controller.rb +23 -20
- data/app/controllers/kaui/credits_controller.rb +28 -25
- data/app/controllers/kaui/custom_fields_controller.rb +172 -38
- data/app/controllers/kaui/engine_controller.rb +2 -1
- data/app/controllers/kaui/engine_controller_util.rb +132 -114
- data/app/controllers/kaui/home_controller.rb +230 -217
- data/app/controllers/kaui/invoice_items_controller.rb +43 -39
- data/app/controllers/kaui/invoice_tags_controller.rb +32 -0
- data/app/controllers/kaui/invoices_controller.rb +134 -88
- data/app/controllers/kaui/login_proxy_controller.rb +2 -1
- data/app/controllers/kaui/payment_methods_controller.rb +103 -90
- data/app/controllers/kaui/payments_controller.rb +95 -92
- data/app/controllers/kaui/queues_controller.rb +47 -14
- data/app/controllers/kaui/refunds_controller.rb +36 -33
- data/app/controllers/kaui/registrations_controller.rb +7 -7
- data/app/controllers/kaui/role_definitions_controller.rb +17 -14
- data/app/controllers/kaui/sessions_controller.rb +7 -4
- data/app/controllers/kaui/subscriptions_controller.rb +197 -187
- data/app/controllers/kaui/tag_definitions_controller.rb +28 -27
- data/app/controllers/kaui/tags_controller.rb +25 -22
- data/app/controllers/kaui/tenants_controller.rb +30 -28
- data/app/controllers/kaui/transactions_controller.rb +43 -38
- data/app/helpers/kaui/account_helper.rb +22 -12
- data/app/helpers/kaui/application_helper.rb +8 -3
- data/app/helpers/kaui/date_helper.rb +4 -3
- data/app/helpers/kaui/home_helper.rb +2 -0
- data/app/helpers/kaui/locale_helper.rb +7 -6
- data/app/helpers/kaui/money_helper.rb +2 -1
- data/app/helpers/kaui/object_helper.rb +11 -10
- data/app/helpers/kaui/payment_helper.rb +7 -6
- data/app/helpers/kaui/payment_method_helper.rb +3 -2
- data/app/helpers/kaui/permissions_helper.rb +9 -9
- data/app/helpers/kaui/plugin_helper.rb +25 -23
- data/app/helpers/kaui/subscription_helper.rb +27 -29
- data/app/helpers/kaui/us_states_helper.rb +7 -6
- data/app/helpers/kaui/uuid_helper.rb +9 -6
- data/app/models/kaui/ability.rb +19 -12
- data/app/models/kaui/account.rb +45 -28
- data/app/models/kaui/account_email.rb +23 -20
- data/app/models/kaui/account_timeline.rb +5 -1
- data/app/models/kaui/admin.rb +65 -64
- data/app/models/kaui/admin_tenant.rb +81 -82
- data/app/models/kaui/allowed_user.rb +13 -9
- data/app/models/kaui/allowed_user_tenant.rb +4 -2
- data/app/models/kaui/application_record.rb +2 -0
- data/app/models/kaui/audit_log.rb +6 -3
- data/app/models/kaui/base.rb +13 -7
- data/app/models/kaui/bundle.rb +41 -24
- data/app/models/kaui/catalog.rb +118 -113
- data/app/models/kaui/chargeback.rb +5 -1
- data/app/models/kaui/credit.rb +4 -1
- data/app/models/kaui/custom_field.rb +9 -6
- data/app/models/kaui/invoice.rb +25 -22
- data/app/models/kaui/invoice_item.rb +9 -6
- data/app/models/kaui/invoice_payment.rb +49 -54
- data/app/models/kaui/killbill_authenticatable.rb +14 -8
- data/app/models/kaui/killbill_registerable.rb +7 -0
- data/app/models/kaui/overdue.rb +64 -65
- data/app/models/kaui/payment.rb +22 -19
- data/app/models/kaui/payment_method.rb +48 -39
- data/app/models/kaui/payment_state.rb +41 -38
- data/app/models/kaui/rails_methods.rb +9 -9
- data/app/models/kaui/refund.rb +7 -1
- data/app/models/kaui/role_definition.rb +5 -1
- data/app/models/kaui/simple_plan.rb +5 -3
- data/app/models/kaui/subscription.rb +10 -7
- data/app/models/kaui/tag.rb +25 -22
- data/app/models/kaui/tag_definition.rb +50 -45
- data/app/models/kaui/tenant.rb +6 -5
- data/app/models/kaui/transaction.rb +43 -31
- data/app/models/kaui/user.rb +10 -16
- data/app/models/kaui/user_role.rb +8 -5
- data/app/views/kaui/accounts/_billing_info.html.erb +5 -1
- data/app/views/kaui/accounts/_form.html.erb +2 -2
- data/app/views/kaui/accounts/_payment_methods.html.erb +3 -0
- data/app/views/kaui/accounts/index.html.erb +9 -4
- data/app/views/kaui/admin_allowed_users/_form.html.erb +3 -3
- data/app/views/kaui/admin_tenants/_form_catalog_translation.erb +1 -1
- data/app/views/kaui/admin_tenants/_form_invoice_template.erb +1 -1
- data/app/views/kaui/admin_tenants/_form_invoice_translation.erb +1 -1
- data/app/views/kaui/admin_tenants/_form_plugin_config.erb +13 -3
- data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +11 -5
- data/app/views/kaui/admin_tenants/new_catalog.html.erb +2 -2
- data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +2 -2
- data/app/views/kaui/admin_tenants/new_plan_currency.html.erb +1 -1
- data/app/views/kaui/bundles/_bundle_details.html.erb +12 -0
- data/app/views/kaui/bundles/index.html.erb +3 -14
- data/app/views/kaui/bundles/transfer.html.erb +13 -5
- data/app/views/kaui/invoice_tags/_form.html.erb +33 -0
- data/app/views/kaui/invoice_tags/_form_bar.html.erb +21 -0
- data/app/views/kaui/invoice_tags/edit.html.erb +10 -0
- data/app/views/kaui/invoices/_invoice_table.html.erb +29 -8
- data/app/views/kaui/invoices/index.html.erb +6 -4
- data/app/views/kaui/invoices/show.html.erb +10 -1
- data/app/views/kaui/layouts/kaui_flash.html.erb +32 -1
- data/app/views/kaui/layouts/kaui_header.html.erb +19 -2
- data/app/views/kaui/payment_methods/_payment_methods_details_table.html.erb +13 -4
- data/app/views/kaui/payments/_payment_table.html.erb +21 -11
- data/app/views/kaui/payments/index.html.erb +12 -10
- data/app/views/kaui/queues/index.html.erb +1 -1
- data/app/views/kaui/subscriptions/_cancel_by_date_modal.html.erb +1 -4
- data/app/views/kaui/subscriptions/_edit_form.html.erb +1 -1
- data/app/views/kaui/subscriptions/_form.html.erb +1 -1
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +3 -3
- data/app/views/kaui/subscriptions/edit_bcd.erb +1 -1
- data/app/views/kaui/tag_definitions/index.html.erb +2 -2
- data/app/views/kaui/tags/index.html.erb +1 -0
- data/config/initializers/bootstrap_datepicker_rails.rb +3 -0
- data/config/initializers/devise.rb +8 -6
- data/config/initializers/js_routes.rb +9 -0
- data/config/initializers/kilbill_client_init.rb +13 -0
- data/config/initializers/killbill_authenticatable.rb +71 -21
- data/config/initializers/killbill_registerable.rb +5 -3
- data/config/initializers/time_formats.rb +6 -4
- data/config/locales/en.yml +78 -1
- data/config/routes.rb +40 -32
- data/db/migrate/20130812155313_devise_create_kaui_users.rb +10 -8
- data/db/migrate/20150109214021_create_kaui_tenants.rb +10 -8
- data/db/migrate/20150112232813_create_kaui_allowed_users.rb +10 -8
- data/lib/generators/kaui/install/install_generator.rb +23 -20
- data/lib/generators/kaui/install/templates/config/initializers/kaui.rb +3 -1
- data/lib/kaui/engine.rb +17 -5
- data/lib/kaui/installer/installer.rb +27 -26
- data/lib/kaui/version.rb +3 -1
- data/lib/kaui.rb +76 -23
- data/lib/tasks/kaui_tasks.rake +1 -0
- metadata +141 -436
- data/app/assets/javascripts/application.js +0 -17
- data/app/assets/javascripts/kaui/bootstrap-tweaks.js +0 -172
- data/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -44
- data/app/assets/stylesheets/kaui/kaui.less +0 -21
- data/app/assets/stylesheets/kaui/timeline.less +0 -4
- data/config/initializers/asset.rb +0 -1
- data/config/initializers/kilbill-client-init.rb +0 -9
- data/db/schema.rb +0 -15
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/controllers/application_controller.rb +0 -9
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/bin/setup +0 -38
- data/test/dummy/bin/update +0 -29
- data/test/dummy/bin/yarn +0 -11
- data/test/dummy/config/application.rb +0 -18
- data/test/dummy/config/boot.rb +0 -3
- data/test/dummy/config/database.yml +0 -27
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -58
- data/test/dummy/config/environments/production.rb +0 -91
- data/test/dummy/config/environments/test.rb +0 -49
- data/test/dummy/config/initializers/application_controller_renderer.rb +0 -6
- data/test/dummy/config/initializers/assets.rb +0 -14
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/killbill_client.rb +0 -1
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/new_framework_defaults_5_1.rb +0 -14
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -33
- data/test/dummy/config/routes.rb +0 -3
- data/test/dummy/config/secrets.yml +0 -32
- data/test/dummy/config/symmetric-encryption.yml +0 -135
- data/test/dummy/config.ru +0 -4
- data/test/dummy/db/schema.rb +0 -52
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/fixtures/SpyCarAdvanced.xml +0 -824
- data/test/fixtures/catalog-v1.xml +0 -73
- data/test/fixtures/catalog_translation_fr-v1.properties +0 -1
- data/test/fixtures/invoice_template-v1.html +0 -100
- data/test/fixtures/invoice_translation_fr-v1.properties +0 -23
- data/test/fixtures/overdue-v1.xml +0 -49
- data/test/fixtures/stripe.yml +0 -2
- data/test/functional/kaui/account_children_controller_test.rb +0 -32
- data/test/functional/kaui/account_custom_fields_controller_test.rb +0 -29
- data/test/functional/kaui/account_emails_controller_test.rb +0 -55
- data/test/functional/kaui/account_tags_controller_test.rb +0 -48
- data/test/functional/kaui/account_timelines_controller_test.rb +0 -20
- data/test/functional/kaui/accounts_controller_test.rb +0 -297
- data/test/functional/kaui/admin_allowed_users_controller_test.rb +0 -234
- data/test/functional/kaui/admin_controller_test.rb +0 -45
- data/test/functional/kaui/admin_tenants_controller_test.rb +0 -352
- data/test/functional/kaui/audit_logs_controller_test.rb +0 -71
- data/test/functional/kaui/bundle_tags_controller_test.rb +0 -23
- data/test/functional/kaui/bundles_controller_test.rb +0 -130
- data/test/functional/kaui/chargebacks_controller_test.rb +0 -42
- data/test/functional/kaui/charges_controller_test.rb +0 -60
- data/test/functional/kaui/credits_controller_test.rb +0 -54
- data/test/functional/kaui/custom_fields_controller_test.rb +0 -52
- data/test/functional/kaui/functional_test_helper.rb +0 -13
- data/test/functional/kaui/functional_test_helper_nosetup.rb +0 -120
- data/test/functional/kaui/home_controller_test.rb +0 -407
- data/test/functional/kaui/invoice_items_controller_test.rb +0 -82
- data/test/functional/kaui/invoices_controller_test.rb +0 -88
- data/test/functional/kaui/login_proxy_controller_test.rb +0 -12
- data/test/functional/kaui/payment_methods_controller_test.rb +0 -52
- data/test/functional/kaui/payments_controller_test.rb +0 -59
- data/test/functional/kaui/queues_controller_test.rb +0 -17
- data/test/functional/kaui/refunds_controller_test.rb +0 -63
- data/test/functional/kaui/registrations_controller_test.rb +0 -49
- data/test/functional/kaui/role_definitions_controller_test.rb +0 -47
- data/test/functional/kaui/subscriptions_controller_test.rb +0 -194
- data/test/functional/kaui/tag_definitions_controller_test.rb +0 -29
- data/test/functional/kaui/tags_controller_test.rb +0 -21
- data/test/functional/kaui/tenants_controller_test.rb +0 -60
- data/test/functional/kaui/transactions_controller_test.rb +0 -90
- data/test/integration/kaui/date_helper_integration_test.rb +0 -16
- data/test/integration/kaui/integration_test_helper.rb +0 -32
- data/test/integration/kaui/navigation_test.rb +0 -43
- data/test/killbill_test_helper.rb +0 -217
- data/test/test_helper.rb +0 -22
- data/test/unit/helpers/kaui/admin_allowed_users_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/admin_tenants_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/payment_method_helper_test.rb +0 -17
- data/test/unit/helpers/kaui/tenants_helper_test.rb +0 -6
- data/test/unit/helpers/kaui/uuid_helper_test.rb +0 -16
- data/test/unit/kaui/account_email_test.rb +0 -19
- data/test/unit/kaui/account_test.rb +0 -14
- data/test/unit/kaui/admin_tenant_test.rb +0 -132
- data/test/unit/kaui/allowed_user_test.rb +0 -34
- data/test/unit/kaui/base_test.rb +0 -23
- data/test/unit/kaui/date_helper_test.rb +0 -26
- data/test/unit/kaui/invoice_item_test.rb +0 -11
- data/test/unit/kaui/invoice_payment_test.rb +0 -42
- data/test/unit/kaui/invoice_test.rb +0 -20
- data/test/unit/kaui/money_helper_test.rb +0 -16
- data/test/unit/kaui/payment_test.rb +0 -42
- data/test/unit/kaui/tag_definition_test.rb +0 -11
- data/test/unit/kaui/tenant_test.rb +0 -19
- /data/app/assets/stylesheets/{application.css → kaui_application.css} +0 -0
@@ -1,233 +1,244 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Kaui
|
4
|
+
class SubscriptionsController < Kaui::EngineController
|
5
|
+
def new
|
6
|
+
@base_product_name = params[:base_product_name]
|
7
|
+
@subscription = Kaui::Subscription.new(bundle_id: params[:bundle_id],
|
8
|
+
account_id: params[:account_id],
|
9
|
+
product_category: params[:product_category] || 'BASE')
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
@bundle, plans_details = lookup_bundle_and_plan_details(@subscription, @base_product_name)
|
12
|
+
@plans = plans_details.map(&:plan)
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
return unless @plans.empty?
|
15
|
+
|
16
|
+
flash[:error] = if @subscription.product_category == 'BASE'
|
17
|
+
'No plan available in the catalog'
|
18
|
+
else
|
19
|
+
"No add-on available in the catalog for product #{@base_product_name}"
|
20
|
+
end
|
21
|
+
redirect_to kaui_engine.account_bundles_path(@subscription.account_id), error: 'No available plan'
|
19
22
|
end
|
20
|
-
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def create
|
25
|
+
plan_name = params.require(:plan_name)
|
26
|
+
@base_product_name = params[:base_product_name]
|
27
|
+
@subscription = Kaui::Subscription.new(params.require(:subscription).delete_if { |_key, value| value.blank? })
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
+
begin
|
30
|
+
@bundle, plans_details = lookup_bundle_and_plan_details(@subscription, @base_product_name)
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
plan_details = plans_details.find { |p| p.plan == plan_name }
|
33
|
+
raise "Unable to find plan #{plan_name}" if plan_details.nil?
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
+
@subscription.plan_name = plan_name
|
36
|
+
requested_date = params[:type_change] == 'DATE' ? params[:requested_date].presence : nil
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
38
|
+
# price override?
|
39
|
+
override_fixed_price = begin
|
40
|
+
plan_details.phases.first.prices.blank?
|
41
|
+
rescue StandardError
|
42
|
+
false
|
43
|
+
end
|
44
|
+
override_recurring_price = !override_fixed_price
|
45
|
+
phase_type = @bundle.nil? ? plan_details.phases.first.type : @bundle.subscriptions.first.phase_type
|
46
|
+
overrides = price_overrides(phase_type, override_fixed_price, override_recurring_price)
|
47
|
+
@subscription.price_overrides = overrides unless overrides.blank?
|
48
|
+
|
49
|
+
# un-set product_category since is not needed if plan name exist
|
50
|
+
@subscription.product_category = nil
|
51
|
+
@subscription = @subscription.create(current_user.kb_username, params[:reason], params[:comment], requested_date, false, options_for_klient)
|
52
|
+
redirect_to kaui_engine.account_bundles_path(@subscription.account_id), notice: 'Subscription was successfully created'
|
53
|
+
rescue StandardError => e
|
54
|
+
@plans = plans_details.nil? ? [] : plans_details.map(&:plan)
|
55
|
+
|
56
|
+
if e.is_a?(::KillBillClient::API::BadRequest) && !e.response.nil? && !e.response.body.nil?
|
57
|
+
error_message = begin
|
58
|
+
JSON.parse(e.response.body)
|
59
|
+
rescue StandardError
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
if (!error_message.nil? & !error_message['code'].nil?) && error_message['code'] == 2010 # CAT_NO_PRICE_FOR_CURRENCY
|
63
|
+
# Hack for lack of proper Kill Bill messaging (https://github.com/killbill/killbill-admin-ui/issues/266)
|
64
|
+
flash.now[:error] = "Unable to create the subscription: a price for this currency hasn't been specified in the catalog"
|
65
|
+
render :new and return
|
66
|
+
end
|
56
67
|
end
|
57
|
-
end
|
58
68
|
|
59
|
-
|
60
|
-
|
69
|
+
flash.now[:error] = "Error while creating the subscription: #{as_string(e)}"
|
70
|
+
render :new
|
71
|
+
end
|
61
72
|
end
|
62
|
-
end
|
63
73
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
def update
|
72
|
-
plan_name = params.require(:plan_name)
|
73
|
-
|
74
|
-
requested_date = params[:type_change] == "DATE" ? params[:requested_date].presence : nil
|
75
|
-
billing_policy = params[:type_change] == "POLICY" ? params[:policy].presence : nil
|
76
|
-
|
77
|
-
wait_for_completion = params[:wait_for_completion] == '1'
|
78
|
-
|
79
|
-
subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
|
80
|
-
|
81
|
-
input = { :planName => plan_name }
|
74
|
+
def edit
|
75
|
+
@subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
|
76
|
+
_, plans_details = lookup_bundle_and_plan_details(@subscription)
|
77
|
+
# Use a Set to deal with multiple pricelists
|
78
|
+
@plans = Set.new.merge(plans_details.map(&:plan))
|
79
|
+
end
|
82
80
|
|
83
|
-
|
84
|
-
|
85
|
-
override_fixed_price = current_plan.last['recurringPrice'].nil?
|
86
|
-
override_recurring_price = !override_fixed_price
|
87
|
-
overrides = price_overrides(subscription.phase_type, override_fixed_price, override_recurring_price)
|
88
|
-
input[:priceOverrides] = overrides unless overrides.blank?
|
81
|
+
def update
|
82
|
+
plan_name = params.require(:plan_name)
|
89
83
|
|
90
|
-
|
91
|
-
|
92
|
-
params[:reason],
|
93
|
-
params[:comment],
|
94
|
-
requested_date,
|
95
|
-
billing_policy,
|
96
|
-
nil,
|
97
|
-
wait_for_completion,
|
98
|
-
options_for_klient)
|
84
|
+
requested_date = params[:type_change] == 'DATE' ? params[:requested_date].presence : nil
|
85
|
+
billing_policy = params[:type_change] == 'POLICY' ? params[:policy].presence : nil
|
99
86
|
|
100
|
-
|
101
|
-
rescue => e
|
102
|
-
redirect_to edit_subscription_path(params.require(:id)), :flash => { :error => "Error while changing subscription: #{as_string(e)}" }
|
103
|
-
end
|
87
|
+
wait_for_completion = params[:wait_for_completion] == '1'
|
104
88
|
|
105
|
-
|
106
|
-
requested_date = params[:requested_date].presence
|
107
|
-
billing_policy = params[:policy].presence
|
108
|
-
# START_OF_TERM is *not* a valid entitlement_policy and so would default to IMMEDIATE
|
109
|
-
entitlement_policy = billing_policy && billing_policy == 'START_OF_TERM' ? 'IMMEDIATE' : billing_policy
|
89
|
+
subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
|
110
90
|
|
111
|
-
|
112
|
-
use_requested_date_for_billing = (params[:use_requested_date_for_billing] || '1') == '1'
|
91
|
+
input = { planName: plan_name }
|
113
92
|
|
114
|
-
|
93
|
+
# price override?
|
94
|
+
current_plan = subscription.prices.select { |price| price['phaseType'] == subscription.phase_type }
|
95
|
+
override_fixed_price = current_plan.last['recurringPrice'].nil?
|
96
|
+
override_recurring_price = !override_fixed_price
|
97
|
+
overrides = price_overrides(subscription.phase_type, override_fixed_price, override_recurring_price)
|
98
|
+
input[:priceOverrides] = overrides unless overrides.blank?
|
99
|
+
|
100
|
+
subscription.change_plan(input,
|
101
|
+
current_user.kb_username,
|
102
|
+
params[:reason],
|
103
|
+
params[:comment],
|
104
|
+
requested_date,
|
105
|
+
billing_policy,
|
106
|
+
nil,
|
107
|
+
wait_for_completion,
|
108
|
+
options_for_klient)
|
109
|
+
|
110
|
+
redirect_to kaui_engine.account_bundles_path(subscription.account_id), notice: 'Subscription plan successfully changed'
|
111
|
+
rescue StandardError => e
|
112
|
+
redirect_to edit_subscription_path(params.require(:id)), flash: { error: "Error while changing subscription: #{as_string(e)}" }
|
113
|
+
end
|
115
114
|
|
116
|
-
|
115
|
+
def destroy
|
116
|
+
requested_date = params[:requested_date].presence
|
117
|
+
billing_policy = params[:policy].presence
|
118
|
+
# START_OF_TERM is *not* a valid entitlement_policy and so would default to IMMEDIATE
|
119
|
+
entitlement_policy = billing_policy && billing_policy == 'START_OF_TERM' ? 'IMMEDIATE' : billing_policy
|
120
|
+
|
121
|
+
# true by default except default policy
|
122
|
+
use_requested_date_for_billing = if requested_date
|
123
|
+
(params[:use_requested_date_for_billing] || '1') == '1'
|
124
|
+
else
|
125
|
+
nil
|
126
|
+
end
|
127
|
+
subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
|
128
|
+
subscription.cancel(current_user.kb_username, params[:reason], params[:comment], requested_date, entitlement_policy, billing_policy, use_requested_date_for_billing, options_for_klient)
|
129
|
+
redirect_to kaui_engine.account_bundles_path(subscription.account_id), notice: 'Subscription was successfully cancelled'
|
130
|
+
end
|
117
131
|
|
118
|
-
|
119
|
-
|
132
|
+
def reinstate
|
133
|
+
subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
|
120
134
|
|
121
|
-
|
122
|
-
subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
|
135
|
+
subscription.uncancel(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
123
136
|
|
124
|
-
|
137
|
+
redirect_to kaui_engine.account_bundles_path(subscription.account_id), notice: 'Subscription was successfully reinstated'
|
138
|
+
end
|
125
139
|
|
126
|
-
|
127
|
-
|
140
|
+
def edit_bcd
|
141
|
+
@subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
|
142
|
+
end
|
128
143
|
|
129
|
-
|
130
|
-
|
131
|
-
|
144
|
+
def update_bcd
|
145
|
+
input_subscription = params.require(:subscription)
|
146
|
+
subscription = Kaui::Subscription.new
|
147
|
+
subscription.subscription_id = params.require(:id)
|
148
|
+
subscription.bill_cycle_day_local = input_subscription['bill_cycle_day_local']
|
132
149
|
|
133
|
-
|
134
|
-
input_subscription = params.require(:subscription)
|
135
|
-
subscription = Kaui::Subscription.new
|
136
|
-
subscription.subscription_id = params.require(:id)
|
137
|
-
subscription.bill_cycle_day_local = input_subscription["bill_cycle_day_local"]
|
150
|
+
effective_from_date = params['effective_from_date']
|
138
151
|
|
139
|
-
|
152
|
+
subscription.update_bcd(current_user.kb_username, params[:reason], params[:comment], effective_from_date, nil, options_for_klient)
|
153
|
+
redirect_to kaui_engine.account_bundles_path(input_subscription['account_id']), notice: 'Subscription BCD was successfully changed'
|
154
|
+
end
|
140
155
|
|
141
|
-
|
142
|
-
|
143
|
-
|
156
|
+
def show
|
157
|
+
restful_show
|
158
|
+
end
|
144
159
|
|
145
|
-
|
146
|
-
|
147
|
-
|
160
|
+
def restful_show
|
161
|
+
subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
|
162
|
+
redirect_to kaui_engine.account_bundles_path(subscription.account_id)
|
163
|
+
end
|
148
164
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
165
|
+
def validate_bundle_external_key
|
166
|
+
json_response do
|
167
|
+
external_key = params.require(:external_key)
|
153
168
|
|
154
|
-
|
155
|
-
|
156
|
-
|
169
|
+
begin
|
170
|
+
bundle = Kaui::Bundle.find_by_external_key(external_key, false, options_for_klient)
|
171
|
+
rescue KillBillClient::API::NotFound
|
172
|
+
bundle = nil
|
173
|
+
end
|
157
174
|
|
158
|
-
|
159
|
-
bundle = Kaui::Bundle.find_by_external_key(external_key, false, options_for_klient)
|
160
|
-
rescue KillBillClient::API::NotFound
|
161
|
-
bundle = nil
|
175
|
+
{ is_found: !bundle.nil? }
|
162
176
|
end
|
163
|
-
|
164
|
-
{ :is_found => !bundle.nil? }
|
165
177
|
end
|
166
|
-
end
|
167
178
|
|
179
|
+
def validate_external_key
|
180
|
+
json_response do
|
181
|
+
external_key = params.require(:external_key)
|
168
182
|
|
169
|
-
|
170
|
-
|
171
|
-
|
183
|
+
begin
|
184
|
+
subscription = Kaui::Subscription.find_by_external_key(external_key, options_for_klient)
|
185
|
+
rescue KillBillClient::API::NotFound
|
186
|
+
subscription = nil
|
187
|
+
end
|
172
188
|
|
173
|
-
|
174
|
-
subscription = Kaui::Subscription.find_by_external_key(external_key, options_for_klient)
|
175
|
-
rescue KillBillClient::API::NotFound
|
176
|
-
subscription = nil
|
189
|
+
{ is_found: !subscription.nil? }
|
177
190
|
end
|
178
|
-
|
179
|
-
{ :is_found => !subscription.nil? }
|
180
191
|
end
|
181
|
-
end
|
182
192
|
|
183
|
-
|
184
|
-
|
185
|
-
|
193
|
+
def update_tags
|
194
|
+
subscription_id = params.require(:id)
|
195
|
+
subscription = Kaui::Subscription.find_by_id(subscription_id, options_for_klient)
|
186
196
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
tags << tag_info[1]
|
192
|
-
end
|
197
|
+
tags = []
|
198
|
+
params.each do |tag|
|
199
|
+
tag_info = tag.split('_')
|
200
|
+
next if (tag_info.size != 2) || (tag_info[0] != 'tag')
|
193
201
|
|
194
|
-
|
195
|
-
|
196
|
-
end
|
202
|
+
tags << tag_info[1]
|
203
|
+
end
|
197
204
|
|
198
|
-
|
205
|
+
Kaui::Tag.set_for_subscription(subscription_id, tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
206
|
+
redirect_to kaui_engine.account_bundles_path(subscription.account_id), notice: 'Subscription tags successfully set'
|
207
|
+
end
|
199
208
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
if
|
204
|
-
bundle.
|
205
|
-
|
206
|
-
|
207
|
-
|
209
|
+
private
|
210
|
+
|
211
|
+
def lookup_bundle_and_plan_details(subscription, base_product_name = nil)
|
212
|
+
if subscription.product_category == 'ADD_ON'
|
213
|
+
bundle = Kaui::Bundle.find_by_id(@subscription.bundle_id, options_for_klient)
|
214
|
+
if base_product_name.blank?
|
215
|
+
bundle.subscriptions.each do |sub|
|
216
|
+
if sub.product_category == 'BASE'
|
217
|
+
base_product_name = sub.product_name
|
218
|
+
break
|
219
|
+
end
|
208
220
|
end
|
209
221
|
end
|
222
|
+
plans_details = Kaui::Catalog.available_addons(base_product_name, subscription.account_id, options_for_klient)
|
223
|
+
else
|
224
|
+
bundle = nil
|
225
|
+
plans_details = catalog_plans(subscription.product_category == 'BASE' ? nil : subscription.product_category)
|
210
226
|
end
|
211
|
-
|
212
|
-
else
|
213
|
-
bundle = nil
|
214
|
-
plans_details = catalog_plans(subscription.product_category == 'BASE' ? nil : subscription.product_category)
|
227
|
+
[bundle, plans_details]
|
215
228
|
end
|
216
|
-
[bundle, plans_details]
|
217
|
-
end
|
218
229
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
else
|
230
|
+
def catalog_plans(product_category = nil)
|
231
|
+
return Kaui::Catalog.available_base_plans(@subscription.account_id, options_for_klient) if product_category == 'BASE'
|
232
|
+
|
223
233
|
options = options_for_klient
|
224
234
|
|
225
|
-
catalog = Kaui::Catalog.get_tenant_catalog_json(DateTime.now.to_s, options)
|
235
|
+
catalog = Kaui::Catalog.get_tenant_catalog_json(DateTime.now.to_s, @subscription.account_id, options)
|
226
236
|
return [] if catalog.blank?
|
227
237
|
|
228
238
|
plans = []
|
229
239
|
catalog[catalog.size - 1].products.each do |product|
|
230
240
|
next if product.type == 'ADD_ON' || (!product_category.nil? && product.type != product_category)
|
241
|
+
|
231
242
|
product.plans.each do |plan|
|
232
243
|
class << plan
|
233
244
|
attr_accessor :plan
|
@@ -238,23 +249,22 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
238
249
|
end
|
239
250
|
end
|
240
251
|
|
241
|
-
|
242
|
-
|
252
|
+
plans
|
243
253
|
end
|
244
|
-
end
|
245
254
|
|
246
|
-
|
247
|
-
|
255
|
+
def price_overrides(phase_type, override_fixed_price, override_recurring_price)
|
256
|
+
return nil if params[:price_override].blank? || params[:price_override].to_i.negative?
|
248
257
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
258
|
+
price_override = params[:price_override]
|
259
|
+
overrides = []
|
260
|
+
override = KillBillClient::Model::PhasePriceAttributes.new
|
261
|
+
override.phase_type = phase_type
|
262
|
+
override.fixed_price = price_override if override_fixed_price
|
263
|
+
override.recurring_price = price_override if override_recurring_price
|
255
264
|
|
256
|
-
|
265
|
+
overrides << override
|
257
266
|
|
258
|
-
|
267
|
+
overrides
|
268
|
+
end
|
259
269
|
end
|
260
270
|
end
|
@@ -1,40 +1,41 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Kaui
|
4
|
+
class TagDefinitionsController < Kaui::EngineController
|
5
|
+
def index
|
5
6
|
@tag_definitions = Kaui::TagDefinition.all('NONE', options_for_klient)
|
6
|
-
rescue => e
|
7
|
+
rescue StandardError => e
|
7
8
|
flash.now[:error] = "Error while retrieving tag definitions: #{as_string(e)}"
|
8
|
-
@tag_definitions
|
9
|
+
@tag_definitions = []
|
9
10
|
end
|
10
|
-
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def new
|
13
|
+
@tag_definition = Kaui::TagDefinition.new
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def create
|
17
|
+
params[:tag_definition][:applicable_object_types] = params[:tag_definition][:applicable_object_types].values unless params[:tag_definition][:applicable_object_types].blank?
|
18
|
+
@tag_definition = Kaui::TagDefinition.new(params[:tag_definition])
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
begin
|
21
|
+
@tag_definition = @tag_definition.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
22
|
+
redirect_to kaui_engine.tag_definitions_path, notice: 'Tag definition successfully created'
|
23
|
+
rescue StandardError => e
|
24
|
+
flash.now[:error] = "Error while creating tag definition: #{as_string(e)}"
|
25
|
+
render action: :new
|
26
|
+
end
|
26
27
|
end
|
27
|
-
end
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
def destroy
|
30
|
+
@tag_definition = Kaui::TagDefinition.find_by_id(params[:id], 'NONE', options_for_klient)
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
begin
|
33
|
+
@tag_definition.delete(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
34
|
+
redirect_to kaui_engine.tag_definitions_path, notice: 'Tag definition successfully deleted'
|
35
|
+
rescue StandardError => e
|
36
|
+
flash.now[:error] = "Error while deleting tag definition: #{as_string(e)}"
|
37
|
+
render action: :index
|
38
|
+
end
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
@@ -1,39 +1,42 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Kaui
|
4
|
+
class TagsController < Kaui::EngineController
|
5
|
+
def index
|
6
|
+
@search_query = params[:q]
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
@ordering = params[:ordering] || (@search_query.blank? ? 'desc' : 'asc')
|
9
|
+
@offset = params[:offset] || 0
|
10
|
+
@limit = params[:limit] || 50
|
9
11
|
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def pagination
|
14
|
-
searcher = lambda do |search_key, offset, limit|
|
15
|
-
Kaui::Tag.list_or_search(search_key, offset, limit, options_for_klient)
|
12
|
+
@max_nb_records = @search_query.blank? ? Kaui::Tag.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records : 0
|
16
13
|
end
|
17
14
|
|
18
|
-
|
19
|
-
|
15
|
+
def pagination
|
16
|
+
searcher = lambda do |search_key, offset, limit|
|
17
|
+
Kaui::Tag.list_or_search(search_key, offset, limit, options_for_klient)
|
18
|
+
end
|
19
|
+
|
20
|
+
data_extractor = lambda do |tag, column|
|
21
|
+
[
|
20
22
|
tag.tag_id,
|
21
23
|
tag.object_id,
|
22
24
|
tag.object_type,
|
23
25
|
tag.tag_definition_name
|
24
|
-
|
25
|
-
|
26
|
+
][column]
|
27
|
+
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
formatter = lambda do |tag|
|
30
|
+
url_for_object = view_context.url_for_object(tag.object_id, tag.object_type)
|
31
|
+
[
|
30
32
|
tag.tag_id,
|
31
33
|
url_for_object ? view_context.link_to(tag.object_id, url_for_object) : tag.object_id,
|
32
34
|
tag.object_type,
|
33
35
|
tag.tag_definition_name
|
34
|
-
|
35
|
-
|
36
|
+
]
|
37
|
+
end
|
36
38
|
|
37
|
-
|
39
|
+
paginate searcher, data_extractor, formatter
|
40
|
+
end
|
38
41
|
end
|
39
42
|
end
|