zuora_rest_client 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +53 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +18 -0
  7. data/README.md +56 -0
  8. data/Rakefile +6 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/fixtures/vcr_cassettes/zuora/create_account_object_success.yml +59 -0
  12. data/fixtures/vcr_cassettes/zuora/create_account_success.yml +66 -0
  13. data/fixtures/vcr_cassettes/zuora/delete_account_object_success.yml +223 -0
  14. data/fixtures/vcr_cassettes/zuora/describe_account.yml +577 -0
  15. data/fixtures/vcr_cassettes/zuora/describe_account_related_objects.yml +577 -0
  16. data/fixtures/vcr_cassettes/zuora/describe_all_account_fields.yml +577 -0
  17. data/fixtures/vcr_cassettes/zuora/describe_all_zobjects.yml +176 -0
  18. data/fixtures/vcr_cassettes/zuora/describe_exportable_account_fields.yml +577 -0
  19. data/fixtures/vcr_cassettes/zuora/describe_non_exportable_account_fields.yml +577 -0
  20. data/fixtures/vcr_cassettes/zuora/describe_non_updateable_account_fields.yml +577 -0
  21. data/fixtures/vcr_cassettes/zuora/describe_updateable_account_fields.yml +577 -0
  22. data/fixtures/vcr_cassettes/zuora/get_account_object_success.yml +60 -0
  23. data/fixtures/vcr_cassettes/zuora/get_account_success.yml +149 -0
  24. data/fixtures/vcr_cassettes/zuora/get_account_summary_success.yml +141 -0
  25. data/fixtures/vcr_cassettes/zuora/update_account_object_success.yml +115 -0
  26. data/fixtures/vcr_cassettes/zuora/update_account_success.yml +207 -0
  27. data/lib/zuora_rest_client/client.rb +1917 -0
  28. data/lib/zuora_rest_client/connection.rb +189 -0
  29. data/lib/zuora_rest_client/result.rb +8 -0
  30. data/lib/zuora_rest_client/version.rb +3 -0
  31. data/lib/zuora_rest_client.rb +7 -0
  32. data/zuora_rest_client.gemspec +45 -0
  33. metadata +383 -0
@@ -0,0 +1,1917 @@
1
+ require 'zuora_rest_client/connection'
2
+ require 'addressable/uri'
3
+ require 'fire_poll'
4
+ require 'base64'
5
+
6
+ module ZuoraRestClient
7
+
8
+ class Client
9
+
10
+ DEFAULT_CLIENT_OPTIONS = {
11
+ logger: Logger.new($stdout),
12
+ log_level: :error,
13
+ log: true }
14
+
15
+ DEFAULT_AQUA_QUERY_OPTIONS = {
16
+ wait_for_completed_result: true,
17
+ max_wait: 3600,
18
+ poll_delay: 2 }
19
+
20
+ DEFAULT_EXPORT_OPTIONS = {
21
+ format: :csv,
22
+ zip: false,
23
+ name: nil,
24
+ encrypted: false,
25
+ max_wait: 3600,
26
+ poll_delay: 2 }
27
+
28
+ def initialize(username, password, environment = :production, options = {})
29
+ @client_options = {}.merge(DEFAULT_CLIENT_OPTIONS).merge(options)
30
+ @connection = ZuoraRestClient::Connection.new(username, password, environment, options)
31
+ end
32
+
33
+ ##############################################################################
34
+ # #
35
+ # Actions #
36
+ # #
37
+ ##############################################################################
38
+
39
+ def amend(request, zuora_version = nil)
40
+ @connection.rest_post('/action/amend', request, zuora_version)
41
+ end
42
+
43
+ def create(request, zuora_version = nil)
44
+ @connection.rest_post('/action/create', request, zuora_version)
45
+ end
46
+
47
+ def delete(request, zuora_version = nil)
48
+ @connection.rest_post('/action/delete', request, zuora_version)
49
+ end
50
+
51
+ def execute(request, zuora_version = nil)
52
+ @connection.rest_post('/action/execute', request, zuora_version)
53
+ end
54
+
55
+ def generate(request, zuora_version = nil)
56
+ @connection.rest_post('/action/generate', request, zuora_version)
57
+ end
58
+
59
+ def query(request, zuora_version = nil)
60
+ @connection.rest_post('/action/query', request, zuora_version)
61
+ end
62
+
63
+ def query_more(request, zuora_version = nil)
64
+ @connection.rest_post('/action/queryMore', request, zuora_version)
65
+ end
66
+
67
+ def subscribe(request, zuora_version = nil)
68
+ @connection.rest_post('/action/subscribe', request, zuora_version)
69
+ end
70
+
71
+ def update(request, zuora_version = nil)
72
+ @connection.rest_post('/action/update', request, zuora_version)
73
+ end
74
+
75
+ ##############################################################################
76
+ # #
77
+ # Accounting Codes #
78
+ # #
79
+ ##############################################################################
80
+
81
+ def create_accounting_code(request, zuora_version = nil)
82
+ @connection.rest_post('/accounting-codes', request, zuora_version)
83
+ end
84
+
85
+ def get_all_accounting_codes(zuora_version = nil)
86
+ @connection.rest_get('/accounting-codes', zuora_version)
87
+ end
88
+
89
+ def activate_accounting_code(accounting_code_id, zuora_version = nil)
90
+ @connection.rest_put("/accounting-codes/#{accounting_code_id}/activate", nil, zuora_version)
91
+ end
92
+
93
+ def deactivate_accounting_code(accounting_code_id, zuora_version = nil)
94
+ @connection.rest_put("/accounting-codes/#{accounting_code_id}/deactivate", nil, zuora_version)
95
+ end
96
+
97
+ def delete_accounting_code(accounting_code_id, zuora_version = nil)
98
+ @connection.rest_delete("/accounting-codes/#{accounting_code_id}", zuora_version)
99
+ end
100
+
101
+ def query_accounting_code(accounting_code_id, zuora_version = nil)
102
+ @connection.rest_get("/accounting-codes/#{accounting_code_id}", zuora_version)
103
+ end
104
+
105
+ def update_accounting_code(accounting_code_id, request, zuora_version = nil)
106
+ @connection.rest_put("/accounting-codes/#{accounting_code_id}", request, zuora_version)
107
+ end
108
+
109
+ ##############################################################################
110
+ # #
111
+ # Accounting Periods #
112
+ # #
113
+ ##############################################################################
114
+
115
+ def close_accounting_period(accounting_period_id, zuora_version = nil)
116
+ @connection.rest_put("/accounting-periods/#{accounting_period_id}/close", nil, zuora_version)
117
+ end
118
+
119
+ def pending_close_accounting_period(accounting_period_id, zuora_version = nil)
120
+ @connection.rest_put("/accounting-periods/#{accounting_period_id}/pending-close", nil, zuora_version)
121
+ end
122
+
123
+ def create_accounting_period(request, zuora_version = nil)
124
+ @connection.rest_post('/accounting-periods', request, zuora_version)
125
+ end
126
+
127
+ def get_all_accounting_periods(zuora_version = nil)
128
+ @connection.rest_get('/accounting-periods', zuora_version)
129
+ end
130
+
131
+ def get_accounting_period(accounting_period_id, zuora_version = nil)
132
+ @connection.rest_get("/accounting-periods/#{accounting_period_id}", zuora_version)
133
+ end
134
+
135
+ def update_accounting_period(accounting_period_id, request, zuora_version = nil)
136
+ @connection.rest_put("/accounting-periods/#{accounting_period_id}", request, zuora_version)
137
+ end
138
+
139
+ def delete_accounting_period(accounting_period_id, zuora_version = nil)
140
+ @connection.rest_delete("/accounting-periods/#{accounting_period_id}", zuora_version)
141
+ end
142
+
143
+ def reopen_accounting_period(accounting_period_id, zuora_version = nil)
144
+ @connection.rest_put("/accounting-periods/#{accounting_period_id}/reopen", nil, zuora_version)
145
+ end
146
+
147
+ def run_trial_balance_on_accounting_period(accounting_period_id, zuora_version = nil)
148
+ @connection.rest_put("/accounting-periods/#{accounting_period_id}/run-trial_balance", nil, zuora_version)
149
+ end
150
+
151
+ ##############################################################################
152
+ # #
153
+ # Accounts #
154
+ # #
155
+ ##############################################################################
156
+
157
+ def create_account(request, zuora_version = nil)
158
+ @connection.rest_post('/accounts', request, zuora_version)
159
+ end
160
+
161
+ def get_account(account_key, zuora_version = nil)
162
+ @connection.rest_get("/accounts/#{account_key}", zuora_version)
163
+ end
164
+
165
+ def update_account(account_key, request, zuora_version = nil)
166
+ @connection.rest_put("/accounts/#{account_key}", request, zuora_version)
167
+ end
168
+
169
+ def get_account_summary(account_key, zuora_version = nil)
170
+ @connection.rest_get("/accounts/#{account_key}/summary", zuora_version)
171
+ end
172
+
173
+ def create_account_object(request, zuora_version = nil)
174
+ @connection.rest_post('/object/account', request, zuora_version)
175
+ end
176
+
177
+ def retrieve_account_object(account_id, fields = nil, zuora_version = nil)
178
+ uri = Addressable::URI.parse("/object/account/#{account_id}")
179
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
180
+ @connection.rest_get(uri.to_s, zuora_version)
181
+ end
182
+
183
+ def update_account_object(account_id, request, zuora_version = nil)
184
+ @connection.rest_put("/object/account/#{account_id}", request, zuora_version)
185
+ end
186
+
187
+ def delete_account_object(account_id, zuora_version = nil)
188
+ @connection.rest_delete("/object/account/#{account_id}", zuora_version)
189
+ end
190
+
191
+ ##############################################################################
192
+ # #
193
+ # Amendments #
194
+ # #
195
+ ##############################################################################
196
+
197
+ def get_amendment(amendment_key, zuora_version = nil)
198
+ @connection.rest_get("/amendments/#{amendment_key}", zuora_version)
199
+ end
200
+
201
+ def get_amendment_by_subscription_id(subscription_id, zuora_version = nil)
202
+ @connection.rest_get("/amendments/subscriptions/#{subscription_id}", zuora_version)
203
+ end
204
+
205
+ def create_amendment_object(request, zuora_version = nil)
206
+ @connection.rest_post('/object/amendment', request, zuora_version)
207
+ end
208
+
209
+ def retrieve_amendment_object(amendment_id, fields = nil, zuora_version = nil)
210
+ uri = Addressable::URI.parse("/object/amendment/#{amendment_id}")
211
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
212
+ @connection.rest_get(uri.to_s, zuora_version)
213
+ end
214
+
215
+ def update_amendment_object(amendment_id, request, zuora_version = nil)
216
+ @connection.rest_put("/object/amendment/#{amendment_id}", request, zuora_version)
217
+ end
218
+
219
+ def delete_amendment_object(amendment_id, zuora_version = nil)
220
+ @connection.rest_delete("/object/amendment/#{amendment_id}", zuora_version)
221
+ end
222
+
223
+ ##############################################################################
224
+ # #
225
+ # AQuA #
226
+ # #
227
+ ##############################################################################
228
+
229
+ def aqua_query(request, options = {})
230
+ aqua_query_options = {}.merge(DEFAULT_AQUA_QUERY_OPTIONS).merge(options)
231
+ result = @connection.app_post('/apps/api/batch-query/', request)
232
+ logger.debug "********* AQUA POST QUERY RESULT: #{result.inspect}"
233
+
234
+ raise "Error: #{result.message}" if result.status == 'Error'
235
+
236
+ if aqua_query_options[:wait_for_completed_result]
237
+ poll_started = false
238
+ FirePoll.poll(nil, aqua_query_options[:max_wait]) do
239
+ sleep aqua_query_options[:poll_delay] if poll_started
240
+ poll_started = true
241
+ result = get_aqua_job_result(result.id)
242
+ logger.debug "********* CURRENT AQUA JOB STATUS: #{result.inspect}"
243
+ raise "Error: #{result.message}" if result.status == 'Error'
244
+ result.status != 'submitted' && result.status.end_with?('ed')
245
+ end
246
+
247
+ logger.debug "********* FINAL AQUA JOB STATUS: #{result.inspect}"
248
+ end
249
+
250
+ result
251
+ end
252
+
253
+ def get_aqua_job_result(job_id)
254
+ @connection.app_get("/apps/api/batch-query/jobs/#{job_id}")
255
+ end
256
+
257
+ def get_last_aqua_job_result(partner, project)
258
+ @connection.app_get("/apps/api/batch-query/jobs/partner/#{partner}/project/#{project}")
259
+ end
260
+
261
+ ##############################################################################
262
+ # #
263
+ # Attachments #
264
+ # #
265
+ ##############################################################################
266
+
267
+ def add_attachment(source_filename_or_io, source_content_type, associated_object_type, associated_object_key, description = nil, zuora_version = nil)
268
+ payload = { file: Faraday::UploadIO(source_filename_or_io, source_content_type) }
269
+ uri = Addressable::URI.parse('/attachments')
270
+ query_values = { associatedObjectType: associated_object_type.to_s, associatedObjectKey: associated_object_key.to_s }
271
+ query_values[:description] = description if !description.nil?
272
+ uri.query_values = query_values
273
+ @connection.rest_post(uri.to_s, payload, zuora_version, false)
274
+ end
275
+
276
+ def view_attachment_list(associated_object_type, associated_object_key, zuora_version = nil)
277
+ @connection.rest_get("/attachments/#{associated_object_type}/#{associated_object_key}", zuora_version)
278
+ end
279
+
280
+ def view_attachment(attachment_id, zuora_version = nil)
281
+ @connection.rest_get("/attachments/#{attachment_id}", zuora_version)
282
+ end
283
+
284
+ def edit_attachment(attachment_id, request, zuora_version = nil)
285
+ @connection.rest_put("/attachments/#{attachment_id}", request, zuora_version)
286
+ end
287
+
288
+ def delete_attachment(attachment_id, zuora_version = nil)
289
+ @connection.rest_delete("/attachments/#{attachment_id}", zuora_version)
290
+ end
291
+
292
+ ##############################################################################
293
+ # #
294
+ # Bill Run #
295
+ # #
296
+ ##############################################################################
297
+
298
+ def create_bill_run_object(request, zuora_version = nil)
299
+ @connection.rest_post('/object/bill-run', request, zuora_version)
300
+ end
301
+
302
+ def retrieve_bill_run_object(bill_run_id, fields = nil, zuora_version = nil)
303
+ uri = Addressable::URI.parse("/object/bill-run/#{bill_run_id}")
304
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
305
+ @connection.rest_get(uri.to_s, zuora_version)
306
+ end
307
+
308
+ def update_bill_run_object(bill_run_id, request, zuora_version = nil)
309
+ @connection.rest_put("/object/bill-run/#{bill_run_id}", request, zuora_version)
310
+ end
311
+
312
+ def delete_bill_run_object(bill_run_id, zuora_version = nil)
313
+ @connection.rest_delete("/object/bill-run/#{bill_run_id}", zuora_version)
314
+ end
315
+
316
+ ##############################################################################
317
+ # #
318
+ # Billing Preview Run #
319
+ # #
320
+ ##############################################################################
321
+
322
+ def create_billing_preview_run(request, zuora_version = nil)
323
+ @connection.rest_post('/billing-preview-runs', request, zuora_version)
324
+ end
325
+
326
+ def get_billing_preview_run(billing_preview_run_id, zuora_version = nil)
327
+ @connection.rest_get("/billing-preview-runs/#{billing_preview_run_id}", zuora_version)
328
+ end
329
+
330
+ ##############################################################################
331
+ # #
332
+ # Catalog #
333
+ # #
334
+ ##############################################################################
335
+
336
+ def get_product_catalog(zuora_version = nil)
337
+ @connection.rest_get('/catalog/products', zuora_version)
338
+ end
339
+
340
+ def share_product_with_entities(product_id, request, zuora_version = nil)
341
+ @connection.rest_put("/catalog/products/#{product_id}/share", request, zuora_version)
342
+ end
343
+
344
+ ##############################################################################
345
+ # #
346
+ # Charge Revenue Summaries #
347
+ # #
348
+ ##############################################################################
349
+
350
+ def get_charge_summary_details_by_crs_number(crs_number, zuora_version = nil)
351
+ @connection.rest_get("/charge-revenue-summaries/#{crs_number}", zuora_version)
352
+ end
353
+
354
+ def get_charge_summary_details_by_charge_id(charge_id, zuora_version = nil)
355
+ @connection.rest_get("/charge-revenue-summaries/subscription-charges/#{charge_id}", zuora_version)
356
+ end
357
+
358
+ ##############################################################################
359
+ # #
360
+ # Communication Profiles #
361
+ # #
362
+ ##############################################################################
363
+
364
+ def retrieve_communication_profile_object(communication_profile_id, fields = nil, zuora_version = nil)
365
+ uri = Addressable::URI.parse("/object/communication-profile/#{communication_profile_id}")
366
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
367
+ @connection.rest_get(uri.to_s, zuora_version)
368
+ end
369
+
370
+ def delete_communication_profile_object(communication_profile_id, zuora_version = nil)
371
+ @connection.rest_delete("/object/communication-profile/#{communication_profile_id}", zuora_version)
372
+ end
373
+
374
+ ##############################################################################
375
+ # #
376
+ # Contacts #
377
+ # #
378
+ ##############################################################################
379
+
380
+ def create_contact_object(request, zuora_version = nil)
381
+ @connection.rest_post('/object/contact', request, zuora_version)
382
+ end
383
+
384
+ def retrieve_contact_object(contact_id, fields = nil, zuora_version = nil)
385
+ uri = Addressable::URI.parse("/object/contact/#{contact_id}")
386
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
387
+ @connection.rest_get("/object/contact/#{contact_id}", zuora_version)
388
+ end
389
+
390
+ def update_contact_object(contact_id, request, zuora_version = nil)
391
+ @connection.rest_put("/object/contact/#{contact_id}", request, zuora_version)
392
+ end
393
+
394
+ def delete_contact_object(contact_id, zuora_version = nil)
395
+ @connection.rest_delete("/object/contact/#{contact_id}", zuora_version)
396
+ end
397
+
398
+ ##############################################################################
399
+ # #
400
+ # Credit Balance Adjustments #
401
+ # #
402
+ ##############################################################################
403
+
404
+ def retrieve_credit_balance_adjustment_object(credit_balance_adjustment_id, fields = nil, zuora_version = nil)
405
+ uri = Addressable::URI.parse("/object/credit-balance-adjustment/#{credit_balance_adjustment_id}")
406
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
407
+ @connection.rest_get(uri.to_s, zuora_version)
408
+ end
409
+
410
+ def delete_credit_balance_adjustment_object(credit_balance_adjustment_id, zuora_version = nil)
411
+ @connection.rest_delete("/object/credit-balance-adjustment/#{credit_balance_adjustment_id}", zuora_version)
412
+ end
413
+
414
+ ##############################################################################
415
+ # #
416
+ # Credit Memos #
417
+ # #
418
+ ##############################################################################
419
+
420
+ def get_credit_memo(credit_memo_id, zuora_version = nil)
421
+ @connection.rest_get("/creditmemos/#{credit_memo_id}", zuora_version)
422
+ end
423
+
424
+ def delete_credit_memo(credit_memo_id, zuora_version = nil)
425
+ @connection.rest_delete("/creditmemos/#{credit_memo_id}", zuora_version)
426
+ end
427
+
428
+ def update_credit_memo(credit_memo_id, request, zuora_version = nil)
429
+ @connection.rest_put("/creditmemos/#{credit_memo_id}", request, zuora_version)
430
+ end
431
+
432
+ def post_credit_memo(credit_memo_id, zuora_version = nil)
433
+ @connection.rest_post("/creditmemos/#{credit_memo_id}/post", nil, zuora_version)
434
+ end
435
+
436
+ def get_credit_memo_item(credit_memo_id, credit_memo_item_id, zuora_version = nil)
437
+ @connection.rest_get("/creditmemos/#{credit_memo_id}/items/#{credit_memo_item_id}", zuora_version)
438
+ end
439
+
440
+ def refund_credit_memo(credit_memo_id, request, zuora_version = nil)
441
+ @connection.rest_post("/creditmemos/#{credit_memo_id}/refund", request, zuora_version)
442
+ end
443
+
444
+ def query_credit_memos_by_account(request, zuora_version = nil)
445
+ @connection.rest_post('/creditmemos/query', request, zuora_version)
446
+ end
447
+
448
+ def get_credit_memo_parts(credit_memo_id, zuora_version = nil)
449
+ @connection.rest_get("/creditmemos/#{credit_memo_id}/parts", zuora_version)
450
+ end
451
+
452
+ def apply_credit_memo(credit_memo_id, request, zuora_version = nil)
453
+ @connection.rest_post("/creditmemos/#{credit_memo_id}/apply", request, zuora_version)
454
+ end
455
+
456
+ def get_credit_memo_items(credit_memo_id, zuora_version = nil)
457
+ @connection.rest_get("/creditmemos/#{credit_memo_id}/items", zuora_version)
458
+ end
459
+
460
+ def get_credit_memo_part_items(credit_memo_id, part_id, zuora_version = nil)
461
+ @connection.rest_get("/creditmemos/#{credit_memo_id}/parts/#{part_id}/itemparts", zuora_version)
462
+ end
463
+
464
+ def unapply_credit_memo(credit_memo_id, zuora_version = nil)
465
+ @connection.rest_post("/creditmemos/#{credit_memo_id}/unapply", request, zuora_version)
466
+ end
467
+
468
+ def create_credit_memo_from_invoice(invoice_id, request, zuora_version = nil)
469
+ @connection.rest_post("/creditmemos/invoice/#{invoice_id}", request, zuora_version)
470
+ end
471
+
472
+ def get_credit_memo_part_item(credit_memo_id, part_id, item_part_id, zuora_version = nil)
473
+ @connection.rest_get("/creditmemos/#{credit_memo_id}/parts/#{part_id}/itemparts/#{item_part_id}", zuora_version)
474
+ end
475
+
476
+ def create_credit_memo_from_charge(request, zuora_version = nil)
477
+ @connection.rest_post('/creditmemos', request, zuora_version)
478
+ end
479
+
480
+ def get_credit_memos(zuora_version = nil)
481
+ @connection.rest_get('/creditmemos', zuora_version)
482
+ end
483
+
484
+ def get_credit_memo_part(credit_memo_id, part_id, zuora_version = nil)
485
+ @connection.rest_get("/creditmemos/#{credit_memo_id}/parts/#{part_id}", zuora_version)
486
+ end
487
+
488
+ def cancel_credit_memo(credit_memo_id, zuora_version = nil)
489
+ @connection.rest_post("/creditmemos/#{credit_memo_id}/cancel", nil, zuora_version)
490
+ end
491
+
492
+ def create_credit_memo_pdf(credit_memo_id, zuora_version = nil)
493
+ @connection.rest_post("/creditmemos/#{credit_memo_id}/pdfs", nil, zuora_version)
494
+ end
495
+
496
+ ##############################################################################
497
+ # #
498
+ # Custom Exchange Rates #
499
+ # #
500
+ ##############################################################################
501
+
502
+ def get_custom_exchange_rates(currency, zuora_version = nil)
503
+ @connection.rest_get("/custom-exchange-rates/#{currency}", zuora_version)
504
+ end
505
+
506
+ ##############################################################################
507
+ # #
508
+ # Debit Memos #
509
+ # #
510
+ ##############################################################################
511
+
512
+ def get_debit_memo_item(debit_memo_id, debit_memo_item_id, zuora_version = nil)
513
+ @connection.rest_get("/debitmemos/#{debit_memo_id}/items/#{debit_memo_item_id}", zuora_version)
514
+ end
515
+
516
+ def create_debit_memo_from_invoice(invoice_id, request, zuora_version = nil)
517
+ @connection.rest_post("/debitmemos/invoice/#{invoice_id}", request, zuora_version)
518
+ end
519
+
520
+ def create_debit_memo_from_charge(request, zuora_version = nil)
521
+ @connection.rest_post("/debitmemos", request, zuora_version)
522
+ end
523
+
524
+ def get_debit_memos(zuora_version = nil)
525
+ @connection.rest_get("/debitmemos", zuora_version)
526
+ end
527
+
528
+ def create_debit_memo_pdf(debit_memo_id, zuora_version = nil)
529
+ @connection.rest_post("/debitmemos/#{debit_memo_id}/pdfs", nil, zuora_version)
530
+ end
531
+
532
+ def get_debit_memo_items(debit_memo_id, zuora_version = nil)
533
+ @connection.rest_get("/debitmemos/#{debit_memo_id}/items", zuora_version)
534
+ end
535
+
536
+ def cancel_debit_memo(debit_memo_id, zuora_version = nil)
537
+ @connection.rest_post("/debitmemos/#{debit_memo_id}/cancel", nil, zuora_version)
538
+ end
539
+
540
+ def get_debit_memo(debit_memo_id, zuora_version = nil)
541
+ @connection.rest_get("/debitmemos/#{debit_memo_id}", zuora_version)
542
+ end
543
+
544
+ def delete_debit_memo(debit_memo_id, zuora_version = nil)
545
+ @connection.rest_delete("/debitmemos/#{debit_memo_id}", zuora_version)
546
+ end
547
+
548
+ def update_debit_memo(debit_memo_id, request, zuora_version = nil)
549
+ @connection.rest_put("/debitmemos/#{debit_memo_id}", request, zuora_version)
550
+ end
551
+
552
+ def post_debit_memo(debit_memo_id, zuora_version = nil)
553
+ @connection.rest_post("/debitmemos/#{debit_memo_id}/post", nil, zuora_version)
554
+ end
555
+
556
+ ##############################################################################
557
+ # #
558
+ # Describe #
559
+ # #
560
+ ##############################################################################
561
+
562
+ def describe_object(object = '', zuora_version = nil)
563
+ path = "/describe/#{object}"
564
+ path = "/#{zuora_version.to_s}#{path}" if !zuora_version.nil?
565
+ result = @connection.rest_get(path)
566
+ if result.respond_to?(:objects)
567
+
568
+ # Listing all objects
569
+ result = result.objects.object
570
+
571
+ elsif result.respond_to?(:object)
572
+
573
+ # Returning single object
574
+ result = result.object
575
+ result.fields = result.fields.field if result.fields
576
+ result.related_objects = result.related_objects.object if result.related_objects
577
+ result.fields.map! do |field|
578
+ field.contexts = field.contexts.context if field.contexts
579
+ field.options = field.options.option if field.options
580
+ field
581
+ end
582
+
583
+ end
584
+
585
+ result
586
+ end
587
+
588
+ def describe_fields(object, field_filter_options = {}, zuora_version = nil)
589
+
590
+ return [] if object.nil? || object == ''
591
+
592
+ # Invoke Zuora describe
593
+ results = describe_object(object, zuora_version)
594
+ results = results.fields
595
+
596
+ # Filter results
597
+ results.select! do |field|
598
+
599
+ match = true
600
+
601
+ # Process field filters
602
+ %w(selectable createable updateable filterable custom).each do |option|
603
+ if field_filter_options[option.to_sym] == true
604
+ match &&= field[option.to_sym]
605
+ elsif field_filter_options[option.to_sym] == false
606
+ match &&= !field[option.to_sym]
607
+ end
608
+ end
609
+
610
+ # Process nested field filters
611
+ %w(soap export).each do |context|
612
+ if field_filter_options["#{context}able".to_sym] == true
613
+ match &&= field.contexts.include?(context)
614
+ elsif field_filter_options["#{context}able".to_sym] == false
615
+ match &&= !field.contexts.include?(context)
616
+ end
617
+ end
618
+
619
+ match
620
+ end
621
+
622
+ # Sort results by field name
623
+ results.sort! { |a, b| a.name <=> b.name }
624
+
625
+ results
626
+ end
627
+
628
+ def describe_related_objects(object, zuora_version = nil)
629
+
630
+ return [] if object.nil? || object == ''
631
+
632
+ # Invoke Zuora describe
633
+ results = describe_object(object, zuora_version)
634
+ results = results.related_objects
635
+
636
+ results
637
+ end
638
+
639
+ ##############################################################################
640
+ # #
641
+ # Entities #
642
+ # #
643
+ ##############################################################################
644
+
645
+ def create_entity(request, zuora_version = nil)
646
+ @connection.rest_post('/entities', request, zuora_version)
647
+ end
648
+
649
+ def get_entities(zuora_version = nil)
650
+ @connection.rest_get('/entities', zuora_version)
651
+ end
652
+
653
+ def update_entity(entity_id, request, zuora_version = nil)
654
+ @connection.rest_put("/entities/#{entity_id}", request, zuora_version)
655
+ end
656
+
657
+ def get_entity(entity_id, zuora_version = nil)
658
+ @connection.rest_get("/entities/#{entity_id}", zuora_version)
659
+ end
660
+
661
+ def delete_entity(entity_id, zuora_version = nil)
662
+ @connection.rest_delete("/entities/#{entity_id}", zuora_version)
663
+ end
664
+
665
+ def provision_entity(entity_id, zuora_version = nil)
666
+ @connection.rest_put("/entities/#{entity_id}/provision", nil, zuora_version)
667
+ end
668
+
669
+ ##############################################################################
670
+ # #
671
+ # Entity Connections #
672
+ # #
673
+ ##############################################################################
674
+
675
+ def get_entity_connections(zuora_version = nil)
676
+ @connection.rest_get('/entity-connections', zuora_version)
677
+ end
678
+
679
+ def initiate_entity_connection(request, zuora_version = nil)
680
+ @connection.rest_post('/entity-connections', request, zuora_version)
681
+ end
682
+
683
+ def accept_entity_connection(entity_connection_id, zuora_version = nil)
684
+ @connection.rest_put("/entity-connections/#{entity_connection_id}/accept", nil, zuora_version)
685
+ end
686
+
687
+ def deny_entity_connection(entity_connection_id, zuora_version = nil)
688
+ @connection.rest_put("/entity-connections/#{entity_connection_id}/deny", nil, zuora_version)
689
+ end
690
+
691
+ def disconnect_entity_connection(entity_connection_id, zuora_version = nil)
692
+ @connection.rest_put("/entity-connections/#{entity_connection_id}/disconnect", nil, zuora_version)
693
+ end
694
+
695
+ ##############################################################################
696
+ # #
697
+ # Exports #
698
+ # #
699
+ ##############################################################################
700
+
701
+ def create_export_object(request, zuora_version = nil)
702
+ @connection.rest_post('/object/export', request, zuora_version)
703
+ end
704
+
705
+ def retrieve_export_object(export_id, fields = nil, zuora_version = nil)
706
+ uri = Addressable::URI.parse("/object/export/#{export_id}")
707
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
708
+ @connection.rest_get(uri.to_s, zuora_version)
709
+ end
710
+
711
+ def delete_export_object(export_id, zuora_version = nil)
712
+ @connection.rest_delete("/object/export/#{export_id}", zuora_version)
713
+ end
714
+
715
+ def export(export_zoql, destination_io, options = {}, delete_export_from_server = true)
716
+
717
+ export_options = {}.merge(DEFAULT_EXPORT_OPTIONS).merge(options)
718
+
719
+ # Construct export request
720
+ export_request = {
721
+ Format: export_options[:format].to_s,
722
+ Query: export_zoql,
723
+ Zip: export_options[:zip],
724
+ Encrypted: export_options[:encrypted] }
725
+ if !export_options[:name].nil?
726
+ export_request[:Name] = export_options[:name]
727
+ end
728
+
729
+ # Submit create export request
730
+ create_export_result = create_export_result(export_request)
731
+ logger.debug "********* EXPORT CREATE RESULT: #{create_export_result.inspect}"
732
+ unless create_export_result.Success
733
+ raise "Error creating export: #{create_export_result.Errors.map { |error| error.message }.join('; ')}"
734
+ end
735
+
736
+ # Poll Zuora until CSV is ready for download
737
+ poll_started = false
738
+ export_record = nil
739
+ FirePoll.poll(nil, export_options[:max_wait]) do
740
+ sleep export_options[:poll_delay] if poll_started
741
+ poll_started = true
742
+ poll_query_request = {
743
+ queryString: "SELECT Id, FileId, Status, StatusReason FROM Export WHERE Id = '#{create_export_result.Id}'" }
744
+ poll_query_result = query(poll_query_request)
745
+ export_record = poll_query_result.records.first
746
+ logger.debug "********* CURRENT EXPORT STATUS: #{export_record.Status}"
747
+ export_record.Status.end_with? 'ed'
748
+ end
749
+
750
+ # Check status and if complete, output file to destination IO
751
+ logger.debug "********* FINAL EXPORT STATUS: #{export_record.Status}"
752
+ case export_record.Status
753
+ when 'Completed'
754
+ get_file(export_zobject.FileId, destination_io)
755
+ when 'Canceled'
756
+ raise "Error downloading file: #{export_record.Status} - #{export_record.StatusReason}"
757
+ when 'Failed'
758
+ raise "Error downloading file: #{export_record.Status} - #{export_record.StatusReason}"
759
+ end
760
+
761
+ # If requested, delete export from server
762
+ if delete_export_from_server
763
+ delete_export_object(export_record.Id)
764
+ end
765
+
766
+ export_record
767
+ end
768
+
769
+ ##############################################################################
770
+ # #
771
+ # Features #
772
+ # #
773
+ ##############################################################################
774
+
775
+ def retrieve_feature_object(feature_id, fields = nil, zuora_version = nil)
776
+ uri = Addressable::URI.parse("/object/feature/#{feature_id}")
777
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
778
+ @connection.rest_get(uri.to_s, zuora_version)
779
+ end
780
+
781
+ def delete_feature_object(feature_id, zuora_version = nil)
782
+ @connection.rest_delete("/object/feature/#{feature_id}", zuora_version)
783
+ end
784
+
785
+ ##############################################################################
786
+ # #
787
+ # Get Files #
788
+ # #
789
+ ##############################################################################
790
+
791
+ def get_file(file_id, destination_io, zuora_version = nil)
792
+ @connection.rest_streamed_get("/files/#{file_id}", destination_io, zuora_version)
793
+ end
794
+
795
+ ##############################################################################
796
+ # #
797
+ # HMAC Signatures #
798
+ # #
799
+ ##############################################################################
800
+
801
+ def hmac_signature(request, zuora_version = nil)
802
+ @connection.rest_post('/hmac-signatures', request, zuora_version)
803
+ end
804
+
805
+ ##############################################################################
806
+ # #
807
+ # Hosted Pages #
808
+ # #
809
+ ##############################################################################
810
+
811
+ def get_hosted_pages(version_number = nil, zuora_version = nil)
812
+ uri = Addressable::URI.parse('/hostedpages')
813
+ uri.query_values = { version: version_number.to_s } if !version_number.nil?
814
+ @connection.rest_get(uri.to_s, zuora_version)
815
+ end
816
+
817
+ ##############################################################################
818
+ # #
819
+ # Imports #
820
+ # #
821
+ ##############################################################################
822
+
823
+ def retrieve_import_object(import_id, fields = nil, zuora_version = nil)
824
+ uri = Addressable::URI.parse("/object/import/#{import_id}")
825
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
826
+ @connection.rest_get(uri.to_s, zuora_version)
827
+ end
828
+
829
+ def delete_import_object(import_id, zuora_version = nil)
830
+ @connection.rest_delete("/object/import/#{import_id}", zuora_version)
831
+ end
832
+
833
+ ##############################################################################
834
+ # #
835
+ # Invoice Adjustments #
836
+ # #
837
+ ##############################################################################
838
+
839
+ def create_invoice_adjustment_object(request, zuora_version = nil)
840
+ @connection.rest_post('/object/invoice-adjustment', request, zuora_version)
841
+ end
842
+
843
+ def retrieve_invoice_adjustment_object(invoice_adjustment_id, fields = nil, zuora_version = nil)
844
+ uri = Addressable::URI.parse("/object/invoice-adjustment/#{invoice_adjustment_id}")
845
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
846
+ @connection.rest_get(uri.to_s, zuora_version)
847
+ end
848
+
849
+ def update_invoice_adjustment_object(invoice_adjustment_id, request, zuora_version = nil)
850
+ @connection.rest_put("/object/invoice-adjustment/#{invoice_adjustment_id}", request, zuora_version)
851
+ end
852
+
853
+ def delete_invoice_adjustment_object(invoice_adjustment_id, zuora_version = nil)
854
+ @connection.rest_delete("/object/invoice-adjustment/#{invoice_adjustment_id}", zuora_version)
855
+ end
856
+
857
+ ##############################################################################
858
+ # #
859
+ # Invoice Item Adjustments #
860
+ # #
861
+ ##############################################################################
862
+
863
+ def retrieve_invoice_item_adjustment_object(invoice_item_adjustment_id, fields = nil, zuora_version = nil)
864
+ uri = Addressable::URI.parse("/object/invoice-item-adjustment/#{invoice_item_adjustment_id}")
865
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
866
+ @connection.rest_get(uri.to_s, zuora_version)
867
+ end
868
+
869
+ def delete_invoice_item_adjustment_object(invoice_item_adjustment_id, zuora_version = nil)
870
+ @connection.rest_delete("/object/invoice-item-adjustment/#{invoice_item_adjustment_id}", zuora_version)
871
+ end
872
+
873
+ ##############################################################################
874
+ # #
875
+ # Invoice Items #
876
+ # #
877
+ ##############################################################################
878
+
879
+ def retrieve_invoice_item_object(invoice_item_id, fields = nil, zuora_version = nil)
880
+ uri = Addressable::URI.parse("/object/invoice-item/#{invoice_item_id}")
881
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
882
+ @connection.rest_get(uri.to_s, zuora_version)
883
+ end
884
+
885
+ def delete_invoice_item_object(invoice_item_id, zuora_version = nil)
886
+ @connection.rest_delete("/object/invoice-item/#{invoice_item_id}", zuora_version)
887
+ end
888
+
889
+ ##############################################################################
890
+ # #
891
+ # Invoice Payments #
892
+ # #
893
+ ##############################################################################
894
+
895
+ def create_invoice_payment_object(request, zuora_version = nil)
896
+ @connection.rest_post('/object/invoice-payment', request, zuora_version)
897
+ end
898
+
899
+ def retrieve_invoice_payment_object(invoice_payment_id, fields = nil, zuora_version = nil)
900
+ uri = Addressable::URI.parse("/object/invoice-payment/#{invoice_payment_id}")
901
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
902
+ @connection.rest_get(uri.to_s, zuora_version)
903
+ end
904
+
905
+ def update_invoice_payment_object(invoice_payment_id, request, zuora_version = nil)
906
+ @connection.rest_put("/object/invoice-payment/#{invoice_payment_id}", request, zuora_version)
907
+ end
908
+
909
+ def delete_invoice_payment_object(invoice_payment_id, zuora_version = nil)
910
+ @connection.rest_delete("/object/invoice-payment/#{invoice_payment_id}", zuora_version)
911
+ end
912
+
913
+ ##############################################################################
914
+ # #
915
+ # Invoice Split Items #
916
+ # #
917
+ ##############################################################################
918
+
919
+ def retrieve_invoice_split_item_object(invoice_split_item_id, fields = nil, zuora_version = nil)
920
+ uri = Addressable::URI.parse("/object/invoice-split-item/#{invoice_split_item_id}")
921
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
922
+ @connection.rest_get(uri.to_s, zuora_version)
923
+ end
924
+
925
+ def delete_invoice_split_item_object(invoice_split_item_id, zuora_version = nil)
926
+ @connection.rest_delete("/object/invoice-split-item/#{invoice_split_item_id}", zuora_version)
927
+ end
928
+
929
+ ##############################################################################
930
+ # #
931
+ # Invoice Splits #
932
+ # #
933
+ ##############################################################################
934
+
935
+ def retrieve_invoice_split_object(invoice_split_id, fields = nil, zuora_version = nil)
936
+ uri = Addressable::URI.parse("/object/invoice-split/#{invoice_split_id}")
937
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
938
+ @connection.rest_get(uri.to_s, zuora_version)
939
+ end
940
+
941
+ def delete_invoice_split_object(invoice_split_id, zuora_version = nil)
942
+ @connection.rest_delete("/object/invoice-split/#{invoice_split_id}", zuora_version)
943
+ end
944
+
945
+ ##############################################################################
946
+ # #
947
+ # Invoices #
948
+ # #
949
+ ##############################################################################
950
+
951
+ def reverse_invoice(invoice_id, zuora_version = nil)
952
+ @connection.rest_put("/invoices/#{invoice_id}/reverse", nil, zuora_version)
953
+ end
954
+
955
+ def create_invoice_object(request, zuora_version = nil)
956
+ @connection.rest_post('/object/invoice', request, zuora_version)
957
+ end
958
+
959
+ def retrieve_invoice_object(invoice_id, fields = nil, zuora_version = nil)
960
+ uri = Addressable::URI.parse("/object/invoice/#{invoice_id}")
961
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
962
+ @connection.rest_get(uri.to_s, zuora_version)
963
+ end
964
+
965
+ def update_invoice_object(invoice_id, request, zuora_version = nil)
966
+ @connection.rest_put("/object/invoice/#{invoice_id}", request, zuora_version)
967
+ end
968
+
969
+ def delete_invoice_object(invoice_id, zuora_version = nil)
970
+ @connection.rest_delete("/object/invoice/#{invoice_id}", zuora_version)
971
+ end
972
+
973
+ def get_invoice_pdf_by(identifying_field_sym, identifier, destination_io)
974
+ raise "Unsupported identifying_field_sym. Expected: :id or :invoice_number, Actual: #{identifying_field_sym}" if ![:id, :invoice_number].include?(identifying_field_sym)
975
+
976
+ # Set IO to binary mode
977
+ destination_io.try(:binmode)
978
+
979
+ # Query invoice Id or number
980
+ results = query({ queryString: "select Id, Body from Invoice where #{identifying_field_sym.to_s.camelize} = '#{identifier.gsub("'", %q(\\\'))}'" })
981
+ raise "Cannot find invoice where #{identifying_field_sym.to_s.camelize} = '#{identifier}'" if results.size == 0
982
+
983
+ # Write body to IO
984
+ invoice = results.records.first
985
+ destination_io.try(:write, Base64.decode64(invoice.Body))
986
+
987
+ # Set pointer to beginning of file
988
+ destination_io.try(:rewind)
989
+
990
+ # Return nothing
991
+ nil
992
+
993
+ end
994
+
995
+ ##############################################################################
996
+ # #
997
+ # Journal Runs #
998
+ # #
999
+ ##############################################################################
1000
+
1001
+ def create_journal_run(request, zuora_version = nil)
1002
+ @connection.rest_post('/journal-runs', request, zuora_version)
1003
+ end
1004
+
1005
+ def get_journal_run(journal_run_number, zuora_version = nil)
1006
+ @connection.rest_get("/journal-runs/#{journal_run_number}", zuora_version)
1007
+ end
1008
+
1009
+ def delete_journal_run(journal_run_number, zuora_version = nil)
1010
+ @connection.rest_delete("/journal-runs/#{journal_run_number}", zuora_version)
1011
+ end
1012
+
1013
+ def cancel_journal_run(journal_run_number, zuora_version = nil)
1014
+ @connection.rest_put("/journal-runs/#{journal_run_number}/cancel", nil, zuora_version)
1015
+ end
1016
+
1017
+ ##############################################################################
1018
+ # #
1019
+ # Mass Updater #
1020
+ # #
1021
+ ##############################################################################
1022
+
1023
+ def perform_mass_action(source_filename_or_io, source_content_type, params_hash, zuora_version = nil)
1024
+ payload = { file: Faraday::UploadIO(source_filename_or_io, source_content_type), params: params_hash }
1025
+ @connection.rest_post('/bulk', payload, zuora_version, false)
1026
+ end
1027
+
1028
+ def get_mass_action_result(bulk_key, zuora_version = nil)
1029
+ @connection.rest_get("/bulk/#{bulk_key}", zuora_version)
1030
+ end
1031
+
1032
+ def stop_mass_action(bulk_key, zuora_version = nil)
1033
+ @connection.rest_put("/bulk/#{bulk_key}/stop", zuora_version)
1034
+ end
1035
+
1036
+ ##############################################################################
1037
+ # #
1038
+ # Notification History #
1039
+ # #
1040
+ ##############################################################################
1041
+
1042
+ def get_callout_notification_history(query_params = {}, zuora_version = nil)
1043
+ uri = Addressable::URI.parse('/notification-history/callout')
1044
+ uri.query_values = query_params
1045
+ @connection.rest_get(uri.to_s, zuora_version)
1046
+ end
1047
+
1048
+ def get_email_notification_history(query_params = {}, zuora_version = nil)
1049
+ uri = Addressable::URI.parse('/notification-history/email')
1050
+ uri.query_values = query_params
1051
+ @connection.rest_get(uri.to_s, zuora_version)
1052
+ end
1053
+
1054
+ ##############################################################################
1055
+ # #
1056
+ # Operations #
1057
+ # #
1058
+ ##############################################################################
1059
+
1060
+ def invoice_and_collect(request, zuora_version = nil)
1061
+ @connection.rest_post('/operations/invoice-collect', request, zuora_version)
1062
+ end
1063
+
1064
+ def create_billing_preview(request, zuora_version = nil)
1065
+ @connection.rest_post('/operations/billing-preview', request, zuora_version)
1066
+ end
1067
+
1068
+ ##############################################################################
1069
+ # #
1070
+ # Payment Gateways #
1071
+ # #
1072
+ ##############################################################################
1073
+
1074
+ def get_payment_gateways(zuora_version = nil)
1075
+ @connection.rest_get('/paymentgateways', zuora_version)
1076
+ end
1077
+
1078
+ ##############################################################################
1079
+ # #
1080
+ # Payment Method Snapshots #
1081
+ # #
1082
+ ##############################################################################
1083
+
1084
+ def retrieve_payment_method_snapshot_object(payment_method_snapshot_id, fields = nil, zuora_version = nil)
1085
+ uri = Addressable::URI.parse("/object/payment-method-snapshot/#{payment_method_snapshot_id}")
1086
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1087
+ @connection.rest_get(uri.to_s, zuora_version)
1088
+ end
1089
+
1090
+ def delete_payment_method_snapshot_object(payment_method_snapshot_id, zuora_version = nil)
1091
+ @connection.rest_delete("/object/payment-method-snapshot/#{payment_method_snapshot_id}", zuora_version)
1092
+ end
1093
+
1094
+ ##############################################################################
1095
+ # #
1096
+ # Payment Method Transaction Logs #
1097
+ # #
1098
+ ##############################################################################
1099
+
1100
+ def retrieve_payment_method_transaction_log_object(payment_method_transaction_log_id, fields = nil, zuora_version = nil)
1101
+ uri = Addressable::URI.parse("/object/payment-method-transaction-log/#{payment_method_transaction_log_id}")
1102
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1103
+ @connection.rest_get(uri.to_s, zuora_version)
1104
+ end
1105
+
1106
+ def delete_payment_method_transaction_log_object(payment_method_transaction_log_id, zuora_version = nil)
1107
+ @connection.rest_delete("/object/payment-method-transaction-log/#{payment_method_transaction_log_id}", zuora_version)
1108
+ end
1109
+
1110
+ ##############################################################################
1111
+ # #
1112
+ # Payment Method #
1113
+ # #
1114
+ ##############################################################################
1115
+
1116
+ def create_payment_method(request, zuora_version = nil)
1117
+ @connection.rest_post('/payment-methods/credit-cards', request, zuora_version)
1118
+ end
1119
+
1120
+ def get_payment_method(account_key, zuora_version = nil)
1121
+ @connection.rest_get("/payment-methods/credit-cards/accounts/#{account_key}", zuora_version)
1122
+ end
1123
+
1124
+ def update_payment_method(payment_method_id, request, zuora_version = nil)
1125
+ @connection.rest_put("/payment-methods/credit-cards/#{payment_method_id}", request, zuora_version)
1126
+ end
1127
+
1128
+ def delete_payment_method(payment_method_id, zuora_version = nil)
1129
+ @connection.rest_delete("/payment-methods/credit-cards/#{payment_method_id}", zuora_version)
1130
+ end
1131
+
1132
+ def create_payment_method_decryption(request, zuora_version = nil)
1133
+ @connection.rest_post('/payment-methods/decryption', request, zuora_version)
1134
+ end
1135
+
1136
+ def create_payment_method_object(request, zuora_version = nil)
1137
+ @connection.rest_post('/object/payment-method', request, zuora_version)
1138
+ end
1139
+
1140
+ def retrieve_payment_method_object(payment_method_id, fields = nil, zuora_version = nil)
1141
+ uri = Addressable::URI.parse("/object/payment-method/#{payment_method_id}")
1142
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1143
+ @connection.rest_get(uri.to_s, zuora_version)
1144
+ end
1145
+
1146
+ def update_payment_method_object(payment_method_id, request, zuora_version = nil)
1147
+ @connection.rest_put("/object/payment-method/#{payment_method_id}", request, zuora_version)
1148
+ end
1149
+
1150
+ def delete_payment_method_object(payment_method_id, zuora_version = nil)
1151
+ @connection.rest_delete("/object/payment-method/#{payment_method_id}", zuora_version)
1152
+ end
1153
+
1154
+ ##############################################################################
1155
+ # #
1156
+ # Payment Transaction Logs #
1157
+ # #
1158
+ ##############################################################################
1159
+
1160
+ def retrieve_payment_transaction_log_object(payment_transaction_log_id, fields = nil, zuora_version = nil)
1161
+ uri = Addressable::URI.parse("/object/payment-transaction-log/#{payment_transaction_log_id}")
1162
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1163
+ @connection.rest_get(uri.to_s, zuora_version)
1164
+ end
1165
+
1166
+ def delete_payment_transaction_log_object(payment_transaction_log_id, zuora_version = nil)
1167
+ @connection.rest_delete("/object/payment-transaction-log/#{payment_transaction_log_id}", zuora_version)
1168
+ end
1169
+
1170
+ ##############################################################################
1171
+ # #
1172
+ # Payments #
1173
+ # #
1174
+ ##############################################################################
1175
+
1176
+ def unapply_payment(payment_id, request, zuora_version = nil)
1177
+ @connection.rest_post("/payments/#{payment_id}/unapply", request, zuora_version)
1178
+ end
1179
+
1180
+ def get_payment_parts(payment_id, zuora_version = nil)
1181
+ @connection.rest_get("/payments/#{payment_id}/parts", zuora_version)
1182
+ end
1183
+
1184
+ def get_payment_part_items(payment_id, part_id, zuora_version = nil)
1185
+ @connection.rest_get("/payments/#{payment_id}/parts/#{part_id}/itemparts", zuora_version)
1186
+ end
1187
+
1188
+ def apply_payment(payment_id, request, zuora_version = nil)
1189
+ @connection.rest_post("/payments/#{payment_id}/apply", request, zuora_version)
1190
+ end
1191
+
1192
+ def refund_payment(payment_id, request, zuora_version = nil)
1193
+ @connection.rest_post("/payments/#{payment_id}/refund", request, zuora_version)
1194
+ end
1195
+
1196
+ def create_payment(request, zuora_version = nil)
1197
+ @connection.rest_post('/payments', request, zuora_version)
1198
+ end
1199
+
1200
+ def get_all_payments(zuora_version = nil)
1201
+ @connection.rest_get('/payments', zuora_version)
1202
+ end
1203
+
1204
+ def get_payment_part(payment_id, part_id, zuora_version = nil)
1205
+ @connection.rest_get("/payments/#{payment_id}/parts/#{part_id}", zuora_version)
1206
+ end
1207
+
1208
+ def get_payment_part_item(payment_id, part_id, item_part_id, zuora_version = nil)
1209
+ @connection.rest_get("/payments/#{payment_id}/parts/#{part_id}/itemparts/#{item_part_id}", zuora_version)
1210
+ end
1211
+
1212
+ def transfer_payment(payment_id, request, zuora_version = nil)
1213
+ @connection.rest_post("/payments/#{payment_id}/accounts", request, zuora_version)
1214
+ end
1215
+
1216
+ def cancel_payment(payment_id, zuora_version = nil)
1217
+ @connection.rest_post("/payments/#{payment_id}/cancel", nil, zuora_version)
1218
+ end
1219
+
1220
+ def get_payment(payment_id, zuora_version = nil)
1221
+ @connection.rest_get("/payments/#{payment_id}", zuora_version)
1222
+ end
1223
+
1224
+ def delete_payment(payment_id, zuora_version = nil)
1225
+ @connection.rest_delete("/payments/#{payment_id}", zuora_version)
1226
+ end
1227
+
1228
+ def update_payment(payment_id, request, zuora_version = nil)
1229
+ @connection.rest_put("/payments/#{payment_id}", request, zuora_version)
1230
+ end
1231
+
1232
+ def create_payment_object(request, zuora_version = nil)
1233
+ @connection.rest_post('/object/payment', request, zuora_version)
1234
+ end
1235
+
1236
+ def retrieve_payment_object(payment_id, fields = nil, zuora_version = nil)
1237
+ uri = Addressable::URI.parse("/object/payment/#{payment_id}")
1238
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1239
+ @connection.rest_get(uri.to_s, zuora_version)
1240
+ end
1241
+
1242
+ def update_payment_object(payment_id, request, zuora_version = nil)
1243
+ @connection.rest_put("/object/payment/#{payment_id}", request, zuora_version)
1244
+ end
1245
+
1246
+ def delete_payment_object(payment_id, zuora_version = nil)
1247
+ @connection.rest_delete("/object/payment/#{payment_id}", zuora_version)
1248
+ end
1249
+
1250
+ ##############################################################################
1251
+ # #
1252
+ # Product Features #
1253
+ # #
1254
+ ##############################################################################
1255
+
1256
+ def retrieve_product_feature_object(product_feature_id, fields = nil, zuora_version = nil)
1257
+ uri = Addressable::URI.parse("/object/product-feature/#{product_feature_id}")
1258
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1259
+ @connection.rest_get(uri.to_s, zuora_version)
1260
+ end
1261
+
1262
+ def delete_product_feature_object(product_feature_id, zuora_version = nil)
1263
+ @connection.rest_delete("/object/product-feature/#{product_feature_id}", zuora_version)
1264
+ end
1265
+
1266
+ ##############################################################################
1267
+ # #
1268
+ # Product Rate Plan Charge Tiers #
1269
+ # #
1270
+ ##############################################################################
1271
+
1272
+ def retrieve_product_rate_plan_charge_tier_object(product_rate_plan_charge_tier_id, fields = nil, zuora_version = nil)
1273
+ uri = Addressable::URI.parse("/object/product-rate-plan-charge-tier/#{product_rate_plan_charge_tier_id}")
1274
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1275
+ @connection.rest_get(uri.to_s, zuora_version)
1276
+ end
1277
+
1278
+ def delete_product_rate_plan_charge_tier_object(product_rate_plan_charge_tier_id, zuora_version = nil)
1279
+ @connection.rest_delete("/object/product-rate-plan-charge-tier/#{product_rate_plan_charge_tier_id}", zuora_version)
1280
+ end
1281
+
1282
+ ##############################################################################
1283
+ # #
1284
+ # Product Rate Plan Charges #
1285
+ # #
1286
+ ##############################################################################
1287
+
1288
+ def retrieve_product_rate_plan_charge_object(product_rate_plan_charge_id, fields = nil, zuora_version = nil)
1289
+ uri = Addressable::URI.parse("/object/product-rate-plan-charge/#{product_rate_plan_charge_id}")
1290
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1291
+ @connection.rest_get(uri.to_s, zuora_version)
1292
+ end
1293
+
1294
+ def delete_product_rate_plan_charge_object(product_rate_plan_charge_id, zuora_version = nil)
1295
+ @connection.rest_delete("/object/product-rate-plan-charge/#{product_rate_plan_charge_id}", zuora_version)
1296
+ end
1297
+
1298
+ ##############################################################################
1299
+ # #
1300
+ # Product Rate Plans #
1301
+ # #
1302
+ ##############################################################################
1303
+
1304
+ def create_product_rate_plan_object(request, zuora_version = nil)
1305
+ @connection.rest_post('/object/product-rate-plan', request, zuora_version)
1306
+ end
1307
+
1308
+ def retrieve_product_rate_plan_object(product_rate_plan_id, fields = nil, zuora_version = nil)
1309
+ uri = Addressable::URI.parse("/object/product-rate-plan/#{product_rate_plan_id}")
1310
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1311
+ @connection.rest_get(uri.to_s, zuora_version)
1312
+ end
1313
+
1314
+ def update_product_rate_plan_object(product_rate_plan_id, request, zuora_version = nil)
1315
+ @connection.rest_put("/object/product-rate-plan/#{product_rate_plan_id}", request, zuora_version)
1316
+ end
1317
+
1318
+ def delete_product_rate_plan_object(product_rate_plan_id, zuora_version = nil)
1319
+ @connection.rest_delete("/object/product-rate-plan/#{product_rate_plan_id}", zuora_version)
1320
+ end
1321
+
1322
+ ##############################################################################
1323
+ # #
1324
+ # Products #
1325
+ # #
1326
+ ##############################################################################
1327
+
1328
+ def create_product_object(request, zuora_version = nil)
1329
+ @connection.rest_post('/object/product', request, zuora_version)
1330
+ end
1331
+
1332
+ def retrieve_product_object(product_id, fields = nil, zuora_version = nil)
1333
+ uri = Addressable::URI.parse("/object/product/#{product_id}")
1334
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1335
+ @connection.rest_get(uri.to_s, zuora_version)
1336
+ end
1337
+
1338
+ def update_product_object(product_id, request, zuora_version = nil)
1339
+ @connection.rest_put("/object/product/#{product_id}", request, zuora_version)
1340
+ end
1341
+
1342
+ def delete_product_object(product_id, zuora_version = nil)
1343
+ @connection.rest_delete("/object/product/#{product_id}", zuora_version)
1344
+ end
1345
+
1346
+ ##############################################################################
1347
+ # #
1348
+ # Quotes Document #
1349
+ # #
1350
+ ##############################################################################
1351
+
1352
+ def generate_quote_document(request, zuora_version = nil)
1353
+ @connection.rest_post('/quotes/document', request, zuora_version)
1354
+ end
1355
+
1356
+ ##############################################################################
1357
+ # #
1358
+ # Rate Plan Charge Tiers #
1359
+ # #
1360
+ ##############################################################################
1361
+
1362
+ def retrieve_rate_plan_charge_tier_object(rate_plan_charge_tier_id, fields = nil, zuora_version = nil)
1363
+ uri = Addressable::URI.parse("/object/rate-plan-charge-tier/#{rate_plan_charge_tier_id}")
1364
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1365
+ @connection.rest_get(uri.to_s, zuora_version)
1366
+ end
1367
+
1368
+ def delete_rate_plan_charge_tier_object(rate_plan_charge_tier_id, zuora_version = nil)
1369
+ @connection.rest_delete("/object/rate-plan-charge-tier/#{rate_plan_charge_tier_id}", zuora_version)
1370
+ end
1371
+
1372
+ ##############################################################################
1373
+ # #
1374
+ # Rate Plan Charges #
1375
+ # #
1376
+ ##############################################################################
1377
+
1378
+ def retrieve_rate_plan_charge_object(rate_plan_chargeid, fields = nil, zuora_version = nil)
1379
+ uri = Addressable::URI.parse("/object/rate-plan-charge/#{rate_plan_charge_id}")
1380
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1381
+ @connection.rest_get(uri.to_s, zuora_version)
1382
+ end
1383
+
1384
+ def delete_rate_plan_charge_object(rate_plan_charge_id, zuora_version = nil)
1385
+ @connection.rest_delete("/object/rate-plan-charge/#{rate_plan_charge_id}", zuora_version)
1386
+ end
1387
+
1388
+ ##############################################################################
1389
+ # #
1390
+ # Rate Plans #
1391
+ # #
1392
+ ##############################################################################
1393
+
1394
+ def retrieve_rate_plan_object(rate_plan_id, fields = nil, zuora_version = nil)
1395
+ uri = Addressable::URI.parse("/object/rate-plan/#{rate_plan_id}")
1396
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1397
+ @connection.rest_get(uri.to_s, zuora_version)
1398
+ end
1399
+
1400
+ def delete_rate_plan_object(rate_plan_id, zuora_version = nil)
1401
+ @connection.rest_delete("/object/rate-plan/#{rate_plan_id}", zuora_version)
1402
+ end
1403
+
1404
+ ##############################################################################
1405
+ # #
1406
+ # Refund Invoice Payments #
1407
+ # #
1408
+ ##############################################################################
1409
+
1410
+ def retrieve_refund_invoice_payment_object(refund_invoice_payment_id, fields = nil, zuora_version = nil)
1411
+ uri = Addressable::URI.parse("/object/refund-invoice-payment/#{refund_invoice_payment_id}")
1412
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1413
+ @connection.rest_get(uri.to_s, zuora_version)
1414
+ end
1415
+
1416
+ def delete_refund_invoice_payment_object(refund_invoice_payment_id, zuora_version = nil)
1417
+ @connection.rest_delete("/object/refund-invoice-payment/#{refund_invoice_payment_id}", zuora_version)
1418
+ end
1419
+
1420
+ ##############################################################################
1421
+ # #
1422
+ # Refund Transaction Logs #
1423
+ # #
1424
+ ##############################################################################
1425
+
1426
+ def retrieve_refund_transaction_log_object(refund_transaction_log_id, fields = nil, zuora_version = nil)
1427
+ uri = Addressable::URI.parse("/object/refund-transaction-log/#{refund_transaction_log_id}")
1428
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1429
+ @connection.rest_get(uri.to_s, zuora_version)
1430
+ end
1431
+
1432
+ def delete_refund_transaction_log_object(refund_transaction_log_id, zuora_version = nil)
1433
+ @connection.rest_delete("/object/refund-transaction-log/#{refund_transaction_log_id}", zuora_version)
1434
+ end
1435
+
1436
+ ##############################################################################
1437
+ # #
1438
+ # Refunds #
1439
+ # #
1440
+ ##############################################################################
1441
+
1442
+ def get_refund(refund_id, zuora_version = nil)
1443
+ @connection.rest_get("/refunds/#{refund_id}", zuora_version)
1444
+ end
1445
+
1446
+ def delete_refund(refund_id, zuora_version = nil)
1447
+ @connection.rest_delete("/refunds/#{refund_id}", zuora_version)
1448
+ end
1449
+
1450
+ def update_refund(refund_id, request, zuora_version = nil)
1451
+ @connection.rest_put("/refunds/#{refund_id}", request, zuora_version)
1452
+ end
1453
+
1454
+ def get_refund_part_items(refund_id, refund_part_id, zuora_version = nil)
1455
+ @connection.rest_get("/refunds/#{refund_id}/parts/#{refund_part_id}/itemparts", zuora_version)
1456
+ end
1457
+
1458
+ def get_all_refunds(zuora_version = nil)
1459
+ @connection.rest_get('/refunds', zuora_version)
1460
+ end
1461
+
1462
+ def get_refund_parts(refund_id, zuora_version = nil)
1463
+ @connection.rest_get("/refunds/#{refund_id}/parts", zuora_version)
1464
+ end
1465
+
1466
+ def get_refund_part(refund_id, refund_part_id, zuora_version = nil)
1467
+ @connection.rest_get("/refunds/#{refund_id}/parts/#{refund_part_id}", zuora_version)
1468
+ end
1469
+
1470
+ def get_refund_part_item(refund_id, refund_part_id, item_part_id, zuora_version = nil)
1471
+ @connection.rest_get("/refunds/#{refund_id}/parts/#{refund_part_id}/itemparts/#{item_part_id}", zuora_version)
1472
+ end
1473
+
1474
+ def cancel_refund(refund_id, zuora_version = nil)
1475
+ @connection.rest_post("/refunds/#{refund_id}/cancel", zuora_version)
1476
+ end
1477
+
1478
+ def create_refund_object(request, zuora_version = nil)
1479
+ @connection.rest_post('/object/refund', request, zuora_version)
1480
+ end
1481
+
1482
+ def retrieve_refund_object(refund_id, fields = nil, zuora_version = nil)
1483
+ uri = Addressable::URI.parse("/object/refund/#{refund_id}")
1484
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1485
+ @connection.rest_get(uri.to_s, zuora_version)
1486
+ end
1487
+
1488
+ def update_refund_object(refund_id, request, zuora_version = nil)
1489
+ @connection.rest_put("/object/refund/#{refund_id}", request, zuora_version)
1490
+ end
1491
+
1492
+ def delete_refund_object(refund_id, zuora_version = nil)
1493
+ @connection.rest_delete("/object/refund/#{refund_id}", zuora_version)
1494
+ end
1495
+
1496
+ ##############################################################################
1497
+ # #
1498
+ # Revenue Events #
1499
+ # #
1500
+ ##############################################################################
1501
+
1502
+ def get_revenue_event_details(event_number, zuora_version = nil)
1503
+ @connection.rest_get("/revenue-events/#{event_number}", zuora_version)
1504
+ end
1505
+
1506
+ def get_revenue_event_for_revenue_schedule(revenue_schedule_number, zuora_version = nil)
1507
+ @connection.rest_get("/revenue-events/revenue-schedules/#{revenue_schedule_number}", zuora_version)
1508
+ end
1509
+
1510
+ ##############################################################################
1511
+ # #
1512
+ # Revenue Items #
1513
+ # #
1514
+ ##############################################################################
1515
+
1516
+ def get_revenue_items_by_crs_number(crs_number, zuora_version = nil)
1517
+ @connection.rest_get("/revenue-items/charge-revenue-summaries/#{crs_number}", zuora_version)
1518
+ end
1519
+
1520
+ def get_revenue_items_by_revenue_event_number(event_number, zuora_version = nil)
1521
+ @connection.rest_get("/revenue-items/revenue-events/#{event_number}", zuora_version)
1522
+ end
1523
+
1524
+ def update_revenue_items_by_revenue_event_number(event_number, request, zuora_version = nil)
1525
+ @connection.rest_put("/revenue-items/revenue-events/#{event_number}", request, zuora_version)
1526
+ end
1527
+
1528
+ def get_revenue_items_by_revenue_schedule(revenue_schedule_number, zuora_version = nil)
1529
+ @connection.rest_get("/revenue-items/revenue-schedules/#{revenue_schedule_number}", zuora_version)
1530
+ end
1531
+
1532
+ def update_revenue_items_by_revenue_schedule(revenue_schedule_number, request, zuora_version = nil)
1533
+ @connection.rest_put("/revenue-items/revenue-schedules/#{revenue_schedule_number}", request, zuora_version)
1534
+ end
1535
+
1536
+ ##############################################################################
1537
+ # #
1538
+ # Revenue Rules #
1539
+ # #
1540
+ ##############################################################################
1541
+
1542
+ def get_revenue_recognition_rule_by_subscription_charge(charge_id, zuora_version = nil)
1543
+ @connection.rest_get("/revenue-recognition-rules/subscription-charges/#{charge_id}", zuora_version)
1544
+ end
1545
+
1546
+ def get_revenue_recognition_rule_by_product_rate_plan_charge(charge_id, zuora_version = nil)
1547
+ @connection.rest_get("/revenue-recognition-rules/product-charges/#{charge_id}", zuora_version)
1548
+ end
1549
+
1550
+ ##############################################################################
1551
+ # #
1552
+ # Revenue Schedules #
1553
+ # #
1554
+ ##############################################################################
1555
+
1556
+ def create_revenue_schedule_for_invoice_item_distribute_by_date_range(invoice_item_id, request, zuora_version = nil)
1557
+ @connection.rest_post("/revenue-schedules/invoice-items/#{invoice_item_id}/distribute-revenue-with-date-range", request, zuora_version)
1558
+ end
1559
+
1560
+ def create_revenue_schedule_for_invoice_item_distribute_manually(invoice_item_id, request, zuora_version = nil)
1561
+ @connection.rest_post("/revenue-schedules/invoice-items/#{invoice_item_id}", request, zuora_version)
1562
+ end
1563
+
1564
+ def get_revenue_schedule_by_invoice_item(invoice_item_id, zuora_version = nil)
1565
+ @connection.rest_get("/revenue-schedules/invoice-items/#{invoice_item_id}", zuora_version)
1566
+ end
1567
+
1568
+ def create_revenue_schedule_for_invoice_item_adjustment_distribute_by_date_range(invoice_item_adjustment_id, request, zuora_version = nil)
1569
+ @connection.rest_post("/revenue-schedules/invoice-item-adjustments/#{invoice_item_adjustment_id}/distribute-revenue-with-date-range", request, zuora_version)
1570
+ end
1571
+
1572
+ def create_revenue_schedule_for_invoice_item_adjustment_distribute_manually(invoice_item_adjustment_id, request, zuora_version = nil)
1573
+ @connection.rest_post("/revenue-schedules/invoice-items/#{invoice_item_adjustment_id}", request, zuora_version)
1574
+ end
1575
+
1576
+ def create_revenue_schedule_on_subscription_charge(charge_id, request, zuora_version = nil)
1577
+ @connection.rest_post("/revenue-schedules/subscription-charges/#{charge_id}", request, zuora_version)
1578
+ end
1579
+
1580
+ def get_revenue_schedule_by_subscription_charge(charge_id, zuora_version = nil)
1581
+ @connection.rest_get("/revenue-schedules/subscription-charges/#{charge_id}", zuora_version)
1582
+ end
1583
+
1584
+ def distribute_revenue_across_accounting_periods(revenue_schedule_number, request, zuora_version = nil)
1585
+ @connection.rest_put("/revenue-schedules/#{revenue_schedule_number}/distribute-revenue-across-accounting-periods", request, zuora_version)
1586
+ end
1587
+
1588
+ def distribute_revenue_on_specific_date(revenue_schedule_number, request, zuora_version = nil)
1589
+ @connection.rest_put("/revenue-schedules/#{revenue_schedule_number}/distribute-revenue-on-specific-date", request, zuora_version)
1590
+ end
1591
+
1592
+ def distribute_revenue_by_date_range(revenue_schedule_number, request, zuora_version = nil)
1593
+ @connection.rest_put("/revenue-schedules/#{revenue_schedule_number}/distribute-revenue-with-date-range", request, zuora_version)
1594
+ end
1595
+
1596
+ def delete_revenue_schedule(revenue_schedule_number, zuora_version = nil)
1597
+ @connection.rest_delete("/revenue-schedules/#{revenue_schedule_number}", zuora_version)
1598
+ end
1599
+
1600
+ def get_revenue_schedule_details(revenue_schedule_number, zuora_version = nil)
1601
+ @connection.rest_get("/revenue-schedules/#{revenue_schedule_number}", zuora_version)
1602
+ end
1603
+
1604
+ def get_revenue_schedule_by_invoice_item_adjustment(invoice_item_adjustement_id, zuora_version = nil)
1605
+ @connection.rest_get("/revenue-schedules/invoice-item-adjustments/#{invoice_item_adjustement_id}", zuora_version)
1606
+ end
1607
+
1608
+ def update_revenue_schedule_basic_information(revenue_schedule_number, request, zuora_version = nil)
1609
+ @connection.rest_put("/revenue-schedules/#{revenue_schedule_number}/basic-information", request, zuora_version)
1610
+ end
1611
+
1612
+ def create_revenue_schedule_for_credit_memo_item_distribute_by_date_range(credit_memo_item_id, request, zuora_version = nil)
1613
+ @connection.rest_post("/revenue-schedules/credit-memo-items/#{credit_memo_item_id}/distribute-revenue-with-date-range", request, zuora_version)
1614
+ end
1615
+
1616
+ def create_revenue_schedule_for_debit_memo_item_distribute_by_date_range(debit_memo_item_id, request, zuora_version = nil)
1617
+ @connection.rest_post("/revenue-schedules/debit-memo-items/#{debit_memo_item_id}/distribute-revenue-with-date-range", request, zuora_version)
1618
+ end
1619
+
1620
+ def create_revenue_schedule_for_credit_memo_item_distribute_manually(credit_memo_item_id, request, zuora_version = nil)
1621
+ @connection.rest_post("/revenue-schedules/credit-memo-items/#{credit_memo_item_id}", request, zuora_version)
1622
+ end
1623
+
1624
+ def get_revenue_schedule_by_credit_memo_item(credit_memo_item_id, zuora_version = nil)
1625
+ @connection.rest_get("/revenue-schedules/credit-memo-items/#{credit_memo_item_id}", zuora_version)
1626
+ end
1627
+
1628
+ def create_revenue_schedule_for_debit_memo_item_distribute_manually(debit_memo_item_id, request, zuora_version = nil)
1629
+ @connection.rest_post("/revenue-schedules/debit-memo-items/#{debit_memo_item_id}", request, zuora_version)
1630
+ end
1631
+
1632
+ def get_revenue_schedule_by_debit_memo_item(debit_memo_item_id, zuora_version = nil)
1633
+ @connection.rest_get("/revenue-schedules/debit-memo-items/#{debit_memo_item_id}", zuora_version)
1634
+ end
1635
+
1636
+ def get_all_revenue_schedules_of_product_charges(charge_id, account_id, zuora_version = nil)
1637
+ @connection.rest_get("/revenue-schedules/product-charges/#{charge_id}/#{account_id}", zuora_version)
1638
+ end
1639
+
1640
+ ##############################################################################
1641
+ # #
1642
+ # RSA Signatures #
1643
+ # #
1644
+ ##############################################################################
1645
+
1646
+ def generate_rsa_signature(request, zuora_version = nil)
1647
+ @connection.rest_post('/rsa-signatures', request, zuora_version)
1648
+ end
1649
+
1650
+ def decrypt_rsa_signature(request, zuora_version = nil)
1651
+ @connection.rest_post('/rsa-signatures/decrypt', request, zuora_version)
1652
+ end
1653
+
1654
+ ##############################################################################
1655
+ # #
1656
+ # Settings #
1657
+ # #
1658
+ ##############################################################################
1659
+
1660
+ def get_revenue_automation_start_date(zuora_version = nil)
1661
+ @connection.rest_get('/settings/finance/revenue-automation-start-date', zuora_version)
1662
+ end
1663
+
1664
+ ##############################################################################
1665
+ # #
1666
+ # Subscription Product Features #
1667
+ # #
1668
+ ##############################################################################
1669
+
1670
+ def retrieve_subscription_product_feature_object(subscription_product_feature_id, fields = nil, zuora_version = nil)
1671
+ uri = Addressable::URI.parse("/object/subscription-product-feature/#{subscription_product_feature_id}")
1672
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1673
+ @connection.rest_get(uri.to_s, zuora_version)
1674
+ end
1675
+
1676
+ def delete_subscription_product_feature_object(product_feature_id, zuora_version = nil)
1677
+ @connection.rest_delete("/object/subscription-product-feature/#{subscription_product_feature_id}", zuora_version)
1678
+ end
1679
+
1680
+ ##############################################################################
1681
+ # #
1682
+ # Subscriptions #
1683
+ # #
1684
+ ##############################################################################
1685
+
1686
+ def preview_subscription(request, zuora_version = nil)
1687
+ @connection.rest_post('/subscriptions/preview', request, zuora_version)
1688
+ end
1689
+
1690
+ def create_subscription(request, zuora_version = nil)
1691
+ @connection.rest_post('/subscriptions', request, zuora_version)
1692
+ end
1693
+
1694
+ def get_subscriptions_by_account(account_key, zuora_version = nil)
1695
+ @connection.rest_get("/subscriptions/accounts/#{account_key}", zuora_version)
1696
+ end
1697
+
1698
+ def update_subscription(subscription_key, request, zuora_version = nil)
1699
+ @connection.rest_put("/subscriptions/#{subscription_key}", request, zuora_version)
1700
+ end
1701
+
1702
+ def get_subscription_by_key(subscription_key, zuora_version = nil)
1703
+ @connection.rest_get("/subscriptions/#{subscription_key}", zuora_version)
1704
+ end
1705
+
1706
+ def get_subscription_by_key_and_version(subscription_key, version, zuora_version = nil)
1707
+ @connection.rest_get("/subscriptions/#{subscription_key}/versions/#{version}", zuora_version)
1708
+ end
1709
+
1710
+ def renew_subscription(subscription_key, request, zuora_version = nil)
1711
+ @connection.rest_put("/subscriptions/#{subscription_key}/renew", request, zuora_version)
1712
+ end
1713
+
1714
+ def cancel_subscription(subscription_key, request, zuora_version = nil)
1715
+ @connection.rest_put("/subscriptions/#{subscription_key}/cancel", request, zuora_version)
1716
+ end
1717
+
1718
+ def resume_subscription(subscription_key, request, zuora_version = nil)
1719
+ @connection.rest_put("/subscriptions/#{subscription_key}/resume", request, zuora_version)
1720
+ end
1721
+
1722
+ def suspend_subscription(subscription_key, request, zuora_version = nil)
1723
+ @connection.rest_put("/subscriptions/#{subscription_key}/suspend", request, zuora_version)
1724
+ end
1725
+
1726
+ def retrieve_subscription_object(subscription_id, zuora_version = nil)
1727
+ @connection.rest_get("/object/subscription/#{subscription_id}", zuora_version)
1728
+ end
1729
+
1730
+ def update_subscription_object(subscription_id, request, zuora_version = nil)
1731
+ @connection.rest_put("/object/subscription/#{subscription_id}", request, zuora_version)
1732
+ end
1733
+
1734
+ def delete_subscription_object(subscription_id, zuora_version = nil)
1735
+ @connection.rest_delete("/object/subscription/#{subscription_id}", zuora_version)
1736
+ end
1737
+
1738
+ ##############################################################################
1739
+ # #
1740
+ # Summary Journal Entries #
1741
+ # #
1742
+ ##############################################################################
1743
+
1744
+ def create_summary_journal_entry(request, zuora_version = nil)
1745
+ @connection.rest_post('/journal-entries', request, zuora_version)
1746
+ end
1747
+
1748
+ def get_all_summary_journal_entries_for_journal_run(journal_run_number, zuora_version = nil)
1749
+ @connection.rest_get("/journal-entries/journal-runs/#{journal_run_number}", zuora_version)
1750
+ end
1751
+
1752
+ def get_summary_journal_entry(journal_entry_number, zuora_version = nil)
1753
+ @connection.rest_get("/journal-entries/#{journal_entry_number}", zuora_version)
1754
+ end
1755
+
1756
+ def delete_summary_journal_entry(journal_entry_number, zuora_version = nil)
1757
+ @connection.rest_delete("/journal-entries/#{journal_entry_number}", zuora_version)
1758
+ end
1759
+
1760
+ def cancel_summary_journal_entry(journal_entry_number, zuora_version = nil)
1761
+ @connection.rest_put("/journal-entries/#{journal_entry_number}/cancel", nil, zuora_version)
1762
+ end
1763
+
1764
+ def update_summary_journal_entry_basic_information(journal_entry_number, request, zuora_version = nil)
1765
+ @connection.rest_put("/journal-entries/#{journal_entry_number}/basic-information", request, zuora_version)
1766
+ end
1767
+
1768
+ ##############################################################################
1769
+ # #
1770
+ # Taxation Item #
1771
+ # #
1772
+ ##############################################################################
1773
+
1774
+ def get_taxation_item(taxation_item_id, zuora_version = nil)
1775
+ @connection.rest_get("/taxationitems/#{taxation_item_id}", zuora_version)
1776
+ end
1777
+
1778
+ def delete_taxation_item(taxation_item_id, zuora_version = nil)
1779
+ @connection.rest_delete("/taxationitems/#{taxation_item_id}", zuora_version)
1780
+ end
1781
+
1782
+ def update_taxation_item(taxation_item_id, request, zuora_version = nil)
1783
+ @connection.rest_put("/taxationitems/#{taxation_item_id}", request, zuora_version)
1784
+ end
1785
+
1786
+ def create_taxation_item_for_credit_memo(memo_id, request, zuora_version = nil)
1787
+ @connection.rest_post("/taxationitems/creditmemo/#{memo_id}", request, zuora_version)
1788
+ end
1789
+
1790
+ def create_taxation_item_for_debit_memo(memo_id, request, zuora_version = nil)
1791
+ @connection.rest_post("/taxationitems/debitmemo/#{memo_id}", request, zuora_version)
1792
+ end
1793
+
1794
+ def create_taxation_item_object(request, zuora_version = nil)
1795
+ @connection.rest_post('/object/taxation-item', request, zuora_version)
1796
+ end
1797
+
1798
+ def retrieve_taxation_item_object(taxation_item_id, fields = nil, zuora_version = nil)
1799
+ uri = Addressable::URI.parse("/object/taxation-item/#{taxation_item_id}")
1800
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1801
+ @connection.rest_get(uri.to_s, zuora_version)
1802
+ end
1803
+
1804
+ def update_taxation_item_object(taxation_item_id, request, zuora_version = nil)
1805
+ @connection.rest_put("/object/taxation-item/#{taxation_item_id}", request, zuora_version)
1806
+ end
1807
+
1808
+ def delete_taxation_item_object(taxation_item_id, zuora_version = nil)
1809
+ @connection.rest_delete("/object/taxation-item/#{taxation_item_id}", zuora_version)
1810
+ end
1811
+
1812
+ ##############################################################################
1813
+ # #
1814
+ # Transactions #
1815
+ # #
1816
+ ##############################################################################
1817
+
1818
+ def get_invoice_transactions(account_key, zuora_version = nil)
1819
+ @connection.rest_get("/transactions/invoices/accounts/#{account_key}", zuora_version)
1820
+ end
1821
+
1822
+ def get_payment_transactions(account_key, zuora_version = nil)
1823
+ @connection.rest_get("/transactions/payments/accounts/#{account_key}", zuora_version)
1824
+ end
1825
+
1826
+ ##############################################################################
1827
+ # #
1828
+ # Unit of Measure #
1829
+ # #
1830
+ ##############################################################################
1831
+
1832
+ def create_unit_of_measure_object(request, zuora_version = nil)
1833
+ @connection.rest_post('/object/unit-of-measure', request, zuora_version)
1834
+ end
1835
+
1836
+ def retrieve_unit_of_measure_object(unit_of_measure_id, fields = nil, zuora_version = nil)
1837
+ uri = Addressable::URI.parse("/object/unit-of-measure/#{unit_of_measure_id}")
1838
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1839
+ @connection.rest_get(uri.to_s, zuora_version)
1840
+ end
1841
+
1842
+ def update_unit_of_measure_object(unit_of_measure_id, request, zuora_version = nil)
1843
+ @connection.rest_put("/object/unit-of-measure/#{unit_of_measure_id}", request, zuora_version)
1844
+ end
1845
+
1846
+ def delete_unit_of_measure_object(unit_of_measure_id, zuora_version = nil)
1847
+ @connection.rest_delete("/object/unit-of-measure/#{unit_of_measure_id}", zuora_version)
1848
+ end
1849
+
1850
+ ##############################################################################
1851
+ # #
1852
+ # Usage #
1853
+ # #
1854
+ ##############################################################################
1855
+
1856
+ def post_usage(source_filename_or_io, source_content_type, zuora_version = nil)
1857
+ payload = { file: Faraday::UploadIO(source_filename_or_io, source_content_type) }
1858
+ @connection.rest_post('/usage', payload, zuora_version, false)
1859
+ end
1860
+
1861
+ def get_usage(account_key, zuora_version = nil)
1862
+ @connection.rest_get("/usage/accounts/#{account_key}", zuora_version)
1863
+ end
1864
+
1865
+ def create_usage_object(request, zuora_version = nil)
1866
+ @connection.rest_post('/object/usage', request, zuora_version)
1867
+ end
1868
+
1869
+ def retrieve_usage_object(usage_id, fields = nil, zuora_version = nil)
1870
+ uri = Addressable::URI.parse("/object/usage/#{usage_id}")
1871
+ uri.query_values = { fields: fields.to_s } if !fields.nil?
1872
+ @connection.rest_get(uri.to_s, zuora_version)
1873
+ end
1874
+
1875
+ def update_usage_object(usage_id, request, zuora_version = nil)
1876
+ @connection.rest_put("/object/usage/#{usage_id}", request, zuora_version)
1877
+ end
1878
+
1879
+ def delete_usage_object(usage_id, zuora_version = nil)
1880
+ @connection.rest_delete("/object/usage/#{usage_id}", zuora_version)
1881
+ end
1882
+
1883
+ ##############################################################################
1884
+ # #
1885
+ # Users #
1886
+ # #
1887
+ ##############################################################################
1888
+
1889
+ def send_user_access_request(username, request, zuora_version = nil)
1890
+ @connection.rest_put("/users/#{username}/request-access", request, zuora_version)
1891
+ end
1892
+
1893
+ def accept_user_access(username, zuora_version = nil)
1894
+ @connection.rest_put("/users/#{username}/accept-access", nil, zuora_version)
1895
+ end
1896
+
1897
+ def deny_user_access(username, zuora_version = nil)
1898
+ @connection.rest_put("/users/#{username}/deny-access", nil, zuora_version)
1899
+ end
1900
+
1901
+ def get_accessible_entities_for_user(username, zuora_version = nil)
1902
+ @connection.rest_get("/users/#{username}/accessible-entities", zuora_version)
1903
+ end
1904
+
1905
+ private
1906
+
1907
+ def logger
1908
+ result = @options[:logger] || Logger.new($stdout)
1909
+ log_level = (@options[:log_level] || :info).to_s.upcase
1910
+ result.level = Logger::INFO
1911
+ result.level = Logger.const_get(log_level) if Logger.const_defined?(log_level)
1912
+ result
1913
+ end
1914
+
1915
+ end
1916
+
1917
+ end