Class: ProcessOut::Customer

Inherits:
Object
  • Object
show all
Defined in:
lib/processout/customer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data = {}) ⇒ Customer

Initializes the Customer object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/processout/customer.rb', line 109

def initialize(client, data = {})
  @client = client

  @id = data.fetch(:id, "")
  @project = data.fetch(:project, nil)
  @email = data.fetch(:email, "")
  @first_name = data.fetch(:first_name, "")
  @last_name = data.fetch(:last_name, "")
  @address1 = data.fetch(:address1, "")
  @address2 = data.fetch(:address2, "")
  @city = data.fetch(:city, "")
  @state = data.fetch(:state, "")
  @zip = data.fetch(:zip, "")
  @country_code = data.fetch(:country_code, "")
  @balance = data.fetch(:balance, "0")
  @currency = data.fetch(:currency, "")
   = data.fetch(:metadata, Hash.new)
  @has_pin = data.fetch(:has_pin, false)
  @sandbox = data.fetch(:sandbox, false)
  @created_at = data.fetch(:created_at, "")
  
end

Instance Attribute Details

#address1Object

Returns the value of attribute address1.



15
16
17
# File 'lib/processout/customer.rb', line 15

def address1
  @address1
end

#address2Object

Returns the value of attribute address2.



16
17
18
# File 'lib/processout/customer.rb', line 16

def address2
  @address2
end

#balanceObject

Returns the value of attribute balance.



21
22
23
# File 'lib/processout/customer.rb', line 21

def balance
  @balance
end

#cityObject

Returns the value of attribute city.



17
18
19
# File 'lib/processout/customer.rb', line 17

def city
  @city
end

#country_codeObject

Returns the value of attribute country_code.



20
21
22
# File 'lib/processout/customer.rb', line 20

def country_code
  @country_code
end

#created_atObject

Returns the value of attribute created_at.



26
27
28
# File 'lib/processout/customer.rb', line 26

def created_at
  @created_at
end

#currencyObject

Returns the value of attribute currency.



22
23
24
# File 'lib/processout/customer.rb', line 22

def currency
  @currency
end

#emailObject

Returns the value of attribute email.



12
13
14
# File 'lib/processout/customer.rb', line 12

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



13
14
15
# File 'lib/processout/customer.rb', line 13

def first_name
  @first_name
end

#has_pinObject

Returns the value of attribute has_pin.



24
25
26
# File 'lib/processout/customer.rb', line 24

def has_pin
  @has_pin
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/processout/customer.rb', line 10

def id
  @id
end

#last_nameObject

Returns the value of attribute last_name.



14
15
16
# File 'lib/processout/customer.rb', line 14

def last_name
  @last_name
end

#metadataObject

Returns the value of attribute metadata.



23
24
25
# File 'lib/processout/customer.rb', line 23

def 
  
end

#projectObject

Returns the value of attribute project.



11
12
13
# File 'lib/processout/customer.rb', line 11

def project
  @project
end

#sandboxObject

Returns the value of attribute sandbox.



25
26
27
# File 'lib/processout/customer.rb', line 25

def sandbox
  @sandbox
end

#stateObject

Returns the value of attribute state.



18
19
20
# File 'lib/processout/customer.rb', line 18

def state
  @state
end

#zipObject

Returns the value of attribute zip.



19
20
21
# File 'lib/processout/customer.rb', line 19

def zip
  @zip
end

Instance Method Details

#all(options = {}) ⇒ Object

Get all the customers. Params:

options

Hash of options



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/processout/customer.rb', line 326

def all(options = {})
  request = Request.new(@client)
  path    = "/customers"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  a    = Array.new
  body = response.body
  for v in body['customers']
    tmp = Customer.new(@client)
    tmp.fill_with_data(v)
    a.push(tmp)
  end

  return_values.push(a)
  

  
  return_values[0]
end

#create(options = {}) ⇒ Object

Create a new customer. Params:

options

Hash of options



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/processout/customer.rb', line 354

def create(options = {})
  request = Request.new(@client)
  path    = "/customers"
  data    = {
    "balance" => @balance, 
    "currency" => @currency, 
    "email" => @email, 
    "first_name" => @first_name, 
    "last_name" => @last_name, 
    "address1" => @address1, 
    "address2" => @address2, 
    "city" => @city, 
    "state" => @state, 
    "zip" => @zip, 
    "country_code" => @country_code, 
    "metadata" => 
  }

  response = Response.new(request.post(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["customer"]
  
  
  return_values.push(self.fill_with_data(body))
  

  
  return_values[0]
end

#delete(options = {}) ⇒ Object

Delete the customer. Params:

options

Hash of options



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/processout/customer.rb', line 449

def delete(options = {})
  request = Request.new(@client)
  path    = "/customers/" + CGI.escape(@id) + ""
  data    = {

  }

  response = Response.new(request.delete(path, data, options))
  return_values = Array.new
  
  return_values.push(response.success)

  
  return_values[0]
end

#delete_token(token_id, options = {}) ⇒ Object

Delete a customer’s token by its ID. Params:

token_id

ID of the token

options

Hash of options



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/processout/customer.rb', line 279

def delete_token(token_id, options = {})
  request = Request.new(@client)
  path    = "customers/" + CGI.escape(@id) + "/tokens/" + CGI.escape(token_id) + ""
  data    = {

  }

  response = Response.new(request.delete(path, data, options))
  return_values = Array.new
  
  return_values.push(response.success)

  
  return_values[0]
end

#fetch_subscriptions(options = {}) ⇒ Object

Get the subscriptions belonging to the customer. Params:

options

Hash of options



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/processout/customer.rb', line 199

def fetch_subscriptions(options = {})
  request = Request.new(@client)
  path    = "/customers/" + CGI.escape(@id) + "/subscriptions"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  a    = Array.new
  body = response.body
  for v in body['subscriptions']
    tmp = Subscription.new(@client)
    tmp.fill_with_data(v)
    a.push(tmp)
  end

  return_values.push(a)
  

  
  return_values[0]
end

#fetch_tokens(options = {}) ⇒ Object

Get the customer’s tokens. Params:

options

Hash of options



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/processout/customer.rb', line 227

def fetch_tokens(options = {})
  request = Request.new(@client)
  path    = "/customers/" + CGI.escape(@id) + "/tokens"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  a    = Array.new
  body = response.body
  for v in body['tokens']
    tmp = Token.new(@client)
    tmp.fill_with_data(v)
    a.push(tmp)
  end

  return_values.push(a)
  

  
  return_values[0]
end

#fetch_transactions(options = {}) ⇒ Object

Get the transactions belonging to the customer. Params:

options

Hash of options



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/processout/customer.rb', line 298

def fetch_transactions(options = {})
  request = Request.new(@client)
  path    = "/customers/" + CGI.escape(@id) + "/transactions"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  a    = Array.new
  body = response.body
  for v in body['transactions']
    tmp = Transaction.new(@client)
    tmp.fill_with_data(v)
    a.push(tmp)
  end

  return_values.push(a)
  

  
  return_values[0]
end

#fill_with_data(data) ⇒ Object

Fills the object with data coming from the API Params:

data

Hash of data coming from the API



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/processout/customer.rb', line 140

def fill_with_data(data)
  if data.include? "id"
    self.id = data["id"]
  end
  if data.include? "project"
    self.project = data["project"]
  end
  if data.include? "email"
    self.email = data["email"]
  end
  if data.include? "first_name"
    self.first_name = data["first_name"]
  end
  if data.include? "last_name"
    self.last_name = data["last_name"]
  end
  if data.include? "address1"
    self.address1 = data["address1"]
  end
  if data.include? "address2"
    self.address2 = data["address2"]
  end
  if data.include? "city"
    self.city = data["city"]
  end
  if data.include? "state"
    self.state = data["state"]
  end
  if data.include? "zip"
    self.zip = data["zip"]
  end
  if data.include? "country_code"
    self.country_code = data["country_code"]
  end
  if data.include? "balance"
    self.balance = data["balance"]
  end
  if data.include? "currency"
    self.currency = data["currency"]
  end
  if data.include? "metadata"
    self. = data["metadata"]
  end
  if data.include? "has_pin"
    self.has_pin = data["has_pin"]
  end
  if data.include? "sandbox"
    self.sandbox = data["sandbox"]
  end
  if data.include? "created_at"
    self.created_at = data["created_at"]
  end
  
  self
end

#find(customer_id, options = {}) ⇒ Object

Find a customer by its ID. Params:

customer_id

ID of the customer

options

Hash of options



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/processout/customer.rb', line 390

def find(customer_id, options = {})
  request = Request.new(@client)
  path    = "/customers/" + CGI.escape(customer_id) + ""
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["customer"]
  
  
  obj = Customer.new(@client)
  return_values.push(obj.fill_with_data(body))
  

  
  return_values[0]
end

#find_token(token_id, options = {}) ⇒ Object

Find a customer’s token by its ID. Params:

token_id

ID of the token

options

Hash of options



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/processout/customer.rb', line 256

def find_token(token_id, options = {})
  request = Request.new(@client)
  path    = "/customers/" + CGI.escape(@id) + "/tokens/" + CGI.escape(token_id) + ""
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["token"]
  token = Token.new(@client)
  return_values.push(token.fill_with_data(body))

  
  return_values[0]
end

#new(data = {}) ⇒ Object

Create a new Customer using the current client



133
134
135
# File 'lib/processout/customer.rb', line 133

def new(data = {})
  Customer.new(@client, data)
end

#save(options = {}) ⇒ Object

Save the updated customer attributes. Params:

options

Hash of options



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/processout/customer.rb', line 415

def save(options = {})
  request = Request.new(@client)
  path    = "/customers/" + CGI.escape(@id) + ""
  data    = {
    "balance" => @balance, 
    "email" => @email, 
    "first_name" => @first_name, 
    "last_name" => @last_name, 
    "address1" => @address1, 
    "address2" => @address2, 
    "city" => @city, 
    "state" => @state, 
    "zip" => @zip, 
    "country_code" => @country_code, 
    "metadata" => 
  }

  response = Response.new(request.put(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["customer"]
  
  
  return_values.push(self.fill_with_data(body))
  

  
  return_values[0]
end