Class: Cielo::API30::CreditCard

Inherits:
Object
  • Object
show all
Defined in:
lib/cielo/api30/credit_card.rb

Overview

Credit card data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ CreditCard

Returns a new instance of CreditCard.



21
22
23
24
25
# File 'lib/cielo/api30/credit_card.rb', line 21

def initialize(args = {})
  @security_code = args[:security_code]
  @brand = args[:brand]
  @card_token = args[:token]
end

Instance Attribute Details

#brandString

Credit card brand

Returns:

  • (String)

    the current value of brand



12
13
14
# File 'lib/cielo/api30/credit_card.rb', line 12

def brand
  @brand
end

#card_numberString

Credit card number

Returns:

  • (String)

    the current value of card_number



12
13
14
# File 'lib/cielo/api30/credit_card.rb', line 12

def card_number
  @card_number
end

#card_tokenString

Card token

Returns:

  • (String)

    the current value of card_token



12
13
14
# File 'lib/cielo/api30/credit_card.rb', line 12

def card_token
  @card_token
end

#expiration_dateString

Credit card expiration date

Returns:

  • (String)

    the current value of expiration_date



12
13
14
# File 'lib/cielo/api30/credit_card.rb', line 12

def expiration_date
  @expiration_date
end

#holderString

Holder name

Returns:

  • (String)

    the current value of holder



12
13
14
# File 'lib/cielo/api30/credit_card.rb', line 12

def holder
  @holder
end

#save_cardBoolean

Whether or not to save the card

Returns:

  • (Boolean)

    the current value of save_card



12
13
14
# File 'lib/cielo/api30/credit_card.rb', line 12

def save_card
  @save_card
end

#security_codeString

Credit card security code

Returns:

  • (String)

    the current value of security_code



12
13
14
# File 'lib/cielo/api30/credit_card.rb', line 12

def security_code
  @security_code
end

Class Method Details

.from_json(data) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cielo/api30/credit_card.rb', line 33

def self.from_json(data)
  return if data.nil?

  credit_card = new
  credit_card.card_number = data["CardNumber"]
  credit_card.holder = data["Holder"]
  credit_card.expiration_date = data["ExpirationDate"]
  credit_card.security_code = data["SecurityCode"]
  credit_card.save_card = data["SaveCard"]
  credit_card.brand = data["Brand"]
  credit_card.card_token = data["CardToken"]
  credit_card
end

Instance Method Details

#as_json(options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cielo/api30/credit_card.rb', line 47

def as_json(options={})
  {
    CardNumber: @card_number,
    Holder: @holder,
    ExpirationDate: @expiration_date,
    SecurityCode: @security_code,
    SaveCard: @save_card,
    Brand: @brand,
    CardToken: @card_token
  }
end

#to_json(*options) ⇒ Object



27
28
29
30
31
# File 'lib/cielo/api30/credit_card.rb', line 27

def to_json(*options)
  hash = as_json(*options)
  hash.reject! {|k,v| v.nil?}
  hash.to_json(*options)
end