kaui 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +5 -3
- data/app/controllers/kaui/accounts_controller.rb +1 -1
- data/app/controllers/kaui/bundles_controller.rb +26 -0
- data/app/controllers/kaui/chargebacks_controller.rb +1 -1
- data/app/controllers/kaui/invoices_controller.rb +6 -1
- data/app/helpers/kaui/killbill_helper.rb +42 -14
- data/app/models/kaui/user.rb +9 -0
- data/app/views/kaui/bundles/index.html.erb +26 -13
- data/app/views/kaui/invoices/index.html.erb +1 -16
- data/app/views/kaui/tags/_tags_table.html.erb +3 -1
- data/config/initializers/killbill_authenticatable.rb +8 -0
- data/config/routes.rb +3 -0
- data/kaui.gemspec +3 -1
- data/lib/kaui/version.rb +1 -1
- data/test/test_helper.rb +8 -1
- metadata +21 -5
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kaui (0.6.
|
4
|
+
kaui (0.6.6)
|
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.6.
|
9
|
+
killbill-client (~> 0.6.1)
|
10
10
|
money-rails (~> 0.8.1)
|
11
11
|
rails (~> 3.2.14)
|
12
12
|
rest-client (~> 1.6.7)
|
@@ -53,6 +53,7 @@ GEM
|
|
53
53
|
railties (>= 3.2.6, < 5)
|
54
54
|
warden (~> 1.2.3)
|
55
55
|
erubis (2.7.0)
|
56
|
+
fakeweb (1.3.0)
|
56
57
|
hike (1.2.3)
|
57
58
|
i18n (0.6.9)
|
58
59
|
journey (1.0.4)
|
@@ -60,7 +61,7 @@ GEM
|
|
60
61
|
railties (>= 3.0, < 5.0)
|
61
62
|
thor (>= 0.14, < 2.0)
|
62
63
|
json (1.8.1)
|
63
|
-
killbill-client (0.6.
|
64
|
+
killbill-client (0.6.1)
|
64
65
|
json (~> 1.8.0)
|
65
66
|
mail (2.5.4)
|
66
67
|
mime-types (~> 1.16)
|
@@ -122,6 +123,7 @@ PLATFORMS
|
|
122
123
|
ruby
|
123
124
|
|
124
125
|
DEPENDENCIES
|
126
|
+
fakeweb (~> 1.3)
|
125
127
|
kaui!
|
126
128
|
mysql2
|
127
129
|
sqlite3
|
@@ -55,7 +55,7 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
55
55
|
@account_emails = Kaui::AccountEmail.where({ :account_id => @account.account_id }, options_for_klient)
|
56
56
|
@overdue_state = Kaui::KillbillHelper::get_overdue_state_for_account(@account.account_id, options_for_klient)
|
57
57
|
@payment_methods = Kaui::KillbillHelper::get_non_external_payment_methods(@account.account_id, options_for_klient)
|
58
|
-
@bundles = Kaui::KillbillHelper::
|
58
|
+
@bundles = Kaui::KillbillHelper::get_bundles_for_account(@account.account_id, options_for_klient)
|
59
59
|
|
60
60
|
@subscriptions_by_bundle_id = {}
|
61
61
|
|
@@ -6,6 +6,32 @@ class Kaui::BundlesController < Kaui::EngineController
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
def pagination
|
10
|
+
json = { :sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => [] }
|
11
|
+
|
12
|
+
search_key = params[:sSearch]
|
13
|
+
if search_key.present?
|
14
|
+
bundles = Kaui::KillbillHelper::search_bundles(search_key, params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
|
15
|
+
else
|
16
|
+
bundles = Kaui::KillbillHelper::get_bundles(params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
|
17
|
+
end
|
18
|
+
json[:iTotalDisplayRecords] = bundles.pagination_total_nb_records
|
19
|
+
json[:iTotalRecords] = bundles.pagination_max_nb_records
|
20
|
+
|
21
|
+
bundles.each do |bundle|
|
22
|
+
json[:aaData] << [
|
23
|
+
view_context.link_to(bundle.bundle_id, view_context.url_for(:action => :show, :id => bundle.bundle_id)),
|
24
|
+
view_context.link_to(bundle.account_id, view_context.url_for(:controller => :accounts, :action => :show, :id => bundle.account_id)),
|
25
|
+
bundle.external_key,
|
26
|
+
bundle.subscriptions.nil? ? '' : (bundle.subscriptions.map { |s| s.product_name }).join(', ')
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
respond_to do |format|
|
31
|
+
format.json { render :json => json }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
9
35
|
def show
|
10
36
|
key = params[:id]
|
11
37
|
if key.present?
|
@@ -54,7 +54,7 @@ class Kaui::ChargebacksController < Kaui::EngineController
|
|
54
54
|
# Cancel all subscriptions on the account, if required
|
55
55
|
if should_cancel_subs
|
56
56
|
begin
|
57
|
-
bundles = Kaui::KillbillHelper::
|
57
|
+
bundles = Kaui::KillbillHelper::get_bundles_for_account(params[:account_id], options_for_klient)
|
58
58
|
bundles.each do |bundle|
|
59
59
|
bundle.subscriptions.each do |subscription|
|
60
60
|
# Already cancelled?
|
@@ -8,7 +8,12 @@ class Kaui::InvoicesController < Kaui::EngineController
|
|
8
8
|
def pagination
|
9
9
|
json = { :sEcho => params[:sEcho], :iTotalRecords => 0, :iTotalDisplayRecords => 0, :aaData => [] }
|
10
10
|
|
11
|
-
|
11
|
+
search_key = params[:sSearch]
|
12
|
+
if search_key.present?
|
13
|
+
invoices = Kaui::KillbillHelper::search_invoices(search_key, params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
|
14
|
+
else
|
15
|
+
invoices = Kaui::KillbillHelper::get_invoices(params[:iDisplayStart] || 0, params[:iDisplayLength] || 10, options_for_klient)
|
16
|
+
end
|
12
17
|
json[:iTotalDisplayRecords] = invoices.pagination_total_nb_records
|
13
18
|
json[:iTotalRecords] = invoices.pagination_max_nb_records
|
14
19
|
|
@@ -147,11 +147,47 @@ module Kaui
|
|
147
147
|
else
|
148
148
|
raise ArgumentError.new("account id not specified") if account_id.blank?
|
149
149
|
bundles = KillBillClient::Model::Bundle.find_all_by_account_id_and_external_key account_id, key, options
|
150
|
-
bundles
|
150
|
+
get_active_bundle_or_latest_created(bundles)
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
|
-
def self.
|
154
|
+
def self.get_active_bundle_or_latest_created(bundles)
|
155
|
+
|
156
|
+
if bundles.empty?
|
157
|
+
return nil
|
158
|
+
end
|
159
|
+
|
160
|
+
latest_start_date = nil
|
161
|
+
latest_bundle = nil
|
162
|
+
|
163
|
+
bundles.each do |b|
|
164
|
+
b.subscriptions.each do |s|
|
165
|
+
if s.product_category != 'ADD_ON'
|
166
|
+
if latest_start_date.nil? || latest_start_date < s.start_date
|
167
|
+
latest_start_date = s.start_date
|
168
|
+
latest_bundle = b
|
169
|
+
end
|
170
|
+
|
171
|
+
if s.cancelled_date.nil? || s.cancelled_date > Time.now
|
172
|
+
return b
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
latest_bundle
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def self.get_bundles(offset, limit, options = {})
|
183
|
+
KillBillClient::Model::Bundle.find_in_batches offset, limit, options
|
184
|
+
end
|
185
|
+
|
186
|
+
def self.search_bundles(search_key, offset, limit, options = {})
|
187
|
+
KillBillClient::Model::Bundle.find_in_batches_by_search_key search_key, offset, limit, options
|
188
|
+
end
|
189
|
+
|
190
|
+
def self.get_bundles_for_account(account_id, options = {})
|
155
191
|
account = KillBillClient::Model::Account.find_by_id account_id, false, false, options
|
156
192
|
account.bundles options
|
157
193
|
end
|
@@ -229,6 +265,10 @@ module Kaui
|
|
229
265
|
KillBillClient::Model::Invoice.find_in_batches offset, limit, options
|
230
266
|
end
|
231
267
|
|
268
|
+
def self.search_invoices(search_key, offset, limit, options = {})
|
269
|
+
KillBillClient::Model::Invoice.find_in_batches_by_search_key search_key, offset, limit, options
|
270
|
+
end
|
271
|
+
|
232
272
|
def self.get_invoice(id_or_number, with_items = true, audit = "NONE", options = {})
|
233
273
|
KillBillClient::Model::Invoice.find_by_id_or_number id_or_number, with_items, audit, options
|
234
274
|
end
|
@@ -292,11 +332,6 @@ module Kaui
|
|
292
332
|
|
293
333
|
############## CATALOG ##############
|
294
334
|
|
295
|
-
def self.get_full_catalog(options = {})
|
296
|
-
data = call_killbill :get, "/1.0/kb/catalog/simpleCatalog", options
|
297
|
-
data[:json]
|
298
|
-
end
|
299
|
-
|
300
335
|
def self.get_available_addons(base_product_name, options = {})
|
301
336
|
data = call_killbill :get, "/1.0/kb/catalog/availableAddons?baseProductName=#{base_product_name}", options
|
302
337
|
if data.has_key?(:json)
|
@@ -404,7 +439,6 @@ module Kaui
|
|
404
439
|
end
|
405
440
|
|
406
441
|
def self.create_refund(payment_id, refund, current_user = nil, reason = nil, comment = nil, options = {})
|
407
|
-
|
408
442
|
new_refund = KillBillClient::Model::Refund.new
|
409
443
|
new_refund.payment_id = payment_id
|
410
444
|
new_refund.amount = refund["amount"]
|
@@ -433,7 +467,6 @@ module Kaui
|
|
433
467
|
end
|
434
468
|
|
435
469
|
def self.create_chargeback(chargeback, current_user = nil, reason = nil, comment = nil, options = {})
|
436
|
-
|
437
470
|
new_chargeback = KillBillClient::Model::Chargeback.new
|
438
471
|
new_chargeback.payment_id = chargeback.payment_id
|
439
472
|
new_chargeback.amount = chargeback.chargeback_amount
|
@@ -535,11 +568,6 @@ module Kaui
|
|
535
568
|
KillBillClient::Model::CustomField.find_in_batches_by_search_key search_key, offset, limit, options
|
536
569
|
end
|
537
570
|
|
538
|
-
def self.get_custom_fields_for_account(account_id, options = {})
|
539
|
-
data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/customFields", options
|
540
|
-
process_response(data, :multiple) { |json| Kaui::CustomField.new(json) }
|
541
|
-
end
|
542
|
-
|
543
571
|
############## OVERDUE ##############
|
544
572
|
|
545
573
|
def self.get_overdue_state_for_account(account_id, options = {})
|
data/app/models/kaui/user.rb
CHANGED
@@ -26,6 +26,15 @@ module Kaui
|
|
26
26
|
:api_secret => api_secret
|
27
27
|
end
|
28
28
|
|
29
|
+
# Verify the Kill Bill session hasn't timed-out
|
30
|
+
def authenticated_with_killbill?(api_key=KillBillClient.api_key, api_secret=KillBillClient.api_secret)
|
31
|
+
KillBillClient.url = Kaui.killbill_finder.call
|
32
|
+
subject = KillBillClient::Model::Security.find_subject :session_id => kb_session_id,
|
33
|
+
:api_key => api_key,
|
34
|
+
:api_secret => api_secret
|
35
|
+
subject.is_authenticated
|
36
|
+
end
|
37
|
+
|
29
38
|
private
|
30
39
|
|
31
40
|
def self.do_find_permissions(options = {})
|
@@ -1,14 +1,27 @@
|
|
1
|
-
|
2
|
-
<
|
3
|
-
<
|
4
|
-
|
5
|
-
<
|
6
|
-
<
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
<table id="bundles-table" class="table table-condensed">
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<th>Bundle ID</th>
|
5
|
+
<th>Account ID</th>
|
6
|
+
<th>External key</th>
|
7
|
+
<th>Subscriptions</th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
<tbody>
|
11
|
+
<tr>
|
12
|
+
<td colspan="1" class="dataTables_empty">Loading data from server</td>
|
13
|
+
</tr>
|
14
|
+
</tbody>
|
15
|
+
</table>
|
16
|
+
|
17
|
+
<%= javascript_tag do %>
|
18
|
+
$(document).ready(function() {
|
19
|
+
$('#bundles-table').dataTable({
|
20
|
+
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
|
21
|
+
"sPaginationType": "bootstrap",
|
22
|
+
"bProcessing": true,
|
23
|
+
"bServerSide": true,
|
24
|
+
"sAjaxSource": "<%= bundles_pagination_path :format => :json %>"
|
25
|
+
});
|
26
|
+
});
|
14
27
|
<% end %>
|
@@ -1,18 +1,3 @@
|
|
1
|
-
<%= form_tag invoices_path, :class => "form-horizontal", :method => :get do %>
|
2
|
-
<fieldset>
|
3
|
-
<legend>Please enter invoice id</legend>
|
4
|
-
<div class="control-group">
|
5
|
-
<label class="control-label" for="invoice_id">Invoice</label>
|
6
|
-
<div class="controls">
|
7
|
-
<%= text_field_tag 'invoice_id', nil, :class => "input-xlarge", :id => "invoice_id", :placeholder => "InvoiceId, InvoiceNumber" %>
|
8
|
-
</div>
|
9
|
-
</div>
|
10
|
-
<div class="form-actions">
|
11
|
-
<%= button_tag "Search", :class =>"btn btn-primary" %>
|
12
|
-
</div>
|
13
|
-
</fieldset>
|
14
|
-
<% end %>
|
15
|
-
|
16
1
|
<table id="invoices-table" class="table table-condensed">
|
17
2
|
<thead>
|
18
3
|
<tr>
|
@@ -33,7 +18,7 @@
|
|
33
18
|
<%= javascript_tag do %>
|
34
19
|
$(document).ready(function() {
|
35
20
|
$('#invoices-table').dataTable({
|
36
|
-
"sDom": "<'row-fluid'<'span6'l><'span6'>r>t<'row-fluid'<'span6'i><'span6'p>>",
|
21
|
+
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
|
37
22
|
"sPaginationType": "bootstrap",
|
38
23
|
"bProcessing": true,
|
39
24
|
"bServerSide": true,
|
@@ -6,6 +6,8 @@
|
|
6
6
|
<% end %>
|
7
7
|
<br/>
|
8
8
|
<% end %>
|
9
|
-
|
9
|
+
<% if can? :add, Kaui::Tag or can? :remove, Kaui::Tag %>
|
10
|
+
<%= link_to 'Add/Remove', tags_url_or_path, :class => 'btn btn-mini' %>
|
11
|
+
<% end %>
|
10
12
|
<%= link_to 'Tags Audit', tags_show_path, :class => 'btn btn-mini' %>
|
11
13
|
</dd>
|
@@ -31,6 +31,14 @@ end
|
|
31
31
|
|
32
32
|
Warden::Strategies.add(:killbill_authenticatable, Devise::Strategies::KillbillAuthenticatable)
|
33
33
|
|
34
|
+
Warden::Manager.after_set_user do |user, auth, opts|
|
35
|
+
unless user.authenticated_with_killbill?
|
36
|
+
scope = opts[:scope]
|
37
|
+
auth.logout(scope)
|
38
|
+
throw(:warden, :scope => scope, :reason => "Kill Bill session expired")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
34
42
|
Devise.add_module(:killbill_authenticatable,
|
35
43
|
:strategy => true,
|
36
44
|
:route => :session,
|
data/config/routes.rb
CHANGED
@@ -69,6 +69,9 @@ Kaui::Engine.routes.draw do
|
|
69
69
|
|
70
70
|
resources :invoice_items, :only => [ :index, :show, :edit, :update, :destroy ]
|
71
71
|
|
72
|
+
scope "/bundles" do
|
73
|
+
match "/pagination" => "bundles#pagination", :via => :get, :as => "bundles_pagination"
|
74
|
+
end
|
72
75
|
resources :bundles, :only => [ :index, :show ] do
|
73
76
|
member do
|
74
77
|
put :do_transfer
|
data/kaui.gemspec
CHANGED
@@ -27,10 +27,12 @@ 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.6.
|
30
|
+
s.add_dependency 'killbill-client', '~> 0.6.1'
|
31
31
|
s.add_dependency 'devise', '~> 3.0.2'
|
32
32
|
s.add_dependency 'cancan', '~> 1.6.10'
|
33
33
|
|
34
|
+
s.add_development_dependency "fakeweb", '~> 1.3'
|
35
|
+
|
34
36
|
if defined?(JRUBY_VERSION)
|
35
37
|
s.add_development_dependency 'activerecord-jdbc-adapter', '~> 1.2.2'
|
36
38
|
s.add_development_dependency 'activerecord-jdbcmysql-adapter', '~> 1.2.2'
|
data/lib/kaui/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'fakeweb'
|
2
|
+
|
1
3
|
# Configure Rails Environment
|
2
4
|
ENV["RAILS_ENV"] = "test"
|
3
5
|
|
@@ -13,6 +15,11 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
13
15
|
# Load helpers
|
14
16
|
Dir["#{File.dirname(__FILE__)}/unit/helpers/kaui/*.rb"].each { |f| require f }
|
15
17
|
|
18
|
+
# Setup Kill Bill stubs
|
19
|
+
FakeWeb.allow_net_connect = false
|
20
|
+
FakeWeb.register_uri(:get, "http://127.0.0.1:8080/1.0/kb/security/subject", body: "{\"is_authenticated\":true}", :content_type => "application/json")
|
21
|
+
FakeWeb.register_uri(:any, %r|http://127.0.0.1:8080|, body: "{}", :content_type => "application/json")
|
22
|
+
|
16
23
|
# Include Devise helpers
|
17
24
|
class ActionController::TestCase
|
18
25
|
include Devise::TestHelpers
|
@@ -86,7 +93,7 @@ module Kaui::KillbillHelper
|
|
86
93
|
[]
|
87
94
|
end
|
88
95
|
|
89
|
-
def self.
|
96
|
+
def self.get_bundles_for_account(account_id, options = {})
|
90
97
|
[]
|
91
98
|
end
|
92
99
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
requirements:
|
99
99
|
- - ~>
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version: 0.6.
|
101
|
+
version: 0.6.1
|
102
102
|
type: :runtime
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.6.
|
109
|
+
version: 0.6.1
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
111
|
name: devise
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +139,22 @@ dependencies:
|
|
139
139
|
- - ~>
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: 1.6.10
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: fakeweb
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ~>
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '1.3'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ~>
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '1.3'
|
142
158
|
- !ruby/object:Gem::Dependency
|
143
159
|
name: sqlite3
|
144
160
|
requirement: !ruby/object:Gem::Requirement
|
@@ -441,7 +457,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
441
457
|
version: '0'
|
442
458
|
segments:
|
443
459
|
- 0
|
444
|
-
hash: -
|
460
|
+
hash: -1686099938526165848
|
445
461
|
requirements: []
|
446
462
|
rubyforge_project:
|
447
463
|
rubygems_version: 1.8.25
|