kaui 0.1.7 → 0.1.8
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/app/controllers/kaui/account_tags_controller.rb +38 -27
- data/app/controllers/kaui/account_timelines_controller.rb +10 -4
- data/app/controllers/kaui/accounts_controller.rb +31 -12
- data/app/controllers/kaui/bundle_tags_controller.rb +5 -1
- data/app/controllers/kaui/bundles_controller.rb +6 -3
- data/app/controllers/kaui/chargebacks_controller.rb +21 -12
- data/app/controllers/kaui/charges_controller.rb +15 -13
- data/app/controllers/kaui/credits_controller.rb +19 -9
- data/app/controllers/kaui/invoice_items_controller.rb +9 -5
- data/app/controllers/kaui/invoices_controller.rb +28 -20
- data/app/controllers/kaui/payments_controller.rb +11 -6
- data/app/controllers/kaui/refunds_controller.rb +9 -4
- data/app/controllers/kaui/subscriptions_controller.rb +50 -38
- data/app/helpers/kaui/killbill_helper.rb +202 -332
- data/app/models/kaui/account_email.rb +22 -11
- data/app/views/kaui/chargebacks/new.html.erb +3 -1
- data/app/views/kaui/refunds/new.html.erb +4 -2
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +2 -4
- data/lib/kaui/version.rb +1 -1
- data/test/dummy/log/test.log +997 -113084
- metadata +2 -67
- data/app/controllers/kaui/tags_controller.rb +0 -85
- data/app/views/kaui/account_emails/edit.html.erb +0 -6
- data/app/views/kaui/tags/_form.html.erb +0 -25
- data/app/views/kaui/tags/edit.html.erb +0 -6
- data/app/views/kaui/tags/index.html.erb +0 -25
- data/app/views/kaui/tags/new.html.erb +0 -5
- data/app/views/kaui/tags/show.html.erb +0 -15
- data/test/dummy/log/development.log +0 -60886
- data/test/dummy/test/fixtures/bill_cycle_days.yml +0 -3
- data/test/dummy/tmp/cache/assets/C94/4E0/sprockets%2Fea1476dc10a3348303f74d111f70441a +0 -0
- data/test/dummy/tmp/cache/assets/C95/690/sprockets%2Fc4b083702793f7599f4a3069c50f89a8 +0 -0
- data/test/dummy/tmp/cache/assets/CAA/680/sprockets%2F3824d037523f650518fb22acab75559d +0 -0
- data/test/dummy/tmp/cache/assets/CC2/520/sprockets%2F9637f46d37325381f96d96d94ae0bc50 +0 -0
- data/test/dummy/tmp/cache/assets/CD0/9D0/sprockets%2F5c9508c21501c73fbe00473a09b1f5f4 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CDF/1F0/sprockets%2F76ac5628a0c4d1b976cb622ec4493751 +0 -381
- data/test/dummy/tmp/cache/assets/CEA/300/sprockets%2Fdf2ad5c9d0990441c2bf59883383d652 +0 -0
- data/test/dummy/tmp/cache/assets/CF7/710/sprockets%2F86d43448e1fc383cb6f3d752ef288882 +0 -0
- data/test/dummy/tmp/cache/assets/D17/DD0/sprockets%2F665455ecdc7609b23f4ecb366d86055a +0 -9409
- data/test/dummy/tmp/cache/assets/D32/200/sprockets%2Ffa467106e01bda5d6246baea72159d64 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D39/5E0/sprockets%2F59fd338be48a81a17a2a785cbd1612b4 +0 -0
- data/test/dummy/tmp/cache/assets/D44/170/sprockets%2Fac15571bce3f926a498da7cd09322d97 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D6C/710/sprockets%2F1765773caead06c0a6a19ea9de2453f7 +0 -0
- data/test/dummy/tmp/cache/assets/D76/910/sprockets%2Ff99b4bdc434e11e8634e6af62fe805e0 +0 -0
- data/test/dummy/tmp/cache/assets/D9F/160/sprockets%2F510462e1ebd5dbb7ae20888b77f9bed2 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E07/1E0/sprockets%2F5a3fe6e98fdf72bbe75c605e54ebc5b0 +0 -9409
- data/test/dummy/tmp/cache/assets/E20/230/sprockets%2F7d3b1348fdf74cf1b6ba2107fbbac5af +0 -0
- data/test/dummy/tmp/cache/assets/E22/F40/sprockets%2Faffacf2e6be325520bd3bfd2096b6dd4 +0 -0
- data/test/dummy/tmp/cache/assets/E24/9D0/sprockets%2Fb966ab0a50fda3c156fbad4d8ab73ef6 +0 -381
- data/test/functional/kaui/account_emails_controller_test.rb +0 -51
- data/test/functional/kaui/tags_controller_test.rb +0 -51
|
@@ -4,7 +4,11 @@ class Kaui::AccountTagsController < Kaui::EngineController
|
|
|
4
4
|
account_id = params[:id]
|
|
5
5
|
|
|
6
6
|
if account_id.present?
|
|
7
|
-
|
|
7
|
+
begin
|
|
8
|
+
tags = Kaui::KillbillHelper::get_tags_for_account(account_id)
|
|
9
|
+
rescue => e
|
|
10
|
+
flash[:error] = "Error while getting tags: #{e.message} #{e.response}"
|
|
11
|
+
end
|
|
8
12
|
else
|
|
9
13
|
flash[:error] = "No account id given"
|
|
10
14
|
end
|
|
@@ -12,36 +16,43 @@ class Kaui::AccountTagsController < Kaui::EngineController
|
|
|
12
16
|
|
|
13
17
|
def edit
|
|
14
18
|
@account_id = params[:account_id]
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
begin
|
|
20
|
+
@available_tags = Kaui::KillbillHelper::get_tag_definitions.sort
|
|
21
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
22
|
+
@tag_names = Kaui::KillbillHelper::get_tags_for_account(@account.account_id).map { |tag| tag.tag_definition_name }
|
|
23
|
+
rescue => e
|
|
24
|
+
flash[:error] = "Error while editing tags: #{e.message} #{e.response}"
|
|
25
|
+
end
|
|
19
26
|
end
|
|
20
27
|
|
|
21
28
|
def update
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
tags_to_remove
|
|
29
|
+
begin
|
|
30
|
+
current_tags = Kaui::KillbillHelper::get_tags_for_account(params[:account_id]).map { |tag| tag.tag_definition_id }
|
|
31
|
+
|
|
32
|
+
new_tags = []
|
|
33
|
+
params.each do |tag, tag_name|
|
|
34
|
+
tag_info = tag.split('_')
|
|
35
|
+
next if tag_info.size != 2 or tag_info[0] != 'tag'
|
|
36
|
+
new_tags << tag_info[1]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Find tags to remove
|
|
40
|
+
tags_to_remove = []
|
|
41
|
+
current_tags.each do |current_tag_definition_id|
|
|
42
|
+
tags_to_remove << current_tag_definition_id unless new_tags.include?(current_tag_definition_id)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Find tags to add
|
|
46
|
+
tags_to_add = []
|
|
47
|
+
new_tags.each do |new_tag_definition_id|
|
|
48
|
+
tags_to_add << new_tag_definition_id unless current_tags.include?(new_tag_definition_id)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
Kaui::KillbillHelper::remove_tags_for_account(params[:account_id], tags_to_remove)
|
|
52
|
+
Kaui::KillbillHelper::add_tags_for_account(params[:account_id], tags_to_add)
|
|
53
|
+
rescue => e
|
|
54
|
+
flash[:error] = "Error while updating tags: #{e.message} #{e.response}"
|
|
34
55
|
end
|
|
35
|
-
|
|
36
|
-
# Find tags to add
|
|
37
|
-
tags_to_add = []
|
|
38
|
-
new_tags.each do |new_tag_definition_id|
|
|
39
|
-
tags_to_add << new_tag_definition_id unless current_tags.include?(new_tag_definition_id)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
Kaui::KillbillHelper::remove_tags_for_account(params[:account_id], tags_to_remove)
|
|
43
|
-
Kaui::KillbillHelper::add_tags_for_account(params[:account_id], tags_to_add)
|
|
44
|
-
|
|
45
56
|
redirect_to kaui_engine.account_path(params[:account_id])
|
|
46
57
|
end
|
|
47
58
|
|
|
@@ -26,9 +26,11 @@ class Kaui::AccountTimelinesController < Kaui::EngineController
|
|
|
26
26
|
unless @timeline.nil?
|
|
27
27
|
@timeline.payments.each do |payment|
|
|
28
28
|
if payment.invoice_id.present? && payment.payment_id.present?
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
begin
|
|
30
|
+
@invoices_by_id[payment.invoice_id] = Kaui::KillbillHelper::get_invoice(payment.invoice_id)
|
|
31
|
+
rescue => e
|
|
32
|
+
flash[:error] = "Could not get invoice information for the timeline #{@account_id}: #{e.message} #{e.response}"
|
|
33
|
+
end
|
|
32
34
|
payment.bundle_keys.split(",").each do |bundle_key|
|
|
33
35
|
unless @bundle_names.has_key?(bundle_key)
|
|
34
36
|
@bundle_names[bundle_key] = Kaui.bundle_key_display_string.call(bundle_key)
|
|
@@ -38,7 +40,11 @@ class Kaui::AccountTimelinesController < Kaui::EngineController
|
|
|
38
40
|
end
|
|
39
41
|
@timeline.invoices.each do |invoice|
|
|
40
42
|
if invoice.invoice_id.present? && !@invoices_by_id.has_key?(invoice.invoice_id)
|
|
41
|
-
|
|
43
|
+
begin
|
|
44
|
+
@invoices_by_id[invoice.invoice_id] = Kaui::KillbillHelper::get_invoice(invoice.invoice_id)
|
|
45
|
+
rescue => e
|
|
46
|
+
flash[:error] = "Could not get invoice information for the timeline #{@account_id}: #{e.message} #{e.response}"
|
|
47
|
+
end
|
|
42
48
|
invoice.bundle_keys.split(",").each do |bundle_key|
|
|
43
49
|
unless @bundle_names.has_key?(bundle_key)
|
|
44
50
|
@bundle_names[bundle_key] = Kaui.bundle_key_display_string.call(bundle_key)
|
|
@@ -53,7 +53,11 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
|
53
53
|
def payment_methods
|
|
54
54
|
@account_id = params[:id]
|
|
55
55
|
if @account_id.present?
|
|
56
|
-
|
|
56
|
+
begin
|
|
57
|
+
@payment_methods = Kaui::KillbillHelper::get_payment_methods(@account_id)
|
|
58
|
+
rescue => e
|
|
59
|
+
flash[:error] = "Error while getting payment methods: #{e.message} #{e.response}"
|
|
60
|
+
end
|
|
57
61
|
unless @payment_methods.is_a?(Array)
|
|
58
62
|
flash[:notice] = "No payment methods for account_id '#{@account_id}'"
|
|
59
63
|
redirect_to :action => :index
|
|
@@ -66,7 +70,11 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
|
66
70
|
|
|
67
71
|
def add_payment_method
|
|
68
72
|
account_id = params[:id]
|
|
69
|
-
|
|
73
|
+
begin
|
|
74
|
+
@account = Kaui::KillbillHelper::get_account(account_id)
|
|
75
|
+
rescue => e
|
|
76
|
+
flash[:error] = "Error while adding payment methods: #{e.message} #{e.response}"
|
|
77
|
+
end
|
|
70
78
|
if @account.nil?
|
|
71
79
|
flash[:error] = "Account not found for id #{account_id}"
|
|
72
80
|
redirect_to :back
|
|
@@ -77,7 +85,11 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
|
77
85
|
|
|
78
86
|
def do_add_payment_method
|
|
79
87
|
account_id = params[:id]
|
|
80
|
-
|
|
88
|
+
begin
|
|
89
|
+
@account = Kaui::KillbillHelper::get_account(account_id)
|
|
90
|
+
rescue => e
|
|
91
|
+
flash[:error] = "Error while adding payment method: #{e.message} #{e.response}"
|
|
92
|
+
end
|
|
81
93
|
|
|
82
94
|
# Implementation example using standard credit card fields
|
|
83
95
|
@card_type = params[:card_type]
|
|
@@ -114,14 +126,13 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
|
114
126
|
'pluginName' => Kaui.creditcard_plugin_name.call,
|
|
115
127
|
'pluginInfo' => plugin_info)
|
|
116
128
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if success
|
|
129
|
+
begin
|
|
130
|
+
Kaui::KillbillHelper::add_payment_method(payment_method, current_user, @reason, @comment)
|
|
120
131
|
flash[:info] = "Payment method created"
|
|
121
132
|
redirect_to kaui_engine.account_timeline_path(@account.account_id)
|
|
122
133
|
return
|
|
123
|
-
|
|
124
|
-
flash[:error] = "Error while adding payment method"
|
|
134
|
+
rescue => e
|
|
135
|
+
flash[:error] = "Error while adding payment method #{invoice_id}: #{e.message} #{e.response}"
|
|
125
136
|
end
|
|
126
137
|
end
|
|
127
138
|
render "kaui/payment_methods/new"
|
|
@@ -131,7 +142,11 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
|
131
142
|
@account_id = params[:id]
|
|
132
143
|
@payment_method_id = params[:payment_method_id]
|
|
133
144
|
if @account_id.present? && @payment_method_id.present?
|
|
134
|
-
|
|
145
|
+
begin
|
|
146
|
+
@payment_methods = Kaui::KillbillHelper::set_payment_method_as_default(@account_id, @payment_method_id)
|
|
147
|
+
rescue => e
|
|
148
|
+
flash[:error] = "Error while setting payment method as default #{invoice_id}: #{e.message} #{e.response}"
|
|
149
|
+
end
|
|
135
150
|
else
|
|
136
151
|
flash[:notice] = "No account_id or payment_method_id given"
|
|
137
152
|
end
|
|
@@ -139,8 +154,12 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
|
139
154
|
end
|
|
140
155
|
|
|
141
156
|
def toggle_email_notifications
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
begin
|
|
158
|
+
@account = Kaui::KillbillHelper::update_email_notifications(params[:id], params[:is_notified])
|
|
159
|
+
flash[:notice] = "Email preferences updated"
|
|
160
|
+
redirect_to :back
|
|
161
|
+
rescue => e
|
|
162
|
+
flash[:error] = "Error while switching email notifications #{invoice_id}: #{e.message} #{e.response}"
|
|
163
|
+
end
|
|
145
164
|
end
|
|
146
165
|
end
|
|
@@ -3,7 +3,11 @@ class Kaui::BundleTagsController < Kaui::EngineController
|
|
|
3
3
|
def show
|
|
4
4
|
bundle_id = params[:id]
|
|
5
5
|
if bundle_id.present?
|
|
6
|
-
|
|
6
|
+
begin
|
|
7
|
+
tags = Kaui::KillbillHelper::get_tags_for_bundle(bundle_id)
|
|
8
|
+
rescue => e
|
|
9
|
+
flash[:error] = "Error while retrieving tags information: #{e.message} #{e.response}"
|
|
10
|
+
end
|
|
7
11
|
else
|
|
8
12
|
flash[:error] = "No account id given"
|
|
9
13
|
end
|
|
@@ -29,9 +29,12 @@ class Kaui::BundlesController < Kaui::EngineController
|
|
|
29
29
|
|
|
30
30
|
def transfer
|
|
31
31
|
bundle_id = params[:id]
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
begin
|
|
33
|
+
@bundle = Kaui::KillbillHelper::get_bundle(bundle_id)
|
|
34
|
+
@account = Kaui::KillbillHelper::get_account_by_bundle_id(bundle_id)
|
|
35
|
+
rescue => e
|
|
36
|
+
flash[:error] = "Error while preparing to transfer bundle: #{e.message} #{e.response}"
|
|
37
|
+
end
|
|
35
38
|
if @account.nil?
|
|
36
39
|
flash[:error] = "Account not found for bundle id #{bundle_id}"
|
|
37
40
|
end
|
|
@@ -3,7 +3,11 @@ class Kaui::ChargebacksController < Kaui::EngineController
|
|
|
3
3
|
def show
|
|
4
4
|
@payment_id = params[:id]
|
|
5
5
|
if @payment_id.present?
|
|
6
|
-
|
|
6
|
+
begin
|
|
7
|
+
data = Kaui::KillbillHelper::get_chargebacks_for_payment(@payment_id)
|
|
8
|
+
rescue => e
|
|
9
|
+
flash[:error] = "Error while getting chargeback information: #{e.message} #{e.response}"
|
|
10
|
+
end
|
|
7
11
|
if data.present?
|
|
8
12
|
@chargeback = Kaui::Chargeback.new(data)
|
|
9
13
|
else
|
|
@@ -19,25 +23,30 @@ class Kaui::ChargebacksController < Kaui::EngineController
|
|
|
19
23
|
@account_id = params[:account_id]
|
|
20
24
|
@invoice_id = params[:invoice_id]
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
begin
|
|
27
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
28
|
+
@payment = Kaui::KillbillHelper::get_payment(@payment_id)
|
|
29
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
|
|
30
|
+
@payment_method = Kaui::KillbillHelper::get_payment_method(@payment.payment_method_id)
|
|
31
|
+
rescue => e
|
|
32
|
+
flash[:error] = "Error while starting a new chargeback: #{e.message} #{e.response}"
|
|
33
|
+
redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
|
|
34
|
+
end
|
|
27
35
|
|
|
28
|
-
@chargeback = Kaui::Chargeback.new("
|
|
29
|
-
"
|
|
36
|
+
@chargeback = Kaui::Chargeback.new("paymentId" => @payment_id,
|
|
37
|
+
"chargebackAmount" => @payment.amount)
|
|
30
38
|
end
|
|
31
39
|
|
|
32
40
|
def create
|
|
33
41
|
account_id = params[:account_id]
|
|
34
42
|
chargeback = Kaui::Chargeback.new(params[:chargeback])
|
|
43
|
+
|
|
35
44
|
if chargeback.present?
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
begin
|
|
46
|
+
Kaui::KillbillHelper::create_chargeback(chargeback, params[:reason], params[:comment])
|
|
38
47
|
flash[:info] = "Chargeback created"
|
|
39
|
-
|
|
40
|
-
flash[:error] = "
|
|
48
|
+
rescue => e
|
|
49
|
+
flash[:error] = "Error while creating a new chargeback: #{e.message} #{e.response}"
|
|
41
50
|
end
|
|
42
51
|
else
|
|
43
52
|
flash[:error] = "No chargeback to process"
|
|
@@ -3,30 +3,32 @@ class Kaui::ChargesController < Kaui::EngineController
|
|
|
3
3
|
def new
|
|
4
4
|
@account_id = params[:account_id]
|
|
5
5
|
@invoice_id = params[:invoice_id]
|
|
6
|
+
begin
|
|
7
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
if @invoice_id.present?
|
|
10
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
|
|
11
|
+
@charge = Kaui::Charge.new("accountId" => @account_id, "invoiceId" => @invoice_id)
|
|
12
|
+
else
|
|
13
|
+
@charge = Kaui::Charge.new("accountId" => @account_id)
|
|
14
|
+
end
|
|
15
|
+
rescue => e
|
|
16
|
+
flash[:error] = "Error while creating a charge: #{e.message} #{e.response}"
|
|
14
17
|
end
|
|
15
|
-
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def create
|
|
19
21
|
charge = Kaui::Charge.new(params[:charge])
|
|
20
22
|
|
|
21
23
|
if charge.present?
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
begin
|
|
25
|
+
Kaui::KillbillHelper::create_charge(charge, params[:requested_date], current_user, nil, params[:comment])
|
|
24
26
|
flash[:info] = "Charge created"
|
|
27
|
+
redirect_to kaui_engine.account_timeline_path(:id => charge.account_id)
|
|
28
|
+
rescue => e
|
|
29
|
+
flash[:error] = "Error while creating a charge: #{e.message} #{e.response}"
|
|
25
30
|
end
|
|
26
|
-
else
|
|
27
|
-
flash[:error] = "No charge to process"
|
|
28
31
|
end
|
|
29
|
-
redirect_to kaui_engine.account_timeline_path(:id => charge.account_id)
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
end
|
|
@@ -4,8 +4,12 @@ class Kaui::CreditsController < Kaui::EngineController
|
|
|
4
4
|
@invoice_id = params[:invoice_id]
|
|
5
5
|
|
|
6
6
|
if params.has_key?(:account_id)
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
begin
|
|
8
|
+
# invoice id can be nil for account level credit
|
|
9
|
+
data = Kaui::KillbillHelper::get_credits(@account_id, @invoice_id)
|
|
10
|
+
rescue => e
|
|
11
|
+
flash[:error] = "Error getting credit information: #{e.message} #{e.response}"
|
|
12
|
+
end
|
|
9
13
|
if data.present?
|
|
10
14
|
@credit = Kaui::Credit.new(data)
|
|
11
15
|
else
|
|
@@ -19,8 +23,14 @@ class Kaui::CreditsController < Kaui::EngineController
|
|
|
19
23
|
def new
|
|
20
24
|
@account_id = params[:account_id]
|
|
21
25
|
@invoice_id = params[:invoice_id]
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
|
|
27
|
+
begin
|
|
28
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
29
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id) unless @invoice_id.nil?
|
|
30
|
+
rescue => e
|
|
31
|
+
flash[:error] = "Error while starting to create credit: #{e.message} #{e.response}"
|
|
32
|
+
end
|
|
33
|
+
|
|
24
34
|
credit_amount = @invoice.balance unless @invoice.nil?
|
|
25
35
|
|
|
26
36
|
@credit = Kaui::Credit.new("accountId" => @account_id, "invoiceId" => @invoice_id,
|
|
@@ -29,13 +39,13 @@ class Kaui::CreditsController < Kaui::EngineController
|
|
|
29
39
|
|
|
30
40
|
def create
|
|
31
41
|
credit = Kaui::Credit.new(params[:credit])
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
begin
|
|
43
|
+
Kaui::KillbillHelper::create_credit(credit, current_user, params[:reason], params[:comment])
|
|
44
|
+
account = Kaui::KillbillHelper::get_account(credit.account_id)
|
|
34
45
|
flash[:info] = "Credit created"
|
|
35
|
-
|
|
36
|
-
flash[:error] = "Error while
|
|
46
|
+
rescue => e
|
|
47
|
+
flash[:error] = "Error while starting to create credit: #{e.message} #{e.response}"
|
|
37
48
|
end
|
|
38
|
-
account = Kaui::KillbillHelper::get_account(credit.account_id)
|
|
39
49
|
redirect_to Kaui.account_home_path.call(account.external_key)
|
|
40
50
|
end
|
|
41
51
|
end
|
|
@@ -15,12 +15,12 @@ class Kaui::InvoiceItemsController < Kaui::EngineController
|
|
|
15
15
|
|
|
16
16
|
def update
|
|
17
17
|
@invoice_item = Kaui::InvoiceItem.new(params[:invoice_item])
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
begin
|
|
19
|
+
Kaui::KillbillHelper.adjust_invoice(@invoice_item, current_user, params[:reason], params[:comment])
|
|
20
20
|
flash[:notice] = "Adjustment item created"
|
|
21
21
|
redirect_to kaui_engine.invoice_path(@invoice_item.invoice_id)
|
|
22
|
-
|
|
23
|
-
flash[:error] = "
|
|
22
|
+
rescue => e
|
|
23
|
+
flash[:error] = "Error while updating the invoice item: #{e.message} #{e.response}"
|
|
24
24
|
render :action => "edit"
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -31,7 +31,11 @@ class Kaui::InvoiceItemsController < Kaui::EngineController
|
|
|
31
31
|
invoice_item_id = params[:id]
|
|
32
32
|
invoice_id = params[:invoice_id]
|
|
33
33
|
if invoice_item_id.present? and invoice_id.present?
|
|
34
|
-
|
|
34
|
+
begin
|
|
35
|
+
@invoice_item = Kaui::KillbillHelper.get_invoice_item(invoice_id, invoice_item_id)
|
|
36
|
+
rescue => e
|
|
37
|
+
flash[:error] = "Error while trying to find the invoice item: #{e.message} #{e.response}"
|
|
38
|
+
end
|
|
35
39
|
unless @invoice_item.present?
|
|
36
40
|
flash[:error] = "Invoice for id #{invoice_id} and invoice item id #{invoice_item_id} not found"
|
|
37
41
|
render :action => :index
|
|
@@ -8,28 +8,32 @@ class Kaui::InvoicesController < Kaui::EngineController
|
|
|
8
8
|
def show
|
|
9
9
|
@invoice_id = params[:id]
|
|
10
10
|
if @invoice_id.present?
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
begin
|
|
12
|
+
@invoice = Kaui::KillbillHelper.get_invoice(@invoice_id)
|
|
13
|
+
if @invoice.present?
|
|
14
|
+
@account = Kaui::KillbillHelper.get_account(@invoice.account_id)
|
|
15
|
+
@payments = Kaui::KillbillHelper.get_payments(@invoice_id)
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
@subscriptions = {}
|
|
18
|
+
@bundles = {}
|
|
19
|
+
if @invoice.items.present?
|
|
20
|
+
@invoice.items.each do |item|
|
|
21
|
+
unless item.subscription_id.nil? || @subscriptions.has_key?(item.subscription_id)
|
|
22
|
+
@subscriptions[item.subscription_id] = Kaui::KillbillHelper.get_subscription(item.subscription_id)
|
|
23
|
+
end
|
|
24
|
+
unless item.bundle_id.nil? || @bundles.has_key?(item.bundle_id)
|
|
25
|
+
@bundles[item.bundle_id] = Kaui::KillbillHelper.get_bundle(item.bundle_id)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
else
|
|
29
|
+
flash[:error] = "Invoice items for #{@invoice_id} not found"
|
|
30
|
+
end
|
|
27
31
|
else
|
|
28
|
-
flash[:error] = "Invoice
|
|
32
|
+
flash[:error] = "Invoice #{@invoice_id} not found"
|
|
33
|
+
render :action => :index
|
|
29
34
|
end
|
|
30
|
-
|
|
31
|
-
flash[:error] = "
|
|
32
|
-
render :action => :index
|
|
35
|
+
rescue => e
|
|
36
|
+
flash[:error] = "Error while getting information for invoice #{invoice_id}: #{e.message} #{e.response}"
|
|
33
37
|
end
|
|
34
38
|
else
|
|
35
39
|
flash[:error] = "No id given"
|
|
@@ -37,6 +41,10 @@ class Kaui::InvoicesController < Kaui::EngineController
|
|
|
37
41
|
end
|
|
38
42
|
|
|
39
43
|
def show_html
|
|
40
|
-
|
|
44
|
+
begin
|
|
45
|
+
render :text => Kaui::KillbillHelper.get_invoice_html(params[:id])
|
|
46
|
+
rescue => e
|
|
47
|
+
flash[:error] = "Error rendering invoice html #{invoice_id}: #{e.message} #{e.response}"
|
|
48
|
+
end
|
|
41
49
|
end
|
|
42
50
|
end
|
|
@@ -3,8 +3,13 @@ class Kaui::PaymentsController < Kaui::EngineController
|
|
|
3
3
|
def new
|
|
4
4
|
@account_id = params[:account_id]
|
|
5
5
|
@invoice_id = params[:invoice_id]
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
begin
|
|
7
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
|
|
8
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
9
|
+
rescue => e
|
|
10
|
+
flash[:error] = "Error while creating a new payment: #{e.message} #{e.response}"
|
|
11
|
+
redirect_to kaui_engine.account_timeline_path(:id => payment.account_id)
|
|
12
|
+
end
|
|
8
13
|
|
|
9
14
|
@payment = Kaui::Payment.new("accountId" => @account_id, "invoiceId" => @invoice_id, "amount" => @invoice.balance)
|
|
10
15
|
end
|
|
@@ -13,12 +18,12 @@ class Kaui::PaymentsController < Kaui::EngineController
|
|
|
13
18
|
payment = Kaui::Payment.new(params[:payment])
|
|
14
19
|
if payment.present?
|
|
15
20
|
payment.external = (payment.external == "1")
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
begin
|
|
22
|
+
Kaui::KillbillHelper::create_payment(payment, payment.external, current_user, params[:reason], params[:comment])
|
|
18
23
|
flash[:info] = "Payment created"
|
|
24
|
+
rescue => e
|
|
25
|
+
flash[:error] = "Error while creating a new payment: #{e.message} #{e.response}"
|
|
19
26
|
end
|
|
20
|
-
else
|
|
21
|
-
flash[:error] = "No payment to process"
|
|
22
27
|
end
|
|
23
28
|
redirect_to kaui_engine.account_timeline_path(:id => payment.account_id)
|
|
24
29
|
end
|
|
@@ -39,10 +39,15 @@ class Kaui::RefundsController < Kaui::EngineController
|
|
|
39
39
|
|
|
40
40
|
@refund = Kaui::Refund.new('adjusted' => true)
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
begin
|
|
43
|
+
@account = Kaui::KillbillHelper::get_account(@account_id)
|
|
44
|
+
@payment = Kaui::KillbillHelper::get_payment(@payment_id)
|
|
45
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id)
|
|
46
|
+
@payment_method = Kaui::KillbillHelper::get_payment_method(@payment.payment_method_id)
|
|
47
|
+
rescue => e
|
|
48
|
+
flash[:error] = "Error while processing refund: #{e.message} #{e.response}"
|
|
49
|
+
redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
|
|
50
|
+
end
|
|
46
51
|
end
|
|
47
52
|
|
|
48
53
|
def create
|