Class: AdaptivePay::Response
- Inherits:
-
Object
- Object
- AdaptivePay::Response
show all
- Defined in:
- lib/adaptive_pay/response.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(interface, type, response) ⇒ Response
Returns a new instance of Response.
6
7
8
9
10
11
12
|
# File 'lib/adaptive_pay/response.rb', line 6
def initialize(interface, type, response)
@type = type
@base_page_url = interface.base_page_url
@attributes = {}
@raw = response.body
parse response
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/adaptive_pay/response.rb', line 55
def method_missing(name, *args)
if @attributes.has_key?(name.to_s.camelize(:lower))
@attributes[name.to_s.camelize(:lower)]
else
super
end
end
|
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
4
5
6
|
# File 'lib/adaptive_pay/response.rb', line 4
def raw
@raw
end
|
Instance Method Details
#completed? ⇒ Boolean
31
32
33
|
# File 'lib/adaptive_pay/response.rb', line 31
def completed?
payment_exec_status == "COMPLETED"
end
|
#created? ⇒ Boolean
23
24
25
|
# File 'lib/adaptive_pay/response.rb', line 23
def created?
payment_exec_status == "CREATED"
end
|
#errors ⇒ Object
35
36
37
|
# File 'lib/adaptive_pay/response.rb', line 35
def errors
read_attribute("error")
end
|
#failure? ⇒ Boolean
18
19
20
|
# File 'lib/adaptive_pay/response.rb', line 18
def failure?
!@success
end
|
#payment_page_url ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/adaptive_pay/response.rb', line 40
def payment_page_url
case @type
when :preapproval
"#{@base_page_url}/webscr?cmd=_ap-preapproval&preapprovalkey=#{URI.escape(preapproval_key)}"
when :payment
"#{@base_page_url}/webscr?cmd=_ap-payment&paykey=#{URI.escape(pay_key)}"
end
end
|
#pending? ⇒ Boolean
27
28
29
|
# File 'lib/adaptive_pay/response.rb', line 27
def pending?
payment_exec_status == "PENDING"
end
|
#read_attribute(name) ⇒ Object
49
50
51
52
53
|
# File 'lib/adaptive_pay/response.rb', line 49
def read_attribute(name)
names = name.split('.')
names, last_name = names[0..-2], names.last
names.inject(@attributes) {|a,n| a[n] || {}}[last_name]
end
|
#success? ⇒ Boolean
14
15
16
|
# File 'lib/adaptive_pay/response.rb', line 14
def success?
!!@success
end
|