Class: Remit::InboundRequest

Inherits:
Object
  • Object
show all
Extended by:
SignatureUtilsForOutbound
Includes:
ConvertKey
Defined in:
lib/remit/inbound_request.rb

Direct Known Subclasses

IpnRequest, PipelineResponse

Constant Summary collapse

SIGNATURE_KEY =

signature key name

'signature'

Constants included from SignatureUtilsForOutbound

SignatureUtilsForOutbound::CERTIFICATE_URL_KEYNAME, SignatureUtilsForOutbound::SIGNATURE_KEYNAME, SignatureUtilsForOutbound::SIGNATURE_METHOD_KEYNAME, SignatureUtilsForOutbound::SIGNATURE_VERSION_2, SignatureUtilsForOutbound::SIGNATURE_VERSION_KEYNAME

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SignatureUtilsForOutbound

check_parameters, get_http_params, urlencode

Methods included from ConvertKey

#convert_key

Constructor Details

#initialize(request_url, params, client, options = {}) ⇒ InboundRequest

request_url is the full request path up to the query string, as from request.url in the controller params is the full params hash from the controller client is a fully instantiated Remit::API with access keys and sandbox settings

Only clean params hash is params is sent as a hash. Assume caller has cleaned string if string is sent as params



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/remit/inbound_request.rb', line 26

def initialize(request_url, params, client, options = {})
  if params.is_a?(String)
    @string_params = params
    @hash_params = Hash.from_url_params(params)
  else
    unless options.kind_of?(Hash)
      options = {}
    end
    options[:skip_param_keys] ||= []
    #this is a bit of helpful sugar for rails framework users
    options[:skip_param_keys] |= ['action','controller']

    if params.respond_to?(:reject)
      params.reject! {|key, val| options[:skip_param_keys].include?(key) }
    else
      params = {}
    end
    @hash_params      = params
    @string_params    = InboundRequest.get_http_params(@hash_params)
  end
  #puts "Params are: #{params.inspect}"
  @request_url        = request_url
  @client             = client
  @supplied_signature = @hash_params[self.class::SIGNATURE_KEY]
  @allow_sigv1        = options[:allow_sigv1] || false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

:nodoc:



75
76
77
78
79
80
81
82
# File 'lib/remit/inbound_request.rb', line 75

def method_missing(method, *args, &block) #:nodoc:
  return @hash_params[method.to_s] if @hash_params.has_key?(method.to_s)
  return @hash_params[method.to_sym] if @hash_params.has_key?(method.to_sym)
  key = self.convert_key(method)
  return @hash_params[key] if @hash_params.has_key?(key)
  return @hash_params[key.to_s] if @hash_params.has_key?(key.to_s)
  super
end

Instance Attribute Details

#allow_sigv1Object (readonly)

Returns the value of attribute allow_sigv1.



12
13
14
# File 'lib/remit/inbound_request.rb', line 12

def allow_sigv1
  @allow_sigv1
end

#hash_paramsObject (readonly)

BJM: need to access sometimes from the app



15
16
17
# File 'lib/remit/inbound_request.rb', line 15

def hash_params
  @hash_params
end

#supplied_signatureObject (readonly)

Returns the value of attribute supplied_signature.



11
12
13
# File 'lib/remit/inbound_request.rb', line 11

def supplied_signature
  @supplied_signature
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/remit/inbound_request.rb', line 53

def valid?
  if @hash_params['signatureVersion'].to_i == 2
    #puts "\nhash_params: #{@hash_params.inspect}\n"
    #puts "\nstring_params: #{@string_params.inspect}\n"
    return false unless InboundRequest.check_parameters(@hash_params)
    verify_request = Remit::VerifySignature::Request.new(
      :url_end_point => @request_url,#InboundRequest.urlencode(@request_url),
      :version => Remit::API::API_VERSION,
      :http_parameters => @string_params
    )
    #puts "\nurl_end_point#{@request_url.inspect}\n"
    #puts "\nhttp_parameters: #{verify_request.http_parameters.inspect}\n"
    result = @client.verify_signature(verify_request)
    #puts "\nresult: #{result.raw.inspect}\n"
    result.verify_signature_result.verification_status == 'Success'
  elsif @hash_params['signatureVersion'].nil? and self.allow_sigv1
    self.supplied_signature == Remit::API.signature_v1(URI.parse(@request_url).path, @hash_params, @client.secret_key).gsub('+', ' ')
  else
    false
  end
end