kaui 0.1.6 → 0.1.7

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 (39) hide show
  1. data/README.rdoc +8 -1
  2. data/app/controllers/kaui/accounts_controller.rb +13 -9
  3. data/app/controllers/kaui/bundle_tags_controller.rb +15 -7
  4. data/app/controllers/kaui/bundles_controller.rb +11 -12
  5. data/app/controllers/kaui/credits_controller.rb +2 -1
  6. data/app/controllers/kaui/payments_controller.rb +2 -2
  7. data/app/controllers/kaui/subscriptions_controller.rb +40 -27
  8. data/app/helpers/kaui/killbill_helper.rb +38 -56
  9. data/app/models/kaui/account.rb +4 -0
  10. data/app/models/kaui/base.rb +8 -0
  11. data/app/models/kaui/chargeback.rb +4 -0
  12. data/app/models/kaui/invoice.rb +26 -0
  13. data/app/models/kaui/invoice_item.rb +4 -0
  14. data/app/models/kaui/payment.rb +9 -0
  15. data/app/models/kaui/refund.rb +4 -0
  16. data/app/views/kaui/account_timelines/show.html.erb +13 -21
  17. data/app/views/kaui/accounts/show.html.erb +15 -4
  18. data/app/views/kaui/chargebacks/new.html.erb +8 -1
  19. data/app/views/kaui/charges/new.html.erb +9 -2
  20. data/app/views/kaui/credits/new.html.erb +8 -1
  21. data/app/views/kaui/invoices/show.html.erb +4 -4
  22. data/app/views/kaui/payments/_payments_table.html.erb +2 -2
  23. data/app/views/kaui/payments/new.html.erb +16 -1
  24. data/app/views/kaui/refunds/new.html.erb +8 -1
  25. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +2 -2
  26. data/app/views/kaui/subscriptions/edit.html.erb +1 -1
  27. data/lib/kaui/version.rb +1 -1
  28. data/test/dummy/app/assets/javascripts/application.js +1 -0
  29. data/test/dummy/log/development.log +6795 -0
  30. data/test/dummy/log/test.log +6534 -0
  31. data/test/dummy/tmp/cache/assets/C95/690/sprockets%2Fc4b083702793f7599f4a3069c50f89a8 +0 -0
  32. data/test/dummy/tmp/cache/assets/CC2/520/sprockets%2F9637f46d37325381f96d96d94ae0bc50 +0 -0
  33. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  34. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  35. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  36. data/test/unit/kaui/base_test.rb +14 -0
  37. metadata +6 -4
  38. data/app/controllers/kaui/external_payments_controller.rb +0 -21
  39. data/app/views/kaui/external_payments/new.html.erb +0 -56
data/README.rdoc CHANGED
@@ -17,6 +17,13 @@ You can run Kaui locally using the dummy app in the test directory:
17
17
  Kaui expects the container app to define the <tt>current_user</tt> method, which returns the
18
18
  name of the logged-in user. This is used by Killbill for auditing purposes.
19
19
 
20
+ You also need to install validation.js into your asset pipeline.
21
+
22
+ Gem dependencies:
23
+
24
+ gem 'rest-client', '~> 1.6.7'
25
+ gem 'money-rails', '~> 0.5.0'
26
+
20
27
  === Running tests
21
28
 
22
29
  Prepare a kaui_test database locally to be able to run the test suite:
@@ -26,4 +33,4 @@ Prepare a kaui_test database locally to be able to run the test suite:
26
33
 
27
34
  You can run tests using rake:
28
35
 
29
- rake test
36
+ rake test
@@ -25,17 +25,21 @@ class Kaui::AccountsController < Kaui::EngineController
25
25
  end
26
26
 
27
27
  if @account.present? and @account.is_a? Kaui::Account
28
- @tags = Kaui::KillbillHelper::get_tags_for_account(@account.account_id).sort
29
- @account_emails = Kaui::AccountEmail.where(:account_id => @account.account_id)
30
- @payment_methods = Kaui::KillbillHelper::get_payment_methods(@account.account_id)
31
- @bundles = Kaui::KillbillHelper::get_bundles(@account.account_id)
32
- @subscriptions_by_bundle_id = {}
28
+ begin
29
+ @tags = Kaui::KillbillHelper::get_tags_for_account(@account.account_id).sort
30
+ @account_emails = Kaui::AccountEmail.where(:account_id => @account.account_id)
31
+ @payment_methods = Kaui::KillbillHelper::get_payment_methods(@account.account_id)
32
+ @bundles = Kaui::KillbillHelper::get_bundles(@account.account_id)
33
+ @subscriptions_by_bundle_id = {}
33
34
 
34
- @bundles.each do |bundle|
35
- subscriptions = Kaui::KillbillHelper::get_subscriptions_for_bundle(bundle.bundle_id)
36
- if subscriptions.present?
37
- @subscriptions_by_bundle_id[bundle.bundle_id.to_s] = (@subscriptions_by_bundle_id[bundle.bundle_id.to_s] || []) + subscriptions
35
+ @bundles.each do |bundle|
36
+ subscriptions = Kaui::KillbillHelper::get_subscriptions_for_bundle(bundle.bundle_id)
37
+ if subscriptions.present?
38
+ @subscriptions_by_bundle_id[bundle.bundle_id.to_s] = (@subscriptions_by_bundle_id[bundle.bundle_id.to_s] || []) + subscriptions
39
+ end
38
40
  end
41
+ rescue => e
42
+ flash[:error] = "Error while retrieving account information for account: #{e.message} #{e.response}"
39
43
  end
40
44
  else
41
45
  flash[:error] = "Account #{@account_id} not found: #{@account}"
@@ -11,18 +11,26 @@ class Kaui::BundleTagsController < Kaui::EngineController
11
11
 
12
12
  def edit
13
13
  @bundle_id = params[:bundle_id]
14
- @available_tags = Kaui::KillbillHelper::get_tag_definitions.sort {|tag_a, tag_b| tag_a.name.downcase <=> tag_b.name.downcase }
14
+ begin
15
+ @available_tags = Kaui::KillbillHelper::get_tag_definitions.sort {|tag_a, tag_b| tag_a.name.downcase <=> tag_b.name.downcase }
15
16
 
16
- @bundle = Kaui::KillbillHelper::get_bundle(@bundle_id)
17
- @tags = Kaui::KillbillHelper::get_tags_for_bundle(@bundle_id)
17
+ @bundle = Kaui::KillbillHelper::get_bundle(@bundle_id)
18
+ @tags = Kaui::KillbillHelper::get_tags_for_bundle(@bundle_id)
19
+ rescue => e
20
+ flash[:error] = "Error while retrieving tags information: #{e.message} #{e.response}"
21
+ end
18
22
  end
19
23
 
20
24
  def update
21
- bundle = Kaui::KillbillHelper::get_bundle(params[:bundle_id])
22
- tags = params[:tags]
25
+ begin
26
+ bundle = Kaui::KillbillHelper::get_bundle(params[:bundle_id])
27
+ tags = params[:tags]
23
28
 
24
- Kaui::KillbillHelper::set_tags_for_bundle(bundle.bundle_id, tags)
25
- redirect_to Kaui.bundle_home_path.call(bundle.bundle_id)
29
+ Kaui::KillbillHelper::set_tags_for_bundle(bundle.bundle_id, tags)
30
+ redirect_to Kaui.bundle_home_path.call(bundle.bundle_id)
31
+ rescue => e
32
+ flash[:error] = "Error while updating tags: #{e.message} #{e.response}"
33
+ end
26
34
  end
27
35
 
28
36
  end
@@ -9,19 +9,18 @@ class Kaui::BundlesController < Kaui::EngineController
9
9
  def show
10
10
  key = params[:id]
11
11
  if key.present?
12
- # support id (UUID) and external key search
13
- if key =~ /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/
14
- @bundle = Kaui::KillbillHelper.get_bundle(key)
15
- else
16
- @bundle = Kaui::KillbillHelper.get_bundle_by_external_key(key, params[:account_id])
17
- end
12
+ begin
13
+ @bundle = Kaui::KillbillHelper::get_bundle_by_key(key, params[:account_id])
18
14
 
19
- if @bundle.present?
20
- @account = Kaui::KillbillHelper::get_account_by_bundle_id(@bundle.bundle_id)
21
- @subscriptions = Kaui::KillbillHelper.get_subscriptions_for_bundle(@bundle.bundle_id)
22
- else
23
- flash[:error] = "Bundle #{key} not found"
24
- render :action => :index
15
+ if @bundle.present?
16
+ @account = Kaui::KillbillHelper::get_account_by_bundle_id(@bundle.bundle_id)
17
+ @subscriptions = Kaui::KillbillHelper::get_subscriptions_for_bundle(@bundle.bundle_id)
18
+ else
19
+ flash[:error] = "Bundle #{key} not found"
20
+ render :action => :index
21
+ end
22
+ rescue => e
23
+ flash[:error] = "Error while retrieving bundle information for #{key}: #{e.message} #{e.response}"
25
24
  end
26
25
  else
27
26
  flash[:error] = "No id given"
@@ -23,7 +23,8 @@ class Kaui::CreditsController < Kaui::EngineController
23
23
  @invoice = Kaui::KillbillHelper::get_invoice(@invoice_id) unless @invoice_id.nil?
24
24
  credit_amount = @invoice.balance unless @invoice.nil?
25
25
 
26
- @credit = Kaui::Credit.new("accountId" => @account_id, "invoiceId" => @invoice_id, "creditAmount" => credit_amount)
26
+ @credit = Kaui::Credit.new("accountId" => @account_id, "invoiceId" => @invoice_id,
27
+ "creditAmount" => credit_amount, "effectiveDate" => Time.now.utc.iso8601)
27
28
  end
28
29
 
29
30
  def create
@@ -11,9 +11,9 @@ class Kaui::PaymentsController < Kaui::EngineController
11
11
 
12
12
  def create
13
13
  payment = Kaui::Payment.new(params[:payment])
14
-
15
14
  if payment.present?
16
- success = Kaui::KillbillHelper::create_payment(payment, params[:external], current_user, params[:reason], params[:comment])
15
+ payment.external = (payment.external == "1")
16
+ success = Kaui::KillbillHelper::create_payment(payment, payment.external, current_user, params[:reason], params[:comment])
17
17
  if success
18
18
  flash[:info] = "Payment created"
19
19
  end
@@ -18,13 +18,17 @@ class Kaui::SubscriptionsController < Kaui::EngineController
18
18
  def new
19
19
  bundle_id = params[:bundle_id]
20
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
- @catalog = Kaui::KillbillHelper::get_available_base_plans()
26
- end
21
+ begin
22
+ @bundle = Kaui::KillbillHelper::get_bundle(bundle_id)
27
23
 
24
+ if @base_subscription.present?
25
+ @catalog = Kaui::KillbillHelper::get_available_addons(@base_subscription)
26
+ else
27
+ @catalog = Kaui::KillbillHelper::get_available_base_plans()
28
+ end
29
+ rescue => e
30
+ flash[:error] = "Error while trying to start new subscription creation: #{e.message} #{e.response}"
31
+ end
28
32
  @subscription = Kaui::Subscription.new("bundleId" => bundle_id)
29
33
  end
30
34
 
@@ -50,7 +54,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
50
54
  Kaui::KillbillHelper::create_subscription(@subscription, current_user)
51
55
  redirect_to Kaui.bundle_home_path.call(@bundle.bundle_id)
52
56
  rescue => e
53
- flash[:error] = e.message
57
+ flash[:error] = "Error while creating the new subscription: #{e.message} #{e.response}"
54
58
  render :new
55
59
  end
56
60
  end
@@ -64,14 +68,18 @@ class Kaui::SubscriptionsController < Kaui::EngineController
64
68
  @billing_period = params[:billing_period]
65
69
  @price_list = params[:price_list]
66
70
 
67
- @subscription = Kaui::Subscription.new(:bundle_id => @bundle_id,
68
- :product_name => @product_name,
69
- :product_category => @product_category,
70
- :billing_period => @billing_period,
71
- :price_list => @price_list)
72
-
73
- @bundle = Kaui::KillbillHelper.get_bundle(subscription.bundle_id)
74
- @available_plans = Kaui::KillbillHelper.get_available_addons(params[:base_product_name])
71
+ begin
72
+ @subscription = Kaui::Subscription.new(:bundle_id => @bundle_id,
73
+ :product_name => @product_name,
74
+ :product_category => @product_category,
75
+ :billing_period => @billing_period,
76
+ :price_list => @price_list)
77
+
78
+ @bundle = Kaui::KillbillHelper.get_bundle(subscription.bundle_id)
79
+ @available_plans = Kaui::KillbillHelper.get_available_addons(params[:base_product_name])
80
+ rescue => e
81
+ flash[:error] = "Error while adding an addon: #{e.message} #{e.response}"
82
+ end
75
83
  end
76
84
 
77
85
  def edit
@@ -95,21 +103,26 @@ class Kaui::SubscriptionsController < Kaui::EngineController
95
103
 
96
104
  def update
97
105
  if params.has_key?(:subscription) && params[:subscription].has_key?(:subscription_id)
98
- subscription = Kaui::KillbillHelper::get_subscription(params[:subscription][:subscription_id])
99
- bundle = Kaui::KillbillHelper::get_bundle(subscription.bundle_id)
100
- catalog = Kaui::KillbillHelper::get_available_base_plans
101
106
 
102
- plan = catalog[params[:plan_name]]
103
- requested_date = params[:requested_date]
107
+ begin
108
+ subscription = Kaui::KillbillHelper::get_subscription(params[:subscription][:subscription_id])
109
+ bundle = Kaui::KillbillHelper::get_bundle(subscription.bundle_id)
110
+ catalog = Kaui::KillbillHelper::get_available_base_plans
104
111
 
105
- subscription.billing_period = plan["billingPeriod"]
106
- subscription.product_category = plan["productCategory"]
107
- subscription.product_name = plan["productName"]
108
- subscription.price_list = plan["priceListName"]
109
- subscription.subscription_id = params[:subscription][:subscription_id]
112
+ plan = catalog[params[:plan_name]]
113
+ requested_date = params[:requested_date]
110
114
 
111
- Kaui::KillbillHelper::update_subscription(subscription, requested_date, current_user)
112
- redirect_to Kaui.bundle_home_path.call(bundle.bundle_id)
115
+ subscription.billing_period = plan["billingPeriod"]
116
+ subscription.product_category = plan["productCategory"]
117
+ subscription.product_name = plan["productName"]
118
+ subscription.price_list = plan["priceListName"]
119
+ subscription.subscription_id = params[:subscription][:subscription_id]
120
+
121
+ Kaui::KillbillHelper::update_subscription(subscription, requested_date, current_user)
122
+ redirect_to Kaui.bundle_home_path.call(bundle.bundle_id)
123
+ rescue => e
124
+ flash[:error] = "Error while updating subscription: #{e.message} #{e.response}"
125
+ end
113
126
  else
114
127
  flash[:error] = "No subscription given"
115
128
  redirect_to :back
@@ -105,7 +105,6 @@ module Kaui
105
105
  "X-Killbill-Comment" => "#{comment}"
106
106
  return data[:code] < 300
107
107
  rescue => e
108
- puts "#{$!}\n\t" + e.backtrace.join("\n\t")
109
108
  end
110
109
  end
111
110
 
@@ -121,77 +120,60 @@ module Kaui
121
120
  "X-Killbill-Comment" => "#{comment}"
122
121
  return data[:code] = 200
123
122
  rescue => e
124
- puts "#{$!}\n\t" + e.backtrace.join("\n\t")
125
123
  end
126
124
  end
127
125
 
128
126
  ############## BUNDLE ##############
129
127
 
130
- def self.get_bundles(account_id)
131
- begin
132
- data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/bundles"
133
- process_response(data, :multiple) {|json| Kaui::Bundle.new(json) }
134
- rescue RestClient::BadRequest
135
- []
136
- rescue => e
128
+ def self.get_bundle_by_key(key, account_id)
129
+ # support id (UUID) and external key search
130
+ if key =~ /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/
131
+ @bundle = Kaui::KillbillHelper::get_bundle(key)
132
+ else
133
+ @bundle = Kaui::KillbillHelper::get_bundle_by_external_key(key, account_id)
137
134
  end
138
135
  end
139
136
 
137
+ def self.get_bundles(account_id)
138
+ data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/bundles"
139
+ process_response(data, :multiple) {|json| Kaui::Bundle.new(json) }
140
+ end
141
+
140
142
  def self.get_bundle_by_external_key(account_id, external_key)
141
- begin
142
- data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/bundles?externalKey=#{external_key}"
143
- process_response(data, :single) {|json| Kaui::Bundle.new(json) }
144
- rescue => e
145
- end
143
+ data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/bundles?externalKey=#{external_key}"
144
+ process_response(data, :single) {|json| Kaui::Bundle.new(json) }
146
145
  end
147
146
 
148
147
  def self.get_bundle(bundle_id)
149
- begin
150
- data = call_killbill :get, "/1.0/kb/bundles/#{bundle_id}"
151
- process_response(data, :single) {|json| Kaui::Bundle.new(json) }
152
- rescue => e
153
- end
148
+ data = call_killbill :get, "/1.0/kb/bundles/#{bundle_id}"
149
+ process_response(data, :single) {|json| Kaui::Bundle.new(json) }
154
150
  end
155
151
 
156
152
  def self.transfer_bundle(bundle_id, new_account_id, cancel_immediately = false, transfer_addons = true, current_user = nil, reason = nil, comment = nil)
157
- begin
158
- data = call_killbill :put,
159
- "/1.0/kb/bundles/#{bundle_id}?cancelImmediately=#{cancel_immediately}&transferAddOn=#{transfer_addons}",
160
- ActiveSupport::JSON.encode("accountId" => new_account_id),
161
- :content_type => :json,
162
- "X-Killbill-CreatedBy" => current_user,
163
- "X-Killbill-Reason" => "#{reason}",
164
- "X-Killbill-Comment" => "#{comment}"
165
- return data[:code] < 300
166
-
167
- rescue => e
168
- end
153
+ data = call_killbill :put,
154
+ "/1.0/kb/bundles/#{bundle_id}?cancelImmediately=#{cancel_immediately}&transferAddOn=#{transfer_addons}",
155
+ ActiveSupport::JSON.encode("accountId" => new_account_id),
156
+ :content_type => :json,
157
+ "X-Killbill-CreatedBy" => current_user,
158
+ "X-Killbill-Reason" => "#{reason}",
159
+ "X-Killbill-Comment" => "#{comment}"
160
+ return data[:code] < 300
169
161
  end
170
162
 
171
163
  ############## SUBSCRIPTION ##############
172
164
 
173
165
  def self.get_subscriptions_for_bundle(bundle_id)
174
- begin
175
- data = call_killbill :get, "/1.0/kb/bundles/#{bundle_id}/subscriptions"
176
- process_response(data, :multiple) {|json| Kaui::Subscription.new(json) }
177
- rescue RestClient::BadRequest
178
- []
179
- rescue => e
180
- end
166
+ data = call_killbill :get, "/1.0/kb/bundles/#{bundle_id}/subscriptions"
167
+ process_response(data, :multiple) {|json| Kaui::Subscription.new(json) }
181
168
  end
182
169
 
183
170
  def self.get_subscriptions(account_id)
184
- begin
185
171
  subscriptions = []
186
172
  bundles = get_bundles(account_id)
187
173
  bundles.each do |bundle|
188
174
  subscriptions += get_subscriptions_for_bundle(bundle.bundle_id)
189
175
  end
190
176
  subscriptions
191
- rescue RestClient::BadRequest
192
- []
193
- rescue => e
194
- end
195
177
  end
196
178
 
197
179
  def self.get_subscription(subscription_id)
@@ -223,7 +205,8 @@ module Kaui
223
205
  begin
224
206
  subscription_data = Kaui::Subscription.camelize(subscription.to_hash)
225
207
  date_param = "?requestedDate=" + requested_date.to_s unless requested_date.blank?
226
-
208
+ # We don't want to pass events
209
+ subscription_data.delete(:events)
227
210
  data = call_killbill :put,
228
211
  "/1.0/kb/subscriptions/#{subscription.subscription_id}#{date_param}",
229
212
  ActiveSupport::JSON.encode(subscription_data, :root => false),
@@ -337,22 +320,16 @@ module Kaui
337
320
  ############## CATALOG ##############
338
321
 
339
322
  def self.get_available_addons(base_product_name)
340
- begin
341
- data = call_killbill :get, "/1.0/kb/catalog/availableAddons?baseProductName=#{base_product_name}"
342
- if data.has_key?(:json)
343
- data[:json].inject({}) {|catalog_hash, item| catalog_hash.merge!(item["planName"] => item) }
344
- end
345
- rescue => e
323
+ data = call_killbill :get, "/1.0/kb/catalog/availableAddons?baseProductName=#{base_product_name}"
324
+ if data.has_key?(:json)
325
+ data[:json].inject({}) {|catalog_hash, item| catalog_hash.merge!(item["planName"] => item) }
346
326
  end
347
327
  end
348
328
 
349
329
  def self.get_available_base_plans()
350
- begin
351
- data = call_killbill :get, "/1.0/kb/catalog/availableBasePlans"
352
- if data.has_key?(:json)
353
- data[:json].inject({}) {|catalog_hash, item| catalog_hash.merge!(item["planName"] => item) }
354
- end
355
- rescue => e
330
+ data = call_killbill :get, "/1.0/kb/catalog/availableBasePlans"
331
+ if data.has_key?(:json)
332
+ data[:json].inject({}) {|catalog_hash, item| catalog_hash.merge!(item["planName"] => item) }
356
333
  end
357
334
  end
358
335
 
@@ -381,6 +358,11 @@ module Kaui
381
358
  payment_data = Kaui::Payment.camelize(payment.to_hash)
382
359
 
383
360
  if payment.invoice_id.present?
361
+ # We should use different model for POST and GEt, this seems fragile...
362
+ payment_data.delete(:external)
363
+ payment_data.delete(:refunds)
364
+ payment_data.delete(:chargebacks)
365
+ payment_data.delete(:audit_logs)
384
366
  data = call_killbill :post,
385
367
  "/1.0/kb/invoices/#{payment.invoice_id}/payments?externalPayment=#{external}",
386
368
  ActiveSupport::JSON.encode(payment_data, :root => false),
@@ -42,4 +42,8 @@ class Kaui::Account < Kaui::Base
42
42
  def to_param
43
43
  @account_id
44
44
  end
45
+
46
+ def balance_to_money
47
+ Kaui::Base.to_money(balance.abs, currency)
48
+ end
45
49
  end
@@ -96,6 +96,14 @@ class Kaui::Base
96
96
  result
97
97
  end
98
98
 
99
+ def self.to_money(amount, currency)
100
+ begin
101
+ return Money.new(amount.to_f * 100, currency)
102
+ rescue => e
103
+ end if currency.present?
104
+ Money.new(amount.to_f * 100, "USD")
105
+ end
106
+
99
107
  def self.camelize(value)
100
108
  case value
101
109
  when Array
@@ -30,4 +30,8 @@ class Kaui::Chargeback < Kaui::Base
30
30
 
31
31
  has_many :audit_logs, Kaui::AuditLog
32
32
 
33
+ # TODO - fix chargeback json to return the currency
34
+ def chargeback_amount_to_money(currency)
35
+ Kaui::Base.to_money(chargeback_amount, currency)
36
+ end
33
37
  end
@@ -33,4 +33,30 @@ class Kaui::Invoice < Kaui::Base
33
33
  :bundle_keys => data['bundleKeys'],
34
34
  :audit_logs => data['auditLogs'])
35
35
  end
36
+
37
+ # TODO - fix invoice json to return the currency
38
+
39
+ def amount_to_money(currency)
40
+ Kaui::Base.to_money(amount, currency)
41
+ end
42
+
43
+ def balance_to_money(currency)
44
+ Kaui::Base.to_money(balance, currency)
45
+ end
46
+
47
+ def payment_amount_to_money(currency)
48
+ Kaui::Base.to_money(payment_amount, currency)
49
+ end
50
+
51
+ def refund_adjustment_to_money(currency)
52
+ Kaui::Base.to_money(refund_adjustment, currency)
53
+ end
54
+
55
+ def credit_balance_adjustment_to_money(currency)
56
+ Kaui::Base.to_money(credit_balance_adjustment, currency)
57
+ end
58
+
59
+ def credit_adjustment_to_money(currency)
60
+ Kaui::Base.to_money(credit_adjustment, currency)
61
+ end
36
62
  end
@@ -19,4 +19,8 @@ class Kaui::InvoiceItem < Kaui::Base
19
19
  define_attr :currency
20
20
  define_attr :linked_invoice_item_id
21
21
  define_attr :audit_logs
22
+
23
+ def amount_to_money
24
+ Kaui::Base.to_money(amount, currency)
25
+ end
22
26
  end
@@ -22,8 +22,17 @@ class Kaui::Payment < Kaui::Base
22
22
  define_attr :ext_second_payment_id_ref
23
23
  define_attr :gateway_error_code
24
24
  define_attr :gateway_error_msg
25
+ define_attr :external
25
26
 
26
27
  has_many :refunds, Kaui::Refund
27
28
  has_many :chargebacks, Kaui::Chargeback
28
29
  has_many :audit_logs, Kaui::AuditLog
30
+
31
+ def amount_to_money
32
+ Kaui::Base.to_money(amount, currency)
33
+ end
34
+
35
+ def paid_amount_to_money
36
+ Kaui::Base.to_money(paid_amount, currency)
37
+ end
29
38
  end
@@ -16,4 +16,8 @@ class Kaui::Refund < Kaui::Base
16
16
  define_attr :adjustments
17
17
 
18
18
  has_many :audit_logs, Kaui::AuditLog
19
+
20
+ def amount_to_money
21
+ Kaui::Base.to_money(amount, currency)
22
+ end
19
23
  end
@@ -62,16 +62,16 @@
62
62
  <% end %>
63
63
  </td>
64
64
  <td><%= "INVOICE" %></td>
65
- <td><%= "Amount:" %> <%= invoice.amount %> <%= @account.currency %><br/>
66
- <%= "Balance:" %> <%= invoice.balance %> <%= @account.currency %><br/>
67
- <% if invoice.credit_adjustment.present? && invoice.credit_adjustment > 0 %>
68
- <%= "Credit adjustment:" %> <%= invoice.credit_adjustment %> <%= @account.currency %> <br/>
65
+ <td><%= "Amount:" %> <%= humanized_money_with_symbol invoice.amount_to_money(@account.currency) %><br/>
66
+ <%= "Balance:" %> <%= humanized_money_with_symbol invoice.balance_to_money(@account.currency) %><br/>
67
+ <% if invoice.credit_adjustment.present? && invoice.credit_adjustment > 0 %>
68
+ <%= "Credit adjustment:" %> <%= humanized_money_with_symbol invoice.credit_adjustment_to_money(@account.currency) %><br/>
69
69
  <% end %>
70
- <% if invoice.credit_balance_adjustment.present? && invoice.credit_balance_adjustment > 0 %>
71
- <%= "Credit balance adjustment:" %> <%= invoice.credit_balance_adjustment %> <%= @account.currency %> <br/>
70
+ <% if invoice.credit_balance_adjustment.present? && invoice.credit_balance_adjustment > 0 %>
71
+ <%= "Credit balance adjustment:" %> <%= humanized_money_with_symbol invoice.credit_balance_adjustment_to_money(@account.currency) %><br/>
72
72
  <% end %>
73
- <% if invoice.refund_adjustment.present? && invoice.refund_adjustment < 0 %>
74
- <%= "Refund adjustment:" %> <%= invoice.refund_adjustment %> <%= @account.currency %> <br/>
73
+ <% if invoice.refund_adjustment.present? && invoice.refund_adjustment < 0 %>
74
+ <%= "Refund adjustment:" %> <%= humanized_money_with_symbol invoice.refund_adjustment_to_money(@account.currency) %><br/>
75
75
  <% end %>
76
76
  <%= "Invoice #" %>
77
77
  <%= link_to invoice.invoice_number, invoice_path(:id => invoice.invoice_id) %>
@@ -91,18 +91,10 @@
91
91
  :invoice_id => invoice.invoice_id }),
92
92
  :class => "btn btn-mini" %>
93
93
  </nobr>
94
- <nobr>
95
- <%= link_to "External Payment",
96
- kaui_engine.new_payment_path(:params => { :account_id => invoice.account_id,
97
- :invoice_id => invoice.invoice_id,
98
- :external => "true" }),
99
- :class => "btn btn-mini" %>
100
- </nobr>
101
94
  <nobr>
102
95
  <%= link_to "Payment",
103
96
  kaui_engine.new_payment_path(:params => { :account_id => invoice.account_id,
104
- :invoice_id => invoice.invoice_id,
105
- :external => "false" }),
97
+ :invoice_id => invoice.invoice_id }),
106
98
  :class => "btn btn-mini" %>
107
99
  </nobr>
108
100
  <% end %>
@@ -144,7 +136,7 @@
144
136
  <td>
145
137
  <%= "Adjusted:" %> <% if refund.adjusted %>yes<% else %>no<% end %><br/>
146
138
  <%= "Payment id:" %> <%= refund.payment_id %><br/>
147
- <%= "Refund Amount:" %> <%= refund.amount %><br/>
139
+ <%= "Refund Amount:" %> <%= humanized_money_with_symbol refund.amount_to_money %><br/>
148
140
  </td>
149
141
  <td>
150
142
  <% if refund.audit_logs.present? %>
@@ -183,7 +175,7 @@
183
175
  <td><%= "CHARGEBACK" %></td>
184
176
  <td>
185
177
  <%= "Payment id:" %> <%= chargeback.payment_id %><br/>
186
- <%= "Chargeback Amount:" %> <%= chargeback.chargeback_amount %><br/>
178
+ <%= "Chargeback Amount:" %> <%= humanized_money_with_symbol chargeback.chargeback_amount_to_money(@account.currency) %><br/>
187
179
  </td>
188
180
  <td>
189
181
  <% if chargeback.audit_logs.present? %>
@@ -227,8 +219,8 @@
227
219
  <td><%= "PAYMENT" %></td>
228
220
  <td>
229
221
  <%= "Payment id:" %> <%= payment.payment_id %><br/>
230
- <%= "Total amount:" %> <%= payment.amount %> <%= @account.currency if payment.amount.present? %><br/>
231
- <%= "Paid amount:" %> <%= payment.paid_amount %> <%= @account.currency %><br/>
222
+ <%= "Total amount:" %> <%= humanized_money_with_symbol payment.amount_to_money %><br/>
223
+ <%= "Paid amount:" %> <%= humanized_money_with_symbol payment.paid_amount_to_money %><br/>
232
224
  <span <% if payment.status == 'FAILED' %>class="alert-error" <% elsif payment.status == 'SUCCESS' %>class="alert-success" <% end %>>
233
225
  <%= payment.status %>
234
226
  </span>
@@ -32,15 +32,26 @@
32
32
  <dd><%= @account.external_key %>&nbsp;</dd>
33
33
  <dt>Account balance:</dt>
34
34
  <% if @account.balance.nil? %>
35
- <dd>unknown &nbsp;</dd>
35
+ <dd>unknown
36
36
  <% elsif @account.balance <= 0 %>
37
- <dd><span class="label label-success" ><%= @account.balance %></span> &nbsp;</dd>
37
+ <dd><span class="label label-success" ><%= humanized_money_with_symbol @account.balance_to_money %></span>
38
38
  <% else %>
39
- <dd><span class="label label-important" ><%= @account.balance %></span>&nbsp;</dd>
39
+ <dd><span class="label label-important" ><%= humanized_money_with_symbol @account.balance_to_money %></span>
40
40
  <% end %>
41
+ &nbsp;
42
+ <nobr>
43
+ <%= link_to 'Charge',
44
+ kaui_engine.new_charge_path(:params => { :account_id => @account.account_id }),
45
+ :class => "btn btn-mini" %>
46
+ </nobr>
47
+ <nobr>
48
+ <%= link_to 'Credit',
49
+ kaui_engine.new_credit_path(:params => { :account_id => @account.account_id }),
50
+ :class => "btn btn-mini" %>
51
+ </nobr>
52
+ </dd>
41
53
  <dt>Notified for inv?</dt>
42
54
  <dd><%= @account.is_notified_for_invoices %>&nbsp;<%= link_to "Toggle", kaui_engine.toggle_email_notifications_account_path(@account.account_id, :is_notified => !@account.is_notified_for_invoices), :method => :post, :class => 'btn btn-mini' %></dd>
43
-
44
55
  <%= render :partial => "kaui/tags/tags_table",
45
56
  :locals => { :tags => @tags, :tags_url_or_path => kaui_engine.edit_account_tags_path(:params => { :account_id => @account.account_id }) } %>
46
57
  <%= render :partial => "kaui/account_emails/account_emails_table",
@@ -74,7 +74,7 @@
74
74
  <div class="control-group">
75
75
  <%= f.label :chargeback_amount, "Chargeback amount", :class => "control-label" %>
76
76
  <div class="controls">
77
- <%= f.text_field :chargeback_amount, :class => 'input-small' %>
77
+ <%= f.text_field :chargeback_amount, :id => 'chargeback_amount', :class => 'input-small' %>
78
78
  <p class="help-inline"><%= @account.currency %></p>
79
79
  </div>
80
80
  </div>
@@ -96,3 +96,10 @@
96
96
  </div>
97
97
  </fieldset>
98
98
  <% end %>
99
+ <%= javascript_tag do %>
100
+ $(document).ready(function() {
101
+ $("#chargeback_amount").keydown(function(event) {
102
+ preventNonNumericValues(event);
103
+ });
104
+ });
105
+ <% end %>