kaui 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. data/app/controllers/kaui/account_tags_controller.rb +5 -4
  2. data/app/controllers/kaui/account_timelines_controller.rb +3 -3
  3. data/app/controllers/kaui/accounts_controller.rb +8 -8
  4. data/app/controllers/kaui/analytics_controller.rb +28 -0
  5. data/app/controllers/kaui/bundle_tags_controller.rb +3 -3
  6. data/app/controllers/kaui/bundles_controller.rb +5 -5
  7. data/app/controllers/kaui/chargebacks_controller.rb +3 -3
  8. data/app/controllers/kaui/charges_controller.rb +2 -2
  9. data/app/controllers/kaui/credits_controller.rb +3 -3
  10. data/app/controllers/kaui/engine_controller.rb +3 -0
  11. data/app/controllers/kaui/invoice_items_controller.rb +2 -2
  12. data/app/controllers/kaui/invoices_controller.rb +2 -2
  13. data/app/controllers/kaui/payment_methods_controller.rb +1 -1
  14. data/app/controllers/kaui/payments_controller.rb +2 -2
  15. data/app/controllers/kaui/refunds_controller.rb +4 -4
  16. data/app/controllers/kaui/subscriptions_controller.rb +10 -9
  17. data/app/controllers/kaui/tags_controller.rb +85 -0
  18. data/app/helpers/kaui/killbill_helper.rb +24 -3
  19. data/app/models/kaui/account_email.rb +6 -3
  20. data/app/models/kaui/analytics.rb +19 -0
  21. data/app/models/kaui/tag_definition.rb +10 -0
  22. data/app/models/kaui/time_series_data.rb +4 -0
  23. data/app/views/kaui/account_emails/edit.html.erb +6 -0
  24. data/app/views/kaui/analytics/accounts_over_time.html.erb +9 -0
  25. data/app/views/kaui/analytics/index.html.erb +12 -0
  26. data/app/views/kaui/analytics/payments_over_time.html.erb +9 -0
  27. data/app/views/kaui/analytics/subscriptions_over_time.html.erb +9 -0
  28. data/app/views/kaui/subscriptions/edit.html.erb +6 -0
  29. data/app/views/kaui/tag_definitions/index.html.erb +5 -1
  30. data/app/views/kaui/tag_definitions/show.html.erb +4 -0
  31. data/app/views/kaui/tags/_form.html.erb +25 -0
  32. data/app/views/kaui/tags/edit.html.erb +6 -0
  33. data/app/views/kaui/tags/index.html.erb +25 -0
  34. data/app/views/kaui/tags/new.html.erb +5 -0
  35. data/app/views/kaui/tags/show.html.erb +15 -0
  36. data/config/routes.rb +6 -0
  37. data/lib/kaui/error_helper.rb +13 -0
  38. data/lib/kaui/version.rb +1 -1
  39. data/test/dummy/app/assets/javascripts/application.js +2 -0
  40. data/test/dummy/app/assets/stylesheets/application.css +1 -0
  41. data/test/dummy/app/views/layouts/application.html.erb +1 -0
  42. data/test/dummy/log/development.log +74528 -0
  43. data/test/dummy/log/test.log +119755 -1147
  44. data/test/dummy/test/fixtures/bill_cycle_days.yml +3 -0
  45. data/test/dummy/test/fixtures/tag_definitions.yml +12 -1
  46. data/test/dummy/tmp/cache/assets/C94/4E0/sprockets%2Fea1476dc10a3348303f74d111f70441a +0 -0
  47. data/test/dummy/tmp/cache/assets/C95/690/sprockets%2Fc4b083702793f7599f4a3069c50f89a8 +0 -0
  48. data/test/dummy/tmp/cache/assets/CAA/680/sprockets%2F3824d037523f650518fb22acab75559d +0 -0
  49. data/test/dummy/tmp/cache/assets/CC2/520/sprockets%2F9637f46d37325381f96d96d94ae0bc50 +0 -0
  50. data/test/dummy/tmp/cache/assets/CD0/9D0/sprockets%2F5c9508c21501c73fbe00473a09b1f5f4 +0 -0
  51. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  52. data/test/dummy/tmp/cache/assets/CDF/1F0/sprockets%2F76ac5628a0c4d1b976cb622ec4493751 +381 -0
  53. data/test/dummy/tmp/cache/assets/CE0/8A0/sprockets%2Fc18dc7330236e7db17d280973d617b9a +0 -0
  54. data/test/dummy/tmp/cache/assets/CEA/300/sprockets%2Fdf2ad5c9d0990441c2bf59883383d652 +0 -0
  55. data/test/dummy/tmp/cache/assets/CEC/5B0/sprockets%2F1695e8510891108e3950e2a3e4fdf9df +0 -0
  56. data/test/dummy/tmp/cache/assets/CF7/710/sprockets%2F86d43448e1fc383cb6f3d752ef288882 +0 -0
  57. data/test/dummy/tmp/cache/assets/D05/510/sprockets%2F1c14866e2401c27b0ff5e33d1b92c4e8 +0 -0
  58. data/test/dummy/tmp/cache/assets/D07/DA0/sprockets%2Ffaad9b18203975dbf0c60f3234a51874 +0 -0
  59. data/test/dummy/tmp/cache/assets/D17/DD0/sprockets%2F665455ecdc7609b23f4ecb366d86055a +9409 -0
  60. data/test/dummy/tmp/cache/assets/D32/200/sprockets%2Ffa467106e01bda5d6246baea72159d64 +0 -0
  61. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  62. data/test/dummy/tmp/cache/assets/D39/5E0/sprockets%2F59fd338be48a81a17a2a785cbd1612b4 +0 -0
  63. data/test/dummy/tmp/cache/assets/D44/170/sprockets%2Fac15571bce3f926a498da7cd09322d97 +0 -0
  64. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  65. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  66. data/test/dummy/tmp/cache/assets/D6C/710/sprockets%2F1765773caead06c0a6a19ea9de2453f7 +0 -0
  67. data/test/dummy/tmp/cache/assets/D76/910/sprockets%2Ff99b4bdc434e11e8634e6af62fe805e0 +0 -0
  68. data/test/dummy/tmp/cache/assets/D9F/160/sprockets%2F510462e1ebd5dbb7ae20888b77f9bed2 +0 -0
  69. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  70. data/test/dummy/tmp/cache/assets/DDF/650/sprockets%2Fbe16f0bf3d2b7af18010acbd53ba22f5 +0 -0
  71. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  72. data/test/dummy/tmp/cache/assets/E07/1E0/sprockets%2F5a3fe6e98fdf72bbe75c605e54ebc5b0 +9409 -0
  73. data/test/dummy/tmp/cache/assets/E10/BE0/sprockets%2F9c06f8f8da4e736ccf6de8360cd39bfa +0 -0
  74. data/test/dummy/tmp/cache/assets/E20/230/sprockets%2F7d3b1348fdf74cf1b6ba2107fbbac5af +0 -0
  75. data/test/dummy/tmp/cache/assets/E22/F40/sprockets%2Faffacf2e6be325520bd3bfd2096b6dd4 +0 -0
  76. data/test/dummy/tmp/cache/assets/E24/9D0/sprockets%2Fb966ab0a50fda3c156fbad4d8ab73ef6 +381 -0
  77. data/test/functional/kaui/account_emails_controller_test.rb +51 -0
  78. data/test/functional/kaui/tags_controller_test.rb +51 -0
  79. data/test/unit/kaui/tag_definition_test.rb +11 -0
  80. metadata +88 -3
@@ -7,7 +7,8 @@ class Kaui::AccountTagsController < Kaui::EngineController
7
7
  begin
8
8
  tags = Kaui::KillbillHelper::get_tags_for_account(account_id)
9
9
  rescue => e
10
- flash[:error] = "Error while getting tags: #{e.message} #{e.response}"
10
+ flash[:error] = "Error while getting tags: #{as_string(e)}"
11
+
11
12
  end
12
13
  else
13
14
  flash[:error] = "No account id given"
@@ -17,11 +18,11 @@ class Kaui::AccountTagsController < Kaui::EngineController
17
18
  def edit
18
19
  @account_id = params[:account_id]
19
20
  begin
20
- @available_tags = Kaui::KillbillHelper::get_tag_definitions.sort
21
+ @available_tags = Kaui::TagDefinition.all_for_account.sort
21
22
  @account = Kaui::KillbillHelper::get_account(@account_id)
22
23
  @tag_names = Kaui::KillbillHelper::get_tags_for_account(@account.account_id).map { |tag| tag.tag_definition_name }
23
24
  rescue => e
24
- flash[:error] = "Error while editing tags: #{e.message} #{e.response}"
25
+ flash[:error] = "Error while editing tags: #{as_string(e)}"
25
26
  end
26
27
  end
27
28
 
@@ -51,7 +52,7 @@ class Kaui::AccountTagsController < Kaui::EngineController
51
52
  Kaui::KillbillHelper::remove_tags_for_account(params[:account_id], tags_to_remove)
52
53
  Kaui::KillbillHelper::add_tags_for_account(params[:account_id], tags_to_add)
53
54
  rescue => e
54
- flash[:error] = "Error while updating tags: #{e.message} #{e.response}"
55
+ flash[:error] = "Error while updating tags: #{as_string(e)}"
55
56
  end
56
57
  redirect_to kaui_engine.account_path(params[:account_id])
57
58
  end
@@ -16,7 +16,7 @@ class Kaui::AccountTimelinesController < Kaui::EngineController
16
16
  @account = Kaui::KillbillHelper::get_account(@account_id)
17
17
  @timeline = Kaui::KillbillHelper::get_account_timeline(@account_id)
18
18
  rescue => e
19
- flash[:error] = "Could not load the account timeline for #{@account_id}: #{e.message} #{e.response}"
19
+ flash[:error] = "Could not load the account timeline for #{@account_id}: #{as_string(e)}"
20
20
  redirect_to :action => :index
21
21
  return
22
22
  end
@@ -29,7 +29,7 @@ class Kaui::AccountTimelinesController < Kaui::EngineController
29
29
  begin
30
30
  @invoices_by_id[payment.invoice_id] = Kaui::KillbillHelper::get_invoice(payment.invoice_id)
31
31
  rescue => e
32
- flash[:error] = "Could not get invoice information for the timeline #{@account_id}: #{e.message} #{e.response}"
32
+ flash[:error] = "Could not get invoice information for the timeline #{@account_id}: #{as_string(e)}"
33
33
  end
34
34
  payment.bundle_keys.split(",").each do |bundle_key|
35
35
  unless @bundle_names.has_key?(bundle_key)
@@ -43,7 +43,7 @@ class Kaui::AccountTimelinesController < Kaui::EngineController
43
43
  begin
44
44
  @invoices_by_id[invoice.invoice_id] = Kaui::KillbillHelper::get_invoice(invoice.invoice_id)
45
45
  rescue => e
46
- flash[:error] = "Could not get invoice information for the timeline #{@account_id}: #{e.message} #{e.response}"
46
+ flash[:error] = "Could not get invoice information for the timeline #{@account_id}: #{as_string(e)}"
47
47
  end
48
48
  invoice.bundle_keys.split(",").each do |bundle_key|
49
49
  unless @bundle_names.has_key?(bundle_key)
@@ -20,7 +20,7 @@ class Kaui::AccountsController < Kaui::EngineController
20
20
  flash[:error] = "Error while retrieving the account for #{key}: #{e.message}"
21
21
  render :action => :index and return
22
22
  rescue => e
23
- flash[:error] = "Error while retrieving the account for #{key}: #{e.message} #{e.response}"
23
+ flash[:error] = "Error while retrieving the account for #{key}: #{as_string(e)}"
24
24
  render :action => :index and return
25
25
  end
26
26
 
@@ -39,7 +39,7 @@ class Kaui::AccountsController < Kaui::EngineController
39
39
  end
40
40
  end
41
41
  rescue => e
42
- flash[:error] = "Error while retrieving account information for account: #{e.message} #{e.response}"
42
+ flash[:error] = "Error while retrieving account information for account: #{as_string(e)}"
43
43
  end
44
44
  else
45
45
  flash[:error] = "Account #{@account_id} not found: #{@account}"
@@ -56,7 +56,7 @@ class Kaui::AccountsController < Kaui::EngineController
56
56
  begin
57
57
  @payment_methods = Kaui::KillbillHelper::get_payment_methods(@account_id)
58
58
  rescue => e
59
- flash[:error] = "Error while getting payment methods: #{e.message} #{e.response}"
59
+ flash[:error] = "Error while getting payment methods: #{as_string(e)}"
60
60
  end
61
61
  unless @payment_methods.is_a?(Array)
62
62
  flash[:notice] = "No payment methods for account_id '#{@account_id}'"
@@ -73,7 +73,7 @@ class Kaui::AccountsController < Kaui::EngineController
73
73
  begin
74
74
  @account = Kaui::KillbillHelper::get_account(account_id)
75
75
  rescue => e
76
- flash[:error] = "Error while adding payment methods: #{e.message} #{e.response}"
76
+ flash[:error] = "Error while adding payment methods: #{as_string(e)}"
77
77
  end
78
78
  if @account.nil?
79
79
  flash[:error] = "Account not found for id #{account_id}"
@@ -88,7 +88,7 @@ class Kaui::AccountsController < Kaui::EngineController
88
88
  begin
89
89
  @account = Kaui::KillbillHelper::get_account(account_id)
90
90
  rescue => e
91
- flash[:error] = "Error while adding payment method: #{e.message} #{e.response}"
91
+ flash[:error] = "Error while adding payment method: #{as_string(e)}"
92
92
  end
93
93
 
94
94
  # Implementation example using standard credit card fields
@@ -132,7 +132,7 @@ class Kaui::AccountsController < Kaui::EngineController
132
132
  redirect_to kaui_engine.account_timeline_path(@account.account_id)
133
133
  return
134
134
  rescue => e
135
- flash[:error] = "Error while adding payment method #{invoice_id}: #{e.message} #{e.response}"
135
+ flash[:error] = "Error while adding payment method #{invoice_id}: #{as_string(e)}"
136
136
  end
137
137
  end
138
138
  render "kaui/payment_methods/new"
@@ -145,7 +145,7 @@ class Kaui::AccountsController < Kaui::EngineController
145
145
  begin
146
146
  @payment_methods = Kaui::KillbillHelper::set_payment_method_as_default(@account_id, @payment_method_id)
147
147
  rescue => e
148
- flash[:error] = "Error while setting payment method as default #{invoice_id}: #{e.message} #{e.response}"
148
+ flash[:error] = "Error while setting payment method as default #{invoice_id}: #{as_string(e)}"
149
149
  end
150
150
  else
151
151
  flash[:notice] = "No account_id or payment_method_id given"
@@ -159,7 +159,7 @@ class Kaui::AccountsController < Kaui::EngineController
159
159
  flash[:notice] = "Email preferences updated"
160
160
  redirect_to :back
161
161
  rescue => e
162
- flash[:error] = "Error while switching email notifications #{invoice_id}: #{e.message} #{e.response}"
162
+ flash[:error] = "Error while switching email notifications #{invoice_id}: #{as_string(e)}"
163
163
  end
164
164
  end
165
165
  end
@@ -0,0 +1,28 @@
1
+ module Kaui
2
+ class AnalyticsController < ApplicationController
3
+ def index
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}"
12
+ end
13
+ end
14
+ end
15
+ @product_type = catalog['name']
16
+ end
17
+
18
+ def accounts_over_time
19
+ @accounts = Analytics.accounts_over_time
20
+ end
21
+
22
+ def subscriptions_over_time
23
+ @product_type = params[:product_type]
24
+ @slug = params[:slug]
25
+ @subscriptions = Analytics.subscriptions_over_time(@product_type, @slug)
26
+ end
27
+ end
28
+ end
@@ -6,7 +6,7 @@ class Kaui::BundleTagsController < Kaui::EngineController
6
6
  begin
7
7
  tags = Kaui::KillbillHelper::get_tags_for_bundle(bundle_id)
8
8
  rescue => e
9
- flash[:error] = "Error while retrieving tags information: #{e.message} #{e.response}"
9
+ flash[:error] = "Error while retrieving tags information: #{as_string(e)}"
10
10
  end
11
11
  else
12
12
  flash[:error] = "No account id given"
@@ -21,7 +21,7 @@ class Kaui::BundleTagsController < Kaui::EngineController
21
21
  @bundle = Kaui::KillbillHelper::get_bundle(@bundle_id)
22
22
  @tags = Kaui::KillbillHelper::get_tags_for_bundle(@bundle_id)
23
23
  rescue => e
24
- flash[:error] = "Error while retrieving tags information: #{e.message} #{e.response}"
24
+ flash[:error] = "Error while retrieving tags information: #{as_string(e)}"
25
25
  end
26
26
  end
27
27
 
@@ -33,7 +33,7 @@ class Kaui::BundleTagsController < Kaui::EngineController
33
33
  Kaui::KillbillHelper::set_tags_for_bundle(bundle.bundle_id, tags)
34
34
  redirect_to Kaui.bundle_home_path.call(bundle.bundle_id)
35
35
  rescue => e
36
- flash[:error] = "Error while updating tags: #{e.message} #{e.response}"
36
+ flash[:error] = "Error while updating tags: #{as_string(e)}"
37
37
  end
38
38
  end
39
39
 
@@ -20,7 +20,7 @@ class Kaui::BundlesController < Kaui::EngineController
20
20
  render :action => :index
21
21
  end
22
22
  rescue => e
23
- flash[:error] = "Error while retrieving bundle information for #{key}: #{e.message} #{e.response}"
23
+ flash[:error] = "Error while retrieving bundle information for #{key}: #{as_string(e)}"
24
24
  end
25
25
  else
26
26
  flash[:error] = "No id given"
@@ -33,7 +33,7 @@ class Kaui::BundlesController < Kaui::EngineController
33
33
  @bundle = Kaui::KillbillHelper::get_bundle(bundle_id)
34
34
  @account = Kaui::KillbillHelper::get_account_by_bundle_id(bundle_id)
35
35
  rescue => e
36
- flash[:error] = "Error while preparing to transfer bundle: #{e.message} #{e.response}"
36
+ flash[:error] = "Error while preparing to transfer bundle: #{as_string(e)}"
37
37
  end
38
38
  if @account.nil?
39
39
  flash[:error] = "Account not found for bundle id #{bundle_id}"
@@ -47,7 +47,7 @@ class Kaui::BundlesController < Kaui::EngineController
47
47
  begin
48
48
  result = Kaui::KillbillHelper.get_account_by_key(key, false)
49
49
  rescue => e
50
- flash[:error] = "Error while retrieving account for #{key}: #{e.message} #{e.response}"
50
+ flash[:error] = "Error while retrieving account for #{key}: #{as_string(e)}"
51
51
  render :action => :index
52
52
  return
53
53
  end
@@ -57,7 +57,7 @@ class Kaui::BundlesController < Kaui::EngineController
57
57
  Kaui::KillbillHelper::transfer_bundle(bundle_id, @new_account.account_id)
58
58
  flash[:info] = "Bundle transfered successfully"
59
59
  rescue => e
60
- flash[:error] = "Error transfering bundle #{e.message} #{e.response}"
60
+ flash[:error] = "Error transfering bundle #{as_string(e)}"
61
61
  end
62
62
  redirect_to Kaui.account_home_path.call(@new_account.external_key)
63
63
  return
@@ -72,7 +72,7 @@ class Kaui::BundlesController < Kaui::EngineController
72
72
  @bundle = Kaui::KillbillHelper::get_bundle(bundle_id)
73
73
  @account = Kaui::KillbillHelper::get_account_by_bundle_id(bundle_id)
74
74
  rescue => e
75
- flash[:error] = "Error while redirecting: #{e.message} #{e.response}"
75
+ flash[:error] = "Error while redirecting: #{as_string(e)}"
76
76
  render :transfer
77
77
  end
78
78
  end
@@ -6,7 +6,7 @@ class Kaui::ChargebacksController < Kaui::EngineController
6
6
  begin
7
7
  data = Kaui::KillbillHelper::get_chargebacks_for_payment(@payment_id)
8
8
  rescue => e
9
- flash[:error] = "Error while getting chargeback information: #{e.message} #{e.response}"
9
+ flash[:error] = "Error while getting chargeback information: #{as_string(e)}"
10
10
  end
11
11
  if data.present?
12
12
  @chargeback = Kaui::Chargeback.new(data)
@@ -29,7 +29,7 @@ class Kaui::ChargebacksController < Kaui::EngineController
29
29
  @invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
30
30
  @payment_method = Kaui::KillbillHelper::get_payment_method(@payment.payment_method_id)
31
31
  rescue => e
32
- flash[:error] = "Error while starting a new chargeback: #{e.message} #{e.response}"
32
+ flash[:error] = "Error while starting a new chargeback: #{as_string(e)}"
33
33
  redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
34
34
  end
35
35
 
@@ -46,7 +46,7 @@ class Kaui::ChargebacksController < Kaui::EngineController
46
46
  Kaui::KillbillHelper::create_chargeback(chargeback, params[:reason], params[:comment])
47
47
  flash[:info] = "Chargeback created"
48
48
  rescue => e
49
- flash[:error] = "Error while creating a new chargeback: #{e.message} #{e.response}"
49
+ flash[:error] = "Error while creating a new chargeback: #{as_string(e)}"
50
50
  end
51
51
  else
52
52
  flash[:error] = "No chargeback to process"
@@ -13,7 +13,7 @@ class Kaui::ChargesController < Kaui::EngineController
13
13
  @charge = Kaui::Charge.new("accountId" => @account_id)
14
14
  end
15
15
  rescue => e
16
- flash[:error] = "Error while creating a charge: #{e.message} #{e.response}"
16
+ flash[:error] = "Error while creating a charge: #{as_string(e)}"
17
17
  end
18
18
  end
19
19
 
@@ -26,7 +26,7 @@ class Kaui::ChargesController < Kaui::EngineController
26
26
  flash[:info] = "Charge created"
27
27
  redirect_to kaui_engine.account_timeline_path(:id => charge.account_id)
28
28
  rescue => e
29
- flash[:error] = "Error while creating a charge: #{e.message} #{e.response}"
29
+ flash[:error] = "Error while creating a charge: #{as_string(e)}"
30
30
  end
31
31
  end
32
32
  end
@@ -8,7 +8,7 @@ class Kaui::CreditsController < Kaui::EngineController
8
8
  # invoice id can be nil for account level credit
9
9
  data = Kaui::KillbillHelper::get_credits(@account_id, @invoice_id)
10
10
  rescue => e
11
- flash[:error] = "Error getting credit information: #{e.message} #{e.response}"
11
+ flash[:error] = "Error getting credit information: #{as_string(e)}"
12
12
  end
13
13
  if data.present?
14
14
  @credit = Kaui::Credit.new(data)
@@ -28,7 +28,7 @@ class Kaui::CreditsController < Kaui::EngineController
28
28
  @account = Kaui::KillbillHelper::get_account(@account_id)
29
29
  @invoice = Kaui::KillbillHelper::get_invoice(@invoice_id) unless @invoice_id.nil?
30
30
  rescue => e
31
- flash[:error] = "Error while starting to create credit: #{e.message} #{e.response}"
31
+ flash[:error] = "Error while starting to create credit: #{as_string(e)}"
32
32
  end
33
33
 
34
34
  credit_amount = @invoice.balance unless @invoice.nil?
@@ -44,7 +44,7 @@ class Kaui::CreditsController < Kaui::EngineController
44
44
  account = Kaui::KillbillHelper::get_account(credit.account_id)
45
45
  flash[:info] = "Credit created"
46
46
  rescue => e
47
- flash[:error] = "Error while starting to create credit: #{e.message} #{e.response}"
47
+ flash[:error] = "Error while starting to create credit: #{as_string(e)}"
48
48
  end
49
49
  redirect_to Kaui.account_home_path.call(account.external_key)
50
50
  end
@@ -1,4 +1,7 @@
1
+ require 'kaui/error_helper'
2
+
1
3
  class Kaui::EngineController < ApplicationController
4
+ include Kaui::ErrorHelper
2
5
  # This is a semi-isolated engine (https://bibwild.wordpress.com/2012/05/10/the-semi-isolated-rails-engine/)
3
6
  # We expect that the hosting app's ApplicationController has these methods defined:
4
7
  #
@@ -20,7 +20,7 @@ class Kaui::InvoiceItemsController < Kaui::EngineController
20
20
  flash[:notice] = "Adjustment item created"
21
21
  redirect_to kaui_engine.invoice_path(@invoice_item.invoice_id)
22
22
  rescue => e
23
- flash[:error] = "Error while updating the invoice item: #{e.message} #{e.response}"
23
+ flash[:error] = "Error while updating the invoice item: #{as_string(e)}"
24
24
  render :action => "edit"
25
25
  end
26
26
  end
@@ -34,7 +34,7 @@ class Kaui::InvoiceItemsController < Kaui::EngineController
34
34
  begin
35
35
  @invoice_item = Kaui::KillbillHelper.get_invoice_item(invoice_id, invoice_item_id)
36
36
  rescue => e
37
- flash[:error] = "Error while trying to find the invoice item: #{e.message} #{e.response}"
37
+ flash[:error] = "Error while trying to find the invoice item: #{as_string(e)}"
38
38
  end
39
39
  unless @invoice_item.present?
40
40
  flash[:error] = "Invoice for id #{invoice_id} and invoice item id #{invoice_item_id} not found"
@@ -33,7 +33,7 @@ class Kaui::InvoicesController < Kaui::EngineController
33
33
  render :action => :index
34
34
  end
35
35
  rescue => e
36
- flash[:error] = "Error while getting information for invoice #{invoice_id}: #{e.message} #{e.response}"
36
+ flash[:error] = "Error while getting information for invoice #{invoice_id}: #{as_string(e)}"
37
37
  end
38
38
  else
39
39
  flash[:error] = "No id given"
@@ -44,7 +44,7 @@ class Kaui::InvoicesController < Kaui::EngineController
44
44
  begin
45
45
  render :text => Kaui::KillbillHelper.get_invoice_html(params[:id])
46
46
  rescue => e
47
- flash[:error] = "Error rendering invoice html #{invoice_id}: #{e.message} #{e.response}"
47
+ flash[:error] = "Error rendering invoice html #{invoice_id}: #{as_string(e)}"
48
48
  end
49
49
  end
50
50
  end
@@ -11,7 +11,7 @@ class Kaui::PaymentMethodsController < Kaui::EngineController
11
11
  begin
12
12
  Kaui::KillbillHelper.delete_payment_method(payment_method_id, params[:set_auto_pay_off])
13
13
  rescue => e
14
- flash[:error] = "Error while deleting payment method #{payment_method_id}: #{e.message} #{e.response}"
14
+ flash[:error] = "Error while deleting payment method #{payment_method_id}: #{as_string(e)}"
15
15
  end
16
16
  else
17
17
  flash[:notice] = "Did not get the payment method id"
@@ -7,7 +7,7 @@ class Kaui::PaymentsController < Kaui::EngineController
7
7
  @invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
8
8
  @account = Kaui::KillbillHelper::get_account(@account_id)
9
9
  rescue => e
10
- flash[:error] = "Error while creating a new payment: #{e.message} #{e.response}"
10
+ flash[:error] = "Error while creating a new payment: #{as_string(e)}"
11
11
  redirect_to kaui_engine.account_timeline_path(:id => payment.account_id)
12
12
  end
13
13
 
@@ -22,7 +22,7 @@ class Kaui::PaymentsController < Kaui::EngineController
22
22
  Kaui::KillbillHelper::create_payment(payment, payment.external, current_user, params[:reason], params[:comment])
23
23
  flash[:info] = "Payment created"
24
24
  rescue => e
25
- flash[:error] = "Error while creating a new payment: #{e.message} #{e.response}"
25
+ flash[:error] = "Error while creating a new payment: #{as_string(e)}"
26
26
  end
27
27
  end
28
28
  redirect_to kaui_engine.account_timeline_path(:id => payment.account_id)
@@ -10,7 +10,7 @@ class Kaui::RefundsController < Kaui::EngineController
10
10
  begin
11
11
  data = Kaui::KillbillHelper::get_refund(params[:id])
12
12
  rescue => e
13
- flash[:error] = "Error while retrieving the refund with id #{params[:id]}: #{e.message} #{e.response}"
13
+ flash[:error] = "Error while retrieving the refund with id #{params[:id]}: #{as_string(e)}"
14
14
  end
15
15
  if data.present?
16
16
  @refunds = [data]
@@ -22,7 +22,7 @@ class Kaui::RefundsController < Kaui::EngineController
22
22
  render :action => :index
23
23
  end
24
24
  rescue => e
25
- flash[:error] = "Error while retrieving the refunds for the payment: #{e.message} #{e.response}"
25
+ flash[:error] = "Error while retrieving the refunds for the payment: #{as_string(e)}"
26
26
  render :action => :index
27
27
  end
28
28
  end
@@ -45,7 +45,7 @@ class Kaui::RefundsController < Kaui::EngineController
45
45
  @invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
46
46
  @payment_method = Kaui::KillbillHelper::get_payment_method(@payment.payment_method_id)
47
47
  rescue => e
48
- flash[:error] = "Error while processing refund: #{e.message} #{e.response}"
48
+ flash[:error] = "Error while processing refund: #{as_string(e)}"
49
49
  redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
50
50
  end
51
51
  end
@@ -61,7 +61,7 @@ class Kaui::RefundsController < Kaui::EngineController
61
61
  Kaui::KillbillHelper::create_refund(params[:payment_id], refund, current_user, params[:reason], params[:comment])
62
62
  flash[:info] = "Refund created"
63
63
  rescue => e
64
- flash[:error] = "Error while processing refund: #{e.message} #{e.response}"
64
+ flash[:error] = "Error while processing refund: #{as_string(e)}"
65
65
  end
66
66
  else
67
67
  flash[:error] = "No refund to process"
@@ -15,7 +15,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
15
15
  redirect_to :back
16
16
  end
17
17
  rescue => e
18
- flash[:error] = "Error while getting subscription information: #{e.message} #{e.response}"
18
+ flash[:error] = "Error while getting subscription information: #{as_string(e)}"
19
19
  end
20
20
  end
21
21
 
@@ -31,7 +31,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
31
31
  @catalog = Kaui::KillbillHelper::get_available_base_plans()
32
32
  end
33
33
  rescue => e
34
- flash[:error] = "Error while trying to start new subscription creation: #{e.message} #{e.response}"
34
+ flash[:error] = "Error while trying to start new subscription creation: #{as_string(e)}"
35
35
  end
36
36
  @subscription = Kaui::Subscription.new("bundleId" => bundle_id)
37
37
  end
@@ -59,7 +59,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
59
59
  Kaui::KillbillHelper::create_subscription(@subscription, current_user)
60
60
  redirect_to Kaui.bundle_home_path.call(@bundle.bundle_id)
61
61
  rescue => e
62
- flash[:error] = "Error while creating the new subscription: #{e.message} #{e.response}"
62
+ flash[:error] = "Error while creating the new subscription: #{as_string(e)}"
63
63
  render :new
64
64
  end
65
65
  end
@@ -83,7 +83,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
83
83
  @bundle = Kaui::KillbillHelper.get_bundle(subscription.bundle_id)
84
84
  @available_plans = Kaui::KillbillHelper.get_available_addons(params[:base_product_name])
85
85
  rescue => e
86
- flash[:error] = "Error while adding an addon: #{e.message} #{e.response}"
86
+ flash[:error] = "Error while adding an addon: #{as_string(e)}"
87
87
  end
88
88
  end
89
89
 
@@ -106,7 +106,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
106
106
  redirect_to :back
107
107
  end
108
108
  rescue => e
109
- flash[:error] = "Error while editing subscription: #{e.message} #{e.response}"
109
+ flash[:error] = "Error while editing subscription: #{as_string(e)}"
110
110
  end
111
111
  end
112
112
 
@@ -120,6 +120,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
120
120
 
121
121
  plan = catalog[params[:plan_name]]
122
122
  requested_date = params[:requested_date]
123
+ policy = params[:policy]
123
124
 
124
125
  subscription.billing_period = plan["billingPeriod"]
125
126
  subscription.product_category = plan["productCategory"]
@@ -127,9 +128,9 @@ class Kaui::SubscriptionsController < Kaui::EngineController
127
128
  subscription.price_list = plan["priceListName"]
128
129
  subscription.subscription_id = params[:subscription][:subscription_id]
129
130
 
130
- Kaui::KillbillHelper::update_subscription(subscription, requested_date, current_user)
131
+ Kaui::KillbillHelper::update_subscription(subscription, requested_date, policy, current_user)
131
132
  rescue => e
132
- flash[:error] = "Error while updating subscription: #{e.message} #{e.response}"
133
+ flash[:error] = "Error while updating subscription: #{as_string(e)}"
133
134
  end
134
135
  else
135
136
  flash[:error] = "No subscription given"
@@ -144,7 +145,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
144
145
  Kaui::KillbillHelper::reinstate_subscription(subscription_id, current_user)
145
146
  flash[:info] = "Subscription reinstated"
146
147
  rescue => e
147
- flash[:error] = "Error while reinstating subscription: #{e.message} #{e.response}"
148
+ flash[:error] = "Error while reinstating subscription: #{as_string(e)}"
148
149
  end
149
150
  else
150
151
  flash[:error] = "No subscription id given"
@@ -158,7 +159,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
158
159
  begin
159
160
  Kaui::KillbillHelper::delete_subscription(subscription_id, current_user)
160
161
  rescue => e
161
- flash[:error] = "Error while reinstating subscription: #{e.message} #{e.response}"
162
+ flash[:error] = "Error while reinstating subscription: #{as_string(e)}"
162
163
  end
163
164
  else
164
165
  flash[:error] = "No subscription id given"
@@ -0,0 +1,85 @@
1
+ module Kaui
2
+ class TagsController < ApplicationController
3
+ # GET /tags
4
+ # GET /tags.json
5
+ def index
6
+ @tags = Tag.all
7
+
8
+ respond_to do |format|
9
+ format.html # index.html.erb
10
+ format.json { render :json => @tags }
11
+ end
12
+ end
13
+
14
+ # GET /tags/1
15
+ # GET /tags/1.json
16
+ def show
17
+ @tag = Tag.find(params[:id])
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.json { render :json => @tag }
22
+ end
23
+ end
24
+
25
+ # GET /tags/new
26
+ # GET /tags/new.json
27
+ def new
28
+ @tag = Tag.new
29
+
30
+ respond_to do |format|
31
+ format.html # new.html.erb
32
+ format.json { render :json => @tag }
33
+ end
34
+ end
35
+
36
+ # GET /tags/1/edit
37
+ def edit
38
+ @tag = Tag.find(params[:id])
39
+ end
40
+
41
+ # POST /tags
42
+ # POST /tags.json
43
+ def create
44
+ @tag = Tag.new(params[:tag])
45
+
46
+ respond_to do |format|
47
+ if @tag.save
48
+ format.html { redirect_to @tag, :notice => 'Tag was successfully created.' }
49
+ format.json { render :json => @tag, :status => :created, :location => @tag }
50
+ else
51
+ format.html { render :action => "new" }
52
+ format.json { render :json => @tag.errors, :status => :unprocessable_entity }
53
+ end
54
+ end
55
+ end
56
+
57
+ # PUT /tags/1
58
+ # PUT /tags/1.json
59
+ def update
60
+ @tag = Tag.find(params[:id])
61
+
62
+ respond_to do |format|
63
+ if @tag.update_attributes(params[:tag])
64
+ format.html { redirect_to @tag, :notice => 'Tag was successfully updated.' }
65
+ format.json { head :no_content }
66
+ else
67
+ format.html { render :action => "edit" }
68
+ format.json { render :json => @tag.errors, :status => :unprocessable_entity }
69
+ end
70
+ end
71
+ end
72
+
73
+ # DELETE /tags/1
74
+ # DELETE /tags/1.json
75
+ def destroy
76
+ @tag = Tag.find(params[:id])
77
+ @tag.destroy
78
+
79
+ respond_to do |format|
80
+ format.html { redirect_to tags_url }
81
+ format.json { head :no_content }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -173,13 +173,17 @@ module Kaui
173
173
  "X-Killbill-Comment" => "#{comment}"
174
174
  end
175
175
 
176
- def self.update_subscription(subscription, requested_date = nil, current_user = nil, reason = nil, comment = nil)
176
+ def self.update_subscription(subscription, requested_date = nil, policy = nil, current_user = nil, reason = nil, comment = nil)
177
177
  subscription_data = Kaui::Subscription.camelize(subscription.to_hash)
178
- date_param = "?requestedDate=" + requested_date.to_s unless requested_date.blank?
178
+
179
+ params = "?"
180
+ params = "#{params}requestedDate=#{requested_date.to_s}&" unless requested_date.blank?
181
+ params = "#{params}policy=#{policy}" unless policy.blank?
182
+
179
183
  # We don't want to pass events
180
184
  subscription_data.delete(:events)
181
185
  call_killbill :put,
182
- "/1.0/kb/subscriptions/#{subscription.subscription_id}#{date_param}",
186
+ "/1.0/kb/subscriptions/#{subscription.subscription_id}#{params}",
183
187
  ActiveSupport::JSON.encode(subscription_data, :root => false),
184
188
  :content_type => :json,
185
189
  "X-Killbill-CreatedBy" => current_user,
@@ -265,6 +269,11 @@ module Kaui
265
269
 
266
270
  ############## CATALOG ##############
267
271
 
272
+ def self.get_full_catalog
273
+ data = call_killbill :get, "/1.0/kb/catalog/simpleCatalog"
274
+ data[:json]
275
+ end
276
+
268
277
  def self.get_available_addons(base_product_name)
269
278
  data = call_killbill :get, "/1.0/kb/catalog/availableAddons?baseProductName=#{base_product_name}"
270
279
  if data.has_key?(:json)
@@ -480,5 +489,17 @@ module Kaui
480
489
  "X-Killbill-Comment" => "#{comment}"
481
490
  end
482
491
  end
492
+
493
+ ############## ANALYTICS ##############
494
+
495
+ def self.get_accounts_created_over_time
496
+ data = call_killbill :get, "/1.0/kb/analytics/accountsCreatedOverTime"
497
+ process_response(data, :single) { |json| Kaui::TimeSeriesData.new(json) }
498
+ end
499
+
500
+ def self.get_subscriptions_created_over_time(product_type, slug)
501
+ data = call_killbill :get, "/1.0/kb/analytics/subscriptionsCreatedOverTime?productType=#{product_type}&slug=#{slug}"
502
+ process_response(data, :single) { |json| Kaui::TimeSeriesData.new(json) }
503
+ end
483
504
  end
484
505
  end