Module: StripeMock::CreditCards

Defined in:
lib/stripe_mock/credit_cards/cards.rb

Constant Summary collapse

BAD_CARDS =
[
  {
    exp_month: '0',
    code: :invalid_expiry_month
  },
  {
    exp_year: '0',
    code: :invalid_expiry_year
  },
  {
    number: '4242424242424241',
    code: :incorrect_number
  },
  {
    number: '4000000000000002',
    code: :card_declined
  },
  {
    number: '4000000000000127',
    code: :incorrect_cvc
  },
  {
    number: '4000000000000119',
    code: :processing_error
  },
  {
    number: 'asdf',
    code: :invalid_number
  },
  {
    cvc: '0',
    code: :invalid_cvc
  }
]

Class Method Summary collapse

Class Method Details

.attr_value_by_code(type, code) ⇒ Object



43
44
45
46
47
# File 'lib/stripe_mock/credit_cards/cards.rb', line 43

def attr_value_by_code(type, code)
  BAD_CARDS.detect do |hash|
    code == hash[:code]
  end[type.to_sym]
end

.card_error(card_hash) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/stripe_mock/credit_cards/cards.rb', line 53

def card_error(card_hash)
  hash = BAD_CARDS.detect do |hash|
    hash.keys.any? do |key|
      !card_hash[key].nil? && card_hash[key] == hash[key]
    end
  end

  unless hash.nil?
    StripeMock.card_failures[hash[:code]]
  end
end

.card_number_by_code(code) ⇒ Object



39
40
41
# File 'lib/stripe_mock/credit_cards/cards.rb', line 39

def card_number_by_code(code)
  attr_value_by_code(:number, code)
end

.is_erroneous?(card_hash) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/stripe_mock/credit_cards/cards.rb', line 49

def is_erroneous?(card_hash)
  !card_error(card_hash).nil?
end