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



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/processout/card_create_request.rb', line 139

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. = 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)
  
end

Instance Attribute Details

#applepay_midObject

Returns the value of attribute applepay_mid.



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

def applepay_mid
  @applepay_mid
end

#applepay_responseObject

Returns the value of attribute applepay_response.



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

def applepay_response
  @applepay_response
end

#contactObject

Returns the value of attribute contact.



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

def contact
  @contact
end

#cryptogramObject

Returns the value of attribute cryptogram.



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

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.



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

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.



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

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.



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

def payment_token
  @payment_token
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

#shippingObject

Returns the value of attribute shipping.



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

def shipping
  @shipping
end

#token_typeObject

Returns the value of attribute token_type.



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

def token_type
  @token_type
end

Instance Method Details

#create(options = {}) ⇒ Object

Create a new card. Params:

options

Hash of options



283
284
285
286
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
313
314
315
316
317
318
319
320
# File 'lib/processout/card_create_request.rb', line 283

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, 
    "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
  }

  response = Response.new(request.post(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["card"]
  
  
  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



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
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
# File 'lib/processout/card_create_request.rb', line 193

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? "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
  
  self
end

#new(data = {}) ⇒ Object

Create a new CardCreateRequest using the current client



163
164
165
# File 'lib/processout/card_create_request.rb', line 163

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



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/processout/card_create_request.rb', line 255

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. = 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
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/processout/card_create_request.rb', line 168

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,
      "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,
  }.to_json
end