kaui 0.1.18 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +30 -0
  3. data/Gemfile +21 -0
  4. data/Gemfile.lock +107 -0
  5. data/README.md +60 -0
  6. data/app/assets/images/kaui/.gitkeep +0 -0
  7. data/{test/dummy/tmp/cache/assets/D07/DA0/sprockets%2Ffaad9b18203975dbf0c60f3234a51874 → app/assets/javascripts/kaui/analytics.js} +0 -0
  8. data/{test/dummy/tmp/cache/assets/C8D/080/sprockets%2F4556c595251e3b8d4f688467e330da26 → app/assets/javascripts/kaui/bootstrap-tweaks.js} +0 -0
  9. data/app/assets/javascripts/kaui/validation.js +21 -0
  10. data/app/assets/stylesheets/kaui/analytics.css +26 -0
  11. data/app/controllers/kaui/accounts_controller.rb +0 -3
  12. data/app/controllers/kaui/analytics_controller.rb +20 -11
  13. data/app/controllers/kaui/engine_controller.rb +13 -4
  14. data/app/controllers/kaui/invoices_controller.rb +1 -1
  15. data/app/controllers/kaui/refunds_controller.rb +16 -1
  16. data/app/controllers/kaui/subscriptions_controller.rb +6 -0
  17. data/app/controllers/kaui/tag_definitions_controller.rb +7 -2
  18. data/app/helpers/kaui/date_helper.rb +2 -3
  19. data/app/helpers/kaui/killbill_helper.rb +0 -3
  20. data/app/models/kaui/account.rb +0 -2
  21. data/app/models/kaui/account_timeline.rb +0 -2
  22. data/app/models/kaui/audit_log.rb +0 -2
  23. data/app/models/kaui/bundle.rb +0 -2
  24. data/app/models/kaui/invoice.rb +1 -3
  25. data/app/models/kaui/invoice_item.rb +1 -3
  26. data/app/models/kaui/payment.rb +7 -3
  27. data/app/models/kaui/payment_attempt.rb +1 -3
  28. data/app/models/kaui/payment_method.rb +1 -3
  29. data/app/models/kaui/plugin_info.rb +1 -3
  30. data/app/models/kaui/plugin_info_property.rb +1 -3
  31. data/app/models/kaui/refund.rb +1 -3
  32. data/app/models/kaui/time_series_data.rb +5 -1
  33. data/app/views/kaui/account_timelines/show.html.erb +10 -10
  34. data/app/views/kaui/accounts/show.html.erb +1 -1
  35. data/app/views/kaui/bundles/show.html.erb +1 -1
  36. data/app/views/kaui/home/index.html.erb +10 -0
  37. data/app/views/kaui/invoices/show.html.erb +6 -6
  38. data/app/views/kaui/layouts/kaui_application.html.erb +48 -0
  39. data/app/views/kaui/payments/_payments_table.html.erb +2 -2
  40. data/app/views/kaui/refunds/show.html.erb +2 -2
  41. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +20 -39
  42. data/app/views/kaui/subscriptions/show.html.erb +2 -2
  43. data/bin/kaui +4 -0
  44. data/config/routes.rb +2 -2
  45. data/kaui.gemspec +27 -0
  46. data/lib/generators/kaui/install/install_generator.rb +68 -0
  47. data/lib/generators/kaui/install/templates/app/assets/javascripts/kaui/all.js +16 -0
  48. data/lib/generators/kaui/install/templates/app/assets/stylesheets/kaui/all.css +11 -0
  49. data/lib/generators/kaui/install/templates/config/initializers/kaui.rb +3 -0
  50. data/lib/kaui/engine.rb +12 -0
  51. data/lib/kaui/installer/installer.rb +82 -0
  52. data/lib/kaui/version.rb +1 -1
  53. data/lib/kaui.rb +13 -1
  54. data/script/rails +8 -0
  55. data/script/sandbox +25 -0
  56. data/test/dummy/app/assets/javascripts/application.js +5 -3
  57. data/test/dummy/app/assets/stylesheets/application.css +2 -1
  58. data/test/dummy/app/mailers/.gitkeep +0 -0
  59. data/test/dummy/app/models/.gitkeep +0 -0
  60. data/test/dummy/lib/assets/.gitkeep +0 -0
  61. data/test/dummy/log/.gitkeep +0 -0
  62. data/test/test_helper.rb +18 -0
  63. data/{test/dummy/vendor → vendor}/assets/images/img/glyphicons-halflings-white.png +0 -0
  64. data/{test/dummy/vendor → vendor}/assets/images/img/glyphicons-halflings.png +0 -0
  65. data/vendor/assets/javascripts/js/bootstrap-datepicker.cd46d38.js +1211 -0
  66. data/{test/dummy/vendor/assets/javascripts → vendor/assets/javascripts/js}/bootstrap.v2.0.4.min.js +0 -0
  67. data/{test/dummy/vendor/assets/javascripts → vendor/assets/javascripts/js}/jquery.dataTables.v1.9.3.min.js +0 -0
  68. data/vendor/assets/stylesheets/css/bootstrap-datepicker.cd46d38.css +274 -0
  69. data/{test/dummy/vendor/assets/stylesheets → vendor/assets/stylesheets/css}/bootstrap.v2.0.4.min.css +0 -0
  70. metadata +131 -130
  71. data/README.rdoc +0 -36
  72. data/app/assets/javascripts/kaui/account_timeline.js +0 -2
  73. data/app/assets/javascripts/kaui/application.js +0 -15
  74. data/app/assets/javascripts/kaui/bundles.js +0 -2
  75. data/app/assets/javascripts/kaui/chargebacks.js +0 -2
  76. data/app/assets/javascripts/kaui/extpayments.js +0 -2
  77. data/app/assets/javascripts/kaui/home.js +0 -2
  78. data/app/assets/javascripts/kaui/invoices.js +0 -2
  79. data/app/assets/javascripts/kaui/payments.js +0 -2
  80. data/app/assets/javascripts/kaui/refunds.js +0 -2
  81. data/app/assets/stylesheets/kaui/account_timeline.css +0 -4
  82. data/app/assets/stylesheets/kaui/application.css +0 -13
  83. data/app/assets/stylesheets/kaui/bundles.css +0 -4
  84. data/app/assets/stylesheets/kaui/chargebacks.css +0 -4
  85. data/app/assets/stylesheets/kaui/extpayments.css +0 -4
  86. data/app/assets/stylesheets/kaui/home.css +0 -4
  87. data/app/assets/stylesheets/kaui/invoices.css +0 -4
  88. data/app/assets/stylesheets/kaui/payments.css +0 -4
  89. data/app/assets/stylesheets/kaui/refunds.css +0 -4
  90. data/app/controllers/kaui/tags_controller.rb +0 -85
  91. data/app/views/kaui/account_emails/edit.html.erb +0 -6
  92. data/app/views/kaui/analytics/payments_over_time.html.erb +0 -9
  93. data/app/views/kaui/tags/_form.html.erb +0 -25
  94. data/app/views/kaui/tags/edit.html.erb +0 -6
  95. data/app/views/kaui/tags/index.html.erb +0 -25
  96. data/app/views/kaui/tags/new.html.erb +0 -5
  97. data/app/views/kaui/tags/show.html.erb +0 -15
  98. data/test/dummy/log/development.log +0 -99013
  99. data/test/dummy/log/test.log +0 -127459
  100. data/test/dummy/tmp/cache/assets/C94/4E0/sprockets%2Fea1476dc10a3348303f74d111f70441a +0 -0
  101. data/test/dummy/tmp/cache/assets/C95/690/sprockets%2Fc4b083702793f7599f4a3069c50f89a8 +0 -0
  102. data/test/dummy/tmp/cache/assets/CAA/680/sprockets%2F3824d037523f650518fb22acab75559d +0 -0
  103. data/test/dummy/tmp/cache/assets/CC2/520/sprockets%2F9637f46d37325381f96d96d94ae0bc50 +0 -0
  104. data/test/dummy/tmp/cache/assets/CD0/9D0/sprockets%2F5c9508c21501c73fbe00473a09b1f5f4 +0 -0
  105. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  106. data/test/dummy/tmp/cache/assets/CDF/1F0/sprockets%2F76ac5628a0c4d1b976cb622ec4493751 +0 -381
  107. data/test/dummy/tmp/cache/assets/CE0/8A0/sprockets%2Fc18dc7330236e7db17d280973d617b9a +0 -0
  108. data/test/dummy/tmp/cache/assets/CEA/300/sprockets%2Fdf2ad5c9d0990441c2bf59883383d652 +0 -0
  109. data/test/dummy/tmp/cache/assets/CEC/5B0/sprockets%2F1695e8510891108e3950e2a3e4fdf9df +0 -0
  110. data/test/dummy/tmp/cache/assets/CF7/710/sprockets%2F86d43448e1fc383cb6f3d752ef288882 +0 -0
  111. data/test/dummy/tmp/cache/assets/CFF/A00/sprockets%2F642f58fb154eff788f45c881b294e818 +0 -0
  112. data/test/dummy/tmp/cache/assets/D04/1D0/sprockets%2F3baf64d90ead2434455d2296227ba8a2 +0 -7038
  113. data/test/dummy/tmp/cache/assets/D05/510/sprockets%2F1c14866e2401c27b0ff5e33d1b92c4e8 +0 -0
  114. data/test/dummy/tmp/cache/assets/D17/DD0/sprockets%2F665455ecdc7609b23f4ecb366d86055a +0 -9409
  115. data/test/dummy/tmp/cache/assets/D32/200/sprockets%2Ffa467106e01bda5d6246baea72159d64 +0 -0
  116. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  117. data/test/dummy/tmp/cache/assets/D39/5E0/sprockets%2F59fd338be48a81a17a2a785cbd1612b4 +0 -0
  118. data/test/dummy/tmp/cache/assets/D44/170/sprockets%2Fac15571bce3f926a498da7cd09322d97 +0 -0
  119. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  120. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  121. data/test/dummy/tmp/cache/assets/D6C/710/sprockets%2F1765773caead06c0a6a19ea9de2453f7 +0 -0
  122. data/test/dummy/tmp/cache/assets/D76/910/sprockets%2Ff99b4bdc434e11e8634e6af62fe805e0 +0 -0
  123. data/test/dummy/tmp/cache/assets/D79/1E0/sprockets%2F97b08ebe07a73d8195ba124ffb45f98b +0 -7038
  124. data/test/dummy/tmp/cache/assets/D9F/160/sprockets%2F510462e1ebd5dbb7ae20888b77f9bed2 +0 -0
  125. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  126. data/test/dummy/tmp/cache/assets/DDF/650/sprockets%2Fbe16f0bf3d2b7af18010acbd53ba22f5 +0 -0
  127. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  128. data/test/dummy/tmp/cache/assets/E07/1E0/sprockets%2F5a3fe6e98fdf72bbe75c605e54ebc5b0 +0 -9409
  129. data/test/dummy/tmp/cache/assets/E10/BE0/sprockets%2F9c06f8f8da4e736ccf6de8360cd39bfa +0 -0
  130. data/test/dummy/tmp/cache/assets/E20/230/sprockets%2F7d3b1348fdf74cf1b6ba2107fbbac5af +0 -0
  131. data/test/dummy/tmp/cache/assets/E22/F40/sprockets%2Faffacf2e6be325520bd3bfd2096b6dd4 +0 -0
  132. data/test/dummy/tmp/cache/assets/E24/9D0/sprockets%2Fb966ab0a50fda3c156fbad4d8ab73ef6 +0 -381
  133. data/test/functional/kaui/account_emails_controller_test.rb +0 -51
  134. data/test/functional/kaui/tags_controller_test.rb +0 -51
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/
7
+ test/dummy/.sass-cache
8
+ .idea
9
+ sandbox
10
+ foo
data/.travis.yml ADDED
@@ -0,0 +1,30 @@
1
+ language: ruby
2
+
3
+ notifications:
4
+ email:
5
+ - ri-dev@ning.com
6
+
7
+ rvm:
8
+ - 1.9.3
9
+ - 1.9.2
10
+ - jruby-18mode
11
+ - jruby-19mode
12
+ - ruby-head
13
+ - jruby-head
14
+ - 1.8.7
15
+
16
+ jdk:
17
+ - openjdk7
18
+ - oraclejdk7
19
+ - openjdk6
20
+
21
+ before_script:
22
+ - mysql -e 'create database kaui_test;'
23
+
24
+ matrix:
25
+ allow_failures:
26
+ - rvm: ruby-head
27
+ - rvm: jruby-head
28
+
29
+ env:
30
+ - MYSQL_PASSWORD=''
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 3.2.3"
4
+ gem 'rest-client', '~> 1.6.7'
5
+ gem 'money-rails', '~> 0.5.0'
6
+ gem 'd3_rails', '~> 2.10.0'
7
+
8
+ group :development, :test do
9
+ # jquery-rails is used by the dummy application
10
+ gem "jquery-rails"
11
+
12
+ if defined?(JRUBY_VERSION)
13
+ gem "jruby-openssl", "~> 0.7.7"
14
+
15
+ gem 'activerecord-jdbc-adapter', '~> 1.2.2'
16
+ gem 'activerecord-jdbcmysql-adapter', '~> 1.2.2'
17
+ gem 'jdbc-mysql', :require => false
18
+ else
19
+ gem 'mysql2'
20
+ end
21
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,107 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.3)
5
+ actionpack (= 3.2.3)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.3)
8
+ activemodel (= 3.2.3)
9
+ activesupport (= 3.2.3)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.1)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.2)
17
+ activemodel (3.2.3)
18
+ activesupport (= 3.2.3)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.3)
21
+ activemodel (= 3.2.3)
22
+ activesupport (= 3.2.3)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.3)
26
+ activemodel (= 3.2.3)
27
+ activesupport (= 3.2.3)
28
+ activesupport (3.2.3)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.0)
33
+ d3_rails (2.10.0)
34
+ railties (>= 3.1.0)
35
+ erubis (2.7.0)
36
+ hike (1.2.1)
37
+ i18n (0.6.0)
38
+ journey (1.0.3)
39
+ jquery-rails (2.0.2)
40
+ railties (>= 3.2.0, < 5.0)
41
+ thor (~> 0.14)
42
+ json (1.7.0)
43
+ json (1.7.0-java)
44
+ mail (2.4.4)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.18)
49
+ money (5.0.0)
50
+ i18n (~> 0.4)
51
+ json
52
+ money-rails (0.5.0)
53
+ activesupport (~> 3.0)
54
+ money (~> 5.0.0)
55
+ railties (~> 3.0)
56
+ multi_json (1.3.4)
57
+ mysql2 (0.3.11)
58
+ polyglot (0.3.3)
59
+ rack (1.4.1)
60
+ rack-cache (1.2)
61
+ rack (>= 0.4)
62
+ rack-ssl (1.3.2)
63
+ rack
64
+ rack-test (0.6.1)
65
+ rack (>= 1.0)
66
+ rails (3.2.3)
67
+ actionmailer (= 3.2.3)
68
+ actionpack (= 3.2.3)
69
+ activerecord (= 3.2.3)
70
+ activeresource (= 3.2.3)
71
+ activesupport (= 3.2.3)
72
+ bundler (~> 1.0)
73
+ railties (= 3.2.3)
74
+ railties (3.2.3)
75
+ actionpack (= 3.2.3)
76
+ activesupport (= 3.2.3)
77
+ rack-ssl (~> 1.3.2)
78
+ rake (>= 0.8.7)
79
+ rdoc (~> 3.4)
80
+ thor (~> 0.14.6)
81
+ rake (0.9.2.2)
82
+ rdoc (3.12)
83
+ json (~> 1.4)
84
+ rest-client (1.6.7)
85
+ mime-types (>= 1.16)
86
+ sprockets (2.1.3)
87
+ hike (~> 1.2)
88
+ rack (~> 1.0)
89
+ tilt (~> 1.1, != 1.3.0)
90
+ thor (0.14.6)
91
+ tilt (1.3.3)
92
+ treetop (1.4.10)
93
+ polyglot
94
+ polyglot (>= 0.3.1)
95
+ tzinfo (0.3.33)
96
+
97
+ PLATFORMS
98
+ java
99
+ ruby
100
+
101
+ DEPENDENCIES
102
+ d3_rails (~> 2.10.0)
103
+ jquery-rails
104
+ money-rails (~> 0.5.0)
105
+ mysql2
106
+ rails (~> 3.2.3)
107
+ rest-client (~> 1.6.7)
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ Getting started
2
+ ===============
3
+
4
+ Running Kaui
5
+ ------------
6
+
7
+ You can run Kaui locally using the dummy app in the test directory:
8
+
9
+ # Point to your killbill installation
10
+ export KILLBILL_URL="http://killbill.company.com:8080"
11
+ cd test/dummy && rails s
12
+
13
+
14
+ Mounting Kaui into your own Rails app
15
+ -------------------------------------
16
+
17
+ The Kaui gem comes with a `kaui` script to mount it in your existing Rails app. See the [Getting Started](http://killbilling.org/start.html#kaui_deployment) guide.
18
+
19
+ Kaui expects the container app to define the <tt>current_user</tt> method, which returns the
20
+ name of the logged-in user. This is used by Killbill for auditing purposes.
21
+
22
+ Finally, Killbill server needs to be running for Kaui to fetch its information. Set the `KILLBILL_URL`
23
+ variable to point to your existing Killbill installation (e.g. http://killbill.company.com:8080).
24
+
25
+
26
+ Running tests
27
+ -------------
28
+
29
+ Prepare a kaui_test database locally to be able to run the test suite:
30
+
31
+ create database kaui_test;
32
+ grant all privileges on kaui_test.* to 'root'@'localhost' identified by '';
33
+
34
+ You can run tests using rake:
35
+
36
+ rake test
37
+
38
+
39
+ Development
40
+ ===========
41
+
42
+ Working with the kaui script
43
+ ----------------------------
44
+
45
+ In order to generate the Rubygems-friendly `kaui` script, you need to build the gem
46
+ and install it locally.
47
+
48
+ First, build the gem in the `pkg` directory:
49
+
50
+ rake build
51
+
52
+ Then, install and run it from a local directory:
53
+
54
+ mkdir foo
55
+ gem install pkg/kaui-*.gem -i foo
56
+ GEM_PATH=$PWD/foo:$GEM_PATH ./foo/bin/kaui /path/to/rails/app --path=$PWD --skip-bundle
57
+
58
+ Alternatively, you can run the `kaui` script under `bin` by setting your loadpath correctly:
59
+
60
+ ruby -Ilib bin/kaui /path/to/rails/app --path=$PWD --skip-bundle
File without changes
@@ -0,0 +1,21 @@
1
+ // Restrict numeric input for a text field
2
+ // TODO - consider switching to HTML5's <input type="number" />
3
+ function preventNonNumericValues(event) {
4
+ // Allow: backspace, delete, tab, escape, and enter
5
+ if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
6
+ // Allow: Ctrl+A
7
+ (event.keyCode == 65 && event.ctrlKey === true) ||
8
+ // Allow dot
9
+ (event.keyCode == 190) ||
10
+ // Allow: home, end, left, right
11
+ (event.keyCode >= 35 && event.keyCode <= 39)) {
12
+ // let it happen, don't do anything
13
+ return;
14
+ }
15
+ else {
16
+ // Ensure that it is a number and stop the keypress
17
+ if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
18
+ event.preventDefault();
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,26 @@
1
+ path {
2
+ stroke: steelblue;
3
+ stroke-width: 1;
4
+ fill: none;
5
+ }
6
+
7
+ .axis {
8
+ shape-rendering: crispEdges;
9
+ }
10
+
11
+ .x.axis line {
12
+ stroke: lightgrey;
13
+ }
14
+
15
+ .x.axis .minor {
16
+ stroke-opacity: .5;
17
+ }
18
+
19
+ .x.axis path {
20
+ display: none;
21
+ }
22
+
23
+ .y.axis line, .y.axis path {
24
+ fill: none;
25
+ stroke: #000;
26
+ }
@@ -1,6 +1,3 @@
1
- require 'rest_client'
2
- require 'json'
3
-
4
1
  class Kaui::AccountsController < Kaui::EngineController
5
2
  def index
6
3
  if params[:account_id].present?
@@ -1,22 +1,31 @@
1
1
  module Kaui
2
- class AnalyticsController < ApplicationController
2
+ class AnalyticsController < Kaui::EngineController
3
3
  def index
4
4
  @slugs = []
5
- catalog = Kaui::KillbillHelper::get_full_catalog()
6
- catalog['products'].each do |product|
7
- product['plans'].each do |plan|
8
- name = plan['name']
9
- plan['phases'].each do |phase|
10
- type = phase['type']
11
- @slugs << "#{name.downcase}-#{type.downcase}"
5
+ begin
6
+ catalog = Kaui::KillbillHelper::get_full_catalog()
7
+ catalog['products'].each do |product|
8
+ product['plans'].each do |plan|
9
+ name = plan['name']
10
+ plan['phases'].each do |phase|
11
+ type = phase['type']
12
+ @slugs << "#{name.downcase}-#{type.downcase}"
13
+ end
12
14
  end
13
15
  end
16
+ @product_type = catalog['name']
17
+ rescue => e
18
+ flash[:error] = "Error while retrieving catalog: #{as_string(e)}"
14
19
  end
15
- @product_type = catalog['name']
16
20
  end
17
21
 
18
22
  def accounts_over_time
19
- @accounts = Analytics.accounts_over_time
23
+ begin
24
+ @accounts = Analytics.accounts_over_time
25
+ rescue => e
26
+ flash[:error] = "Error while retrieving data: #{as_string(e)}"
27
+ @accounts = Kaui::TimeSeriesData.empty
28
+ end
20
29
  end
21
30
 
22
31
  def subscriptions_over_time
@@ -25,4 +34,4 @@ module Kaui
25
34
  @subscriptions = Analytics.subscriptions_over_time(@product_type, @slug)
26
35
  end
27
36
  end
28
- end
37
+ end
@@ -2,8 +2,17 @@ require 'kaui/error_helper'
2
2
 
3
3
  class Kaui::EngineController < ApplicationController
4
4
  include Kaui::ErrorHelper
5
- # This is a semi-isolated engine (https://bibwild.wordpress.com/2012/05/10/the-semi-isolated-rails-engine/)
6
- # We expect that the hosting app's ApplicationController has these methods defined:
7
- #
8
- # current_user - returns the id of the current user
5
+
6
+ layout :get_layout
7
+
8
+ # Used for auditing purposes
9
+ def current_user
10
+ super rescue Kaui.config[:default_current_user]
11
+ end
12
+
13
+ protected
14
+
15
+ def get_layout
16
+ layout ||= Kaui.config[:layout]
17
+ end
9
18
  end
@@ -36,7 +36,7 @@ class Kaui::InvoicesController < Kaui::EngineController
36
36
  render :action => :index
37
37
  end
38
38
  rescue => e
39
- flash[:error] = "Error while getting information for invoice #{invoice_id}: #{as_string(e)}"
39
+ flash[:error] = "Error while getting information for invoice #{@invoice_id}: #{as_string(e)}"
40
40
  end
41
41
  else
42
42
  flash[:error] = "No id given"
@@ -19,10 +19,25 @@ class Kaui::RefundsController < Kaui::EngineController
19
19
  @refunds = Kaui::KillbillHelper::get_refunds_for_payment(params[:id])
20
20
  unless @refunds.present?
21
21
  flash[:error] = "Refund for id or payment id #{params[:id]} couldn't be found"
22
- render :action => :index
22
+ render :action => :index and return
23
23
  end
24
24
  rescue => e
25
25
  flash[:error] = "Error while retrieving the refunds for the payment: #{as_string(e)}"
26
+ render :action => :index and return
27
+ end
28
+ end
29
+
30
+ if @refunds.size > 0
31
+ begin
32
+ # Retrieve the account via the payment
33
+ payment = Kaui::KillbillHelper::get_payment(@refunds[0].payment_id)
34
+ unless payment.present?
35
+ flash[:error] = "Account for payment id #{@refunds[0].payment_id} couldn't be found"
36
+ render :action => :index
37
+ end
38
+ @account = Kaui::KillbillHelper::get_account(payment.account_id)
39
+ rescue => e
40
+ flash[:error] = "Error while retrieving the account for the refund: #{as_string(e)}"
26
41
  render :action => :index
27
42
  end
28
43
  end
@@ -14,6 +14,12 @@ class Kaui::SubscriptionsController < Kaui::EngineController
14
14
  flash[:error] = "No subscription id given or subscription not found"
15
15
  redirect_to :back
16
16
  end
17
+
18
+ @account = Kaui::KillbillHelper::get_account_by_bundle_id(@subscription.bundle_id)
19
+ unless @account.present?
20
+ flash[:error] = "Unable to retrieve account for bundle #{@subscription.bundle_id}"
21
+ redirect_to :back
22
+ end
17
23
  rescue => e
18
24
  flash[:error] = "Error while getting subscription information: #{as_string(e)}"
19
25
  end
@@ -1,9 +1,14 @@
1
1
  module Kaui
2
- class TagDefinitionsController < ApplicationController
2
+ class TagDefinitionsController < Kaui::EngineController
3
3
  # GET /tag_definitions
4
4
  # GET /tag_definitions.json
5
5
  def index
6
- @tag_definitions = TagDefinition.all
6
+ begin
7
+ @tag_definitions = TagDefinition.all
8
+ rescue => e
9
+ flash[:error] = "Error while retrieving tag definitions: #{as_string(e)}"
10
+ @tag_definitions = []
11
+ end
7
12
 
8
13
  respond_to do |format|
9
14
  format.html # index.html.erb
@@ -1,8 +1,7 @@
1
1
  module Kaui
2
2
  module DateHelper
3
- def format_date(date)
4
- # TODO: make timezone configurable
5
- parsed_date = DateTime.parse(date.to_s).in_time_zone("Pacific Time (US & Canada)")
3
+ def format_date(date, timezone="Pacific Time (US & Canada)")
4
+ parsed_date = DateTime.parse(date.to_s).in_time_zone(timezone)
6
5
  parsed_date.to_s(:date_only)
7
6
  end
8
7
  end
@@ -1,6 +1,3 @@
1
- require 'rest_client'
2
- require 'time'
3
-
4
1
  module Kaui
5
2
  module KillbillHelper
6
3
 
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::Account < Kaui::Base
4
2
  define_attr :account_id
5
3
  define_attr :external_key
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::AccountTimeline < Kaui::Base
4
2
  has_one :account, Kaui::Account
5
3
  has_many :payments, Kaui::Payment
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::AuditLog < Kaui::Base
4
2
  define_attr :change_date
5
3
  define_attr :change_type
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::Bundle < Kaui::Base
4
2
  define_attr :account_id
5
3
  define_attr :external_key
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::Invoice < Kaui::Base
4
2
  define_attr :amount
5
3
  define_attr :balance
@@ -59,4 +57,4 @@ class Kaui::Invoice < Kaui::Base
59
57
  def credit_adjustment_to_money(currency)
60
58
  Kaui::Base.to_money(credit_adjustment, currency)
61
59
  end
62
- end
60
+ end
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::InvoiceItem < Kaui::Base
4
2
  SAMPLE_REASON_CODES = [ "100 - Courtesy",
5
3
  "101 - Billing Error",
@@ -23,4 +21,4 @@ class Kaui::InvoiceItem < Kaui::Base
23
21
  def amount_to_money
24
22
  Kaui::Base.to_money(amount, currency)
25
23
  end
26
- end
24
+ end
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::Payment < Kaui::Base
4
2
 
5
3
  SAMPLE_REASON_CODES = [ "600 - Alt payment method",
@@ -13,6 +11,7 @@ class Kaui::Payment < Kaui::Base
13
11
  define_attr :paid_amount
14
12
  define_attr :payment_id
15
13
  define_attr :payment_method_id
14
+ # TODO - is this used?
16
15
  define_attr :refund_amount
17
16
  define_attr :requested_date
18
17
  define_attr :retry_count
@@ -35,4 +34,9 @@ class Kaui::Payment < Kaui::Base
35
34
  def paid_amount_to_money
36
35
  Kaui::Base.to_money(paid_amount, currency)
37
36
  end
38
- end
37
+
38
+ def is_fully_refunded?
39
+ # paid_amount is the original payment amount minus the refunds
40
+ paid_amount == 0
41
+ end
42
+ end
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::PaymentAttempt < Kaui::Base
4
2
  define_attr :account_id
5
3
  define_attr :invoice_id
@@ -26,4 +24,4 @@ class Kaui::PaymentAttempt < Kaui::Base
26
24
  :udpated_dt => data['updatedDate'],
27
25
  :retry_count => data['retryCount'])
28
26
  end
29
- end
27
+ end
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::PaymentMethod < Kaui::Base
4
2
  define_attr :account_id
5
3
  define_attr :is_default
@@ -35,4 +33,4 @@ class Kaui::PaymentMethod < Kaui::Base
35
33
  def email
36
34
  plugin_info.property("email") if plugin_info.present?
37
35
  end
38
- end
36
+ end
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::PluginInfo < Kaui::Base
4
2
  define_attr :external_payment_id
5
3
 
@@ -9,4 +7,4 @@ class Kaui::PluginInfo < Kaui::Base
9
7
  prop = properties.find { |prop| prop.key == key } unless properties.nil?
10
8
  prop.value unless prop.nil?
11
9
  end
12
- end
10
+ end
@@ -1,7 +1,5 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::PluginInfoProperty < Kaui::Base
4
2
  define_attr :key
5
3
  define_attr :value
6
4
  define_attr :is_updatable
7
- end
5
+ end
@@ -1,5 +1,3 @@
1
- require 'active_model'
2
-
3
1
  class Kaui::Refund < Kaui::Base
4
2
  SAMPLE_REASON_CODES = [ "500 - Courtesy",
5
3
  "501 - Billing Error",
@@ -21,4 +19,4 @@ class Kaui::Refund < Kaui::Base
21
19
  def amount_to_money
22
20
  Kaui::Base.to_money(amount, currency)
23
21
  end
24
- end
22
+ end
@@ -1,4 +1,8 @@
1
1
  class Kaui::TimeSeriesData < Kaui::Base
2
2
  define_attr :dates
3
3
  define_attr :values
4
- end
4
+
5
+ def self.empty
6
+ Kaui::TimeSeriesData.new(:dates => [], :values => [])
7
+ end
8
+ end