Module: StripeMock::CardErrors

Defined in:
lib/stripe_mock/api/errors.rb

Class Method Summary collapse

Class Method Details

.add_json_body(error_values) ⇒ Object



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

def self.add_json_body(error_values)
  error_keys = [:message, :param, :code]

  json_hash = Hash[error_keys.zip error_values]
  json_hash[:type] = 'card_error'
  json_hash[:decline_code] = get_decline_code(json_hash[:code])

  error_values.last.merge!(json_body: { error: json_hash }, http_body: { error: json_hash })

  error_values
end

.argument_mapObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/stripe_mock/api/errors.rb', line 25

def self.argument_map
  @__map ||= {
    incorrect_number: add_json_body(["The card number is incorrect", 'number', 'incorrect_number', http_status: 402]),
    invalid_number: add_json_body(["The card number is not a valid credit card number", 'number', 'invalid_number', http_status: 402]),
    invalid_expiry_month: add_json_body(["The card's expiration month is invalid", 'exp_month', 'invalid_expiry_month', http_status: 402]),
    invalid_expiry_year: add_json_body(["The card's expiration year is invalid", 'exp_year', 'invalid_expiry_year', http_status: 402]),
    invalid_cvc: add_json_body(["The card's security code is invalid", 'cvc', 'invalid_cvc', http_status: 402]),
    expired_card: add_json_body(["The card has expired", 'exp_month', 'expired_card', http_status: 402]),
    incorrect_cvc: add_json_body(["The card's security code is incorrect", 'cvc', 'incorrect_cvc', http_status: 402]),
    card_declined: add_json_body(["The card was declined", nil, 'card_declined', http_status: 402]),
    missing: add_json_body(["There is no card on a customer that is being charged.", nil, 'missing', http_status: 402]),
    processing_error: add_json_body(["An error occurred while processing the card", nil, 'processing_error', http_status: 402]),
    card_error: add_json_body(['The card number is not a valid credit card number.', 'number', 'invalid_number', http_status: 402]),
    incorrect_zip: add_json_body(['The zip code you supplied failed validation.', 'address_zip', 'incorrect_zip', http_status: 402])
  }
end

.get_decline_code(code) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/stripe_mock/api/errors.rb', line 42

def self.get_decline_code(code)
  decline_code_map = {
    card_declined: 'do_not_honor',
    missing: nil
  }
  decline_code_map.default = code.to_s

  code_key = code.to_sym
  decline_code_map[code_key]
end