processout 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -83,15 +83,15 @@ module ProcessOut
83
83
  def initialize(client, data = {})
84
84
  @client = client
85
85
 
86
- @id = data.fetch(:id, "")
87
- @project = data.fetch(:project, nil)
88
- @subscription = data.fetch(:subscription, nil)
89
- @coupon = data.fetch(:coupon, nil)
90
- @amount = data.fetch(:amount, "")
91
- @expires_at = data.fetch(:expires_at, "")
92
- @metadata = data.fetch(:metadata, Hash.new)
93
- @sandbox = data.fetch(:sandbox, false)
94
- @created_at = data.fetch(:created_at, "")
86
+ self.id = data.fetch(:id, nil)
87
+ self.project = data.fetch(:project, nil)
88
+ self.subscription = data.fetch(:subscription, nil)
89
+ self.coupon = data.fetch(:coupon, nil)
90
+ self.amount = data.fetch(:amount, nil)
91
+ self.expires_at = data.fetch(:expires_at, nil)
92
+ self.metadata = data.fetch(:metadata, nil)
93
+ self.sandbox = data.fetch(:sandbox, nil)
94
+ self.created_at = data.fetch(:created_at, nil)
95
95
 
96
96
  end
97
97
 
@@ -104,6 +104,9 @@ module ProcessOut
104
104
  # Params:
105
105
  # +data+:: +Hash+ of data coming from the API
106
106
  def fill_with_data(data)
107
+ if data.nil?
108
+ return self
109
+ end
107
110
  if data.include? "id"
108
111
  self.id = data["id"]
109
112
  end
@@ -135,11 +138,33 @@ module ProcessOut
135
138
  self
136
139
  end
137
140
 
141
+ # Prefills the object with the data passed as Parameters
142
+ # Params:
143
+ # +data+:: +Hash+ of data
144
+ def prefill(data)
145
+ if data.nil?
146
+ return self
147
+ end
148
+ self.id = data.fetch(:id, self.id)
149
+ self.project = data.fetch(:project, self.project)
150
+ self.subscription = data.fetch(:subscription, self.subscription)
151
+ self.coupon = data.fetch(:coupon, self.coupon)
152
+ self.amount = data.fetch(:amount, self.amount)
153
+ self.expires_at = data.fetch(:expires_at, self.expires_at)
154
+ self.metadata = data.fetch(:metadata, self.metadata)
155
+ self.sandbox = data.fetch(:sandbox, self.sandbox)
156
+ self.created_at = data.fetch(:created_at, self.created_at)
157
+
158
+ self
159
+ end
160
+
138
161
  # Apply a new discount to the given subscription ID.
139
162
  # Params:
140
163
  # +subscription_id+:: ID of the subscription
141
164
  # +options+:: +Hash+ of options
142
165
  def apply(subscription_id, options = {})
166
+ self.prefill(options)
167
+
143
168
  request = Request.new(@client)
144
169
  path = "/subscriptions/" + CGI.escape(subscription_id) + "/discounts"
145
170
  data = {
@@ -168,6 +193,8 @@ module ProcessOut
168
193
  # +coupon_id+:: ID of the coupon
169
194
  # +options+:: +Hash+ of options
170
195
  def apply_coupon(subscription_id, coupon_id, options = {})
196
+ self.prefill(options)
197
+
171
198
  request = Request.new(@client)
172
199
  path = "/subscriptions/" + CGI.escape(subscription_id) + "/discounts"
173
200
  data = {
@@ -195,6 +222,8 @@ module ProcessOut
195
222
  # +discount_id+:: ID of the discount
196
223
  # +options+:: +Hash+ of options
197
224
  def find(subscription_id, discount_id, options = {})
225
+ self.prefill(options)
226
+
198
227
  request = Request.new(@client)
199
228
  path = "/subscriptions/" + CGI.escape(subscription_id) + "/discounts/" + CGI.escape(discount_id) + ""
200
229
  data = {
@@ -55,12 +55,12 @@ module ProcessOut
55
55
  def initialize(client, data = {})
56
56
  @client = client
57
57
 
58
- @id = data.fetch(:id, "")
59
- @project = data.fetch(:project, nil)
60
- @name = data.fetch(:name, "")
61
- @data = data.fetch(:data, nil)
62
- @sandbox = data.fetch(:sandbox, false)
63
- @fired_at = data.fetch(:fired_at, "")
58
+ self.id = data.fetch(:id, nil)
59
+ self.project = data.fetch(:project, nil)
60
+ self.name = data.fetch(:name, nil)
61
+ self.data = data.fetch(:data, nil)
62
+ self.sandbox = data.fetch(:sandbox, nil)
63
+ self.fired_at = data.fetch(:fired_at, nil)
64
64
 
65
65
  end
66
66
 
@@ -73,6 +73,9 @@ module ProcessOut
73
73
  # Params:
74
74
  # +data+:: +Hash+ of data coming from the API
75
75
  def fill_with_data(data)
76
+ if data.nil?
77
+ return self
78
+ end
76
79
  if data.include? "id"
77
80
  self.id = data["id"]
78
81
  end
@@ -95,10 +98,29 @@ module ProcessOut
95
98
  self
96
99
  end
97
100
 
101
+ # Prefills the object with the data passed as Parameters
102
+ # Params:
103
+ # +data+:: +Hash+ of data
104
+ def prefill(data)
105
+ if data.nil?
106
+ return self
107
+ end
108
+ self.id = data.fetch(:id, self.id)
109
+ self.project = data.fetch(:project, self.project)
110
+ self.name = data.fetch(:name, self.name)
111
+ self.data = data.fetch(:data, self.data)
112
+ self.sandbox = data.fetch(:sandbox, self.sandbox)
113
+ self.fired_at = data.fetch(:fired_at, self.fired_at)
114
+
115
+ self
116
+ end
117
+
98
118
  # Get all the webhooks of the event.
99
119
  # Params:
100
120
  # +options+:: +Hash+ of options
101
121
  def fetch_webhooks(options = {})
122
+ self.prefill(options)
123
+
102
124
  request = Request.new(@client)
103
125
  path = "/events/" + CGI.escape(@id) + "/webhooks"
104
126
  data = {
@@ -127,6 +149,8 @@ module ProcessOut
127
149
  # Params:
128
150
  # +options+:: +Hash+ of options
129
151
  def all(options = {})
152
+ self.prefill(options)
153
+
130
154
  request = Request.new(@client)
131
155
  path = "/events"
132
156
  data = {
@@ -156,6 +180,8 @@ module ProcessOut
156
180
  # +event_id+:: ID of the event
157
181
  # +options+:: +Hash+ of options
158
182
  def find(event_id, options = {})
183
+ self.prefill(options)
184
+
159
185
  request = Request.new(@client)
160
186
  path = "/events/" + CGI.escape(event_id) + ""
161
187
  data = {
@@ -57,14 +57,14 @@ module ProcessOut
57
57
  def initialize(client, data = {})
58
58
  @client = client
59
59
 
60
- @id = data.fetch(:id, "")
61
- @name = data.fetch(:name, "")
62
- @display_name = data.fetch(:display_name, "")
63
- @logo_url = data.fetch(:logo_url, "")
64
- @url = data.fetch(:url, "")
65
- @flows = data.fetch(:flows, Array.new)
66
- @tags = data.fetch(:tags, Array.new)
67
- @description = data.fetch(:description, "")
60
+ self.id = data.fetch(:id, nil)
61
+ self.name = data.fetch(:name, nil)
62
+ self.display_name = data.fetch(:display_name, nil)
63
+ self.logo_url = data.fetch(:logo_url, nil)
64
+ self.url = data.fetch(:url, nil)
65
+ self.flows = data.fetch(:flows, nil)
66
+ self.tags = data.fetch(:tags, nil)
67
+ self.description = data.fetch(:description, nil)
68
68
 
69
69
  end
70
70
 
@@ -77,6 +77,9 @@ module ProcessOut
77
77
  # Params:
78
78
  # +data+:: +Hash+ of data coming from the API
79
79
  def fill_with_data(data)
80
+ if data.nil?
81
+ return self
82
+ end
80
83
  if data.include? "id"
81
84
  self.id = data["id"]
82
85
  end
@@ -105,6 +108,25 @@ module ProcessOut
105
108
  self
106
109
  end
107
110
 
111
+ # Prefills the object with the data passed as Parameters
112
+ # Params:
113
+ # +data+:: +Hash+ of data
114
+ def prefill(data)
115
+ if data.nil?
116
+ return self
117
+ end
118
+ self.id = data.fetch(:id, self.id)
119
+ self.name = data.fetch(:name, self.name)
120
+ self.display_name = data.fetch(:display_name, self.display_name)
121
+ self.logo_url = data.fetch(:logo_url, self.logo_url)
122
+ self.url = data.fetch(:url, self.url)
123
+ self.flows = data.fetch(:flows, self.flows)
124
+ self.tags = data.fetch(:tags, self.tags)
125
+ self.description = data.fetch(:description, self.description)
126
+
127
+ self
128
+ end
129
+
108
130
 
109
131
  end
110
132
  end
@@ -56,11 +56,11 @@ module ProcessOut
56
56
  def initialize(client, data = {})
57
57
  @client = client
58
58
 
59
- @id = data.fetch(:id, "")
60
- @project = data.fetch(:project, nil)
61
- @gateway = data.fetch(:gateway, nil)
62
- @enabled = data.fetch(:enabled, false)
63
- @public_keys = data.fetch(:public_keys, Hash.new)
59
+ self.id = data.fetch(:id, nil)
60
+ self.project = data.fetch(:project, nil)
61
+ self.gateway = data.fetch(:gateway, nil)
62
+ self.enabled = data.fetch(:enabled, nil)
63
+ self.public_keys = data.fetch(:public_keys, nil)
64
64
 
65
65
  end
66
66
 
@@ -73,6 +73,9 @@ module ProcessOut
73
73
  # Params:
74
74
  # +data+:: +Hash+ of data coming from the API
75
75
  def fill_with_data(data)
76
+ if data.nil?
77
+ return self
78
+ end
76
79
  if data.include? "id"
77
80
  self.id = data["id"]
78
81
  end
@@ -92,6 +95,22 @@ module ProcessOut
92
95
  self
93
96
  end
94
97
 
98
+ # Prefills the object with the data passed as Parameters
99
+ # Params:
100
+ # +data+:: +Hash+ of data
101
+ def prefill(data)
102
+ if data.nil?
103
+ return self
104
+ end
105
+ self.id = data.fetch(:id, self.id)
106
+ self.project = data.fetch(:project, self.project)
107
+ self.gateway = data.fetch(:gateway, self.gateway)
108
+ self.enabled = data.fetch(:enabled, self.enabled)
109
+ self.public_keys = data.fetch(:public_keys, self.public_keys)
110
+
111
+ self
112
+ end
113
+
95
114
 
96
115
  end
97
116
  end
@@ -125,22 +125,22 @@ module ProcessOut
125
125
  def initialize(client, data = {})
126
126
  @client = client
127
127
 
128
- @id = data.fetch(:id, "")
129
- @project = data.fetch(:project, nil)
130
- @transaction = data.fetch(:transaction, nil)
131
- @customer = data.fetch(:customer, nil)
132
- @subscription = data.fetch(:subscription, nil)
133
- @url = data.fetch(:url, "")
134
- @name = data.fetch(:name, "")
135
- @amount = data.fetch(:amount, "")
136
- @currency = data.fetch(:currency, "")
137
- @metadata = data.fetch(:metadata, Hash.new)
138
- @request_email = data.fetch(:request_email, false)
139
- @request_shipping = data.fetch(:request_shipping, false)
140
- @return_url = data.fetch(:return_url, "")
141
- @cancel_url = data.fetch(:cancel_url, "")
142
- @sandbox = data.fetch(:sandbox, false)
143
- @created_at = data.fetch(:created_at, "")
128
+ self.id = data.fetch(:id, nil)
129
+ self.project = data.fetch(:project, nil)
130
+ self.transaction = data.fetch(:transaction, nil)
131
+ self.customer = data.fetch(:customer, nil)
132
+ self.subscription = data.fetch(:subscription, nil)
133
+ self.url = data.fetch(:url, nil)
134
+ self.name = data.fetch(:name, nil)
135
+ self.amount = data.fetch(:amount, nil)
136
+ self.currency = data.fetch(:currency, nil)
137
+ self.metadata = data.fetch(:metadata, nil)
138
+ self.request_email = data.fetch(:request_email, nil)
139
+ self.request_shipping = data.fetch(:request_shipping, nil)
140
+ self.return_url = data.fetch(:return_url, nil)
141
+ self.cancel_url = data.fetch(:cancel_url, nil)
142
+ self.sandbox = data.fetch(:sandbox, nil)
143
+ self.created_at = data.fetch(:created_at, nil)
144
144
 
145
145
  end
146
146
 
@@ -153,6 +153,9 @@ module ProcessOut
153
153
  # Params:
154
154
  # +data+:: +Hash+ of data coming from the API
155
155
  def fill_with_data(data)
156
+ if data.nil?
157
+ return self
158
+ end
156
159
  if data.include? "id"
157
160
  self.id = data["id"]
158
161
  end
@@ -205,11 +208,40 @@ module ProcessOut
205
208
  self
206
209
  end
207
210
 
211
+ # Prefills the object with the data passed as Parameters
212
+ # Params:
213
+ # +data+:: +Hash+ of data
214
+ def prefill(data)
215
+ if data.nil?
216
+ return self
217
+ end
218
+ self.id = data.fetch(:id, self.id)
219
+ self.project = data.fetch(:project, self.project)
220
+ self.transaction = data.fetch(:transaction, self.transaction)
221
+ self.customer = data.fetch(:customer, self.customer)
222
+ self.subscription = data.fetch(:subscription, self.subscription)
223
+ self.url = data.fetch(:url, self.url)
224
+ self.name = data.fetch(:name, self.name)
225
+ self.amount = data.fetch(:amount, self.amount)
226
+ self.currency = data.fetch(:currency, self.currency)
227
+ self.metadata = data.fetch(:metadata, self.metadata)
228
+ self.request_email = data.fetch(:request_email, self.request_email)
229
+ self.request_shipping = data.fetch(:request_shipping, self.request_shipping)
230
+ self.return_url = data.fetch(:return_url, self.return_url)
231
+ self.cancel_url = data.fetch(:cancel_url, self.cancel_url)
232
+ self.sandbox = data.fetch(:sandbox, self.sandbox)
233
+ self.created_at = data.fetch(:created_at, self.created_at)
234
+
235
+ self
236
+ end
237
+
208
238
  # Authorize the invoice using the given source (customer or token)
209
239
  # Params:
210
240
  # +source+:: Source used to authorization the payment. Can be a card, a token or a gateway request
211
241
  # +options+:: +Hash+ of options
212
242
  def authorize(source, options = {})
243
+ self.prefill(options)
244
+
213
245
  request = Request.new(@client)
214
246
  path = "/invoices/" + CGI.escape(@id) + "/authorize"
215
247
  data = {
@@ -233,6 +265,8 @@ module ProcessOut
233
265
  # +source+:: Source used to authorization the payment. Can be a card, a token or a gateway request
234
266
  # +options+:: +Hash+ of options
235
267
  def capture(source, options = {})
268
+ self.prefill(options)
269
+
236
270
  request = Request.new(@client)
237
271
  path = "/invoices/" + CGI.escape(@id) + "/capture"
238
272
  data = {
@@ -255,6 +289,8 @@ module ProcessOut
255
289
  # Params:
256
290
  # +options+:: +Hash+ of options
257
291
  def fetch_customer(options = {})
292
+ self.prefill(options)
293
+
258
294
  request = Request.new(@client)
259
295
  path = "/invoices/" + CGI.escape(@id) + "/customers"
260
296
  data = {
@@ -278,6 +314,8 @@ module ProcessOut
278
314
  # +customer_id+:: ID of the customer to be linked to the invoice
279
315
  # +options+:: +Hash+ of options
280
316
  def assign_customer(customer_id, options = {})
317
+ self.prefill(options)
318
+
281
319
  request = Request.new(@client)
282
320
  path = "/invoices/" + CGI.escape(@id) + "/customers"
283
321
  data = {
@@ -300,6 +338,8 @@ module ProcessOut
300
338
  # Params:
301
339
  # +options+:: +Hash+ of options
302
340
  def fetch_transaction(options = {})
341
+ self.prefill(options)
342
+
303
343
  request = Request.new(@client)
304
344
  path = "/invoices/" + CGI.escape(@id) + "/transactions"
305
345
  data = {
@@ -322,6 +362,8 @@ module ProcessOut
322
362
  # Params:
323
363
  # +options+:: +Hash+ of options
324
364
  def void(options = {})
365
+ self.prefill(options)
366
+
325
367
  request = Request.new(@client)
326
368
  path = "/invoices/" + CGI.escape(@id) + "/void"
327
369
  data = {
@@ -344,6 +386,8 @@ module ProcessOut
344
386
  # Params:
345
387
  # +options+:: +Hash+ of options
346
388
  def all(options = {})
389
+ self.prefill(options)
390
+
347
391
  request = Request.new(@client)
348
392
  path = "/invoices"
349
393
  data = {
@@ -372,6 +416,8 @@ module ProcessOut
372
416
  # Params:
373
417
  # +options+:: +Hash+ of options
374
418
  def create(options = {})
419
+ self.prefill(options)
420
+
375
421
  request = Request.new(@client)
376
422
  path = "/invoices"
377
423
  data = {
@@ -404,6 +450,8 @@ module ProcessOut
404
450
  # +customer_id+:: ID of the customer
405
451
  # +options+:: +Hash+ of options
406
452
  def create_for_customer(customer_id, options = {})
453
+ self.prefill(options)
454
+
407
455
  request = Request.new(@client)
408
456
  path = "/invoices"
409
457
  data = {
@@ -437,6 +485,8 @@ module ProcessOut
437
485
  # +invoice_id+:: ID of the invoice
438
486
  # +options+:: +Hash+ of options
439
487
  def find(invoice_id, options = {})
488
+ self.prefill(options)
489
+
440
490
  request = Request.new(@client)
441
491
  path = "/invoices/" + CGI.escape(invoice_id) + ""
442
492
  data = {
@@ -84,18 +84,18 @@ module ProcessOut
84
84
  def initialize(client, data = {})
85
85
  @client = client
86
86
 
87
- @id = data.fetch(:id, "")
88
- @project = data.fetch(:project, nil)
89
- @name = data.fetch(:name, "")
90
- @amount = data.fetch(:amount, "")
91
- @currency = data.fetch(:currency, "")
92
- @metadata = data.fetch(:metadata, Hash.new)
93
- @interval = data.fetch(:interval, "")
94
- @trial_period = data.fetch(:trial_period, "0d")
95
- @return_url = data.fetch(:return_url, "")
96
- @cancel_url = data.fetch(:cancel_url, "")
97
- @sandbox = data.fetch(:sandbox, false)
98
- @created_at = data.fetch(:created_at, "")
87
+ self.id = data.fetch(:id, nil)
88
+ self.project = data.fetch(:project, nil)
89
+ self.name = data.fetch(:name, nil)
90
+ self.amount = data.fetch(:amount, nil)
91
+ self.currency = data.fetch(:currency, nil)
92
+ self.metadata = data.fetch(:metadata, nil)
93
+ self.interval = data.fetch(:interval, nil)
94
+ self.trial_period = data.fetch(:trial_period, nil)
95
+ self.return_url = data.fetch(:return_url, nil)
96
+ self.cancel_url = data.fetch(:cancel_url, nil)
97
+ self.sandbox = data.fetch(:sandbox, nil)
98
+ self.created_at = data.fetch(:created_at, nil)
99
99
 
100
100
  end
101
101
 
@@ -108,6 +108,9 @@ module ProcessOut
108
108
  # Params:
109
109
  # +data+:: +Hash+ of data coming from the API
110
110
  def fill_with_data(data)
111
+ if data.nil?
112
+ return self
113
+ end
111
114
  if data.include? "id"
112
115
  self.id = data["id"]
113
116
  end
@@ -148,10 +151,35 @@ module ProcessOut
148
151
  self
149
152
  end
150
153
 
154
+ # Prefills the object with the data passed as Parameters
155
+ # Params:
156
+ # +data+:: +Hash+ of data
157
+ def prefill(data)
158
+ if data.nil?
159
+ return self
160
+ end
161
+ self.id = data.fetch(:id, self.id)
162
+ self.project = data.fetch(:project, self.project)
163
+ self.name = data.fetch(:name, self.name)
164
+ self.amount = data.fetch(:amount, self.amount)
165
+ self.currency = data.fetch(:currency, self.currency)
166
+ self.metadata = data.fetch(:metadata, self.metadata)
167
+ self.interval = data.fetch(:interval, self.interval)
168
+ self.trial_period = data.fetch(:trial_period, self.trial_period)
169
+ self.return_url = data.fetch(:return_url, self.return_url)
170
+ self.cancel_url = data.fetch(:cancel_url, self.cancel_url)
171
+ self.sandbox = data.fetch(:sandbox, self.sandbox)
172
+ self.created_at = data.fetch(:created_at, self.created_at)
173
+
174
+ self
175
+ end
176
+
151
177
  # Get all the plans.
152
178
  # Params:
153
179
  # +options+:: +Hash+ of options
154
180
  def all(options = {})
181
+ self.prefill(options)
182
+
155
183
  request = Request.new(@client)
156
184
  path = "/plans"
157
185
  data = {
@@ -180,6 +208,8 @@ module ProcessOut
180
208
  # Params:
181
209
  # +options+:: +Hash+ of options
182
210
  def create(options = {})
211
+ self.prefill(options)
212
+
183
213
  request = Request.new(@client)
184
214
  path = "/plans"
185
215
  data = {
@@ -213,6 +243,8 @@ module ProcessOut
213
243
  # +plan_id+:: ID of the plan
214
244
  # +options+:: +Hash+ of options
215
245
  def find(plan_id, options = {})
246
+ self.prefill(options)
247
+
216
248
  request = Request.new(@client)
217
249
  path = "/plans/" + CGI.escape(plan_id) + ""
218
250
  data = {
@@ -234,10 +266,12 @@ module ProcessOut
234
266
  return_values[0]
235
267
  end
236
268
 
237
- # Update the plan. This action won't affect subscriptions already linked to this plan.
269
+ # Save the updated plan attributes. This action won't affect subscriptions already linked to this plan.
238
270
  # Params:
239
271
  # +options+:: +Hash+ of options
240
- def update(options = {})
272
+ def save(options = {})
273
+ self.prefill(options)
274
+
241
275
  request = Request.new(@client)
242
276
  path = "/plans/" + CGI.escape(@id) + ""
243
277
  data = {
@@ -266,6 +300,8 @@ module ProcessOut
266
300
  # Params:
267
301
  # +options+:: +Hash+ of options
268
302
  def end(options = {})
303
+ self.prefill(options)
304
+
269
305
  request = Request.new(@client)
270
306
  path = "/plans/" + CGI.escape(@id) + ""
271
307
  data = {
@@ -89,19 +89,19 @@ module ProcessOut
89
89
  def initialize(client, data = {})
90
90
  @client = client
91
91
 
92
- @id = data.fetch(:id, "")
93
- @project = data.fetch(:project, nil)
94
- @url = data.fetch(:url, "")
95
- @name = data.fetch(:name, "")
96
- @amount = data.fetch(:amount, "")
97
- @currency = data.fetch(:currency, "")
98
- @metadata = data.fetch(:metadata, Hash.new)
99
- @request_email = data.fetch(:request_email, false)
100
- @request_shipping = data.fetch(:request_shipping, false)
101
- @return_url = data.fetch(:return_url, "")
102
- @cancel_url = data.fetch(:cancel_url, "")
103
- @sandbox = data.fetch(:sandbox, false)
104
- @created_at = data.fetch(:created_at, "")
92
+ self.id = data.fetch(:id, nil)
93
+ self.project = data.fetch(:project, nil)
94
+ self.url = data.fetch(:url, nil)
95
+ self.name = data.fetch(:name, nil)
96
+ self.amount = data.fetch(:amount, nil)
97
+ self.currency = data.fetch(:currency, nil)
98
+ self.metadata = data.fetch(:metadata, nil)
99
+ self.request_email = data.fetch(:request_email, nil)
100
+ self.request_shipping = data.fetch(:request_shipping, nil)
101
+ self.return_url = data.fetch(:return_url, nil)
102
+ self.cancel_url = data.fetch(:cancel_url, nil)
103
+ self.sandbox = data.fetch(:sandbox, nil)
104
+ self.created_at = data.fetch(:created_at, nil)
105
105
 
106
106
  end
107
107
 
@@ -114,6 +114,9 @@ module ProcessOut
114
114
  # Params:
115
115
  # +data+:: +Hash+ of data coming from the API
116
116
  def fill_with_data(data)
117
+ if data.nil?
118
+ return self
119
+ end
117
120
  if data.include? "id"
118
121
  self.id = data["id"]
119
122
  end
@@ -157,10 +160,36 @@ module ProcessOut
157
160
  self
158
161
  end
159
162
 
163
+ # Prefills the object with the data passed as Parameters
164
+ # Params:
165
+ # +data+:: +Hash+ of data
166
+ def prefill(data)
167
+ if data.nil?
168
+ return self
169
+ end
170
+ self.id = data.fetch(:id, self.id)
171
+ self.project = data.fetch(:project, self.project)
172
+ self.url = data.fetch(:url, self.url)
173
+ self.name = data.fetch(:name, self.name)
174
+ self.amount = data.fetch(:amount, self.amount)
175
+ self.currency = data.fetch(:currency, self.currency)
176
+ self.metadata = data.fetch(:metadata, self.metadata)
177
+ self.request_email = data.fetch(:request_email, self.request_email)
178
+ self.request_shipping = data.fetch(:request_shipping, self.request_shipping)
179
+ self.return_url = data.fetch(:return_url, self.return_url)
180
+ self.cancel_url = data.fetch(:cancel_url, self.cancel_url)
181
+ self.sandbox = data.fetch(:sandbox, self.sandbox)
182
+ self.created_at = data.fetch(:created_at, self.created_at)
183
+
184
+ self
185
+ end
186
+
160
187
  # Create a new invoice from the product.
161
188
  # Params:
162
189
  # +options+:: +Hash+ of options
163
190
  def create_invoice(options = {})
191
+ self.prefill(options)
192
+
164
193
  request = Request.new(@client)
165
194
  path = "/products/" + CGI.escape(@id) + "/invoices"
166
195
  data = {
@@ -183,6 +212,8 @@ module ProcessOut
183
212
  # Params:
184
213
  # +options+:: +Hash+ of options
185
214
  def all(options = {})
215
+ self.prefill(options)
216
+
186
217
  request = Request.new(@client)
187
218
  path = "/products"
188
219
  data = {
@@ -211,6 +242,8 @@ module ProcessOut
211
242
  # Params:
212
243
  # +options+:: +Hash+ of options
213
244
  def create(options = {})
245
+ self.prefill(options)
246
+
214
247
  request = Request.new(@client)
215
248
  path = "/products"
216
249
  data = {
@@ -243,6 +276,8 @@ module ProcessOut
243
276
  # +product_id+:: ID of the product
244
277
  # +options+:: +Hash+ of options
245
278
  def find(product_id, options = {})
279
+ self.prefill(options)
280
+
246
281
  request = Request.new(@client)
247
282
  path = "/products/" + CGI.escape(product_id) + ""
248
283
  data = {
@@ -268,6 +303,8 @@ module ProcessOut
268
303
  # Params:
269
304
  # +options+:: +Hash+ of options
270
305
  def save(options = {})
306
+ self.prefill(options)
307
+
271
308
  request = Request.new(@client)
272
309
  path = "/products/" + CGI.escape(@id) + ""
273
310
  data = {
@@ -299,6 +336,8 @@ module ProcessOut
299
336
  # Params:
300
337
  # +options+:: +Hash+ of options
301
338
  def delete(options = {})
339
+ self.prefill(options)
340
+
302
341
  request = Request.new(@client)
303
342
  path = "/products/" + CGI.escape(@id) + ""
304
343
  data = {