Class: MerbMerchant::Billing::CreditCard

Inherits:
Object
  • Object
show all
Includes:
CreditCardMethods, Validateable
Defined in:
lib/merb_merchant/billing/credit_card.rb,
lib/merb_merchant/billing/expiry_date.rb

Overview

Description

This credit card object can be used as a stand alone object. It acts just like an ActiveRecord object but doesn’t support the .save method as its not backed by a database.

For testing purposes, use the ‘bogus’ credit card type. This card skips the vast majority of validations. This allows you to focus on your core concerns until you’re ready to be more concerned with the details of particular creditcards or your gateway.

Testing With CreditCard

Often when testing we don’t care about the particulars of a given card type. When using the ‘test’ mode in your Gateway, there are six different valid card numbers: 1, 2, 3, ‘success’, ‘fail’, and ‘error’.

– For details, see CreditCardMethods#valid_number? ++

Example Usage

cc = CreditCard.new(
  :first_name => 'Steve', 
  :last_name  => 'Smith', 
  :month      => '9', 
  :year       => '2010', 
  :type       => 'visa', 
  :number     => '4242424242424242'
)

cc.valid? # => true
cc.display_number # => XXXX-XXXX-XXXX-4242

Defined Under Namespace

Classes: ExpiryDate

Constant Summary

Constants included from CreditCardMethods

MerbMerchant::Billing::CreditCardMethods::CARD_COMPANIES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validateable

#errors, #initialize, #valid?

Methods included from CreditCardMethods

included, #valid_expiry_year?, #valid_issue_number?, #valid_month?, #valid_start_year?

Instance Attribute Details

#first_nameObject

Essential attributes for a valid, non-bogus creditcards



47
48
49
# File 'lib/merb_merchant/billing/credit_card.rb', line 47

def first_name
  @first_name
end

#issue_numberObject

Required for Switch / Solo cards



50
51
52
# File 'lib/merb_merchant/billing/credit_card.rb', line 50

def issue_number
  @issue_number
end

#last_nameObject

Essential attributes for a valid, non-bogus creditcards



47
48
49
# File 'lib/merb_merchant/billing/credit_card.rb', line 47

def last_name
  @last_name
end

#monthObject

Essential attributes for a valid, non-bogus creditcards



47
48
49
# File 'lib/merb_merchant/billing/credit_card.rb', line 47

def month
  @month
end

#numberObject

Essential attributes for a valid, non-bogus creditcards



47
48
49
# File 'lib/merb_merchant/billing/credit_card.rb', line 47

def number
  @number
end

#start_monthObject

Required for Switch / Solo cards



50
51
52
# File 'lib/merb_merchant/billing/credit_card.rb', line 50

def start_month
  @start_month
end

#start_yearObject

Required for Switch / Solo cards



50
51
52
# File 'lib/merb_merchant/billing/credit_card.rb', line 50

def start_year
  @start_year
end

#typeObject

Essential attributes for a valid, non-bogus creditcards



47
48
49
# File 'lib/merb_merchant/billing/credit_card.rb', line 47

def type
  @type
end

#verification_valueObject

Optional verification_value (CVV, CVV2 etc). Gateways will try their best to run validation on the passed in value if it is supplied



54
55
56
# File 'lib/merb_merchant/billing/credit_card.rb', line 54

def verification_value
  @verification_value
end

#yearObject

Essential attributes for a valid, non-bogus creditcards



47
48
49
# File 'lib/merb_merchant/billing/credit_card.rb', line 47

def year
  @year
end

Class Method Details

.requires_verification_value?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/merb_merchant/billing/credit_card.rb', line 106

def self.requires_verification_value?
  require_verification_value
end

Instance Method Details

#display_numberObject

Show the card number, with all but last 4 numbers replace with “X”. (XXXX-XXXX-XXXX-4338)



86
87
88
# File 'lib/merb_merchant/billing/credit_card.rb', line 86

def display_number
  self.class.mask(number)
end

#expired?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/merb_merchant/billing/credit_card.rb', line 61

def expired?
  expiry_date.expired?
end

#expiry_dateObject

Provides proxy access to an expiry date object



57
58
59
# File 'lib/merb_merchant/billing/credit_card.rb', line 57

def expiry_date
  ExpiryDate.new(@month, @year)
end

#first_name?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/merb_merchant/billing/credit_card.rb', line 69

def first_name?
  !@first_name.blank?
end

#last_digitsObject



90
91
92
# File 'lib/merb_merchant/billing/credit_card.rb', line 90

def last_digits
  self.class.last_digits(number)
end

#last_name?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/merb_merchant/billing/credit_card.rb', line 73

def last_name?
  !@last_name.blank?
end

#nameObject



77
78
79
# File 'lib/merb_merchant/billing/credit_card.rb', line 77

def name
  "#{@first_name} #{@last_name}"
end

#name?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/merb_merchant/billing/credit_card.rb', line 65

def name?
  first_name? && last_name?
end

#require_verification_valueObject

Attributes



43
# File 'lib/merb_merchant/billing/credit_card.rb', line 43

cattr_accessor :require_verification_value

#validateObject



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/merb_merchant/billing/credit_card.rb', line 94

def validate
  validate_essential_attributes

  # Bogus card is pretty much for testing purposes. Lets just skip these extra tests if its used
  return if type == 'bogus'

  validate_card_type
  validate_card_number
  validate_verification_value
  validate_switch_or_solo_attributes
end

#verification_value?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/merb_merchant/billing/credit_card.rb', line 81

def verification_value?
  !@verification_value.blank?
end