class UnionPay::Core::Response

Attributes

body[R]

Public Class Methods

new(resp, config) click to toggle source
# File lib/union-pay/core/response.rb, line 8
def initialize(resp, config)
  if resp.is_a?(String)
    @body = parse_query(resp)
  else
    @raw_body = ::UnionPay::Core::Utils.key_to_sym(resp)
    @body = @raw_body.dup
    decode_reserved!(@body)
  end
  @config = config
end

Public Instance Methods

[](key) click to toggle source
# File lib/union-pay/core/response.rb, line 27
def [](key)
  @body[key]
end
inspect() click to toggle source
# File lib/union-pay/core/response.rb, line 31
def inspect
  @body.inspect
end
sign_valid?() click to toggle source
# File lib/union-pay/core/response.rb, line 23
def sign_valid?
  Signer.md5_sign(@raw_body, @config.secret_key) == @raw_body[:signature]
end
success?() click to toggle source
# File lib/union-pay/core/response.rb, line 19
def success?
  sign_valid? && @body[:respCode] == '00'
end

Private Instance Methods

decode_reserved!(params) click to toggle source
# File lib/union-pay/core/response.rb, line 44
def decode_reserved!(params)
  params.each do |k, v|
    params[k] = UnionPay::Core::Utils.decode_reserved(v) if k.to_s =~ /Reserved$/
  end
end
parse_query(query_string) click to toggle source
# File lib/union-pay/core/response.rb, line 36
def parse_query(query_string)
  h = CGI.parse(query_string)
  @raw_body = Hash[h.collect{|k, v| v.size <= 1 ? [k.to_sym, v.first] : [k.to_sym, v]}]
  h = @raw_body.dup
  decode_reserved!(h)
  h
end