module StripeMock::CardErrors
Public Class Methods
build_card_error(message, param, **kwargs)
click to toggle source
# File lib/stripe_mock/api/errors.rb, line 57 def self.build_card_error(message, param, **kwargs) json_hash = { message: message, param: param, code: kwargs[:code], type: 'card_error', decline_code: get_decline_code(kwargs[:code]) } error_keyword_args = kwargs.merge(json_body: { error: json_hash }, http_body: { error: json_hash }.to_json) Stripe::CardError.new(message, param, **error_keyword_args) end
build_error_for(code)
click to toggle source
# File lib/stripe_mock/api/errors.rb, line 26 def self.build_error_for(code) case code when :incorrect_number then build_card_error('The card number is incorrect', 'number', code: 'incorrect_number', http_status: 402) when :invalid_number then build_card_error('The card number is not a valid credit card number', 'number', code: 'invalid_number', http_status: 402) when :invalid_expiry_month then build_card_error("The card's expiration month is invalid", 'exp_month', code: 'invalid_expiry_month', http_status: 402) when :invalid_expiry_year then build_card_error("The card's expiration year is invalid", 'exp_year', code: 'invalid_expiry_year', http_status: 402) when :invalid_cvc then build_card_error("The card's security code is invalid", 'cvc', code: 'invalid_cvc', http_status: 402) when :expired_card then build_card_error('The card has expired', 'exp_month', code: 'expired_card', http_status: 402) when :incorrect_cvc then build_card_error("The card's security code is incorrect", 'cvc', code: 'incorrect_cvc', http_status: 402) when :card_declined then build_card_error('The card was declined', nil, code: 'card_declined', http_status: 402) when :missing then build_card_error('There is no card on a customer that is being charged.', nil, code: 'missing', http_status: 402) when :processing_error then build_card_error('An error occurred while processing the card', nil, code: 'processing_error', http_status: 402) when :card_error then build_card_error('The card number is not a valid credit card number.', 'number', code: 'invalid_number', http_status: 402) when :incorrect_zip then build_card_error('The zip code you supplied failed validation.', 'address_zip', code: 'incorrect_zip', http_status: 402) when :insufficient_funds then build_card_error('The card has insufficient funds to complete the purchase.', nil, code: 'insufficient_funds', http_status: 402) when :lost_card then build_card_error('The payment has been declined because the card is reported lost.', nil, code: 'lost_card', http_status: 402) when :stolen_card then build_card_error('The payment has been declined because the card is reported stolen.', nil, code: 'stolen_card', http_status: 402) end end
get_decline_code(code)
click to toggle source
# File lib/stripe_mock/api/errors.rb, line 46 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