kaui 0.6.6 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +51 -37
  4. data/README.md +5 -0
  5. data/Rakefile +1 -1
  6. data/app/controllers/kaui/account_emails_controller.rb +26 -44
  7. data/app/controllers/kaui/account_tags_controller.rb +26 -38
  8. data/app/controllers/kaui/account_timelines_controller.rb +47 -50
  9. data/app/controllers/kaui/accounts_controller.rb +68 -148
  10. data/app/controllers/kaui/bundle_tags_controller.rb +32 -21
  11. data/app/controllers/kaui/bundles_controller.rb +44 -69
  12. data/app/controllers/kaui/chargebacks_controller.rb +31 -61
  13. data/app/controllers/kaui/charges_controller.rb +19 -21
  14. data/app/controllers/kaui/credits_controller.rb +22 -36
  15. data/app/controllers/kaui/custom_fields_controller.rb +15 -13
  16. data/app/controllers/kaui/engine_controller.rb +8 -10
  17. data/app/controllers/kaui/invoice_items_controller.rb +24 -41
  18. data/app/controllers/kaui/invoices_controller.rb +36 -46
  19. data/app/controllers/kaui/payment_methods_controller.rb +84 -28
  20. data/app/controllers/kaui/payments_controller.rb +64 -26
  21. data/app/controllers/kaui/refunds_controller.rb +27 -107
  22. data/app/controllers/kaui/subscriptions_controller.rb +88 -132
  23. data/app/controllers/kaui/tag_definitions_controller.rb +32 -79
  24. data/app/controllers/kaui/tags_controller.rb +16 -14
  25. data/app/controllers/kaui/transactions_controller.rb +25 -0
  26. data/app/helpers/kaui/money_helper.rb +8 -0
  27. data/app/helpers/kaui/subscription_helper.rb +115 -0
  28. data/app/helpers/kaui/uuid_helper.rb +9 -0
  29. data/app/models/kaui/ability.rb +2 -2
  30. data/app/models/kaui/account.rb +25 -42
  31. data/app/models/kaui/account_email.rb +11 -48
  32. data/app/models/kaui/account_timeline.rb +1 -5
  33. data/app/models/kaui/audit_log.rb +1 -15
  34. data/app/models/kaui/base.rb +1 -126
  35. data/app/models/kaui/bundle.rb +47 -14
  36. data/app/models/kaui/catalog.rb +2 -0
  37. data/app/models/kaui/chargeback.rb +24 -36
  38. data/app/models/kaui/credit.rb +5 -20
  39. data/app/models/kaui/custom_field.rb +9 -5
  40. data/app/models/kaui/invoice.rb +9 -53
  41. data/app/models/kaui/invoice_item.rb +8 -18
  42. data/app/models/kaui/invoice_payment.rb +24 -0
  43. data/app/models/kaui/payment.rb +14 -32
  44. data/app/models/kaui/payment_method.rb +36 -0
  45. data/app/models/kaui/rails_methods.rb +7 -9
  46. data/app/models/kaui/refund.rb +5 -20
  47. data/app/models/kaui/subscription.rb +7 -27
  48. data/app/models/kaui/tag.rb +10 -6
  49. data/app/models/kaui/tag_definition.rb +26 -34
  50. data/app/models/kaui/transaction.rb +30 -0
  51. data/app/models/kaui/user.rb +2 -0
  52. data/app/views/kaui/account_emails/_form.html.erb +8 -28
  53. data/app/views/kaui/account_emails/show.html.erb +10 -10
  54. data/app/views/kaui/account_tags/_account_tags_table.html.erb +20 -18
  55. data/app/views/kaui/account_tags/_form.html.erb +42 -0
  56. data/app/views/kaui/account_tags/edit.html.erb +1 -41
  57. data/app/views/kaui/account_tags/show.html.erb +6 -3
  58. data/app/views/kaui/account_timelines/show.html.erb +273 -302
  59. data/app/views/kaui/accounts/_form.html.erb +116 -0
  60. data/app/views/kaui/accounts/index.html.erb +13 -11
  61. data/app/views/kaui/accounts/new.html.erb +5 -0
  62. data/app/views/kaui/accounts/show.html.erb +101 -99
  63. data/app/views/kaui/bundle_tags/_bundle_tags_table.html.erb +29 -9
  64. data/app/views/kaui/bundle_tags/_form.html.erb +41 -0
  65. data/app/views/kaui/bundle_tags/edit.html.erb +2 -34
  66. data/app/views/kaui/bundle_tags/show.html.erb +6 -0
  67. data/app/views/kaui/bundles/index.html.erb +9 -9
  68. data/app/views/kaui/bundles/show.html.erb +17 -15
  69. data/app/views/kaui/bundles/transfer.html.erb +25 -24
  70. data/app/views/kaui/chargebacks/_form.html.erb +44 -0
  71. data/app/views/kaui/chargebacks/new.html.erb +3 -115
  72. data/app/views/kaui/charges/_form.html.erb +73 -0
  73. data/app/views/kaui/charges/new.html.erb +2 -91
  74. data/app/views/kaui/credits/_form.html.erb +73 -0
  75. data/app/views/kaui/credits/new.html.erb +2 -85
  76. data/app/views/kaui/invoice_items/edit.html.erb +77 -78
  77. data/app/views/kaui/invoices/show.html.erb +3 -10
  78. data/app/views/kaui/layouts/kaui_application.html.erb +0 -2
  79. data/app/views/kaui/payment_methods/_form.html.erb +30 -0
  80. data/app/views/kaui/payment_methods/_new_creditcard_payment_method.html.erb +19 -18
  81. data/app/views/kaui/payment_methods/_payment_methods_table.html.erb +8 -5
  82. data/app/views/kaui/payment_methods/index.html.erb +10 -10
  83. data/app/views/kaui/payment_methods/new.html.erb +2 -20
  84. data/app/views/kaui/payment_methods/show.html.erb +2 -1
  85. data/app/views/kaui/payments/_payments_table.html.erb +30 -22
  86. data/app/views/kaui/payments/index.html.erb +1 -1
  87. data/app/views/kaui/payments/new.html.erb +5 -5
  88. data/app/views/kaui/payments/show.html.erb +3 -0
  89. data/app/views/kaui/refunds/new.html.erb +96 -104
  90. data/app/views/kaui/subscriptions/_form.html.erb +36 -0
  91. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +39 -44
  92. data/app/views/kaui/subscriptions/edit.html.erb +24 -35
  93. data/app/views/kaui/subscriptions/index.html.erb +13 -12
  94. data/app/views/kaui/subscriptions/new.html.erb +6 -43
  95. data/app/views/kaui/subscriptions/show.html.erb +32 -25
  96. data/app/views/kaui/tag_definitions/_form.html.erb +10 -37
  97. data/app/views/kaui/tag_definitions/index.html.erb +3 -5
  98. data/app/views/kaui/tag_definitions/show.html.erb +1 -2
  99. data/app/views/kaui/transactions/_form.html.erb +77 -0
  100. data/app/views/kaui/transactions/new.html.erb +3 -0
  101. data/config/initializers/kilbill-client-init.rb +1 -1
  102. data/config/routes.rb +4 -15
  103. data/kaui.gemspec +8 -6
  104. data/lib/kaui/engine.rb +4 -1
  105. data/lib/kaui/version.rb +1 -1
  106. data/lib/kaui.rb +2 -2
  107. data/test/functional/kaui/account_emails_controller_test.rb +28 -0
  108. data/test/functional/kaui/account_tags_controller_test.rb +29 -0
  109. data/test/functional/kaui/account_timelines_controller_test.rb +21 -0
  110. data/test/functional/kaui/accounts_controller_test.rb +56 -50
  111. data/test/functional/kaui/bundle_tags_controller_test.rb +29 -0
  112. data/test/functional/kaui/bundles_controller_test.rb +58 -13
  113. data/test/functional/kaui/chargebacks_controller_test.rb +16 -5
  114. data/test/functional/kaui/charges_controller_test.rb +39 -0
  115. data/test/functional/kaui/credits_controller_test.rb +35 -0
  116. data/test/functional/kaui/custom_fields_controller_test.rb +21 -0
  117. data/test/functional/kaui/functional_test_helper.rb +61 -0
  118. data/test/functional/kaui/invoice_items_controller_test.rb +24 -10
  119. data/test/functional/kaui/invoices_controller_test.rb +41 -13
  120. data/test/functional/kaui/payment_methods_controller_test.rb +49 -0
  121. data/test/functional/kaui/payments_controller_test.rb +32 -5
  122. data/test/functional/kaui/refunds_controller_test.rb +40 -5
  123. data/test/functional/kaui/subscriptions_controller_test.rb +82 -0
  124. data/test/functional/kaui/tag_definitions_controller_test.rb +27 -53
  125. data/test/functional/kaui/tags_controller_test.rb +21 -0
  126. data/test/functional/kaui/transactions_controller_test.rb +32 -0
  127. data/test/integration/kaui/integration_test_helper.rb +31 -0
  128. data/test/integration/kaui/navigation_test.rb +43 -0
  129. data/test/killbill_test_helper.rb +143 -0
  130. data/test/test_helper.rb +10 -227
  131. data/test/unit/kaui/account_email_test.rb +19 -0
  132. data/test/unit/kaui/account_test.rb +7 -35
  133. data/test/unit/kaui/base_test.rb +5 -46
  134. data/test/unit/kaui/date_helper_test.rb +6 -5
  135. data/test/unit/kaui/invoice_item_test.rb +5 -17
  136. data/test/unit/kaui/invoice_payment_test.rb +42 -0
  137. data/test/unit/kaui/invoice_test.rb +15 -15
  138. data/test/unit/kaui/money_helper_test.rb +10 -0
  139. data/test/unit/kaui/payment_test.rb +42 -0
  140. data/test/unit/kaui/tag_definition_test.rb +5 -28
  141. data/test/unit/kaui/uuid_helper_test.rb +10 -0
  142. metadata +134 -159
  143. data/app/controllers/kaui/analytics_controller.rb +0 -28
  144. data/app/helpers/kaui/killbill_helper.rb +0 -611
  145. data/app/models/kaui/analytics.rb +0 -19
  146. data/app/models/kaui/analytics_sanity.rb +0 -7
  147. data/app/models/kaui/business_account.rb +0 -12
  148. data/app/models/kaui/business_field.rb +0 -6
  149. data/app/models/kaui/business_invoice.rb +0 -31
  150. data/app/models/kaui/business_invoice_item.rb +0 -17
  151. data/app/models/kaui/business_invoice_payment.rb +0 -25
  152. data/app/models/kaui/business_overdue_status.rb +0 -8
  153. data/app/models/kaui/business_snapshot.rb +0 -9
  154. data/app/models/kaui/business_subscription_transition.rb +0 -53
  155. data/app/models/kaui/business_tag.rb +0 -5
  156. data/app/models/kaui/charge.rb +0 -14
  157. data/app/models/kaui/entitlement.rb +0 -2
  158. data/app/models/kaui/event.rb +0 -13
  159. data/app/models/kaui/external_payment.rb +0 -15
  160. data/app/models/kaui/overdue_state.rb +0 -10
  161. data/app/models/kaui/payment_attempt.rb +0 -27
  162. data/app/models/kaui/product.rb +0 -24
  163. data/app/models/kaui/time_series_data.rb +0 -8
  164. data/app/views/kaui/analytics/account_snapshot.html.erb +0 -211
  165. data/app/views/kaui/analytics/index.html.erb +0 -17
  166. data/app/views/kaui/chargebacks/index.html.erb +0 -14
  167. data/app/views/kaui/chargebacks/show.html.erb +0 -19
  168. data/app/views/kaui/credits/index.html.erb +0 -14
  169. data/app/views/kaui/credits/show.html.erb +0 -19
  170. data/app/views/kaui/invoice_items/index.html.erb +0 -20
  171. data/app/views/kaui/invoice_items/show.html.erb +0 -31
  172. data/app/views/kaui/refunds/_refunds_table.html.erb +0 -31
  173. data/app/views/kaui/refunds/index.html.erb +0 -43
  174. data/app/views/kaui/refunds/show.html.erb +0 -33
  175. data/app/views/kaui/tag_definitions/edit.html.erb +0 -3
  176. data/test/dummy/test/fixtures/accounts.yml +0 -32
  177. data/test/dummy/test/fixtures/bill_cycle_days.yml +0 -3
  178. data/test/dummy/test/fixtures/bundles.yml +0 -4
  179. data/test/dummy/test/fixtures/invoice_items.yml +0 -13
  180. data/test/dummy/test/fixtures/invoices.yml +0 -11
  181. data/test/dummy/test/fixtures/overdue_states.yml +0 -8
  182. data/test/dummy/test/fixtures/payment_methods.yml +0 -5
  183. data/test/dummy/test/fixtures/plugin_info_properties.yml +0 -59
  184. data/test/dummy/test/fixtures/plugin_infos.yml +0 -2
  185. data/test/dummy/test/fixtures/refunds.yml +0 -9
  186. data/test/dummy/test/fixtures/tag_definitions.yml +0 -20
  187. data/test/functional/kaui/account_timeline_controller_test.rb +0 -9
  188. data/test/functional/kaui/extpayments_controller_test.rb +0 -9
  189. data/test/functional/kaui/home_controller_test.rb +0 -11
  190. data/test/integration/navigation_test.rb +0 -10
  191. data/test/kaui_test.rb +0 -7
  192. data/test/unit/helpers/kaui/account_timeline_helper_test.rb +0 -6
  193. data/test/unit/helpers/kaui/bundles_helper_test.rb +0 -6
  194. data/test/unit/helpers/kaui/chargebacks_helper_test.rb +0 -6
  195. data/test/unit/helpers/kaui/extpayments_helper_test.rb +0 -6
  196. data/test/unit/helpers/kaui/home_helper_test.rb +0 -6
  197. data/test/unit/helpers/kaui/invoices_helper_test.rb +0 -6
  198. data/test/unit/helpers/kaui/payments_helper_test.rb +0 -6
  199. data/test/unit/helpers/kaui/refunds_helper_test.rb +0 -6
  200. data/test/unit/kaui/overdue_state_test.rb +0 -18
  201. data/test/unit/kaui/refund_test.rb +0 -20
  202. data/test/unit/model_test.rb +0 -151
@@ -1,127 +1,47 @@
1
1
  class Kaui::RefundsController < Kaui::EngineController
2
2
 
3
- def index
4
- if params[:refund_id].present?
5
- redirect_to kaui_engine.refund_path(params[:refund_id])
6
- end
7
- end
8
-
9
- def pagination
10
- json = { :sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => [] }
11
-
12
- search_key = params[:sSearch]
13
- if search_key.present?
14
- refunds = Kaui::KillbillHelper::search_refunds(search_key, params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
15
- else
16
- refunds = Kaui::KillbillHelper::get_refunds(params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
17
- end
18
- json[:iTotalDisplayRecords] = refunds.pagination_total_nb_records
19
- json[:iTotalRecords] = refunds.pagination_max_nb_records
20
-
21
- refunds.each do |refund|
22
- json[:aaData] << [
23
- view_context.link_to(refund.refund_id, view_context.url_for(:controller => :refunds, :action => :show, :id => refund.refund_id)),
24
- view_context.format_date(refund.effective_date),
25
- view_context.humanized_money_with_symbol(Kaui::Base.to_money(refund.amount, refund.currency)),
26
- refund.adjusted,
27
- refund.status
28
- ]
29
- end
30
-
31
- respond_to do |format|
32
- format.json { render :json => json }
33
- end
34
- end
35
-
36
- def show
37
- if params[:id].present?
38
- begin
39
- data = Kaui::KillbillHelper::get_refund(params[:id], options_for_klient)
40
- rescue => e
41
- flash.now[:error] = "Error while retrieving the refund with id #{params[:id]}: #{as_string(e)}"
42
- end
43
- if data.present?
44
- @refunds = [data]
45
- else
46
- begin
47
- @refunds = Kaui::KillbillHelper::get_refunds_for_payment(params[:id], options_for_klient)
48
- unless @refunds.present?
49
- flash.now[:error] = "Refund for id or payment id #{params[:id]} couldn't be found"
50
- render :action => :index and return
51
- end
52
- rescue => e
53
- flash.now[:error] = "Error while retrieving the refunds for the payment: #{as_string(e)}"
54
- render :action => :index and return
55
- end
56
- end
57
-
58
- if @refunds.size > 0
59
- begin
60
- # Retrieve the account via the payment
61
- payment = Kaui::KillbillHelper::get_payment(@refunds[0].payment_id, options_for_klient)
62
- unless payment.present?
63
- flash.now[:error] = "Account for payment id #{@refunds[0].payment_id} couldn't be found"
64
- render :action => :index
65
- end
66
- @account = Kaui::KillbillHelper::get_account(payment.account_id, false, false, options_for_klient)
67
- rescue => e
68
- flash.now[:error] = "Error while retrieving the account for the refund: #{as_string(e)}"
69
- render :action => :index
70
- end
71
- end
72
- else
73
- flash.now[:error] = "A refund or payment id should be specifed"
74
- render :action => :index
75
- end
76
- end
77
-
78
3
  def new
79
- @payment_id = params[:payment_id]
80
- @invoice_id = params[:invoice_id]
81
- @account_id = params[:account_id]
4
+ payment_id = params[:payment_id]
5
+ invoice_id = params[:invoice_id]
6
+ account_id = params[:account_id]
82
7
 
83
- @refund = Kaui::Refund.new('adjusted' => true)
8
+ @refund = KillBillClient::Model::InvoiceItem.new
84
9
 
85
10
  begin
86
- @account = Kaui::KillbillHelper::get_account(@account_id, false, false, options_for_klient)
87
- @payment = Kaui::KillbillHelper::get_payment(@payment_id, options_for_klient)
88
- @invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, "NONE", options_for_klient)
11
+ @account = Kaui::Account.find_by_id(account_id, false, false, options_for_klient)
12
+ @payment = Kaui::InvoicePayment::find_by_id(payment_id, false, options_for_klient)
13
+ @invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
89
14
  rescue => e
90
15
  flash[:error] = "Error while processing refund: #{as_string(e)}"
91
- redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
16
+ redirect_to kaui_engine.account_timeline_path(:id => account_id)
92
17
  end
93
18
  end
94
19
 
95
20
  def create
96
- invoice = Kaui::KillbillHelper::get_invoice(params[:invoice_id], true, "NONE", options_for_klient)
97
- refund = {}
98
- refund.merge! params[:refund]
99
- refund["adjusted"] = (refund["adjustment_type"] != "noInvoiceAdjustment")
21
+ invoice = Kaui::Invoice.find_by_id_or_number(params[:invoice_id], true, 'NONE', options_for_klient)
22
+
23
+ items = []
24
+ if params[:adjustment_type] == 'invoiceItemAdjustment'
25
+ (params[:adjustments] || []).each do |ii|
26
+ original_item = find_original_item(invoice.items, ii[0])
100
27
 
101
- if refund["adjustment_type"] == "invoiceItemAdjustment"
102
- refund["adjustments"] = []
103
- params[:adjustments].each_with_index do |ii, idx|
104
- original_item = find_original_item(invoice.items, ii[0])
105
- h = Hash.new
106
- h[:invoice_item_id] = ii[0]
28
+ item = KillBillClient::Model::InvoiceItem.new
29
+ item.invoice_item_id = ii[0]
107
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
108
- # decide what is the maxium amount we can have on that item
109
- h[:amount] = (ii[1].to_f == original_item.amount) ? nil : ii[1]
110
- kaui_ii = Kaui::InvoiceItem.new(h)
111
- puts "Got #{kaui_ii.inspect}"
112
- refund["adjustments"][idx] = kaui_ii
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]
33
+
34
+ items << item
113
35
  end
114
36
  end
115
- if refund.present?
116
- begin
117
- Kaui::KillbillHelper::create_refund(params[:payment_id], refund, current_user, params[:reason], params[:comment], options_for_klient)
118
- flash[:notice] = "Refund created"
119
- rescue => e
120
- flash[:error] = "Error while processing refund: #{as_string(e)}"
121
- end
122
- else
123
- flash[:error] = "No refund to process"
37
+
38
+ begin
39
+ KillBillClient::Model::InvoicePayment.refund(params[:payment_id], params[:amount], items, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
40
+ flash[:notice] = 'Refund created'
41
+ rescue => e
42
+ flash[:error] = "Error while processing refund: #{as_string(e)}"
124
43
  end
44
+
125
45
  redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
126
46
  end
127
47
 
@@ -1,121 +1,73 @@
1
- require 'kaui/product'
2
-
3
1
  class Kaui::SubscriptionsController < Kaui::EngineController
4
- def index
5
- if params[:subscription_id].present?
6
- redirect_to kaui_engine.subscription_path(params[:subscription_id])
7
- end
8
- end
9
2
 
10
- def show
11
- begin
12
- @subscription = Kaui::KillbillHelper.get_subscription(params[:id], options_for_klient)
13
- unless @subscription.present?
14
- flash[:error] = "No subscription id given or subscription not found"
15
- redirect_to :back
16
- end
17
-
18
- @account = Kaui::KillbillHelper::get_account_by_bundle_id(@subscription.bundle_id, options_for_klient)
19
- unless @account.present?
20
- flash[:error] = "Unable to retrieve account for bundle #{@subscription.bundle_id}"
21
- redirect_to :back
22
- end
23
- rescue => e
24
- flash.now[:error] = "Error while getting subscription information: #{as_string(e)}"
25
- end
3
+ def index
26
4
  end
27
5
 
28
6
  def new
29
- @account_id = params[:account_id]
30
- bundle_id = params[:bundle_id]
31
- @base_subscription = params[:base_subscription]
32
- @product_category = params[:product_category]
33
- begin
7
+ @base_product_name = params[:base_product_name]
8
+ @subscription = Kaui::Subscription.new(:bundle_id => params[:bundle_id],
9
+ :account_id => params[:account_id],
10
+ :product_category => params[:product_category] || 'BASE')
34
11
 
35
- if @product_category == "ADD_ON"
36
- @bundle = Kaui::KillbillHelper::get_bundle(bundle_id, options_for_klient)
37
- @catalog = Kaui::KillbillHelper::get_available_addons(@base_subscription, options_for_klient)
38
- elsif @product_category == "BASE"
39
- @catalog = Kaui::KillbillHelper::get_available_base_plans(options_for_klient)
12
+ begin
13
+ if @subscription.product_category == 'ADD_ON'
14
+ @bundle = Kaui::Bundle::find_by_id(@subscription.bundle_id, options_for_klient)
15
+ plans_details = Kaui::Catalog::available_addons(@base_product_name, options_for_klient)
16
+ else
17
+ plans_details = Kaui::Catalog::available_base_plans(options_for_klient)
40
18
  end
19
+ @plans = plans_details.map { |p| p.plan }
41
20
  rescue => e
42
21
  flash.now[:error] = "Error while trying to start new subscription creation: #{as_string(e)}"
22
+ render :action => :index
43
23
  end
44
- @subscription = Kaui::Subscription.new("bundleId" => bundle_id, "accountId" => @account_id, "product_category" => @product_category)
45
24
  end
46
25
 
47
26
  def create
48
-
49
- @subscription = Kaui::Subscription.new(params[:subscription])
50
-
51
- @plan_name = params[:plan_name]
27
+ @subscription = Kaui::Subscription.new(params[:subscription].delete_if { |key, value| value.blank? })
52
28
 
53
29
  begin
54
- if @subscription.product_category == "ADD_ON"
55
- @base_subscription = params[:base_subscription]
56
- @bundle = Kaui::KillbillHelper::get_bundle(@subscription.bundle_id, options_for_klient)
57
- @catalog = Kaui::KillbillHelper::get_available_addons(@base_subscription, options_for_klient)
58
- @subscription.account_id = @bundle.account_id
30
+ if @subscription.product_category == 'ADD_ON'
31
+ @bundle = Kaui::Bundle::find_by_id(@subscription.bundle_id, options_for_klient)
32
+ plans_details = Kaui::Catalog::available_addons(params[:base_product_name], options_for_klient)
59
33
  else
60
- @catalog = Kaui::KillbillHelper::get_available_base_plans(options_for_klient)
61
- @subscription.external_key = params[:external_key]
34
+ plans_details = Kaui::Catalog::available_base_plans(options_for_klient)
62
35
  end
63
36
 
64
- plan = @catalog[@plan_name]
65
- @subscription.billing_period = plan["billingPeriod"]
66
- @subscription.product_name = plan["productName"]
67
- @subscription.price_list = plan["priceListName"]
68
-
69
- res = Kaui::KillbillHelper::create_subscription(@subscription, current_user, params[:reason], params[:comment], options_for_klient)
37
+ plan_details = plans_details.find { |p| p.plan == params[:plan_name] }
38
+ @subscription.billing_period = plan_details.final_phase_billing_period
39
+ @subscription.product_name = plan_details.product
40
+ @subscription.price_list = plan_details.price_list
70
41
 
71
- redirect_to Kaui.bundle_home_path.call(res.bundle_id)
42
+ @subscription = @subscription.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
43
+ redirect_to bundle_path(@subscription.bundle_id), :notice => 'Subscription was successfully created'
72
44
  rescue => e
73
- flash.now[:error] = "Error while creating the new subscription: #{as_string(e)}"
45
+ @plans = plans_details.nil? ? [] : plans_details.map { |p| p.plan }
46
+ flash.now[:error] = "Error while creating the subscription: #{as_string(e)}"
74
47
  render :new
75
48
  end
76
49
  end
77
50
 
78
- def add_addon
79
- @base_product_name = params[:base_product_name]
80
-
81
- @account_id = params[:account_id]
82
- @bundle_id = params[:bundle_id]
83
- @product_name = params[:product_name]
84
- @product_category = params[:product_category]
85
- @billing_period = params[:billing_period]
86
- @price_list = params[:price_list]
87
-
51
+ def show
88
52
  begin
89
- @subscription = Kaui::Subscription.new(:account_id => @account_id,
90
- :bundle_id => @bundle_id,
91
- :product_name => @product_name,
92
- :product_category => @product_category,
93
- :billing_period => @billing_period,
94
- :price_list => @price_list)
95
-
96
- @bundle = Kaui::KillbillHelper.get_bundle(subscription.bundle_id, options_for_klient)
97
- @available_plans = Kaui::KillbillHelper.get_available_addons(params[:base_product_name], options_for_klient)
53
+ @subscription = Kaui::Subscription.find_by_id(params[:id], options_for_klient)
54
+ # Need to retrieve the account for the timezone
55
+ @account = Kaui::Account::find_by_id(@subscription.account_id, false, false, options_for_klient)
98
56
  rescue => e
99
- flash.now[:error] = "Error while adding an addon: #{as_string(e)}"
57
+ flash.now[:error] = "Error while getting subscription information: #{as_string(e)}"
58
+ render :action => :index
100
59
  end
101
60
  end
102
61
 
103
62
  def edit
104
63
  begin
105
- @subscription = Kaui::KillbillHelper.get_subscription(params[:id], options_for_klient)
106
- if @subscription.present?
107
- @bundle = Kaui::KillbillHelper::get_bundle(@subscription.bundle_id, options_for_klient)
108
- @account = Kaui::KillbillHelper::get_account(@bundle.account_id, false, false, options_for_klient)
109
- @catalog = Kaui::KillbillHelper::get_available_base_plans(options_for_klient)
64
+ @subscription = Kaui::Subscription.find_by_id(params[:id], options_for_klient)
65
+ plans_details = Kaui::Catalog::available_base_plans(options_for_klient)
66
+ @plans = plans_details.map { |p| p.plan }
110
67
 
111
- @current_plan = "#{@subscription.product_name} #{@subscription.billing_period}".humanize
112
-
113
- if @subscription.price_list != "DEFAULT"
114
- @current_plan += " (price list #{@subscription.price_list})"
115
- end
116
- else
117
- flash[:error] = "No subscription id given or subscription not found"
118
- redirect_to :back
68
+ @current_plan = "#{@subscription.product_name} #{@subscription.billing_period}".humanize
69
+ if @subscription.price_list != 'DEFAULT'
70
+ @current_plan += " (price list #{@subscription.price_list})"
119
71
  end
120
72
  rescue => e
121
73
  flash.now[:error] = "Error while editing subscription: #{as_string(e)}"
@@ -123,61 +75,65 @@ class Kaui::SubscriptionsController < Kaui::EngineController
123
75
  end
124
76
 
125
77
  def update
126
- if params.has_key?(:subscription) && params[:subscription].has_key?(:subscription_id)
127
-
128
- begin
129
- subscription = Kaui::KillbillHelper::get_subscription(params[:subscription][:subscription_id], options_for_klient)
130
- bundle = Kaui::KillbillHelper::get_bundle(subscription.bundle_id, options_for_klient)
131
- catalog = Kaui::KillbillHelper::get_available_base_plans(options_for_klient)
132
-
133
- plan = catalog[params[:plan_name]]
134
- requested_date = params[:requested_date]
135
- policy = params[:policy] unless params[:policy].empty?
136
-
137
- subscription.billing_period = plan["billingPeriod"]
138
- subscription.product_category = plan["productCategory"]
139
- subscription.product_name = plan["productName"]
140
- subscription.price_list = plan["priceListName"]
141
- subscription.subscription_id = params[:subscription][:subscription_id]
142
-
143
- Kaui::KillbillHelper::update_subscription(subscription, requested_date, policy, current_user, params[:reason], params[:comment], options_for_klient)
144
- rescue => e
145
- flash[:error] = "Error while updating subscription: #{as_string(e)}"
146
- end
147
- else
148
- flash[:error] = "No subscription given"
78
+ requested_date = params[:requested_date] unless params[:requested_date].blank?
79
+ billing_policy = params[:policy] unless params[:policy].blank?
80
+ wait_for_completion = params[:wait_for_completion] == '1'
81
+
82
+ subscription = Kaui::Subscription.new(:subscription_id => params[:id])
83
+
84
+ begin
85
+ plans_details = Kaui::Catalog::available_base_plans(options_for_klient)
86
+ new_plan_details = plans_details.find { |p| p.plan == params[:plan_name] }
87
+
88
+ subscription.change_plan({
89
+ :productName => new_plan_details.product,
90
+ :billingPeriod => new_plan_details.final_phase_billing_period,
91
+ :priceList => new_plan_details.price_list
92
+ },
93
+ current_user.kb_username,
94
+ params[:reason],
95
+ params[:comment],
96
+ requested_date,
97
+ billing_policy,
98
+ wait_for_completion,
99
+ options_for_klient)
100
+ flash[:notice] = 'Subscription plan successfully changed'
101
+ rescue => e
102
+ flash[:error] = "Error while changing subscription plan: #{as_string(e)}"
149
103
  end
150
- redirect_to Kaui.bundle_home_path.call(bundle.bundle_id)
104
+
105
+ redirect_to subscription_path(subscription.subscription_id)
151
106
  end
152
107
 
153
108
  def destroy
154
- subscription_id = params[:id]
109
+ requested_date = params[:requested_date] unless params[:requested_date].blank?
110
+ entitlement_policy = params[:policy] unless params[:policy].blank?
111
+ billing_policy = entitlement_policy
112
+ # true by default
113
+ use_requested_date_for_billing = (params[:use_requested_date_for_billing] || '1') == '1'
155
114
 
156
- if subscription_id.present?
157
- begin
158
- Kaui::KillbillHelper::delete_subscription(subscription_id, current_user, params[:reason], params[:comment], params[:policy], params[:policy], options_for_klient)
159
- rescue => e
160
- flash[:error] = "Error while canceling subscription: #{as_string(e)}"
161
- end
162
- else
163
- flash[:error] = "No subscription id given"
115
+ subscription = Kaui::Subscription.new(:subscription_id => params[:id])
116
+
117
+ begin
118
+ subscription.cancel(current_user.kb_username, params[:reason], params[:comment], requested_date, entitlement_policy, billing_policy, use_requested_date_for_billing, options_for_klient)
119
+ flash[:notice] = 'Subscription was successfully cancelled'
120
+ rescue => e
121
+ flash[:error] = "Error while canceling subscription: #{as_string(e)}"
164
122
  end
165
- redirect_to :back
123
+
124
+ redirect_to subscription_path(subscription.subscription_id)
166
125
  end
167
126
 
168
127
  def reinstate
169
- subscription_id = params[:id]
170
- if subscription_id.present?
171
- begin
172
- Kaui::KillbillHelper::reinstate_subscription(subscription_id, current_user, params[:reason], params[:comment], options_for_klient)
173
- flash[:notice] = "Subscription reinstated"
174
- rescue => e
175
- flash[:error] = "Error while reinstating subscription: #{as_string(e)}"
176
- end
177
- else
178
- flash[:error] = "No subscription id given"
128
+ subscription = Kaui::Subscription.new(:subscription_id => params[:id])
129
+
130
+ begin
131
+ subscription.uncancel(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
132
+ flash[:notice] = 'Subscription was successfully reinstated'
133
+ rescue => e
134
+ flash[:error] = "Error while reinstating subscription: #{as_string(e)}"
179
135
  end
180
- redirect_to :back
181
- end
182
136
 
137
+ redirect_to subscription_path(subscription.subscription_id)
138
+ end
183
139
  end
@@ -1,90 +1,43 @@
1
- module Kaui
2
- class TagDefinitionsController < Kaui::EngineController
3
- # GET /tag_definitions
4
- # GET /tag_definitions.json
5
- def index
6
- begin
7
- @tag_definitions = TagDefinition.all(options_for_klient)
8
- rescue => e
9
- flash.now[:error] = "Error while retrieving tag definitions: #{as_string(e)}"
10
- @tag_definitions = []
11
- end
12
-
13
- respond_to do |format|
14
- format.html # index.html.erb
15
- format.json { render :json => @tag_definitions }
16
- end
17
- end
18
-
19
- # GET /tag_definitions/1
20
- # GET /tag_definitions/1.json
21
- def show
22
- @tag_definition = TagDefinition.find(params[:id], options_for_klient)
23
-
24
- respond_to do |format|
25
- format.html # show.html.erb
26
- format.json { render :json => @tag_definition }
27
- end
28
- end
29
-
30
- # GET /tag_definitions/new
31
- # GET /tag_definitions/new.json
32
- def new
33
- @tag_definition = TagDefinition.new
34
-
35
- respond_to do |format|
36
- format.html # new.html.erb
37
- format.json { render :json => @tag_definition }
38
- end
39
- end
40
-
41
- # GET /tag_definitions/1/edit
42
- def edit
43
- @tag_definition = TagDefinition.find(params[:id], options_for_klient)
1
+ class Kaui::TagDefinitionsController < Kaui::EngineController
2
+
3
+ def index
4
+ begin
5
+ @tag_definitions = Kaui::TagDefinition.all('NONE', options_for_klient)
6
+ rescue => e
7
+ flash.now[:error] = "Error while retrieving tag definitions: #{as_string(e)}"
8
+ @tag_definitions = []
44
9
  end
10
+ end
45
11
 
46
- # POST /tag_definitions
47
- # POST /tag_definitions.json
48
- def create
49
- @tag_definition = TagDefinition.new(params[:tag_definition])
12
+ def show
13
+ @tag_definition = Kaui::TagDefinition.find_by_id(params[:id], 'NONE', options_for_klient)
14
+ end
50
15
 
51
- respond_to do |format|
52
- if @tag_definition.save(current_user, params[:reason], params[:comment], options_for_klient)
53
- format.html { redirect_to @tag_definition, :notice => 'Tag definition was successfully created.' }
54
- format.json { render :json => @tag_definition, :status => :created, :location => @tag_definition }
55
- else
56
- format.html { render :action => "new" }
57
- format.json { render :json => @tag_definition.errors, :status => :unprocessable_entity }
58
- end
59
- end
60
- end
16
+ def new
17
+ @tag_definition = Kaui::TagDefinition.new
18
+ end
61
19
 
62
- # PUT /tag_definitions/1
63
- # PUT /tag_definitions/1.json
64
- def update
65
- @tag_definition = TagDefinition.find(params[:id], options_for_klient)
20
+ def create
21
+ @tag_definition = Kaui::TagDefinition.new(params[:tag_definition])
66
22
 
67
- respond_to do |format|
68
- if @tag_definition.update_attributes(params[:tag_definition])
69
- format.html { redirect_to @tag_definition, :notice => 'Tag definition was successfully updated.' }
70
- format.json { head :no_content }
71
- else
72
- format.html { render :action => "edit" }
73
- format.json { render :json => @tag_definition.errors, :status => :unprocessable_entity }
74
- end
75
- end
23
+ begin
24
+ @tag_definition = @tag_definition.create(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
25
+ redirect_to kaui_engine.tag_definition_path(@tag_definition.id), :notice => 'Tag definition successfully created'
26
+ rescue => e
27
+ flash.now[:error] = "Error while creating tag definition: #{as_string(e)}"
28
+ render :action => :new
76
29
  end
30
+ end
77
31
 
78
- # DELETE /tag_definitions/1
79
- # DELETE /tag_definitions/1.json
80
- def destroy
81
- @tag_definition = TagDefinition.find(params[:id], options_for_klient)
82
- @tag_definition.destroy(current_user, params[:reason], params[:comment], options_for_klient)
32
+ def destroy
33
+ @tag_definition = Kaui::TagDefinition.find_by_id(params[:id], 'NONE', options_for_klient)
83
34
 
84
- respond_to do |format|
85
- format.html { redirect_to tag_definitions_url, :notice => 'Tag definition was successfully destroyed.' }
86
- format.json { head :no_content }
87
- end
35
+ begin
36
+ @tag_definition.delete(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
37
+ redirect_to kaui_engine.tag_definitions_path, :notice => 'Tag definition successfully deleted'
38
+ rescue => e
39
+ flash.now[:error] = "Error while deleting tag definition: #{as_string(e)}"
40
+ render :action => :index
88
41
  end
89
42
  end
90
43
  end
@@ -4,27 +4,29 @@ class Kaui::TagsController < Kaui::EngineController
4
4
  end
5
5
 
6
6
  def pagination
7
- json = { :sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => [] }
8
-
9
7
  search_key = params[:sSearch]
10
- if search_key.present?
11
- tags = Kaui::KillbillHelper::search_tags(search_key, params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
12
- else
13
- tags = Kaui::KillbillHelper::get_tags(params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
14
- end
15
- json[:iTotalDisplayRecords] = tags.pagination_total_nb_records
16
- json[:iTotalRecords] = tags.pagination_max_nb_records
8
+ offset = params[:iDisplayStart] || 0
9
+ limit = params[:iDisplayLength] || 10
10
+
11
+ tags = Kaui::Tag.list_or_search(search_key, offset, limit, options_for_klient)
12
+
13
+ json = {
14
+ :sEcho => params[:sEcho],
15
+ :iTotalRecords => tags.pagination_max_nb_records,
16
+ :iTotalDisplayRecords => tags.pagination_total_nb_records,
17
+ :aaData => []
18
+ }
17
19
 
18
20
  tags.each do |tag|
19
21
  json[:aaData] << [
20
- tag.tag_id,
21
- tag.object_type,
22
- tag.tag_definition_name,
23
- ]
22
+ tag.tag_id,
23
+ tag.object_type,
24
+ tag.tag_definition_name,
25
+ ]
24
26
  end
25
27
 
26
28
  respond_to do |format|
27
29
  format.json { render :json => json }
28
30
  end
29
31
  end
30
- end
32
+ end
@@ -0,0 +1,25 @@
1
+ class Kaui::TransactionsController < Kaui::EngineController
2
+
3
+ def new
4
+ @account_id = params[:account_id]
5
+ @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])
10
+ end
11
+
12
+ def create
13
+ @account_id = params[:account_id]
14
+ @payment_method_id = params[:payment_method_id]
15
+ @transaction = Kaui::Transaction.new(params[:transaction].delete_if { |key, value| value.blank? })
16
+
17
+ begin
18
+ payment = @transaction.create(@account_id, @payment_method_id, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
19
+ redirect_to kaui_engine.account_timeline_path(:id => payment.account_id), :notice => 'Transaction successfully created'
20
+ rescue => e
21
+ flash.now[:error] = "Error while creating a new transaction: #{as_string(e)}"
22
+ render :action => :new
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ module Kaui
2
+ module MoneyHelper
3
+
4
+ def currencies
5
+ (Money::Currency.table.map { |c| c[1][:iso_code] } + ['BTC']).sort.uniq
6
+ end
7
+ end
8
+ end