Sha256: a33cc16dbd3f11d7f96ca76c1795c6122f661b99f42f1af4c02bf125836d9dca

Contents?: true

Size: 812 Bytes

Versions: 13

Compression:

Stored size: 812 Bytes

Contents

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    module CreditCardFormatting
      def expdate(credit_card)
        "#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
      end

      # This method is used to format numerical information pertaining to credit cards.
      #
      #   format(2005, :two_digits)  # => "05"
      #   format(05,   :four_digits) # => "0005"
      def format(number, option)
        return '' if number.blank?

        case option
        when :two_digits  then sprintf('%.2i', number.to_i)[-2..-1]
        when :four_digits then sprintf('%.4i', number.to_i)[-4..-1]
        when :four_digits_year then number.to_s.length == 2 ? '20' + number.to_s : format(number, :four_digits)
        else number
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
swiss-activemerchant-1.0.5 lib/active_merchant/billing/credit_card_formatting.rb
swiss-activemerchant-1.0.4 lib/active_merchant/billing/credit_card_formatting.rb
swiss-activemerchant-1.0.2 lib/active_merchant/billing/credit_card_formatting.rb
swiss-activemerchant-1.0.1 lib/active_merchant/billing/credit_card_formatting.rb
activemerchant-1.133.0 lib/active_merchant/billing/credit_card_formatting.rb
activemerchant-1.131.0 lib/active_merchant/billing/credit_card_formatting.rb
activemerchant-1.130.0 lib/active_merchant/billing/credit_card_formatting.rb
activemerchant-1.129.0 lib/active_merchant/billing/credit_card_formatting.rb
activemerchant-1.126.0 lib/active_merchant/billing/credit_card_formatting.rb
activemerchant-1.125.0 lib/active_merchant/billing/credit_card_formatting.rb
archetype2142_activemerchant-1.124.0 lib/active_merchant/billing/credit_card_formatting.rb
activemerchant-1.124.0 lib/active_merchant/billing/credit_card_formatting.rb
activemerchant-1.123.0 lib/active_merchant/billing/credit_card_formatting.rb