Class: Omnipay::Gateway
- Inherits:
-
Object
- Object
- Omnipay::Gateway
- Defined in:
- lib/omnipay/gateway.rb
Overview
Gateway middleware
Constant Summary collapse
- BASE_PATH =
'/pay'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}, &block) ⇒ Gateway
constructor
A new instance of Gateway.
Constructor Details
#initialize(app, options = {}, &block) ⇒ Gateway
Returns a new instance of Gateway.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/omnipay/gateway.rb', line 10 def initialize(app, ={}, &block) @app = app = @adapter_config_block = block # Refreshed at each request @uid = nil @request = nil end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/omnipay/gateway.rb', line 22 def call(env) # Get the current request @request = Rack::Request.new(env) # Check if the path is good, and extract the uid @uid = extract_uid_from_path(@request.path) return @app.call(env) unless @uid # Get the adapter config for this uid (to handle dynamic configuration) adapter = Adapter.new(@uid, callback_url, , @adapter_config_block) return @app.call(env) unless adapter.valid? # Handle the request phase if request_phase? return RequestPhase.new(@request, adapter).response end # Handle the callback phase if callback_phase? CallbackPhase.new(@request, adapter).update_env! end # Forward to the app @app.call(env) end |