kaui 0.4.1 → 0.4.2

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.
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kaui (0.4.1)
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.1)
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.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.1)
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 @base_subscription.present?
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
- else
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
- @base_subscription = params[:base_subscription]
48
+
49
+ @subscription = Kaui::Subscription.new(params[:subscription])
50
+
47
51
  @plan_name = params[:plan_name]
48
52
 
49
53
  begin
50
- @subscription = Kaui::Subscription.new(params[:subscription])
51
- @bundle = Kaui::KillbillHelper::get_bundle(@subscription.bundle_id, options_for_klient)
52
- if @base_subscription.present?
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.product_category = "ADD_ON"
58
+ @subscription.account_id = @bundle.account_id
55
59
  else
56
60
  @catalog = Kaui::KillbillHelper::get_available_base_plans(options_for_klient)
57
- @subscription.product_category = "BASE"
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
- redirect_to Kaui.bundle_home_path.call(@bundle.bundle_id)
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
- Kaui::KillbillHelper::delete_subscription(subscription_id, params[:policy], params[:ctd], params[:billing_period], current_user, params[:reason], params[:comment], options_for_klient)
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
- def self.update_subscription(subscription, requested_date = nil, policy = nil, current_user = nil, reason = nil, comment = nil, options = {})
197
- subscription_data = Kaui::Subscription.camelize(subscription.to_hash)
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
- # We don't want to pass events
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.reinstate_subscription(subscription_id, current_user = nil, reason = nil, comment = nil, options = {})
212
- call_killbill :put,
213
- "/1.0/kb/entitlements/#{subscription_id}/uncancel",
214
- "",
215
- build_audit_headers(current_user, reason, comment, options)
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, policy = nil, ctd = nil, billing_period = nil, current_user = nil, reason = nil, comment = nil, options = {})
219
- prev_ctd = compute_previous_ctd(ctd, billing_period)
220
- params = "?"
221
- params += "policy=#{policy}&" unless policy.blank?
222
- params += "requestedDate=#{prev_ctd.strftime('%Y-%m-%dT%H:%M:%S')}" unless prev_ctd.nil?
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
- <h1>Add subscription <% if @bundle.external_key %> to <%= Kaui.bundle_key_display_string.call(@bundle.external_key) %> <% end %></h1>
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 => { :action => :create }, :html => { :class => "form-horizontal" }) do |f| %>
5
- <fieldset>
6
- <%= f.hidden_field :bundle_id %>
7
- <%= hidden_field_tag :base_subscription, @base_subscription %>
8
- <div class="control-group">
9
- <%= label_tag :plan_name, "Available Plans:", :class => "control-label" %>
10
- <div class="controls">
11
- <%= select_tag :plan_name, options_for_select(@catalog.keys, @plan_name) %>
12
- <p class="help-block">
13
- Proration on customer's invoice will be done automatically.
14
- </p>
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
- </div>
17
- <div class="form-actions">
18
- <%= f.submit 'Add', :class => 'btn btn-primary' %>
19
- <%= link_to 'Back', :back, :class => 'btn' %>
20
- </div>
21
- </fieldset>
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.1'
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
@@ -1,3 +1,3 @@
1
1
  module Kaui
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
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.1
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-23 00:00:00.000000000 Z
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.1
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.1
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: 730929266616147309
438
+ hash: -1588433820236604683
439
439
  requirements: []
440
440
  rubyforge_project:
441
441
  rubygems_version: 1.8.25