Module: StripeMock::RequestHandlers::PromotionCodes
- Included in:
- Instance
- Defined in:
- lib/stripe_mock/request_handlers/promotion_codes.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_promotion_code(route, method_url, params, headers) ⇒ Object
- #list_promotion_code(route, method_url, params, headers) ⇒ Object
- #new_promotion_code(route, method_url, params, headers) ⇒ Object
- #update_promotion_code(route, method_url, params, headers) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/stripe_mock/request_handlers/promotion_codes.rb', line 5 def PromotionCodes.included(klass) klass.add_handler 'post /v1/promotion_codes', :new_promotion_code klass.add_handler 'post /v1/promotion_codes/([^/]*)', :update_promotion_code klass.add_handler 'get /v1/promotion_codes/([^/]*)', :get_promotion_code klass.add_handler 'get /v1/promotion_codes', :list_promotion_code end |
Instance Method Details
#get_promotion_code(route, method_url, params, headers) ⇒ Object
33 34 35 36 |
# File 'lib/stripe_mock/request_handlers/promotion_codes.rb', line 33 def get_promotion_code(route, method_url, params, headers) route =~ method_url assert_existence :promotion_code, $1, promotion_codes[$1] end |
#list_promotion_code(route, method_url, params, headers) ⇒ Object
38 39 40 |
# File 'lib/stripe_mock/request_handlers/promotion_codes.rb', line 38 def list_promotion_code(route, method_url, params, headers) Data.mock_list_object(promotion_codes.values, params) end |
#new_promotion_code(route, method_url, params, headers) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/stripe_mock/request_handlers/promotion_codes.rb', line 12 def new_promotion_code(route, method_url, params, headers) params[:id] ||= new_id("promo") raise Stripe::InvalidRequestError.new("Missing required param: coupon", "promotion_code", http_status: 400) unless params[:coupon] if params[:restrictions] if params[:restrictions][:minimum_amount] && !params[:restrictions][:minimum_amount_currency] raise Stripe::InvalidRequestError.new( "You must pass minimum_amount_currency when passing minimum_amount", "minimum_amount_currency", http_status: 400 ) end end promotion_codes[ params[:id] ] = Data.mock_promotion_code(params) end |
#update_promotion_code(route, method_url, params, headers) ⇒ Object
27 28 29 30 31 |
# File 'lib/stripe_mock/request_handlers/promotion_codes.rb', line 27 def update_promotion_code(route, method_url, params, headers) route =~ method_url assert_existence :promotion_code, $1, promotion_codes[$1] promotion_codes[$1].merge!(params) end |