Class: Rack::Payment::CreditCard

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-payment/credit_card.rb

Constant Summary collapse

REQUIRED =
%w( first_name last_name type number month year verification_value )

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCreditCard

Returns a new instance of CreditCard.



10
11
12
# File 'lib/rack-payment/credit_card.rb', line 10

def initialize
  @active_merchant_card ||= ActiveMerchant::Billing::CreditCard.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/rack-payment/credit_card.rb', line 18

def method_missing name, *args, &block
  if active_merchant_card.respond_to?(name)
    active_merchant_card.send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#active_merchant_cardObject

Returns the value of attribute active_merchant_card.



8
9
10
# File 'lib/rack-payment/credit_card.rb', line 8

def active_merchant_card
  @active_merchant_card
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/rack-payment/credit_card.rb', line 14

def [] key
  send key
end

#cvvObject

Aliases



45
# File 'lib/rack-payment/credit_card.rb', line 45

def cvv()       verification_value              end

#cvv=(value) ⇒ Object



46
# File 'lib/rack-payment/credit_card.rb', line 46

def cvv=(value) self.verification_value=(value) end

#errorsObject



62
63
64
65
66
67
68
# File 'lib/rack-payment/credit_card.rb', line 62

def errors
  REQUIRED.inject([]) do |errors, required_attribute_name|
    value = send required_attribute_name
    errors << "#{ required_attribute_name.titleize } is required" if value.nil? or value.empty?
    errors
  end
end

#expiration_monthObject



51
# File 'lib/rack-payment/credit_card.rb', line 51

def expiration_month()       month              end

#expiration_month=(value) ⇒ Object



52
# File 'lib/rack-payment/credit_card.rb', line 52

def expiration_month=(value) self.month=(value) end

#expiration_yearObject



48
# File 'lib/rack-payment/credit_card.rb', line 48

def expiration_year()       year              end

#expiration_year=(value) ⇒ Object



49
# File 'lib/rack-payment/credit_card.rb', line 49

def expiration_year=(value) self.year=(value) end

#full_nameObject



58
59
60
# File 'lib/rack-payment/credit_card.rb', line 58

def full_name
  [ first_name, last_name ].compact.join(' ')
end

#fully_filled_out?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/rack-payment/credit_card.rb', line 34

def fully_filled_out?
  # errors.empty?
  raise "Not yet spec'd"
end

#partially_filled_out?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/rack-payment/credit_card.rb', line 26

def partially_filled_out?
  %w( type number verification_value month year first_name last_name ).each do |field|
    return true unless send(field).nil?
  end

  return false
end

#typeObject



54
55
56
# File 'lib/rack-payment/credit_card.rb', line 54

def type
  active_merchant_card.type
end

#update(options) ⇒ Object



39
40
41
# File 'lib/rack-payment/credit_card.rb', line 39

def update options
  options.each {|key, value| send "#{key}=", value }
end