Module: StripeMock::RequestHandlers::ParamValidators
- Included in:
- Instance
- Defined in:
- lib/stripe_mock/request_handlers/validators/param_validators.rb
Constant Summary collapse
- SUPPORTED_PLAN_INTERVALS =
["month", "year", "week", "day"]
- SUPPORTED_CURRENCIES =
[ "usd", "aed", "afn", "all", "amd", "ang", "aoa", "ars", "aud", "awg", "azn", "bam", "bbd", "bdt", "bgn", "bif", "bmd", "bnd", "bob", "brl", "bsd", "bwp", "bzd", "cad", "cdf", "chf", "clp", "cny", "cop", "crc", "cve", "czk", "djf", "dkk", "dop", "dzd", "egp", "etb", "eur", "fjd", "fkp", "gbp", "gel", "gip", "gmd", "gnf", "gtq", "gyd", "hkd", "hnl", "hrk", "htg", "huf", "idr", "ils", "inr", "isk", "jmd", "jpy", "kes", "kgs", "khr", "kmf", "krw", "kyd", "kzt", "lak", "lbp", "lkr", "lrd", "lsl", "mad", "mdl", "mga", "mkd", "mmk", "mnt", "mop", "mro", "mur", "mvr", "mwk", "mxn", "myr", "mzn", "nad", "ngn", "nio", "nok", "npr", "nzd", "pab", "pen", "pgk", "php", "pkr", "pln", "pyg", "qar", "ron", "rsd", "rub", "rwf", "sar", "sbd", "scr", "sek", "sgd", "shp", "sll", "sos", "srd", "std", "szl", "thb", "tjs", "top", "try", "ttd", "twd", "tzs", "uah", "ugx", "uyu", "uzs", "vnd", "vuv", "wst", "xaf", "xcd", "xof", "xpf", "yer", "zar", "zmw", "eek", "lvl", "svc", "vef", "ltl" ]
Instance Method Summary collapse
- #already_exists_message(obj_class) ⇒ Object
- #invalid_currency_message(my_val) ⇒ Object
- #invalid_integer_message(my_val) ⇒ Object
- #invalid_plan_interval_message ⇒ Object
- #missing_param_message(attr_name) ⇒ Object
-
#missing_plan_amount_message ⇒ Object
PlanValidator.
- #not_found_message(obj_class, obj_id) ⇒ Object
- #require_param(param_name) ⇒ Object
- #validate_create_plan_params(params) ⇒ Object
- #validate_create_price_params(params) ⇒ Object
- #validate_create_product_params(params) ⇒ Object
- #validate_list_prices_params(params) ⇒ Object
Instance Method Details
#already_exists_message(obj_class) ⇒ Object
5 6 7 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 5 def (obj_class) "#{obj_class.to_s.split("::").last} already exists." end |
#invalid_currency_message(my_val) ⇒ Object
64 65 66 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 64 def (my_val) "Invalid currency: #{my_val.downcase}. Stripe currently supports these currencies: #{SUPPORTED_CURRENCIES.join(", ")}" end |
#invalid_integer_message(my_val) ⇒ Object
17 18 19 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 17 def (my_val) "Invalid integer: #{my_val}" end |
#invalid_plan_interval_message ⇒ Object
47 48 49 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 47 def "Invalid interval: must be one of day, month, week, or year" end |
#missing_param_message(attr_name) ⇒ Object
13 14 15 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 13 def (attr_name) "Missing required param: #{attr_name}." end |
#missing_plan_amount_message ⇒ Object
PlanValidator
41 42 43 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 41 def "Plans require an `amount` parameter to be set." end |
#not_found_message(obj_class, obj_id) ⇒ Object
9 10 11 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 9 def (obj_class, obj_id) "No such #{obj_class.to_s.split("::").last.downcase}: #{obj_id}" end |
#require_param(param_name) ⇒ Object
141 142 143 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 141 def require_param(param_name) raise Stripe::InvalidRequestError.new("Missing required param: #{param_name}.", param_name.to_s, http_status: 400) end |
#validate_create_plan_params(params) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 68 def validate_create_plan_params(params) plan_id = params[:id].to_s product_id = params[:product] @base_strategy.create_plan_params.keys.each do |attr_name| = if attr_name == :amount "Plans require an `#{attr_name}` parameter to be set." else "Missing required param: #{attr_name}." end raise Stripe::InvalidRequestError.new(, attr_name) if params[attr_name].nil? end if plans[plan_id] = (Stripe::Plan) raise Stripe::InvalidRequestError.new(, :id) end unless products[product_id] = (Stripe::Product, product_id) raise Stripe::InvalidRequestError.new(, :product) end unless SUPPORTED_PLAN_INTERVALS.include?(params[:interval]) = raise Stripe::InvalidRequestError.new(, :interval) end unless SUPPORTED_CURRENCIES.include?(params[:currency]) = (params[:currency]) raise Stripe::InvalidRequestError.new(, :currency) end unless params[:amount].integer? = (params[:amount]) raise Stripe::InvalidRequestError.new(, :amount) end end |
#validate_create_price_params(params) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 109 def validate_create_price_params(params) price_id = params[:id].to_s require_param(:currency) unless params[:currency] unless params[:product] || params[:product_data] raise Stripe::InvalidRequestError("Requires product or product_data") end product_id = params[:product] || create_product(nil, nil, params[:product_data], nil).id if prices[price_id] = (Stripe::Price) raise Stripe::InvalidRequestError.new(, :id) end unless products[product_id] = (Stripe::Product, product_id) raise Stripe::InvalidRequestError.new(, :product) end unless SUPPORTED_CURRENCIES.include?(params[:currency]) = (params[:currency]) raise Stripe::InvalidRequestError.new(, :currency) end end |
#validate_create_product_params(params) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 26 def validate_create_product_params(params) params[:id] = params[:id].to_s @base_strategy.create_product_params.keys.reject{ |k,_| k == :id }.each do |k| raise Stripe::InvalidRequestError.new((k), k) if params[k].nil? end if products[ params[:id] ] raise Stripe::InvalidRequestError.new((Stripe::Product), :id) end end |
#validate_list_prices_params(params) ⇒ Object
135 136 137 138 139 |
# File 'lib/stripe_mock/request_handlers/validators/param_validators.rb', line 135 def validate_list_prices_params(params) if params[:lookup_keys] && !params[:lookup_keys].is_a?(Array) raise Stripe::InvalidRequestError.new('Invalid array', :lookup_keys) end end |