Class: ActiveMerchant::Billing::CreditCard
- Inherits:
-
Object
- Object
- ActiveMerchant::Billing::CreditCard
- Includes:
- CreditCardMethods, Validateable
- Defined in:
- lib/active_merchant/billing/credit_card.rb,
lib/active_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
ActiveMerchant::Billing::CreditCardMethods::CARD_COMPANIES
Instance Attribute Summary collapse
-
#first_name ⇒ Object
Essential attributes for a valid, non-bogus creditcards.
-
#issue_number ⇒ Object
Required for Switch / Solo cards.
-
#last_name ⇒ Object
Essential attributes for a valid, non-bogus creditcards.
-
#month ⇒ Object
Essential attributes for a valid, non-bogus creditcards.
-
#number ⇒ Object
Essential attributes for a valid, non-bogus creditcards.
-
#start_month ⇒ Object
Required for Switch / Solo cards.
-
#start_year ⇒ Object
Required for Switch / Solo cards.
-
#type ⇒ Object
(also: #brand)
Essential attributes for a valid, non-bogus creditcards.
-
#verification_value ⇒ Object
Optional verification_value (CVV, CVV2 etc).
-
#year ⇒ Object
Essential attributes for a valid, non-bogus creditcards.
Class Method Summary collapse
Instance Method Summary collapse
-
#display_number ⇒ Object
Show the card number, with all but last 4 numbers replace with “X”.
- #expired? ⇒ Boolean
-
#expiry_date ⇒ Object
Provides proxy access to an expiry date object.
- #first_name? ⇒ Boolean
- #last_digits ⇒ Object
- #last_name? ⇒ Boolean
- #name ⇒ Object
- #name? ⇒ Boolean
-
#require_verification_value ⇒ Object
Attributes.
- #validate ⇒ Object
- #verification_value? ⇒ Boolean
Methods included from Validateable
Methods included from CreditCardMethods
included, #valid_expiry_year?, #valid_issue_number?, #valid_month?, #valid_start_year?
Instance Attribute Details
#first_name ⇒ Object
Essential attributes for a valid, non-bogus creditcards
47 48 49 |
# File 'lib/active_merchant/billing/credit_card.rb', line 47 def first_name @first_name end |
#issue_number ⇒ Object
Required for Switch / Solo cards
50 51 52 |
# File 'lib/active_merchant/billing/credit_card.rb', line 50 def issue_number @issue_number end |
#last_name ⇒ Object
Essential attributes for a valid, non-bogus creditcards
47 48 49 |
# File 'lib/active_merchant/billing/credit_card.rb', line 47 def last_name @last_name end |
#month ⇒ Object
Essential attributes for a valid, non-bogus creditcards
47 48 49 |
# File 'lib/active_merchant/billing/credit_card.rb', line 47 def month @month end |
#number ⇒ Object
Essential attributes for a valid, non-bogus creditcards
47 48 49 |
# File 'lib/active_merchant/billing/credit_card.rb', line 47 def number @number end |
#start_month ⇒ Object
Required for Switch / Solo cards
50 51 52 |
# File 'lib/active_merchant/billing/credit_card.rb', line 50 def start_month @start_month end |
#start_year ⇒ Object
Required for Switch / Solo cards
50 51 52 |
# File 'lib/active_merchant/billing/credit_card.rb', line 50 def start_year @start_year end |
#type ⇒ Object Also known as: brand
Essential attributes for a valid, non-bogus creditcards
47 48 49 |
# File 'lib/active_merchant/billing/credit_card.rb', line 47 def type @type end |
#verification_value ⇒ Object
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/active_merchant/billing/credit_card.rb', line 54 def verification_value @verification_value end |
#year ⇒ Object
Essential attributes for a valid, non-bogus creditcards
47 48 49 |
# File 'lib/active_merchant/billing/credit_card.rb', line 47 def year @year end |
Class Method Details
.requires_verification_value? ⇒ Boolean
108 109 110 |
# File 'lib/active_merchant/billing/credit_card.rb', line 108 def self.requires_verification_value? require_verification_value end |
Instance Method Details
#display_number ⇒ Object
Show the card number, with all but last 4 numbers replace with “X”. (XXXX-XXXX-XXXX-4338)
88 89 90 |
# File 'lib/active_merchant/billing/credit_card.rb', line 88 def display_number self.class.mask(number) end |
#expired? ⇒ Boolean
63 64 65 |
# File 'lib/active_merchant/billing/credit_card.rb', line 63 def expired? expiry_date.expired? end |
#expiry_date ⇒ Object
Provides proxy access to an expiry date object
59 60 61 |
# File 'lib/active_merchant/billing/credit_card.rb', line 59 def expiry_date ExpiryDate.new(@month, @year) end |
#first_name? ⇒ Boolean
71 72 73 |
# File 'lib/active_merchant/billing/credit_card.rb', line 71 def first_name? @first_name.present? end |
#last_digits ⇒ Object
92 93 94 |
# File 'lib/active_merchant/billing/credit_card.rb', line 92 def last_digits self.class.last_digits(number) end |
#last_name? ⇒ Boolean
75 76 77 |
# File 'lib/active_merchant/billing/credit_card.rb', line 75 def last_name? @last_name.present? end |
#name ⇒ Object
79 80 81 |
# File 'lib/active_merchant/billing/credit_card.rb', line 79 def name [@first_name, @last_name].compact.join(' ') end |
#name? ⇒ Boolean
67 68 69 |
# File 'lib/active_merchant/billing/credit_card.rb', line 67 def name? first_name? || last_name? end |
#require_verification_value ⇒ Object
Attributes
43 |
# File 'lib/active_merchant/billing/credit_card.rb', line 43 cattr_accessor :require_verification_value |
#validate ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/active_merchant/billing/credit_card.rb', line 96 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
83 84 85 |
# File 'lib/active_merchant/billing/credit_card.rb', line 83 def verification_value? !@verification_value.blank? end |