Class: Rack::Monetize::ProcessMonetizeState

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/monetize/process_monetize_state.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ProcessMonetizeState

Returns a new instance of ProcessMonetizeState.



4
5
6
# File 'lib/rack/monetize/process_monetize_state.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rack/monetize/process_monetize_state.rb', line 8

def call(env)
  req = ::Rack::Request.new(env)

  # If there is no `monetization_state` field ignore this middleware
  return @app.call(env) unless req.params['monetization_state']

  # Otherwise calculate the signature and check that it matches
  if req.params['monetization_state'] && check_monetization_state(req.params['monetization_state'])
    @app.call(env)
  else
    [403, {}, ['']]
  end
end