kaui 4.0.11 → 4.0.13
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/app/assets/javascripts/kaui/kaui_override.js +21 -0
- data/app/assets/stylesheets/kaui/subscription.css +75 -0
- data/app/assets/stylesheets/kaui/tags.css +6 -3
- data/app/controllers/kaui/account_timelines_controller.rb +3 -3
- data/app/controllers/kaui/accounts_controller.rb +52 -52
- data/app/controllers/kaui/admin_allowed_users_controller.rb +29 -29
- data/app/controllers/kaui/admin_controller.rb +2 -2
- data/app/controllers/kaui/admin_tenants_controller.rb +89 -81
- data/app/controllers/kaui/audit_logs_controller.rb +1 -1
- data/app/controllers/kaui/bundles_controller.rb +53 -5
- data/app/controllers/kaui/chargebacks_controller.rb +1 -1
- data/app/controllers/kaui/charges_controller.rb +5 -2
- data/app/controllers/kaui/credits_controller.rb +1 -1
- data/app/controllers/kaui/custom_fields_controller.rb +11 -11
- data/app/controllers/kaui/engine_controller_util.rb +5 -5
- data/app/controllers/kaui/home_controller.rb +6 -2
- data/app/controllers/kaui/invoices_controller.rb +6 -4
- data/app/controllers/kaui/payment_methods_controller.rb +5 -5
- data/app/controllers/kaui/payments_controller.rb +19 -19
- data/app/controllers/kaui/queues_controller.rb +6 -6
- data/app/controllers/kaui/registrations_controller.rb +1 -1
- data/app/controllers/kaui/role_definitions_controller.rb +2 -2
- data/app/controllers/kaui/sessions_controller.rb +1 -1
- data/app/controllers/kaui/subscriptions_controller.rb +15 -14
- data/app/controllers/kaui/tag_definitions_controller.rb +1 -1
- data/app/controllers/kaui/tenants_controller.rb +2 -2
- data/app/controllers/kaui/transactions_controller.rb +6 -6
- data/app/helpers/kaui/account_helper.rb +9 -7
- data/app/helpers/kaui/exception_helper.rb +7 -5
- data/app/helpers/kaui/payment_helper.rb +2 -9
- data/app/helpers/kaui/plugin_helper.rb +3 -5
- data/app/helpers/kaui/subscription_helper.rb +46 -30
- data/app/helpers/kaui/uuid_helper.rb +1 -1
- data/app/models/kaui/account.rb +4 -3
- data/app/models/kaui/admin_tenant.rb +2 -2
- data/app/models/kaui/allowed_user.rb +3 -1
- data/app/models/kaui/allowed_user_tenant.rb +2 -2
- data/app/models/kaui/audit_log.rb +1 -1
- data/app/models/kaui/bundle.rb +11 -5
- data/app/models/kaui/invoice.rb +1 -1
- data/app/models/kaui/invoice_payment.rb +2 -2
- data/app/models/kaui/killbill_authenticatable.rb +2 -39
- data/app/models/kaui/killbill_registerable.rb +3 -11
- data/app/models/kaui/overdue.rb +5 -2
- data/app/models/kaui/payment.rb +1 -1
- data/app/models/kaui/payment_state.rb +3 -1
- data/app/models/kaui/rails_methods.rb +2 -2
- data/app/models/kaui/tag_definition.rb +2 -2
- data/app/models/kaui/tenant.rb +2 -1
- data/app/models/kaui/transaction.rb +1 -1
- data/app/services/dependencies/kenui.rb +1 -1
- data/app/views/kaui/accounts/_account_details.html.erb +1 -1
- data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +25 -1
- data/app/views/kaui/bundles/_bundle_filterbar.html.erb +119 -0
- data/app/views/kaui/bundles/index.html.erb +28 -3
- data/app/views/kaui/components/search_input/_search_input.html.erb +39 -1
- data/app/views/kaui/invoices/index.html.erb +15 -11
- data/app/views/kaui/refunds/_form.html.erb +3 -11
- data/app/views/kaui/subscriptions/_form.html.erb +7 -1
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +12 -1
- data/config/routes.rb +79 -79
- data/lib/devise/models/killbill_authenticatable.rb +38 -0
- data/lib/devise/models/killbill_registerable.rb +9 -0
- data/lib/generators/kaui/install/install_generator.rb +1 -4
- data/lib/kaui/version.rb +1 -1
- data/lib/kaui.rb +7 -7
- metadata +5 -2
|
@@ -23,7 +23,7 @@ module Kaui
|
|
|
23
23
|
query_string = params[:search]
|
|
24
24
|
|
|
25
25
|
if all_fields_checked
|
|
26
|
-
columns = KillBillClient::Model::PaymentAttributes.instance_variable_get(
|
|
26
|
+
columns = KillBillClient::Model::PaymentAttributes.instance_variable_get(:@json_attributes) - %w[transactions audit_logs]
|
|
27
27
|
columns += %w[payment_date status] # additional fields not part of the model
|
|
28
28
|
csv_headers = columns.dup
|
|
29
29
|
Kaui::Payment::REMAPPING_FIELDS.each do |k, v|
|
|
@@ -86,7 +86,7 @@ module Kaui
|
|
|
86
86
|
csv << data
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
|
-
send_data csv_string, filename: "payments-#{
|
|
89
|
+
send_data csv_string, filename: "payments-#{Time.zone.today}.csv", type: 'text/csv'
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
def pagination
|
|
@@ -140,6 +140,23 @@ module Kaui
|
|
|
140
140
|
paginate searcher, data_extractor, formatter
|
|
141
141
|
end
|
|
142
142
|
|
|
143
|
+
def show
|
|
144
|
+
cached_options_for_klient = options_for_klient
|
|
145
|
+
|
|
146
|
+
invoice_payment = Kaui::InvoicePayment.find_safely_by_id(params.require(:id), cached_options_for_klient)
|
|
147
|
+
@payment = Kaui::InvoicePayment.build_from_raw_payment(invoice_payment)
|
|
148
|
+
|
|
149
|
+
fetch_payment_fields = promise do
|
|
150
|
+
direct_payment = Kaui::Payment.new(payment_id: @payment.payment_id)
|
|
151
|
+
direct_payment.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase }
|
|
152
|
+
end
|
|
153
|
+
# The payment method may have been deleted
|
|
154
|
+
fetch_payment_method = promise { Kaui::PaymentMethod.find_safely_by_id(@payment.payment_method_id, cached_options_for_klient) }
|
|
155
|
+
|
|
156
|
+
@custom_fields = wait(fetch_payment_fields)
|
|
157
|
+
@payment_method = wait(fetch_payment_method)
|
|
158
|
+
end
|
|
159
|
+
|
|
143
160
|
def new
|
|
144
161
|
cached_options_for_klient = options_for_klient
|
|
145
162
|
fetch_invoice = promise { Kaui::Invoice.find_by_id(params.require(:invoice_id), false, 'NONE', cached_options_for_klient) }
|
|
@@ -159,23 +176,6 @@ module Kaui
|
|
|
159
176
|
redirect_to kaui_engine.account_invoice_path(payment.account_id, payment.target_invoice_id), notice: 'Payment triggered'
|
|
160
177
|
end
|
|
161
178
|
|
|
162
|
-
def show
|
|
163
|
-
cached_options_for_klient = options_for_klient
|
|
164
|
-
|
|
165
|
-
invoice_payment = Kaui::InvoicePayment.find_safely_by_id(params.require(:id), cached_options_for_klient)
|
|
166
|
-
@payment = Kaui::InvoicePayment.build_from_raw_payment(invoice_payment)
|
|
167
|
-
|
|
168
|
-
fetch_payment_fields = promise do
|
|
169
|
-
direct_payment = Kaui::Payment.new(payment_id: @payment.payment_id)
|
|
170
|
-
direct_payment.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase }
|
|
171
|
-
end
|
|
172
|
-
# The payment method may have been deleted
|
|
173
|
-
fetch_payment_method = promise { Kaui::PaymentMethod.find_safely_by_id(@payment.payment_method_id, cached_options_for_klient) }
|
|
174
|
-
|
|
175
|
-
@custom_fields = wait(fetch_payment_fields)
|
|
176
|
-
@payment_method = wait(fetch_payment_method)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
179
|
def restful_show
|
|
180
180
|
begin
|
|
181
181
|
payment = Kaui::InvoicePayment.find_by_id(params.require(:id), false, true, options_for_klient)
|
|
@@ -6,25 +6,25 @@ module Kaui
|
|
|
6
6
|
def index
|
|
7
7
|
@account_id = params[:account_id]
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
if params[:max_date].present?
|
|
10
10
|
begin
|
|
11
11
|
max_date_test = Time.parse(params[:max_date]).iso8601
|
|
12
12
|
rescue StandardError
|
|
13
13
|
ensure
|
|
14
14
|
if max_date_test.nil?
|
|
15
|
-
flash[:error] = I18n.
|
|
15
|
+
flash[:error] = I18n.t('errors.messages.invalid_max_date')
|
|
16
16
|
redirect_to account_queues_path(@account.account_id) and return
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
if params[:min_date].present?
|
|
22
22
|
begin
|
|
23
23
|
min_date_test = Time.parse(params[:min_date]).iso8601
|
|
24
24
|
rescue StandardError
|
|
25
25
|
ensure
|
|
26
26
|
if min_date_test.nil?
|
|
27
|
-
flash[:error] = I18n.
|
|
27
|
+
flash[:error] = I18n.t('errors.messages.invalid_min_date')
|
|
28
28
|
redirect_to account_queues_path(@account.account_id) and return
|
|
29
29
|
end
|
|
30
30
|
end
|
|
@@ -37,8 +37,8 @@ module Kaui
|
|
|
37
37
|
@now = DateTime.now.in_time_zone('UTC')
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
min_date = (Time.parse(params[:min_date]).iso8601
|
|
41
|
-
max_date = (Time.parse(params[:max_date]).iso8601
|
|
40
|
+
min_date = (Time.parse(params[:min_date]).iso8601 if params[:min_date].present?) || '1970-01-01'
|
|
41
|
+
max_date = (Time.parse(params[:max_date]).iso8601 if params[:max_date].present?) || Time.now.iso8601
|
|
42
42
|
|
|
43
43
|
with_history = params[:with_history] || false
|
|
44
44
|
@queues_entries = Kaui::Admin.get_queues_entries(@account_id,
|
|
@@ -16,7 +16,7 @@ module Kaui
|
|
|
16
16
|
|
|
17
17
|
@user = Kaui::AllowedUser.new(kb_username: sign_up_params.require(:kb_username))
|
|
18
18
|
|
|
19
|
-
if Kaui::AllowedUser.
|
|
19
|
+
if Kaui::AllowedUser.find_by(kb_username: @user.kb_username).present?
|
|
20
20
|
flash.now[:error] = "User with name #{@user.kb_username} already exists!"
|
|
21
21
|
render :new and return
|
|
22
22
|
end
|
|
@@ -6,7 +6,7 @@ module Kaui
|
|
|
6
6
|
@role_definition = Kaui::RoleDefinition.new
|
|
7
7
|
|
|
8
8
|
# Store user form context if coming from user creation/edit
|
|
9
|
-
return
|
|
9
|
+
return if params[:return_to_user].blank?
|
|
10
10
|
|
|
11
11
|
session[:role_return_context] = {
|
|
12
12
|
kb_username: params[:kb_username],
|
|
@@ -29,7 +29,7 @@ module Kaui
|
|
|
29
29
|
return_context = session.delete(:role_return_context)
|
|
30
30
|
if return_context.present?
|
|
31
31
|
# Add the new role to the existing roles
|
|
32
|
-
existing_roles = return_context[:roles].to_s.split(',').
|
|
32
|
+
existing_roles = return_context[:roles].to_s.split(',').compact_blank
|
|
33
33
|
existing_roles << @role_definition.role unless existing_roles.include?(@role_definition.role)
|
|
34
34
|
return_context[:roles] = existing_roles.join(',')
|
|
35
35
|
|
|
@@ -20,7 +20,7 @@ module Kaui
|
|
|
20
20
|
Rails.logger.error(exception.message)
|
|
21
21
|
Rails.logger.error(exception.backtrace.join("\n")) if exception.backtrace
|
|
22
22
|
@error = standardize_exception(exception)
|
|
23
|
-
render 'kaui/errors/500', status:
|
|
23
|
+
render 'kaui/errors/500', status: :internal_server_error, layout: false
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
protected
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
module Kaui
|
|
4
4
|
class SubscriptionsController < Kaui::EngineController
|
|
5
|
+
def show
|
|
6
|
+
restful_show
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
def new
|
|
6
10
|
@base_product_name = params[:base_product_name]
|
|
7
11
|
@subscription = Kaui::Subscription.new(bundle_id: params[:bundle_id],
|
|
@@ -21,10 +25,17 @@ module Kaui
|
|
|
21
25
|
redirect_to kaui_engine.account_bundles_path(@subscription.account_id), error: 'No available plan'
|
|
22
26
|
end
|
|
23
27
|
|
|
28
|
+
def edit
|
|
29
|
+
@subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', options_for_klient)
|
|
30
|
+
_, plans_details = lookup_bundle_and_plan_details(@subscription)
|
|
31
|
+
# Use a Set to deal with multiple pricelists
|
|
32
|
+
@plans = Set.new.merge(plans_details.map(&:plan))
|
|
33
|
+
end
|
|
34
|
+
|
|
24
35
|
def create
|
|
25
36
|
plan_name = params.require(:plan_name)
|
|
26
37
|
@base_product_name = params[:base_product_name]
|
|
27
|
-
@subscription = Kaui::Subscription.new(params.require(:subscription).
|
|
38
|
+
@subscription = Kaui::Subscription.new(params.require(:subscription).permit!.to_h.compact_blank)
|
|
28
39
|
|
|
29
40
|
begin
|
|
30
41
|
@bundle, plans_details = lookup_bundle_and_plan_details(@subscription, @base_product_name)
|
|
@@ -44,7 +55,8 @@ module Kaui
|
|
|
44
55
|
override_recurring_price = !override_fixed_price
|
|
45
56
|
phase_type = @bundle.nil? ? plan_details.phases.first.type : @bundle.subscriptions.first.phase_type
|
|
46
57
|
overrides = price_overrides(phase_type, override_fixed_price, override_recurring_price)
|
|
47
|
-
@subscription.price_overrides = overrides
|
|
58
|
+
@subscription.price_overrides = overrides if overrides.present?
|
|
59
|
+
@subscription.quantity = params[:quantity].to_i if params[:quantity].present? && params[:quantity].to_i.positive?
|
|
48
60
|
|
|
49
61
|
# un-set product_category since is not needed if plan name exist
|
|
50
62
|
@subscription.product_category = nil
|
|
@@ -71,13 +83,6 @@ module Kaui
|
|
|
71
83
|
end
|
|
72
84
|
end
|
|
73
85
|
|
|
74
|
-
def edit
|
|
75
|
-
@subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', 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
|
|
80
|
-
|
|
81
86
|
def update
|
|
82
87
|
plan_name = params.require(:plan_name)
|
|
83
88
|
|
|
@@ -95,7 +100,7 @@ module Kaui
|
|
|
95
100
|
override_fixed_price = current_plan.last['recurringPrice'].nil?
|
|
96
101
|
override_recurring_price = !override_fixed_price
|
|
97
102
|
overrides = price_overrides(subscription.phase_type, override_fixed_price, override_recurring_price)
|
|
98
|
-
input[:priceOverrides] = overrides
|
|
103
|
+
input[:priceOverrides] = overrides if overrides.present?
|
|
99
104
|
|
|
100
105
|
subscription.change_plan(input,
|
|
101
106
|
current_user.kb_username,
|
|
@@ -153,10 +158,6 @@ module Kaui
|
|
|
153
158
|
redirect_to kaui_engine.account_bundles_path(input_subscription['account_id']), notice: 'Subscription BCD was successfully changed'
|
|
154
159
|
end
|
|
155
160
|
|
|
156
|
-
def show
|
|
157
|
-
restful_show
|
|
158
|
-
end
|
|
159
|
-
|
|
160
161
|
def restful_show
|
|
161
162
|
subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', options_for_klient)
|
|
162
163
|
redirect_to kaui_engine.account_bundles_path(subscription.account_id)
|
|
@@ -14,7 +14,7 @@ module Kaui
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def create
|
|
17
|
-
params[:tag_definition][:applicable_object_types] = params[:tag_definition][:applicable_object_types].values
|
|
17
|
+
params[:tag_definition][:applicable_object_types] = params[:tag_definition][:applicable_object_types].values if params[:tag_definition][:applicable_object_types].present?
|
|
18
18
|
@tag_definition = Kaui::TagDefinition.new(params[:tag_definition])
|
|
19
19
|
|
|
20
20
|
begin
|
|
@@ -6,7 +6,7 @@ module Kaui
|
|
|
6
6
|
|
|
7
7
|
def index
|
|
8
8
|
# Retrieve current user and extract allowed list of tenants
|
|
9
|
-
allowed_user = Kaui::AllowedUser.
|
|
9
|
+
allowed_user = Kaui::AllowedUser.find_by(kb_username: current_user.kb_username)
|
|
10
10
|
@tenants = allowed_user&.kaui_tenants || []
|
|
11
11
|
|
|
12
12
|
#
|
|
@@ -30,7 +30,7 @@ module Kaui
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def select_tenant
|
|
33
|
-
tenant = Kaui::Tenant.
|
|
33
|
+
tenant = Kaui::Tenant.find_by(kb_tenant_id: params.require(:kb_tenant_id))
|
|
34
34
|
select_tenant_for_tenant_id(tenant.kb_tenant_id, tenant.name, tenant.id)
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -24,10 +24,10 @@ module Kaui
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def create
|
|
27
|
-
transaction = Kaui::Transaction.new(params[:transaction].
|
|
27
|
+
transaction = Kaui::Transaction.new(params[:transaction].permit!.to_h.compact_blank)
|
|
28
28
|
|
|
29
|
-
plugin_properties = params[:plugin_properties].values.reject { |item| item['value'].blank? || item['key'].blank? }
|
|
30
|
-
|
|
29
|
+
plugin_properties = params[:plugin_properties].values.reject { |item| item['value'].blank? || item['key'].blank? } if params[:plugin_properties].present?
|
|
30
|
+
if plugin_properties.present?
|
|
31
31
|
plugin_properties.map! do |property|
|
|
32
32
|
KillBillClient::Model::PluginPropertyAttributes.new(property)
|
|
33
33
|
end
|
|
@@ -35,15 +35,15 @@ module Kaui
|
|
|
35
35
|
|
|
36
36
|
options = plugin_properties.blank? ? options_for_klient : { pluginProperty: plugin_properties }.merge(options_for_klient)
|
|
37
37
|
|
|
38
|
-
control_plugin_names = params[:control_plugin_names].
|
|
39
|
-
options
|
|
38
|
+
control_plugin_names = params[:control_plugin_names].compact_blank if params[:control_plugin_names].present?
|
|
39
|
+
options[:controlPluginNames] = control_plugin_names if control_plugin_names.present?
|
|
40
40
|
|
|
41
41
|
payment = transaction.create(params.require(:account_id), params[:payment_method_id], current_user.kb_username, params[:reason], params[:comment], options)
|
|
42
42
|
redirect_to kaui_engine.account_payment_path(payment.account_id, payment.payment_id), notice: 'Transaction successfully created'
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def fix_transaction_state
|
|
46
|
-
transaction = Kaui::Transaction.new(params[:transaction].
|
|
46
|
+
transaction = Kaui::Transaction.new(params[:transaction].permit!.to_h.compact_blank)
|
|
47
47
|
payment_id = transaction.payment_id
|
|
48
48
|
transaction_id = transaction.transaction_id
|
|
49
49
|
transaction_status = transaction.status
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module Kaui
|
|
4
4
|
module AccountHelper
|
|
5
|
-
def pretty_account_identifier
|
|
6
|
-
|
|
5
|
+
def pretty_account_identifier(account = nil)
|
|
6
|
+
account ||= @account # rubocop:disable Rails/HelperInstanceVariable
|
|
7
|
+
return nil if account.nil?
|
|
7
8
|
|
|
8
|
-
Kaui.pretty_account_identifier.call(
|
|
9
|
+
Kaui.pretty_account_identifier.call(account)
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def email_notifications_plugin_available?
|
|
@@ -39,13 +40,14 @@ module Kaui
|
|
|
39
40
|
end
|
|
40
41
|
end
|
|
41
42
|
|
|
42
|
-
def account_closed?
|
|
43
|
-
|
|
43
|
+
def account_closed?(account = nil)
|
|
44
|
+
account ||= @account # rubocop:disable Rails/HelperInstanceVariable
|
|
45
|
+
return false if account.nil?
|
|
44
46
|
|
|
45
47
|
# NOTE: we ignore errors here, so that the call doesn't prevent the screen to load. While the error isn't surfaced, if there is an error with the catalog for instance,
|
|
46
48
|
# the AJAX call to compute the next invoice date should hopefully trigger a flash error.
|
|
47
49
|
blocking_states = begin
|
|
48
|
-
|
|
50
|
+
account.blocking_states('ACCOUNT', 'account-service', 'NONE', Kaui.current_tenant_user_options(current_user, session))
|
|
49
51
|
rescue StandardError
|
|
50
52
|
[]
|
|
51
53
|
end
|
|
@@ -77,7 +79,7 @@ module Kaui
|
|
|
77
79
|
# If bundles are provided, check for subscription BCD
|
|
78
80
|
if bundles.present?
|
|
79
81
|
bundles.each do |bundle|
|
|
80
|
-
next
|
|
82
|
+
next if bundle.subscriptions.blank?
|
|
81
83
|
|
|
82
84
|
bundle.subscriptions.each do |subscription|
|
|
83
85
|
# Skip cancelled subscriptions
|
|
@@ -6,7 +6,7 @@ module Kaui
|
|
|
6
6
|
if defined?(JRUBY_VERSION)
|
|
7
7
|
case exception
|
|
8
8
|
when ActiveRecord::JDBCError, ActiveRecord::NoDatabaseError, ActiveRecord::DatabaseConnectionError, ActiveRecord::ConnectionNotEstablished
|
|
9
|
-
return I18n.
|
|
9
|
+
return I18n.t('errors.messages.unable_to_connect_database')
|
|
10
10
|
else
|
|
11
11
|
return exception.message
|
|
12
12
|
end
|
|
@@ -14,13 +14,15 @@ module Kaui
|
|
|
14
14
|
|
|
15
15
|
case exception
|
|
16
16
|
when ActiveRecord::DatabaseConnectionError
|
|
17
|
-
I18n.
|
|
17
|
+
I18n.t('errors.messages.unable_to_connect_database')
|
|
18
18
|
when Errno::ECONNREFUSED, Errno::EBADF
|
|
19
|
-
I18n.
|
|
19
|
+
I18n.t('errors.messages.unable_to_connect_killbill')
|
|
20
20
|
when ->(e) { e.class.name.start_with?('KillBillClient::API') }
|
|
21
|
-
I18n.
|
|
21
|
+
I18n.t('errors.messages.error_communicating_killbill')
|
|
22
22
|
else
|
|
23
|
-
|
|
23
|
+
# Show detailed error in development/test, or when KAUI_SHOW_ERROR_DETAILS is set (for Docker)
|
|
24
|
+
show_details = Rails.env.development? || Rails.env.test? || ENV['KAUI_SHOW_ERROR_DETAILS'].present?
|
|
25
|
+
show_details ? exception.message : nil
|
|
24
26
|
end
|
|
25
27
|
end
|
|
26
28
|
end
|
|
@@ -7,15 +7,8 @@ module Kaui
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def colored_transaction_status(transaction_status)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"success'>"
|
|
13
|
-
else
|
|
14
|
-
"danger'>"
|
|
15
|
-
end
|
|
16
|
-
data += transaction_status
|
|
17
|
-
data += '</span>'
|
|
18
|
-
data.html_safe
|
|
10
|
+
alert_class = transaction_status == 'SUCCESS' ? 'alert-success' : 'alert-danger'
|
|
11
|
+
tag.span(transaction_status, class: alert_class)
|
|
19
12
|
end
|
|
20
13
|
|
|
21
14
|
def gateway_url(payment_method, payment)
|
|
@@ -11,10 +11,8 @@ module Kaui
|
|
|
11
11
|
def installed_plugin_names
|
|
12
12
|
plugins = []
|
|
13
13
|
nodes_info = KillBillClient::Model::NodesInfo.nodes_info(Kaui.current_tenant_user_options(current_user, session)) || []
|
|
14
|
-
plugins_info = nodes_info.
|
|
15
|
-
plugins_info.each do |plugin|
|
|
16
|
-
next unless plugin.state == 'RUNNING'
|
|
17
|
-
|
|
14
|
+
plugins_info = nodes_info.flat_map { |node| node.plugins_info || [] }
|
|
15
|
+
plugins_info.select { |p| p.state == 'RUNNING' }.uniq(&:plugin_name).each do |plugin|
|
|
18
16
|
plugin_name = plugin.plugin_name
|
|
19
17
|
plugin_key = plugin_name.gsub('-plugin', '')
|
|
20
18
|
|
|
@@ -40,7 +38,7 @@ module Kaui
|
|
|
40
38
|
def installed_plugins
|
|
41
39
|
installed_plugins = []
|
|
42
40
|
nodes_info = KillBillClient::Model::NodesInfo.nodes_info(Kaui.current_tenant_user_options(current_user, session)) || []
|
|
43
|
-
plugins_info = nodes_info.
|
|
41
|
+
plugins_info = nodes_info.flat_map { |node| node.plugins_info || [] }
|
|
44
42
|
|
|
45
43
|
plugins_info.each do |plugin|
|
|
46
44
|
next if plugin.version.nil?
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Kaui
|
|
4
4
|
module SubscriptionHelper
|
|
5
5
|
def humanized_subscription_product_category(sub)
|
|
6
|
-
if
|
|
6
|
+
if sub.blank? || sub.product_category.blank?
|
|
7
7
|
nil
|
|
8
8
|
else
|
|
9
9
|
humanized_product_category(sub.product_category)
|
|
@@ -21,16 +21,16 @@ module Kaui
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def humanized_subscription_product_name(sub, catalog = nil)
|
|
24
|
-
if
|
|
24
|
+
if sub.blank? || sub.product_name.blank?
|
|
25
25
|
nil
|
|
26
26
|
else
|
|
27
27
|
product = catalog&.products&.find { |p| p.name == sub.product_name }
|
|
28
|
-
humanized_product_name(!product.nil? &&
|
|
28
|
+
humanized_product_name(!product.nil? && product.pretty_name.present? ? product.pretty_name : sub.product_name)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def humanized_subscription_pretty_plan_name(sub, catalog = nil)
|
|
33
|
-
if
|
|
33
|
+
if sub.blank? || sub.product_name.blank?
|
|
34
34
|
nil
|
|
35
35
|
else
|
|
36
36
|
product = catalog&.products&.find { |p| p.name == sub.product_name }
|
|
@@ -47,7 +47,7 @@ module Kaui
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def humanized_subscription_billing_period(sub)
|
|
50
|
-
if
|
|
50
|
+
if sub.blank? || sub.billing_period.blank?
|
|
51
51
|
nil
|
|
52
52
|
else
|
|
53
53
|
humanized_billing_period(sub.billing_period)
|
|
@@ -63,7 +63,7 @@ module Kaui
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def humanized_subscription_price_list(sub, show_default)
|
|
66
|
-
if
|
|
66
|
+
if sub.blank? || sub.price_list.blank? || (!show_default && (sub.price_list.upcase == 'DEFAULT'))
|
|
67
67
|
nil
|
|
68
68
|
else
|
|
69
69
|
sub.price_list.downcase.capitalize
|
|
@@ -78,19 +78,17 @@ module Kaui
|
|
|
78
78
|
humanized_billing_period = humanized_subscription_billing_period(sub)
|
|
79
79
|
humanized_price_list = humanized_subscription_price_list(sub, false)
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
humanized_product_name.html_safe
|
|
81
|
+
if humanized_billing_period.nil?
|
|
82
|
+
if humanized_price_list.nil?
|
|
83
|
+
humanized_product_name + humanized_price_override(sub, '', '(', ')')
|
|
84
|
+
else
|
|
85
|
+
"#{humanized_product_name} (#{humanized_price_list.downcase}#{humanized_price_override(sub)})"
|
|
86
|
+
end
|
|
87
|
+
elsif humanized_price_list.nil?
|
|
88
|
+
"#{humanized_product_name} (#{humanized_billing_period.downcase}#{humanized_price_override(sub)})"
|
|
89
|
+
else
|
|
90
|
+
"#{humanized_product_name} (#{humanized_billing_period.downcase}, #{humanized_price_list.downcase}#{humanized_price_override(sub)})"
|
|
91
|
+
end
|
|
94
92
|
end
|
|
95
93
|
|
|
96
94
|
def humanized_price_override(sub, separation = ', ', open_bracket = '', close_bracket = '')
|
|
@@ -109,28 +107,46 @@ module Kaui
|
|
|
109
107
|
end
|
|
110
108
|
end
|
|
111
109
|
|
|
110
|
+
def catalog_for_subscription(sub, catalogs)
|
|
111
|
+
return nil if catalogs.blank? || sub&.start_date.blank?
|
|
112
|
+
|
|
113
|
+
start_date = Date.parse(sub.start_date)
|
|
114
|
+
|
|
115
|
+
# Find the latest catalog version whose effective_date <= subscription start_date
|
|
116
|
+
best = catalogs.select do |c|
|
|
117
|
+
Date.parse(c.effective_date) <= start_date
|
|
118
|
+
rescue StandardError
|
|
119
|
+
false
|
|
120
|
+
end.max_by(&:effective_date)
|
|
121
|
+
|
|
122
|
+
# Fall back to the oldest version if none precedes the start_date
|
|
123
|
+
best || catalogs.first
|
|
124
|
+
rescue StandardError
|
|
125
|
+
catalogs.last
|
|
126
|
+
end
|
|
127
|
+
|
|
112
128
|
def humanized_subscription_phase_type(sub)
|
|
113
129
|
sub.phase_type
|
|
114
130
|
end
|
|
115
131
|
|
|
116
132
|
def humanized_subscription_start_date(sub, account)
|
|
117
|
-
if
|
|
133
|
+
if sub.blank? || sub.start_date.blank? || account.blank? || account.time_zone.blank?
|
|
118
134
|
nil
|
|
119
135
|
else
|
|
120
|
-
format_date(sub.start_date, account.time_zone)
|
|
136
|
+
format_date(sub.start_date, account.time_zone)
|
|
121
137
|
end
|
|
122
138
|
end
|
|
123
139
|
|
|
124
140
|
def humanized_subscription_charged_through_date(sub, account)
|
|
125
|
-
if
|
|
141
|
+
if sub.blank? || sub.charged_through_date.blank? || account.blank? || account.time_zone.blank?
|
|
126
142
|
nil
|
|
127
143
|
else
|
|
128
|
-
format_date(sub.charged_through_date, account.time_zone)
|
|
144
|
+
format_date(sub.charged_through_date, account.time_zone)
|
|
129
145
|
end
|
|
130
146
|
end
|
|
131
147
|
|
|
132
148
|
def humanized_subscription_cancelled_date(sub, account)
|
|
133
|
-
if
|
|
149
|
+
if sub.blank? || sub.cancelled_date.blank? || account.blank? || account.time_zone.blank?
|
|
134
150
|
nil
|
|
135
151
|
else
|
|
136
152
|
"Entitlement date: #{format_date(sub.cancelled_date, account.time_zone)}"
|
|
@@ -138,15 +154,15 @@ module Kaui
|
|
|
138
154
|
end
|
|
139
155
|
|
|
140
156
|
def humanized_subscription_billing_start_date(sub, account)
|
|
141
|
-
if
|
|
157
|
+
if sub.blank? || sub.billing_start_date.blank? || account.blank? || account.time_zone.blank?
|
|
142
158
|
nil
|
|
143
159
|
else
|
|
144
|
-
format_date(sub.billing_start_date, account.time_zone)
|
|
160
|
+
format_date(sub.billing_start_date, account.time_zone)
|
|
145
161
|
end
|
|
146
162
|
end
|
|
147
163
|
|
|
148
164
|
def humanized_subscription_billing_end_date(sub, account)
|
|
149
|
-
if
|
|
165
|
+
if sub.blank? || sub.billing_end_date.blank? || account.blank? || account.time_zone.blank?
|
|
150
166
|
nil
|
|
151
167
|
else
|
|
152
168
|
"Billing date: #{format_date(sub.billing_end_date, account.time_zone)}"
|
|
@@ -154,10 +170,10 @@ module Kaui
|
|
|
154
170
|
end
|
|
155
171
|
|
|
156
172
|
def humanized_subscription_cancelled_information(sub, account)
|
|
157
|
-
if
|
|
173
|
+
if sub.blank? || sub.cancelled_date.blank? || account.blank? || account.time_zone.blank?
|
|
158
174
|
nil
|
|
159
175
|
else
|
|
160
|
-
|
|
176
|
+
safe_join([humanized_subscription_cancelled_date(sub, account), humanized_subscription_billing_end_date(sub, account)], tag.br)
|
|
161
177
|
end
|
|
162
178
|
end
|
|
163
179
|
|
|
@@ -166,7 +182,7 @@ module Kaui
|
|
|
166
182
|
end
|
|
167
183
|
|
|
168
184
|
def subscription_future_cancelled?(sub, account)
|
|
169
|
-
sub.present? && sub.state != 'CANCELLED' && sub.billing_end_date.present? && Time.parse(sub.billing_end_date) > current_time(account.time_zone)
|
|
185
|
+
sub.present? && sub.state != 'CANCELLED' && sub.billing_end_date.present? && Time.zone.parse(sub.billing_end_date) > current_time(account.time_zone)
|
|
170
186
|
end
|
|
171
187
|
|
|
172
188
|
def subscription_cancelled?(sub)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Kaui
|
|
4
4
|
module UuidHelper
|
|
5
5
|
def truncate_uuid(uuid)
|
|
6
|
-
return uuid unless
|
|
6
|
+
return uuid unless /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/.match?(uuid)
|
|
7
7
|
|
|
8
8
|
split = uuid.split('-')
|
|
9
9
|
"#{split[0]}-...-#{split[4]}"
|
data/app/models/kaui/account.rb
CHANGED
|
@@ -17,7 +17,8 @@ module Kaui
|
|
|
17
17
|
ADVANCED_SEARCH_NAME_CHANGES = [%w[pay_via_parent is_payment_delegated_to_parent]].freeze
|
|
18
18
|
|
|
19
19
|
def check_account_details_phone?
|
|
20
|
-
return
|
|
20
|
+
return false if phone.blank?
|
|
21
|
+
return true if /\A(?:\+?\d{1,3}\s*-?)?\(?(?:\d{3})?\)?[- ]?\d{3}[- ]?\d{4}\z/i.match?(phone)
|
|
21
22
|
|
|
22
23
|
false
|
|
23
24
|
end
|
|
@@ -29,7 +30,7 @@ module Kaui
|
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
def self.find_by_id_or_key(account_id_or_key, with_balance, with_balance_and_cba, options = {})
|
|
32
|
-
if
|
|
33
|
+
if /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/.match?(account_id_or_key)
|
|
33
34
|
begin
|
|
34
35
|
find_by_id(account_id_or_key, with_balance, with_balance_and_cba, options)
|
|
35
36
|
rescue StandardError => e
|
|
@@ -63,7 +64,7 @@ module Kaui
|
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
def persisted?
|
|
66
|
-
|
|
67
|
+
account_id.present?
|
|
67
68
|
end
|
|
68
69
|
end
|
|
69
70
|
end
|
|
@@ -41,7 +41,7 @@ module Kaui
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def format_plugin_config(plugin_key, plugin_type, props)
|
|
44
|
-
return nil
|
|
44
|
+
return nil if props.blank?
|
|
45
45
|
return props['raw_config'].gsub(/\r\n?/, "\n") if props['raw_config']
|
|
46
46
|
|
|
47
47
|
if plugin_type == 'ruby'
|
|
@@ -66,7 +66,7 @@ module Kaui
|
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def reformat_plugin_config(_plugin_type, props)
|
|
69
|
-
|
|
69
|
+
if props['raw_config'].present?
|
|
70
70
|
new_props = {}
|
|
71
71
|
props['raw_config'].split("\n").each do |p|
|
|
72
72
|
line = p.split('=')
|
|
@@ -4,7 +4,9 @@ module Kaui
|
|
|
4
4
|
class AllowedUser < ApplicationRecord
|
|
5
5
|
has_many :kaui_allowed_user_tenants,
|
|
6
6
|
class_name: 'Kaui::AllowedUserTenant',
|
|
7
|
-
foreign_key: 'kaui_allowed_user_id'
|
|
7
|
+
foreign_key: 'kaui_allowed_user_id',
|
|
8
|
+
dependent: :destroy,
|
|
9
|
+
inverse_of: :kaui_allowed_user
|
|
8
10
|
|
|
9
11
|
has_many :kaui_tenants, -> { distinct },
|
|
10
12
|
through: :kaui_allowed_user_tenants,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Kaui
|
|
4
4
|
class AllowedUserTenant < ApplicationRecord
|
|
5
|
-
belongs_to :kaui_allowed_user, class_name: 'Kaui::AllowedUser'
|
|
6
|
-
belongs_to :kaui_tenant, class_name: 'Kaui::Tenant'
|
|
5
|
+
belongs_to :kaui_allowed_user, class_name: 'Kaui::AllowedUser'
|
|
6
|
+
belongs_to :kaui_tenant, class_name: 'Kaui::Tenant'
|
|
7
7
|
end
|
|
8
8
|
end
|