Class: ProcessOut::CardCreateRequest

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes the CardCreateRequest object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/processout/card_create_request.rb', line 161

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

  self.device = data.fetch(:device, nil)
  self.name = data.fetch(:name, nil)
  self.number = data.fetch(:number, nil)
  self.exp_day = data.fetch(:exp_day, nil)
  self.exp_month = data.fetch(:exp_month, nil)
  self.exp_year = data.fetch(:exp_year, nil)
  self.cvc2 = data.fetch(:cvc2, nil)
  self.preferred_scheme = data.fetch(:preferred_scheme, nil)
  self.preferred_card_type = data.fetch(:preferred_card_type, nil)
  self. = data.fetch(:metadata, nil)
  self.token_type = data.fetch(:token_type, nil)
  self.eci = data.fetch(:eci, nil)
  self.cryptogram = data.fetch(:cryptogram, nil)
  self.applepay_response = data.fetch(:applepay_response, nil)
  self.applepay_mid = data.fetch(:applepay_mid, nil)
  self.payment_token = data.fetch(:payment_token, nil)
  self.contact = data.fetch(:contact, nil)
  self.shipping = data.fetch(:shipping, nil)
  self.scheme_details = data.fetch(:scheme_details, nil)
  
end

Instance Attribute Details

#applepay_midObject

Returns the value of attribute applepay_mid.



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

def applepay_mid
  @applepay_mid
end

#applepay_responseObject

Returns the value of attribute applepay_response.



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

def applepay_response
  @applepay_response
end

#contactObject

Returns the value of attribute contact.



27
28
29
# File 'lib/processout/card_create_request.rb', line 27

def contact
  @contact
end

#cryptogramObject

Returns the value of attribute cryptogram.



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

def cryptogram
  @cryptogram
end

#cvc2Object

Returns the value of attribute cvc2.



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

def cvc2
  @cvc2
end

#deviceObject

Returns the value of attribute device.



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

def device
  @device
end

#eciObject

Returns the value of attribute eci.



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

def eci
  @eci
end

#exp_dayObject

Returns the value of attribute exp_day.



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

def exp_day
  @exp_day
end

#exp_monthObject

Returns the value of attribute exp_month.



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

def exp_month
  @exp_month
end

#exp_yearObject

Returns the value of attribute exp_year.



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

def exp_year
  @exp_year
end

#metadataObject

Returns the value of attribute metadata.



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

def 
  @metadata
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#payment_tokenObject

Returns the value of attribute payment_token.



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

def payment_token
  @payment_token
end

#preferred_card_typeObject

Returns the value of attribute preferred_card_type.



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

def preferred_card_type
  @preferred_card_type
end

#preferred_schemeObject

Returns the value of attribute preferred_scheme.



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

def preferred_scheme
  @preferred_scheme
end

#scheme_detailsObject

Returns the value of attribute scheme_details.



29
30
31
# File 'lib/processout/card_create_request.rb', line 29

def scheme_details
  @scheme_details
end

#shippingObject

Returns the value of attribute shipping.



28
29
30
# File 'lib/processout/card_create_request.rb', line 28

def shipping
  @shipping
end

#token_typeObject

Returns the value of attribute token_type.



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

def token_type
  @token_type
end

Instance Method Details

#create(options = {}) ⇒ Object

Create a new card. Params:

options

Hash of options



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/processout/card_create_request.rb', line 317

def create(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/cards"
  data    = {
    "device" => @device, 
    "name" => @name, 
    "number" => @number, 
    "exp_day" => @exp_day, 
    "exp_month" => @exp_month, 
    "exp_year" => @exp_year, 
    "cvc2" => @cvc2, 
    "preferred_scheme" => @preferred_scheme, 
    "preferred_card_type" => @preferred_card_type, 
    "metadata" => @metadata, 
    "token_type" => @token_type, 
    "eci" => @eci, 
    "cryptogram" => @cryptogram, 
    "applepay_response" => @applepay_response, 
    "applepay_mid" => @applepay_mid, 
    "payment_token" => @payment_token, 
    "contact" => @contact, 
    "shipping" => @shipping, 
    "scheme_details" => @scheme_details
  }

  response = Response.new(request.post(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body.key?("card") ? body["card"] : nil
  
  
  return_values.push(self.fill_with_data(body))
  

  
  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



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/processout/card_create_request.rb', line 219

def fill_with_data(data)
  if data.nil?
    return self
  end
  if data.include? "device"
    self.device = data["device"]
  end
  if data.include? "name"
    self.name = data["name"]
  end
  if data.include? "number"
    self.number = data["number"]
  end
  if data.include? "exp_day"
    self.exp_day = data["exp_day"]
  end
  if data.include? "exp_month"
    self.exp_month = data["exp_month"]
  end
  if data.include? "exp_year"
    self.exp_year = data["exp_year"]
  end
  if data.include? "cvc2"
    self.cvc2 = data["cvc2"]
  end
  if data.include? "preferred_scheme"
    self.preferred_scheme = data["preferred_scheme"]
  end
  if data.include? "preferred_card_type"
    self.preferred_card_type = data["preferred_card_type"]
  end
  if data.include? "metadata"
    self. = data["metadata"]
  end
  if data.include? "token_type"
    self.token_type = data["token_type"]
  end
  if data.include? "eci"
    self.eci = data["eci"]
  end
  if data.include? "cryptogram"
    self.cryptogram = data["cryptogram"]
  end
  if data.include? "applepay_response"
    self.applepay_response = data["applepay_response"]
  end
  if data.include? "applepay_mid"
    self.applepay_mid = data["applepay_mid"]
  end
  if data.include? "payment_token"
    self.payment_token = data["payment_token"]
  end
  if data.include? "contact"
    self.contact = data["contact"]
  end
  if data.include? "shipping"
    self.shipping = data["shipping"]
  end
  if data.include? "scheme_details"
    self.scheme_details = data["scheme_details"]
  end
  
  self
end

#new(data = {}) ⇒ Object

Create a new CardCreateRequest using the current client



187
188
189
# File 'lib/processout/card_create_request.rb', line 187

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

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/processout/card_create_request.rb', line 287

def prefill(data)
  if data.nil?
    return self
  end
  self.device = data.fetch(:device, self.device)
  self.name = data.fetch(:name, self.name)
  self.number = data.fetch(:number, self.number)
  self.exp_day = data.fetch(:exp_day, self.exp_day)
  self.exp_month = data.fetch(:exp_month, self.exp_month)
  self.exp_year = data.fetch(:exp_year, self.exp_year)
  self.cvc2 = data.fetch(:cvc2, self.cvc2)
  self.preferred_scheme = data.fetch(:preferred_scheme, self.preferred_scheme)
  self.preferred_card_type = data.fetch(:preferred_card_type, self.preferred_card_type)
  self. = data.fetch(:metadata, self.)
  self.token_type = data.fetch(:token_type, self.token_type)
  self.eci = data.fetch(:eci, self.eci)
  self.cryptogram = data.fetch(:cryptogram, self.cryptogram)
  self.applepay_response = data.fetch(:applepay_response, self.applepay_response)
  self.applepay_mid = data.fetch(:applepay_mid, self.applepay_mid)
  self.payment_token = data.fetch(:payment_token, self.payment_token)
  self.contact = data.fetch(:contact, self.contact)
  self.shipping = data.fetch(:shipping, self.shipping)
  self.scheme_details = data.fetch(:scheme_details, self.scheme_details)
  
  self
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/processout/card_create_request.rb', line 192

def to_json(options)
  {
      "device": self.device,
      "name": self.name,
      "number": self.number,
      "exp_day": self.exp_day,
      "exp_month": self.exp_month,
      "exp_year": self.exp_year,
      "cvc2": self.cvc2,
      "preferred_scheme": self.preferred_scheme,
      "preferred_card_type": self.preferred_card_type,
      "metadata": self.,
      "token_type": self.token_type,
      "eci": self.eci,
      "cryptogram": self.cryptogram,
      "applepay_response": self.applepay_response,
      "applepay_mid": self.applepay_mid,
      "payment_token": self.payment_token,
      "contact": self.contact,
      "shipping": self.shipping,
      "scheme_details": self.scheme_details,
  }.to_json
end