kaui 0.1.15 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/kaui/subscriptions_controller.rb +2 -2
- data/app/helpers/kaui/killbill_helper.rb +22 -2
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +2 -1
- data/app/views/kaui/subscriptions/show.html.erb +1 -1
- data/lib/kaui/version.rb +1 -1
- data/test/dummy/log/development.log +5081 -0
- metadata +2 -2
@@ -157,9 +157,9 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
157
157
|
subscription_id = params[:id]
|
158
158
|
if subscription_id.present?
|
159
159
|
begin
|
160
|
-
Kaui::KillbillHelper::delete_subscription(subscription_id, params[:policy], current_user)
|
160
|
+
Kaui::KillbillHelper::delete_subscription(subscription_id, params[:policy], params[:ctd], params[:billing_period], current_user)
|
161
161
|
rescue => e
|
162
|
-
flash[:error] = "Error while
|
162
|
+
flash[:error] = "Error while canceling subscription: #{as_string(e)}"
|
163
163
|
end
|
164
164
|
else
|
165
165
|
flash[:error] = "No subscription id given"
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rest_client'
|
2
|
+
require 'time'
|
2
3
|
|
3
4
|
module Kaui
|
4
5
|
module KillbillHelper
|
@@ -205,8 +206,11 @@ module Kaui
|
|
205
206
|
"X-Killbill-Comment" => "#{comment}"
|
206
207
|
end
|
207
208
|
|
208
|
-
def self.delete_subscription(subscription_id, policy = nil, current_user = nil, reason = nil, comment = nil)
|
209
|
-
|
209
|
+
def self.delete_subscription(subscription_id, policy = nil, ctd = nil, billing_period = nil, current_user = nil, reason = nil, comment = nil)
|
210
|
+
prev_ctd = compute_previous_ctd(ctd, billing_period)
|
211
|
+
params = "?"
|
212
|
+
params += "policy=#{policy}&" unless policy.blank?
|
213
|
+
params += "requestedDate=#{prev_ctd.strftime('%Y-%m-%dT%H:%M:%S')}" unless prev_ctd.nil?
|
210
214
|
call_killbill :delete,
|
211
215
|
"/1.0/kb/subscriptions/#{subscription_id}#{params}",
|
212
216
|
"X-Killbill-CreatedBy" => current_user,
|
@@ -214,6 +218,22 @@ module Kaui
|
|
214
218
|
"X-Killbill-Comment" => "#{comment}"
|
215
219
|
end
|
216
220
|
|
221
|
+
def self.compute_previous_ctd(ctd, billing_period)
|
222
|
+
return nil if ctd.nil? or billing_period.nil?
|
223
|
+
|
224
|
+
ctd = DateTime.parse(ctd)
|
225
|
+
billing_period = billing_period.upcase
|
226
|
+
if billing_period == 'MONTHLY'
|
227
|
+
ctd.prev_month(1)
|
228
|
+
elsif billing_period == 'QUARTERLY'
|
229
|
+
ctd.prev_month(3)
|
230
|
+
elsif billing_period == 'ANNUAL'
|
231
|
+
ctd.prev_month(12)
|
232
|
+
else
|
233
|
+
nil
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
217
237
|
############## INVOICE ##############
|
218
238
|
|
219
239
|
def self.get_invoice(invoice_id)
|
@@ -39,7 +39,8 @@
|
|
39
39
|
</a>
|
40
40
|
<ul class="dropdown-menu">
|
41
41
|
<li><%= link_to "Cancel (default policy)", kaui_engine.subscription_path(:id => sub.subscription_id), :method => :delete %></li>
|
42
|
-
<li><%= link_to "Cancel
|
42
|
+
<li><%= link_to "Cancel at previous CTD (no proration)", kaui_engine.subscription_path(:id => sub.subscription_id, :policy => 'IMMEDIATE', :ctd => sub.charged_through_date, :billing_period => sub.billing_period), :method => :delete %></li>
|
43
|
+
<li><%= link_to "Cancel immediately (generate proration)", kaui_engine.subscription_path(:id => sub.subscription_id, :policy => 'IMMEDIATE'), :method => :delete %></li>
|
43
44
|
<li><%= link_to "Cancel end of term", kaui_engine.subscription_path(:id => sub.subscription_id, :policy => 'END_OF_TERM'), :method => :delete %></li>
|
44
45
|
</ul>
|
45
46
|
</div>
|
data/lib/kaui/version.rb
CHANGED