Class: RocketGate::CreditCard

Inherits:
Object
  • Object
show all
Includes:
Hashable, Validatable
Defined in:
lib/rocketgate/credit_card.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hashable

included

Methods included from Validatable

included, #invalid_attributes, #validate!

Constructor Details

#initialize(*args) ⇒ CreditCard

Returns a new instance of CreditCard.



16
17
18
19
20
# File 'lib/rocketgate/credit_card.rb', line 16

def initialize(*args)
  @number, @exp_month, @exp_year, @cvv = *args

  clean_number! if @number
end

Instance Attribute Details

#card_hashObject

Returns the value of attribute card_hash.



5
6
7
# File 'lib/rocketgate/credit_card.rb', line 5

def card_hash
  @card_hash
end

#cvvObject

Returns the value of attribute cvv.



5
6
7
# File 'lib/rocketgate/credit_card.rb', line 5

def cvv
  @cvv
end

#exp_monthObject

Returns the value of attribute exp_month.



5
6
7
# File 'lib/rocketgate/credit_card.rb', line 5

def exp_month
  @exp_month
end

#exp_yearObject

Returns the value of attribute exp_year.



5
6
7
# File 'lib/rocketgate/credit_card.rb', line 5

def exp_year
  @exp_year
end

#numberObject

Returns the value of attribute number.



5
6
7
# File 'lib/rocketgate/credit_card.rb', line 5

def number
  @number
end

Class Method Details

.from_card_hash(card_hash) ⇒ Object



22
23
24
25
26
# File 'lib/rocketgate/credit_card.rb', line 22

def self.from_card_hash(card_hash)
  new.tap do |cc|
    cc.card_hash = card_hash
  end
end

Instance Method Details

#to_hashObject



28
29
30
# File 'lib/rocketgate/credit_card.rb', line 28

def to_hash
  card_hash ? { cardHash: card_hash } : super
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/rocketgate/credit_card.rb', line 32

def valid?
  !card_hash.nil? || super
end