kaui 0.0.2 → 0.0.3

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 (30) hide show
  1. data/app/controllers/kaui/account_tags_controller.rb +1 -1
  2. data/app/controllers/kaui/account_timelines_controller.rb +1 -1
  3. data/app/controllers/kaui/accounts_controller.rb +1 -1
  4. data/app/controllers/kaui/bundle_tags_controller.rb +1 -1
  5. data/app/controllers/kaui/bundles_controller.rb +1 -1
  6. data/app/controllers/kaui/chargebacks_controller.rb +5 -2
  7. data/app/controllers/kaui/credits_controller.rb +1 -1
  8. data/app/controllers/kaui/engine_controller.rb +6 -0
  9. data/app/controllers/kaui/home_controller.rb +2 -4
  10. data/app/controllers/kaui/invoices_controller.rb +2 -2
  11. data/app/controllers/kaui/payment_methods_controller.rb +1 -1
  12. data/app/controllers/kaui/refunds_controller.rb +10 -4
  13. data/app/controllers/kaui/subscriptions_controller.rb +60 -8
  14. data/app/helpers/kaui/killbill_helper.rb +94 -60
  15. data/app/models/kaui/account.rb +2 -2
  16. data/app/models/kaui/invoice.rb +8 -9
  17. data/app/models/kaui/invoice_item.rb +8 -7
  18. data/app/models/kaui/payment.rb +14 -15
  19. data/app/models/kaui/subscription.rb +10 -10
  20. data/app/views/kaui/chargebacks/new.html.erb +1 -1
  21. data/app/views/kaui/invoices/show.html.erb +3 -4
  22. data/app/views/kaui/refunds/new.html.erb +2 -2
  23. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +16 -12
  24. data/app/views/kaui/subscriptions/new.html.erb +22 -0
  25. data/app/views/kaui/subscriptions/show.html.erb +1 -1
  26. data/config/routes.rb +6 -2
  27. data/lib/kaui/version.rb +1 -1
  28. data/lib/kaui.rb +0 -2
  29. metadata +6 -5
  30. data/app/controllers/kaui/application_controller.rb +0 -2
@@ -1,4 +1,4 @@
1
- class Kaui::AccountTagsController < ApplicationController
1
+ class Kaui::AccountTagsController < Kaui::EngineController
2
2
 
3
3
  def show
4
4
  account_id = params[:id]
@@ -1,4 +1,4 @@
1
- class Kaui::AccountTimelinesController < ApplicationController
1
+ class Kaui::AccountTimelinesController < Kaui::EngineController
2
2
  def index
3
3
  if params[:account_id].present?
4
4
  redirect_to account_timeline_path(params[:account_id])
@@ -1,7 +1,7 @@
1
1
  require 'rest_client'
2
2
  require 'json'
3
3
 
4
- class Kaui::AccountsController < ApplicationController
4
+ class Kaui::AccountsController < Kaui::EngineController
5
5
  def index
6
6
  if params[:account_id].present?
7
7
  redirect_to account_path(params[:account_id])
@@ -1,4 +1,4 @@
1
- class Kaui::BundleTagsController < ApplicationController
1
+ class Kaui::BundleTagsController < Kaui::EngineController
2
2
 
3
3
  def show
4
4
  bundle_id = params[:id]
@@ -1,4 +1,4 @@
1
- class Kaui::BundlesController < ApplicationController
1
+ class Kaui::BundlesController < Kaui::EngineController
2
2
 
3
3
  def index
4
4
  if params[:bundle_id].present?
@@ -1,4 +1,4 @@
1
- class Kaui::ChargebacksController < ApplicationController
1
+ class Kaui::ChargebacksController < Kaui::EngineController
2
2
  def show
3
3
  @payment_id = params[:id]
4
4
  if @payment_id.present?
@@ -34,9 +34,12 @@ class Kaui::ChargebacksController < ApplicationController
34
34
  success = Kaui::KillbillHelper::create_chargeback(chargeback, params[:reason], params[:comment])
35
35
  if success
36
36
  flash[:info] = "Chargeback created"
37
+ else
38
+ flash[:error] = "Could not process chargeback"
37
39
  end
40
+ else
41
+ flash[:error] = "No chargeback to process"
38
42
  end
39
- flash[:error] = "Could not process chargeback"
40
43
  redirect_to account_timeline_path(:id => params[:account_id])
41
44
  end
42
45
 
@@ -1,4 +1,4 @@
1
- class Kaui::CreditsController < ApplicationController
1
+ class Kaui::CreditsController < Kaui::EngineController
2
2
  def show
3
3
  @payment_id = params[:id]
4
4
  if @payment_id.present?
@@ -0,0 +1,6 @@
1
+ class Kaui::EngineController < ApplicationController
2
+ # This is a semi-isolated engine (https://bibwild.wordpress.com/2012/05/10/the-semi-isolated-rails-engine/)
3
+ # We expect that the hosting app's ApplicationController has these methods defined:
4
+ #
5
+ # current_user - returns the id of the current user
6
+ end
@@ -1,6 +1,4 @@
1
- module Kaui
2
- class HomeController < ApplicationController
3
- def index
4
- end
1
+ class Kaui::HomeController < Kaui::EngineController
2
+ def index
5
3
  end
6
4
  end
@@ -1,4 +1,4 @@
1
- class Kaui::InvoicesController < ApplicationController
1
+ class Kaui::InvoicesController < Kaui::EngineController
2
2
  def index
3
3
  if params[:id].present?
4
4
  redirect_to invoice_path(params[:id])
@@ -23,7 +23,7 @@ class Kaui::InvoicesController < ApplicationController
23
23
  end
24
24
  end
25
25
  else
26
- flash[:error] = "Invoice items for #{@invoice_id} not found"
26
+ flash[:error] = "Invoice items for #{@invoice_id} not found"
27
27
  end
28
28
  else
29
29
  flash[:error] = "Invoice #{@invoice_id} not found"
@@ -1,6 +1,6 @@
1
1
  require 'kaui/killbill_helper'
2
2
 
3
- class Kaui::PaymentMethodsController < ApplicationController
3
+ class Kaui::PaymentMethodsController < Kaui::EngineController
4
4
  def show
5
5
  # TODO: show payment method details
6
6
  end
@@ -1,4 +1,4 @@
1
- class Kaui::RefundsController < ApplicationController
1
+ class Kaui::RefundsController < Kaui::EngineController
2
2
  def show
3
3
  @payment_id = params[:id]
4
4
  if @payment_id.present?
@@ -32,10 +32,16 @@ class Kaui::RefundsController < ApplicationController
32
32
  refund = Kaui::Refund.new(params[:refund])
33
33
  refund.adjusted = (refund.adjusted == "1")
34
34
  if refund.present?
35
- Kaui::KillbillHelper::create_refund(params[:payment_id], refund, params[:reason], params[:comment])
36
- redirect_to account_timeline_path(:id => params[:account_id])
35
+ success = Kaui::KillbillHelper::create_refund(params[:payment_id], refund, params[:reason], params[:comment])
36
+ if success
37
+ flash[:info] = "Refund created"
38
+ else
39
+ flash[:error] = "Error while processing refund"
40
+ end
37
41
  else
38
- flash[:error] = "No refund given to process"
42
+ flash[:error] = "No refund to process"
39
43
  end
44
+ redirect_to account_timeline_path(:id => params[:account_id])
40
45
  end
46
+
41
47
  end
@@ -1,6 +1,6 @@
1
1
  require 'kaui/product'
2
2
 
3
- class Kaui::SubscriptionsController < ApplicationController
3
+ class Kaui::SubscriptionsController < Kaui::EngineController
4
4
  def index
5
5
  if params[:subscription_id].present?
6
6
  redirect_to subscription_path(params[:subscription_id])
@@ -16,6 +16,48 @@ class Kaui::SubscriptionsController < ApplicationController
16
16
  end
17
17
 
18
18
  def new
19
+ bundle_id = params[:bundle_id]
20
+ @base_subscription = params[:base_subscription]
21
+ @bundle = Kaui::KillbillHelper::get_bundle(bundle_id)
22
+ if @base_subscription.present?
23
+ @catalog = Kaui::KillbillHelper::get_available_addons(@base_subscription)
24
+ else
25
+ # TODO: call catalog to get base subscription types
26
+ end
27
+
28
+ @subscription = Kaui::Subscription.new("bundleId" => bundle_id)
29
+ end
30
+
31
+ def create
32
+ @base_subscription = params[:base_subscription]
33
+ @subscription = Kaui::Subscription.new(params[:subscription])
34
+ @bundle = Kaui::KillbillHelper::get_bundle(@subscription.bundle_id)
35
+ @plan_name = params[:plan_name]
36
+ if @base_subscription.present?
37
+ @catalog = Kaui::KillbillHelper::get_available_addons(@base_subscription)
38
+ @subscription.product_category = "ADD_ON"
39
+ else
40
+ # TODO: call catalog to get base subscription types
41
+ @subscription.product_category = "BASE"
42
+ end
43
+
44
+ plan = @catalog[@plan_name]
45
+ @subscription.billing_period = plan["billingPeriod"]
46
+ @subscription.product_name = plan["productName"]
47
+ @subscription.price_list = plan["priceListName"]
48
+
49
+ begin
50
+ Kaui::KillbillHelper::create_subscription(@subscription)
51
+ redirect_to Kaui.bundle_home_path.call(@bundle.external_key)
52
+ rescue => e
53
+ flash[:error] = e.message
54
+ render :new
55
+ end
56
+ end
57
+
58
+ def add_addon
59
+ @base_product_name = params[:base_product_name]
60
+
19
61
  @bundle_id = params[:bundle_id]
20
62
  @product_name = params[:product_name]
21
63
  @product_category = params[:product_category]
@@ -27,14 +69,9 @@ class Kaui::SubscriptionsController < ApplicationController
27
69
  :product_category => @product_category,
28
70
  :billing_period => @billing_period,
29
71
  :price_list => @price_list)
30
- end
31
-
32
- def create
33
- subscription = Kaui::Subscription.new(params[:subscription])
34
- bundle = Kaui::KillbillHelper.get_bundle(subscription.bundle_id)
35
72
 
36
- Kaui::KillbillHelper::create_subscription(subscription)
37
- redirect_to account_timeline_path(:id => bundle.account_id)
73
+ @bundle = Kaui::KillbillHelper.get_bundle(subscription.bundle_id)
74
+ @available_plans = Kaui::KillbillHelper.get_available_addons(params[:base_product_name])
38
75
  end
39
76
 
40
77
  def edit
@@ -64,6 +101,21 @@ class Kaui::SubscriptionsController < ApplicationController
64
101
  end
65
102
  end
66
103
 
104
+ def reinstate
105
+ subscription_id = params[:id]
106
+ if subscription_id.present?
107
+ success = Kaui::KillbillHelper.reinstate_subscription(subscription_id, current_user)
108
+ if success
109
+ flash[:info] = "Subscription reinstated"
110
+ else
111
+ flash[:error] = "Error reinstating subscription"
112
+ end
113
+ redirect_to :back
114
+ else
115
+ flash[:error] = "No subscription id given"
116
+ end
117
+ end
118
+
67
119
  def destroy
68
120
  subscription_id = params[:id]
69
121
  if subscription_id.present?
@@ -15,6 +15,20 @@ module Kaui
15
15
  data
16
16
  end
17
17
 
18
+ def self.process_response(response, arity, &block)
19
+ if response.nil? || response[:json].nil?
20
+ arity == :single ? nil : []
21
+ elsif block_given?
22
+ arity == :single ? yield(response[:json]) : response[:json].collect {|item| yield(item) }
23
+ else
24
+ response[:json]
25
+ end
26
+ end
27
+
28
+ def self.extract_reason_code(reason)
29
+ reason_code = $1 if reason =~ /\s*(\d+).*/
30
+ end
31
+
18
32
  ############## ACCOUNT ##############
19
33
 
20
34
  def self.get_account_timeline(account_id)
@@ -106,7 +120,6 @@ module Kaui
106
120
  bundles.each do |bundle|
107
121
  subscriptions += get_subscriptions_for_bundle(bundle.bundle_id)
108
122
  end
109
- puts subscriptions
110
123
  subscriptions
111
124
  rescue RestClient::BadRequest
112
125
  []
@@ -124,60 +137,61 @@ module Kaui
124
137
  end
125
138
  end
126
139
 
127
- def self.create_subscription(subscription)
140
+ def self.create_subscription(subscription, current_user = nil, reason = nil, comment = nil)
128
141
  begin
129
142
  subscription_data = Kaui::Subscription.camelize(subscription.to_hash)
130
143
  data = call_killbill :post,
131
144
  "/1.0/kb/subscriptions",
132
145
  ActiveSupport::JSON.encode(subscription_data, :root => false),
133
146
  :content_type => "application/json",
134
- "X-Killbill-CreatedBy" => Kaui.current_user.call.to_s,
135
- "X-Killbill-Reason" => "Very special reason",
136
- "X-Killbill-Comment" => "Very special comment"
147
+ "X-Killbill-CreatedBy" => current_user,
148
+ "X-Killbill-Reason" => "#{reason}",
149
+ "X-Killbill-Comment" => "#{comment}"
137
150
  return data[:code] == 201
138
151
  rescue => e
139
152
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
140
153
  end
141
154
  end
142
155
 
143
- def self.update_subscription(subscription)
156
+ def self.update_subscription(subscription, current_user = nil, reason = nil, comment = nil)
144
157
  begin
145
158
  subscription_data = Kaui::Subscription.camelize(subscription.to_hash)
146
159
  data = call_killbill :put,
147
160
  "/1.0/kb/subscriptions/#{subscription.subscription_id}",
148
161
  ActiveSupport::JSON.encode(subscription_data, :root => false),
149
162
  :content_type => :json,
150
- "X-Killbill-CreatedBy" => Kaui.current_user.call.to_s,
151
- "X-Killbill-Reason" => "Very special reason",
152
- "X-Killbill-Comment" => "Very special comment"
153
- return data[:code] == 200
163
+ "X-Killbill-CreatedBy" => current_user,
164
+ "X-Killbill-Reason" => "#{reason}",
165
+ "X-Killbill-Comment" => "#{comment}"
166
+ return data[:code] < 300
154
167
  rescue => e
155
168
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
156
169
  end
157
170
  end
158
171
 
159
- def self.reinstate_subscription(subscription_id)
172
+ def self.reinstate_subscription(subscription_id, current_user = nil, reason = nil, comment = nil)
160
173
  begin
161
174
  data = call_killbill :put,
162
- "/1.0/subscriptions/#{subscription_id}/uncancel",
175
+ "/1.0/kb/subscriptions/#{subscription_id}/uncancel",
176
+ "",
163
177
  :content_type => :json,
164
- "X-Killbill-CreatedBy" => Kaui.current_user.call.to_s,
165
- "X-Killbill-Reason" => "Very special reason",
166
- "X-Killbill-Comment" => "Very special comment"
167
- return data[:code] == 200
178
+ "X-Killbill-CreatedBy" => current_user,
179
+ "X-Killbill-Reason" => "#{reason}",
180
+ "X-Killbill-Comment" => "#{comment}"
181
+ return data[:code] < 300
168
182
  rescue => e
169
183
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
170
184
  end
171
185
  end
172
186
 
173
- def self.delete_subscription(subscription_id)
187
+ def self.delete_subscription(subscription_id, current_user = nil, reason = nil, comment = nil)
174
188
  begin
175
189
  data = call_killbill :delete,
176
190
  "/1.0/kb/subscriptions/#{subscription_id}",
177
- "X-Killbill-CreatedBy" => Kaui.current_user.call.to_s,
178
- "X-Killbill-Reason" => "Very special reason",
179
- "X-Killbill-Comment" => "Very special comment"
180
- return data[:code] == 200
191
+ "X-Killbill-CreatedBy" => current_user,
192
+ "X-Killbill-Reason" => "#{reason}",
193
+ "X-Killbill-Comment" => "#{comment}"
194
+ return data[:code] < 300
181
195
  rescue => e
182
196
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
183
197
  end
@@ -196,10 +210,12 @@ module Kaui
196
210
 
197
211
  ############## CATALOG ##############
198
212
 
199
- def self.get_available_addons
213
+ def self.get_available_addons(base_product_name)
200
214
  begin
201
- data = call_killbill :get, "/1.0/catalog/availableAddons"
202
- return data[:json]
215
+ data = call_killbill :get, "/1.0/kb/catalog/availableAddons?baseProductName=#{base_product_name}"
216
+ if data.has_key?(:json)
217
+ data[:json].inject({}) {|catalog_hash, item| catalog_hash.merge!(item["planName"] => item) }
218
+ end
203
219
  rescue => e
204
220
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
205
221
  end
@@ -231,8 +247,12 @@ module Kaui
231
247
 
232
248
  def self.get_payment(invoice_id, payment_id)
233
249
  payments = get_payments(invoice_id)
234
- payments.each do |payment|
235
- return payment if payment.payment_id == payment_id
250
+ if payments.present?
251
+ payments.each do |payment|
252
+ if payment.payment_id == payment_id
253
+ return payment
254
+ end
255
+ end
236
256
  end
237
257
  nil
238
258
  end
@@ -240,7 +260,8 @@ module Kaui
240
260
  def self.get_payments(invoice_id)
241
261
  begin
242
262
  data = call_killbill :get, "/1.0/kb/invoices/#{invoice_id}/payments"
243
- process_response(data, :single) {|json| Kaui::Payment.new(json) }
263
+ response_data = process_response(data, :multiple) {|json| Kaui::Payment.new(json) }
264
+ return response_data
244
265
  rescue => e
245
266
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
246
267
  []
@@ -249,9 +270,13 @@ module Kaui
249
270
 
250
271
  ############## PAYMENT METHOD ##############
251
272
 
252
- def self.delete_payment_method(account_id, payment_method_id)
273
+ def self.delete_payment_method(account_id, payment_method_id, current_user = nil, reason = nil, comment = nil)
253
274
  begin
254
- call_killbill :delete, "/1.0/accounts/#{account_id}/paymentMethods/#{payment_method_id}"
275
+ call_killbill :delete,
276
+ "/1.0/accounts/#{account_id}/paymentMethods/#{payment_method_id}",
277
+ "X-Killbill-CreatedBy" => current_user,
278
+ "X-Killbill-Reason" => "#{reason}",
279
+ "X-Killbill-Comment" => "#{comment}"
255
280
  rescue => e
256
281
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
257
282
  end
@@ -260,7 +285,7 @@ module Kaui
260
285
  def self.get_payment_methods(account_id)
261
286
  begin
262
287
  data = call_killbill :get, "/1.0/accounts/#{account_id}/paymentMethods"
263
- process_response(data, :single) {|json| Kaui::PaymentMethod.new(json) }
288
+ process_response(data, :multiple) {|json| Kaui::PaymentMethod.new(json) }
264
289
  rescue => e
265
290
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
266
291
  end
@@ -270,23 +295,25 @@ module Kaui
270
295
 
271
296
  def self.get_refunds_for_payment(payment_id)
272
297
  begin
273
- call_killbill :get, "/1.0/kb/payments/#{payment_id}/refunds"
298
+ data = call_killbill :get, "/1.0/kb/payments/#{payment_id}/refunds"
299
+ process_response(data, :multiple) {|json| Kaui::Refund.new(json) }
274
300
  rescue => e
275
301
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
276
302
  end
277
303
  end
278
304
 
279
- def self.create_refund(payment_id, refund, reason, comment)
305
+ def self.create_refund(payment_id, refund, current_user = nil, reason = nil, comment = nil)
280
306
  begin
281
307
  refund_data = Kaui::Refund.camelize(refund.to_hash)
308
+
282
309
  data = call_killbill :post,
283
310
  "/1.0/kb/payments/#{payment_id}/refunds",
284
311
  ActiveSupport::JSON.encode(refund_data, :root => false),
285
312
  :content_type => "application/json",
286
- "X-Killbill-CreatedBy" => Kaui.current_user.call.to_s,
287
- "X-Killbill-Reason" => "#{reason}",
313
+ "X-Killbill-CreatedBy" => current_user,
314
+ "X-Killbill-Reason" => extract_reason_code(reason),
288
315
  "X-Killbill-Comment" => "#{comment}"
289
- return response[:code] == 201
316
+ return data[:code] < 300
290
317
  rescue => e
291
318
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
292
319
  end
@@ -297,23 +324,42 @@ module Kaui
297
324
  def self.get_chargebacks_for_payment(payment_id)
298
325
  begin
299
326
  data = call_killbill :get, "/1.0/kb/chargebacks/payments/#{payment_id}"
300
- process_response(data, :single) {|json| Kaui::Chargeback.new(json) }
327
+ process_response(data, :multiple) {|json| Kaui::Chargeback.new(json) }
301
328
  rescue => e
302
329
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
303
330
  end
304
331
  end
305
332
 
306
- def self.create_chargeback(chargeback, reason, comment)
333
+ def self.create_chargeback(chargeback, current_user = nil, reason = nil, comment = nil)
307
334
  begin
308
335
  chargeback_data = Kaui::Refund.camelize(chargeback.to_hash)
336
+
309
337
  data = call_killbill :post,
310
338
  "/1.0/kb/chargebacks",
311
339
  ActiveSupport::JSON.encode(chargeback_data, :root => false),
312
340
  :content_type => "application/json",
313
- "X-Killbill-CreatedBy" => Kaui.current_user.call.to_s,
314
- "X-Killbill-Reason" => "#{reason}",
341
+ "X-Killbill-CreatedBy" => current_user,
342
+ "X-Killbill-Reason" => extract_reason_code(reason),
315
343
  "X-Killbill-Comment" => "#{comment}"
316
- return data[:code] == 201
344
+ return data[:code] < 300
345
+ rescue => e
346
+ puts "#{$!}\n\t" + e.backtrace.join("\n\t")
347
+ end
348
+ end
349
+
350
+ ############## CREDIT ##############
351
+
352
+ def self.create_credit(credit, current_user = nil, reason = nil, comment = nil)
353
+ begin
354
+ credit_data = Kaui::Refund.camelize(credit.to_hash)
355
+ data = call_killbill :post,
356
+ "/1.0/kb/credits",
357
+ ActiveSupport::JSON.encode(credit_data, :root => false),
358
+ :content_type => "application/json",
359
+ "X-Killbill-CreatedBy" => current_user,
360
+ "X-Killbill-Reason" => extract_reason_code(reason),
361
+ "X-Killbill-Comment" => "#{comment}"
362
+ return data[:code] < 300
317
363
  rescue => e
318
364
  puts "#{$!}\n\t" + e.backtrace.join("\n\t")
319
365
  end
@@ -350,16 +396,16 @@ module Kaui
350
396
  end
351
397
 
352
398
 
353
- def self.set_tags_for_account(account_id, tags)
399
+ def self.set_tags_for_account(account_id, tags, current_user = nil, reason = nil, comment = nil)
354
400
  begin
355
401
  if tags.nil? || tags.empty?
356
402
  else
357
403
  data = call_killbill :post,
358
404
  "/1.0/kb/accounts/#{account_id}/tags?" + RestClient::Payload.generate(:tag_list => tags.join(",")).to_s,
359
405
  nil,
360
- "X-Killbill-CreatedBy" => Kaui.current_user.call.to_s,
361
- "X-Killbill-Reason" => "Very special reason",
362
- "X-Killbill-Comment" => "Very special comment"
406
+ "X-Killbill-CreatedBy" => current_user,
407
+ "X-Killbill-Reason" => "#{reason}",
408
+ "X-Killbill-Comment" => "#{comment}"
363
409
  return data[:code] == 201
364
410
  end
365
411
  rescue => e
@@ -367,16 +413,16 @@ module Kaui
367
413
  end
368
414
  end
369
415
 
370
- def self.set_tags_for_bundle(bundle_id, tags)
416
+ def self.set_tags_for_bundle(bundle_id, tags, current_user = nil, reason = nil, comment = nil)
371
417
  begin
372
418
  if tags.nil? || tags.empty?
373
419
  else
374
420
  data = call_killbill :post,
375
421
  "/1.0/kb/bundles/#{bundle_id}/tags?" + RestClient::Payload.generate(:tag_list => tags.join(",")).to_s,
376
422
  nil,
377
- "X-Killbill-CreatedBy" => Kaui.current_user.call.to_s,
378
- "X-Killbill-Reason" => "Very special reason",
379
- "X-Killbill-Comment" => "Very special comment"
423
+ "X-Killbill-CreatedBy" => current_user,
424
+ "X-Killbill-Reason" => "#{reason}",
425
+ "X-Killbill-Comment" => "#{comment}"
380
426
  return data[:code] == 201
381
427
  end
382
428
  rescue => e
@@ -384,17 +430,5 @@ module Kaui
384
430
  end
385
431
  end
386
432
 
387
- private
388
-
389
- def self.process_response(response, arity, &block)
390
- if response.nil? || response[:json].nil?
391
- arity == :single ? nil : []
392
- elsif block_given?
393
- arity == :single ? yield(response[:json]) : response[:json].collect {|item| yield(item) }
394
- else
395
- response[:json]
396
- end
397
- end
398
-
399
433
  end
400
434
  end
@@ -6,8 +6,8 @@ class Kaui::Account < Kaui::Base
6
6
  define_attr :name
7
7
  define_attr :first_name_length
8
8
  define_attr :email
9
- define_attr :billing_day
10
9
  define_attr :currency
10
+ define_attr :payment_method_id
11
11
  define_attr :timezone
12
12
  define_attr :address1
13
13
  define_attr :address2
@@ -22,8 +22,8 @@ class Kaui::Account < Kaui::Base
22
22
  :name => data['name'] || "#{data['firstName'] || ''}#{data.has_key?('firstName') ? ' ' : ''}#{data['lastName'] || ''}",
23
23
  :first_name_length => data['length'] || (data.has_key?('firstName') ? data['firstName'].length : 0),
24
24
  :email => data['email'],
25
- :billing_day => data['billingDay'],
26
25
  :currency => data['currency'],
26
+ :payment_method_id => data['paymentMethodId'],
27
27
  :timezone => data['timeZone'] || data['timezone'],
28
28
  :address1 => data['address1'],
29
29
  :address2 => data['address2'],
@@ -17,19 +17,18 @@ class Kaui::Invoice < Kaui::Base
17
17
  has_many :items, Kaui::InvoiceItem
18
18
 
19
19
  def initialize(data = {})
20
- super(:amount => data['amount'],
21
- :balance => data['balance'],
22
- :invoice_id => data['invoiceId'],
20
+ super(
23
21
  :account_id => data['accountId'],
24
- :invoice_number => data['invoiceNumber'],
25
- :payment_amount => data['paymentAmount'],
26
- :refund_adjustment => data['refundAdj'],
22
+ :amount => data['amount'],
23
+ :balance => data['balance'],
27
24
  :credit_balance_adjustment => data['cba'],
28
25
  :credit_adjustment => data['creditAdj'],
29
26
  :invoice_dt => data['invoiceDate'],
30
- :payment_dt => data['paymentDate'],
27
+ :invoice_id => data['invoiceId'],
28
+ :invoice_number => data['invoiceNumber'],
29
+ :refund_adjustment => data['refundAdj'],
31
30
  :target_dt => data['targetDate'],
32
- :bundle_keys => data['bundleKeys'],
33
- :items => data['items'])
31
+ :items => data['items'],
32
+ :bundle_keys => data['bundleKeys'])
34
33
  end
35
34
  end
@@ -14,16 +14,17 @@ class Kaui::InvoiceItem < Kaui::Base
14
14
  define_attr :currency;
15
15
 
16
16
  def initialize(data = {})
17
- super(:invoice_id => data['invoiceId'],
17
+ super(
18
18
  :account_id => data['accountId'],
19
+ :amount => data['amount'],
19
20
  :bundle_id => data['bundleId'],
20
- :subscription_id => data['subscriptionId'],
21
- :plan_name => data['planName'],
22
- :phase_name => data['phaseName'],
21
+ :currency => data['currency'],
23
22
  :description => data['description'],
24
- :start_date => data['startDate'],
25
23
  :end_date => data['endDate'],
26
- :amount => data['amount'],
27
- :currency => data['currency'])
24
+ :invoice_id => data['invoiceId'],
25
+ :phase_name => data['phaseName'],
26
+ :plan_name => data['planName'],
27
+ :start_date => data['startDate'],
28
+ :subscription_id => data['subscriptionId'])
28
29
  end
29
30
  end
@@ -1,34 +1,33 @@
1
1
  require 'active_model'
2
2
 
3
3
  class Kaui::Payment < Kaui::Base
4
- define_attr :invoice_id
4
+ define_attr :account_id
5
5
  define_attr :amount
6
- define_attr :refund_amount
7
6
  define_attr :currency
7
+ define_attr :invoice_id
8
+ define_attr :effective_dt
9
+ define_attr :paid_amount
8
10
  define_attr :payment_id
9
- define_attr :external_payment_id
10
- define_attr :payment_attempt_date
11
- define_attr :payment_method
12
11
  define_attr :payment_method_id
13
- define_attr :card_type
12
+ define_attr :refund_amount
14
13
  define_attr :requested_dt
15
- define_attr :effective_dt
14
+ define_attr :retry_count
16
15
  define_attr :status
17
16
  define_attr :bundle_keys
18
17
 
19
18
  def initialize(data = {})
20
- super(:invoice_id => data['invoiceId'],
19
+ super(
20
+ :account_id => data['accountId'],
21
21
  :amount => data['amount'],
22
- :refund_amount => data['refundAmount'],
23
22
  :currency => data['currency'],
24
- :payment_id => data['id'] || data['paymentId'],
25
- :external_payment_id => data['externalPaymentId'],
26
- :payment_attempt_date => data['paymentAttemptDate'],
27
- :payment_method => data['paymentMethod'],
23
+ :effective_dt => data['effectiveDate'],
24
+ :invoice_id => data['invoiceId'],
25
+ :paid_amount => data['paidAmount'],
26
+ :payment_id => data['paymentId'],
28
27
  :payment_method_id => data['paymentMethodId'],
29
- :card_type => data['cardType'],
28
+ :refund_amount => data['refundAmount'],
30
29
  :requested_dt => data['requestedDate'],
31
- :effective_dt => data['effectiveDate'],
30
+ :retry_count => data['retryCount'],
32
31
  :status => data['status'],
33
32
  :bundle_keys => data['bundleKeys'])
34
33
  end
@@ -7,19 +7,19 @@ class Kaui::Subscription < Kaui::Base
7
7
  define_attr :charged_through_date
8
8
  define_attr :price_list
9
9
  define_attr :start_date
10
- define_attr :canceledDate
10
+ define_attr :canceled_date
11
11
  has_many :events, Kaui::Event
12
12
 
13
13
  def initialize(data = {})
14
- super(:subscription_id => data['subscriptionId'],
15
- :bundle_id => data['bundleId'],
16
- :product_category => data['productCategory'],
17
- :product_name => data['productName'],
18
- :billing_period => data['billingPeriod'],
19
- :charged_through_date => data['chargedThroughDate'],
20
- :price_list => data['priceList'],
21
- :start_date => data['startDate'],
22
- :canceledDate => data['cancelledDate'],
14
+ super(:subscription_id => data['subscriptionId'] || data['subscription_id'],
15
+ :bundle_id => data['bundleId'] || data['bundle_id'],
16
+ :product_category => data['productCategory'] || data['product_category'],
17
+ :product_name => data['productName'] || data['product_name'],
18
+ :billing_period => data['billingPeriod'] || data['billing_period'],
19
+ :charged_through_date => data['chargedThroughDate'] || data['charged_through_date'],
20
+ :price_list => data['priceList'] || data['price_list'],
21
+ :start_date => data['startDate'] || data['start_date'],
22
+ :canceled_date => data['cancelledDate'] || data['canceled_date'],
23
23
  :events => data['events'])
24
24
  end
25
25
  end
@@ -43,7 +43,7 @@
43
43
  <label class="control-label">Payment method</label>
44
44
  <div class="controls">
45
45
  <label class="checkbox">
46
- <%= @payment.payment_method %>
46
+ <%= @payment.payment_method_id %>
47
47
  </label>
48
48
  </div>
49
49
  </div>
@@ -1,10 +1,9 @@
1
1
  <% if @invoice.present? %>
2
+ <h3>Invoice number: <%= @invoice.invoice_number %></h3>
2
3
  <dl class="dl-horizontal">
3
4
  <dt>Account Name:</dt>
4
5
  <dd><%= @account.name %>&nbsp;</dd>
5
6
  <dd><%= link_to @account.email, Kaui.account_home_path.call(@account.external_key) %>&nbsp;</dd>
6
- <dt>Invoice number:</dt>
7
- <dd><%= @invoice.invoice_number %>&nbsp;</dd>
8
7
  <dt>Invoice date:</dt>
9
8
  <dd><%= format_date(@invoice.invoice_dt).html_safe %>&nbsp;</dd>
10
9
  <dt>Target date:</dt>
@@ -27,7 +26,7 @@
27
26
  <th>Start date</th>
28
27
  <th>Charged through date</th>
29
28
  <th>Price list</th>
30
- </tr>
29
+ </tr>
31
30
  </thead>
32
31
  <tbody>
33
32
  <% @invoice.items.each do |item| %>
@@ -51,7 +50,7 @@
51
50
  </table>
52
51
  <div class="page-header">
53
52
  <h3>Payments</h3>
54
- </div>
53
+ </div>
55
54
  <% else %>
56
55
  <p>Invoice not found</p>
57
56
  <% end %>
@@ -42,7 +42,7 @@
42
42
  <label class="control-label">Payment method</label>
43
43
  <div class="controls">
44
44
  <label class="checkbox">
45
- <%= @payment.payment_method %>
45
+ <%= @payment.payment_method_id %>
46
46
  </label>
47
47
  </div>
48
48
  </div>
@@ -58,7 +58,7 @@
58
58
  <label class="control-label">Payment</label>
59
59
  <div class="controls">
60
60
  <label class="checkbox">
61
- <%= @payment.amount %> <%= @account.currency %>
61
+ <%= @payment.amount %> <%= @account.currency if @payment.amount.present? %>
62
62
  </label>
63
63
  </div>
64
64
  </div>
@@ -23,21 +23,25 @@
23
23
  <td><%= format_date(sub.start_date).html_safe %></td>
24
24
  <td><%= format_date(sub.charged_through_date).html_safe %></td>
25
25
  <td>
26
- <% if sub.canceledDate.present? %>
27
- <%= "Canceled as of #{sub.canceledDate}" %>
26
+ <% if sub.canceled_date.present? %>
27
+ <%= "Pending cancellation on " %> <%= format_date(sub.canceled_date).html_safe %>
28
28
  <% end %>
29
29
  </td>
30
30
  <td>
31
- <% if sub.product_category == 'BASE' %>
32
- <%= link_to "Change", kaui_engine.edit_subscription_path(sub.subscription_id), :class => "btn btn-mini" unless sub.canceledDate.present? %>
33
- <%= link_to "Cancel", kaui_engine.subscription_path(:id => sub.subscription_id), :method => :delete, :class => "btn btn-mini" %>
34
- <%= link_to "Add Addons", kaui_engine.subscription_path(sub.subscription_id), :method => :post, :class => "btn btn-mini" %>
35
- <% else %>
36
- <% end %>
37
- <% if sub.product_category == 'ADD_ON' %>
38
- <%= link_to "Cancel", kaui_engine.subscription_path(:id => sub.subscription_id), :method => :delete, :class => "btn btn-mini" unless sub.canceledDate.present? %>
39
- <%= link_to "Reinstate", kaui_engine.subscription_path(:id => sub.subscription_id), :method => :put, :class => "btn btn-mini" if sub.canceledDate.present? %>
40
- <% end %>
31
+ <nobr>
32
+ <% if sub.product_category == 'BASE' %>
33
+ <%= link_to "Change", kaui_engine.edit_subscription_path(sub.subscription_id), :class => "btn btn-mini" unless sub.canceled_date.present? %>
34
+ <%= link_to "Cancel", kaui_engine.subscription_path(:id => sub.subscription_id), :method => :delete, :class => "btn btn-mini" %>
35
+ <%= link_to "Add Addons", kaui_engine.new_subscription_path(:params => { :bundle_id => sub.bundle_id, :base_subscription => sub.product_name }), :class => "btn btn-mini" %>
36
+ <% else %>
37
+ <% end %>
38
+ <% if sub.product_category == 'ADD_ON' %>
39
+ <%= link_to "Cancel", kaui_engine.subscription_path(:id => sub.subscription_id), :method => :delete, :class => "btn btn-mini" unless sub.canceled_date.present? %>
40
+ <% if sub.canceled_date.present? && Time.parse(sub.canceled_date) > Time.now %>
41
+ <%= link_to "Reinstate", kaui_engine.reinstate_subscription_path(:id => sub.subscription_id), :method => :put, :class => "btn btn-mini" %>
42
+ <% end %>
43
+ <% end %>
44
+ </nobr>
41
45
  </td>
42
46
  </tr>
43
47
  <% end %>
@@ -0,0 +1,22 @@
1
+ <div class="page-header">
2
+ <h1>Add subscription to <%= Kaui.bundle_key_display_string.call(@bundle.external_key) %></h1>
3
+ </div>
4
+ <%= form_for(@subscription, :url => { :action => :create }, :html => { :class => "form-horizontal" }) do |f| %>
5
+ <fieldset>
6
+ <%= f.hidden_field :bundle_id %>
7
+ <%= hidden_field_tag :base_subscription, @base_subscription %>
8
+ <div class="control-group">
9
+ <%= label_tag :plan_name, "Available Plans:", :class => "control-label" %>
10
+ <div class="controls">
11
+ <%= select_tag :plan_name, options_for_select(@catalog.keys, @plan_name) %>
12
+ <p class="help-block">
13
+ Proration on customer's invoice will be done automatically.
14
+ </p>
15
+ </div>
16
+ </div>
17
+ <div class="form-actions">
18
+ <%= f.submit 'Add', :class => 'btn btn-primary' %>
19
+ <%= link_to 'Back', :back, :class => 'btn' %>
20
+ </div>
21
+ </fieldset>
22
+ <% end %>
@@ -18,4 +18,4 @@
18
18
  <hr/>
19
19
  <%= link_to "Change", kaui_engine.edit_subscription_path(@subscription.subscription_id), :class => "btn btn-mini" %>
20
20
  <%= link_to "Cancel", kaui_engine.subscription_path(@subscription.subscription_id), :method => :delete, :confirm => "Are you sure?", :class => "btn btn-mini" %>
21
- <%= link_to "Add Addons", kaui_engine.subscription_path(@subscription.subscription_id), :method => :post, :class => "btn btn-mini" %>
21
+ <%= link_to "Add Addons", kaui_engine.new_subscription_path(:params => { :bundle_id => @subscription.bundle_id, :base_subscription => @subscription.product_name }), :class => "btn btn-mini" %>
data/config/routes.rb CHANGED
@@ -16,7 +16,7 @@ Kaui::Engine.routes.draw do
16
16
  post :credits, :as => "credits"
17
17
  end
18
18
  end
19
-
19
+
20
20
  resources :chargebacks, :only => [ :show, :create, :new ]
21
21
 
22
22
  resources :credits, :only => [ :create, :new ]
@@ -29,7 +29,11 @@ Kaui::Engine.routes.draw do
29
29
 
30
30
  resources :bundles, :only => [ :index, :show ]
31
31
 
32
- resources :subscriptions, :except => [ :new, :create ]
32
+ resources :subscriptions do
33
+ member do
34
+ put :reinstate
35
+ end
36
+ end
33
37
 
34
38
  scope "/account_tags" do
35
39
  match "/" => "account_tags#show", :via => :get, :as => "account_tags"
data/lib/kaui/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kaui
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/kaui.rb CHANGED
@@ -9,12 +9,10 @@ module Kaui
9
9
  mattr_accessor :bundle_home_path
10
10
  mattr_accessor :invoice_home_path
11
11
  mattr_accessor :bundle_key_display_string
12
- mattr_accessor :current_user
13
12
 
14
13
  self.killbill_finder = lambda { Kaui::Engine.config.killbill_url }
15
14
  self.account_home_path = lambda {|account_id| Kaui::Engine.routes.url_helpers.account_path(account_id) }
16
15
  self.bundle_home_path = lambda {|bundle_id| Kaui::Engine.routes.url_helpers.bundle_path(:id => bundle_id) }
17
16
  self.invoice_home_path = lambda {|invoice_id| Kaui::Engine.routes.url_helpers.invoice_path(:id => invoice_id) }
18
17
  self.bundle_key_display_string = lambda {|bundle_key| bundle_key }
19
- self.current_user = lambda { nil }
20
18
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaui
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alena Dudzinskaya
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-17 00:00:00 Z
18
+ date: 2012-07-23 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Rails UI plugin for Killbill administration.
@@ -49,11 +49,11 @@ files:
49
49
  - app/controllers/kaui/account_tags_controller.rb
50
50
  - app/controllers/kaui/account_timelines_controller.rb
51
51
  - app/controllers/kaui/accounts_controller.rb
52
- - app/controllers/kaui/application_controller.rb
53
52
  - app/controllers/kaui/bundle_tags_controller.rb
54
53
  - app/controllers/kaui/bundles_controller.rb
55
54
  - app/controllers/kaui/chargebacks_controller.rb
56
55
  - app/controllers/kaui/credits_controller.rb
56
+ - app/controllers/kaui/engine_controller.rb
57
57
  - app/controllers/kaui/home_controller.rb
58
58
  - app/controllers/kaui/invoices_controller.rb
59
59
  - app/controllers/kaui/payment_methods_controller.rb
@@ -107,6 +107,7 @@ files:
107
107
  - app/views/kaui/subscriptions/_subscriptions_table.html.erb
108
108
  - app/views/kaui/subscriptions/edit.html.erb
109
109
  - app/views/kaui/subscriptions/index.html.erb
110
+ - app/views/kaui/subscriptions/new.html.erb
110
111
  - app/views/kaui/subscriptions/show.html.erb
111
112
  - app/views/kaui/tags/_tags_table.html.erb
112
113
  - config/initializers/time_formats.rb
@@ -1,2 +0,0 @@
1
- class Kaui::ApplicationController < ActionController::Base
2
- end