module Midpay::Strategy
Attributes
app[R]
arguments[R]
env[R]
options[R]
Public Class Methods
included(base)
click to toggle source
# File lib/midpay/strategy.rb, line 39 def self.included base base.extend ClassMethods Midpay[base.strategy_name.to_sym] = base end
new(app, *args, &block)
click to toggle source
# File lib/midpay/strategy.rb, line 68 def initialize app, *args, &block @app, @env = app, nil opts = args.last.is_a?(::Hash) ? args.pop : {} @options = self.class.default_options.dup [:app_key, :app_secret, :request_params_proc].each do |k| options[k] = opts.delete(k) end @arguments = self.class.default_arguments.dup.merge(opts) options.request_params_proc ||= block end
Public Instance Methods
_call(env)
click to toggle source
# File lib/midpay/strategy.rb, line 83 def _call(env) @env = env; on_path?(callback_path) ? callback_call! : (on_path?(request_path) ? request_call! : app.call(env)) end
call(env)
click to toggle source
# File lib/midpay/strategy.rb, line 79 def call(env) dup._call(env) end
callback_call!()
click to toggle source
# File lib/midpay/strategy.rb, line 126 def callback_call! log :info, "midpay callback_call!" pi = PaymentInfo.new(options.name) callback_phase(pi) raise ::Midpay::Errors::InvalidPaymentInfo.new unless pi.valid? env['midpay.strategy'] = self env['midpay.callback'] = pi app.call(env) end
callback_path()
click to toggle source
# File lib/midpay/strategy.rb, line 97 def callback_path path = options.callback_path || "#{root_path}/#{options.name}/callback" path.sub(/\/$/,'') end
callback_phase()
click to toggle source
# File lib/midpay/strategy.rb, line 149 def callback_phase; raise NotImplementedError.new; end
callback_url()
click to toggle source
# File lib/midpay/strategy.rb, line 110 def callback_url URI.join(request.url, callback_path).to_s end
current_path()
click to toggle source
# File lib/midpay/strategy.rb, line 102 def current_path request.path_info.downcase.sub(/\/$/,'') end
log(l ,msg)
click to toggle source
# File lib/midpay/strategy.rb, line 144 def log(l ,msg) ::Midpay.logger.send(l, msg) end
on_path?(path)
click to toggle source
# File lib/midpay/strategy.rb, line 106 def on_path? path current_path.casecmp(path) == 0 end
request()
click to toggle source
# File lib/midpay/strategy.rb, line 136 def request @request ||= ::Rack::Request.new(@env) end
request_call!()
click to toggle source
# File lib/midpay/strategy.rb, line 114 def request_call! log :info, "midpay request_call!" response = ::Rack::Response.new request_phase(response) response.finish end
request_data()
click to toggle source
# File lib/midpay/strategy.rb, line 121 def request_data proc = options.request_params_proc @request_data ||= ::Midpay::SignableHash.new(proc.respond_to?(:call) ? proc.call(request.params.dup) : {}) end
request_params()
click to toggle source
# File lib/midpay/strategy.rb, line 140 def request_params @request_params ||= ::Midpay::SignableHash.new(@request.params || {}) end
request_path()
click to toggle source
# File lib/midpay/strategy.rb, line 92 def request_path path = options.request_path || "#{root_path}/#{options.name}" path.sub(/\/$/,'') end
request_phase(response)
click to toggle source
# File lib/midpay/strategy.rb, line 148 def request_phase(response); raise NotImplementedError.new; end
root_path()
click to toggle source
# File lib/midpay/strategy.rb, line 88 def root_path ::Midpay.config.root_path.to_s.sub(/\/$/,'') end