kaui 0.15.0 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/app/assets/stylesheets/kaui/common.less +0 -6
  4. data/app/assets/stylesheets/kaui/datatable.less +14 -0
  5. data/app/assets/stylesheets/kaui/home.less +4 -0
  6. data/app/controllers/kaui/accounts_controller.rb +37 -0
  7. data/app/controllers/kaui/admin_allowed_users_controller.rb +2 -2
  8. data/app/controllers/kaui/admin_controller.rb +27 -0
  9. data/app/controllers/kaui/admin_tenants_controller.rb +8 -2
  10. data/app/controllers/kaui/engine_controller.rb +2 -2
  11. data/app/controllers/kaui/engine_controller_util.rb +1 -1
  12. data/app/controllers/kaui/home_controller.rb +3 -1
  13. data/app/controllers/kaui/invoices_controller.rb +10 -0
  14. data/app/controllers/kaui/payments_controller.rb +31 -7
  15. data/app/controllers/kaui/queues_controller.rb +11 -0
  16. data/app/controllers/kaui/subscriptions_controller.rb +20 -2
  17. data/app/controllers/kaui/tags_controller.rb +11 -0
  18. data/app/controllers/kaui/transactions_controller.rb +27 -4
  19. data/app/helpers/kaui/account_helper.rb +1 -1
  20. data/app/helpers/kaui/application_helper.rb +5 -0
  21. data/app/helpers/kaui/date_helper.rb +5 -1
  22. data/app/helpers/kaui/payment_helper.rb +9 -0
  23. data/app/models/kaui/admin.rb +75 -0
  24. data/app/models/kaui/invoice_payment.rb +26 -9
  25. data/app/models/kaui/payment.rb +2 -0
  26. data/app/models/kaui/payment_method.rb +18 -5
  27. data/app/models/kaui/transaction.rb +8 -0
  28. data/app/models/kaui/user.rb +4 -0
  29. data/app/views/kaui/accounts/_account_info.html.erb +23 -2
  30. data/app/views/kaui/accounts/_billing_info.html.erb +21 -0
  31. data/app/views/kaui/accounts/_form.html.erb +14 -8
  32. data/app/views/kaui/accounts/index.html.erb +5 -2
  33. data/app/views/kaui/admin/index.html.erb +39 -0
  34. data/app/views/kaui/admin/index.js.erb +3 -0
  35. data/app/views/kaui/admin_allowed_users/show.html.erb +2 -2
  36. data/app/views/kaui/admin_tenants/_tenant_details.html.erb +15 -0
  37. data/app/views/kaui/admin_tenants/_useful_links.html.erb +18 -0
  38. data/app/views/kaui/admin_tenants/new_catalog.html.erb +0 -1
  39. data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +0 -1
  40. data/app/views/kaui/admin_tenants/show.html.erb +42 -12
  41. data/app/views/kaui/home/index.html.erb +8 -1
  42. data/app/views/kaui/invoices/_invoice_table.html.erb +1 -1
  43. data/app/views/kaui/invoices/index.html.erb +13 -3
  44. data/app/views/kaui/invoices/show.html.erb +11 -1
  45. data/app/views/kaui/layouts/kaui_account_navbar.html.erb +4 -0
  46. data/app/views/kaui/layouts/kaui_navbar.html.erb +19 -12
  47. data/app/views/kaui/payments/_payment_table.html.erb +60 -50
  48. data/app/views/kaui/payments/index.html.erb +13 -3
  49. data/app/views/kaui/payments/show.html.erb +6 -0
  50. data/app/views/kaui/queues/index.html.erb +124 -0
  51. data/app/views/kaui/subscriptions/_edit_form.html.erb +4 -4
  52. data/app/views/kaui/subscriptions/_form.html.erb +3 -3
  53. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +25 -22
  54. data/app/views/kaui/subscriptions/edit_bcd.erb +29 -0
  55. data/app/views/kaui/tags/index.html.erb +7 -1
  56. data/app/views/kaui/transactions/_form.html.erb +16 -6
  57. data/config/routes.rb +23 -4
  58. data/kaui.gemspec +1 -1
  59. data/lib/kaui/version.rb +1 -1
  60. data/test/fixtures/catalog-v1.xml +0 -1
  61. metadata +161 -151
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf008611430663168c6e6f8ef1adca13ef8b0929
4
- data.tar.gz: 55cd8e91ff9c1798881a5e8af70dfede6f9576de
3
+ metadata.gz: 4208468a561fd0c2e15a06de685932b20eb28933
4
+ data.tar.gz: 32231b5c4acd5c8ed70e425c185e28cd2efd658d
5
5
  SHA512:
6
- metadata.gz: 90239db91f63b3eeff5170aa41f6e7b75b34c3b4f17eceabe1830f86134193c8a44f3e09c28450b4e6851fdec534e346cd599c97094dd28039f480dd38b690f0
7
- data.tar.gz: 7ee1407b3378494668e50879f686c6c33809ad3a3a086572c4abe9572b5a10c460298a5a6058977fe39c1ddcfc62195fc0cf7d461f4c062c6ebdc58ac4f20e23
6
+ metadata.gz: 3be5d4c9eb3f8c88cd3938403be9d22f36e61655e398a034dfd02b744a4ad309c6361858f70c5552cb781d3d5eede2cb333ad3f318d1ce1e553e0ceb806017c8
7
+ data.tar.gz: 50a33a56415bbde528bf403040b76695d0abe9c7e375920f658c60078015e173b8b6fa6f06a673012b2bf7f2438a0e44e1cc5b7d1e2bf1dad2c21480c91f9402
data/README.md CHANGED
@@ -6,10 +6,10 @@ Kaui core mountable engine. For Kaui the UI, see [killbill-admin-ui-standalone](
6
6
  Kill Bill compatibility
7
7
  -----------------------
8
8
 
9
- | API version | Kill Bill version |
10
- | ----------: | ----------------: |
11
- | 0.14.y | 0.16.z |
12
- | 0.15.y | 0.18.z |
9
+ | Kaui version | Kill Bill version |
10
+ | -----------: | ----------------: |
11
+ | 0.14.y | 0.16.z |
12
+ | 0.15.y | 0.18.z |
13
13
 
14
14
  Running Kaui locally
15
15
  ---------------------
@@ -77,12 +77,6 @@ a {
77
77
  }
78
78
  }
79
79
 
80
- small {
81
- font-size: 14px;
82
- display: inline-block;
83
- text-transform: uppercase;
84
- }
85
-
86
80
  span {
87
81
  &.success, &.fail {
88
82
  display: inline-block;
@@ -12,6 +12,20 @@
12
12
  }
13
13
  }
14
14
  }
15
+
16
+ table.table-small-padding {
17
+ th, td {
18
+ white-space: nowrap;
19
+
20
+ &:first-of-type {
21
+ padding-left: 20px;
22
+ }
23
+ }
24
+ }
25
+
26
+ tr.disabled {
27
+ background-color: #f5f5f5;
28
+ }
15
29
  }
16
30
 
17
31
  table.dataTable {
@@ -47,6 +47,10 @@
47
47
  }
48
48
  }
49
49
 
50
+ .legend {
51
+ margin-top: 40px;
52
+ }
53
+
50
54
  .duck_help {
51
55
  width: 352px;
52
56
  height: 260px;
@@ -2,6 +2,16 @@ class Kaui::AccountsController < Kaui::EngineController
2
2
 
3
3
  def index
4
4
  @search_query = params[:q]
5
+
6
+ @limit = 50
7
+ if @search_query.blank?
8
+ max_nb_records = Kaui::Account.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records
9
+ @offset = [0, max_nb_records - @limit].max
10
+ @ordering = 'desc'
11
+ else
12
+ @offset = 0
13
+ @ordering = 'asc'
14
+ end
5
15
  end
6
16
 
7
17
  def pagination
@@ -66,6 +76,33 @@ class Kaui::AccountsController < Kaui::EngineController
66
76
  run_in_parallel fetch_overdue_state, fetch_account_tags, fetch_account_emails, fetch_payment_methods, fetch_available_tags
67
77
  end
68
78
 
79
+ def trigger_invoice
80
+ account_id = params.require(:account_id)
81
+ target_date = params[:target_date].presence
82
+ dry_run = params[:dry_run] == '1'
83
+
84
+ invoice = nil
85
+ begin
86
+ invoice = dry_run ? Kaui::Invoice.trigger_invoice_dry_run(account_id, target_date, false, options_for_klient) :
87
+ Kaui::Invoice.trigger_invoice(account_id, target_date, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
88
+ rescue KillBillClient::API::NotFound
89
+ # Null invoice
90
+ end
91
+
92
+ if invoice.nil?
93
+ redirect_to account_path(account_id), :notice => "Nothing to generate for target date #{target_date.nil? ? 'today' : target_date}"
94
+ elsif dry_run
95
+ @invoice = Kaui::Invoice.build_from_raw_invoice(invoice)
96
+ @payments = []
97
+ @payment_methods = nil
98
+ @account = Kaui::Account.find_by_id(account_id, false, false, options_for_klient)
99
+ render :template => 'kaui/invoices/show'
100
+ else
101
+ # Redirect to fetch payments, etc.
102
+ redirect_to invoice_path(invoice.invoice_id, :account_id => account_id), :notice => "Generated invoice #{invoice.invoice_number} for target date #{invoice.target_date}"
103
+ end
104
+ end
105
+
69
106
  # Fetched asynchronously, as it takes time. This also helps with enforcing permissions.
70
107
  def next_invoice_date
71
108
  next_invoice = Kaui::Invoice.trigger_invoice_dry_run(params.require(:account_id), nil, true, options_for_klient)
@@ -25,7 +25,7 @@ class Kaui::AdminAllowedUsersController < Kaui::EngineController
25
25
 
26
26
  def show
27
27
  @allowed_user = Kaui::AllowedUser.find(params.require(:id))
28
- raise ActiveRecord::RecordNotFound.new("Could not find user #{@allowed_user.id}") unless (Kaui.root_username == current_user.kb_username || @allowed_user.kb_username == current_user.kb_username)
28
+ raise ActiveRecord::RecordNotFound.new("Could not find user #{@allowed_user.id}") unless (current_user.root? || @allowed_user.kb_username == current_user.kb_username)
29
29
 
30
30
  tenants_for_current_user = retrieve_tenants_for_current_user
31
31
  @tenants = Kaui::Tenant.all.select { |tenant| tenants_for_current_user.include?(tenant.kb_tenant_id) }
@@ -34,7 +34,7 @@ class Kaui::AdminAllowedUsersController < Kaui::EngineController
34
34
  def add_tenant
35
35
  allowed_user = Kaui::AllowedUser.find(params.require(:allowed_user).require(:id))
36
36
 
37
- if Kaui.root_username != current_user.kb_username
37
+ if !current_user.root?
38
38
  redirect_to admin_allowed_user_path(allowed_user.id), :alert => 'Only the root user can set tenants for user'
39
39
  return
40
40
  end
@@ -0,0 +1,27 @@
1
+ class Kaui::AdminController < Kaui::EngineController
2
+
3
+ skip_before_filter :check_for_redirect_to_tenant_screen
4
+
5
+ def index
6
+ @clock = Kaui::Admin.get_clock(nil, options_for_klient)
7
+
8
+ respond_to do |format|
9
+ format.html
10
+ format.js
11
+ end
12
+ end
13
+
14
+ def set_clock
15
+ if params[:commit] == 'Submit'
16
+ current_datetime = DateTime.parse(Kaui::Admin.get_clock(nil, options_for_klient)['currentUtcTime'])
17
+ new_local_date = Date.parse(params[:new_date])
18
+ new_datetime = DateTime.new(new_local_date.year, new_local_date.month, new_local_date.day, current_datetime.hour, current_datetime.min, current_datetime.sec, 'Z').to_s
19
+ msg = "Clock was successfully updated to #{new_datetime}"
20
+ else
21
+ new_datetime = nil
22
+ msg = 'Clock was successfully reset'
23
+ end
24
+ Kaui::Admin.set_clock(new_datetime, nil, options_for_klient)
25
+ redirect_to admin_path, :notice => msg
26
+ end
27
+ end
@@ -79,6 +79,9 @@ class Kaui::AdminTenantsController < Kaui::EngineController
79
79
 
80
80
  @plugin_config = Kaui::AdminTenant::get_oss_plugin_info(plugin_repository) rescue @plugin_config = ""
81
81
  @tenant_plugin_config = Kaui::AdminTenant::get_tenant_plugin_config(plugin_repository, options) rescue @tenant_plugin_config = ""
82
+
83
+ # When reloading page from the view, it sends the last tab that was active
84
+ @active_tab = params[:active_tab] || "CatalogShow"
82
85
  end
83
86
 
84
87
  def upload_catalog
@@ -97,6 +100,8 @@ class Kaui::AdminTenantsController < Kaui::EngineController
97
100
  end
98
101
 
99
102
  def new_catalog
103
+
104
+
100
105
  @tenant = safely_find_tenant_by_id(params[:id])
101
106
 
102
107
  options = tenant_options_for_client
@@ -115,7 +120,7 @@ class Kaui::AdminTenantsController < Kaui::EngineController
115
120
  latest_catalog.products.select { |p| p.type == 'STANDALONE' }.map { |p| p.name } : []
116
121
  @product_categories = [:BASE, :ADD_ON, :STANDALONE]
117
122
  @billing_period = [:DAILY, :WEEKLY, :BIWEEKLY, :THIRTY_DAYS, :MONTHLY, :QUARTERLY, :BIANNUAL, :ANNUAL, :BIENNIAL]
118
- @time_units = [:UNLIMITED, :DAYS, :MONTHS, :YEARS]
123
+ @time_units = [:UNLIMITED, :DAYS, :WEEKS, :MONTHS, :YEARS]
119
124
 
120
125
  @simple_plan = Kaui::SimplePlan.new
121
126
  end
@@ -257,7 +262,7 @@ class Kaui::AdminTenantsController < Kaui::EngineController
257
262
  current_tenant = safely_find_tenant_by_id(params[:id])
258
263
  au = Kaui::AllowedUser.find(params.require(:allowed_user).require(:id))
259
264
 
260
- if Kaui.root_username != current_user.kb_username
265
+ if !current_user.root?
261
266
  render :json => {:alert => 'Only the root user can remove users from tenants'}.to_json, :status => 401
262
267
  return
263
268
  end
@@ -280,6 +285,7 @@ class Kaui::AdminTenantsController < Kaui::EngineController
280
285
 
281
286
  private
282
287
 
288
+
283
289
  def safely_find_tenant_by_id(tenant_id)
284
290
  tenant = Kaui::Tenant.find_by_id(tenant_id)
285
291
  raise ActiveRecord::RecordNotFound.new('Could not find tenant ' + tenant_id) unless retrieve_tenants_for_current_user.include?(tenant.kb_tenant_id)
@@ -36,7 +36,7 @@ class Kaui::EngineController < ApplicationController
36
36
  end
37
37
 
38
38
  def retrieve_tenants_for_current_user
39
- if Kaui.root_username == current_user.kb_username
39
+ if current_user.root?
40
40
  Kaui::Tenant.all.map(&:kb_tenant_id)
41
41
  else
42
42
  Kaui::AllowedUser.preload(:kaui_tenants).find_by_kb_username(current_user.kb_username).kaui_tenants.map(&:kb_tenant_id)
@@ -49,7 +49,7 @@ class Kaui::EngineController < ApplicationController
49
49
  Kaui::AllowedUser.preload(:kaui_tenants).all.select do |user|
50
50
  tenants_for_user = user.kaui_tenants.map(&:kb_tenant_id)
51
51
  if tenants_for_user.empty?
52
- Kaui.root_username == current_user.kb_username
52
+ current_user.root?
53
53
  else
54
54
  (tenants_for_user - tenants_for_current_user).empty?
55
55
  end
@@ -38,7 +38,7 @@ module Kaui::EngineControllerUtil
38
38
  b = data_extractor.call(b, ordering_column)
39
39
  sort = a <=> b
40
40
  sort.nil? ? -1 : sort
41
- end
41
+ end unless search_key.nil? # Keep DB ordering when listing all entries
42
42
  pages.reverse! if ordering_dir == 'desc'
43
43
 
44
44
  pages.each { |page| json[:data] << formatter.call(page) }
@@ -10,6 +10,8 @@ class Kaui::HomeController < Kaui::EngineController
10
10
  redirect_to invoice_path(:id => search_query)
11
11
  elsif search_type == 'payment'
12
12
  redirect_to payment_path(:id => search_query)
13
+ elsif search_type == 'transaction'
14
+ redirect_to transaction_path(:id => search_query)
13
15
  else
14
16
  redirect_to accounts_path(:q => search_query)
15
17
  end
@@ -18,6 +20,6 @@ class Kaui::HomeController < Kaui::EngineController
18
20
  private
19
21
 
20
22
  def parse_query(query)
21
- /((invoice|payment):)?(.*)/.match(query).captures.drop(1)
23
+ /((invoice|payment|transaction):)?(.*)/.match(query).captures.drop(1)
22
24
  end
23
25
  end
@@ -2,6 +2,16 @@ class Kaui::InvoicesController < Kaui::EngineController
2
2
 
3
3
  def index
4
4
  @search_query = params[:account_id]
5
+
6
+ @limit = 50
7
+ if @search_query.blank?
8
+ max_nb_records = Kaui::Invoice.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records
9
+ @offset = [0, max_nb_records - @limit].max
10
+ @ordering = 'desc'
11
+ else
12
+ @offset = 0
13
+ @ordering = 'asc'
14
+ end
5
15
  end
6
16
 
7
17
  def pagination
@@ -1,16 +1,39 @@
1
1
  class Kaui::PaymentsController < Kaui::EngineController
2
2
 
3
3
  def index
4
- @search_query = params[:account_id]
4
+ @search_query = params[:q] || params[:account_id]
5
+
6
+ @limit = 50
7
+ if @search_query.blank?
8
+ max_nb_records = Kaui::Payment.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records
9
+ @offset = [0, max_nb_records - @limit].max
10
+ @ordering = 'desc'
11
+ else
12
+ @offset = 0
13
+ @ordering = 'asc'
14
+ end
5
15
  end
6
16
 
7
17
  def pagination
8
18
  searcher = lambda do |search_key, offset, limit|
9
- account = Kaui::Account::find_by_id_or_key(search_key, false, false, options_for_klient) rescue nil
10
- if account.nil?
11
- payments = Kaui::Payment.list_or_search(search_key, offset, limit, options_for_klient)
19
+ if Kaui::Payment::TRANSACTION_STATUSES.include?(search_key)
20
+ # Search is done by payment state on the server side, see http://docs.killbill.io/latest/userguide_payment.html#_payment_states
21
+ payment_state = if %w(PLUGIN_FAILURE UNKNOWN).include?(search_key)
22
+ '_ERRORED'
23
+ elsif search_key == 'PAYMENT_FAILURE'
24
+ '_FAILED'
25
+ else
26
+ '_' + search_key
27
+ end
28
+ payments = Kaui::Payment.list_or_search(payment_state, offset, limit, options_for_klient)
29
+ payments.reject! { |payment| payment.transactions[-1].status != search_key }
12
30
  else
13
- payments = account.payments(options_for_klient).map! { |payment| Kaui::Payment.build_from_raw_payment(payment) }
31
+ account = Kaui::Account::find_by_id_or_key(search_key, false, false, options_for_klient) rescue nil
32
+ if account.nil?
33
+ payments = Kaui::Payment.list_or_search(search_key, offset, limit, options_for_klient)
34
+ else
35
+ payments = account.payments(options_for_klient).map! { |payment| Kaui::Payment.build_from_raw_payment(payment) }
36
+ end
14
37
  end
15
38
 
16
39
  payments.each do |payment|
@@ -65,11 +88,12 @@ class Kaui::PaymentsController < Kaui::EngineController
65
88
  end
66
89
 
67
90
  def show
68
- @payment = Kaui::InvoicePayment.build_from_raw_payment(Kaui::InvoicePayment.find_by_id(params.require(:id), true, true, options_for_klient))
91
+ invoice_payment = Kaui::InvoicePayment.find_safely_by_id(params.require(:id), options_for_klient)
92
+ @payment = Kaui::InvoicePayment.build_from_raw_payment(invoice_payment)
69
93
 
70
94
  fetch_account = lambda { @account = Kaui::Account.find_by_id(@payment.account_id, false, false, options_for_klient) }
71
95
  # The payment method may have been deleted
72
- fetch_payment_method = lambda { @payment_method = Kaui::PaymentMethod.find_by_id(@payment.payment_method_id, true, options_for_klient) rescue nil }
96
+ fetch_payment_method = lambda { @payment_method = Kaui::PaymentMethod.find_safely_by_id(@payment.payment_method_id, options_for_klient) }
73
97
 
74
98
  run_in_parallel fetch_account, fetch_payment_method
75
99
  end
@@ -0,0 +1,11 @@
1
+ class Kaui::QueuesController < Kaui::EngineController
2
+
3
+ def index
4
+ @account_id = params[:account_id]
5
+ @now = Kaui::Admin.get_clock(nil, options_for_klient)['currentUtcTime'].to_datetime
6
+
7
+ min_date = params[:min_date]
8
+ with_history = params[:with_history] || false
9
+ @queues_entries = Kaui::Admin.get_queues_entries(@account_id, options_for_klient.merge(:withHistory => with_history, :minDate => min_date))
10
+ end
11
+ end
@@ -77,8 +77,10 @@ class Kaui::SubscriptionsController < Kaui::EngineController
77
77
 
78
78
  def destroy
79
79
  requested_date = params[:requested_date].presence
80
- entitlement_policy = params[:policy].presence
81
- billing_policy = entitlement_policy
80
+ billing_policy = params[:policy].presence
81
+ # START_OF_TERM is *not* a valid entitlement_policy and so would default to IMMEDIATE
82
+ entitlement_policy = billing_policy && billing_policy == 'START_OF_TERM' ? 'IMMEDIATE' : billing_policy
83
+
82
84
  # true by default
83
85
  use_requested_date_for_billing = (params[:use_requested_date_for_billing] || '1') == '1'
84
86
 
@@ -97,6 +99,22 @@ class Kaui::SubscriptionsController < Kaui::EngineController
97
99
  redirect_to kaui_engine.account_bundles_path(subscription.account_id), :notice => 'Subscription was successfully reinstated'
98
100
  end
99
101
 
102
+ def edit_bcd
103
+ @subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
104
+ end
105
+
106
+ def update_bcd
107
+ input_subscription = params.require(:subscription)
108
+ subscription = Kaui::Subscription.new
109
+ subscription.subscription_id = params.require(:id)
110
+ subscription.bill_cycle_day_local = input_subscription["bill_cycle_day_local"]
111
+
112
+ effective_from_date = params["effective_from_date"]
113
+
114
+ subscription.update_bcd(current_user.kb_username, params[:reason], params[:comment], effective_from_date, nil, options_for_klient)
115
+ redirect_to kaui_engine.account_bundles_path(input_subscription["account_id"]), :notice => 'Subscription BCD was successfully changed'
116
+ end
117
+
100
118
  def show
101
119
  restful_show
102
120
  end
@@ -1,6 +1,17 @@
1
1
  class Kaui::TagsController < Kaui::EngineController
2
2
 
3
3
  def index
4
+ @search_query = params[:q]
5
+
6
+ @limit = 50
7
+ if @search_query.blank?
8
+ max_nb_records = Kaui::Tag.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records
9
+ @offset = [0, max_nb_records - @limit].max
10
+ @ordering = 'desc'
11
+ else
12
+ @offset = 0
13
+ @ordering = 'asc'
14
+ end
4
15
  end
5
16
 
6
17
  def pagination
@@ -1,12 +1,24 @@
1
1
  class Kaui::TransactionsController < Kaui::EngineController
2
2
 
3
+ def restful_show
4
+ payment = Kaui::Payment.find_by_transaction_id(params.require(:id), false, true, options_for_klient)
5
+ redirect_to account_payment_path(payment.account_id, payment.payment_id)
6
+ end
7
+
3
8
  def new
4
9
  @account_id = params[:account_id]
5
10
  @payment_method_id = params[:payment_method_id]
6
- @transaction = Kaui::Transaction.new(:payment_id => params[:payment_id],
7
- :amount => params[:amount],
8
- :currency => params[:currency],
9
- :transaction_type => params[:transaction_type])
11
+
12
+ transaction_id = params[:transaction_id].presence
13
+ if transaction_id.nil?
14
+ @transaction = Kaui::Transaction.new(:payment_id => params[:payment_id],
15
+ :amount => params[:amount],
16
+ :currency => params[:currency],
17
+ :transaction_type => params[:transaction_type])
18
+ else
19
+ payment = Kaui::Payment.find_by_transaction_id(transaction_id, false, false, options_for_klient)
20
+ @transaction = Kaui::Transaction.build_from_raw_transaction(payment.transactions.find { |tx| tx.transaction_id == transaction_id })
21
+ end
10
22
  end
11
23
 
12
24
  def create
@@ -15,4 +27,15 @@ class Kaui::TransactionsController < Kaui::EngineController
15
27
  payment = transaction.create(params.require(:account_id), params[:payment_method_id], current_user.kb_username, params[:reason], params[:comment], options_for_klient)
16
28
  redirect_to kaui_engine.account_payment_path(payment.account_id, payment.payment_id), :notice => 'Transaction successfully created'
17
29
  end
30
+
31
+ def fix_transaction_state
32
+ transaction = Kaui::Transaction.new(params[:transaction].delete_if { |key, value| value.blank? })
33
+ payment_id = transaction.payment_id
34
+ transaction_id = transaction.transaction_id
35
+ transaction_status = transaction.status
36
+
37
+ Kaui::Admin.fix_transaction_state(payment_id, transaction_id, transaction_status, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
38
+
39
+ redirect_to kaui_engine.account_payment_path(params.require(:account_id), payment_id), :notice => "Transaction successfully transitioned to #{transaction_status}"
40
+ end
18
41
  end