Class: VirtualMerchant::CreditCard

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ CreditCard

Returns a new instance of CreditCard.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/virtual_merchant/credit_card.rb', line 9

def initialize(info)
  @errors = {}
  check_for_errors(info) unless info[:encrypted]
  return unless valid?
  if info[:encrypted]
    from_encrypted(info)
  elsif info[:swipe]
    from_unencrypted_swipe(info[:swipe])
  else
    from_manual(info)
  end
end

Instance Attribute Details

#encryptedObject

Returns the value of attribute encrypted.



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

def encrypted
  @encrypted
end

#encrypted_track_1Object

Returns the value of attribute encrypted_track_1.



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

def encrypted_track_1
  @encrypted_track_1
end

#encrypted_track_2Object

Returns the value of attribute encrypted_track_2.



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

def encrypted_track_2
  @encrypted_track_2
end

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

#expirationObject

Returns the value of attribute expiration.



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

def expiration
  @expiration
end

#last_fourObject

Returns the value of attribute last_four.



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

def last_four
  @last_four
end

#name_on_cardObject

Returns the value of attribute name_on_card.



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

def name_on_card
  @name_on_card
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#security_codeObject

Returns the value of attribute security_code.



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

def security_code
  @security_code
end

#swipeObject

Returns the value of attribute swipe.



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

def swipe
  @swipe
end

#swipedObject

Returns the value of attribute swiped.



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

def swiped
  @swiped
end

#track2Object

Returns the value of attribute track2.



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

def track2
  @track2
end

#validObject

Returns the value of attribute valid.



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

def valid
  @valid
end

Instance Method Details

#blurred_numberObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/virtual_merchant/credit_card.rb', line 38

def blurred_number
  begin
    number = self.number.to_s
    leng = number.length
    n = number[0..1]
    (leng-6).times {n+= "*"}
    n += number[number.length-4..number.length]
    n
  rescue Exception => e
    puts "-"
    puts "Error in VirtualMerchant-Ruby Gem when trying to blur card number: #{e}."
    puts "You either passed a nil value for card_number or a number that is too short."
    puts caller
    puts "-"
  end
end

#check_for_errors(info) ⇒ Object



22
23
24
# File 'lib/virtual_merchant/credit_card.rb', line 22

def check_for_errors info
  @errors = VirtualMerchant::UserInput.new(info).errors
end

#encrypted?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/virtual_merchant/credit_card.rb', line 26

def encrypted?
  self.encrypted
end

#swiped?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/virtual_merchant/credit_card.rb', line 30

def swiped?
  self.swiped
end

#valid?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/virtual_merchant/credit_card.rb', line 34

def valid?
  errors.count == 0
end