Class: Omnipay::CallbackPhase
- Inherits:
-
Object
- Object
- Omnipay::CallbackPhase
- Defined in:
- lib/omnipay/callback_phase.rb
Overview
Class responsible for the processing in a gateway’s callback phase. It updates the request’s environemnt with the formatted Omnipay response given by the apdater’s implementation.
Instance Method Summary collapse
- #initialize(request, adapter) ⇒ CallbackPhase constructor
-
#update_env! ⇒ Object
Actually set the request’s environment variable ‘omnipay.response’ with the formatted summary of the payment transaction.
Constructor Details
#initialize(request, adapter) ⇒ CallbackPhase
9 10 11 12 |
# File 'lib/omnipay/callback_phase.rb', line 9 def initialize(request, adapter) @request = request @adapter = adapter end |
Instance Method Details
#update_env! ⇒ Object
Note:
Should only be called once because of the signatures lifetime
Actually set the request’s environment variable ‘omnipay.response’ with the formatted summary of the payment transaction.
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 44 45 46 47 48 |
# File 'lib/omnipay/callback_phase.rb', line 17 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 |