kaui 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44e6088db793de66aab1c622dac27f3ae50c8d8a
4
- data.tar.gz: 1c33caaa564cc276412f6e7ca9cc721421c2ecff
3
+ metadata.gz: bd49d087cb5c254ed629586ba797f0634fb3eb98
4
+ data.tar.gz: a974af62e8d78d37100fccf5c8bc27057cf98c6c
5
5
  SHA512:
6
- metadata.gz: c7d1fd9ea17cca4ecaab91417b0119d87f4d99d17a2ffd660c83208d2c7385d5d5ff37350ee76b4d0d4ae33ee90a638e65c94f1eb4dbc5e9b58b7d0727ff1d42
7
- data.tar.gz: b07a484c935a30a48388e3a20047f4b494430559fb27ad917459a69e5588c184be03de1ada2b270da563322102d06bae3c727dde61a0b70128545047b52b8ea6
6
+ metadata.gz: d87e9d3c36da492ff243e3ab800f9bc766f4884955d02e9697bc37a6239039ff38264c22563e912fd050cee10ef9f8565f649f2ac72bae675670b15abfd477da
7
+ data.tar.gz: c7f4ef4c208234e5667b7ce9eb887c923381a4e262239e3148d4559ed719f6a1bbbfb4685c5092c7e7158f5b7b3825d41814c3bbe376612171259ce8743497ad
data/.travis.yml CHANGED
@@ -21,6 +21,11 @@ jdk:
21
21
  before_script:
22
22
  - mysql -e 'create database kaui_test;'
23
23
 
24
+ script:
25
+ - RAILS_ENV=test bundle exec rake db:migrate --trace
26
+ - bundle exec rake db:test:prepare
27
+ - bundle exec rake
28
+
24
29
  matrix:
25
30
  allow_failures:
26
31
  - rvm: ruby-head
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kaui (0.3.0)
4
+ kaui (0.3.1)
5
5
  cancan (~> 1.6.10)
6
6
  d3_rails (~> 3.2.8)
7
7
  devise (~> 3.0.2)
8
8
  jquery-rails (~> 3.0.4)
9
- killbill-client (~> 0.2.0)
9
+ killbill-client (~> 0.2.1)
10
10
  money-rails (~> 0.8.1)
11
11
  rails (~> 3.2.14)
12
12
  rest-client (~> 1.6.7)
@@ -60,7 +60,7 @@ GEM
60
60
  railties (>= 3.0, < 5.0)
61
61
  thor (>= 0.14, < 2.0)
62
62
  json (1.8.0)
63
- killbill-client (0.2.0)
63
+ killbill-client (0.2.1)
64
64
  mail (2.5.4)
65
65
  mime-types (~> 1.16)
66
66
  treetop (~> 1.4.8)
@@ -1,10 +1,10 @@
1
1
  module Kaui
2
- class AccountEmailsController < ApplicationController
2
+ class AccountEmailsController < EngineController
3
3
  # GET /account_emails/1
4
4
  # GET /account_emails/1.json
5
5
  def show
6
6
  @account_id = params[:id]
7
- @account_emails = AccountEmail.where(:account_id => @account_id)
7
+ @account_emails = AccountEmail.where({ :account_id => @account_id }, options_for_klient)
8
8
 
9
9
  respond_to do |format|
10
10
  format.html # show.html.erb
@@ -29,7 +29,7 @@ module Kaui
29
29
  @account_email = AccountEmail.new(params[:account_email])
30
30
 
31
31
  respond_to do |format|
32
- if @account_email.save
32
+ if @account_email.save(current_user, params[:reason], params[:comment], options_for_klient)
33
33
  format.html { redirect_to kaui_engine.account_email_path(@account_email), :notice => 'Account email was successfully created.' }
34
34
  format.json { render :json => @account_email, :status => :created, :location => @account_email }
35
35
  else
@@ -42,8 +42,8 @@ module Kaui
42
42
  # DELETE /account_emails/1
43
43
  # DELETE /account_emails/1.json
44
44
  def destroy
45
- @account_email = AccountEmail.where(:account_id => params[:id], :email => params[:email])
46
- @account_email.destroy
45
+ @account_email = AccountEmail.where({ :account_id => params[:id], :email => params[:email] }, options_for_klient)
46
+ @account_email.destroy(current_user, params[:reason], params[:comment], options_for_klient)
47
47
 
48
48
  respond_to do |format|
49
49
  format.html { redirect_to kaui_engine.account_email_path(params[:id]) }
@@ -17,7 +17,7 @@ class Kaui::AccountTagsController < Kaui::EngineController
17
17
  def edit
18
18
  @account_id = params[:account_id]
19
19
  begin
20
- @available_tags = Kaui::TagDefinition.all_for_account.sort
20
+ @available_tags = Kaui::TagDefinition.all_for_account(options_for_klient).sort
21
21
  @account = Kaui::KillbillHelper::get_account(@account_id, false, false, options_for_klient)
22
22
  @tag_names = Kaui::KillbillHelper::get_tags_for_account(@account.account_id, options_for_klient).map { |tag| tag.tag_definition_name }
23
23
  rescue => e
@@ -48,12 +48,11 @@ class Kaui::AccountTagsController < Kaui::EngineController
48
48
  tags_to_add << new_tag_definition_id unless current_tags.include?(new_tag_definition_id)
49
49
  end
50
50
 
51
- Kaui::KillbillHelper::remove_tags_for_account(params[:account_id], tags_to_remove, options_for_klient) unless tags_to_remove.empty?
52
- Kaui::KillbillHelper::add_tags_for_account(params[:account_id], tags_to_add, options_for_klient) unless tags_to_add.empty?
51
+ Kaui::KillbillHelper::remove_tags_for_account(params[:account_id], tags_to_remove, current_user, params[:reason], params[:comment], options_for_klient) unless tags_to_remove.empty?
52
+ Kaui::KillbillHelper::add_tags_for_account(params[:account_id], tags_to_add, current_user, params[:reason], params[:comment], options_for_klient) unless tags_to_add.empty?
53
53
  rescue => e
54
54
  flash[:error] = "Error while updating tags: #{as_string(e)}"
55
55
  end
56
56
  redirect_to kaui_engine.account_path(params[:account_id])
57
57
  end
58
-
59
58
  end
@@ -153,7 +153,7 @@ class Kaui::AccountsController < Kaui::EngineController
153
153
 
154
154
  def toggle_email_notifications
155
155
  begin
156
- @account = Kaui::KillbillHelper::update_email_notifications(params[:id], params[:is_notified], options_for_klient)
156
+ @account = Kaui::KillbillHelper::update_email_notifications(params[:id], params[:is_notified], current_user, params[:reason], params[:comment], options_for_klient)
157
157
  flash[:notice] = "Email preferences updated"
158
158
  rescue => e
159
159
  flash[:error] = "Error while switching email notifications #{invoice_id}: #{as_string(e)}"
@@ -30,11 +30,10 @@ class Kaui::BundleTagsController < Kaui::EngineController
30
30
  bundle = Kaui::KillbillHelper::get_bundle(params[:bundle_id], options_for_klient)
31
31
  tags = params[:tags]
32
32
 
33
- Kaui::KillbillHelper::set_tags_for_bundle(bundle.bundle_id, tags, options_for_klient)
33
+ Kaui::KillbillHelper::set_tags_for_bundle(bundle.bundle_id, tags, current_user, params[:reason], params[:comment], options_for_klient)
34
34
  redirect_to Kaui.bundle_home_path.call(bundle.bundle_id)
35
35
  rescue => e
36
36
  flash.now[:error] = "Error while updating tags: #{as_string(e)}"
37
37
  end
38
38
  end
39
-
40
39
  end
@@ -55,7 +55,7 @@ class Kaui::BundlesController < Kaui::EngineController
55
55
  if bundle_id.present? && result.is_a?(Kaui::Account)
56
56
  @new_account = result
57
57
  begin
58
- Kaui::KillbillHelper::transfer_bundle(bundle_id, @new_account.account_id, options_for_klient)
58
+ Kaui::KillbillHelper::transfer_bundle(bundle_id, @new_account.account_id, current_user, params[:reason], params[:comment], options_for_klient)
59
59
  flash[:notice] = "Bundle transfered successfully"
60
60
  rescue => e
61
61
  flash[:error] = "Error transfering bundle #{as_string(e)}"
@@ -77,5 +77,4 @@ class Kaui::BundlesController < Kaui::EngineController
77
77
  render :transfer
78
78
  end
79
79
  end
80
-
81
80
  end
@@ -44,7 +44,7 @@ class Kaui::ChargebacksController < Kaui::EngineController
44
44
 
45
45
  if chargeback.present?
46
46
  begin
47
- Kaui::KillbillHelper::create_chargeback(chargeback, params[:reason], params[:comment], options_for_klient)
47
+ Kaui::KillbillHelper::create_chargeback(chargeback, current_user, params[:reason], params[:comment], options_for_klient)
48
48
  flash[:notice] = "Chargeback created"
49
49
  rescue => e
50
50
  flash[:error] = "Error while creating a new chargeback: #{as_string(e)}"
@@ -22,7 +22,7 @@ class Kaui::ChargesController < Kaui::EngineController
22
22
 
23
23
  if charge.present?
24
24
  begin
25
- Kaui::KillbillHelper::create_charge(charge, params[:requested_date], current_user, nil, params[:comment], options_for_klient)
25
+ Kaui::KillbillHelper::create_charge(charge, params[:requested_date], current_user, params[:reason], params[:comment], options_for_klient)
26
26
  flash[:notice] = "Charge created"
27
27
  redirect_to kaui_engine.account_timeline_path(:id => charge.account_id)
28
28
  rescue => e
@@ -27,5 +27,4 @@ class Kaui::PaymentsController < Kaui::EngineController
27
27
  end
28
28
  redirect_to kaui_engine.account_timeline_path(:id => payment.account_id)
29
29
  end
30
-
31
30
  end
@@ -105,5 +105,4 @@ class Kaui::RefundsController < Kaui::EngineController
105
105
  end
106
106
  nil
107
107
  end
108
-
109
108
  end
@@ -62,7 +62,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
62
62
  @subscription.product_name = plan["productName"]
63
63
  @subscription.price_list = plan["priceListName"]
64
64
 
65
- Kaui::KillbillHelper::create_subscription(@subscription, current_user, options_for_klient)
65
+ Kaui::KillbillHelper::create_subscription(@subscription, current_user, params[:reason], params[:comment], options_for_klient)
66
66
  redirect_to Kaui.bundle_home_path.call(@bundle.bundle_id)
67
67
  rescue => e
68
68
  flash.now[:error] = "Error while creating the new subscription: #{as_string(e)}"
@@ -134,7 +134,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
134
134
  subscription.price_list = plan["priceListName"]
135
135
  subscription.subscription_id = params[:subscription][:subscription_id]
136
136
 
137
- Kaui::KillbillHelper::update_subscription(subscription, requested_date, policy, current_user, options_for_klient)
137
+ Kaui::KillbillHelper::update_subscription(subscription, requested_date, policy, current_user, params[:reason], params[:comment], options_for_klient)
138
138
  rescue => e
139
139
  flash[:error] = "Error while updating subscription: #{as_string(e)}"
140
140
  end
@@ -148,7 +148,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
148
148
  subscription_id = params[:id]
149
149
  if subscription_id.present?
150
150
  begin
151
- Kaui::KillbillHelper::reinstate_subscription(subscription_id, current_user, options_for_klient)
151
+ Kaui::KillbillHelper::reinstate_subscription(subscription_id, current_user, params[:reason], params[:comment], options_for_klient)
152
152
  flash[:notice] = "Subscription reinstated"
153
153
  rescue => e
154
154
  flash[:error] = "Error while reinstating subscription: #{as_string(e)}"
@@ -163,7 +163,7 @@ class Kaui::SubscriptionsController < Kaui::EngineController
163
163
  subscription_id = params[:id]
164
164
  if subscription_id.present?
165
165
  begin
166
- Kaui::KillbillHelper::delete_subscription(subscription_id, params[:policy], params[:ctd], params[:billing_period], current_user, options_for_klient)
166
+ Kaui::KillbillHelper::delete_subscription(subscription_id, params[:policy], params[:ctd], params[:billing_period], current_user, params[:reason], params[:comment], options_for_klient)
167
167
  rescue => e
168
168
  flash[:error] = "Error while canceling subscription: #{as_string(e)}"
169
169
  end
@@ -49,7 +49,7 @@ module Kaui
49
49
  @tag_definition = TagDefinition.new(params[:tag_definition])
50
50
 
51
51
  respond_to do |format|
52
- if @tag_definition.save
52
+ if @tag_definition.save(current_user, params[:reason], params[:comment], options_for_klient)
53
53
  format.html { redirect_to @tag_definition, :notice => 'Tag definition was successfully created.' }
54
54
  format.json { render :json => @tag_definition, :status => :created, :location => @tag_definition }
55
55
  else
@@ -79,7 +79,7 @@ module Kaui
79
79
  # DELETE /tag_definitions/1.json
80
80
  def destroy
81
81
  @tag_definition = TagDefinition.find(params[:id], options_for_klient)
82
- @tag_definition.destroy
82
+ @tag_definition.destroy(current_user, params[:reason], params[:comment], options_for_klient)
83
83
 
84
84
  respond_to do |format|
85
85
  format.html { redirect_to tag_definitions_url, :notice => 'Tag definition was successfully destroyed.' }
@@ -21,6 +21,7 @@ module Kaui
21
21
  if args[-1][:session_id]
22
22
  args[-1]["Cookie"] = "JSESSIONID=#{args[-1][:session_id]}"
23
23
  end
24
+ [:api_key, :api_secret, :username, :password, :session_id].each { |k| args[-1].delete(k) }
24
25
 
25
26
  response = RestClient.send(method.to_sym, url, *args)
26
27
  data = {:code => response.code}
@@ -49,7 +50,22 @@ module Kaui
49
50
  end
50
51
 
51
52
  def self.extract_reason_code(reason)
53
+ reason_code = reason
52
54
  reason_code = $1 if reason =~ /\s*(\d+).*/
55
+ reason_code
56
+ end
57
+
58
+ def self.build_audit_headers(current_user, reason, comment, options)
59
+ {
60
+ :content_type => "application/json",
61
+ "X-Killbill-CreatedBy" => extract_created_by(current_user),
62
+ "X-Killbill-Reason" => extract_reason_code(reason),
63
+ "X-Killbill-Comment" => "#{comment}",
64
+ }.merge(options)
65
+ end
66
+
67
+ def self.extract_created_by(current_user)
68
+ current_user.respond_to?(:kb_username) ? current_user.kb_username : current_user.to_s
53
69
  end
54
70
 
55
71
  ############## ACCOUNT ##############
@@ -96,20 +112,13 @@ module Kaui
96
112
  call_killbill :post,
97
113
  "/1.0/kb/accounts/#{account_email.account_id}/emails",
98
114
  ActiveSupport::JSON.encode(account_email_data, :root => false),
99
- :content_type => "application/json",
100
- "X-Killbill-CreatedBy" => current_user,
101
- "X-Killbill-Reason" => extract_reason_code(reason),
102
- "X-Killbill-Comment" => "#{comment}",
103
- **options
115
+ build_audit_headers(current_user, reason, comment, options)
104
116
  end
105
117
 
106
118
  def self.remove_account_email(account_email, current_user = nil, reason = nil, comment = nil, options = {})
107
119
  call_killbill :delete,
108
120
  "/1.0/kb/accounts/#{account_email.account_id}/emails/#{account_email.email}",
109
- "X-Killbill-CreatedBy" => current_user,
110
- "X-Killbill-Reason" => "#{reason}",
111
- "X-Killbill-Comment" => "#{comment}",
112
- **options
121
+ build_audit_headers(current_user, reason, comment, options)
113
122
  end
114
123
 
115
124
  def self.update_email_notifications(account_id, is_notified, current_user = nil, reason = nil, comment = nil, options = {})
@@ -117,11 +126,7 @@ module Kaui
117
126
  call_killbill :put,
118
127
  "/1.0/kb/accounts/#{account_id}/emailNotifications",
119
128
  ActiveSupport::JSON.encode(email_data, :root => false),
120
- :content_type => "application/json",
121
- "X-Killbill-CreatedBy" => current_user,
122
- "X-Killbill-Reason" => extract_reason_code(reason),
123
- "X-Killbill-Comment" => "#{comment}",
124
- **options
129
+ build_audit_headers(current_user, reason, comment, options)
125
130
  end
126
131
 
127
132
  ############## BUNDLE ##############
@@ -154,11 +159,7 @@ module Kaui
154
159
  call_killbill :put,
155
160
  "/1.0/kb/bundles/#{bundle_id}?cancelImmediately=#{cancel_immediately}&transferAddOn=#{transfer_addons}",
156
161
  ActiveSupport::JSON.encode("accountId" => new_account_id),
157
- :content_type => :json,
158
- "X-Killbill-CreatedBy" => current_user,
159
- "X-Killbill-Reason" => "#{reason}",
160
- "X-Killbill-Comment" => "#{comment}",
161
- **options
162
+ build_audit_headers(current_user, reason, comment, options)
162
163
  end
163
164
 
164
165
  ############## SUBSCRIPTION ##############
@@ -189,11 +190,7 @@ module Kaui
189
190
  call_killbill :post,
190
191
  "/1.0/kb/subscriptions",
191
192
  ActiveSupport::JSON.encode(subscription_data, :root => false),
192
- :content_type => "application/json",
193
- "X-Killbill-CreatedBy" => current_user,
194
- "X-Killbill-Reason" => "#{reason}",
195
- "X-Killbill-Comment" => "#{comment}",
196
- **options
193
+ build_audit_headers(current_user, reason, comment, options)
197
194
  end
198
195
 
199
196
  def self.update_subscription(subscription, requested_date = nil, policy = nil, current_user = nil, reason = nil, comment = nil, options = {})
@@ -208,22 +205,14 @@ module Kaui
208
205
  call_killbill :put,
209
206
  "/1.0/kb/subscriptions/#{subscription.subscription_id}#{params}",
210
207
  ActiveSupport::JSON.encode(subscription_data, :root => false),
211
- :content_type => :json,
212
- "X-Killbill-CreatedBy" => current_user,
213
- "X-Killbill-Reason" => "#{reason}",
214
- "X-Killbill-Comment" => "#{comment}",
215
- **options
208
+ build_audit_headers(current_user, reason, comment, options)
216
209
  end
217
210
 
218
211
  def self.reinstate_subscription(subscription_id, current_user = nil, reason = nil, comment = nil, options = {})
219
212
  call_killbill :put,
220
213
  "/1.0/kb/subscriptions/#{subscription_id}/uncancel",
221
214
  "",
222
- :content_type => :json,
223
- "X-Killbill-CreatedBy" => current_user,
224
- "X-Killbill-Reason" => "#{reason}",
225
- "X-Killbill-Comment" => "#{comment}",
226
- **options
215
+ build_audit_headers(current_user, reason, comment, options)
227
216
  end
228
217
 
229
218
  def self.delete_subscription(subscription_id, policy = nil, ctd = nil, billing_period = nil, current_user = nil, reason = nil, comment = nil, options = {})
@@ -233,10 +222,7 @@ module Kaui
233
222
  params += "requestedDate=#{prev_ctd.strftime('%Y-%m-%dT%H:%M:%S')}" unless prev_ctd.nil?
234
223
  call_killbill :delete,
235
224
  "/1.0/kb/subscriptions/#{subscription_id}#{params}",
236
- "X-Killbill-CreatedBy" => current_user,
237
- "X-Killbill-Reason" => "#{reason}",
238
- "X-Killbill-Comment" => "#{comment}",
239
- **options
225
+ build_audit_headers(current_user, reason, comment, options)
240
226
  end
241
227
 
242
228
  def self.compute_previous_ctd(ctd, billing_period, options = {})
@@ -283,11 +269,7 @@ module Kaui
283
269
  call_killbill :post,
284
270
  "/1.0/kb/invoices/#{invoice_item.invoice_id}",
285
271
  ActiveSupport::JSON.encode(invoice_data, :root => false),
286
- :content_type => :json,
287
- "X-Killbill-CreatedBy" => current_user,
288
- "X-Killbill-Reason" => "#{reason}",
289
- "X-Killbill-Comment" => "#{comment}",
290
- **options
272
+ build_audit_headers(current_user, reason, comment, options)
291
273
  end
292
274
 
293
275
  def self.create_charge(charge, requested_date, current_user = nil, reason = nil, comment = nil, options = {})
@@ -298,30 +280,19 @@ module Kaui
298
280
  call_killbill :post,
299
281
  "/1.0/kb/invoices/#{charge.invoice_id}/charges#{date_param}",
300
282
  ActiveSupport::JSON.encode(charge_data, :root => false),
301
- :content_type => "application/json",
302
- "X-Killbill-CreatedBy" => current_user,
303
- "X-Killbill-Reason" => extract_reason_code(reason),
304
- "X-Killbill-Comment" => "#{comment}",
305
- **options
283
+ build_audit_headers(current_user, reason, comment, options)
306
284
  else
307
285
  call_killbill :post,
308
286
  "/1.0/kb/invoices/charges#{date_param}",
309
287
  ActiveSupport::JSON.encode(charge_data, :root => false),
310
- :content_type => "application/json",
311
- "X-Killbill-CreatedBy" => current_user,
312
- "X-Killbill-Reason" => extract_reason_code(reason),
313
- "X-Killbill-Comment" => "#{comment}",
314
- **options
288
+ build_audit_headers(current_user, reason, comment, options)
315
289
  end
316
290
  end
317
291
 
318
292
  def self.delete_cba(account_id, invoice_id, invoice_item_id, current_user = nil, reason = nil, comment = nil, options = {})
319
293
  call_killbill :delete,
320
294
  "/1.0/kb/invoices/#{invoice_id}/#{invoice_item_id}/cba?accountId=#{account_id}",
321
- "X-Killbill-CreatedBy" => current_user,
322
- "X-Killbill-Reason" => "#{reason}",
323
- "X-Killbill-Comment" => "#{comment}",
324
- **options
295
+ build_audit_headers(current_user, reason, comment, options)
325
296
  end
326
297
 
327
298
  ############## CATALOG ##############
@@ -362,11 +333,7 @@ module Kaui
362
333
  call_killbill :post,
363
334
  "/1.0/kb/invoices/payments?externalPayment=#{external}",
364
335
  ActiveSupport::JSON.encode({:accountId => account_id}, :root => false),
365
- :content_type => "application/json",
366
- "X-Killbill-CreatedBy" => current_user,
367
- "X-Killbill-Reason" => extract_reason_code(reason),
368
- "X-Killbill-Comment" => "#{comment}",
369
- **options
336
+ build_audit_headers(current_user, reason, comment, options)
370
337
  end
371
338
 
372
339
  def self.create_payment(payment, external, current_user = nil, reason = nil, comment = nil, options = {})
@@ -381,18 +348,14 @@ module Kaui
381
348
  call_killbill :post,
382
349
  "/1.0/kb/invoices/#{payment.invoice_id}/payments?externalPayment=#{external}",
383
350
  ActiveSupport::JSON.encode(payment_data, :root => false),
384
- :content_type => "application/json",
385
- "X-Killbill-CreatedBy" => current_user,
386
- "X-Killbill-Reason" => extract_reason_code(reason),
387
- "X-Killbill-Comment" => "#{comment}",
388
- **options
351
+ build_audit_headers(current_user, reason, comment, options)
389
352
  end
390
353
  end
391
354
 
392
355
  ############## PAYMENT METHOD ##############
393
356
 
394
357
  def self.delete_payment_method(payment_method_id, set_auto_pay_off = false, current_user = nil, reason = nil, comment = nil, options = {})
395
- KillBillClient::Model::PaymentMethod.destroy payment_method_id, set_auto_pay_off, current_user, reason, comment, options
358
+ KillBillClient::Model::PaymentMethod.destroy payment_method_id, set_auto_pay_off, extract_created_by(current_user), extract_reason_code(reason), comment, options
396
359
  end
397
360
 
398
361
  def self.get_non_external_payment_methods(account_id, options = {})
@@ -414,11 +377,11 @@ module Kaui
414
377
  end
415
378
 
416
379
  def self.set_payment_method_as_default(account_id, payment_method_id, current_user = nil, reason = nil, comment = nil, options = {})
417
- KillBillClient::Model::PaymentMethod.set_default payment_method_id, account_id, current_user, reason, comment, options
380
+ KillBillClient::Model::PaymentMethod.set_default payment_method_id, account_id, extract_created_by(current_user), extract_reason_code(reason), comment, options
418
381
  end
419
382
 
420
383
  def self.add_payment_method(is_default, payment_method, current_user = nil, reason = nil, comment = nil, options = {})
421
- payment_method.create is_default, current_user, reason, comment, options
384
+ payment_method.create is_default, extract_created_by(current_user), extract_reason_code(reason), comment, options
422
385
  end
423
386
 
424
387
  ############## REFUND ##############
@@ -441,11 +404,7 @@ module Kaui
441
404
  call_killbill :post,
442
405
  "/1.0/kb/payments/#{payment_id}/refunds",
443
406
  ActiveSupport::JSON.encode(refund_data, :root => false),
444
- :content_type => "application/json",
445
- "X-Killbill-CreatedBy" => current_user,
446
- "X-Killbill-Reason" => extract_reason_code(reason),
447
- "X-Killbill-Comment" => "#{comment}",
448
- **options
407
+ build_audit_headers(current_user, reason, comment, options)
449
408
  end
450
409
 
451
410
  ############## CHARGEBACK ##############
@@ -461,11 +420,7 @@ module Kaui
461
420
  call_killbill :post,
462
421
  "/1.0/kb/chargebacks",
463
422
  ActiveSupport::JSON.encode(chargeback_data, :root => false),
464
- :content_type => "application/json",
465
- "X-Killbill-CreatedBy" => current_user,
466
- "X-Killbill-Reason" => extract_reason_code(reason),
467
- "X-Killbill-Comment" => "#{comment}",
468
- **options
423
+ build_audit_headers(current_user, reason, comment, options)
469
424
  end
470
425
 
471
426
  ############## CREDIT ##############
@@ -475,11 +430,7 @@ module Kaui
475
430
  call_killbill :post,
476
431
  "/1.0/kb/credits",
477
432
  ActiveSupport::JSON.encode(credit_data, :root => false),
478
- :content_type => "application/json",
479
- "X-Killbill-CreatedBy" => current_user,
480
- "X-Killbill-Reason" => extract_reason_code(reason),
481
- "X-Killbill-Comment" => "#{comment}",
482
- **options
433
+ build_audit_headers(current_user, reason, comment, options)
483
434
  end
484
435
 
485
436
  ############## TAG ##############
@@ -499,20 +450,13 @@ module Kaui
499
450
  call_killbill :post,
500
451
  "/1.0/kb/tagDefinitions",
501
452
  ActiveSupport::JSON.encode(tag_definition_data, :root => false),
502
- :content_type => "application/json",
503
- "X-Killbill-CreatedBy" => current_user,
504
- "X-Killbill-Reason" => extract_reason_code(reason),
505
- "X-Killbill-Comment" => "#{comment}",
506
- **options
453
+ build_audit_headers(current_user, reason, comment, options)
507
454
  end
508
455
 
509
456
  def self.delete_tag_definition(tag_definition_id, current_user = nil, reason = nil, comment = nil, options = {})
510
457
  call_killbill :delete,
511
458
  "/1.0/kb/tagDefinitions/#{tag_definition_id}",
512
- "X-Killbill-CreatedBy" => current_user,
513
- "X-Killbill-Reason" => "#{reason}",
514
- "X-Killbill-Comment" => "#{comment}",
515
- **options
459
+ build_audit_headers(current_user, reason, comment, options)
516
460
  end
517
461
 
518
462
  def self.get_tags_for_account(account_id, options = {})
@@ -525,25 +469,18 @@ module Kaui
525
469
  return data[:json]
526
470
  end
527
471
 
528
-
529
472
  def self.add_tags_for_account(account_id, tags, current_user = nil, reason = nil, comment = nil, options = {})
530
473
  call_killbill :post,
531
474
  "/1.0/kb/accounts/#{account_id}/tags?" + RestClient::Payload.generate(:tagList => tags.join(",")).to_s,
532
475
  nil,
533
- "X-Killbill-CreatedBy" => current_user,
534
- "X-Killbill-Reason" => "#{reason}",
535
- "X-Killbill-Comment" => "#{comment}",
536
- **options
476
+ build_audit_headers(current_user, reason, comment, options)
537
477
  end
538
478
 
539
479
  def self.remove_tags_for_account(account_id, tags, current_user = nil, reason = nil, comment = nil, options = {})
540
480
  return if !tags.present? || tags.size == 0
541
481
  call_killbill :delete,
542
482
  "/1.0/kb/accounts/#{account_id}/tags?" + RestClient::Payload.generate(:tagList => tags.join(",")).to_s,
543
- "X-Killbill-CreatedBy" => current_user,
544
- "X-Killbill-Reason" => "#{reason}",
545
- "X-Killbill-Comment" => "#{comment}",
546
- **options
483
+ build_audit_headers(current_user, reason, comment, options)
547
484
  end
548
485
 
549
486
  def self.set_tags_for_bundle(bundle_id, tags, current_user = nil, reason = nil, comment = nil, options = {})
@@ -552,10 +489,7 @@ module Kaui
552
489
  call_killbill :post,
553
490
  "/1.0/kb/bundles/#{bundle_id}/tags?" + RestClient::Payload.generate(:tag_list => tags.join(",")).to_s,
554
491
  nil,
555
- "X-Killbill-CreatedBy" => current_user,
556
- "X-Killbill-Reason" => "#{reason}",
557
- "X-Killbill-Comment" => "#{comment}",
558
- **options
492
+ build_audit_headers(current_user, reason, comment, options)
559
493
  end
560
494
  end
561
495
 
@@ -584,10 +518,7 @@ module Kaui
584
518
  call_killbill :put,
585
519
  "/1.0/kb/analytics/#{account_id}",
586
520
  nil,
587
- "X-Killbill-CreatedBy" => current_user,
588
- "X-Killbill-Reason" => "#{reason}",
589
- "X-Killbill-Comment" => "#{comment}",
590
- **options
521
+ build_audit_headers(current_user, reason, comment, options)
591
522
  end
592
523
 
593
524
  def self.get_accounts_created_over_time(options = {})
@@ -12,22 +12,18 @@ class Kaui::AccountEmail < Kaui::Base
12
12
  end
13
13
 
14
14
  def self.where(conditions, options_for_klient = {})
15
- begin
16
- account_emails = Kaui::KillbillHelper.get_account_emails(conditions[:account_id], options_for_klient) || []
17
- return account_emails.sort unless conditions[:email].present?
15
+ account_emails = Kaui::KillbillHelper.get_account_emails(conditions[:account_id], options_for_klient) || []
16
+ return account_emails.sort unless conditions[:email].present?
18
17
 
19
- account_emails.each do |account_email|
20
- return account_email if account_email.email == conditions[:email]
21
- end
22
- rescue => e
23
- @errors.add(:where, "Error while getting account emails: #{e}")
18
+ account_emails.each do |account_email|
19
+ return account_email if account_email.email == conditions[:email]
24
20
  end
25
21
  []
26
22
  end
27
23
 
28
- def save(options_for_klient = {})
24
+ def save(user = nil, reason = nil, comment = nil, options_for_klient = {})
29
25
  begin
30
- Kaui::KillbillHelper.add_account_email(self, options_for_klient)
26
+ Kaui::KillbillHelper.add_account_email(self, user, reason, comment, options_for_klient)
31
27
  true
32
28
  rescue => e
33
29
  @errors.add(:save, "Error while trying to add an account email: #{e}")
@@ -35,9 +31,9 @@ class Kaui::AccountEmail < Kaui::Base
35
31
  end
36
32
  end
37
33
 
38
- def destroy(options_for_klient = {})
34
+ def destroy(user = nil, reason = nil, comment = nil, options_for_klient = {})
39
35
  begin
40
- Kaui::KillbillHelper.remove_account_email(self, options_for_klient)
36
+ Kaui::KillbillHelper.remove_account_email(self, user, reason, comment, options_for_klient)
41
37
  true
42
38
  rescue => e
43
39
  @errors.add(:destroy, "Error while trying to delete an account email: #{e}")
@@ -17,19 +17,19 @@ class Kaui::TagDefinition < Kaui::Base
17
17
  # See com.ning.billing.util.dao.ObjectType in killbill-api
18
18
  %w(ACCOUNT ACCOUNT_EMAIL BUNDLE INVOICE PAYMENT INVOICE_ITEM INVOICE_PAYMENT
19
19
  SUBSCRIPTION SUBSCRIPTION_EVENT PAYMENT_METHOD REFUND TAG_DEFINITION).each do |object_type|
20
- define_singleton_method "all_for_#{object_type.downcase}" do
21
- self.all.delete_if { |tag_definition| !tag_definition.applicable_object_types.include? object_type }
20
+ define_singleton_method "all_for_#{object_type.downcase}" do |options_for_klient = {}|
21
+ self.all(options_for_klient).delete_if { |tag_definition| !tag_definition.applicable_object_types.include? object_type }
22
22
  end
23
23
  end
24
24
 
25
- def save(options_for_klient = {})
26
- Kaui::KillbillHelper.create_tag_definition(self, options_for_klient)
25
+ def save(user = nil, reason = nil, comment = nil, options_for_klient = {})
26
+ Kaui::KillbillHelper.create_tag_definition(self, user, reason, comment, options_for_klient)
27
27
  # TODO - we should return the newly created id and update the model
28
28
  # @persisted = true
29
29
  end
30
30
 
31
- def destroy(options_for_klient = {})
32
- Kaui::KillbillHelper.delete_tag_definition(@id, options_for_klient)
31
+ def destroy(user = nil, reason = nil, comment = nil, options_for_klient = {})
32
+ Kaui::KillbillHelper.delete_tag_definition(@id, user, reason, comment, options_for_klient)
33
33
  @persisted = false
34
34
  end
35
35
 
@@ -53,4 +53,4 @@ class Kaui::TagDefinition < Kaui::Base
53
53
  return -1 if !is_system_tag? and tag_definition.is_system_tag?
54
54
  @name <=> tag_definition.name
55
55
  end
56
- end
56
+ end
@@ -242,7 +242,7 @@
242
242
  <%= link_to 'Refund', kaui_engine.new_refund_path(:params => { :payment_id => payment.payment_id,
243
243
  :account_id => @account.account_id,
244
244
  :invoice_id => payment.invoice_id }),
245
- :class => "btn btn-mini #{"disabled" unless payment.payment_id.present? and payment.status == 'SUCCESS' and !payment.is_fully_refunded?}" %>
245
+ :class => "btn btn-mini #{"disabled" unless payment.payment_id.present? and payment.status == 'SUCCESS' and payment.paid_amount != 0}" %>
246
246
  </nobr>
247
247
  <% end %>
248
248
  <% if can? :chargeback, Kaui::Payment %>
data/kaui.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_dependency 'rest-client', '~> 1.6.7'
28
28
  s.add_dependency 'money-rails', '~> 0.8.1'
29
29
  s.add_dependency 'd3_rails', '~> 3.2.8'
30
- s.add_dependency 'killbill-client', '~> 0.2.0'
30
+ s.add_dependency 'killbill-client', '~> 0.2.1'
31
31
  s.add_dependency 'devise', '~> 3.0.2'
32
32
  s.add_dependency 'cancan', '~> 1.6.10'
33
33
 
@@ -68,7 +68,7 @@ module KauiCmd
68
68
  private
69
69
 
70
70
  def rails_project?
71
- File.exists? File.join(@app_path, 'script', 'rails')
71
+ File.exists?(File.join(@app_path, 'script', 'rails')) || File.exists?(File.join(@app_path, 'bin', 'rails'))
72
72
  end
73
73
 
74
74
  def gem(name, gem_options={})
data/lib/kaui/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kaui
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -102,12 +102,12 @@ module Kaui::KillbillHelper
102
102
  find_among_fixtures(Kaui::TagDefinition, tag_definition_id, 'id')
103
103
  end
104
104
 
105
- def self.create_tag_definition(tag_definition, options = {})
105
+ def self.create_tag_definition(tag_definition, user, reason, comment, options = {})
106
106
  tag_definition.id = SecureRandom.uuid
107
107
  add_fixture(tag_definition, Kaui::TagDefinition)
108
108
  end
109
109
 
110
- def self.delete_tag_definition(tag_definition_id, options = {})
110
+ def self.delete_tag_definition(tag_definition_id, user, reason, comment, options = {})
111
111
  delete_fixture(Kaui::TagDefinition, tag_definition_id, 'id')
112
112
  end
113
113
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Killbill core team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-19 00:00:00.000000000 Z
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: 0.2.0
89
+ version: 0.2.1
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: 0.2.0
96
+ version: 0.2.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: devise
99
99
  requirement: !ruby/object:Gem::Requirement