lib/active_merchant/billing/credit_card.rb in activemerchant-1.23.0 vs lib/active_merchant/billing/credit_card.rb in activemerchant-1.24.0

- old
+ new

@@ -20,16 +20,16 @@ # * Dankort # * Maestro # * Forbrugsforeningen # * Laser # - # For testing purposes, use the 'bogus' credit card type. This skips the vast majority of + # For testing purposes, use the 'bogus' credit card brand. 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. # # == Testing With CreditCard - # Often when testing we don't care about the particulars of a given card type. When using the 'test' + # Often when testing we don't care about the particulars of a given card brand. 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?} # @@ -37,11 +37,11 @@ # cc = CreditCard.new( # :first_name => 'Steve', # :last_name => 'Smith', # :month => '9', # :year => '2010', - # :type => 'visa', + # :brand => 'visa', # :number => '4242424242424242' # ) # # cc.valid? # => true # cc.display_number # => XXXX-XXXX-XXXX-4242 @@ -66,11 +66,11 @@ # Returns or sets the expiry year for the card. # # @return [Integer] attr_accessor :year - # Returns or sets the credit card type. + # Returns or sets the credit card brand. # # Valid card types are # # * +'visa'+ # * +'master'+ @@ -85,12 +85,12 @@ # * +'forbrugsforeningen'+ # * +'laser'+ # # Or, if you wish to test your implementation, +'bogus'+. # - # @return (String) the credit card type - attr_accessor :type + # @return (String) the credit card brand + attr_accessor :brand # Returns or sets the first name of the card holder. # # @return [String] attr_accessor :first_name @@ -110,12 +110,20 @@ # the gateway will attempt to validate the value. # # @return [String] the verification value attr_accessor :verification_value - alias_method :brand, :type + def type + self.class.deprecated "CreditCard#type is deprecated and will be removed from a future release of ActiveMerchant. Please use CreditCard#brand instead." + brand + end + def type=(value) + self.class.deprecated "CreditCard#type is deprecated and will be removed from a future release of ActiveMerchant. Please use CreditCard#brand instead." + self.brand = value + end + # Provides proxy access to an expiry date object # # @return [ExpiryDate] def expiry_date ExpiryDate.new(@month, @year) @@ -187,13 +195,13 @@ # Any validation errors are added to the {#errors} attribute. 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' + return if brand == 'bogus' - validate_card_type + validate_card_brand validate_card_number validate_verification_value validate_switch_or_solo_attributes end @@ -207,31 +215,33 @@ self.month = month.to_i self.year = year.to_i self.start_month = start_month.to_i unless start_month.nil? self.start_year = start_year.to_i unless start_year.nil? self.number = number.to_s.gsub(/[^\d]/, "") - self.type.downcase! if type.respond_to?(:downcase) - self.type = self.class.type?(number) if type.blank? + self.brand.downcase! if brand.respond_to?(:downcase) + self.brand = self.class.brand?(number) if brand.blank? end def validate_card_number #:nodoc: if number.blank? errors.add :number, "is required" elsif !CreditCard.valid_number?(number) errors.add :number, "is not a valid credit card number" end - unless errors.on(:number) || errors.on(:type) - errors.add :type, "is not the correct card type" unless CreditCard.matching_type?(number, type) + unless errors.on(:number) || errors.on(:brand) + errors.add :brand, "is not the correct card brand" unless CreditCard.matching_brand?(number, brand) end end - def validate_card_type #:nodoc: - errors.add :type, "is required" if type.blank? && number.present? - errors.add :type, "is invalid" unless type.blank? || CreditCard.card_companies.keys.include?(type) + def validate_card_brand #:nodoc: + errors.add :brand, "is required" if brand.blank? && number.present? + errors.add :brand, "is invalid" unless brand.blank? || CreditCard.card_companies.keys.include?(brand) end + alias_method :validate_card_type, :validate_card_brand + def validate_essential_attributes #:nodoc: errors.add :first_name, "cannot be empty" if @first_name.blank? errors.add :last_name, "cannot be empty" if @last_name.blank? if @month.to_i.zero? || @year.to_i.zero? @@ -243,10 +253,10 @@ errors.add :year, "is not a valid year" unless expired? || valid_expiry_year?(@year) end end def validate_switch_or_solo_attributes #:nodoc: - if %w[switch solo].include?(type) + if %w[switch solo].include?(brand) unless valid_month?(@start_month) && valid_start_year?(@start_year) || valid_issue_number?(@issue_number) errors.add :start_month, "is invalid" unless valid_month?(@start_month) errors.add :start_year, "is invalid" unless valid_start_year?(@start_year) errors.add :issue_number, "cannot be empty" unless valid_issue_number?(@issue_number) end