kaui 2.0.4 → 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 -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 +134 -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 +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 +8 -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 +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 +74 -30
- data/lib/tasks/kaui_tasks.rake +1 -0
- metadata +145 -440
- 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,52 +1,56 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Kaui
|
4
|
+
class PaymentsController < Kaui::EngineController
|
5
|
+
def index
|
6
|
+
@search_query = params[:q] || params[:account_id]
|
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
|
-
|
12
|
+
@max_nb_records = @search_query.blank? ? Kaui::Payment.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records : 0
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
else
|
26
|
-
account = Kaui::Account::find_by_id_or_key(search_key, false, false, options_for_klient) rescue nil
|
27
|
-
if account.nil?
|
28
|
-
payments = Kaui::Payment.list_or_search(search_key, offset, limit, options_for_klient)
|
15
|
+
def pagination
|
16
|
+
searcher = lambda do |search_key, offset, limit|
|
17
|
+
if Kaui::Payment::TRANSACTION_STATUSES.include?(search_key)
|
18
|
+
# Search is done by payment state on the server side, see http://docs.killbill.io/latest/userguide_payment.html#_payment_states
|
19
|
+
payment_state = if %w[PLUGIN_FAILURE UNKNOWN].include?(search_key)
|
20
|
+
'_ERRORED'
|
21
|
+
elsif search_key == 'PAYMENT_FAILURE'
|
22
|
+
'_FAILED'
|
23
|
+
else
|
24
|
+
"_#{search_key}"
|
25
|
+
end
|
26
|
+
payments = Kaui::Payment.list_or_search(payment_state, offset, limit, options_for_klient)
|
29
27
|
else
|
30
|
-
|
28
|
+
account = begin
|
29
|
+
Kaui::Account.find_by_id_or_key(search_key, false, false, options_for_klient)
|
30
|
+
rescue StandardError
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
payments = if account.nil?
|
34
|
+
Kaui::Payment.list_or_search(search_key, offset, limit, options_for_klient)
|
35
|
+
else
|
36
|
+
account.payments(options_for_klient).map! { |payment| Kaui::Payment.build_from_raw_payment(payment) }
|
37
|
+
end
|
31
38
|
end
|
32
|
-
end
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
created_date = transaction_date
|
40
|
+
payments.each do |payment|
|
41
|
+
created_date = nil
|
42
|
+
payment.transactions.each do |transaction|
|
43
|
+
transaction_date = Date.parse(transaction.effective_date)
|
44
|
+
created_date = transaction_date if created_date.nil? || (transaction_date < created_date)
|
40
45
|
end
|
46
|
+
payment.payment_date = created_date
|
41
47
|
end
|
42
|
-
payment.payment_date = created_date
|
43
|
-
end
|
44
48
|
|
45
|
-
|
46
|
-
|
49
|
+
payments
|
50
|
+
end
|
47
51
|
|
48
|
-
|
49
|
-
|
52
|
+
data_extractor = lambda do |payment, column|
|
53
|
+
[
|
50
54
|
payment.payment_number.to_i,
|
51
55
|
payment.payment_date,
|
52
56
|
payment.total_authed_amount_to_money,
|
@@ -54,88 +58,87 @@ class Kaui::PaymentsController < Kaui::EngineController
|
|
54
58
|
payment.returned_amount_to_money,
|
55
59
|
payment.transactions.empty? ? nil : payment.transactions[-1].status,
|
56
60
|
payment.payment_external_key
|
57
|
-
|
58
|
-
|
61
|
+
][column]
|
62
|
+
end
|
59
63
|
|
60
|
-
|
61
|
-
|
62
|
-
view_context.link_to(payment.payment_number, view_context.url_for(:
|
64
|
+
formatter = lambda do |payment|
|
65
|
+
[
|
66
|
+
view_context.link_to(payment.payment_number, view_context.url_for(controller: :payments, action: :show, account_id: payment.account_id, id: payment.payment_id)),
|
63
67
|
view_context.format_date(payment.payment_date, @account.time_zone),
|
64
68
|
view_context.humanized_money_with_symbol(payment.total_authed_amount_to_money),
|
65
69
|
view_context.humanized_money_with_symbol(payment.paid_amount_to_money),
|
66
70
|
view_context.humanized_money_with_symbol(payment.returned_amount_to_money),
|
67
71
|
payment.transactions.empty? ? nil : view_context.colored_transaction_status(payment.transactions[-1].status),
|
68
72
|
payment.payment_external_key
|
69
|
-
|
70
|
-
|
73
|
+
]
|
74
|
+
end
|
71
75
|
|
72
|
-
|
73
|
-
|
76
|
+
paginate searcher, data_extractor, formatter
|
77
|
+
end
|
74
78
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
+
def new
|
80
|
+
cached_options_for_klient = options_for_klient
|
81
|
+
fetch_invoice = promise { Kaui::Invoice.find_by_id(params.require(:invoice_id), 'NONE', cached_options_for_klient) }
|
82
|
+
fetch_payment_methods = promise { Kaui::PaymentMethod.find_all_by_account_id(params.require(:account_id), false, cached_options_for_klient) }
|
79
83
|
|
80
|
-
|
81
|
-
|
84
|
+
@invoice = wait(fetch_invoice)
|
85
|
+
@payment_methods = wait(fetch_payment_methods)
|
82
86
|
|
83
|
-
|
84
|
-
|
87
|
+
@payment = Kaui::InvoicePayment.new('accountId' => @account.account_id, 'targetInvoiceId' => @invoice.invoice_id, 'purchasedAmount' => @invoice.balance)
|
88
|
+
end
|
85
89
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
def create
|
91
|
+
payment = Kaui::InvoicePayment.new(invoice_payment_params)
|
92
|
+
external_payment = params[:external] == '1'
|
93
|
+
payment.payment_method_id = nil if external_payment || payment.payment_method_id.blank?
|
94
|
+
payment.create(external_payment, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
95
|
+
redirect_to kaui_engine.account_invoice_path(payment.account_id, payment.target_invoice_id), notice: 'Payment triggered'
|
96
|
+
end
|
93
97
|
|
94
|
-
|
95
|
-
|
98
|
+
def show
|
99
|
+
cached_options_for_klient = options_for_klient
|
96
100
|
|
97
|
-
|
98
|
-
|
101
|
+
invoice_payment = Kaui::InvoicePayment.find_safely_by_id(params.require(:id), cached_options_for_klient)
|
102
|
+
@payment = Kaui::InvoicePayment.build_from_raw_payment(invoice_payment)
|
99
103
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
104
|
+
fetch_payment_fields = promise do
|
105
|
+
direct_payment = Kaui::Payment.new(payment_id: @payment.payment_id)
|
106
|
+
direct_payment.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase }
|
107
|
+
end
|
108
|
+
# The payment method may have been deleted
|
109
|
+
fetch_payment_method = promise { Kaui::PaymentMethod.find_safely_by_id(@payment.payment_method_id, cached_options_for_klient) }
|
106
110
|
|
107
|
-
|
108
|
-
|
109
|
-
|
111
|
+
@custom_fields = wait(fetch_payment_fields)
|
112
|
+
@payment_method = wait(fetch_payment_method)
|
113
|
+
end
|
110
114
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
115
|
+
def restful_show
|
116
|
+
begin
|
117
|
+
payment = Kaui::InvoicePayment.find_by_id(params.require(:id), false, true, options_for_klient)
|
118
|
+
rescue KillBillClient::API::NotFound
|
119
|
+
payment = Kaui::Payment.find_by_external_key(params.require(:id), false, true, options_for_klient)
|
120
|
+
end
|
121
|
+
redirect_to account_payment_path(payment.account_id, payment.payment_id)
|
116
122
|
end
|
117
|
-
redirect_to account_payment_path(payment.account_id, payment.payment_id)
|
118
|
-
end
|
119
123
|
|
120
|
-
|
121
|
-
begin
|
124
|
+
def cancel_scheduled_payment
|
122
125
|
payment_transaction = Kaui::Transaction.new
|
123
126
|
payment_transaction.transaction_external_key = params.require(:transaction_external_key)
|
124
127
|
|
125
128
|
payment_transaction.cancel_scheduled_payment(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
126
129
|
|
127
|
-
redirect_to kaui_engine.account_payment_path(params.require(:account_id), params.require(:id)), :
|
128
|
-
rescue => e
|
130
|
+
redirect_to kaui_engine.account_payment_path(params.require(:account_id), params.require(:id)), notice: 'Payment attempt retry successfully deleted'
|
131
|
+
rescue StandardError => e
|
129
132
|
flash[:error] = "Error deleting payment attempt retry: #{as_string(e)}"
|
130
133
|
redirect_to kaui_engine.account_path(params.require(:account_id))
|
131
134
|
end
|
132
|
-
end
|
133
135
|
|
134
|
-
|
136
|
+
private
|
135
137
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
138
|
+
def invoice_payment_params
|
139
|
+
invoice_payment = params.require(:invoice_payment)
|
140
|
+
invoice_payment.require(:target_invoice_id)
|
141
|
+
invoice_payment
|
142
|
+
end
|
140
143
|
end
|
141
144
|
end
|
@@ -1,19 +1,52 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module Kaui
|
4
|
+
class QueuesController < Kaui::EngineController
|
5
|
+
# rubocop:disable Lint/SuppressedException,Lint/EnsureReturn
|
6
|
+
def index
|
7
|
+
@account_id = params[:account_id]
|
8
|
+
|
9
|
+
unless params[:max_date].blank?
|
10
|
+
begin
|
11
|
+
max_date_test = Time.parse(params[:max_date]).iso8601
|
12
|
+
rescue StandardError
|
13
|
+
ensure
|
14
|
+
if max_date_test.nil?
|
15
|
+
flash[:error] = I18n.translate('errors.messages.invalid_max_date')
|
16
|
+
redirect_to account_queues_path(@account.account_id) and return
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
unless params[:min_date].blank?
|
22
|
+
begin
|
23
|
+
min_date_test = Time.parse(params[:min_date]).iso8601
|
24
|
+
rescue StandardError
|
25
|
+
ensure
|
26
|
+
if min_date_test.nil?
|
27
|
+
flash[:error] = I18n.translate('errors.messages.invalid_min_date')
|
28
|
+
redirect_to account_queues_path(@account.account_id) and return
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
11
32
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
33
|
+
begin
|
34
|
+
@now = Kaui::Admin.get_clock(nil, options_for_klient)['currentUtcTime'].to_datetime
|
35
|
+
rescue KillBillClient::API::NotFound
|
36
|
+
# If TestResource is not bound, then clock has not been manipulated, we can default to NOW
|
37
|
+
@now = DateTime.now.in_time_zone('UTC')
|
38
|
+
end
|
16
39
|
|
17
|
-
|
40
|
+
min_date = (Time.parse(params[:min_date]).iso8601 unless params[:min_date].blank?) || '1970-01-01'
|
41
|
+
max_date = (Time.parse(params[:max_date]).iso8601 unless params[:max_date].blank?) || Time.now.iso8601
|
42
|
+
|
43
|
+
with_history = params[:with_history] || false
|
44
|
+
@queues_entries = Kaui::Admin.get_queues_entries(@account_id,
|
45
|
+
options_for_klient.merge(withHistory: with_history,
|
46
|
+
minDate: min_date, maxDate: max_date))
|
47
|
+
|
48
|
+
params.permit!
|
49
|
+
end
|
50
|
+
# rubocop:enable Lint/SuppressedException,Lint/EnsureReturn
|
18
51
|
end
|
19
52
|
end
|
@@ -1,49 +1,52 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Kaui
|
4
|
+
class RefundsController < Kaui::EngineController
|
5
|
+
def new
|
6
|
+
cached_options_for_klient = options_for_klient
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
fetch_invoice = promise { Kaui::Invoice.find_by_id(params.require(:invoice_id), 'NONE', cached_options_for_klient) }
|
9
|
+
fetch_payment = promise { Kaui::InvoicePayment.find_by_id(params.require(:payment_id), false, false, cached_options_for_klient) }
|
10
|
+
fetch_bundles = promise { @account.bundles(cached_options_for_klient) }
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
@invoice = wait(fetch_invoice)
|
13
|
+
@payment = wait(fetch_payment)
|
14
|
+
@bundles = wait(fetch_bundles)
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
+
@refund = KillBillClient::Model::InvoiceItem.new(invoice_id: @invoice.invoice_id)
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
# rubocop:disable Lint/FloatComparison
|
20
|
+
def create
|
21
|
+
invoice = Kaui::Invoice.find_by_id(params.require(:invoice_id), 'NONE', options_for_klient)
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
if params[:adjustment_type] == 'invoiceItemAdjustment'
|
24
|
+
items = []
|
25
|
+
(params.to_unsafe_h[:adjustments] || []).each do |ii|
|
26
|
+
original_item = find_original_item(invoice.items, ii[0])
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
item = KillBillClient::Model::InvoiceItem.new
|
29
|
+
item.invoice_item_id = ii[0]
|
30
|
+
# If we tried to do a partial item adjustment, we pass the value, if not we don't send any value and let the system
|
31
|
+
# decide what is the maximum amount we can have on that item
|
32
|
+
item.amount = ii[1].to_f == original_item.amount ? nil : ii[1]
|
30
33
|
|
31
|
-
|
34
|
+
items << item
|
35
|
+
end
|
32
36
|
end
|
33
|
-
end
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
KillBillClient::Model::InvoicePayment.refund(params.require(:payment_id), params[:amount], items, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
39
|
+
redirect_to kaui_engine.account_invoice_path(invoice.account_id, invoice.invoice_id), notice: 'Refund created'
|
40
|
+
end
|
41
|
+
# rubocop:enable Lint/FloatComparison
|
38
42
|
|
39
|
-
|
43
|
+
private
|
40
44
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
return ii
|
45
|
+
def find_original_item(items, item_id)
|
46
|
+
items.each do |ii|
|
47
|
+
return ii if ii.invoice_item_id == item_id
|
45
48
|
end
|
49
|
+
nil
|
46
50
|
end
|
47
|
-
nil
|
48
51
|
end
|
49
52
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kaui
|
2
4
|
class RegistrationsController < Devise::RegistrationsController
|
3
|
-
|
4
5
|
layout Kaui.config[:layout]
|
5
6
|
|
6
7
|
skip_before_action :check_for_redirect_to_tenant_screen, raise: false
|
7
8
|
|
8
9
|
def create
|
9
|
-
|
10
10
|
if Kaui.disable_sign_up_link
|
11
11
|
flash[:error] = 'You need to sign in before adding a user!'
|
12
12
|
redirect_to new_user_session_path and return
|
@@ -14,7 +14,7 @@ module Kaui
|
|
14
14
|
|
15
15
|
sign_up_params = sign_up_rails_params
|
16
16
|
|
17
|
-
@user = Kaui::AllowedUser.new(:
|
17
|
+
@user = Kaui::AllowedUser.new(kb_username: sign_up_params.require(:kb_username))
|
18
18
|
|
19
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!"
|
@@ -37,10 +37,10 @@ module Kaui
|
|
37
37
|
|
38
38
|
def root_options_for_klient
|
39
39
|
{
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
username: Kaui.root_username,
|
41
|
+
password: Kaui.root_password,
|
42
|
+
api_key: Kaui.root_api_key,
|
43
|
+
api_secret: Kaui.root_api_secret
|
44
44
|
}
|
45
45
|
end
|
46
46
|
|
@@ -1,20 +1,23 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Kaui
|
4
|
+
class RoleDefinitionsController < Kaui::EngineController
|
5
|
+
def new
|
6
|
+
@role_definition = Kaui::RoleDefinition.new
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def create
|
10
|
+
# Sanity is done on the server side
|
11
|
+
@role_definition = Kaui::RoleDefinition.new(params.require(:role_definition))
|
12
|
+
@role_definition.permissions = @role_definition.permissions.split(',')
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
begin
|
15
|
+
@role_definition = @role_definition.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
|
16
|
+
redirect_to admin_allowed_users_path, notice: 'Role was successfully created'
|
17
|
+
rescue StandardError => e
|
18
|
+
flash.now[:error] = "Error while creating role: #{as_string(e)}"
|
19
|
+
render action: :new
|
20
|
+
end
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
@@ -1,28 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kaui
|
2
4
|
# Subclassed to specify the correct layout
|
3
5
|
class SessionsController < Devise::SessionsController
|
4
|
-
|
5
6
|
layout Kaui.config[:layout]
|
6
7
|
|
7
8
|
skip_before_action :check_for_redirect_to_tenant_screen, raise: false
|
8
9
|
|
10
|
+
# The sign-in flow eventually calls authenticate! from config/initializers/killbill_authenticatable.rb
|
11
|
+
|
9
12
|
protected
|
10
13
|
|
11
14
|
# Override after_sign_in_path_for to not have to rely on the default 'root' config which we want to keep on home#index
|
12
|
-
def after_sign_in_path_for(
|
15
|
+
def after_sign_in_path_for(_resource)
|
13
16
|
# Clear the tenant_id from the cookie to not rely on old cookie data
|
14
17
|
session[:kb_tenant_id] = nil
|
15
18
|
stored_location_for(:user) || Kaui.tenant_home_path.call
|
16
19
|
end
|
17
20
|
|
18
|
-
def after_sign_out_path_for(
|
21
|
+
def after_sign_out_path_for(_resource)
|
19
22
|
kaui_path
|
20
23
|
end
|
21
24
|
|
22
25
|
def require_no_authentication
|
23
26
|
super
|
24
27
|
# Remove the somewhat confusing message "You are already signed in."
|
25
|
-
flash.discard(:alert) if flash[:alert] == I18n.t(
|
28
|
+
flash.discard(:alert) if flash[:alert] == I18n.t('devise.failure.already_authenticated')
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|