Class: Omnipay::CallbackPhase

Inherits:
Object
  • Object
show all
Defined in:
lib/omnipay/callback_phase.rb

Instance Method Summary collapse

Constructor Details

#initialize(request, adapter) ⇒ CallbackPhase

Returns a new instance of CallbackPhase.



6
7
8
9
# File 'lib/omnipay/callback_phase.rb', line 6

def initialize(request, adapter)
  @request = request
  @adapter = adapter
end

Instance Method Details

#update_env!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/omnipay/callback_phase.rb', line 12

def update_env!

  # The request params, keys symbolized
  params = Hash[@request.params.map{|k,v|[k.to_sym,v]}]

  # Get the callback hash
  callback_hash = @adapter.callback_hash(params)

  # Check the signature
  if callback_hash[:success] && !valid_signature?(callback_hash)
    callback_hash = {
      :success => false, 
      :error => Omnipay::WRONG_SIGNATURE, 
      :error_message => "Signatures do not match."
    }
  end

  # If not successful response, add informations to the error message
  if !callback_hash[:success]
    callback_hash[:error_message] = (callback_hash[:error_message] || callback_hash[:error].to_s) +
      "\nAdapter : #{@adapter.uid}" +
      "\nContext : #{context.inspect}" +
      "\nStored signature : #{stored_signature}" +
      "\nRequest : #{@request.inspect}"
  end

  # Store the response in the environment
  @request.env['omnipay.response'] = callback_hash.merge(:raw => params, :context => context)

  # Force GET request
  @request.env['REQUEST_METHOD'] = 'GET'      
end