Module: ActiveMerchant::Billing::CreditCardFormatting

Included in:
Gateway
Defined in:
lib/active_merchant/billing/credit_card_formatting.rb

Instance Method Summary collapse

Instance Method Details

#expdate(credit_card) ⇒ Object



5
6
7
# File 'lib/active_merchant/billing/credit_card_formatting.rb', line 5

def expdate(credit_card)
  "#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
end

#format(number, option) ⇒ Object

This method is used to format numerical information pertaining to credit cards.

format(2005, :two_digits)  # => "05"
format(05,   :four_digits) # => "0005"


13
14
15
16
17
18
19
20
21
# File 'lib/active_merchant/billing/credit_card_formatting.rb', line 13

def format(number, option)
  return '' if number.blank?

  case option
    when :two_digits  ; sprintf("%.2i", number.to_i)[-2..-1]
    when :four_digits ; sprintf("%.4i", number.to_i)[-4..-1]
    else number
  end
end