Class ActiveMerchant::Billing::CreditCard
In: lib/active_merchant/billing/credit_card.rb
lib/active_merchant/billing/expiry_date.rb
Parent: Object

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’.

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

Methods

Included Modules

CreditCardMethods Validateable

Attributes

first_name  [RW]  Essential attributes for a valid, non-bogus creditcards
issue_number  [RW]  Required for Switch / Solo cards
last_name  [RW]  Essential attributes for a valid, non-bogus creditcards
month  [RW]  Essential attributes for a valid, non-bogus creditcards
number  [RW]  Essential attributes for a valid, non-bogus creditcards
start_month  [RW]  Required for Switch / Solo cards
start_year  [RW]  Required for Switch / Solo cards
type  [RW]  Essential attributes for a valid, non-bogus creditcards
verification_value  [RW]  Optional verification_value (CVV, CVV2 etc). Gateways will try their best to run validation on the passed in value if it is supplied
year  [RW]  Essential attributes for a valid, non-bogus creditcards

Public Class methods

[Source]

     # File lib/active_merchant/billing/credit_card.rb, line 106
106:       def self.requires_verification_value?
107:         require_verification_value
108:       end

Public Instance methods

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

[Source]

    # File lib/active_merchant/billing/credit_card.rb, line 86
86:       def display_number
87:         self.class.mask(number)
88:       end

[Source]

    # File lib/active_merchant/billing/credit_card.rb, line 61
61:       def expired?
62:         expiry_date.expired?
63:       end

Provides proxy access to an expiry date object

[Source]

    # File lib/active_merchant/billing/credit_card.rb, line 57
57:       def expiry_date
58:         ExpiryDate.new(@month, @year)
59:       end

[Source]

    # File lib/active_merchant/billing/credit_card.rb, line 69
69:       def first_name?
70:         !@first_name.blank?
71:       end

[Source]

    # File lib/active_merchant/billing/credit_card.rb, line 90
90:       def last_digits
91:         self.class.last_digits(number)
92:       end

[Source]

    # File lib/active_merchant/billing/credit_card.rb, line 73
73:       def last_name?
74:         !@last_name.blank?
75:       end

[Source]

    # File lib/active_merchant/billing/credit_card.rb, line 77
77:       def name
78:         "#{@first_name} #{@last_name}"
79:       end

[Source]

    # File lib/active_merchant/billing/credit_card.rb, line 65
65:       def name?
66:         first_name? && last_name?
67:       end

[Source]

     # File lib/active_merchant/billing/credit_card.rb, line 94
 94:       def validate
 95:         validate_essential_attributes
 96: 
 97:         # Bogus card is pretty much for testing purposes. Lets just skip these extra tests if its used
 98:         return if type == 'bogus'
 99: 
100:         validate_card_type
101:         validate_card_number
102:         validate_verification_value
103:         validate_switch_or_solo_attributes
104:       end

[Source]

    # File lib/active_merchant/billing/credit_card.rb, line 81
81:       def verification_value?
82:         !@verification_value.blank?
83:       end

[Validate]