Module: ActiveMerchant::Billing::CreditCardFormatting
- Included in:
- Gateway
- Defined in:
- lib/active_merchant/billing/credit_card_formatting.rb
Instance Method Summary collapse
- #expdate(credit_card) ⇒ Object
-
#format(number, option) ⇒ Object
This method is used to format numerical information pertaining to credit cards.
- #strftime_yyyymm(credit_card) ⇒ Object
- #strftime_yyyymmdd_last_day(credit_card) ⇒ Object
Instance Method Details
#expdate(credit_card) ⇒ Object
4 5 6 |
# File 'lib/active_merchant/billing/credit_card_formatting.rb', line 4 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"
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_merchant/billing/credit_card_formatting.rb', line 23 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 |
#strftime_yyyymm(credit_card) ⇒ Object
8 9 10 |
# File 'lib/active_merchant/billing/credit_card_formatting.rb', line 8 def strftime_yyyymm(credit_card) format(credit_card.year, :four_digits) + format(credit_card.month, :two_digits) end |
#strftime_yyyymmdd_last_day(credit_card) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/active_merchant/billing/credit_card_formatting.rb', line 12 def strftime_yyyymmdd_last_day(credit_card) year = credit_card.year.to_i month = credit_card.month.to_i last_day = Date.civil(year, month, -1).day format(year, :four_digits) + format(month, :two_digits) + format(last_day, :two_digits) end |