processout 2.20.0 → 2.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +52 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Dockerfile +7 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/Makefile +4 -0
  9. data/README.md +12 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/processout/activity.rb +206 -0
  14. data/lib/processout/addon.rb +401 -0
  15. data/lib/processout/alternative_merchant_certificate.rb +115 -0
  16. data/lib/processout/api_request.rb +295 -0
  17. data/lib/processout/api_version.rb +92 -0
  18. data/lib/processout/apple_pay_alternative_merchant_certificates.rb +121 -0
  19. data/lib/processout/balance.rb +92 -0
  20. data/lib/processout/balances.rb +111 -0
  21. data/lib/processout/card.rb +503 -0
  22. data/lib/processout/card_information.rb +164 -0
  23. data/lib/processout/coupon.rb +352 -0
  24. data/lib/processout/customer.rb +755 -0
  25. data/lib/processout/customer_action.rb +81 -0
  26. data/lib/processout/discount.rb +360 -0
  27. data/lib/processout/dunning_action.rb +81 -0
  28. data/lib/processout/errors/authentication_error.rb +9 -0
  29. data/lib/processout/errors/generic_error.rb +9 -0
  30. data/lib/processout/errors/internal_error.rb +9 -0
  31. data/lib/processout/errors/notfound_error.rb +9 -0
  32. data/lib/processout/errors/validation_error.rb +9 -0
  33. data/lib/processout/event.rb +237 -0
  34. data/lib/processout/gateway.rb +210 -0
  35. data/lib/processout/gateway_configuration.rb +346 -0
  36. data/lib/processout/gateway_request.rb +26 -0
  37. data/lib/processout/invoice.rb +984 -0
  38. data/lib/processout/invoice_detail.rb +235 -0
  39. data/lib/processout/invoice_device.rb +92 -0
  40. data/lib/processout/invoice_external_fraud_tools.rb +70 -0
  41. data/lib/processout/invoice_risk.rb +81 -0
  42. data/lib/processout/invoice_shipping.rb +202 -0
  43. data/lib/processout/invoice_tax.rb +81 -0
  44. data/lib/processout/networking/request.rb +102 -0
  45. data/lib/processout/networking/response.rb +67 -0
  46. data/lib/processout/payment_data_network_authentication.rb +70 -0
  47. data/lib/processout/payment_data_three_ds_authentication.rb +70 -0
  48. data/lib/processout/payment_data_three_ds_request.rb +103 -0
  49. data/lib/processout/payout.rb +379 -0
  50. data/lib/processout/payout_item.rb +238 -0
  51. data/lib/processout/plan.rb +368 -0
  52. data/lib/processout/product.rb +368 -0
  53. data/lib/processout/project.rb +353 -0
  54. data/lib/processout/refund.rb +277 -0
  55. data/lib/processout/subscription.rb +910 -0
  56. data/lib/processout/three_ds.rb +158 -0
  57. data/lib/processout/token.rb +493 -0
  58. data/lib/processout/transaction.rb +905 -0
  59. data/lib/processout/transaction_operation.rb +418 -0
  60. data/lib/processout/version.rb +3 -0
  61. data/lib/processout/webhook.rb +237 -0
  62. data/lib/processout/webhook_endpoint.rb +149 -0
  63. data/lib/processout.rb +263 -0
  64. data/processout.gemspec +26 -0
  65. metadata +66 -3
@@ -0,0 +1,910 @@
1
+ # The content of this file was automatically generated
2
+
3
+ require "cgi"
4
+ require "json"
5
+ require "processout/networking/request"
6
+ require "processout/networking/response"
7
+
8
+ module ProcessOut
9
+ class Subscription
10
+
11
+ attr_reader :id
12
+ attr_reader :project
13
+ attr_reader :project_id
14
+ attr_reader :plan
15
+ attr_reader :plan_id
16
+ attr_reader :discounts
17
+ attr_reader :addons
18
+ attr_reader :transactions
19
+ attr_reader :customer
20
+ attr_reader :customer_id
21
+ attr_reader :token
22
+ attr_reader :token_id
23
+ attr_reader :url
24
+ attr_reader :name
25
+ attr_reader :amount
26
+ attr_reader :billable_amount
27
+ attr_reader :discounted_amount
28
+ attr_reader :addons_amount
29
+ attr_reader :currency
30
+ attr_reader :metadata
31
+ attr_reader :interval
32
+ attr_reader :trial_end_at
33
+ attr_reader :activated
34
+ attr_reader :active
35
+ attr_reader :cancel_at
36
+ attr_reader :canceled
37
+ attr_reader :cancellation_reason
38
+ attr_reader :pending_cancellation
39
+ attr_reader :return_url
40
+ attr_reader :cancel_url
41
+ attr_reader :unpaid_state
42
+ attr_reader :sandbox
43
+ attr_reader :created_at
44
+ attr_reader :activated_at
45
+ attr_reader :iterate_at
46
+
47
+
48
+ def id=(val)
49
+ @id = val
50
+ end
51
+
52
+ def project=(val)
53
+ if val.nil?
54
+ @project = val
55
+ return
56
+ end
57
+
58
+ if val.instance_of? Project
59
+ @project = val
60
+ else
61
+ obj = Project.new(@client)
62
+ obj.fill_with_data(val)
63
+ @project = obj
64
+ end
65
+
66
+ end
67
+
68
+ def project_id=(val)
69
+ @project_id = val
70
+ end
71
+
72
+ def plan=(val)
73
+ if val.nil?
74
+ @plan = val
75
+ return
76
+ end
77
+
78
+ if val.instance_of? Plan
79
+ @plan = val
80
+ else
81
+ obj = Plan.new(@client)
82
+ obj.fill_with_data(val)
83
+ @plan = obj
84
+ end
85
+
86
+ end
87
+
88
+ def plan_id=(val)
89
+ @plan_id = val
90
+ end
91
+
92
+ def discounts=(val)
93
+ if val.nil?
94
+ @discounts = []
95
+ return
96
+ end
97
+
98
+ if val.length > 0 and val[0].instance_of? Discount
99
+ @discounts = val
100
+ else
101
+ l = Array.new
102
+ for v in val
103
+ obj = Discount.new(@client)
104
+ obj.fill_with_data(v)
105
+ l.push(obj)
106
+ end
107
+ @discounts = l
108
+ end
109
+
110
+ end
111
+
112
+ def addons=(val)
113
+ if val.nil?
114
+ @addons = []
115
+ return
116
+ end
117
+
118
+ if val.length > 0 and val[0].instance_of? Addon
119
+ @addons = val
120
+ else
121
+ l = Array.new
122
+ for v in val
123
+ obj = Addon.new(@client)
124
+ obj.fill_with_data(v)
125
+ l.push(obj)
126
+ end
127
+ @addons = l
128
+ end
129
+
130
+ end
131
+
132
+ def transactions=(val)
133
+ if val.nil?
134
+ @transactions = []
135
+ return
136
+ end
137
+
138
+ if val.length > 0 and val[0].instance_of? Transaction
139
+ @transactions = val
140
+ else
141
+ l = Array.new
142
+ for v in val
143
+ obj = Transaction.new(@client)
144
+ obj.fill_with_data(v)
145
+ l.push(obj)
146
+ end
147
+ @transactions = l
148
+ end
149
+
150
+ end
151
+
152
+ def customer=(val)
153
+ if val.nil?
154
+ @customer = val
155
+ return
156
+ end
157
+
158
+ if val.instance_of? Customer
159
+ @customer = val
160
+ else
161
+ obj = Customer.new(@client)
162
+ obj.fill_with_data(val)
163
+ @customer = obj
164
+ end
165
+
166
+ end
167
+
168
+ def customer_id=(val)
169
+ @customer_id = val
170
+ end
171
+
172
+ def token=(val)
173
+ if val.nil?
174
+ @token = val
175
+ return
176
+ end
177
+
178
+ if val.instance_of? Token
179
+ @token = val
180
+ else
181
+ obj = Token.new(@client)
182
+ obj.fill_with_data(val)
183
+ @token = obj
184
+ end
185
+
186
+ end
187
+
188
+ def token_id=(val)
189
+ @token_id = val
190
+ end
191
+
192
+ def url=(val)
193
+ @url = val
194
+ end
195
+
196
+ def name=(val)
197
+ @name = val
198
+ end
199
+
200
+ def amount=(val)
201
+ @amount = val
202
+ end
203
+
204
+ def billable_amount=(val)
205
+ @billable_amount = val
206
+ end
207
+
208
+ def discounted_amount=(val)
209
+ @discounted_amount = val
210
+ end
211
+
212
+ def addons_amount=(val)
213
+ @addons_amount = val
214
+ end
215
+
216
+ def currency=(val)
217
+ @currency = val
218
+ end
219
+
220
+ def metadata=(val)
221
+ @metadata = val
222
+ end
223
+
224
+ def interval=(val)
225
+ @interval = val
226
+ end
227
+
228
+ def trial_end_at=(val)
229
+ @trial_end_at = val
230
+ end
231
+
232
+ def activated=(val)
233
+ @activated = val
234
+ end
235
+
236
+ def active=(val)
237
+ @active = val
238
+ end
239
+
240
+ def cancel_at=(val)
241
+ @cancel_at = val
242
+ end
243
+
244
+ def canceled=(val)
245
+ @canceled = val
246
+ end
247
+
248
+ def cancellation_reason=(val)
249
+ @cancellation_reason = val
250
+ end
251
+
252
+ def pending_cancellation=(val)
253
+ @pending_cancellation = val
254
+ end
255
+
256
+ def return_url=(val)
257
+ @return_url = val
258
+ end
259
+
260
+ def cancel_url=(val)
261
+ @cancel_url = val
262
+ end
263
+
264
+ def unpaid_state=(val)
265
+ @unpaid_state = val
266
+ end
267
+
268
+ def sandbox=(val)
269
+ @sandbox = val
270
+ end
271
+
272
+ def created_at=(val)
273
+ @created_at = val
274
+ end
275
+
276
+ def activated_at=(val)
277
+ @activated_at = val
278
+ end
279
+
280
+ def iterate_at=(val)
281
+ @iterate_at = val
282
+ end
283
+
284
+
285
+ # Initializes the Subscription object
286
+ # Params:
287
+ # +client+:: +ProcessOut+ client instance
288
+ # +data+:: data that can be used to fill the object
289
+ def initialize(client, data = {})
290
+ @client = client
291
+
292
+ self.id = data.fetch(:id, nil)
293
+ self.project = data.fetch(:project, nil)
294
+ self.project_id = data.fetch(:project_id, nil)
295
+ self.plan = data.fetch(:plan, nil)
296
+ self.plan_id = data.fetch(:plan_id, nil)
297
+ self.discounts = data.fetch(:discounts, nil)
298
+ self.addons = data.fetch(:addons, nil)
299
+ self.transactions = data.fetch(:transactions, nil)
300
+ self.customer = data.fetch(:customer, nil)
301
+ self.customer_id = data.fetch(:customer_id, nil)
302
+ self.token = data.fetch(:token, nil)
303
+ self.token_id = data.fetch(:token_id, nil)
304
+ self.url = data.fetch(:url, nil)
305
+ self.name = data.fetch(:name, nil)
306
+ self.amount = data.fetch(:amount, nil)
307
+ self.billable_amount = data.fetch(:billable_amount, nil)
308
+ self.discounted_amount = data.fetch(:discounted_amount, nil)
309
+ self.addons_amount = data.fetch(:addons_amount, nil)
310
+ self.currency = data.fetch(:currency, nil)
311
+ self.metadata = data.fetch(:metadata, nil)
312
+ self.interval = data.fetch(:interval, nil)
313
+ self.trial_end_at = data.fetch(:trial_end_at, nil)
314
+ self.activated = data.fetch(:activated, nil)
315
+ self.active = data.fetch(:active, nil)
316
+ self.cancel_at = data.fetch(:cancel_at, nil)
317
+ self.canceled = data.fetch(:canceled, nil)
318
+ self.cancellation_reason = data.fetch(:cancellation_reason, nil)
319
+ self.pending_cancellation = data.fetch(:pending_cancellation, nil)
320
+ self.return_url = data.fetch(:return_url, nil)
321
+ self.cancel_url = data.fetch(:cancel_url, nil)
322
+ self.unpaid_state = data.fetch(:unpaid_state, nil)
323
+ self.sandbox = data.fetch(:sandbox, nil)
324
+ self.created_at = data.fetch(:created_at, nil)
325
+ self.activated_at = data.fetch(:activated_at, nil)
326
+ self.iterate_at = data.fetch(:iterate_at, nil)
327
+
328
+ end
329
+
330
+ # Create a new Subscription using the current client
331
+ def new(data = {})
332
+ Subscription.new(@client, data)
333
+ end
334
+
335
+ # Overrides the JSON marshaller to only send the fields we want
336
+ def to_json(options)
337
+ {
338
+ "id": self.id,
339
+ "project": self.project,
340
+ "project_id": self.project_id,
341
+ "plan": self.plan,
342
+ "plan_id": self.plan_id,
343
+ "discounts": self.discounts,
344
+ "addons": self.addons,
345
+ "transactions": self.transactions,
346
+ "customer": self.customer,
347
+ "customer_id": self.customer_id,
348
+ "token": self.token,
349
+ "token_id": self.token_id,
350
+ "url": self.url,
351
+ "name": self.name,
352
+ "amount": self.amount,
353
+ "billable_amount": self.billable_amount,
354
+ "discounted_amount": self.discounted_amount,
355
+ "addons_amount": self.addons_amount,
356
+ "currency": self.currency,
357
+ "metadata": self.metadata,
358
+ "interval": self.interval,
359
+ "trial_end_at": self.trial_end_at,
360
+ "activated": self.activated,
361
+ "active": self.active,
362
+ "cancel_at": self.cancel_at,
363
+ "canceled": self.canceled,
364
+ "cancellation_reason": self.cancellation_reason,
365
+ "pending_cancellation": self.pending_cancellation,
366
+ "return_url": self.return_url,
367
+ "cancel_url": self.cancel_url,
368
+ "unpaid_state": self.unpaid_state,
369
+ "sandbox": self.sandbox,
370
+ "created_at": self.created_at,
371
+ "activated_at": self.activated_at,
372
+ "iterate_at": self.iterate_at,
373
+ }.to_json
374
+ end
375
+
376
+ # Fills the object with data coming from the API
377
+ # Params:
378
+ # +data+:: +Hash+ of data coming from the API
379
+ def fill_with_data(data)
380
+ if data.nil?
381
+ return self
382
+ end
383
+ if data.include? "id"
384
+ self.id = data["id"]
385
+ end
386
+ if data.include? "project"
387
+ self.project = data["project"]
388
+ end
389
+ if data.include? "project_id"
390
+ self.project_id = data["project_id"]
391
+ end
392
+ if data.include? "plan"
393
+ self.plan = data["plan"]
394
+ end
395
+ if data.include? "plan_id"
396
+ self.plan_id = data["plan_id"]
397
+ end
398
+ if data.include? "discounts"
399
+ self.discounts = data["discounts"]
400
+ end
401
+ if data.include? "addons"
402
+ self.addons = data["addons"]
403
+ end
404
+ if data.include? "transactions"
405
+ self.transactions = data["transactions"]
406
+ end
407
+ if data.include? "customer"
408
+ self.customer = data["customer"]
409
+ end
410
+ if data.include? "customer_id"
411
+ self.customer_id = data["customer_id"]
412
+ end
413
+ if data.include? "token"
414
+ self.token = data["token"]
415
+ end
416
+ if data.include? "token_id"
417
+ self.token_id = data["token_id"]
418
+ end
419
+ if data.include? "url"
420
+ self.url = data["url"]
421
+ end
422
+ if data.include? "name"
423
+ self.name = data["name"]
424
+ end
425
+ if data.include? "amount"
426
+ self.amount = data["amount"]
427
+ end
428
+ if data.include? "billable_amount"
429
+ self.billable_amount = data["billable_amount"]
430
+ end
431
+ if data.include? "discounted_amount"
432
+ self.discounted_amount = data["discounted_amount"]
433
+ end
434
+ if data.include? "addons_amount"
435
+ self.addons_amount = data["addons_amount"]
436
+ end
437
+ if data.include? "currency"
438
+ self.currency = data["currency"]
439
+ end
440
+ if data.include? "metadata"
441
+ self.metadata = data["metadata"]
442
+ end
443
+ if data.include? "interval"
444
+ self.interval = data["interval"]
445
+ end
446
+ if data.include? "trial_end_at"
447
+ self.trial_end_at = data["trial_end_at"]
448
+ end
449
+ if data.include? "activated"
450
+ self.activated = data["activated"]
451
+ end
452
+ if data.include? "active"
453
+ self.active = data["active"]
454
+ end
455
+ if data.include? "cancel_at"
456
+ self.cancel_at = data["cancel_at"]
457
+ end
458
+ if data.include? "canceled"
459
+ self.canceled = data["canceled"]
460
+ end
461
+ if data.include? "cancellation_reason"
462
+ self.cancellation_reason = data["cancellation_reason"]
463
+ end
464
+ if data.include? "pending_cancellation"
465
+ self.pending_cancellation = data["pending_cancellation"]
466
+ end
467
+ if data.include? "return_url"
468
+ self.return_url = data["return_url"]
469
+ end
470
+ if data.include? "cancel_url"
471
+ self.cancel_url = data["cancel_url"]
472
+ end
473
+ if data.include? "unpaid_state"
474
+ self.unpaid_state = data["unpaid_state"]
475
+ end
476
+ if data.include? "sandbox"
477
+ self.sandbox = data["sandbox"]
478
+ end
479
+ if data.include? "created_at"
480
+ self.created_at = data["created_at"]
481
+ end
482
+ if data.include? "activated_at"
483
+ self.activated_at = data["activated_at"]
484
+ end
485
+ if data.include? "iterate_at"
486
+ self.iterate_at = data["iterate_at"]
487
+ end
488
+
489
+ self
490
+ end
491
+
492
+ # Prefills the object with the data passed as parameters
493
+ # Params:
494
+ # +data+:: +Hash+ of data
495
+ def prefill(data)
496
+ if data.nil?
497
+ return self
498
+ end
499
+ self.id = data.fetch(:id, self.id)
500
+ self.project = data.fetch(:project, self.project)
501
+ self.project_id = data.fetch(:project_id, self.project_id)
502
+ self.plan = data.fetch(:plan, self.plan)
503
+ self.plan_id = data.fetch(:plan_id, self.plan_id)
504
+ self.discounts = data.fetch(:discounts, self.discounts)
505
+ self.addons = data.fetch(:addons, self.addons)
506
+ self.transactions = data.fetch(:transactions, self.transactions)
507
+ self.customer = data.fetch(:customer, self.customer)
508
+ self.customer_id = data.fetch(:customer_id, self.customer_id)
509
+ self.token = data.fetch(:token, self.token)
510
+ self.token_id = data.fetch(:token_id, self.token_id)
511
+ self.url = data.fetch(:url, self.url)
512
+ self.name = data.fetch(:name, self.name)
513
+ self.amount = data.fetch(:amount, self.amount)
514
+ self.billable_amount = data.fetch(:billable_amount, self.billable_amount)
515
+ self.discounted_amount = data.fetch(:discounted_amount, self.discounted_amount)
516
+ self.addons_amount = data.fetch(:addons_amount, self.addons_amount)
517
+ self.currency = data.fetch(:currency, self.currency)
518
+ self.metadata = data.fetch(:metadata, self.metadata)
519
+ self.interval = data.fetch(:interval, self.interval)
520
+ self.trial_end_at = data.fetch(:trial_end_at, self.trial_end_at)
521
+ self.activated = data.fetch(:activated, self.activated)
522
+ self.active = data.fetch(:active, self.active)
523
+ self.cancel_at = data.fetch(:cancel_at, self.cancel_at)
524
+ self.canceled = data.fetch(:canceled, self.canceled)
525
+ self.cancellation_reason = data.fetch(:cancellation_reason, self.cancellation_reason)
526
+ self.pending_cancellation = data.fetch(:pending_cancellation, self.pending_cancellation)
527
+ self.return_url = data.fetch(:return_url, self.return_url)
528
+ self.cancel_url = data.fetch(:cancel_url, self.cancel_url)
529
+ self.unpaid_state = data.fetch(:unpaid_state, self.unpaid_state)
530
+ self.sandbox = data.fetch(:sandbox, self.sandbox)
531
+ self.created_at = data.fetch(:created_at, self.created_at)
532
+ self.activated_at = data.fetch(:activated_at, self.activated_at)
533
+ self.iterate_at = data.fetch(:iterate_at, self.iterate_at)
534
+
535
+ self
536
+ end
537
+
538
+ # Get the addons applied to the subscription.
539
+ # Params:
540
+ # +options+:: +Hash+ of options
541
+ def fetch_addons(options = {})
542
+ self.prefill(options)
543
+
544
+ request = Request.new(@client)
545
+ path = "/subscriptions/" + CGI.escape(@id) + "/addons"
546
+ data = {
547
+
548
+ }
549
+
550
+ response = Response.new(request.get(path, data, options))
551
+ return_values = Array.new
552
+
553
+ a = Array.new
554
+ body = response.body
555
+ for v in body['addons']
556
+ tmp = Addon.new(@client)
557
+ tmp.fill_with_data(v)
558
+ a.push(tmp)
559
+ end
560
+
561
+ return_values.push(a)
562
+
563
+
564
+
565
+ return_values[0]
566
+ end
567
+
568
+ # Find a subscription's addon by its ID.
569
+ # Params:
570
+ # +addon_id+:: ID of the addon
571
+ # +options+:: +Hash+ of options
572
+ def find_addon(addon_id, options = {})
573
+ self.prefill(options)
574
+
575
+ request = Request.new(@client)
576
+ path = "/subscriptions/" + CGI.escape(@id) + "/addons/" + CGI.escape(addon_id) + ""
577
+ data = {
578
+
579
+ }
580
+
581
+ response = Response.new(request.get(path, data, options))
582
+ return_values = Array.new
583
+
584
+ body = response.body
585
+ body = body["addon"]
586
+ addon = Addon.new(@client)
587
+ return_values.push(addon.fill_with_data(body))
588
+
589
+
590
+ return_values[0]
591
+ end
592
+
593
+ # Delete an addon applied to a subscription.
594
+ # Params:
595
+ # +addon_id+:: ID of the addon or plan to be removed from the subscription
596
+ # +options+:: +Hash+ of options
597
+ def delete_addon(addon_id, options = {})
598
+ self.prefill(options)
599
+
600
+ request = Request.new(@client)
601
+ path = "/subscriptions/" + CGI.escape(@id) + "/addons/" + CGI.escape(addon_id) + ""
602
+ data = {
603
+ "prorate" => options.fetch(:prorate, nil),
604
+ "proration_date" => options.fetch(:proration_date, nil),
605
+ "preview" => options.fetch(:preview, nil)
606
+ }
607
+
608
+ response = Response.new(request.delete(path, data, options))
609
+ return_values = Array.new
610
+
611
+ return_values.push(response.success)
612
+
613
+
614
+ return_values[0]
615
+ end
616
+
617
+ # Get the customer owning the subscription.
618
+ # Params:
619
+ # +options+:: +Hash+ of options
620
+ def fetch_customer(options = {})
621
+ self.prefill(options)
622
+
623
+ request = Request.new(@client)
624
+ path = "/subscriptions/" + CGI.escape(@id) + "/customers"
625
+ data = {
626
+
627
+ }
628
+
629
+ response = Response.new(request.get(path, data, options))
630
+ return_values = Array.new
631
+
632
+ body = response.body
633
+ body = body["customer"]
634
+ customer = Customer.new(@client)
635
+ return_values.push(customer.fill_with_data(body))
636
+
637
+
638
+ return_values[0]
639
+ end
640
+
641
+ # Get the discounts applied to the subscription.
642
+ # Params:
643
+ # +options+:: +Hash+ of options
644
+ def fetch_discounts(options = {})
645
+ self.prefill(options)
646
+
647
+ request = Request.new(@client)
648
+ path = "/subscriptions/" + CGI.escape(@id) + "/discounts"
649
+ data = {
650
+
651
+ }
652
+
653
+ response = Response.new(request.get(path, data, options))
654
+ return_values = Array.new
655
+
656
+ a = Array.new
657
+ body = response.body
658
+ for v in body['discounts']
659
+ tmp = Discount.new(@client)
660
+ tmp.fill_with_data(v)
661
+ a.push(tmp)
662
+ end
663
+
664
+ return_values.push(a)
665
+
666
+
667
+
668
+ return_values[0]
669
+ end
670
+
671
+ # Find a subscription's discount by its ID.
672
+ # Params:
673
+ # +discount_id+:: ID of the discount
674
+ # +options+:: +Hash+ of options
675
+ def find_discount(discount_id, options = {})
676
+ self.prefill(options)
677
+
678
+ request = Request.new(@client)
679
+ path = "/subscriptions/" + CGI.escape(@id) + "/discounts/" + CGI.escape(discount_id) + ""
680
+ data = {
681
+
682
+ }
683
+
684
+ response = Response.new(request.get(path, data, options))
685
+ return_values = Array.new
686
+
687
+ body = response.body
688
+ body = body["discount"]
689
+ discount = Discount.new(@client)
690
+ return_values.push(discount.fill_with_data(body))
691
+
692
+
693
+ return_values[0]
694
+ end
695
+
696
+ # Delete a discount applied to a subscription.
697
+ # Params:
698
+ # +discount_id+:: ID of the discount or coupon to be removed from the subscription
699
+ # +options+:: +Hash+ of options
700
+ def delete_discount(discount_id, options = {})
701
+ self.prefill(options)
702
+
703
+ request = Request.new(@client)
704
+ path = "/subscriptions/" + CGI.escape(@id) + "/discounts/" + CGI.escape(discount_id) + ""
705
+ data = {
706
+
707
+ }
708
+
709
+ response = Response.new(request.delete(path, data, options))
710
+ return_values = Array.new
711
+
712
+ return_values.push(response.success)
713
+
714
+
715
+ return_values[0]
716
+ end
717
+
718
+ # Get the subscriptions past transactions.
719
+ # Params:
720
+ # +options+:: +Hash+ of options
721
+ def fetch_transactions(options = {})
722
+ self.prefill(options)
723
+
724
+ request = Request.new(@client)
725
+ path = "/subscriptions/" + CGI.escape(@id) + "/transactions"
726
+ data = {
727
+
728
+ }
729
+
730
+ response = Response.new(request.get(path, data, options))
731
+ return_values = Array.new
732
+
733
+ a = Array.new
734
+ body = response.body
735
+ for v in body['transactions']
736
+ tmp = Transaction.new(@client)
737
+ tmp.fill_with_data(v)
738
+ a.push(tmp)
739
+ end
740
+
741
+ return_values.push(a)
742
+
743
+
744
+
745
+ return_values[0]
746
+ end
747
+
748
+ # Get all the subscriptions.
749
+ # Params:
750
+ # +options+:: +Hash+ of options
751
+ def all(options = {})
752
+ self.prefill(options)
753
+
754
+ request = Request.new(@client)
755
+ path = "/subscriptions"
756
+ data = {
757
+
758
+ }
759
+
760
+ response = Response.new(request.get(path, data, options))
761
+ return_values = Array.new
762
+
763
+ a = Array.new
764
+ body = response.body
765
+ for v in body['subscriptions']
766
+ tmp = Subscription.new(@client)
767
+ tmp.fill_with_data(v)
768
+ a.push(tmp)
769
+ end
770
+
771
+ return_values.push(a)
772
+
773
+
774
+
775
+ return_values[0]
776
+ end
777
+
778
+ # Create a new subscription for the given customer.
779
+ # Params:
780
+ # +options+:: +Hash+ of options
781
+ def create(options = {})
782
+ self.prefill(options)
783
+
784
+ request = Request.new(@client)
785
+ path = "/subscriptions"
786
+ data = {
787
+ "plan_id" => @plan_id,
788
+ "cancel_at" => @cancel_at,
789
+ "name" => @name,
790
+ "amount" => @amount,
791
+ "currency" => @currency,
792
+ "metadata" => @metadata,
793
+ "interval" => @interval,
794
+ "trial_end_at" => @trial_end_at,
795
+ "customer_id" => @customer_id,
796
+ "return_url" => @return_url,
797
+ "cancel_url" => @cancel_url,
798
+ "source" => options.fetch(:source, nil),
799
+ "coupon_id" => options.fetch(:coupon_id, nil)
800
+ }
801
+
802
+ response = Response.new(request.post(path, data, options))
803
+ return_values = Array.new
804
+
805
+ body = response.body
806
+ body = body["subscription"]
807
+
808
+
809
+ return_values.push(self.fill_with_data(body))
810
+
811
+
812
+
813
+ return_values[0]
814
+ end
815
+
816
+ # Find a subscription by its ID.
817
+ # Params:
818
+ # +subscription_id+:: ID of the subscription
819
+ # +options+:: +Hash+ of options
820
+ def find(subscription_id, options = {})
821
+ self.prefill(options)
822
+
823
+ request = Request.new(@client)
824
+ path = "/subscriptions/" + CGI.escape(subscription_id) + ""
825
+ data = {
826
+
827
+ }
828
+
829
+ response = Response.new(request.get(path, data, options))
830
+ return_values = Array.new
831
+
832
+ body = response.body
833
+ body = body["subscription"]
834
+
835
+
836
+ obj = Subscription.new(@client)
837
+ return_values.push(obj.fill_with_data(body))
838
+
839
+
840
+
841
+ return_values[0]
842
+ end
843
+
844
+ # Save the updated subscription attributes.
845
+ # Params:
846
+ # +options+:: +Hash+ of options
847
+ def save(options = {})
848
+ self.prefill(options)
849
+
850
+ request = Request.new(@client)
851
+ path = "/subscriptions/" + CGI.escape(@id) + ""
852
+ data = {
853
+ "plan_id" => @plan_id,
854
+ "name" => @name,
855
+ "amount" => @amount,
856
+ "interval" => @interval,
857
+ "trial_end_at" => @trial_end_at,
858
+ "metadata" => @metadata,
859
+ "coupon_id" => options.fetch(:coupon_id, nil),
860
+ "source" => options.fetch(:source, nil),
861
+ "prorate" => options.fetch(:prorate, nil),
862
+ "proration_date" => options.fetch(:proration_date, nil),
863
+ "preview" => options.fetch(:preview, nil)
864
+ }
865
+
866
+ response = Response.new(request.put(path, data, options))
867
+ return_values = Array.new
868
+
869
+ body = response.body
870
+ body = body["subscription"]
871
+
872
+
873
+ return_values.push(self.fill_with_data(body))
874
+
875
+
876
+
877
+ return_values[0]
878
+ end
879
+
880
+ # Cancel a subscription. The reason may be provided as well.
881
+ # Params:
882
+ # +options+:: +Hash+ of options
883
+ def cancel(options = {})
884
+ self.prefill(options)
885
+
886
+ request = Request.new(@client)
887
+ path = "/subscriptions/" + CGI.escape(@id) + ""
888
+ data = {
889
+ "cancel_at" => @cancel_at,
890
+ "cancellation_reason" => @cancellation_reason,
891
+ "cancel_at_end" => options.fetch(:cancel_at_end, nil)
892
+ }
893
+
894
+ response = Response.new(request.delete(path, data, options))
895
+ return_values = Array.new
896
+
897
+ body = response.body
898
+ body = body["subscription"]
899
+
900
+
901
+ return_values.push(self.fill_with_data(body))
902
+
903
+
904
+
905
+ return_values[0]
906
+ end
907
+
908
+
909
+ end
910
+ end