lib/active_merchant/billing/credit_card.rb in activemerchant-1.126.0 vs lib/active_merchant/billing/credit_card.rb in activemerchant-1.129.0

- old
+ new

@@ -30,10 +30,16 @@ # * UnionPay # * Alia # * Olimpica # * Creditel # * Confiable + # * Mada + # * BpPlus + # * Passcard + # * Edenred + # * Anda + # * Creditos directos (Tarjeta D) # # 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. # @@ -59,10 +65,12 @@ # cc.display_number # => XXXX-XXXX-XXXX-4242 # class CreditCard < Model include CreditCardMethods + BRANDS_WITH_SPACES_IN_NUMBER = %w(bp_plus) + class << self # Inherited, but can be overridden w/o changing parent's value attr_accessor :require_verification_value attr_accessor :require_name end @@ -74,11 +82,11 @@ # # @return [String] attr_reader :number def number=(value) - @number = (empty?(value) ? value : value.to_s.gsub(/[^\d]/, '')) + @number = (empty?(value) ? value : filter_number(value)) end # Returns or sets the expiry month for the card. # # @return [Integer] @@ -114,10 +122,16 @@ # * +'union_pay'+ # * +'alia'+ # * +'olimpica'+ # * +'creditel'+ # * +'confiable'+ + # * +'mada'+ + # * +'bp_plus'+ + # * +'passcard'+ + # * +'edenred'+ + # * +'anda'+ + # * +'tarjeta-d'+ # # Or, if you wish to test your implementation, +'bogus'+. # # @return (String) the credit card brand def brand @@ -335,10 +349,23 @@ def emv? icc_data.present? end + def allow_spaces_in_card?(number = nil) + BRANDS_WITH_SPACES_IN_NUMBER.include?(self.class.brand?(self.number || number)) + end + private + + def filter_number(value) + regex = if allow_spaces_in_card?(value) + /[^\d ]/ + else + /[^\d]/ + end + value.to_s.gsub(regex, '') + end def validate_essential_attributes #:nodoc: errors = [] if self.class.requires_name?