kaui 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/kaui/account_timelines_controller.rb +37 -42
- data/app/controllers/kaui/accounts_controller.rb +11 -5
- data/app/controllers/kaui/bundles_controller.rb +20 -14
- data/app/controllers/kaui/credits_controller.rb +4 -2
- data/app/controllers/kaui/payment_methods_controller.rb +7 -3
- data/app/controllers/kaui/refunds_controller.rb +17 -8
- data/app/controllers/kaui/subscriptions_controller.rb +1 -2
- data/app/helpers/kaui/killbill_helper.rb +47 -96
- data/app/views/kaui/accounts/show.html.erb +4 -4
- data/app/views/kaui/payment_methods/_payment_methods_table.html.erb +3 -1
- data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +7 -3
- data/lib/kaui/version.rb +1 -1
- data/test/dummy/config/database.yml +1 -1
- data/test/dummy/log/development.log +627 -0
- data/test/dummy/log/test.log +9612 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/test_helper.rb +10 -0
- metadata +2 -2
@@ -7,58 +7,53 @@ class Kaui::AccountTimelinesController < Kaui::EngineController
|
|
7
7
|
|
8
8
|
def show
|
9
9
|
@account_id = params[:id]
|
10
|
-
|
10
|
+
unless @account_id.present?
|
11
|
+
flash[:notice] = "No id given"
|
12
|
+
redirect_to :back
|
13
|
+
return
|
14
|
+
end
|
15
|
+
begin
|
11
16
|
@account = Kaui::KillbillHelper::get_account(@account_id)
|
17
|
+
@timeline = Kaui::KillbillHelper::get_account_timeline(@account_id)
|
18
|
+
rescue => e
|
19
|
+
flash[:error] = "Could not load the account timeline for #{@account_id}: #{e.message} #{e.response}"
|
20
|
+
redirect_to :action => :index
|
21
|
+
return
|
22
|
+
end
|
12
23
|
|
13
|
-
|
14
|
-
|
24
|
+
@invoices_by_id = {}
|
25
|
+
@bundle_names = {}
|
26
|
+
unless @timeline.nil?
|
27
|
+
@timeline.payments.each do |payment|
|
28
|
+
if payment.invoice_id.present? && payment.payment_id.present?
|
15
29
|
|
16
|
-
|
17
|
-
@bundle_names = {}
|
18
|
-
unless @timeline.nil?
|
19
|
-
@timeline.payments.each do |payment|
|
20
|
-
if payment.invoice_id.present? &&
|
21
|
-
payment.payment_id.present? &&
|
22
|
-
# !@payment_attempts_by_payment_id.has_key?(payment.payment_id)
|
30
|
+
@invoices_by_id[payment.invoice_id] = Kaui::KillbillHelper::get_invoice(payment.invoice_id)
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# payment.payment_id)
|
28
|
-
# @payment_attempts_by_payment_id[payment.payment_id] = payment_attempt
|
29
|
-
payment.bundle_keys.split(",").each do |bundle_key|
|
30
|
-
unless @bundle_names.has_key?(bundle_key)
|
31
|
-
@bundle_names[bundle_key] = Kaui.bundle_key_display_string.call(bundle_key)
|
32
|
-
end
|
33
|
-
end
|
32
|
+
payment.bundle_keys.split(",").each do |bundle_key|
|
33
|
+
unless @bundle_names.has_key?(bundle_key)
|
34
|
+
@bundle_names[bundle_key] = Kaui.bundle_key_display_string.call(bundle_key)
|
34
35
|
end
|
35
36
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
@timeline.bundles.each do |bundle|
|
47
|
-
unless @bundle_names.has_key?(bundle.external_key)
|
48
|
-
@bundle_names[bundle.external_key] = Kaui.bundle_key_display_string.call(bundle.external_key)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
@timeline.invoices.each do |invoice|
|
40
|
+
if invoice.invoice_id.present? && !@invoices_by_id.has_key?(invoice.invoice_id)
|
41
|
+
@invoices_by_id[invoice.invoice_id] = Kaui::KillbillHelper::get_invoice(invoice.invoice_id)
|
42
|
+
invoice.bundle_keys.split(",").each do |bundle_key|
|
43
|
+
unless @bundle_names.has_key?(bundle_key)
|
44
|
+
@bundle_names[bundle_key] = Kaui.bundle_key_display_string.call(bundle_key)
|
49
45
|
end
|
50
46
|
end
|
51
|
-
if params.has_key?(:external_key)
|
52
|
-
@selected_bundle = @bundle_names[params[:external_key]]
|
53
|
-
end
|
54
47
|
end
|
55
|
-
else
|
56
|
-
flash[:error] = "Account #{@account_id} not found"
|
57
|
-
redirect_to :action => :index
|
58
48
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
49
|
+
@timeline.bundles.each do |bundle|
|
50
|
+
unless @bundle_names.has_key?(bundle.external_key)
|
51
|
+
@bundle_names[bundle.external_key] = Kaui.bundle_key_display_string.call(bundle.external_key)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
if params.has_key?(:external_key)
|
55
|
+
@selected_bundle = @bundle_names[params[:external_key]]
|
56
|
+
end
|
62
57
|
end
|
63
58
|
end
|
64
59
|
end
|
@@ -11,11 +11,17 @@ class Kaui::AccountsController < Kaui::EngineController
|
|
11
11
|
def show
|
12
12
|
key = params[:id]
|
13
13
|
if key.present?
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@account = Kaui::KillbillHelper::
|
14
|
+
# Remove extra whitespaces
|
15
|
+
key.strip!
|
16
|
+
|
17
|
+
begin
|
18
|
+
@account = Kaui::KillbillHelper::get_account_by_key(key, true)
|
19
|
+
rescue URI::InvalidURIError => e
|
20
|
+
flash[:error] = "Error while retrieving the account for #{key}: #{e.message}"
|
21
|
+
render :action => :index and return
|
22
|
+
rescue => e
|
23
|
+
flash[:error] = "Error while retrieving the account for #{key}: #{e.message} #{e.response}"
|
24
|
+
render :action => :index and return
|
19
25
|
end
|
20
26
|
|
21
27
|
if @account.present? and @account.is_a? Kaui::Account
|
@@ -42,31 +42,37 @@ class Kaui::BundlesController < Kaui::EngineController
|
|
42
42
|
bundle_id = params[:id]
|
43
43
|
key = params[:new_account_key]
|
44
44
|
if key.present?
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
begin
|
46
|
+
result = Kaui::KillbillHelper.get_account_by_key(key, false)
|
47
|
+
rescue => e
|
48
|
+
flash[:error] = "Error while retrieving account for #{key}: #{e.message} #{e.response}"
|
49
|
+
render :action => :index
|
50
|
+
return
|
50
51
|
end
|
51
52
|
if bundle_id.present? && result.is_a?(Kaui::Account)
|
52
53
|
@new_account = result
|
53
|
-
|
54
|
-
|
54
|
+
begin
|
55
|
+
Kaui::KillbillHelper::transfer_bundle(bundle_id, @new_account.account_id)
|
55
56
|
flash[:info] = "Bundle transfered successfully"
|
56
|
-
|
57
|
-
|
58
|
-
else
|
59
|
-
flash[:error] = "Error transfering bundle"
|
57
|
+
rescue => e
|
58
|
+
flash[:error] = "Error transfering bundle #{e.message} #{e.response}"
|
60
59
|
end
|
60
|
+
redirect_to Kaui.account_home_path.call(@new_account.external_key)
|
61
|
+
return
|
61
62
|
else
|
62
63
|
flash[:error] = "Could not retrieve account #{result}"
|
63
64
|
end
|
64
65
|
else
|
65
66
|
flash[:error] = "No account key given"
|
66
67
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
|
69
|
+
begin
|
70
|
+
@bundle = Kaui::KillbillHelper::get_bundle(bundle_id)
|
71
|
+
@account = Kaui::KillbillHelper::get_account_by_bundle_id(bundle_id)
|
72
|
+
rescue => e
|
73
|
+
flash[:error] = "Error while redirecting: #{e.message} #{e.response}"
|
74
|
+
render :transfer
|
75
|
+
end
|
70
76
|
end
|
71
77
|
|
72
78
|
end
|
@@ -21,8 +21,9 @@ class Kaui::CreditsController < Kaui::EngineController
|
|
21
21
|
@invoice_id = params[:invoice_id]
|
22
22
|
@account = Kaui::KillbillHelper::get_account(@account_id)
|
23
23
|
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id) unless @invoice_id.nil?
|
24
|
+
credit_amount = @invoice.balance unless @invoice.nil?
|
24
25
|
|
25
|
-
@credit = Kaui::Credit.new("accountId" => @account_id, "invoiceId" => @invoice_id, "creditAmount" =>
|
26
|
+
@credit = Kaui::Credit.new("accountId" => @account_id, "invoiceId" => @invoice_id, "creditAmount" => credit_amount)
|
26
27
|
end
|
27
28
|
|
28
29
|
def create
|
@@ -33,6 +34,7 @@ class Kaui::CreditsController < Kaui::EngineController
|
|
33
34
|
else
|
34
35
|
flash[:error] = "Error while creating credit"
|
35
36
|
end
|
36
|
-
|
37
|
+
account = Kaui::KillbillHelper::get_account(credit.account_id)
|
38
|
+
redirect_to kaui_engine.account_home_path.call(account.external_key)
|
37
39
|
end
|
38
40
|
end
|
@@ -6,9 +6,13 @@ class Kaui::PaymentMethodsController < Kaui::EngineController
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def destroy
|
9
|
-
|
10
|
-
if
|
11
|
-
|
9
|
+
payment_method_id = params[:id]
|
10
|
+
if payment_method_id.present?
|
11
|
+
begin
|
12
|
+
Kaui::KillbillHelper.delete_payment_method(payment_method_id, params[:set_auto_pay_off])
|
13
|
+
rescue => e
|
14
|
+
flash[:error] = "Error while deleting payment method #{payment_method_id}: #{e.message} #{e.response}"
|
15
|
+
end
|
12
16
|
else
|
13
17
|
flash[:notice] = "Did not get the payment method id"
|
14
18
|
end
|
@@ -7,13 +7,22 @@ class Kaui::RefundsController < Kaui::EngineController
|
|
7
7
|
|
8
8
|
def show
|
9
9
|
if params[:id].present?
|
10
|
-
|
10
|
+
begin
|
11
|
+
data = Kaui::KillbillHelper::get_refund(params[:id])
|
12
|
+
rescue => e
|
13
|
+
flash[:error] = "Error while retrieving the refund with id #{params[:id]}: #{e.message} #{e.response}"
|
14
|
+
end
|
11
15
|
if data.present?
|
12
16
|
@refunds = [data]
|
13
17
|
else
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
begin
|
19
|
+
@refunds = Kaui::KillbillHelper::get_refunds_for_payment(params[:id])
|
20
|
+
unless @refunds.present?
|
21
|
+
flash[:error] = "Refund for id or payment id #{params[:id]} couldn't be found"
|
22
|
+
render :action => :index
|
23
|
+
end
|
24
|
+
rescue => e
|
25
|
+
flash[:error] = "Error while retrieving the refunds for the payment: #{e.message} #{e.response}"
|
17
26
|
render :action => :index
|
18
27
|
end
|
19
28
|
end
|
@@ -43,11 +52,11 @@ class Kaui::RefundsController < Kaui::EngineController
|
|
43
52
|
refund = Kaui::Refund.new(params[:refund])
|
44
53
|
refund.adjusted = (refund.adjusted == "1")
|
45
54
|
if refund.present?
|
46
|
-
|
47
|
-
|
55
|
+
begin
|
56
|
+
Kaui::KillbillHelper::create_refund(params[:payment_id], refund, current_user, params[:reason], params[:comment])
|
48
57
|
flash[:info] = "Refund created"
|
49
|
-
|
50
|
-
flash[:error] = "Error while processing refund"
|
58
|
+
rescue => e
|
59
|
+
flash[:error] = "Error while processing refund: #{e.message} #{e.response}"
|
51
60
|
end
|
52
61
|
else
|
53
62
|
flash[:error] = "No refund to process"
|
@@ -105,9 +105,8 @@ class Kaui::SubscriptionsController < Kaui::EngineController
|
|
105
105
|
subscription.billing_period = plan["billingPeriod"]
|
106
106
|
subscription.product_category = plan["productCategory"]
|
107
107
|
subscription.product_name = plan["productName"]
|
108
|
-
subscription.price_list =
|
108
|
+
subscription.price_list = plan["priceListName"]
|
109
109
|
subscription.subscription_id = params[:subscription][:subscription_id]
|
110
|
-
# TODO: need to use entered start_date (or current date if none entered)
|
111
110
|
|
112
111
|
Kaui::KillbillHelper::update_subscription(subscription, requested_date, current_user)
|
113
112
|
redirect_to kaui_engine.bundle_home_path.call(bundle.bundle_id)
|
@@ -6,17 +6,21 @@ module Kaui
|
|
6
6
|
def self.call_killbill(method, uri, *args)
|
7
7
|
url = Kaui.killbill_finder.call + uri
|
8
8
|
Rails.logger.info "Performing #{method} request to #{url}"
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
if response.
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
begin
|
10
|
+
response = RestClient.send(method.to_sym, url, *args)
|
11
|
+
data = { :code => response.code }
|
12
|
+
if response.code < 300 && response.body.present?
|
13
|
+
if response.headers[:content_type] =~ /application\/json.*/
|
14
|
+
data[:json] = JSON.parse(response.body)
|
15
|
+
else
|
16
|
+
data[:body] = response.body
|
17
|
+
end
|
16
18
|
end
|
19
|
+
data
|
20
|
+
rescue => e
|
21
|
+
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
22
|
+
raise e
|
17
23
|
end
|
18
|
-
# TODO: error handling
|
19
|
-
data
|
20
24
|
end
|
21
25
|
|
22
26
|
def self.process_response(response, arity, &block)
|
@@ -35,32 +39,28 @@ module Kaui
|
|
35
39
|
|
36
40
|
############## ACCOUNT ##############
|
37
41
|
|
38
|
-
def self.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
def self.get_account_by_key(key, with_balance)
|
43
|
+
# support id (UUID) and external key search
|
44
|
+
if key =~ /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/
|
45
|
+
Kaui::KillbillHelper.get_account(key, with_balance)
|
46
|
+
else
|
47
|
+
Kaui::KillbillHelper.get_account_by_external_key(key, with_balance)
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
51
|
+
def self.get_account_timeline(account_id)
|
52
|
+
data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/timeline?audit=MINIMAL"
|
53
|
+
process_response(data, :single) {|json| Kaui::AccountTimeline.new(json) }
|
54
|
+
end
|
55
|
+
|
47
56
|
def self.get_account(account_id, with_balance=false)
|
48
|
-
|
49
|
-
|
50
|
-
process_response(data, :single) {|json| Kaui::Account.new(json) }
|
51
|
-
rescue => e
|
52
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
53
|
-
end
|
57
|
+
data = call_killbill :get, "/1.0/kb/accounts/#{account_id}?accountWithBalance=#{with_balance}"
|
58
|
+
process_response(data, :single) {|json| Kaui::Account.new(json) }
|
54
59
|
end
|
55
60
|
|
56
61
|
def self.get_account_by_external_key(external_key, with_balance=false)
|
57
|
-
|
58
|
-
|
59
|
-
process_response(data, :single) {|json| Kaui::Account.new(json) }
|
60
|
-
rescue => e
|
61
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
62
|
-
"#{e.message} #{e.response}"
|
63
|
-
end
|
62
|
+
data = call_killbill :get, "/1.0/kb/accounts?externalKey=#{external_key}&accountWithBalance=#{with_balance}"
|
63
|
+
process_response(data, :single) {|json| Kaui::Account.new(json) }
|
64
64
|
end
|
65
65
|
|
66
66
|
def self.get_account_by_bundle_id(bundle_id)
|
@@ -68,7 +68,6 @@ module Kaui
|
|
68
68
|
bundle = get_bundle(bundle_id)
|
69
69
|
account = get_account(bundle.account_id)
|
70
70
|
rescue => e
|
71
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
@@ -135,7 +134,6 @@ module Kaui
|
|
135
134
|
rescue RestClient::BadRequest
|
136
135
|
[]
|
137
136
|
rescue => e
|
138
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
139
137
|
end
|
140
138
|
end
|
141
139
|
|
@@ -144,7 +142,6 @@ module Kaui
|
|
144
142
|
data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/bundles?externalKey=#{external_key}"
|
145
143
|
process_response(data, :single) {|json| Kaui::Bundle.new(json) }
|
146
144
|
rescue => e
|
147
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
148
145
|
end
|
149
146
|
end
|
150
147
|
|
@@ -153,7 +150,6 @@ module Kaui
|
|
153
150
|
data = call_killbill :get, "/1.0/kb/bundles/#{bundle_id}"
|
154
151
|
process_response(data, :single) {|json| Kaui::Bundle.new(json) }
|
155
152
|
rescue => e
|
156
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
157
153
|
end
|
158
154
|
end
|
159
155
|
|
@@ -169,7 +165,6 @@ module Kaui
|
|
169
165
|
return data[:code] < 300
|
170
166
|
|
171
167
|
rescue => e
|
172
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
173
168
|
end
|
174
169
|
end
|
175
170
|
|
@@ -182,7 +177,6 @@ module Kaui
|
|
182
177
|
rescue RestClient::BadRequest
|
183
178
|
[]
|
184
179
|
rescue => e
|
185
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
186
180
|
end
|
187
181
|
end
|
188
182
|
|
@@ -197,7 +191,6 @@ module Kaui
|
|
197
191
|
rescue RestClient::BadRequest
|
198
192
|
[]
|
199
193
|
rescue => e
|
200
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
201
194
|
end
|
202
195
|
end
|
203
196
|
|
@@ -206,7 +199,6 @@ module Kaui
|
|
206
199
|
data = call_killbill :get, "/1.0/kb/subscriptions/#{subscription_id}"
|
207
200
|
process_response(data, :single) {|json| Kaui::Subscription.new(json) }
|
208
201
|
rescue => e
|
209
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
210
202
|
end
|
211
203
|
end
|
212
204
|
|
@@ -224,7 +216,6 @@ module Kaui
|
|
224
216
|
"X-Killbill-Comment" => "#{comment}"
|
225
217
|
return data[:code] == 201
|
226
218
|
rescue => e
|
227
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
228
219
|
end
|
229
220
|
end
|
230
221
|
|
@@ -242,7 +233,6 @@ module Kaui
|
|
242
233
|
"X-Killbill-Comment" => "#{comment}"
|
243
234
|
return data[:code] < 300
|
244
235
|
rescue => e
|
245
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
246
236
|
end
|
247
237
|
end
|
248
238
|
|
@@ -257,7 +247,6 @@ module Kaui
|
|
257
247
|
"X-Killbill-Comment" => "#{comment}"
|
258
248
|
return data[:code] < 300
|
259
249
|
rescue => e
|
260
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
261
250
|
end
|
262
251
|
end
|
263
252
|
|
@@ -270,7 +259,6 @@ module Kaui
|
|
270
259
|
"X-Killbill-Comment" => "#{comment}"
|
271
260
|
return data[:code] < 300
|
272
261
|
rescue => e
|
273
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
274
262
|
end
|
275
263
|
end
|
276
264
|
|
@@ -281,7 +269,6 @@ module Kaui
|
|
281
269
|
data = call_killbill :get, "/1.0/kb/invoices/#{invoice_id}?withItems=true"
|
282
270
|
process_response(data, :single) {|json| Kaui::Invoice.new(json) }
|
283
271
|
rescue => e
|
284
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
285
272
|
end
|
286
273
|
end
|
287
274
|
|
@@ -302,7 +289,6 @@ module Kaui
|
|
302
289
|
data = call_killbill :get, "/1.0/kb/invoices/#{invoice_id}/html"
|
303
290
|
data[:body] if data.present?
|
304
291
|
rescue => e
|
305
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
306
292
|
end
|
307
293
|
end
|
308
294
|
|
@@ -318,7 +304,6 @@ module Kaui
|
|
318
304
|
"X-Killbill-Comment" => "#{comment}"
|
319
305
|
return data[:code] < 300
|
320
306
|
rescue => e
|
321
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
322
307
|
end
|
323
308
|
end
|
324
309
|
|
@@ -346,7 +331,6 @@ module Kaui
|
|
346
331
|
end
|
347
332
|
return data[:code] < 300
|
348
333
|
rescue => e
|
349
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
350
334
|
end
|
351
335
|
end
|
352
336
|
|
@@ -359,7 +343,6 @@ module Kaui
|
|
359
343
|
data[:json].inject({}) {|catalog_hash, item| catalog_hash.merge!(item["planName"] => item) }
|
360
344
|
end
|
361
345
|
rescue => e
|
362
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
363
346
|
end
|
364
347
|
end
|
365
348
|
|
@@ -370,7 +353,6 @@ module Kaui
|
|
370
353
|
data[:json].inject({}) {|catalog_hash, item| catalog_hash.merge!(item["planName"] => item) }
|
371
354
|
end
|
372
355
|
rescue => e
|
373
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
374
356
|
end
|
375
357
|
end
|
376
358
|
|
@@ -381,7 +363,6 @@ module Kaui
|
|
381
363
|
data = call_killbill :get, "/1.0/kb/payments/#{payment_id}"
|
382
364
|
process_response(data, :single) { |json| Kaui::Payment.new(json) }
|
383
365
|
rescue => e
|
384
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
385
366
|
end
|
386
367
|
end
|
387
368
|
|
@@ -391,7 +372,6 @@ module Kaui
|
|
391
372
|
response_data = process_response(data, :multiple) {|json| Kaui::Payment.new(json) }
|
392
373
|
return response_data
|
393
374
|
rescue => e
|
394
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
395
375
|
[]
|
396
376
|
end
|
397
377
|
end
|
@@ -413,22 +393,18 @@ module Kaui
|
|
413
393
|
return false
|
414
394
|
end
|
415
395
|
rescue => e
|
416
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
417
396
|
end
|
418
397
|
end
|
419
398
|
|
420
399
|
############## PAYMENT METHOD ##############
|
421
400
|
|
422
|
-
def self.delete_payment_method(payment_method_id, current_user = nil, reason = nil, comment = nil)
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
rescue => e
|
430
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
431
|
-
end
|
401
|
+
def self.delete_payment_method(payment_method_id, set_auto_pay_off = false, current_user = nil, reason = nil, comment = nil)
|
402
|
+
set_auto_pay_off_param = "?deleteDefaultPmWithAutoPayOff=true" if set_auto_pay_off
|
403
|
+
call_killbill :delete,
|
404
|
+
"/1.0/kb/paymentMethods/#{payment_method_id}#{set_auto_pay_off_param}",
|
405
|
+
"X-Killbill-CreatedBy" => current_user,
|
406
|
+
"X-Killbill-Reason" => "#{reason}",
|
407
|
+
"X-Killbill-Comment" => "#{comment}"
|
432
408
|
end
|
433
409
|
|
434
410
|
def self.get_payment_methods(account_id)
|
@@ -436,7 +412,6 @@ module Kaui
|
|
436
412
|
data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/paymentMethods?withPluginInfo=true"
|
437
413
|
process_response(data, :multiple) {|json| Kaui::PaymentMethod.new(json) }
|
438
414
|
rescue => e
|
439
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
440
415
|
end
|
441
416
|
end
|
442
417
|
|
@@ -445,7 +420,6 @@ module Kaui
|
|
445
420
|
data = call_killbill :get, "/1.0/kb/paymentMethods/#{payment_method_id}?withPluginInfo=true"
|
446
421
|
process_response(data, :single) {|json| Kaui::PaymentMethod.new(json) }
|
447
422
|
rescue => e
|
448
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
449
423
|
end
|
450
424
|
end
|
451
425
|
|
@@ -459,7 +433,6 @@ module Kaui
|
|
459
433
|
"X-Killbill-Comment" => "#{comment}"
|
460
434
|
return data[:code] < 300
|
461
435
|
rescue => e
|
462
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
463
436
|
end
|
464
437
|
end
|
465
438
|
|
@@ -474,45 +447,31 @@ module Kaui
|
|
474
447
|
"X-Killbill-Comment" => "#{comment}"
|
475
448
|
return data[:code] < 300
|
476
449
|
rescue => e
|
477
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
478
450
|
end
|
479
451
|
end
|
480
452
|
|
481
453
|
############## REFUND ##############
|
482
454
|
|
483
455
|
def self.get_refund(refund_id)
|
484
|
-
|
485
|
-
|
486
|
-
process_response(data, :single) { |json| Kaui::Refund.new(json) }
|
487
|
-
rescue => e
|
488
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
489
|
-
end
|
456
|
+
data = call_killbill :get, "/1.0/kb/refunds/#{refund_id}"
|
457
|
+
process_response(data, :single) { |json| Kaui::Refund.new(json) }
|
490
458
|
end
|
491
459
|
|
492
460
|
def self.get_refunds_for_payment(payment_id)
|
493
|
-
|
494
|
-
|
495
|
-
process_response(data, :multiple) {|json| Kaui::Refund.new(json) }
|
496
|
-
rescue => e
|
497
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
498
|
-
end
|
461
|
+
data = call_killbill :get, "/1.0/kb/payments/#{payment_id}/refunds"
|
462
|
+
process_response(data, :multiple) {|json| Kaui::Refund.new(json) }
|
499
463
|
end
|
500
464
|
|
501
465
|
def self.create_refund(payment_id, refund, current_user = nil, reason = nil, comment = nil)
|
502
|
-
|
503
|
-
refund_data = Kaui::Refund.camelize(refund.to_hash)
|
466
|
+
refund_data = Kaui::Refund.camelize(refund.to_hash)
|
504
467
|
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
return data[:code] < 300
|
513
|
-
rescue => e
|
514
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
515
|
-
end
|
468
|
+
call_killbill :post,
|
469
|
+
"/1.0/kb/payments/#{payment_id}/refunds",
|
470
|
+
ActiveSupport::JSON.encode(refund_data, :root => false),
|
471
|
+
:content_type => "application/json",
|
472
|
+
"X-Killbill-CreatedBy" => current_user,
|
473
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
474
|
+
"X-Killbill-Comment" => "#{comment}"
|
516
475
|
end
|
517
476
|
|
518
477
|
############## CHARGEBACK ##############
|
@@ -522,7 +481,6 @@ module Kaui
|
|
522
481
|
data = call_killbill :get, "/1.0/kb/chargebacks/payments/#{payment_id}"
|
523
482
|
process_response(data, :multiple) {|json| Kaui::Chargeback.new(json) }
|
524
483
|
rescue => e
|
525
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
526
484
|
end
|
527
485
|
end
|
528
486
|
|
@@ -539,7 +497,6 @@ module Kaui
|
|
539
497
|
"X-Killbill-Comment" => "#{comment}"
|
540
498
|
return data[:code] < 300
|
541
499
|
rescue => e
|
542
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
543
500
|
end
|
544
501
|
end
|
545
502
|
|
@@ -557,7 +514,6 @@ module Kaui
|
|
557
514
|
"X-Killbill-Comment" => "#{comment}"
|
558
515
|
return data[:code] < 300
|
559
516
|
rescue => e
|
560
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
561
517
|
end
|
562
518
|
end
|
563
519
|
|
@@ -578,7 +534,6 @@ module Kaui
|
|
578
534
|
data = call_killbill :get, "/1.0/kb/tagDefinitions/#{tag_definition_id}"
|
579
535
|
process_response(data, :single) { |json| Kaui::TagDefinition.new(json) }
|
580
536
|
rescue => e
|
581
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
582
537
|
[]
|
583
538
|
end
|
584
539
|
end
|
@@ -617,7 +572,6 @@ module Kaui
|
|
617
572
|
data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/tags"
|
618
573
|
process_response(data, :multiple) { |json| Kaui::Tag.new(json) }
|
619
574
|
rescue => e
|
620
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
621
575
|
end
|
622
576
|
end
|
623
577
|
|
@@ -626,7 +580,6 @@ module Kaui
|
|
626
580
|
data = call_killbill :get, "/1.0/kb/bundles/#{bundle_id}/tags"
|
627
581
|
return data[:json]
|
628
582
|
rescue => e
|
629
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
630
583
|
end
|
631
584
|
end
|
632
585
|
|
@@ -656,7 +609,6 @@ module Kaui
|
|
656
609
|
"X-Killbill-Comment" => "#{comment}"
|
657
610
|
return data[:code] < 300
|
658
611
|
rescue => e
|
659
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
660
612
|
end
|
661
613
|
end
|
662
614
|
|
@@ -673,7 +625,6 @@ module Kaui
|
|
673
625
|
return data[:code] == 201
|
674
626
|
end
|
675
627
|
rescue => e
|
676
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
677
628
|
end
|
678
629
|
end
|
679
630
|
|