Object
A CreditCard object represents a physical credit card, and is capable of validating the various data associated with these.
At the moment, the following credit card types are supported:
Visa
MasterCard
Discover
American Express
Diner’s Club
JCB
Switch
Solo
Dankort
Maestro
Forbrugsforeningen
Laser
For testing purposes, use the ‘bogus’ credit card type. This skips the vast majority of validations, allowing you to focus on your core concerns until you’re ready to be more concerned with the details of particular credit cards or your gateway.
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::ClassMethods#valid_number?}
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
Returns or sets the credit card type.
Valid card types are
+’visa’+
+’master’+
+’discover’+
+’american_express’+
+’diners_club’+
+’jcb’+
+’switch’+
+’solo’+
+’dankort’+
+’maestro’+
+’forbrugsforeningen’+
+’laser’+
Or, if you wish to test your implementation, +’bogus’+.
@return (String) the credit card type
Returns or sets the card verification value.
This attribute is optional but recommended. The verification value is a card security code. If provided, the gateway will attempt to validate the value.
@return [String] the verification value
Returns a display-friendly version of the card number.
All but the last 4 numbers are replaced with an “X”, and hyphens are inserted in order to improve legibility.
@example
credit_card = CreditCard.new(:number => "2132542376824338") credit_card.display_number # "XXXX-XXXX-XXXX-4338"
@return [String] a display-friendly version of the card number
# File lib/active_merchant/billing/credit_card.rb, line 173 173: def display_number 174: self.class.mask(number) 175: end
Returns whether the credit card has expired.
@return true if the card has expired, false otherwise
# File lib/active_merchant/billing/credit_card.rb, line 127 127: def expired? 128: expiry_date.expired? 129: end
Provides proxy access to an expiry date object
@return [ExpiryDate]
# File lib/active_merchant/billing/credit_card.rb, line 120 120: def expiry_date 121: ExpiryDate.new(@month, @year) 122: end
Returns whether the first_name attribute has been set.
# File lib/active_merchant/billing/credit_card.rb, line 137 137: def first_name? 138: @first_name.present? 139: end
# File lib/active_merchant/billing/credit_card.rb, line 177 177: def last_digits 178: self.class.last_digits(number) 179: end
Returns whether the last_name attribute has been set.
# File lib/active_merchant/billing/credit_card.rb, line 142 142: def last_name? 143: @last_name.present? 144: end
Returns the full name of the card holder.
@return [String] the full name of the card holder
# File lib/active_merchant/billing/credit_card.rb, line 149 149: def name 150: [@first_name, @last_name].compact.join(' ') 151: end
# File lib/active_merchant/billing/credit_card.rb, line 153 153: def name=(full_name) 154: names = full_name.split 155: self.last_name = names.pop 156: self.first_name = names.join(" ") 157: end
Returns whether either the first_name or the last_name attributes has been set.
# File lib/active_merchant/billing/credit_card.rb, line 132 132: def name? 133: first_name? || last_name? 134: end
Validates the credit card details.
Any validation errors are added to the {#} attribute.
# File lib/active_merchant/billing/credit_card.rb, line 184 184: def validate 185: validate_essential_attributes 186: 187: # Bogus card is pretty much for testing purposes. Lets just skip these extra tests if its used 188: return if type == 'bogus' 189: 190: validate_card_type 191: validate_card_number 192: validate_verification_value 193: validate_switch_or_solo_attributes 194: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.