kaui 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +4 -4
- data/app/controllers/kaui/subscriptions_controller.rb +26 -29
- data/app/helpers/kaui/killbill_helper.rb +21 -32
- data/app/models/kaui/subscription.rb +2 -0
- data/app/views/kaui/accounts/show.html.erb +2 -0
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +1 -1
- data/app/views/kaui/subscriptions/new.html.erb +45 -18
- data/app/views/kaui/subscriptions/show.html.erb +1 -1
- data/kaui.gemspec +1 -1
- data/lib/kaui/version.rb +1 -1
- metadata +5 -5
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kaui (0.4.
|
4
|
+
kaui (0.4.2)
|
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.3.
|
9
|
+
killbill-client (~> 0.3.2)
|
10
10
|
money-rails (~> 0.8.1)
|
11
11
|
rails (~> 3.2.14)
|
12
12
|
rest-client (~> 1.6.7)
|
@@ -42,7 +42,7 @@ GEM
|
|
42
42
|
i18n (~> 0.6, >= 0.6.4)
|
43
43
|
multi_json (~> 1.0)
|
44
44
|
arel (3.0.2)
|
45
|
-
bcrypt-ruby (3.1.
|
45
|
+
bcrypt-ruby (3.1.2)
|
46
46
|
builder (3.0.4)
|
47
47
|
cancan (1.6.10)
|
48
48
|
d3_rails (3.2.8)
|
@@ -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.3.
|
63
|
+
killbill-client (0.3.2)
|
64
64
|
mail (2.5.4)
|
65
65
|
mime-types (~> 1.16)
|
66
66
|
treetop (~> 1.4.8)
|
@@ -26,45 +26,49 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def new
|
29
|
+
@account_id = params[:account_id]
|
29
30
|
bundle_id = params[:bundle_id]
|
30
31
|
@base_subscription = params[:base_subscription]
|
32
|
+
@product_category = params[:product_category]
|
31
33
|
begin
|
32
|
-
@bundle = Kaui::KillbillHelper::get_bundle(bundle_id, options_for_klient)
|
33
34
|
|
34
|
-
if @
|
35
|
+
if @product_category == "ADD_ON"
|
36
|
+
@bundle = Kaui::KillbillHelper::get_bundle(bundle_id, options_for_klient)
|
35
37
|
@catalog = Kaui::KillbillHelper::get_available_addons(@base_subscription, options_for_klient)
|
36
|
-
|
38
|
+
elsif @product_category == "BASE"
|
37
39
|
@catalog = Kaui::KillbillHelper::get_available_base_plans(options_for_klient)
|
38
40
|
end
|
39
41
|
rescue => e
|
40
42
|
flash.now[:error] = "Error while trying to start new subscription creation: #{as_string(e)}"
|
41
43
|
end
|
42
|
-
@subscription = Kaui::Subscription.new("bundleId" => bundle_id)
|
44
|
+
@subscription = Kaui::Subscription.new("bundleId" => bundle_id, "accountId" => @account_id, "product_category" => @product_category)
|
43
45
|
end
|
44
46
|
|
45
47
|
def create
|
46
|
-
|
48
|
+
|
49
|
+
@subscription = Kaui::Subscription.new(params[:subscription])
|
50
|
+
|
47
51
|
@plan_name = params[:plan_name]
|
48
52
|
|
49
53
|
begin
|
50
|
-
@subscription
|
51
|
-
|
52
|
-
|
54
|
+
if @subscription.product_category == "ADD_ON"
|
55
|
+
@base_subscription = params[:base_subscription]
|
56
|
+
@bundle = Kaui::KillbillHelper::get_bundle(@subscription.bundle_id, options_for_klient)
|
53
57
|
@catalog = Kaui::KillbillHelper::get_available_addons(@base_subscription, options_for_klient)
|
54
|
-
@subscription.
|
58
|
+
@subscription.account_id = @bundle.account_id
|
55
59
|
else
|
56
60
|
@catalog = Kaui::KillbillHelper::get_available_base_plans(options_for_klient)
|
57
|
-
@subscription.
|
61
|
+
@subscription.external_key = params[:external_key]
|
58
62
|
end
|
59
63
|
|
60
64
|
plan = @catalog[@plan_name]
|
61
|
-
@subscription.account_id = @bundle.account_id
|
62
65
|
@subscription.billing_period = plan["billingPeriod"]
|
63
66
|
@subscription.product_name = plan["productName"]
|
64
67
|
@subscription.price_list = plan["priceListName"]
|
65
68
|
|
66
|
-
Kaui::KillbillHelper::create_subscription(@subscription, current_user, params[:reason], params[:comment], options_for_klient)
|
67
|
-
|
69
|
+
res = Kaui::KillbillHelper::create_subscription(@subscription, current_user, params[:reason], params[:comment], options_for_klient)
|
70
|
+
|
71
|
+
redirect_to Kaui.bundle_home_path.call(res.bundle_id)
|
68
72
|
rescue => e
|
69
73
|
flash.now[:error] = "Error while creating the new subscription: #{as_string(e)}"
|
70
74
|
render :new
|
@@ -147,26 +151,19 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
147
151
|
redirect_to Kaui.bundle_home_path.call(bundle.bundle_id)
|
148
152
|
end
|
149
153
|
|
150
|
-
def reinstate
|
151
|
-
subscription_id = params[:id]
|
152
|
-
if subscription_id.present?
|
153
|
-
begin
|
154
|
-
Kaui::KillbillHelper::reinstate_subscription(subscription_id, current_user, params[:reason], params[:comment], options_for_klient)
|
155
|
-
flash[:notice] = "Subscription reinstated"
|
156
|
-
rescue => e
|
157
|
-
flash[:error] = "Error while reinstating subscription: #{as_string(e)}"
|
158
|
-
end
|
159
|
-
else
|
160
|
-
flash[:error] = "No subscription id given"
|
161
|
-
end
|
162
|
-
redirect_to :back
|
163
|
-
end
|
164
|
-
|
165
154
|
def destroy
|
155
|
+
|
156
|
+
|
166
157
|
subscription_id = params[:id]
|
158
|
+
|
159
|
+
puts "calling destroy id = #{subscription_id}"
|
160
|
+
|
167
161
|
if subscription_id.present?
|
168
162
|
begin
|
169
|
-
|
163
|
+
|
164
|
+
puts "current_user = #{current_user}"
|
165
|
+
|
166
|
+
Kaui::KillbillHelper::delete_subscription(subscription_id, current_user, params[:reason], params[:comment], params[:policy], options_for_klient)
|
170
167
|
rescue => e
|
171
168
|
flash[:error] = "Error while canceling subscription: #{as_string(e)}"
|
172
169
|
end
|
@@ -184,45 +184,34 @@ module Kaui
|
|
184
184
|
end
|
185
185
|
|
186
186
|
def self.create_subscription(subscription, current_user = nil, reason = nil, comment = nil, options = {})
|
187
|
-
subscription_data = Kaui::Subscription.camelize(subscription.to_hash)
|
188
|
-
# We don't want to pass events
|
189
|
-
subscription_data.delete(:events)
|
190
|
-
call_killbill :post,
|
191
|
-
"/1.0/kb/entitlements",
|
192
|
-
ActiveSupport::JSON.encode(subscription_data, :root => false),
|
193
|
-
build_audit_headers(current_user, reason, comment, options)
|
194
|
-
end
|
195
187
|
|
196
|
-
|
197
|
-
|
188
|
+
entitlement = KillBillClient::Model::EntitlementNoEvents.new
|
189
|
+
entitlement.account_id = subscription.account_id
|
190
|
+
entitlement.bundle_id = subscription.bundle_id
|
191
|
+
entitlement.external_key = subscription.external_key
|
192
|
+
entitlement.product_name = subscription.product_name
|
193
|
+
entitlement.product_category = subscription.product_category
|
194
|
+
entitlement.billing_period = subscription.billing_period
|
195
|
+
entitlement.price_list = subscription.price_list
|
198
196
|
|
199
|
-
params = "?"
|
200
|
-
params = "#{params}requestedDate=#{requested_date.to_s}&" unless requested_date.blank?
|
201
|
-
params = "#{params}policy=#{policy}" unless policy.blank?
|
202
197
|
|
203
|
-
|
204
|
-
subscription_data.delete(:events)
|
205
|
-
call_killbill :put,
|
206
|
-
"/1.0/kb/entitlements/#{subscription.subscription_id}#{params}",
|
207
|
-
ActiveSupport::JSON.encode(subscription_data, :root => false),
|
208
|
-
build_audit_headers(current_user, reason, comment, options)
|
198
|
+
entitlement.create(extract_created_by(current_user), extract_reason_code(reason), comment, options)
|
209
199
|
end
|
210
200
|
|
211
|
-
def self.
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
201
|
+
def self.update_subscription(subscription, requested_date = nil, policy = nil, current_user = nil, reason = nil, comment = nil, options = {})
|
202
|
+
|
203
|
+
requested_date = requested_date.to_s unless requested_date.blank?
|
204
|
+
entitlement = KillBillClient::Model::EntitlementNoEvents.new
|
205
|
+
entitlement.subscription_id = subscription.subscription_id
|
206
|
+
entitlement.change_plan({:productName => subscription.product_name, :billingPeriod => subscription.billing_period, :priceList => subscription.price_list},
|
207
|
+
extract_created_by(current_user), extract_reason_code(reason), comment, requested_date, policy, false, options)
|
216
208
|
end
|
217
209
|
|
218
|
-
def self.delete_subscription(subscription_id,
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
call_killbill :delete,
|
224
|
-
"/1.0/kb/entitlements/#{subscription_id}#{params}",
|
225
|
-
build_audit_headers(current_user, reason, comment, options)
|
210
|
+
def self.delete_subscription(subscription_id, current_user = nil, reason = nil, comment = nil, policy = nil, options = {})
|
211
|
+
|
212
|
+
entitlement = KillBillClient::Model::EntitlementNoEvents.new
|
213
|
+
entitlement.subscription_id = subscription_id
|
214
|
+
entitlement.cancel(extract_created_by(current_user), extract_reason_code(reason), comment, nil, policy, options)
|
226
215
|
end
|
227
216
|
|
228
217
|
def self.compute_previous_ctd(ctd, billing_period, options = {})
|
@@ -2,6 +2,7 @@ class Kaui::Subscription < Kaui::Base
|
|
2
2
|
define_attr :account_id
|
3
3
|
define_attr :subscription_id
|
4
4
|
define_attr :bundle_id
|
5
|
+
define_attr :external_key
|
5
6
|
define_attr :product_category
|
6
7
|
define_attr :product_name
|
7
8
|
define_attr :billing_period
|
@@ -16,6 +17,7 @@ class Kaui::Subscription < Kaui::Base
|
|
16
17
|
super(:account_id => data['accountId'] || data['account_id'],
|
17
18
|
:subscription_id => data['subscriptionId'] || data['subscription_id'],
|
18
19
|
:bundle_id => data['bundleId'] || data['bundle_id'],
|
20
|
+
:external_key => data['externalKey'] || data['external_key'],
|
19
21
|
:product_category => data['productCategory'] || data['product_category'],
|
20
22
|
:product_name => data['productName'] || data['product_name'],
|
21
23
|
:billing_period => data['billingPeriod'] || data['billing_period'],
|
@@ -84,6 +84,8 @@
|
|
84
84
|
:locals => { :tags => @tags, :tags_url_or_path => kaui_engine.edit_account_tags_path(:params => { :account_id => @account.account_id }) } %>
|
85
85
|
<%= render :partial => "kaui/account_emails/account_emails_table",
|
86
86
|
:locals => { :account_emails => @account_emails, :account_id => @account.account_id } %>
|
87
|
+
<dt>New base subscription:</dt>
|
88
|
+
<dd><%= link_to "Create", kaui_engine.new_subscription_path(:params => { :account_id => @account.account_id, :product_category => "BASE" }), :class => "btn btn-mini" %></dd>
|
87
89
|
</dl>
|
88
90
|
<h2><%= link_to "Billing timeline", kaui_engine.account_timeline_path(@account.account_id) %></h2>
|
89
91
|
<% if @payment_methods.present? %>
|
@@ -44,7 +44,7 @@
|
|
44
44
|
</ul>
|
45
45
|
</div>
|
46
46
|
<% if sub.product_category == 'BASE' %>
|
47
|
-
<%= link_to "Add Addons", kaui_engine.new_subscription_path(:params => { :bundle_id => sub.bundle_id, :base_subscription => sub.product_name }), :class => "btn btn-mini" %>
|
47
|
+
<%= link_to "Add Addons", kaui_engine.new_subscription_path(:params => { :bundle_id => sub.bundle_id, :base_subscription => sub.product_name, :product_category => "ADD_ON" }), :class => "btn btn-mini" %>
|
48
48
|
<% end %>
|
49
49
|
<% end %>
|
50
50
|
</nobr>
|
@@ -1,22 +1,49 @@
|
|
1
1
|
<div class="page-header">
|
2
|
-
|
2
|
+
<% if @product_category == "ADD_ON" %>
|
3
|
+
<h1>Add ADD_ON subscription
|
4
|
+
<% if @bundle.external_key %> to <%= Kaui.bundle_key_display_string.call(@bundle.external_key) %>
|
5
|
+
<% end %></h1>
|
6
|
+
<% else %>
|
7
|
+
<h1>Create new base subscription
|
8
|
+
<% if @account_id %> to account <%= @account_id %>
|
9
|
+
<% end %></h1>
|
10
|
+
<% end %>
|
3
11
|
</div>
|
4
|
-
<%= form_for(@subscription, :url => {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
<%= form_for(@subscription, :url => {:action => :create}, :html => {:class => "form-horizontal"}) do |f| %>
|
13
|
+
<fieldset>
|
14
|
+
<% if @product_category == "ADD_ON" %>
|
15
|
+
<%= f.hidden_field :bundle_id %>
|
16
|
+
<%= f.hidden_field :product_category %>
|
17
|
+
<%= hidden_field_tag :base_subscription, @base_subscription %>
|
18
|
+
<div class="control-group">
|
19
|
+
<%= label_tag :plan_name, "Available Plans:", :class => "control-label" %>
|
20
|
+
<div class="controls">
|
21
|
+
<%= select_tag :plan_name, options_for_select(@catalog.keys, @plan_name) %>
|
22
|
+
<p class="help-block">
|
23
|
+
Proration on customer's invoice will be done automatically.
|
24
|
+
</p>
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
<% else %>
|
28
|
+
<%= f.hidden_field :account_id %>
|
29
|
+
<%= f.hidden_field :product_category %>
|
30
|
+
<div class="control-group">
|
31
|
+
<%= label_tag :external_key, "Bundle External Key:", :class => "control-label" %>
|
32
|
+
<div class="controls">
|
33
|
+
<%= text_field_tag :external_key, params[:external_key], :class => 'input-xlarge', :id => "external_key" %>
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
<div class="control-group">
|
37
|
+
<%= label_tag :plan_name, "Available Plans:", :class => "control-label" %>
|
38
|
+
<div class="controls">
|
39
|
+
<%= select_tag :plan_name, options_for_select(@catalog.keys, @plan_name) %>
|
40
|
+
</div>
|
41
|
+
</div>
|
42
|
+
<% end %>
|
43
|
+
<div class="form-actions">
|
44
|
+
<%= f.submit 'Create Subscription', :class => 'btn btn-primary' %>
|
45
|
+
<%= link_to 'Back', :back, :class => 'btn' %>
|
15
46
|
</div>
|
16
|
-
|
17
|
-
|
18
|
-
<%= f.submit 'Add', :class => 'btn btn-primary' %>
|
19
|
-
<%= link_to 'Back', :back, :class => 'btn' %>
|
20
|
-
</div>
|
21
|
-
</fieldset>
|
47
|
+
|
48
|
+
</fieldset>
|
22
49
|
<% end %>
|
@@ -19,7 +19,7 @@
|
|
19
19
|
<hr/>
|
20
20
|
<%= link_to "Change", kaui_engine.edit_subscription_path(@subscription.subscription_id), :class => "btn btn-mini" %>
|
21
21
|
<%= link_to "Cancel", kaui_engine.subscription_path(@subscription.subscription_id), :method => :delete, :confirm => "Are you sure?", :class => "btn btn-mini" %>
|
22
|
-
<%= link_to "Add Addons", kaui_engine.new_subscription_path(:params => { :bundle_id => @subscription.bundle_id, :base_subscription => @subscription.product_name }), :class => "btn btn-mini" %>
|
22
|
+
<%= link_to "Add Addons", kaui_engine.new_subscription_path(:params => { :bundle_id => @subscription.bundle_id, :base_subscription => @subscription.product_name, :product_category => "ADD_ON" }), :class => "btn btn-mini" %>
|
23
23
|
<% else %>
|
24
24
|
<p>Subscription not found</p>
|
25
25
|
<% end %>
|
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.3.
|
30
|
+
s.add_dependency 'killbill-client', '~> 0.3.2'
|
31
31
|
s.add_dependency 'devise', '~> 3.0.2'
|
32
32
|
s.add_dependency 'cancan', '~> 1.6.10'
|
33
33
|
|
data/lib/kaui/version.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.2
|
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: 2013-08-
|
12
|
+
date: 2013-08-27 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.3.
|
101
|
+
version: 0.3.2
|
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.3.
|
109
|
+
version: 0.3.2
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
111
|
name: devise
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -435,7 +435,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
435
435
|
version: '0'
|
436
436
|
segments:
|
437
437
|
- 0
|
438
|
-
hash:
|
438
|
+
hash: -1588433820236604683
|
439
439
|
requirements: []
|
440
440
|
rubyforge_project:
|
441
441
|
rubygems_version: 1.8.25
|