Class: PaynetEasy::PaynetEasyApi::Transport::Response
- Inherits:
-
Object
- Object
- PaynetEasy::PaynetEasyApi::Transport::Response
show all
- Includes:
- Error
- Defined in:
- lib/paynet_easy/paynet_easy_api/transport/response.rb
Constant Summary
collapse
- NEEDED_STATUS_UPDATE =
Need to update payment status
'status_update'
- NEEDED_SHOW_HTML =
Need to show html from response
'show_html'
- NEEDED_REDIRECT =
Need redirect to response url
'redirect'
- @@allowed_needed_actions =
[
NEEDED_STATUS_UPDATE,
NEEDED_SHOW_HTML,
NEEDED_REDIRECT
]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(response = {}) ⇒ Response
Returns a new instance of Response.
25
26
27
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 25
def initialize(response = {})
@data = Hash[response.map {|key, value| [key, value.to_s.strip]}]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
125
126
127
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 125
def method_missing(name, *args, &block)
@data.send name, *args, &block
end
|
Instance Attribute Details
#needed_action ⇒ Object
Returns the value of attribute needed_action.
23
24
25
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 23
def needed_action
@needed_action
end
|
Instance Method Details
#approved? ⇒ Boolean
69
70
71
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 69
def approved?
status == 'approved'
end
|
#card_paynet_id ⇒ Object
89
90
91
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 89
def card_paynet_id
fetch 'card-ref-id', nil
end
|
#control_code ⇒ Object
101
102
103
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 101
def control_code
any_key %w(control merchant_control)
end
|
#declined? ⇒ Boolean
77
78
79
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 77
def declined?
%w(filtered declined).include? status
end
|
#error ⇒ Object
117
118
119
120
121
122
123
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 117
def error
if error? || declined?
PaynetError.new error_message
else
raise RuntimeError, 'Response has no error'
end
end
|
#error? ⇒ Boolean
113
114
115
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 113
def error?
%w(validation-error error).include?(type) || status == 'error'
end
|
#error_code ⇒ Object
109
110
111
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 109
def error_code
any_key %w(error_code error-code)
end
|
#error_message ⇒ Object
105
106
107
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 105
def error_message
any_key %w(error_message error-message)
end
|
#has_html? ⇒ Boolean
53
54
55
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 53
def has_html?
!html.nil?
end
|
#has_redirect_url? ⇒ Boolean
97
98
99
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 97
def has_redirect_url?
!redirect_url.nil?
end
|
#html ⇒ Object
49
50
51
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 49
def html
fetch 'html', nil
end
|
#payment_client_id ⇒ Object
81
82
83
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 81
def payment_client_id
any_key %w(merchant-order-id client_orderid merchant_order)
end
|
#payment_paynet_id ⇒ Object
85
86
87
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 85
def payment_paynet_id
any_key %w(orderid paynet-order-id)
end
|
#processing? ⇒ Boolean
73
74
75
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 73
def processing?
status == 'processing'
end
|
#redirect_needed? ⇒ Boolean
45
46
47
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 45
def redirect_needed?
needed_action == NEEDED_REDIRECT
end
|
#redirect_url ⇒ Object
93
94
95
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 93
def redirect_url
fetch 'redirect-url', nil
end
|
#show_html_needed? ⇒ Boolean
41
42
43
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 41
def show_html_needed?
needed_action == NEEDED_SHOW_HTML
end
|
#status ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 61
def status
if !fetch('status', nil) && !%w(validation-error error).include?(type)
store 'status', 'processing'
end
fetch('status').downcase if key? 'status'
end
|
#status_update_needed? ⇒ Boolean
37
38
39
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 37
def status_update_needed?
needed_action == NEEDED_STATUS_UPDATE
end
|
#type ⇒ Object
57
58
59
|
# File 'lib/paynet_easy/paynet_easy_api/transport/response.rb', line 57
def type
fetch('type').downcase if key? 'type'
end
|