Class: MerbMerchant::Billing::CreditCard
- Inherits:
-
Object
- Object
- MerbMerchant::Billing::CreditCard
- 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
-
#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
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/merb_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/merb_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/merb_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/merb_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/merb_merchant/billing/credit_card.rb', line 47 def number @number end |
#start_month ⇒ Object
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_year ⇒ Object
Required for Switch / Solo cards
50 51 52 |
# File 'lib/merb_merchant/billing/credit_card.rb', line 50 def start_year @start_year end |
#type ⇒ Object
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_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/merb_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/merb_merchant/billing/credit_card.rb', line 47 def year @year end |
Class Method Details
.requires_verification_value? ⇒ 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_number ⇒ Object
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
61 62 63 |
# File 'lib/merb_merchant/billing/credit_card.rb', line 61 def expired? expiry_date.expired? end |
#expiry_date ⇒ Object
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
69 70 71 |
# File 'lib/merb_merchant/billing/credit_card.rb', line 69 def first_name? !@first_name.blank? end |
#last_digits ⇒ Object
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
73 74 75 |
# File 'lib/merb_merchant/billing/credit_card.rb', line 73 def last_name? !@last_name.blank? end |
#name ⇒ Object
77 78 79 |
# File 'lib/merb_merchant/billing/credit_card.rb', line 77 def name "#{@first_name} #{@last_name}" end |
#name? ⇒ Boolean
65 66 67 |
# File 'lib/merb_merchant/billing/credit_card.rb', line 65 def name? first_name? && last_name? end |
#require_verification_value ⇒ Object
Attributes
43 |
# File 'lib/merb_merchant/billing/credit_card.rb', line 43 cattr_accessor :require_verification_value |
#validate ⇒ Object
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
81 82 83 |
# File 'lib/merb_merchant/billing/credit_card.rb', line 81 def verification_value? !@verification_value.blank? end |