Class: Omnipay::Gateway
- Inherits:
-
Object
- Object
- Omnipay::Gateway
- Defined in:
- lib/omnipay/gateway.rb
Overview
Instance of a gateway connection. Has an uid, and encapsulates an adapter strategy.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#adapter_class ⇒ Object
readonly
Returns the value of attribute adapter_class.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
- #callback_hash(request) ⇒ Object
-
#initialize(opts = {}) ⇒ Gateway
constructor
The options hash must include the following keys : - :uid => the gateways uid - :adapter => the adapter class.
-
#ipn_enabled? ⇒ Boolean
Is IPN enabled?.
-
#ipn_hash(request) ⇒ Hash
The formatted response hashes.
-
#payment_redirection(opts = {}) ⇒ Rack::Response
The Rack::Response corresponding to the redirection to the payment page The options hash must contain the following keys : -
:base_uri
: the current http scheme + host (used in the post-payment redirection) - :amount [Integer] : the amount to pay, in cents Depending on the adapter used, the options hash may have other mandatory keys.
Constructor Details
#initialize(opts = {}) ⇒ Gateway
The options hash must include the following keys :
- :uid => the gateways uid
- :adapter => the adapter class
The options hash may also include the following keys :
- :config => the configration hash passed to the adapter for its initialization
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/omnipay/gateway.rb', line 16 def initialize(opts = {}) @uid = opts[:uid] @adapter_class = opts[:adapter] @config = opts[:config] || {} raise ArgumentError.new("missing parameter :uid") unless @uid raise ArgumentError.new("missing parameter :adapter") unless @adapter_class @adapter = @adapter_class.new(@config) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/omnipay/gateway.rb', line 6 def adapter @adapter end |
#adapter_class ⇒ Object (readonly)
Returns the value of attribute adapter_class.
6 7 8 |
# File 'lib/omnipay/gateway.rb', line 6 def adapter_class @adapter_class end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/omnipay/gateway.rb', line 6 def config @config end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
6 7 8 |
# File 'lib/omnipay/gateway.rb', line 6 def uid @uid end |
Instance Method Details
#callback_hash(request) ⇒ Object
65 66 67 |
# File 'lib/omnipay/gateway.rb', line 65 def callback_hash(request) @adapter.callback_hash(request).merge(:raw => request.params) end |
#ipn_enabled? ⇒ Boolean
Is IPN enabled?
71 72 73 |
# File 'lib/omnipay/gateway.rb', line 71 def ipn_enabled? @adapter_class.ipn? end |
#ipn_hash(request) ⇒ Hash
The formatted response hashes
61 62 63 |
# File 'lib/omnipay/gateway.rb', line 61 def ipn_hash(request) @adapter.ipn_hash(request).merge(:raw => request.params) end |
#payment_redirection(opts = {}) ⇒ Rack::Response
The Rack::Response corresponding to the redirection to the payment page The options hash must contain the following keys :
-
:base_uri
: the current http scheme + host (used in the post-payment redirection) -
:amount [Integer] : the amount to pay, in cents
Depending on the adapter used, the options hash may have other mandatory keys. Refer to the adapter’s documentation for more details
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/omnipay/gateway.rb', line 35 def payment_redirection(opts = {}) base_uri = get_base_uri(opts) raise ArgumentError.new('Missing parameter :base_uri') unless base_uri ipn_url = "#{base_uri}#{Omnipay.configuration.base_path}/#{uid}/ipn" callback_url = "#{base_uri}#{Omnipay.configuration.base_path}/#{uid}/callback" method, url, params = @adapter.request_phase(opts, ipn_url, callback_url) if method == 'GET' redirect_url = url + (url.include?('?') ? '&' : '?') + Rack::Utils.build_query(params) Rack::Response.new.tap{|response| response.redirect(redirect_url)} elsif method == 'POST' form = AutosubmitForm.new(url, params) Rack::Response.new([form.html], 200, {'Content-Type' => 'text/html;charset=utf-8'}) else raise ArgumentError.new('the returned method is neither GET nor POST') end end |