Module: StripeMock::RequestHandlers::Coupons

Included in:
Instance
Defined in:
lib/stripe_mock/request_handlers/coupons.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
10
# File 'lib/stripe_mock/request_handlers/coupons.rb', line 5

def Coupons.included(klass)
  klass.add_handler 'post /v1/coupons',        :new_coupon
  klass.add_handler 'get /v1/coupons/(.*)',    :get_coupon
  klass.add_handler 'delete /v1/coupons/(.*)', :delete_coupon
  klass.add_handler 'get /v1/coupons',         :list_coupons
end

Instance Method Details

#delete_coupon(route, method_url, params, headers) ⇒ Object



24
25
26
27
# File 'lib/stripe_mock/request_handlers/coupons.rb', line 24

def delete_coupon(route, method_url, params, headers)
  route =~ method_url
  assert_existence :coupon, $1, coupons.delete($1)
end

#get_coupon(route, method_url, params, headers) ⇒ Object



19
20
21
22
# File 'lib/stripe_mock/request_handlers/coupons.rb', line 19

def get_coupon(route, method_url, params, headers)
  route =~ method_url
  assert_existence :coupon, $1, coupons[$1]
end

#list_coupons(route, method_url, params, headers) ⇒ Object



29
30
31
# File 'lib/stripe_mock/request_handlers/coupons.rb', line 29

def list_coupons(route, method_url, params, headers)
  Data.mock_list_object(coupons.values, params)
end

#new_coupon(route, method_url, params, headers) ⇒ Object

Raises:

  • (Stripe::InvalidRequestError)


12
13
14
15
16
17
# File 'lib/stripe_mock/request_handlers/coupons.rb', line 12

def new_coupon(route, method_url, params, headers)
  params[:id] ||= new_id('coupon')
  raise Stripe::InvalidRequestError.new('Missing required param: duration', 'coupon', http_status: 400) unless params[:duration]
  raise Stripe::InvalidRequestError.new('You must pass currency when passing amount_off', 'coupon', http_status: 400) if params[:amount_off] && !params[:currency]
  coupons[ params[:id] ] = Data.mock_coupon({amount_off: nil, percent_off:nil}.merge(params))
end