Class: Pagseguro::Charge::CreditCard

Inherits:
Object
  • Object
show all
Defined in:
lib/pagseguro/charge/credit_card.rb,
lib/pagseguro/charge/payment_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.



20
21
22
23
24
25
26
# File 'lib/pagseguro/charge/credit_card.rb', line 20

def initialize(args = {})
  @security_code = args[:security_code]
  @number = args[:number]
  @exp_month = args[:exp_month]
  @exp_year = args[:exp_year]
  @holder = args[:holder]
end

Instance Attribute Details

#brandString

Credit card brand

Returns:

  • (String)

    the current value of brand



10
11
12
# File 'lib/pagseguro/charge/credit_card.rb', line 10

def brand
  @brand
end

#exp_monthinteger

Credit card expiration month

Returns:

  • (integer)

    the current value of exp_month



10
11
12
# File 'lib/pagseguro/charge/credit_card.rb', line 10

def exp_month
  @exp_month
end

#exp_yearInteger

Credit card expiration year

Returns:

  • (Integer)

    the current value of exp_year



10
11
12
# File 'lib/pagseguro/charge/credit_card.rb', line 10

def exp_year
  @exp_year
end

#first_digitsObject

Returns the value of attribute first_digits.



11
12
13
# File 'lib/pagseguro/charge/credit_card.rb', line 11

def first_digits
  @first_digits
end

#holderObject

Returns the value of attribute holder.



11
12
13
# File 'lib/pagseguro/charge/credit_card.rb', line 11

def holder
  @holder
end

#last_digitsObject

Returns the value of attribute last_digits.



11
12
13
# File 'lib/pagseguro/charge/credit_card.rb', line 11

def last_digits
  @last_digits
end

#numberLong

Credit card number

Returns:

  • (Long)

    the current value of number



10
11
12
# File 'lib/pagseguro/charge/credit_card.rb', line 10

def number
  @number
end

#security_codeString

Credit card security_code

Returns:

  • (String)

    the current value of security_code



10
11
12
# File 'lib/pagseguro/charge/credit_card.rb', line 10

def security_code
  @security_code
end

Class Method Details

.fill_from_json(data) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pagseguro/charge/credit_card.rb', line 34

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

  credit_card = new
  credit_card.number = data["number"]
  credit_card.exp_month = data["exp_month"]
  credit_card.exp_year = data["exp_year"]
  credit_card.security_code = data["security_code"]
  credit_card.first_digits = data["first_digits"]
  credit_card.last_digits = data["last_digits"]
  credit_card.brand = data["brand"]
  credit_card.holder = Holder.fill_from_json(data["holder"])
  credit_card
end

Instance Method Details

#as_json(options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pagseguro/charge/credit_card.rb', line 49

def as_json(options={})
  {
    brand: @brand,
    number: @number,
    exp_year: @exp_year,
    exp_month: @exp_month,
    security_code: @security_code,
    last_digits: @last_digits,
    first_digits: @first_digits,
    holder: @holder
  }
end

#to_json(*options) ⇒ Object



28
29
30
31
32
# File 'lib/pagseguro/charge/credit_card.rb', line 28

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