Class: Paygate::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/paygate/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/paygate/response.rb', line 5

def body
  @body
end

#http_codeObject

Returns the value of attribute http_code.



5
6
7
# File 'lib/paygate/response.rb', line 5

def http_code
  @http_code
end

#jsonObject

Returns the value of attribute json.



5
6
7
# File 'lib/paygate/response.rb', line 5

def json
  @json
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/paygate/response.rb', line 5

def message
  @message
end

#raw_infoObject

Returns the value of attribute raw_info.



5
6
7
# File 'lib/paygate/response.rb', line 5

def raw_info
  @raw_info
end

#transaction_typeObject

Returns the value of attribute transaction_type.



5
6
7
# File 'lib/paygate/response.rb', line 5

def transaction_type
  @transaction_type
end

Class Method Details

.build_from_net_http_response(txn_type, response) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/paygate/response.rb', line 7

def self.build_from_net_http_response(txn_type, response)
  r = new
  r.transaction_type = txn_type
  r.http_code = response.code
  r.message = response.message
  r.body = response.body

  case txn_type
  when :refund
    r.json = JSON.parse response.body.gsub(/^callback\((.*)\)$/, '\1') if response.code.to_i == 200
  when :profile_pay
    r.json = {}
    response.body.split('&').each do |key_value_pair|
      key_value_ary = key_value_pair.split('=')
      r.json[key_value_ary[0]] = key_value_ary[1]
    end
  end
  r
end