processout 1.2.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,7 @@ module ProcessOut
9
9
 
10
10
  attr_reader :id
11
11
  attr_reader :project
12
+ attr_reader :project_id
12
13
  attr_reader :url
13
14
  attr_reader :name
14
15
  attr_reader :amount
@@ -27,6 +28,11 @@ module ProcessOut
27
28
  end
28
29
 
29
30
  def project=(val)
31
+ if val.nil?
32
+ @project = val
33
+ return
34
+ end
35
+
30
36
  if val.instance_of? Project
31
37
  @project = val
32
38
  else
@@ -37,6 +43,10 @@ module ProcessOut
37
43
 
38
44
  end
39
45
 
46
+ def project_id=(val)
47
+ @project_id = val
48
+ end
49
+
40
50
  def url=(val)
41
51
  @url = val
42
52
  end
@@ -91,6 +101,7 @@ module ProcessOut
91
101
 
92
102
  self.id = data.fetch(:id, nil)
93
103
  self.project = data.fetch(:project, nil)
104
+ self.project_id = data.fetch(:project_id, nil)
94
105
  self.url = data.fetch(:url, nil)
95
106
  self.name = data.fetch(:name, nil)
96
107
  self.amount = data.fetch(:amount, nil)
@@ -123,6 +134,9 @@ module ProcessOut
123
134
  if data.include? "project"
124
135
  self.project = data["project"]
125
136
  end
137
+ if data.include? "project_id"
138
+ self.project_id = data["project_id"]
139
+ end
126
140
  if data.include? "url"
127
141
  self.url = data["url"]
128
142
  end
@@ -169,6 +183,7 @@ module ProcessOut
169
183
  end
170
184
  self.id = data.fetch(:id, self.id)
171
185
  self.project = data.fetch(:project, self.project)
186
+ self.project_id = data.fetch(:project_id, self.project_id)
172
187
  self.url = data.fetch(:url, self.url)
173
188
  self.name = data.fetch(:name, self.name)
174
189
  self.amount = data.fetch(:amount, self.amount)
@@ -8,9 +8,15 @@ module ProcessOut
8
8
  class Project
9
9
 
10
10
  attr_reader :id
11
+ attr_reader :supervisor_project
12
+ attr_reader :supervisor_project_id
13
+ attr_reader :api_version
11
14
  attr_reader :name
12
15
  attr_reader :logo_url
13
16
  attr_reader :email
17
+ attr_reader :default_currency
18
+ attr_reader :private_key
19
+ attr_reader :dunning_configuration
14
20
  attr_reader :created_at
15
21
 
16
22
 
@@ -18,6 +24,42 @@ module ProcessOut
18
24
  @id = val
19
25
  end
20
26
 
27
+ def supervisor_project=(val)
28
+ if val.nil?
29
+ @supervisor_project = val
30
+ return
31
+ end
32
+
33
+ if val.instance_of? Project
34
+ @supervisor_project = val
35
+ else
36
+ obj = Project.new(@client)
37
+ obj.fill_with_data(val)
38
+ @supervisor_project = obj
39
+ end
40
+
41
+ end
42
+
43
+ def supervisor_project_id=(val)
44
+ @supervisor_project_id = val
45
+ end
46
+
47
+ def api_version=(val)
48
+ if val.nil?
49
+ @api_version = val
50
+ return
51
+ end
52
+
53
+ if val.instance_of? APIVersion
54
+ @api_version = val
55
+ else
56
+ obj = APIVersion.new(@client)
57
+ obj.fill_with_data(val)
58
+ @api_version = obj
59
+ end
60
+
61
+ end
62
+
21
63
  def name=(val)
22
64
  @name = val
23
65
  end
@@ -30,6 +72,34 @@ module ProcessOut
30
72
  @email = val
31
73
  end
32
74
 
75
+ def default_currency=(val)
76
+ @default_currency = val
77
+ end
78
+
79
+ def private_key=(val)
80
+ @private_key = val
81
+ end
82
+
83
+ def dunning_configuration=(val)
84
+ if val.nil?
85
+ @dunning_configuration = []
86
+ return
87
+ end
88
+
89
+ if val.length > 0 and val[0].instance_of? DunningAction
90
+ @dunning_configuration = val
91
+ else
92
+ l = Array.new
93
+ for v in val
94
+ obj = DunningAction.new(@client)
95
+ obj.fill_with_data(v)
96
+ l.push(obj)
97
+ end
98
+ @dunning_configuration = l
99
+ end
100
+
101
+ end
102
+
33
103
  def created_at=(val)
34
104
  @created_at = val
35
105
  end
@@ -43,9 +113,15 @@ module ProcessOut
43
113
  @client = client
44
114
 
45
115
  self.id = data.fetch(:id, nil)
116
+ self.supervisor_project = data.fetch(:supervisor_project, nil)
117
+ self.supervisor_project_id = data.fetch(:supervisor_project_id, nil)
118
+ self.api_version = data.fetch(:api_version, nil)
46
119
  self.name = data.fetch(:name, nil)
47
120
  self.logo_url = data.fetch(:logo_url, nil)
48
121
  self.email = data.fetch(:email, nil)
122
+ self.default_currency = data.fetch(:default_currency, nil)
123
+ self.private_key = data.fetch(:private_key, nil)
124
+ self.dunning_configuration = data.fetch(:dunning_configuration, nil)
49
125
  self.created_at = data.fetch(:created_at, nil)
50
126
 
51
127
  end
@@ -65,6 +141,15 @@ module ProcessOut
65
141
  if data.include? "id"
66
142
  self.id = data["id"]
67
143
  end
144
+ if data.include? "supervisor_project"
145
+ self.supervisor_project = data["supervisor_project"]
146
+ end
147
+ if data.include? "supervisor_project_id"
148
+ self.supervisor_project_id = data["supervisor_project_id"]
149
+ end
150
+ if data.include? "api_version"
151
+ self.api_version = data["api_version"]
152
+ end
68
153
  if data.include? "name"
69
154
  self.name = data["name"]
70
155
  end
@@ -74,6 +159,15 @@ module ProcessOut
74
159
  if data.include? "email"
75
160
  self.email = data["email"]
76
161
  end
162
+ if data.include? "default_currency"
163
+ self.default_currency = data["default_currency"]
164
+ end
165
+ if data.include? "private_key"
166
+ self.private_key = data["private_key"]
167
+ end
168
+ if data.include? "dunning_configuration"
169
+ self.dunning_configuration = data["dunning_configuration"]
170
+ end
77
171
  if data.include? "created_at"
78
172
  self.created_at = data["created_at"]
79
173
  end
@@ -89,9 +183,15 @@ module ProcessOut
89
183
  return self
90
184
  end
91
185
  self.id = data.fetch(:id, self.id)
186
+ self.supervisor_project = data.fetch(:supervisor_project, self.supervisor_project)
187
+ self.supervisor_project_id = data.fetch(:supervisor_project_id, self.supervisor_project_id)
188
+ self.api_version = data.fetch(:api_version, self.api_version)
92
189
  self.name = data.fetch(:name, self.name)
93
190
  self.logo_url = data.fetch(:logo_url, self.logo_url)
94
191
  self.email = data.fetch(:email, self.email)
192
+ self.default_currency = data.fetch(:default_currency, self.default_currency)
193
+ self.private_key = data.fetch(:private_key, self.private_key)
194
+ self.dunning_configuration = data.fetch(:dunning_configuration, self.dunning_configuration)
95
195
  self.created_at = data.fetch(:created_at, self.created_at)
96
196
 
97
197
  self
@@ -9,9 +9,11 @@ module ProcessOut
9
9
 
10
10
  attr_reader :id
11
11
  attr_reader :transaction
12
+ attr_reader :transaction_id
13
+ attr_reader :amount
12
14
  attr_reader :reason
13
15
  attr_reader :information
14
- attr_reader :amount
16
+ attr_reader :has_failed
15
17
  attr_reader :metadata
16
18
  attr_reader :sandbox
17
19
  attr_reader :created_at
@@ -22,6 +24,11 @@ module ProcessOut
22
24
  end
23
25
 
24
26
  def transaction=(val)
27
+ if val.nil?
28
+ @transaction = val
29
+ return
30
+ end
31
+
25
32
  if val.instance_of? Transaction
26
33
  @transaction = val
27
34
  else
@@ -32,6 +39,14 @@ module ProcessOut
32
39
 
33
40
  end
34
41
 
42
+ def transaction_id=(val)
43
+ @transaction_id = val
44
+ end
45
+
46
+ def amount=(val)
47
+ @amount = val
48
+ end
49
+
35
50
  def reason=(val)
36
51
  @reason = val
37
52
  end
@@ -40,8 +55,8 @@ module ProcessOut
40
55
  @information = val
41
56
  end
42
57
 
43
- def amount=(val)
44
- @amount = val
58
+ def has_failed=(val)
59
+ @has_failed = val
45
60
  end
46
61
 
47
62
  def metadata=(val)
@@ -66,9 +81,11 @@ module ProcessOut
66
81
 
67
82
  self.id = data.fetch(:id, nil)
68
83
  self.transaction = data.fetch(:transaction, nil)
84
+ self.transaction_id = data.fetch(:transaction_id, nil)
85
+ self.amount = data.fetch(:amount, nil)
69
86
  self.reason = data.fetch(:reason, nil)
70
87
  self.information = data.fetch(:information, nil)
71
- self.amount = data.fetch(:amount, nil)
88
+ self.has_failed = data.fetch(:has_failed, nil)
72
89
  self.metadata = data.fetch(:metadata, nil)
73
90
  self.sandbox = data.fetch(:sandbox, nil)
74
91
  self.created_at = data.fetch(:created_at, nil)
@@ -93,14 +110,20 @@ module ProcessOut
93
110
  if data.include? "transaction"
94
111
  self.transaction = data["transaction"]
95
112
  end
113
+ if data.include? "transaction_id"
114
+ self.transaction_id = data["transaction_id"]
115
+ end
116
+ if data.include? "amount"
117
+ self.amount = data["amount"]
118
+ end
96
119
  if data.include? "reason"
97
120
  self.reason = data["reason"]
98
121
  end
99
122
  if data.include? "information"
100
123
  self.information = data["information"]
101
124
  end
102
- if data.include? "amount"
103
- self.amount = data["amount"]
125
+ if data.include? "has_failed"
126
+ self.has_failed = data["has_failed"]
104
127
  end
105
128
  if data.include? "metadata"
106
129
  self.metadata = data["metadata"]
@@ -124,9 +147,11 @@ module ProcessOut
124
147
  end
125
148
  self.id = data.fetch(:id, self.id)
126
149
  self.transaction = data.fetch(:transaction, self.transaction)
150
+ self.transaction_id = data.fetch(:transaction_id, self.transaction_id)
151
+ self.amount = data.fetch(:amount, self.amount)
127
152
  self.reason = data.fetch(:reason, self.reason)
128
153
  self.information = data.fetch(:information, self.information)
129
- self.amount = data.fetch(:amount, self.amount)
154
+ self.has_failed = data.fetch(:has_failed, self.has_failed)
130
155
  self.metadata = data.fetch(:metadata, self.metadata)
131
156
  self.sandbox = data.fetch(:sandbox, self.sandbox)
132
157
  self.created_at = data.fetch(:created_at, self.created_at)
@@ -9,25 +9,35 @@ module ProcessOut
9
9
 
10
10
  attr_reader :id
11
11
  attr_reader :project
12
- attr_reader :plan_id
12
+ attr_reader :project_id
13
13
  attr_reader :plan
14
+ attr_reader :plan_id
15
+ attr_reader :discounts
16
+ attr_reader :addons
17
+ attr_reader :transactions
14
18
  attr_reader :customer
19
+ attr_reader :customer_id
15
20
  attr_reader :token
21
+ attr_reader :token_id
16
22
  attr_reader :url
17
23
  attr_reader :name
18
24
  attr_reader :amount
25
+ attr_reader :billable_amount
26
+ attr_reader :discounted_amount
27
+ attr_reader :addons_amount
19
28
  attr_reader :currency
20
29
  attr_reader :metadata
21
30
  attr_reader :interval
22
31
  attr_reader :trial_end_at
23
32
  attr_reader :activated
24
33
  attr_reader :active
34
+ attr_reader :cancel_at
25
35
  attr_reader :canceled
26
36
  attr_reader :cancellation_reason
27
37
  attr_reader :pending_cancellation
28
- attr_reader :cancel_at
29
38
  attr_reader :return_url
30
39
  attr_reader :cancel_url
40
+ attr_reader :unpaid_state
31
41
  attr_reader :sandbox
32
42
  attr_reader :created_at
33
43
  attr_reader :activated_at
@@ -39,6 +49,11 @@ module ProcessOut
39
49
  end
40
50
 
41
51
  def project=(val)
52
+ if val.nil?
53
+ @project = val
54
+ return
55
+ end
56
+
42
57
  if val.instance_of? Project
43
58
  @project = val
44
59
  else
@@ -49,11 +64,16 @@ module ProcessOut
49
64
 
50
65
  end
51
66
 
52
- def plan_id=(val)
53
- @plan_id = val
67
+ def project_id=(val)
68
+ @project_id = val
54
69
  end
55
70
 
56
71
  def plan=(val)
72
+ if val.nil?
73
+ @plan = val
74
+ return
75
+ end
76
+
57
77
  if val.instance_of? Plan
58
78
  @plan = val
59
79
  else
@@ -64,7 +84,76 @@ module ProcessOut
64
84
 
65
85
  end
66
86
 
87
+ def plan_id=(val)
88
+ @plan_id = val
89
+ end
90
+
91
+ def discounts=(val)
92
+ if val.nil?
93
+ @discounts = []
94
+ return
95
+ end
96
+
97
+ if val.length > 0 and val[0].instance_of? Discount
98
+ @discounts = val
99
+ else
100
+ l = Array.new
101
+ for v in val
102
+ obj = Discount.new(@client)
103
+ obj.fill_with_data(v)
104
+ l.push(obj)
105
+ end
106
+ @discounts = l
107
+ end
108
+
109
+ end
110
+
111
+ def addons=(val)
112
+ if val.nil?
113
+ @addons = []
114
+ return
115
+ end
116
+
117
+ if val.length > 0 and val[0].instance_of? Addon
118
+ @addons = val
119
+ else
120
+ l = Array.new
121
+ for v in val
122
+ obj = Addon.new(@client)
123
+ obj.fill_with_data(v)
124
+ l.push(obj)
125
+ end
126
+ @addons = l
127
+ end
128
+
129
+ end
130
+
131
+ def transactions=(val)
132
+ if val.nil?
133
+ @transactions = []
134
+ return
135
+ end
136
+
137
+ if val.length > 0 and val[0].instance_of? Transaction
138
+ @transactions = val
139
+ else
140
+ l = Array.new
141
+ for v in val
142
+ obj = Transaction.new(@client)
143
+ obj.fill_with_data(v)
144
+ l.push(obj)
145
+ end
146
+ @transactions = l
147
+ end
148
+
149
+ end
150
+
67
151
  def customer=(val)
152
+ if val.nil?
153
+ @customer = val
154
+ return
155
+ end
156
+
68
157
  if val.instance_of? Customer
69
158
  @customer = val
70
159
  else
@@ -75,7 +164,16 @@ module ProcessOut
75
164
 
76
165
  end
77
166
 
167
+ def customer_id=(val)
168
+ @customer_id = val
169
+ end
170
+
78
171
  def token=(val)
172
+ if val.nil?
173
+ @token = val
174
+ return
175
+ end
176
+
79
177
  if val.instance_of? Token
80
178
  @token = val
81
179
  else
@@ -86,6 +184,10 @@ module ProcessOut
86
184
 
87
185
  end
88
186
 
187
+ def token_id=(val)
188
+ @token_id = val
189
+ end
190
+
89
191
  def url=(val)
90
192
  @url = val
91
193
  end
@@ -98,6 +200,18 @@ module ProcessOut
98
200
  @amount = val
99
201
  end
100
202
 
203
+ def billable_amount=(val)
204
+ @billable_amount = val
205
+ end
206
+
207
+ def discounted_amount=(val)
208
+ @discounted_amount = val
209
+ end
210
+
211
+ def addons_amount=(val)
212
+ @addons_amount = val
213
+ end
214
+
101
215
  def currency=(val)
102
216
  @currency = val
103
217
  end
@@ -122,6 +236,10 @@ module ProcessOut
122
236
  @active = val
123
237
  end
124
238
 
239
+ def cancel_at=(val)
240
+ @cancel_at = val
241
+ end
242
+
125
243
  def canceled=(val)
126
244
  @canceled = val
127
245
  end
@@ -134,10 +252,6 @@ module ProcessOut
134
252
  @pending_cancellation = val
135
253
  end
136
254
 
137
- def cancel_at=(val)
138
- @cancel_at = val
139
- end
140
-
141
255
  def return_url=(val)
142
256
  @return_url = val
143
257
  end
@@ -146,6 +260,10 @@ module ProcessOut
146
260
  @cancel_url = val
147
261
  end
148
262
 
263
+ def unpaid_state=(val)
264
+ @unpaid_state = val
265
+ end
266
+
149
267
  def sandbox=(val)
150
268
  @sandbox = val
151
269
  end
@@ -172,25 +290,35 @@ module ProcessOut
172
290
 
173
291
  self.id = data.fetch(:id, nil)
174
292
  self.project = data.fetch(:project, nil)
175
- self.plan_id = data.fetch(:plan_id, nil)
293
+ self.project_id = data.fetch(:project_id, nil)
176
294
  self.plan = data.fetch(:plan, nil)
295
+ self.plan_id = data.fetch(:plan_id, nil)
296
+ self.discounts = data.fetch(:discounts, nil)
297
+ self.addons = data.fetch(:addons, nil)
298
+ self.transactions = data.fetch(:transactions, nil)
177
299
  self.customer = data.fetch(:customer, nil)
300
+ self.customer_id = data.fetch(:customer_id, nil)
178
301
  self.token = data.fetch(:token, nil)
302
+ self.token_id = data.fetch(:token_id, nil)
179
303
  self.url = data.fetch(:url, nil)
180
304
  self.name = data.fetch(:name, nil)
181
305
  self.amount = data.fetch(:amount, nil)
306
+ self.billable_amount = data.fetch(:billable_amount, nil)
307
+ self.discounted_amount = data.fetch(:discounted_amount, nil)
308
+ self.addons_amount = data.fetch(:addons_amount, nil)
182
309
  self.currency = data.fetch(:currency, nil)
183
310
  self.metadata = data.fetch(:metadata, nil)
184
311
  self.interval = data.fetch(:interval, nil)
185
312
  self.trial_end_at = data.fetch(:trial_end_at, nil)
186
313
  self.activated = data.fetch(:activated, nil)
187
314
  self.active = data.fetch(:active, nil)
315
+ self.cancel_at = data.fetch(:cancel_at, nil)
188
316
  self.canceled = data.fetch(:canceled, nil)
189
317
  self.cancellation_reason = data.fetch(:cancellation_reason, nil)
190
318
  self.pending_cancellation = data.fetch(:pending_cancellation, nil)
191
- self.cancel_at = data.fetch(:cancel_at, nil)
192
319
  self.return_url = data.fetch(:return_url, nil)
193
320
  self.cancel_url = data.fetch(:cancel_url, nil)
321
+ self.unpaid_state = data.fetch(:unpaid_state, nil)
194
322
  self.sandbox = data.fetch(:sandbox, nil)
195
323
  self.created_at = data.fetch(:created_at, nil)
196
324
  self.activated_at = data.fetch(:activated_at, nil)
@@ -216,18 +344,36 @@ module ProcessOut
216
344
  if data.include? "project"
217
345
  self.project = data["project"]
218
346
  end
219
- if data.include? "plan_id"
220
- self.plan_id = data["plan_id"]
347
+ if data.include? "project_id"
348
+ self.project_id = data["project_id"]
221
349
  end
222
350
  if data.include? "plan"
223
351
  self.plan = data["plan"]
224
352
  end
353
+ if data.include? "plan_id"
354
+ self.plan_id = data["plan_id"]
355
+ end
356
+ if data.include? "discounts"
357
+ self.discounts = data["discounts"]
358
+ end
359
+ if data.include? "addons"
360
+ self.addons = data["addons"]
361
+ end
362
+ if data.include? "transactions"
363
+ self.transactions = data["transactions"]
364
+ end
225
365
  if data.include? "customer"
226
366
  self.customer = data["customer"]
227
367
  end
368
+ if data.include? "customer_id"
369
+ self.customer_id = data["customer_id"]
370
+ end
228
371
  if data.include? "token"
229
372
  self.token = data["token"]
230
373
  end
374
+ if data.include? "token_id"
375
+ self.token_id = data["token_id"]
376
+ end
231
377
  if data.include? "url"
232
378
  self.url = data["url"]
233
379
  end
@@ -237,6 +383,15 @@ module ProcessOut
237
383
  if data.include? "amount"
238
384
  self.amount = data["amount"]
239
385
  end
386
+ if data.include? "billable_amount"
387
+ self.billable_amount = data["billable_amount"]
388
+ end
389
+ if data.include? "discounted_amount"
390
+ self.discounted_amount = data["discounted_amount"]
391
+ end
392
+ if data.include? "addons_amount"
393
+ self.addons_amount = data["addons_amount"]
394
+ end
240
395
  if data.include? "currency"
241
396
  self.currency = data["currency"]
242
397
  end
@@ -255,6 +410,9 @@ module ProcessOut
255
410
  if data.include? "active"
256
411
  self.active = data["active"]
257
412
  end
413
+ if data.include? "cancel_at"
414
+ self.cancel_at = data["cancel_at"]
415
+ end
258
416
  if data.include? "canceled"
259
417
  self.canceled = data["canceled"]
260
418
  end
@@ -264,15 +422,15 @@ module ProcessOut
264
422
  if data.include? "pending_cancellation"
265
423
  self.pending_cancellation = data["pending_cancellation"]
266
424
  end
267
- if data.include? "cancel_at"
268
- self.cancel_at = data["cancel_at"]
269
- end
270
425
  if data.include? "return_url"
271
426
  self.return_url = data["return_url"]
272
427
  end
273
428
  if data.include? "cancel_url"
274
429
  self.cancel_url = data["cancel_url"]
275
430
  end
431
+ if data.include? "unpaid_state"
432
+ self.unpaid_state = data["unpaid_state"]
433
+ end
276
434
  if data.include? "sandbox"
277
435
  self.sandbox = data["sandbox"]
278
436
  end
@@ -298,25 +456,35 @@ module ProcessOut
298
456
  end
299
457
  self.id = data.fetch(:id, self.id)
300
458
  self.project = data.fetch(:project, self.project)
301
- self.plan_id = data.fetch(:plan_id, self.plan_id)
459
+ self.project_id = data.fetch(:project_id, self.project_id)
302
460
  self.plan = data.fetch(:plan, self.plan)
461
+ self.plan_id = data.fetch(:plan_id, self.plan_id)
462
+ self.discounts = data.fetch(:discounts, self.discounts)
463
+ self.addons = data.fetch(:addons, self.addons)
464
+ self.transactions = data.fetch(:transactions, self.transactions)
303
465
  self.customer = data.fetch(:customer, self.customer)
466
+ self.customer_id = data.fetch(:customer_id, self.customer_id)
304
467
  self.token = data.fetch(:token, self.token)
468
+ self.token_id = data.fetch(:token_id, self.token_id)
305
469
  self.url = data.fetch(:url, self.url)
306
470
  self.name = data.fetch(:name, self.name)
307
471
  self.amount = data.fetch(:amount, self.amount)
472
+ self.billable_amount = data.fetch(:billable_amount, self.billable_amount)
473
+ self.discounted_amount = data.fetch(:discounted_amount, self.discounted_amount)
474
+ self.addons_amount = data.fetch(:addons_amount, self.addons_amount)
308
475
  self.currency = data.fetch(:currency, self.currency)
309
476
  self.metadata = data.fetch(:metadata, self.metadata)
310
477
  self.interval = data.fetch(:interval, self.interval)
311
478
  self.trial_end_at = data.fetch(:trial_end_at, self.trial_end_at)
312
479
  self.activated = data.fetch(:activated, self.activated)
313
480
  self.active = data.fetch(:active, self.active)
481
+ self.cancel_at = data.fetch(:cancel_at, self.cancel_at)
314
482
  self.canceled = data.fetch(:canceled, self.canceled)
315
483
  self.cancellation_reason = data.fetch(:cancellation_reason, self.cancellation_reason)
316
484
  self.pending_cancellation = data.fetch(:pending_cancellation, self.pending_cancellation)
317
- self.cancel_at = data.fetch(:cancel_at, self.cancel_at)
318
485
  self.return_url = data.fetch(:return_url, self.return_url)
319
486
  self.cancel_url = data.fetch(:cancel_url, self.cancel_url)
487
+ self.unpaid_state = data.fetch(:unpaid_state, self.unpaid_state)
320
488
  self.sandbox = data.fetch(:sandbox, self.sandbox)
321
489
  self.created_at = data.fetch(:created_at, self.created_at)
322
490
  self.activated_at = data.fetch(:activated_at, self.activated_at)
@@ -325,14 +493,14 @@ module ProcessOut
325
493
  self
326
494
  end
327
495
 
328
- # Get the customer owning the subscription.
496
+ # Get the addons applied to the subscription.
329
497
  # Params:
330
498
  # +options+:: +Hash+ of options
331
- def fetch_customer(options = {})
499
+ def fetch_addons(options = {})
332
500
  self.prefill(options)
333
501
 
334
502
  request = Request.new(@client)
335
- path = "/subscriptions/" + CGI.escape(@id) + "/customers"
503
+ path = "/subscriptions/" + CGI.escape(@id) + "/addons"
336
504
  data = {
337
505
 
338
506
  }
@@ -340,23 +508,30 @@ module ProcessOut
340
508
  response = Response.new(request.get(path, data, options))
341
509
  return_values = Array.new
342
510
 
511
+ a = Array.new
343
512
  body = response.body
344
- body = body["customer"]
345
- customer = Customer.new(@client)
346
- return_values.push(customer.fill_with_data(body))
513
+ for v in body['addons']
514
+ tmp = Addon.new(@client)
515
+ tmp.fill_with_data(v)
516
+ a.push(tmp)
517
+ end
518
+
519
+ return_values.push(a)
520
+
347
521
 
348
522
 
349
523
  return_values[0]
350
524
  end
351
525
 
352
- # Get the discounts applied to the subscription.
526
+ # Find a subscription's addon by its ID.
353
527
  # Params:
528
+ # +addon_id+:: ID of the addon
354
529
  # +options+:: +Hash+ of options
355
- def fetch_discounts(options = {})
530
+ def find_addon(addon_id, options = {})
356
531
  self.prefill(options)
357
532
 
358
533
  request = Request.new(@client)
359
- path = "/subscriptions/" + CGI.escape(@id) + "/discounts"
534
+ path = "/subscriptions/" + CGI.escape(@id) + "/addons/" + CGI.escape(addon_id) + ""
360
535
  data = {
361
536
 
362
537
  }
@@ -364,41 +539,88 @@ module ProcessOut
364
539
  response = Response.new(request.get(path, data, options))
365
540
  return_values = Array.new
366
541
 
367
- a = Array.new
368
542
  body = response.body
369
- for v in body['discounts']
370
- tmp = Discount.new(@client)
371
- tmp.fill_with_data(v)
372
- a.push(tmp)
373
- end
543
+ body = body["addon"]
544
+ addon = Addon.new(@client)
545
+ return_values.push(addon.fill_with_data(body))
374
546
 
375
- return_values.push(a)
376
547
 
548
+ return_values[0]
549
+ end
550
+
551
+ # Remove an addon applied to a subscription.
552
+ # Params:
553
+ # +addon_id+:: ID of the addon or plan to be removed from the subscription
554
+ # +options+:: +Hash+ of options
555
+ def remove_addon(addon_id, options = {})
556
+ self.prefill(options)
557
+
558
+ request = Request.new(@client)
559
+ path = "/subscriptions/" + CGI.escape(@id) + "/addons/" + CGI.escape(addon_id) + ""
560
+ data = {
561
+ "prorate" => options.fetch(:prorate, nil),
562
+ "proration_date" => options.fetch(:proration_date, nil),
563
+ "preview" => options.fetch(:preview, nil)
564
+ }
565
+
566
+ response = Response.new(request.delete(path, data, options))
567
+ return_values = Array.new
568
+
569
+ return_values.push(response.success)
377
570
 
378
571
 
379
572
  return_values[0]
380
573
  end
381
574
 
382
- # Apply a coupon on the subscription.
575
+ # Get the customer owning the subscription.
383
576
  # Params:
384
- # +coupon_id+:: ID of the coupon
385
577
  # +options+:: +Hash+ of options
386
- def apply_coupon(coupon_id, options = {})
578
+ def fetch_customer(options = {})
579
+ self.prefill(options)
580
+
581
+ request = Request.new(@client)
582
+ path = "/subscriptions/" + CGI.escape(@id) + "/customers"
583
+ data = {
584
+
585
+ }
586
+
587
+ response = Response.new(request.get(path, data, options))
588
+ return_values = Array.new
589
+
590
+ body = response.body
591
+ body = body["customer"]
592
+ customer = Customer.new(@client)
593
+ return_values.push(customer.fill_with_data(body))
594
+
595
+
596
+ return_values[0]
597
+ end
598
+
599
+ # Get the discounts applied to the subscription.
600
+ # Params:
601
+ # +options+:: +Hash+ of options
602
+ def fetch_discounts(options = {})
387
603
  self.prefill(options)
388
604
 
389
605
  request = Request.new(@client)
390
606
  path = "/subscriptions/" + CGI.escape(@id) + "/discounts"
391
607
  data = {
392
- "coupon_id" => coupon_id
608
+
393
609
  }
394
610
 
395
- response = Response.new(request.post(path, data, options))
611
+ response = Response.new(request.get(path, data, options))
396
612
  return_values = Array.new
397
613
 
614
+ a = Array.new
398
615
  body = response.body
399
- body = body["discount"]
400
- discount = Discount.new(@client)
401
- return_values.push(discount.fill_with_data(body))
616
+ for v in body['discounts']
617
+ tmp = Discount.new(@client)
618
+ tmp.fill_with_data(v)
619
+ a.push(tmp)
620
+ end
621
+
622
+ return_values.push(a)
623
+
402
624
 
403
625
 
404
626
  return_values[0]
@@ -445,12 +667,7 @@ module ProcessOut
445
667
  response = Response.new(request.delete(path, data, options))
446
668
  return_values = Array.new
447
669
 
448
- body = response.body
449
- body = body["discount"]
450
-
451
-
452
- return_values.push(self.fill_with_data(body))
453
-
670
+ return_values.push(response.success)
454
671
 
455
672
 
456
673
  return_values[0]
@@ -552,46 +769,6 @@ module ProcessOut
552
769
 
553
770
 
554
771
 
555
- return_values[0]
556
- end
557
-
558
- # Create a new subscription for the customer from the given plan ID.
559
- # Params:
560
- # +customer_id+:: ID of the customer
561
- # +plan_id+:: ID of the plan
562
- # +options+:: +Hash+ of options
563
- def create_from_plan(customer_id, plan_id, options = {})
564
- self.prefill(options)
565
-
566
- request = Request.new(@client)
567
- path = "/subscriptions"
568
- data = {
569
- "cancel_at" => @cancel_at,
570
- "name" => @name,
571
- "amount" => @amount,
572
- "currency" => @currency,
573
- "metadata" => @metadata,
574
- "interval" => @interval,
575
- "trial_end_at" => @trial_end_at,
576
- "return_url" => @return_url,
577
- "cancel_url" => @cancel_url,
578
- "source" => options.fetch(:source, nil),
579
- "coupon_id" => options.fetch(:coupon_id, nil),
580
- "customer_id" => customer_id,
581
- "plan_id" => plan_id
582
- }
583
-
584
- response = Response.new(request.post(path, data, options))
585
- return_values = Array.new
586
-
587
- body = response.body
588
- body = body["subscription"]
589
-
590
-
591
- return_values.push(self.fill_with_data(body))
592
-
593
-
594
-
595
772
  return_values[0]
596
773
  end
597
774
 
@@ -641,7 +818,8 @@ module ProcessOut
641
818
  "coupon_id" => options.fetch(:coupon_id, nil),
642
819
  "source" => options.fetch(:source, nil),
643
820
  "prorate" => options.fetch(:prorate, nil),
644
- "proration_date" => options.fetch(:proration_date, nil)
821
+ "proration_date" => options.fetch(:proration_date, nil),
822
+ "preview" => options.fetch(:preview, nil)
645
823
  }
646
824
 
647
825
  response = Response.new(request.put(path, data, options))
@@ -668,36 +846,8 @@ module ProcessOut
668
846
  request = Request.new(@client)
669
847
  path = "/subscriptions/" + CGI.escape(@id) + ""
670
848
  data = {
671
- "cancellation_reason" => cancellation_reason
672
- }
673
-
674
- response = Response.new(request.delete(path, data, options))
675
- return_values = Array.new
676
-
677
- body = response.body
678
- body = body["subscription"]
679
-
680
-
681
- return_values.push(self.fill_with_data(body))
682
-
683
-
684
-
685
- return_values[0]
686
- end
687
-
688
- # Schedule the cancellation of the subscription. The reason may be provided as well.
689
- # Params:
690
- # +cancel_at+:: Cancellation date, in the form of a string
691
- # +cancellation_reason+:: Cancellation reason
692
- # +options+:: +Hash+ of options
693
- def cancel_at_date(cancel_at, cancellation_reason, options = {})
694
- self.prefill(options)
695
-
696
- request = Request.new(@client)
697
- path = "/subscriptions/" + CGI.escape(@id) + ""
698
- data = {
849
+ "cancel_at" => @cancel_at,
699
850
  "cancel_at_end" => options.fetch(:cancel_at_end, nil),
700
- "cancel_at" => cancel_at,
701
851
  "cancellation_reason" => cancellation_reason
702
852
  }
703
853