Class: Faker::Stripe
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.ccv(card_type: nil) ⇒ String
Produces a random ccv number.
-
.invalid_card(card_error: nil) ⇒ String
Produces a random invalid card number.
-
.month ⇒ String
Produces a random month in two digits format.
-
.valid_card(card_type: nil) ⇒ String
Produces a random valid card number.
-
.valid_token(card_type: nil) ⇒ String
Produces a random valid Stripe token.
-
.year ⇒ String
Produces a random year that is always in the future.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale
Class Method Details
.ccv(card_type: nil) ⇒ String
Produces a random ccv number.
121 122 123 |
# File 'lib/faker/default/stripe.rb', line 121 def ccv(card_type: nil) (card_type.to_s == 'amex' ? rand_in_range(1000, 9999) : rand_in_range(100, 999)).to_s end |
.invalid_card(card_error: nil) ⇒ String
Produces a random invalid card number.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/faker/default/stripe.rb', line 68 def invalid_card(card_error: nil) invalid_cards = translate('faker.stripe.invalid_cards').keys if card_error.nil? card_error = sample(invalid_cards).to_s else unless invalid_cards.include?(card_error.to_sym) raise ArgumentError, "Invalid credit cards argument can be left blank or include #{invalid_cards.join(', ')}" end end fetch("stripe.invalid_cards.#{card_error}") end |
.month ⇒ String
Produces a random month in two digits format.
92 93 94 |
# File 'lib/faker/default/stripe.rb', line 92 def month format('%02d', rand_in_range(1, 12)) end |
.valid_card(card_type: nil) ⇒ String
Produces a random valid card number.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/faker/default/stripe.rb', line 17 def valid_card(card_type: nil) valid_cards = translate('faker.stripe.valid_cards').keys if card_type.nil? card_type = sample(valid_cards).to_s else unless valid_cards.include?(card_type.to_sym) raise ArgumentError, "Valid credit cards argument can be left blank or include #{valid_cards.join(', ')}" end end fetch("stripe.valid_cards.#{card_type}") end |
.valid_token(card_type: nil) ⇒ String
Produces a random valid Stripe token.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/faker/default/stripe.rb', line 43 def valid_token(card_type: nil) valid_tokens = translate('faker.stripe.valid_tokens').keys if card_type.nil? card_type = sample(valid_tokens).to_s else unless valid_tokens.include?(card_type.to_sym) raise ArgumentError, "Valid credit cards argument can be left blank or include #{valid_tokens.join(', ')}" end end fetch("stripe.valid_tokens.#{card_type}") end |
.year ⇒ String
Produces a random year that is always in the future.
105 106 107 108 |
# File 'lib/faker/default/stripe.rb', line 105 def year start_year = ::Time.new.year + 1 rand_in_range(start_year, start_year + 5).to_s end |