rack-payment 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rack-payment/payment.rb +13 -5
- metadata +2 -2
data/lib/rack-payment/payment.rb
CHANGED
@@ -181,17 +181,22 @@ module Rack #:nodoc:
|
|
181
181
|
# @param [#call] The Rack application for this middleware
|
182
182
|
# @param [Hash] Options for the gateway and for Rack::Payment
|
183
183
|
#
|
184
|
-
def initialize
|
184
|
+
def initialize rack_app = nil, options = nil
|
185
185
|
options ||= {}
|
186
186
|
options = look_for_options_in_a_yml_file.merge(options) unless options['yml_config'] == false or options[:yml_config] == false
|
187
187
|
raise ArgumentError, "You must pass options (or put them in a yml file)." if options.empty?
|
188
|
+
raise ArgumentError, 'You must pass a valid Rack application' unless rack_app.nil? or rack_app.respond_to?(:call)
|
188
189
|
|
189
|
-
@app =
|
190
|
-
@gateway_options = options
|
190
|
+
@app = rack_app
|
191
|
+
@gateway_options = options
|
191
192
|
@gateway_type = options['gateway'] || options[:gateway]
|
192
193
|
|
193
|
-
|
194
|
-
|
194
|
+
# Before trying to instantiate a gateway using these options, let's remove *our* options so we
|
195
|
+
# don't end up passing them to the gateway's constructor, possibly blowing it up!
|
196
|
+
|
197
|
+
@test_mode = @gateway_options.delete(:test_mode) if @gateway_options.keys.include?(:test_mode)
|
198
|
+
@test_mode = @gateway_options.delete('test_mode') if @gateway_options.keys.include?('test_mode')
|
199
|
+
ActiveMerchant::Billing::Base.mode = (@test_mode == false) ? :production : :test unless @test_mode.nil?
|
195
200
|
|
196
201
|
DEFAULT_OPTIONS.each do |name, value|
|
197
202
|
# set the default
|
@@ -204,6 +209,9 @@ module Rack #:nodoc:
|
|
204
209
|
send "#{name.to_s.to_sym}=", @gateway_options.delete(name.to_s.to_sym)
|
205
210
|
end
|
206
211
|
end
|
212
|
+
|
213
|
+
# Now we check to see if the gateway is OK
|
214
|
+
raise ArgumentError, 'You must pass a valid Gateway' unless @gateway_type and gateway.is_a?(ActiveMerchant::Billing::Gateway)
|
207
215
|
end
|
208
216
|
|
209
217
|
# The main Rack #call method required by every Rack application / middleware.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-payment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- remi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|