Class: MoneyOnline::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Response

Returns a new instance of Response.



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

def initialize(params)
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/money_online/response.rb', line 3

def params
  @params
end

Instance Method Details

#amountObject



9
10
11
# File 'lib/money_online/response.rb', line 9

def amount
  params[:amount].to_i
end

#codeObject



60
61
62
# File 'lib/money_online/response.rb', line 60

def code
  valid? ? "YES" : "NO"
end

#errorObject



64
65
66
# File 'lib/money_online/response.rb', line 64

def error
  "Signature is not valid" if invalid?
end

#generate_signatureObject



37
38
39
# File 'lib/money_online/response.rb', line 37

def generate_signature
  Digest::MD5.hexdigest(generate_signature_string)
end

#generate_signature_stringObject



33
34
35
# File 'lib/money_online/response.rb', line 33

def generate_signature_string
  [ params[:amount], user_id, money_payment_id, MoneyOnline.config.secret ].join
end

#invalid?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/money_online/response.rb', line 45

def invalid?
  not valid?
end

#money_payment_idObject



21
22
23
# File 'lib/money_online/response.rb', line 21

def money_payment_id
  params[:paymentid].to_i
end

#order_idObject



25
26
27
# File 'lib/money_online/response.rb', line 25

def order_id
  params[:orderid].to_i
end

#signatureObject



29
30
31
# File 'lib/money_online/response.rb', line 29

def signature
  params[:key]
end

#to_xml(*args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/money_online/response.rb', line 49

def to_xml(*args)
  <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<result>
  <id>#{order_id}</id>
  <code>#{code}</code>
  <comment>#{error}</comment>
</result>
  XML
end

#user_extraObject



17
18
19
# File 'lib/money_online/response.rb', line 17

def user_extra
  params[:userid_extra]
end

#user_idObject



13
14
15
# File 'lib/money_online/response.rb', line 13

def user_id
  params[:userid].to_i
end

#valid?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/money_online/response.rb', line 41

def valid?
  generate_signature == signature
end