processout 4.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,916 +0,0 @@
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.key?("addon") ? body["addon"] : nil
586
- if !body.nil?
587
- addon = Addon.new(@client)
588
- return_values.push(addon.fill_with_data(body))
589
- end
590
-
591
-
592
- return_values[0]
593
- end
594
-
595
- # Delete an addon applied to a subscription.
596
- # Params:
597
- # +addon_id+:: ID of the addon or plan to be removed from the subscription
598
- # +options+:: +Hash+ of options
599
- def delete_addon(addon_id, options = {})
600
- self.prefill(options)
601
-
602
- request = Request.new(@client)
603
- path = "/subscriptions/" + CGI.escape(@id) + "/addons/" + CGI.escape(addon_id) + ""
604
- data = {
605
- "prorate" => options.fetch(:prorate, nil),
606
- "proration_date" => options.fetch(:proration_date, nil),
607
- "preview" => options.fetch(:preview, nil)
608
- }
609
-
610
- response = Response.new(request.delete(path, data, options))
611
- return_values = Array.new
612
-
613
- return_values.push(response.success)
614
-
615
-
616
- return_values[0]
617
- end
618
-
619
- # Get the customer owning the subscription.
620
- # Params:
621
- # +options+:: +Hash+ of options
622
- def fetch_customer(options = {})
623
- self.prefill(options)
624
-
625
- request = Request.new(@client)
626
- path = "/subscriptions/" + CGI.escape(@id) + "/customers"
627
- data = {
628
-
629
- }
630
-
631
- response = Response.new(request.get(path, data, options))
632
- return_values = Array.new
633
-
634
- body = response.body
635
- body = body.key?("customer") ? body["customer"] : nil
636
- if !body.nil?
637
- customer = Customer.new(@client)
638
- return_values.push(customer.fill_with_data(body))
639
- end
640
-
641
-
642
- return_values[0]
643
- end
644
-
645
- # Get the discounts applied to the subscription.
646
- # Params:
647
- # +options+:: +Hash+ of options
648
- def fetch_discounts(options = {})
649
- self.prefill(options)
650
-
651
- request = Request.new(@client)
652
- path = "/subscriptions/" + CGI.escape(@id) + "/discounts"
653
- data = {
654
-
655
- }
656
-
657
- response = Response.new(request.get(path, data, options))
658
- return_values = Array.new
659
-
660
- a = Array.new
661
- body = response.body
662
- for v in body['discounts']
663
- tmp = Discount.new(@client)
664
- tmp.fill_with_data(v)
665
- a.push(tmp)
666
- end
667
-
668
- return_values.push(a)
669
-
670
-
671
-
672
- return_values[0]
673
- end
674
-
675
- # Find a subscription's discount by its ID.
676
- # Params:
677
- # +discount_id+:: ID of the discount
678
- # +options+:: +Hash+ of options
679
- def find_discount(discount_id, options = {})
680
- self.prefill(options)
681
-
682
- request = Request.new(@client)
683
- path = "/subscriptions/" + CGI.escape(@id) + "/discounts/" + CGI.escape(discount_id) + ""
684
- data = {
685
-
686
- }
687
-
688
- response = Response.new(request.get(path, data, options))
689
- return_values = Array.new
690
-
691
- body = response.body
692
- body = body.key?("discount") ? body["discount"] : nil
693
- if !body.nil?
694
- discount = Discount.new(@client)
695
- return_values.push(discount.fill_with_data(body))
696
- end
697
-
698
-
699
- return_values[0]
700
- end
701
-
702
- # Delete a discount applied to a subscription.
703
- # Params:
704
- # +discount_id+:: ID of the discount or coupon to be removed from the subscription
705
- # +options+:: +Hash+ of options
706
- def delete_discount(discount_id, options = {})
707
- self.prefill(options)
708
-
709
- request = Request.new(@client)
710
- path = "/subscriptions/" + CGI.escape(@id) + "/discounts/" + CGI.escape(discount_id) + ""
711
- data = {
712
-
713
- }
714
-
715
- response = Response.new(request.delete(path, data, options))
716
- return_values = Array.new
717
-
718
- return_values.push(response.success)
719
-
720
-
721
- return_values[0]
722
- end
723
-
724
- # Get the subscriptions past transactions.
725
- # Params:
726
- # +options+:: +Hash+ of options
727
- def fetch_transactions(options = {})
728
- self.prefill(options)
729
-
730
- request = Request.new(@client)
731
- path = "/subscriptions/" + CGI.escape(@id) + "/transactions"
732
- data = {
733
-
734
- }
735
-
736
- response = Response.new(request.get(path, data, options))
737
- return_values = Array.new
738
-
739
- a = Array.new
740
- body = response.body
741
- for v in body['transactions']
742
- tmp = Transaction.new(@client)
743
- tmp.fill_with_data(v)
744
- a.push(tmp)
745
- end
746
-
747
- return_values.push(a)
748
-
749
-
750
-
751
- return_values[0]
752
- end
753
-
754
- # Get all the subscriptions.
755
- # Params:
756
- # +options+:: +Hash+ of options
757
- def all(options = {})
758
- self.prefill(options)
759
-
760
- request = Request.new(@client)
761
- path = "/subscriptions"
762
- data = {
763
-
764
- }
765
-
766
- response = Response.new(request.get(path, data, options))
767
- return_values = Array.new
768
-
769
- a = Array.new
770
- body = response.body
771
- for v in body['subscriptions']
772
- tmp = Subscription.new(@client)
773
- tmp.fill_with_data(v)
774
- a.push(tmp)
775
- end
776
-
777
- return_values.push(a)
778
-
779
-
780
-
781
- return_values[0]
782
- end
783
-
784
- # Create a new subscription for the given customer.
785
- # Params:
786
- # +options+:: +Hash+ of options
787
- def create(options = {})
788
- self.prefill(options)
789
-
790
- request = Request.new(@client)
791
- path = "/subscriptions"
792
- data = {
793
- "plan_id" => @plan_id,
794
- "cancel_at" => @cancel_at,
795
- "name" => @name,
796
- "amount" => @amount,
797
- "currency" => @currency,
798
- "metadata" => @metadata,
799
- "interval" => @interval,
800
- "trial_end_at" => @trial_end_at,
801
- "customer_id" => @customer_id,
802
- "return_url" => @return_url,
803
- "cancel_url" => @cancel_url,
804
- "source" => options.fetch(:source, nil),
805
- "coupon_id" => options.fetch(:coupon_id, nil)
806
- }
807
-
808
- response = Response.new(request.post(path, data, options))
809
- return_values = Array.new
810
-
811
- body = response.body
812
- body = body.key?("subscription") ? body["subscription"] : nil
813
-
814
-
815
- return_values.push(self.fill_with_data(body))
816
-
817
-
818
-
819
- return_values[0]
820
- end
821
-
822
- # Find a subscription by its ID.
823
- # Params:
824
- # +subscription_id+:: ID of the subscription
825
- # +options+:: +Hash+ of options
826
- def find(subscription_id, options = {})
827
- self.prefill(options)
828
-
829
- request = Request.new(@client)
830
- path = "/subscriptions/" + CGI.escape(subscription_id) + ""
831
- data = {
832
-
833
- }
834
-
835
- response = Response.new(request.get(path, data, options))
836
- return_values = Array.new
837
-
838
- body = response.body
839
- body = body.key?("subscription") ? body["subscription"] : nil
840
-
841
-
842
- obj = Subscription.new(@client)
843
- return_values.push(obj.fill_with_data(body))
844
-
845
-
846
-
847
- return_values[0]
848
- end
849
-
850
- # Save the updated subscription attributes.
851
- # Params:
852
- # +options+:: +Hash+ of options
853
- def save(options = {})
854
- self.prefill(options)
855
-
856
- request = Request.new(@client)
857
- path = "/subscriptions/" + CGI.escape(@id) + ""
858
- data = {
859
- "plan_id" => @plan_id,
860
- "name" => @name,
861
- "amount" => @amount,
862
- "interval" => @interval,
863
- "trial_end_at" => @trial_end_at,
864
- "metadata" => @metadata,
865
- "coupon_id" => options.fetch(:coupon_id, nil),
866
- "source" => options.fetch(:source, nil),
867
- "prorate" => options.fetch(:prorate, nil),
868
- "proration_date" => options.fetch(:proration_date, nil),
869
- "preview" => options.fetch(:preview, nil)
870
- }
871
-
872
- response = Response.new(request.put(path, data, options))
873
- return_values = Array.new
874
-
875
- body = response.body
876
- body = body.key?("subscription") ? body["subscription"] : nil
877
-
878
-
879
- return_values.push(self.fill_with_data(body))
880
-
881
-
882
-
883
- return_values[0]
884
- end
885
-
886
- # Cancel a subscription. The reason may be provided as well.
887
- # Params:
888
- # +options+:: +Hash+ of options
889
- def cancel(options = {})
890
- self.prefill(options)
891
-
892
- request = Request.new(@client)
893
- path = "/subscriptions/" + CGI.escape(@id) + ""
894
- data = {
895
- "cancel_at" => @cancel_at,
896
- "cancellation_reason" => @cancellation_reason,
897
- "cancel_at_end" => options.fetch(:cancel_at_end, nil)
898
- }
899
-
900
- response = Response.new(request.delete(path, data, options))
901
- return_values = Array.new
902
-
903
- body = response.body
904
- body = body.key?("subscription") ? body["subscription"] : nil
905
-
906
-
907
- return_values.push(self.fill_with_data(body))
908
-
909
-
910
-
911
- return_values[0]
912
- end
913
-
914
-
915
- end
916
- end