kaui 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -64,63 +64,43 @@ module Kaui
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def self.get_account_by_bundle_id(bundle_id)
|
67
|
-
|
68
|
-
|
69
|
-
account = get_account(bundle.account_id)
|
70
|
-
rescue => e
|
71
|
-
end
|
67
|
+
bundle = get_bundle(bundle_id)
|
68
|
+
account = get_account(bundle.account_id)
|
72
69
|
end
|
73
70
|
|
74
71
|
def self.get_account_emails(account_id)
|
75
|
-
|
76
|
-
|
77
|
-
process_response(data, :multiple) { |json| Kaui::AccountEmail.new(json) }
|
78
|
-
rescue => e
|
79
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
80
|
-
end
|
72
|
+
data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/emails"
|
73
|
+
process_response(data, :multiple) { |json| Kaui::AccountEmail.new(json) }
|
81
74
|
end
|
82
75
|
|
83
76
|
def self.add_account_email(account_email, current_user = nil, reason = nil, comment = nil)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
"X-Killbill-Comment" => "#{comment}"
|
93
|
-
return data[:code] = 201
|
94
|
-
rescue => e
|
95
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
96
|
-
end
|
77
|
+
account_email_data = Kaui::AccountEmail.camelize(account_email.to_hash)
|
78
|
+
call_killbill :post,
|
79
|
+
"/1.0/kb/accounts/#{account_email.account_id}/emails",
|
80
|
+
ActiveSupport::JSON.encode(account_email_data, :root => false),
|
81
|
+
:content_type => "application/json",
|
82
|
+
"X-Killbill-CreatedBy" => current_user,
|
83
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
84
|
+
"X-Killbill-Comment" => "#{comment}"
|
97
85
|
end
|
98
86
|
|
99
87
|
def self.remove_account_email(account_email, current_user = nil, reason = nil, comment = nil)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
"X-Killbill-Comment" => "#{comment}"
|
106
|
-
return data[:code] < 300
|
107
|
-
rescue => e
|
108
|
-
end
|
88
|
+
call_killbill :delete,
|
89
|
+
"/1.0/kb/accounts/#{account_email.account_id}/emails/#{account_email.email}",
|
90
|
+
"X-Killbill-CreatedBy" => current_user,
|
91
|
+
"X-Killbill-Reason" => "#{reason}",
|
92
|
+
"X-Killbill-Comment" => "#{comment}"
|
109
93
|
end
|
110
94
|
|
111
95
|
def self.update_email_notifications(account_id, is_notified, current_user = nil, reason = nil, comment = nil)
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
"X-Killbill-Comment" => "#{comment}"
|
121
|
-
return data[:code] = 200
|
122
|
-
rescue => e
|
123
|
-
end
|
96
|
+
email_data = { :isNotifiedForInvoices => is_notified }
|
97
|
+
call_killbill :put,
|
98
|
+
"/1.0/kb/accounts/#{account_id}/emailNotifications",
|
99
|
+
ActiveSupport::JSON.encode(email_data, :root => false),
|
100
|
+
:content_type => "application/json",
|
101
|
+
"X-Killbill-CreatedBy" => current_user,
|
102
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
103
|
+
"X-Killbill-Comment" => "#{comment}"
|
124
104
|
end
|
125
105
|
|
126
106
|
############## BUNDLE ##############
|
@@ -150,14 +130,13 @@ module Kaui
|
|
150
130
|
end
|
151
131
|
|
152
132
|
def self.transfer_bundle(bundle_id, new_account_id, cancel_immediately = false, transfer_addons = true, current_user = nil, reason = nil, comment = nil)
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
return data[:code] < 300
|
133
|
+
call_killbill :put,
|
134
|
+
"/1.0/kb/bundles/#{bundle_id}?cancelImmediately=#{cancel_immediately}&transferAddOn=#{transfer_addons}",
|
135
|
+
ActiveSupport::JSON.encode("accountId" => new_account_id),
|
136
|
+
:content_type => :json,
|
137
|
+
"X-Killbill-CreatedBy" => current_user,
|
138
|
+
"X-Killbill-Reason" => "#{reason}",
|
139
|
+
"X-Killbill-Comment" => "#{comment}"
|
161
140
|
end
|
162
141
|
|
163
142
|
############## SUBSCRIPTION ##############
|
@@ -168,91 +147,69 @@ module Kaui
|
|
168
147
|
end
|
169
148
|
|
170
149
|
def self.get_subscriptions(account_id)
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
150
|
+
subscriptions = []
|
151
|
+
bundles = get_bundles(account_id)
|
152
|
+
bundles.each do |bundle|
|
153
|
+
subscriptions += get_subscriptions_for_bundle(bundle.bundle_id)
|
154
|
+
end
|
155
|
+
subscriptions
|
177
156
|
end
|
178
157
|
|
179
158
|
def self.get_subscription(subscription_id)
|
180
|
-
|
181
|
-
|
182
|
-
process_response(data, :single) {|json| Kaui::Subscription.new(json) }
|
183
|
-
rescue => e
|
184
|
-
end
|
159
|
+
data = call_killbill :get, "/1.0/kb/subscriptions/#{subscription_id}"
|
160
|
+
process_response(data, :single) {|json| Kaui::Subscription.new(json) }
|
185
161
|
end
|
186
162
|
|
187
163
|
def self.create_subscription(subscription, current_user = nil, reason = nil, comment = nil)
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
"X-Killbill-Comment" => "#{comment}"
|
199
|
-
return data[:code] == 201
|
200
|
-
rescue => e
|
201
|
-
end
|
164
|
+
subscription_data = Kaui::Subscription.camelize(subscription.to_hash)
|
165
|
+
# We don't want to pass events
|
166
|
+
subscription_data.delete(:events)
|
167
|
+
call_killbill :post,
|
168
|
+
"/1.0/kb/subscriptions",
|
169
|
+
ActiveSupport::JSON.encode(subscription_data, :root => false),
|
170
|
+
:content_type => "application/json",
|
171
|
+
"X-Killbill-CreatedBy" => current_user,
|
172
|
+
"X-Killbill-Reason" => "#{reason}",
|
173
|
+
"X-Killbill-Comment" => "#{comment}"
|
202
174
|
end
|
203
175
|
|
204
176
|
def self.update_subscription(subscription, requested_date = nil, current_user = nil, reason = nil, comment = nil)
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
"X-Killbill-Comment" => "#{comment}"
|
217
|
-
return data[:code] < 300
|
218
|
-
rescue => e
|
219
|
-
end
|
177
|
+
subscription_data = Kaui::Subscription.camelize(subscription.to_hash)
|
178
|
+
date_param = "?requestedDate=" + requested_date.to_s unless requested_date.blank?
|
179
|
+
# We don't want to pass events
|
180
|
+
subscription_data.delete(:events)
|
181
|
+
call_killbill :put,
|
182
|
+
"/1.0/kb/subscriptions/#{subscription.subscription_id}#{date_param}",
|
183
|
+
ActiveSupport::JSON.encode(subscription_data, :root => false),
|
184
|
+
:content_type => :json,
|
185
|
+
"X-Killbill-CreatedBy" => current_user,
|
186
|
+
"X-Killbill-Reason" => "#{reason}",
|
187
|
+
"X-Killbill-Comment" => "#{comment}"
|
220
188
|
end
|
221
189
|
|
222
190
|
def self.reinstate_subscription(subscription_id, current_user = nil, reason = nil, comment = nil)
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
"X-Killbill-Comment" => "#{comment}"
|
231
|
-
return data[:code] < 300
|
232
|
-
rescue => e
|
233
|
-
end
|
191
|
+
call_killbill :put,
|
192
|
+
"/1.0/kb/subscriptions/#{subscription_id}/uncancel",
|
193
|
+
"",
|
194
|
+
:content_type => :json,
|
195
|
+
"X-Killbill-CreatedBy" => current_user,
|
196
|
+
"X-Killbill-Reason" => "#{reason}",
|
197
|
+
"X-Killbill-Comment" => "#{comment}"
|
234
198
|
end
|
235
199
|
|
236
200
|
def self.delete_subscription(subscription_id, current_user = nil, reason = nil, comment = nil)
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
"X-Killbill-Comment" => "#{comment}"
|
243
|
-
return data[:code] < 300
|
244
|
-
rescue => e
|
245
|
-
end
|
201
|
+
call_killbill :delete,
|
202
|
+
"/1.0/kb/subscriptions/#{subscription_id}",
|
203
|
+
"X-Killbill-CreatedBy" => current_user,
|
204
|
+
"X-Killbill-Reason" => "#{reason}",
|
205
|
+
"X-Killbill-Comment" => "#{comment}"
|
246
206
|
end
|
247
207
|
|
248
208
|
############## INVOICE ##############
|
249
209
|
|
250
210
|
def self.get_invoice(invoice_id)
|
251
|
-
|
252
|
-
|
253
|
-
process_response(data, :single) {|json| Kaui::Invoice.new(json) }
|
254
|
-
rescue => e
|
255
|
-
end
|
211
|
+
data = call_killbill :get, "/1.0/kb/invoices/#{invoice_id}?withItems=true"
|
212
|
+
process_response(data, :single) {|json| Kaui::Invoice.new(json) }
|
256
213
|
end
|
257
214
|
|
258
215
|
def self.get_invoice_item(invoice_id, invoice_item_id)
|
@@ -268,52 +225,41 @@ module Kaui
|
|
268
225
|
end
|
269
226
|
|
270
227
|
def self.get_invoice_html(invoice_id)
|
271
|
-
|
272
|
-
|
273
|
-
data[:body] if data.present?
|
274
|
-
rescue => e
|
275
|
-
end
|
228
|
+
data = call_killbill :get, "/1.0/kb/invoices/#{invoice_id}/html"
|
229
|
+
data[:body] if data.present?
|
276
230
|
end
|
277
231
|
|
278
232
|
def self.adjust_invoice(invoice_item, current_user = nil, reason = nil, comment = nil)
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
"X-Killbill-Comment" => "#{comment}"
|
288
|
-
return data[:code] < 300
|
289
|
-
rescue => e
|
290
|
-
end
|
233
|
+
invoice_data = Kaui::InvoiceItem.camelize(invoice_item.to_hash)
|
234
|
+
call_killbill :post,
|
235
|
+
"/1.0/kb/invoices/#{invoice_item.invoice_id}",
|
236
|
+
ActiveSupport::JSON.encode(invoice_data, :root => false),
|
237
|
+
:content_type => :json,
|
238
|
+
"X-Killbill-CreatedBy" => current_user,
|
239
|
+
"X-Killbill-Reason" => "#{reason}",
|
240
|
+
"X-Killbill-Comment" => "#{comment}"
|
291
241
|
end
|
292
242
|
|
293
243
|
def self.create_charge(charge, requested_date, current_user = nil, reason = nil, comment = nil)
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
"X-Killbill-Comment" => "#{comment}"
|
314
|
-
end
|
315
|
-
return data[:code] < 300
|
316
|
-
rescue => e
|
244
|
+
charge_data = Kaui::Charge.camelize(charge.to_hash)
|
245
|
+
date_param = "?requestedDate=" + requested_date unless requested_date.blank?
|
246
|
+
|
247
|
+
if charge.invoice_id.present?
|
248
|
+
call_killbill :post,
|
249
|
+
"/1.0/kb/invoices/#{charge.invoice_id}/charges#{date_param}",
|
250
|
+
ActiveSupport::JSON.encode(charge_data, :root => false),
|
251
|
+
:content_type => "application/json",
|
252
|
+
"X-Killbill-CreatedBy" => current_user,
|
253
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
254
|
+
"X-Killbill-Comment" => "#{comment}"
|
255
|
+
else
|
256
|
+
call_killbill :post,
|
257
|
+
"/1.0/kb/invoices/charges#{date_param}",
|
258
|
+
ActiveSupport::JSON.encode(charge_data, :root => false),
|
259
|
+
:content_type => "application/json",
|
260
|
+
"X-Killbill-CreatedBy" => current_user,
|
261
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
262
|
+
"X-Killbill-Comment" => "#{comment}"
|
317
263
|
end
|
318
264
|
end
|
319
265
|
|
@@ -336,45 +282,32 @@ module Kaui
|
|
336
282
|
############## PAYMENT ##############
|
337
283
|
|
338
284
|
def self.get_payment(payment_id)
|
339
|
-
|
340
|
-
|
341
|
-
process_response(data, :single) { |json| Kaui::Payment.new(json) }
|
342
|
-
rescue => e
|
343
|
-
end
|
285
|
+
data = call_killbill :get, "/1.0/kb/payments/#{payment_id}"
|
286
|
+
process_response(data, :single) { |json| Kaui::Payment.new(json) }
|
344
287
|
end
|
345
288
|
|
346
289
|
def self.get_payments(invoice_id)
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
return response_data
|
351
|
-
rescue => e
|
352
|
-
[]
|
353
|
-
end
|
290
|
+
data = call_killbill :get, "/1.0/kb/invoices/#{invoice_id}/payments"
|
291
|
+
response_data = process_response(data, :multiple) {|json| Kaui::Payment.new(json) }
|
292
|
+
return response_data
|
354
293
|
end
|
355
294
|
|
356
295
|
def self.create_payment(payment, external, current_user = nil, reason = nil, comment = nil)
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
"X-Killbill-Comment" => "#{comment}"
|
373
|
-
return data[:code] < 300
|
374
|
-
else
|
375
|
-
return false
|
376
|
-
end
|
377
|
-
rescue => e
|
296
|
+
payment_data = Kaui::Payment.camelize(payment.to_hash)
|
297
|
+
|
298
|
+
if payment.invoice_id.present?
|
299
|
+
# We should use different model for POST and GEt, this seems fragile...
|
300
|
+
payment_data.delete(:external)
|
301
|
+
payment_data.delete(:refunds)
|
302
|
+
payment_data.delete(:chargebacks)
|
303
|
+
payment_data.delete(:audit_logs)
|
304
|
+
call_killbill :post,
|
305
|
+
"/1.0/kb/invoices/#{payment.invoice_id}/payments?externalPayment=#{external}",
|
306
|
+
ActiveSupport::JSON.encode(payment_data, :root => false),
|
307
|
+
:content_type => "application/json",
|
308
|
+
"X-Killbill-CreatedBy" => current_user,
|
309
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
310
|
+
"X-Killbill-Comment" => "#{comment}"
|
378
311
|
end
|
379
312
|
end
|
380
313
|
|
@@ -390,46 +323,34 @@ module Kaui
|
|
390
323
|
end
|
391
324
|
|
392
325
|
def self.get_payment_methods(account_id)
|
393
|
-
|
394
|
-
|
395
|
-
process_response(data, :multiple) {|json| Kaui::PaymentMethod.new(json) }
|
396
|
-
rescue => e
|
397
|
-
end
|
326
|
+
data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/paymentMethods?withPluginInfo=true"
|
327
|
+
process_response(data, :multiple) {|json| Kaui::PaymentMethod.new(json) }
|
398
328
|
end
|
399
329
|
|
400
330
|
def self.get_payment_method(payment_method_id)
|
401
|
-
|
402
|
-
|
403
|
-
process_response(data, :single) {|json| Kaui::PaymentMethod.new(json) }
|
404
|
-
rescue => e
|
405
|
-
end
|
331
|
+
data = call_killbill :get, "/1.0/kb/paymentMethods/#{payment_method_id}?withPluginInfo=true"
|
332
|
+
process_response(data, :single) {|json| Kaui::PaymentMethod.new(json) }
|
406
333
|
end
|
407
334
|
|
408
335
|
def self.set_payment_method_as_default(account_id, payment_method_id, current_user = nil, reason = nil, comment = nil)
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
return data[:code] < 300
|
417
|
-
rescue => e
|
418
|
-
end
|
336
|
+
call_killbill :put,
|
337
|
+
"/1.0/kb/accounts/#{account_id}/paymentMethods/#{payment_method_id}/setDefault",
|
338
|
+
"",
|
339
|
+
:content_type => :json,
|
340
|
+
"X-Killbill-CreatedBy" => current_user,
|
341
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
342
|
+
"X-Killbill-Comment" => "#{comment}"
|
419
343
|
end
|
420
344
|
|
421
345
|
def self.add_payment_method(payment_method, current_user = nil, reason = nil, comment = nil)
|
422
346
|
payment_method_data = Kaui::Refund.camelize(payment_method.to_hash)
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
return data[:code] < 300
|
431
|
-
rescue => e
|
432
|
-
end
|
347
|
+
call_killbill :post,
|
348
|
+
"/1.0/kb/accounts/#{payment_method.account_id}/paymentMethods?isDefault=#{payment_method.is_default}",
|
349
|
+
ActiveSupport::JSON.encode(payment_method_data, :root => false),
|
350
|
+
:content_type => :json,
|
351
|
+
"X-Killbill-CreatedBy" => current_user,
|
352
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
353
|
+
"X-Killbill-Comment" => "#{comment}"
|
433
354
|
end
|
434
355
|
|
435
356
|
############## REFUND ##############
|
@@ -459,156 +380,105 @@ module Kaui
|
|
459
380
|
############## CHARGEBACK ##############
|
460
381
|
|
461
382
|
def self.get_chargebacks_for_payment(payment_id)
|
462
|
-
|
463
|
-
|
464
|
-
process_response(data, :multiple) {|json| Kaui::Chargeback.new(json) }
|
465
|
-
rescue => e
|
466
|
-
end
|
383
|
+
data = call_killbill :get, "/1.0/kb/chargebacks/payments/#{payment_id}"
|
384
|
+
process_response(data, :multiple) {|json| Kaui::Chargeback.new(json) }
|
467
385
|
end
|
468
386
|
|
469
387
|
def self.create_chargeback(chargeback, current_user = nil, reason = nil, comment = nil)
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
"X-Killbill-Comment" => "#{comment}"
|
480
|
-
return data[:code] < 300
|
481
|
-
rescue => e
|
482
|
-
end
|
388
|
+
chargeback_data = Kaui::Refund.camelize(chargeback.to_hash)
|
389
|
+
|
390
|
+
call_killbill :post,
|
391
|
+
"/1.0/kb/chargebacks",
|
392
|
+
ActiveSupport::JSON.encode(chargeback_data, :root => false),
|
393
|
+
:content_type => "application/json",
|
394
|
+
"X-Killbill-CreatedBy" => current_user,
|
395
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
396
|
+
"X-Killbill-Comment" => "#{comment}"
|
483
397
|
end
|
484
398
|
|
485
399
|
############## CREDIT ##############
|
486
400
|
|
487
401
|
def self.create_credit(credit, current_user = nil, reason = nil, comment = nil)
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
"X-Killbill-Comment" => "#{comment}"
|
497
|
-
return data[:code] < 300
|
498
|
-
rescue => e
|
499
|
-
end
|
402
|
+
credit_data = Kaui::Credit.camelize(credit.to_hash)
|
403
|
+
call_killbill :post,
|
404
|
+
"/1.0/kb/credits",
|
405
|
+
ActiveSupport::JSON.encode(credit_data, :root => false),
|
406
|
+
:content_type => "application/json",
|
407
|
+
"X-Killbill-CreatedBy" => current_user,
|
408
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
409
|
+
"X-Killbill-Comment" => "#{comment}"
|
500
410
|
end
|
501
411
|
|
502
412
|
############## TAG ##############
|
503
413
|
|
504
414
|
def self.get_tag_definitions
|
505
|
-
|
506
|
-
|
507
|
-
process_response(data, :multiple) { |json| Kaui::TagDefinition.new(json) }
|
508
|
-
rescue => e
|
509
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
510
|
-
[]
|
511
|
-
end
|
415
|
+
data = call_killbill :get, "/1.0/kb/tagDefinitions"
|
416
|
+
process_response(data, :multiple) { |json| Kaui::TagDefinition.new(json) }
|
512
417
|
end
|
513
418
|
|
514
419
|
def self.get_tag_definition(tag_definition_id)
|
515
|
-
|
516
|
-
|
517
|
-
process_response(data, :single) { |json| Kaui::TagDefinition.new(json) }
|
518
|
-
rescue => e
|
519
|
-
[]
|
520
|
-
end
|
420
|
+
data = call_killbill :get, "/1.0/kb/tagDefinitions/#{tag_definition_id}"
|
421
|
+
process_response(data, :single) { |json| Kaui::TagDefinition.new(json) }
|
521
422
|
end
|
522
423
|
|
523
424
|
def self.create_tag_definition(tag_definition, current_user = nil, reason = nil, comment = nil)
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
"X-Killbill-Comment" => "#{comment}"
|
533
|
-
return data[:code] < 300
|
534
|
-
rescue => e
|
535
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
536
|
-
end
|
425
|
+
tag_definition_data = Kaui::TagDefinition.camelize(tag_definition.to_hash)
|
426
|
+
call_killbill :post,
|
427
|
+
"/1.0/kb/tagDefinitions",
|
428
|
+
ActiveSupport::JSON.encode(tag_definition_data, :root => false),
|
429
|
+
:content_type => "application/json",
|
430
|
+
"X-Killbill-CreatedBy" => current_user,
|
431
|
+
"X-Killbill-Reason" => extract_reason_code(reason),
|
432
|
+
"X-Killbill-Comment" => "#{comment}"
|
537
433
|
end
|
538
434
|
|
539
435
|
def self.delete_tag_definition(tag_definition_id, current_user = nil, reason = nil, comment = nil)
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
"X-Killbill-Comment" => "#{comment}"
|
546
|
-
return data[:code] < 300
|
547
|
-
rescue => e
|
548
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
549
|
-
end
|
436
|
+
call_killbill :delete,
|
437
|
+
"/1.0/kb/tagDefinitions/#{tag_definition_id}",
|
438
|
+
"X-Killbill-CreatedBy" => current_user,
|
439
|
+
"X-Killbill-Reason" => "#{reason}",
|
440
|
+
"X-Killbill-Comment" => "#{comment}"
|
550
441
|
end
|
551
442
|
|
552
443
|
def self.get_tags_for_account(account_id)
|
553
|
-
|
554
|
-
|
555
|
-
process_response(data, :multiple) { |json| Kaui::Tag.new(json) }
|
556
|
-
rescue => e
|
557
|
-
end
|
444
|
+
data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/tags"
|
445
|
+
process_response(data, :multiple) { |json| Kaui::Tag.new(json) }
|
558
446
|
end
|
559
447
|
|
560
448
|
def self.get_tags_for_bundle(bundle_id)
|
561
|
-
|
562
|
-
|
563
|
-
return data[:json]
|
564
|
-
rescue => e
|
565
|
-
end
|
449
|
+
data = call_killbill :get, "/1.0/kb/bundles/#{bundle_id}/tags"
|
450
|
+
return data[:json]
|
566
451
|
end
|
567
452
|
|
568
453
|
|
569
454
|
def self.add_tags_for_account(account_id, tags, current_user = nil, reason = nil, comment = nil)
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
"X-Killbill-Reason" => "#{reason}",
|
577
|
-
"X-Killbill-Comment" => "#{comment}"
|
578
|
-
return data[:code] == 201
|
579
|
-
rescue => e
|
580
|
-
puts "#{$!}\n\t" + e.backtrace.join("\n\t")
|
581
|
-
end
|
455
|
+
call_killbill :post,
|
456
|
+
"/1.0/kb/accounts/#{account_id}/tags?" + RestClient::Payload.generate(:tagList => tags.join(",")).to_s,
|
457
|
+
nil,
|
458
|
+
"X-Killbill-CreatedBy" => current_user,
|
459
|
+
"X-Killbill-Reason" => "#{reason}",
|
460
|
+
"X-Killbill-Comment" => "#{comment}"
|
582
461
|
end
|
583
462
|
|
584
463
|
def self.remove_tags_for_account(account_id, tags, current_user = nil, reason = nil, comment = nil)
|
585
|
-
return
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
"X-Killbill-Comment" => "#{comment}"
|
592
|
-
return data[:code] < 300
|
593
|
-
rescue => e
|
594
|
-
end
|
464
|
+
return if !tags.present? || tags.size == 0
|
465
|
+
call_killbill :delete,
|
466
|
+
"/1.0/kb/accounts/#{account_id}/tags?" + RestClient::Payload.generate(:tagList => tags.join(",")).to_s,
|
467
|
+
"X-Killbill-CreatedBy" => current_user,
|
468
|
+
"X-Killbill-Reason" => "#{reason}",
|
469
|
+
"X-Killbill-Comment" => "#{comment}"
|
595
470
|
end
|
596
471
|
|
597
472
|
def self.set_tags_for_bundle(bundle_id, tags, current_user = nil, reason = nil, comment = nil)
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
"X-Killbill-Comment" => "#{comment}"
|
607
|
-
return data[:code] == 201
|
608
|
-
end
|
609
|
-
rescue => e
|
473
|
+
if tags.nil? || tags.empty?
|
474
|
+
else
|
475
|
+
call_killbill :post,
|
476
|
+
"/1.0/kb/bundles/#{bundle_id}/tags?" + RestClient::Payload.generate(:tag_list => tags.join(",")).to_s,
|
477
|
+
nil,
|
478
|
+
"X-Killbill-CreatedBy" => current_user,
|
479
|
+
"X-Killbill-Reason" => "#{reason}",
|
480
|
+
"X-Killbill-Comment" => "#{comment}"
|
610
481
|
end
|
611
482
|
end
|
612
|
-
|
613
483
|
end
|
614
484
|
end
|