kaui 2.1.0 → 2.2.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 -7
- 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} +4 -0
- data/app/assets/stylesheets/kaui/{audit.less → audit.scss} +5 -1
- data/app/assets/stylesheets/kaui/{common.less → common.scss} +17 -15
- 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 +268 -250
- 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 +86 -83
- 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 +130 -117
- 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 +24 -20
- data/app/controllers/kaui/invoices_controller.rb +132 -117
- data/app/controllers/kaui/login_proxy_controller.rb +2 -1
- data/app/controllers/kaui/payment_methods_controller.rb +102 -94
- 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 +16 -14
- data/app/helpers/kaui/application_helper.rb +8 -3
- data/app/helpers/kaui/date_helper.rb +3 -2
- 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 +7 -5
- 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 +1 -1
- data/app/views/kaui/accounts/_form.html.erb +2 -2
- data/app/views/kaui/accounts/index.html.erb +2 -0
- 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/_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/index.html.erb +1 -1
- data/app/views/kaui/bundles/transfer.html.erb +13 -5
- data/app/views/kaui/invoices/_invoice_table.html.erb +1 -1
- data/app/views/kaui/layouts/kaui_flash.html.erb +24 -0
- 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 +9 -9
- 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 +34 -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 +26 -37
- data/lib/tasks/kaui_tasks.rake +1 -0
- metadata +140 -442
- 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/money.rb +0 -2
- 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 -219
- 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,7 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kaui
|
4
|
+
class AuditLog
|
5
|
+
def self.description(log)
|
6
|
+
return unless log.changed_by.present?
|
2
7
|
|
3
|
-
def self.description(log)
|
4
|
-
if log.changed_by.present?
|
5
8
|
changed_str = "#{log.change_type} by #{log.changed_by.strip}"
|
6
9
|
if log.reason_code.blank? && log.comments.blank?
|
7
10
|
changed_str
|
data/app/models/kaui/base.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Kaui
|
4
|
+
class Base
|
5
|
+
def self.to_money(amount, currency)
|
6
|
+
if currency.present?
|
7
|
+
begin
|
8
|
+
return Money.from_amount(amount.to_f, currency)
|
9
|
+
rescue StandardError => _e
|
10
|
+
# Pass through
|
11
|
+
end
|
12
|
+
end
|
13
|
+
Money.from_amount(amount.to_f, 'USD')
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
data/app/models/kaui/bundle.rb
CHANGED
@@ -1,34 +1,39 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kaui
|
4
|
+
class Bundle < KillBillClient::Model::Bundle
|
5
|
+
def self.find_by_id_or_key(bundle_id_or_key, options = {})
|
6
|
+
if bundle_id_or_key =~ /[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}/
|
7
|
+
bundle = begin
|
8
|
+
find_by_id(bundle_id_or_key, options)
|
9
|
+
rescue StandardError
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
return bundle unless bundle.nil?
|
13
|
+
end
|
2
14
|
|
3
|
-
|
4
|
-
|
5
|
-
bundle = find_by_id(bundle_id_or_key, options) rescue nil
|
6
|
-
return bundle unless bundle.nil?
|
15
|
+
# Return the active one
|
16
|
+
find_by_external_key(bundle_id_or_key, false, options)
|
7
17
|
end
|
8
18
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
find_in_batches_by_search_key(search_key, offset, limit, options)
|
16
|
-
else
|
17
|
-
find_in_batches(offset, limit, options)
|
19
|
+
def self.list_or_search(search_key = nil, offset = 0, limit = 10, options = {})
|
20
|
+
if search_key.present?
|
21
|
+
find_in_batches_by_search_key(search_key, offset, limit, options)
|
22
|
+
else
|
23
|
+
find_in_batches(offset, limit, options)
|
24
|
+
end
|
18
25
|
end
|
19
|
-
end
|
20
26
|
|
21
|
-
|
27
|
+
def self.get_active_bundle_or_latest_created(bundles, time_zone = nil)
|
28
|
+
return nil if bundles.empty?
|
22
29
|
|
23
|
-
|
24
|
-
|
30
|
+
latest_start_date = nil
|
31
|
+
latest_bundle = nil
|
25
32
|
|
26
|
-
|
27
|
-
|
33
|
+
bundles.each do |b|
|
34
|
+
b.subscriptions.each do |s|
|
35
|
+
next unless s.product_category != 'ADD_ON'
|
28
36
|
|
29
|
-
bundles.each do |b|
|
30
|
-
b.subscriptions.each do |s|
|
31
|
-
if s.product_category != 'ADD_ON'
|
32
37
|
if latest_start_date.nil? || latest_start_date < s.start_date
|
33
38
|
latest_start_date = s.start_date
|
34
39
|
latest_bundle = b
|
@@ -37,8 +42,20 @@ class Kaui::Bundle < KillBillClient::Model::Bundle
|
|
37
42
|
return b if s.cancelled_date.nil? || s.cancelled_date > ActionController::Base.helpers.current_time(time_zone)
|
38
43
|
end
|
39
44
|
end
|
45
|
+
|
46
|
+
latest_bundle
|
40
47
|
end
|
41
48
|
|
42
|
-
|
49
|
+
def self.list_transfer_policy_params
|
50
|
+
@policy_params = [
|
51
|
+
[I18n.translate('start_of_term'), 'START_OF_TERM'],
|
52
|
+
[I18n.translate('end_of_term'), 'END_OF_TERM'],
|
53
|
+
[I18n.translate('immediate'), 'IMMEDIATE']
|
54
|
+
]
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.list_transfer_policy_params_keys
|
58
|
+
@policy_params = %w[START_OF_TERM END_OF_TERM IMMEDIATE]
|
59
|
+
end
|
43
60
|
end
|
44
61
|
end
|
data/app/models/kaui/catalog.rb
CHANGED
@@ -1,145 +1,150 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Kaui::Catalog < KillBillClient::Model::Catalog
|
4
|
-
|
5
|
-
class << self
|
6
|
-
|
7
|
-
def get_account_catalog_json(account_id, requested_date = nil, options = {})
|
8
|
-
params = {}
|
9
|
-
params[:accountId] = account_id
|
10
|
-
params[:requestedDate] = requested_date if requested_date
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
|
-
|
13
|
-
params,
|
14
|
-
{
|
15
|
-
:head => {'Accept' => "application/json"},
|
16
|
-
:content_type => "application/json",
|
3
|
+
require 'nokogiri'
|
17
4
|
|
18
|
-
|
19
|
-
|
5
|
+
module Kaui
|
6
|
+
class Catalog < KillBillClient::Model::Catalog
|
7
|
+
class << self
|
8
|
+
def get_account_catalog_json(account_id, requested_date = nil, options = {})
|
9
|
+
params = {}
|
10
|
+
params[:accountId] = account_id
|
11
|
+
params[:requestedDate] = requested_date if requested_date
|
12
|
+
|
13
|
+
get KillBillClient::Model::Catalog::KILLBILL_API_CATALOG_PREFIX,
|
14
|
+
params,
|
15
|
+
{
|
16
|
+
head: { 'Accept' => 'application/json' },
|
17
|
+
content_type: 'application/json'
|
18
|
+
}.merge(options)
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
def get_tenant_catalog_json(requested_date = nil, account_id = nil, options = {})
|
22
|
+
super
|
23
|
+
rescue ::KillBillClient::API::InternalServerError => e
|
24
|
+
if !e.response.nil? && !e.response.body.nil?
|
25
|
+
error_message = begin
|
26
|
+
JSON.parse(e.response.body)
|
27
|
+
rescue StandardError
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
raise e if error_message.nil? || error_message['message'].nil?
|
27
31
|
|
28
|
-
|
29
|
-
|
32
|
+
# Hack for lack of proper Kill Bill messaging (see https://github.com/killbill/killbill-admin-ui/issues/265)
|
33
|
+
return [] if error_message['message'].starts_with?('No existing versions')
|
34
|
+
end
|
35
|
+
raise e
|
30
36
|
end
|
31
|
-
raise e
|
32
|
-
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
def get_catalog_json(latest, requested_date, options)
|
39
|
+
catalogs = get_tenant_catalog_json(requested_date, nil, options)
|
40
|
+
return catalogs.length.positive? ? catalogs[catalogs.length - 1] : nil if latest
|
37
41
|
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
# Order by latest
|
43
|
+
result = []
|
44
|
+
catalogs.sort! { |l, r| r.effective_date <=> l.effective_date }
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
catalogs.each_with_index do |current_catalog, idx|
|
47
|
+
result << { version: idx,
|
48
|
+
version_date: current_catalog.effective_date,
|
49
|
+
currencies: current_catalog.currencies,
|
50
|
+
plans: build_existing_simple_plans(current_catalog) }
|
51
|
+
end
|
52
|
+
result
|
47
53
|
end
|
48
|
-
result
|
49
|
-
end
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
tmp[ap]
|
55
|
+
def build_ao_mapping(catalog)
|
56
|
+
tmp = {}
|
57
|
+
catalog&.products&.each do |p|
|
58
|
+
p.available.each do |ap|
|
59
|
+
tmp[ap] = [] unless tmp.key?(ap)
|
60
|
+
tmp[ap] << p.name
|
57
61
|
end
|
58
|
-
tmp[ap] << p.name
|
59
62
|
end
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
def get_catalog_xml(requested_date, options)
|
63
|
+
tmp.map { |e, v| "#{e}:#{v.join(',')}" }.join(';')
|
64
|
+
end
|
66
65
|
|
67
|
-
|
66
|
+
def get_catalog_xml(requested_date, options)
|
67
|
+
catalog_xml = KillBillClient::Model::Catalog.get_tenant_catalog_xml(requested_date, nil, options)
|
68
68
|
|
69
|
-
|
69
|
+
parsed_catalog = parse_catalog_xml(catalog_xml)
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
result = []
|
72
|
+
parsed_catalog.keys.each_with_index do |version_date, i|
|
73
|
+
entry = {}
|
74
|
+
entry[:version] = i
|
75
|
+
entry[:version_date] = version_date
|
76
|
+
entry[:xml] = parsed_catalog[version_date]
|
77
|
+
result << entry
|
78
|
+
end
|
79
|
+
result
|
78
80
|
end
|
79
|
-
result
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
81
|
|
84
|
-
|
82
|
+
private
|
85
83
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
def build_existing_simple_plans(catalog)
|
85
|
+
tmp = catalog.products.map do |p|
|
86
|
+
p.plans.each do |plan|
|
87
|
+
class << plan
|
88
|
+
attr_accessor :product_name, :product_category
|
89
|
+
end
|
90
|
+
plan.product_name = p.name
|
91
|
+
plan.product_category = p.type
|
91
92
|
end
|
92
|
-
|
93
|
-
plan.product_category = p.type
|
94
|
-
end
|
95
|
-
end.flatten!
|
93
|
+
end.flatten!
|
96
94
|
|
97
|
-
|
95
|
+
selected = tmp.select { |p| p.phases.length.to_i <= 2 }
|
98
96
|
|
99
|
-
|
97
|
+
currencies = catalog.currencies
|
100
98
|
|
101
|
-
|
102
|
-
|
103
|
-
|
99
|
+
result = []
|
100
|
+
selected.each do |plan|
|
101
|
+
has_trial = plan.phases[0].type == 'TRIAL'
|
104
102
|
|
105
|
-
|
103
|
+
simple_plan = KillBillClient::Model::SimplePlanAttributes.new
|
106
104
|
|
107
|
-
|
108
|
-
|
109
|
-
|
105
|
+
# Embellish SimplePlanAttributes to contain a map currency -> amount (required in the view)
|
106
|
+
class << simple_plan
|
107
|
+
attr_accessor :prices, :final_phase_duration
|
108
|
+
end
|
109
|
+
simple_plan.prices = plan.phases[-1].prices.each_with_object({}) do |e, r|
|
110
|
+
r[e.currency] = e.value
|
111
|
+
end
|
112
|
+
|
113
|
+
simple_plan.plan_id = plan.name
|
114
|
+
simple_plan.product_name = plan.product_name
|
115
|
+
simple_plan.product_category = plan.product_category
|
116
|
+
simple_plan.currency = currencies[0]
|
117
|
+
simple_plan.amount = simple_plan.prices[currencies[0]]
|
118
|
+
simple_plan.billing_period = plan.billing_period
|
119
|
+
simple_plan.trial_length = has_trial ? plan.phases[0].duration.number : 0
|
120
|
+
simple_plan.trial_time_unit = has_trial ? plan.phases[0].duration.unit : 'N/A'
|
121
|
+
last_phase_duration = plan.phases.last.duration
|
122
|
+
simple_plan.final_phase_duration = if last_phase_duration.number.positive?
|
123
|
+
"#{last_phase_duration.number} #{last_phase_duration.unit.downcase}"
|
124
|
+
else
|
125
|
+
last_phase_duration.unit
|
126
|
+
end
|
127
|
+
|
128
|
+
result << simple_plan
|
110
129
|
end
|
111
|
-
|
112
|
-
|
113
|
-
simple_plan.plan_id = plan.name
|
114
|
-
simple_plan.product_name = plan.product_name
|
115
|
-
simple_plan.product_category = plan.product_category
|
116
|
-
simple_plan.currency = currencies[0]
|
117
|
-
simple_plan.amount = simple_plan.prices[currencies[0]]
|
118
|
-
simple_plan.billing_period = plan.billing_period
|
119
|
-
simple_plan.trial_length = has_trial ? plan.phases[0].duration.number : 0
|
120
|
-
simple_plan.trial_time_unit = has_trial ? plan.phases[0].duration.unit : "N/A"
|
121
|
-
|
122
|
-
result << simple_plan
|
130
|
+
result
|
123
131
|
end
|
124
|
-
result
|
125
|
-
end
|
126
|
-
|
127
|
-
def parse_catalog_xml(input_xml)
|
128
|
-
doc = Nokogiri::XML(input_xml) { |x| x.noblanks }
|
129
|
-
doc_versions = doc.xpath("//version")
|
130
132
|
|
131
|
-
|
133
|
+
def parse_catalog_xml(input_xml)
|
134
|
+
doc = Nokogiri::XML(input_xml, &:noblanks)
|
135
|
+
doc_versions = doc.xpath('//version')
|
132
136
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
137
|
+
doc_versions.each_with_object({}) do |v, hsh|
|
138
|
+
# Replace node 'version' with 'catalog' and add the attributes
|
139
|
+
v.name = 'catalog'
|
140
|
+
v['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance'
|
141
|
+
v['xsi:noNamespaceSchemaLocation'] = 'CatalogSchema.xsd'
|
142
|
+
# Extract version
|
143
|
+
version = v.search('effectiveDate').text
|
139
144
|
|
140
|
-
|
141
|
-
|
142
|
-
|
145
|
+
# Add entry
|
146
|
+
hsh[version] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>#{v.to_xml(indent: 4)}"
|
147
|
+
end
|
143
148
|
end
|
144
149
|
end
|
145
150
|
end
|
data/app/models/kaui/credit.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Kaui
|
4
|
+
class CustomField < KillBillClient::Model::CustomField
|
5
|
+
def self.list_or_search(search_key = nil, offset = 0, limit = 10, options = {})
|
6
|
+
if search_key.present?
|
7
|
+
find_in_batches_by_search_key(search_key, offset, limit, options)
|
8
|
+
else
|
9
|
+
find_in_batches(offset, limit, options)
|
10
|
+
end
|
8
11
|
end
|
9
12
|
end
|
10
13
|
end
|
data/app/models/kaui/invoice.rb
CHANGED
@@ -1,32 +1,35 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
result
|
3
|
+
module Kaui
|
4
|
+
class Invoice < KillBillClient::Model::Invoice
|
5
|
+
def self.build_from_raw_invoice(raw_invoice)
|
6
|
+
result = Kaui::Invoice.new
|
7
|
+
KillBillClient::Model::InvoiceAttributes.instance_variable_get('@json_attributes').each do |attr|
|
8
|
+
result.send("#{attr}=", raw_invoice.send(attr))
|
9
|
+
end
|
10
|
+
result
|
7
11
|
end
|
8
|
-
result
|
9
|
-
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def self.list_or_search(search_key = nil, offset = 0, limit = 10, options = {})
|
14
|
+
if search_key.present?
|
15
|
+
find_in_batches_by_search_key(search_key, offset, limit, options)
|
16
|
+
else
|
17
|
+
find_in_batches(offset, limit, options)
|
18
|
+
end
|
16
19
|
end
|
17
|
-
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
%i[amount balance credits].each do |type|
|
22
|
+
define_method "#{type}_to_money" do
|
23
|
+
Kaui::Base.to_money(send(type), currency)
|
24
|
+
end
|
22
25
|
end
|
23
|
-
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
def refund_adjustment_to_money
|
28
|
+
Kaui::Base.to_money(refund_adj, currency)
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
def credit_adjustment_to_money
|
32
|
+
Kaui::Base.to_money(credit_adj, currency)
|
33
|
+
end
|
31
34
|
end
|
32
35
|
end
|
@@ -1,10 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Kaui
|
4
|
+
class InvoiceItem < KillBillClient::Model::InvoiceItem
|
5
|
+
def amount_to_money
|
6
|
+
Kaui::Base.to_money(amount, currency)
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
def self.amount_to_money(invoice_item)
|
10
|
+
new(amount: invoice_item.amount, currency: invoice_item.currency).amount_to_money
|
11
|
+
end
|
9
12
|
end
|
10
13
|
end
|
@@ -1,67 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def build_from_raw_payment(raw_payment)
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kaui
|
4
|
+
class InvoicePayment < KillBillClient::Model::InvoicePayment
|
5
|
+
include Kaui::PaymentState
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def find_safely_by_id(id, options = {})
|
9
|
+
Kaui::InvoicePayment.find_by_id(id, true, true, options)
|
10
|
+
rescue StandardError => e
|
11
|
+
# Maybe the plugin is not registered or the plugin threw an exception
|
12
|
+
Rails.logger.warn(e)
|
13
|
+
Kaui::InvoicePayment.find_by_id(id, false, true, options)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
16
|
+
def build_from_raw_payment(raw_payment)
|
17
|
+
return nil if raw_payment.nil?
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
# Use Kaui::Transaction to benefit from additional fields (e.g next_retry_date)
|
24
|
-
original_transactions = (result.transactions || [])
|
25
|
-
result.transactions = []
|
26
|
-
original_transactions.each do |transaction|
|
27
|
-
new_transaction = Kaui::Transaction.new
|
28
|
-
KillBillClient::Model::PaymentTransactionAttributes.instance_variable_get('@json_attributes').each do |attr|
|
29
|
-
new_transaction.send("#{attr}=", transaction.send(attr))
|
19
|
+
result = Kaui::InvoicePayment.new
|
20
|
+
KillBillClient::Model::InvoicePaymentAttributes.instance_variable_get('@json_attributes').each do |attr|
|
21
|
+
result.send("#{attr}=", raw_payment.send(attr))
|
30
22
|
end
|
31
|
-
|
23
|
+
# Use Kaui::Transaction to benefit from additional fields (e.g next_retry_date)
|
24
|
+
original_transactions = (result.transactions || [])
|
25
|
+
result.transactions = []
|
26
|
+
original_transactions.each do |transaction|
|
27
|
+
new_transaction = Kaui::Transaction.new
|
28
|
+
KillBillClient::Model::PaymentTransactionAttributes.instance_variable_get('@json_attributes').each do |attr|
|
29
|
+
new_transaction.send("#{attr}=", transaction.send(attr))
|
30
|
+
end
|
31
|
+
result.transactions << new_transaction
|
32
|
+
end
|
33
|
+
result.build_transactions_next_retry_date!
|
34
|
+
result
|
32
35
|
end
|
33
|
-
result.build_transactions_next_retry_date!
|
34
|
-
result
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
[:auth, :captured, :purchased, :refunded, :credited].each do |type|
|
40
|
-
define_method "#{type}_amount_to_money" do
|
41
|
-
Kaui::Base.to_money(send("#{type}_amount"), currency)
|
42
36
|
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# For each payment transaction, compute next_retry date by joining with payment attempts
|
46
|
-
def build_transactions_next_retry_date!
|
47
37
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
38
|
+
%i[auth captured purchased refunded credited].each do |type|
|
39
|
+
define_method "#{type}_amount_to_money" do
|
40
|
+
Kaui::Base.to_money(send("#{type}_amount"), currency)
|
41
|
+
end
|
52
42
|
end
|
53
43
|
|
54
|
-
#
|
55
|
-
|
44
|
+
# For each payment transaction, compute next_retry date by joining with payment attempts
|
45
|
+
def build_transactions_next_retry_date!
|
46
|
+
# Filter scheduled attempts: We could have several in parallel when multiple independent transactions occur at the same time
|
47
|
+
# (They would have different transaction_external_key)
|
48
|
+
scheduled_attempts = (payment_attempts || []).select do |a|
|
49
|
+
a.state_name == 'SCHEDULED'
|
50
|
+
end
|
56
51
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
52
|
+
# Look for latest transaction associated with each such scheduled attempt and set retry date accordingly
|
53
|
+
scheduled_attempts.each do |a|
|
54
|
+
last_transaction_for_attempt = (transactions || []).select do |t|
|
55
|
+
t.transaction_external_key == a.transaction_external_key
|
56
|
+
end.max_by(&:effective_date)
|
62
57
|
|
63
|
-
|
58
|
+
last_transaction_for_attempt.next_retry_date = a.effective_date if last_transaction_for_attempt
|
59
|
+
end
|
64
60
|
end
|
65
|
-
|
66
61
|
end
|
67
62
|
end
|